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.seq = UKPV(5);
|
||||
|
||||
if (message_state_load_res(&state, module) && message_get_specific(&state, &tuple)) {
|
||||
if (state.loadRes(module) && state.getSpecific(&tuple)) {
|
||||
if (buffer)
|
||||
message_get_text(&state, buffer, 100);
|
||||
return make_reg(0, message_get_talker(&state)); /* Talker id */
|
||||
state.getText(buffer, 100);
|
||||
// Talker id
|
||||
return make_reg(0, state.getTalker());
|
||||
} else {
|
||||
if (buffer) strcpy(buffer, DUMMY_MESSAGE);
|
||||
return NULL_REG;
|
||||
|
@ -762,10 +763,11 @@ reg_t kMessage(EngineState *s, int funct_nr, int argc, reg_t *argv) {
|
|||
case 1 : {
|
||||
char *buffer = argc == 7 ? kernel_dereference_char_pointer(s, argv[6], 0) : NULL;
|
||||
|
||||
if (message_get_next(&state)) {
|
||||
if (state.getNext()) {
|
||||
if (buffer)
|
||||
message_get_text(&state, buffer, 100);
|
||||
return make_reg(0, message_get_talker(&state)); /* Talker id */
|
||||
state.getText(buffer, 100);
|
||||
// Talker id
|
||||
return make_reg(0, state.getTalker());
|
||||
} else {
|
||||
if (buffer) strcpy(buffer, DUMMY_MESSAGE);
|
||||
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.seq = UKPV(5);
|
||||
|
||||
if (message_state_load_res(&state, module) && message_get_specific(&state, &tuple))
|
||||
return make_reg(0, message_get_length(&state) + 1);
|
||||
if (state.loadRes(module) && state.getSpecific(&tuple))
|
||||
return make_reg(0, state.getLength() + 1);
|
||||
else return NULL_REG;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,46 +132,46 @@ static int index_record_find(MessageState *state, MessageTuple *t, IndexRecordCu
|
|||
return found;
|
||||
}
|
||||
|
||||
int message_get_specific(MessageState *state, MessageTuple *t) {
|
||||
return index_record_find(state, t, &state->engine_cursor);
|
||||
int MessageState::getSpecific(MessageTuple *t) {
|
||||
return index_record_find(this, t, &engine_cursor);
|
||||
}
|
||||
|
||||
int message_get_next(MessageState *state) {
|
||||
return index_record_next(state, &state->engine_cursor);
|
||||
int MessageState::getNext() {
|
||||
return index_record_next(this, &engine_cursor);
|
||||
}
|
||||
|
||||
int message_get_talker(MessageState *state) {
|
||||
return state->handler->get_talker(&state->engine_cursor);
|
||||
int MessageState::getTalker() {
|
||||
return handler->get_talker(&engine_cursor);
|
||||
}
|
||||
|
||||
int message_get_text(MessageState *state, char *buffer, int length) {
|
||||
state->handler->get_text(&state->engine_cursor, buffer, length);
|
||||
int MessageState::getText(char *buffer, int length) {
|
||||
handler->get_text(&engine_cursor, buffer, length);
|
||||
return strlen(buffer);
|
||||
}
|
||||
|
||||
int message_get_length(MessageState *state) {
|
||||
int MessageState::getLength() {
|
||||
char buffer[500];
|
||||
|
||||
state->handler->get_text(&state->engine_cursor, buffer, sizeof(buffer));
|
||||
handler->get_text(&engine_cursor, buffer, sizeof(buffer));
|
||||
return strlen(buffer);
|
||||
}
|
||||
|
||||
int message_state_load_res(MessageState *state, int module) {
|
||||
if (state->module == module)
|
||||
int MessageState::loadRes(int module) {
|
||||
if (_module == module)
|
||||
return 1;
|
||||
|
||||
state->module = module;
|
||||
state->current_res = state->resmgr->findResource(kResourceTypeMessage, module, 0);
|
||||
_module = module;
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
state->record_count = state->handler->index_record_count(state->current_res->data);
|
||||
state->index_records = state->current_res->data + state->handler->header_size;
|
||||
record_count = handler->index_record_count(current_res->data);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ void message_state_initialize(ResourceManager *resmgr, MessageState *state) {
|
|||
//version = getUInt16(tester->data);
|
||||
|
||||
state->initialized = 1;
|
||||
state->module = -1;
|
||||
state->_module = -1;
|
||||
state->resmgr = resmgr;
|
||||
state->current_res = NULL;
|
||||
state->record_count = 0;
|
||||
|
|
|
@ -43,7 +43,7 @@ struct IndexRecordCursor {
|
|||
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 int get_talker_t(IndexRecordCursor *cursor);
|
||||
typedef void get_text_t(IndexRecordCursor *cursor, char *buffer, int buffer_size);
|
||||
|
@ -60,23 +60,26 @@ struct MessageHandler {
|
|||
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;
|
||||
MessageHandler *handler;
|
||||
ResourceManager *resmgr;
|
||||
Resource *current_res;
|
||||
int module;
|
||||
int _module;
|
||||
int record_count;
|
||||
byte *index_records;
|
||||
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);
|
||||
|
||||
} // End of namespace Sci
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue