SCI: Start converting MessageState into a class
svn-id: r38989
This commit is contained in:
parent
7050c7b03f
commit
82872a7033
3 changed files with 41 additions and 36 deletions
|
@ -750,10 +750,11 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
||||||
tuple.cond = UKPV(4);
|
tuple.cond = UKPV(4);
|
||||||
tuple.seq = UKPV(5);
|
tuple.seq = UKPV(5);
|
||||||
|
|
||||||
if (message_state_load_res(&state, module) && message_get_specific(&state, &tuple)) {
|
if (state.loadRes(module) && state.getSpecific(&tuple)) {
|
||||||
if (buffer)
|
if (buffer)
|
||||||
message_get_text(&state, buffer, 100);
|
state.getText(buffer, 100);
|
||||||
return make_reg(0, message_get_talker(&state)); /* Talker id */
|
// Talker id
|
||||||
|
return make_reg(0, state.getTalker());
|
||||||
} else {
|
} else {
|
||||||
if (buffer) strcpy(buffer, DUMMY_MESSAGE);
|
if (buffer) strcpy(buffer, DUMMY_MESSAGE);
|
||||||
return NULL_REG;
|
return NULL_REG;
|
||||||
|
@ -762,10 +763,11 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
||||||
case 1 : {
|
case 1 : {
|
||||||
char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL;
|
char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL;
|
||||||
|
|
||||||
if (message_get_next(&state)) {
|
if (state.getNext()) {
|
||||||
if (buffer)
|
if (buffer)
|
||||||
message_get_text(&state, buffer, 100);
|
state.getText(buffer, 100);
|
||||||
return make_reg(0, message_get_talker(&state)); /* Talker id */
|
// Talker id
|
||||||
|
return make_reg(0, state.getTalker());
|
||||||
} else {
|
} else {
|
||||||
if (buffer) strcpy(buffer, DUMMY_MESSAGE);
|
if (buffer) strcpy(buffer, DUMMY_MESSAGE);
|
||||||
return NULL_REG;
|
return NULL_REG;
|
||||||
|
@ -779,8 +781,8 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
||||||
tuple.cond = UKPV(4);
|
tuple.cond = UKPV(4);
|
||||||
tuple.seq = UKPV(5);
|
tuple.seq = UKPV(5);
|
||||||
|
|
||||||
if (message_state_load_res(&state, module) && message_get_specific(&state, &tuple))
|
if (state.loadRes(module) && state.getSpecific(&tuple))
|
||||||
return make_reg(0, message_get_length(&state) + 1);
|
return make_reg(0, state.getLength() + 1);
|
||||||
else return NULL_REG;
|
else return NULL_REG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,46 +132,46 @@ static int index_record_find(MessageState *state, MessageTuple *t, IndexRecordCu
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
int message_get_specific(MessageState *state, MessageTuple *t) {
|
int MessageState::getSpecific(MessageTuple *t) {
|
||||||
return index_record_find(state, t, &state->engine_cursor);
|
return index_record_find(this, t, &engine_cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int message_get_next(MessageState *state) {
|
int MessageState::getNext() {
|
||||||
return index_record_next(state, &state->engine_cursor);
|
return index_record_next(this, &engine_cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int message_get_talker(MessageState *state) {
|
int MessageState::getTalker() {
|
||||||
return state->handler->get_talker(&state->engine_cursor);
|
return handler->get_talker(&engine_cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
int message_get_text(MessageState *state, char *buffer, int length) {
|
int MessageState::getText(char *buffer, int length) {
|
||||||
state->handler->get_text(&state->engine_cursor, buffer, length);
|
handler->get_text(&engine_cursor, buffer, length);
|
||||||
return strlen(buffer);
|
return strlen(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int message_get_length(MessageState *state) {
|
int MessageState::getLength() {
|
||||||
char buffer[500];
|
char buffer[500];
|
||||||
|
|
||||||
state->handler->get_text(&state->engine_cursor, buffer, sizeof(buffer));
|
handler->get_text(&engine_cursor, buffer, sizeof(buffer));
|
||||||
return strlen(buffer);
|
return strlen(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int message_state_load_res(MessageState *state, int module) {
|
int MessageState::loadRes(int module) {
|
||||||
if (state->module == module)
|
if (_module == module)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
state->module = module;
|
_module = module;
|
||||||
state->current_res = state->resmgr->findResource(kResourceTypeMessage, module, 0);
|
current_res = resmgr->findResource(kResourceTypeMessage, module, 0);
|
||||||
|
|
||||||
if (state->current_res == NULL || state->current_res->data == NULL) {
|
if (current_res == NULL || current_res->data == NULL) {
|
||||||
sciprintf("Message subsystem: Failed to load %d.MSG\n", module);
|
sciprintf("Message subsystem: Failed to load %d.MSG\n", module);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->record_count = state->handler->index_record_count(state->current_res->data);
|
record_count = handler->index_record_count(current_res->data);
|
||||||
state->index_records = state->current_res->data + state->handler->header_size;
|
index_records = current_res->data + handler->header_size;
|
||||||
|
|
||||||
index_record_cursor_initialize(state, &state->engine_cursor);
|
index_record_cursor_initialize(this, &engine_cursor);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ void message_state_initialize(ResourceManager *resmgr, MessageState *state) {
|
||||||
//version = getUInt16(tester->data);
|
//version = getUInt16(tester->data);
|
||||||
|
|
||||||
state->initialized = 1;
|
state->initialized = 1;
|
||||||
state->module = -1;
|
state->_module = -1;
|
||||||
state->resmgr = resmgr;
|
state->resmgr = resmgr;
|
||||||
state->current_res = NULL;
|
state->current_res = NULL;
|
||||||
state->record_count = 0;
|
state->record_count = 0;
|
||||||
|
|
|
@ -43,7 +43,7 @@ struct IndexRecordCursor {
|
||||||
byte *resource_beginning;
|
byte *resource_beginning;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int index_record_size_t();
|
//typedef int index_record_size_t();
|
||||||
typedef void parse_index_record_t(IndexRecordCursor *index_record, MessageTuple *t);
|
typedef void parse_index_record_t(IndexRecordCursor *index_record, MessageTuple *t);
|
||||||
typedef int get_talker_t(IndexRecordCursor *cursor);
|
typedef int get_talker_t(IndexRecordCursor *cursor);
|
||||||
typedef void get_text_t(IndexRecordCursor *cursor, char *buffer, int buffer_size);
|
typedef void get_text_t(IndexRecordCursor *cursor, char *buffer, int buffer_size);
|
||||||
|
@ -60,23 +60,26 @@ struct MessageHandler {
|
||||||
int index_record_size;
|
int index_record_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MessageState {
|
class MessageState {
|
||||||
|
public:
|
||||||
|
int getSpecific(MessageTuple *t);
|
||||||
|
int getNext();
|
||||||
|
int getTalker();
|
||||||
|
int getLength();
|
||||||
|
int getText(char *buffer, int length);
|
||||||
|
int loadRes(int module);
|
||||||
|
|
||||||
|
public: // TODO: hide the internals
|
||||||
int initialized;
|
int initialized;
|
||||||
MessageHandler *handler;
|
MessageHandler *handler;
|
||||||
ResourceManager *resmgr;
|
ResourceManager *resmgr;
|
||||||
Resource *current_res;
|
Resource *current_res;
|
||||||
int module;
|
int _module;
|
||||||
int record_count;
|
int record_count;
|
||||||
byte *index_records;
|
byte *index_records;
|
||||||
IndexRecordCursor engine_cursor;
|
IndexRecordCursor engine_cursor;
|
||||||
};
|
};
|
||||||
|
|
||||||
int message_get_specific(MessageState *state, MessageTuple *t);
|
|
||||||
int message_get_next(MessageState *state);
|
|
||||||
int message_get_talker(MessageState *state);
|
|
||||||
int message_get_length(MessageState *state);
|
|
||||||
int message_get_text(MessageState *state, char *buffer, int length);
|
|
||||||
int message_state_load_res(MessageState *state, int module);
|
|
||||||
void message_state_initialize(ResourceManager *resmgr, MessageState *state);
|
void message_state_initialize(ResourceManager *resmgr, MessageState *state);
|
||||||
|
|
||||||
} // End of namespace Sci
|
} // End of namespace Sci
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue