[Scummvm-cvs-logs] SF.net SVN: scummvm:[40740] scummvm/trunk/engines/sci
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed May 20 19:52:33 CEST 2009
Revision: 40740
http://scummvm.svn.sourceforge.net/scummvm/?rev=40740&view=rev
Author: fingolfin
Date: 2009-05-20 17:52:33 +0000 (Wed, 20 May 2009)
Log Message:
-----------
SCI: Changed EngineState::opcodes to a Common::Array (maybe we shold just remove the relevant code completely, though, it seems useless, esp. as long as we hardcode the way we interpret every opcode
Modified Paths:
--------------
scummvm/trunk/engines/sci/engine/game.cpp
scummvm/trunk/engines/sci/engine/savegame.cpp
scummvm/trunk/engines/sci/engine/scriptdebug.cpp
scummvm/trunk/engines/sci/engine/state.cpp
scummvm/trunk/engines/sci/engine/state.h
scummvm/trunk/engines/sci/vocab_debug.cpp
scummvm/trunk/engines/sci/vocabulary.h
Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp 2009-05-20 17:52:12 UTC (rev 40739)
+++ scummvm/trunk/engines/sci/engine/game.cpp 2009-05-20 17:52:33 UTC (rev 40740)
@@ -53,7 +53,7 @@
s->parser_rules = NULL;
}
- s->opcodes = vocabulary_get_opcodes(s->resmgr);
+ vocabulary_get_opcodes(s->resmgr, s->_opcodes);
if (!vocabulary_get_snames(s->resmgr, (s->flags & GF_SCI0_OLD), s->_selectorNames)) {
sciprintf("_init_vocabulary(): Could not retrieve selector names (vocab.997)!\n");
@@ -500,8 +500,7 @@
s->_selectorNames.clear();
s->_kernelNames.clear();
- vocabulary_free_opcodes(s->opcodes);
- s->opcodes = NULL;
+ s->_opcodes.clear();
}
void script_free_breakpoints(EngineState *s) {
Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp 2009-05-20 17:52:12 UTC (rev 40739)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp 2009-05-20 17:52:33 UTC (rev 40740)
@@ -834,7 +834,7 @@
retval->_selectorNames = s->_selectorNames;
retval->_kernelNames = s->_kernelNames;
retval->_kfuncTable = s->_kfuncTable;
- retval->opcodes = s->opcodes;
+ retval->_opcodes = s->_opcodes;
memcpy(&(retval->selector_map), &(s->selector_map), sizeof(selector_map_t));
Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp 2009-05-20 17:52:12 UTC (rev 40739)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp 2009-05-20 17:52:33 UTC (rev 40740)
@@ -1302,7 +1302,7 @@
if (print_bw_tag)
sciprintf("[%c] ", opsize ? 'B' : 'W');
- sciprintf("%s", s->opcodes[opcode].name);
+ sciprintf("%s", s->_opcodes[opcode].name.c_str());
i = 0;
while (g_opcode_formats[opcode][i]) {
Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp 2009-05-20 17:52:12 UTC (rev 40739)
+++ scummvm/trunk/engines/sci/engine/state.cpp 2009-05-20 17:52:33 UTC (rev 40740)
@@ -136,8 +136,6 @@
seg_manager = 0;
gc_countdown = 0;
- opcodes = 0;
-
memset(&selector_map, 0, sizeof(selector_map)); // FIXME: Remove this once/if we C++ify selector_map_t
successor = 0;
Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h 2009-05-20 17:52:12 UTC (rev 40739)
+++ scummvm/trunk/engines/sci/engine/state.h 2009-05-20 17:52:33 UTC (rev 40740)
@@ -263,7 +263,7 @@
Common::Array<kfunct_sig_pair_t> _kfuncTable; /**< Table of kernel functions */
- opcode *opcodes;
+ Common::Array<opcode> _opcodes;
selector_map_t selector_map; /**< Shortcut list for important selectors */
Modified: scummvm/trunk/engines/sci/vocab_debug.cpp
===================================================================
--- scummvm/trunk/engines/sci/vocab_debug.cpp 2009-05-20 17:52:12 UTC (rev 40739)
+++ scummvm/trunk/engines/sci/vocab_debug.cpp 2009-05-20 17:52:33 UTC (rev 40740)
@@ -354,53 +354,38 @@
return -1;
}
-opcode* vocabulary_get_opcodes(ResourceManager *resmgr) {
- opcode* o;
+void vocabulary_get_opcodes(ResourceManager *resmgr, Common::Array<opcode> &o) {
int count, i = 0;
Resource* r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_OPCODES, 0);
+ o.clear();
+
// if the resource couldn't be loaded, leave
if (r == NULL) {
- fprintf(stderr, "unable to load vocab.%03d\n", VOCAB_RESOURCE_OPCODES);
- return NULL;
+ warning("unable to load vocab.%03d", VOCAB_RESOURCE_OPCODES);
+ return;
}
count = READ_LE_UINT16(r->data);
- o = (opcode*)malloc(sizeof(opcode) * 256);
+ o.resize(256);
for (i = 0; i < count; i++) {
int offset = READ_LE_UINT16(r->data + 2 + i * 2);
int len = READ_LE_UINT16(r->data + offset) - 2;
o[i].type = READ_LE_UINT16(r->data + offset + 2);
o[i].number = i;
- o[i].name = (char *)malloc(len + 1);
- memcpy(o[i].name, r->data + offset + 4, len);
- o[i].name[len] = '\0';
-#ifdef VOCABULARY_DEBUG
- printf("Opcode %02X: %s, %d\n", i, o[i].name, o[i].type);
+ o[i].name = Common::String((char *)r->data + offset + 4, len);
+#if 1 //def VOCABULARY_DEBUG
+ printf("Opcode %02X: %s, %d\n", i, o[i].name.c_str(), o[i].type);
#endif
}
for (i = count; i < 256; i++) {
o[i].type = 0;
o[i].number = i;
- o[i].name = (char *)malloc(strlen("undefined") + 1);
- strcpy(o[i].name, "undefined");
+ o[i].name = "undefined";
}
- return o;
}
-void vocabulary_free_opcodes(opcode *opcodes) {
- int i;
- if (!opcodes)
- return;
-
- for (i = 0; i < 256; i++) {
- if (opcodes[i].name)
- free(opcodes[i].name);
- }
- free(opcodes);
-}
-
// Alternative kernel func names retriever. Required for KQ1/SCI (at least).
static void _vocabulary_get_knames0alt(const Resource *r, Common::StringList &names) {
uint idx = 0;
Modified: scummvm/trunk/engines/sci/vocabulary.h
===================================================================
--- scummvm/trunk/engines/sci/vocabulary.h 2009-05-20 17:52:12 UTC (rev 40739)
+++ scummvm/trunk/engines/sci/vocabulary.h 2009-05-20 17:52:33 UTC (rev 40740)
@@ -49,7 +49,7 @@
struct opcode {
int type;
int number;
- char* name;
+ Common::String name;
};
#define VOCAB_RESOURCE_OPCODES 998
@@ -199,15 +199,10 @@
/**
- * Returns a null terminated array of opcodes.
+ * Obtain the list of opcodes.
*/
-opcode *vocabulary_get_opcodes(ResourceManager *resmgr);
+void vocabulary_get_opcodes(ResourceManager *resmgr, Common::Array<opcode> &opcodes);
-void vocabulary_free_opcodes(opcode *opcodes);
-/* Frees a previously allocated list of opcodes
-** Parameters: (opcode *) opcodes: Opcodes to free
-*/
-
/**
* Fills a StringList with kernel function names.
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list