aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/game.cpp177
-rw-r--r--engines/sci/engine/kfile.cpp19
-rw-r--r--engines/sci/engine/savegame.cfsml8
-rw-r--r--engines/sci/engine/savegame.cpp122
-rw-r--r--engines/sci/engine/scriptdebug.cpp5
-rw-r--r--engines/sci/include/engine.h19
-rw-r--r--engines/sci/include/kernel.h2
-rw-r--r--engines/sci/sci.cpp6
8 files changed, 252 insertions, 106 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index 87dd1aa4f9..f76238ebce 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -266,8 +266,7 @@ static void _free_graphics_input(EngineState *s) {
s->dyn_views = NULL;
s->port = NULL;
- if (s->pics)
- free(s->pics);
+ free(s->pics);
s->pics = NULL;
}
@@ -445,6 +444,164 @@ static int create_class_table_sci0(EngineState *s) {
return 0;
}
+EngineState::EngineState() {
+ savegame_version = 0;
+
+ widget_serial_counter = 0;
+
+ resource_dir = 0;
+ work_dir = 0;
+ resmgr = 0;
+
+ game_name = 0;
+ game_version = 0;
+
+ gfx_state = 0;
+ old_screen = 0;
+
+ memset(&sound, 0, sizeof(sound)); // FIXME: Remove this once/if we C++ify sfx_state_t
+ sfx_init_flags = 0;
+ sound_volume = 0;
+ sound_mute = 0;
+
+ restarting_flags = 0;
+ have_mouse_flag = 0;
+
+ pic_not_valid = 0;
+ pic_is_new = 0;
+ onscreen_console = 0;
+ osc_backup = 0;
+
+ pic_priority_table = 0;
+
+ status_bar_text = 0;
+
+ status_bar_foreground = 0;
+ status_bar_background = 0;
+
+ game_time = 0;
+
+ save_dir_copy = NULL_REG;
+ save_dir_edit_offset = 0;
+ save_dir_copy_buf = 0;
+
+ mouse_pointer_view = 0;
+ mouse_pointer_loop = 0;
+ mouse_pointer_cel = 0;
+ save_mouse_pointer_view = 0;
+ save_mouse_pointer_loop = 0;
+ save_mouse_pointer_cel = 0;
+
+ port_serial = 0;
+ port = 0;
+
+ memset(ega_colors, 0, sizeof(ega_colors));
+
+ visual = 0;
+
+ titlebar_port = 0;
+ wm_port = 0;
+ picture_port = 0;
+ iconbar_port = 0;
+
+ memset(&pic_visible_map, 0, sizeof(pic_visible_map)); // FIXME: Remove this once/if we C++ify gfx_map_mask_t
+ pic_animate = 0;
+
+ dyn_views_list_serial = 0;
+ dyn_views = 0;
+
+ drop_views_list_serial = 0;
+ drop_views = 0;
+
+ animation_delay = 0;
+ animation_granularity = 0;
+
+ menubar = 0;
+
+ priority_first = 0;
+ priority_last = 0;
+
+ pics_drawn_nr = 0;
+ pics_nr = 0;
+ pics = 0;
+
+ last_wait_time = 0;
+
+ version_lock_flag = 0;
+ version = 0;
+ max_version = 0;
+ min_version = 0;
+
+ kernel_opt_flags = 0;
+
+ _fileHandles.resize(5);
+
+ dirseeker = 0;
+
+ execution_stack = 0;
+ execution_stack_size = 0;
+ execution_stack_pos = 0;
+ execution_stack_base = 0;
+ execution_stack_pos_changed = 0;
+
+ r_acc = NULL_REG;
+ r_amp_rest = 0;
+ r_prev = NULL_REG;
+
+ stack_segment = 0;
+ stack_base = 0;
+ stack_top = 0;
+
+ parser_segment = 0;
+ parser_base = NULL_REG;
+ parser_event = NULL_REG;
+ script_000_segment = 0;
+ script_000 = 0;
+
+ parser_lastmatch_word = 0;
+ bp_list = 0;
+ have_bp = 0;
+ debug_mode = 0;
+ sys_strings_segment = 0;
+ sys_strings = 0;
+ parser_words = 0;
+ parser_words_nr = 0;
+ parser_suffices = 0;
+ parser_suffices_nr = 0;
+ parser_branches = 0;
+ parser_rules = 0;
+ parser_branches_nr = 0;
+ memset(parser_nodes, 0, sizeof(parser_nodes));
+
+ parser_valid = 0;
+
+ synonyms = 0;
+ synonyms_nr = 0;
+
+ game_obj = NULL_REG;
+
+ classtable_size = 0;
+ classtable = 0;
+
+ seg_manager = 0;
+ gc_countdown = 0;
+
+ selector_names_nr = 0;
+ selector_names = 0;
+ kernel_names_nr = 0;
+ kernel_names = 0;
+
+ kfunct_table = 0;
+ kfunct_nr = 0;
+
+ opcodes = 0;
+
+ memset(&selector_map, 0, sizeof(selector_map)); // FIXME: Remove this once/if we C++ify selector_map_t
+ port_ID = 0;
+
+ successor = 0;
+}
+
// Architectural stuff: Init/Unintialize engine
int script_init_engine(EngineState *s, sci_version_t version) {
int result;
@@ -514,10 +671,6 @@ int script_init_engine(EngineState *s, sci_version_t version) {
s->bp_list = NULL; // No breakpoints defined
s->have_bp = 0;
- s->file_handles_nr = 5;
- s->file_handles = (FILE**)sci_calloc(sizeof(FILE *), s->file_handles_nr);
- // Allocate memory for file handles
-
s->dirseeker = 0; // Used by FileIO for FIND_FIRST, FIND_NEXT
if (s->version >= SCI_VERSION_FTU_LOFS_ABSOLUTE &&
@@ -539,8 +692,6 @@ void script_set_gamestate_save_dir(EngineState *s, const char *path) {
}
void script_free_vm_memory(EngineState *s) {
- int i;
-
sciprintf("Freeing VM memory\n");
s->save_dir_copy_buf = NULL;
@@ -548,15 +699,7 @@ void script_free_vm_memory(EngineState *s) {
s->classtable = NULL;
// Close all opened file handles
- for (i = 1; i < s->file_handles_nr; i++)
- if (s->file_handles[i])
- fclose(s->file_handles[i]);
-
- free(s->file_handles);
- s->file_handles = NULL;
-
- // FIXME: file handles will NOT be closed under DOS. DJGPP generates an
- // exception fault whenever you try to close a never-opened file
+ s->_fileHandles.clear();
}
extern void free_kfunct_tables(EngineState *s);
diff --git a/engines/sci/engine/kfile.cpp b/engines/sci/engine/kfile.cpp
index e3adf7a9d5..ac14824fa3 100644
--- a/engines/sci/engine/kfile.cpp
+++ b/engines/sci/engine/kfile.cpp
@@ -150,7 +150,6 @@ static FILE *f_open_mirrored(EngineState *s, char *fname) {
#define _K_FILE_MODE_CREATE 2
void file_open(EngineState *s, char *filename, int mode) {
- int retval = 1; // Ignore file_handles[0]
FILE *file = NULL;
SCIkdebug(SCIkFILE, "Opening file %s with mode %d\n", filename, mode);
@@ -177,13 +176,15 @@ void file_open(EngineState *s, char *filename, int mode) {
return;
}
- while (s->file_handles[retval] && (retval < s->file_handles_nr))
+ uint retval = 1; // Ignore _fileHandles[0]
+ while ((retval < s->_fileHandles.size()) && s->_fileHandles[retval]._file)
retval++;
- if (retval == s->file_handles_nr) // Hit size limit => Allocate more space
- s->file_handles = (FILE**)sci_realloc(s->file_handles, sizeof(FILE *) * ++(s->file_handles_nr));
+ if (retval == s->_fileHandles.size()) { // Hit size limit => Allocate more space
+ s->_fileHandles.resize(s->_fileHandles.size() + 1);
+ }
- s->file_handles[retval] = file;
+ s->_fileHandles[retval]._file = file;
s->r_acc = make_reg(0, retval);
}
@@ -196,18 +197,18 @@ reg_t kFOpen(EngineState *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
}
-static FILE *getFileFromHandle(EngineState *s, int handle) {
+static FILE *getFileFromHandle(EngineState *s, uint handle) {
if (handle == 0) {
SCIkwarn(SCIkERROR, "Attempt to use file handle 0\n");
return 0;
}
- if ((handle >= s->file_handles_nr) || (s->file_handles[handle] == NULL)) {
+ if ((handle >= s->_fileHandles.size()) || (s->_fileHandles[handle]._file == NULL)) {
SCIkwarn(SCIkERROR, "Attempt to use invalid/unused file handle %d\n", handle);
return 0;
}
- return s->file_handles[handle];
+ return s->_fileHandles[handle]._file;
}
void file_close(EngineState *s, int handle) {
@@ -219,7 +220,7 @@ void file_close(EngineState *s, int handle) {
fclose(f);
- s->file_handles[handle] = NULL;
+ s->_fileHandles[handle]._file = NULL;
}
reg_t kFClose(EngineState *s, int funct_nr, int argc, reg_t *argv) {
diff --git a/engines/sci/engine/savegame.cfsml b/engines/sci/engine/savegame.cfsml
index b4b043ae6b..0c5189e55a 100644
--- a/engines/sci/engine/savegame.cfsml
+++ b/engines/sci/engine/savegame.cfsml
@@ -1023,9 +1023,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
}
*/
- retval = (EngineState *) sci_malloc(sizeof(EngineState));
-
- memset(retval, 0, sizeof(EngineState));
+ retval = new EngineState();
retval->savegame_version = -1;
_global_save_state = retval;
@@ -1096,10 +1094,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
// Time state:
retval->last_wait_time = g_system->getMillis();
- // File IO state:
- retval->file_handles_nr = 2;
- retval->file_handles = (FILE **)sci_calloc(2, sizeof(FILE *));
-
// static parser information:
retval->parser_rules = s->parser_rules;
retval->parser_words_nr = s->parser_words_nr;
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 881c13faf8..b52f4515ce 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -326,7 +326,7 @@ static char *_cfsml_unmangle_string(const char *s, unsigned int length) {
while ((source != end) && (c = *source++) && (c > 31)) {
if (c == '\\') { // Escaped character?
- c = *source++;
+ c = *source++;
if ((c != '\\') && (c != '"')) // Un-escape 0-31 only
c -= ('a' - 1);
}
@@ -606,7 +606,7 @@ _cfsml_read_sfx_state_t(Common::SeekableReadStream *fh, sfx_state_t* save_struc,
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -674,7 +674,7 @@ _cfsml_read_clone_entry_t(Common::SeekableReadStream *fh, clone_entry_t* save_st
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -771,7 +771,7 @@ _cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -860,10 +860,10 @@ _cfsml_read_object_t(Common::SeekableReadStream *fh, object_t* save_struc, const
_cfsml_error("Token expected by read_reg_t() for variables[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->variables_nr = max ; // Set array size accordingly
+ save_struc->variables_nr = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -962,7 +962,7 @@ _cfsml_read_menubar_t(Common::SeekableReadStream *fh, menubar_t* save_struc, con
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -1016,10 +1016,10 @@ _cfsml_read_menubar_t(Common::SeekableReadStream *fh, menubar_t* save_struc, con
_cfsml_error("Token expected by _cfsml_read_menu_t() for menus[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->menus_nr = max ; // Set array size accordingly
+ save_struc->menus_nr = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -1094,7 +1094,7 @@ _cfsml_read_list_entry_t(Common::SeekableReadStream *fh, list_entry_t* save_stru
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -1177,7 +1177,7 @@ _cfsml_read_int_hash_map_t(Common::SeekableReadStream *fh, int_hash_map_t* save_
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -1224,7 +1224,7 @@ _cfsml_read_int_hash_map_t(Common::SeekableReadStream *fh, int_hash_map_t* save_
_cfsml_error("Token expected by read_int_hash_map_node_tp() for nodes[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
} else
@@ -1312,7 +1312,7 @@ _cfsml_read_SegManager(Common::SeekableReadStream *fh, SegManager* save_struc, c
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -1373,10 +1373,10 @@ _cfsml_read_SegManager(Common::SeekableReadStream *fh, SegManager* save_struc, c
_cfsml_error("Token expected by read_mem_obj_tp() for heap[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->heap_size = max ; // Set array size accordingly
+ save_struc->heap_size = max ; // Set array size accordingly
} else
if (!strcmp(token, "heap_size")) {
#line 690 "engines/sci/engine/savegame.cfsml"
@@ -1506,7 +1506,7 @@ _cfsml_read_song_t(Common::SeekableReadStream *fh, song_t* save_struc, const cha
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -1661,7 +1661,7 @@ _cfsml_read_menu_item_t(Common::SeekableReadStream *fh, menu_item_t* save_struc,
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -1729,7 +1729,7 @@ _cfsml_read_menu_item_t(Common::SeekableReadStream *fh, menu_item_t* save_struc,
_cfsml_error("Token expected by _cfsml_read_byte() for said[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
} else
@@ -1829,7 +1829,7 @@ _cfsml_read_node_entry_t(Common::SeekableReadStream *fh, node_entry_t* save_stru
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -1943,7 +1943,7 @@ _cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -2011,10 +2011,10 @@ _cfsml_read_dynmem_t(Common::SeekableReadStream *fh, dynmem_t* save_struc, const
_cfsml_error("Token expected by _cfsml_read_byte() for buf[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->size = max ; // Set array size accordingly
+ save_struc->size = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -2076,7 +2076,7 @@ _cfsml_read_local_variables_t(Common::SeekableReadStream *fh, local_variables_t*
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -2144,10 +2144,10 @@ _cfsml_read_local_variables_t(Common::SeekableReadStream *fh, local_variables_t*
_cfsml_error("Token expected by read_reg_t() for locals[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->nr = max ; // Set array size accordingly
+ save_struc->nr = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -2215,7 +2215,7 @@ _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_stru
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -2297,10 +2297,10 @@ _cfsml_read_node_table_t(Common::SeekableReadStream *fh, node_table_t* save_stru
_cfsml_error("Token expected by _cfsml_read_node_entry_t() for table[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->entries_nr = max ; // Set array size accordingly
+ save_struc->entries_nr = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -2354,7 +2354,7 @@ _cfsml_read_sys_strings_t(Common::SeekableReadStream *fh, sys_strings_t* save_st
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -2394,7 +2394,7 @@ _cfsml_read_sys_strings_t(Common::SeekableReadStream *fh, sys_strings_t* save_st
_cfsml_error("Token expected by _cfsml_read_sys_string_t() for strings[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
} else
@@ -2477,7 +2477,7 @@ _cfsml_read_node_t(Common::SeekableReadStream *fh, node_t* save_struc, const cha
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -2585,7 +2585,7 @@ _cfsml_read_list_table_t(Common::SeekableReadStream *fh, list_table_t* save_stru
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -2667,10 +2667,10 @@ _cfsml_read_list_table_t(Common::SeekableReadStream *fh, list_table_t* save_stru
_cfsml_error("Token expected by _cfsml_read_list_entry_t() for table[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->entries_nr = max ; // Set array size accordingly
+ save_struc->entries_nr = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -2719,7 +2719,7 @@ _cfsml_read_class_t(Common::SeekableReadStream *fh, class_t* save_struc, const c
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -2880,7 +2880,7 @@ _cfsml_read_EngineState(Common::SeekableReadStream *fh, EngineState* save_struc,
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -2990,10 +2990,10 @@ _cfsml_read_EngineState(Common::SeekableReadStream *fh, EngineState* save_struc,
_cfsml_error("Token expected by _cfsml_read_class_t() for classtable[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->classtable_size = max ; // Set array size accordingly
+ save_struc->classtable_size = max ; // Set array size accordingly
} else
if (!strcmp(token, "sound")) {
#line 690 "engines/sci/engine/savegame.cfsml"
@@ -3061,7 +3061,7 @@ _cfsml_read_SavegameMetadata(Common::SeekableReadStream *fh, SavegameMetadata* s
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -3180,7 +3180,7 @@ _cfsml_read_menu_t(Common::SeekableReadStream *fh, menu_t* save_struc, const cha
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -3255,10 +3255,10 @@ _cfsml_read_menu_t(Common::SeekableReadStream *fh, menu_t* save_struc, const cha
_cfsml_error("Token expected by _cfsml_read_menu_item_t() for items[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->items_nr = max ; // Set array size accordingly
+ save_struc->items_nr = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -3326,7 +3326,7 @@ _cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_st
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -3408,10 +3408,10 @@ _cfsml_read_clone_table_t(Common::SeekableReadStream *fh, clone_table_t* save_st
_cfsml_error("Token expected by _cfsml_read_clone_entry_t() for table[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->entries_nr = max ; // Set array size accordingly
+ save_struc->entries_nr = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -3482,7 +3482,7 @@ _cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_struc, const c
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -3571,10 +3571,10 @@ _cfsml_read_clone_t(Common::SeekableReadStream *fh, clone_t* save_struc, const c
_cfsml_error("Token expected by read_reg_t() for variables[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->variables_nr = max ; // Set array size accordingly
+ save_struc->variables_nr = max ; // Set array size accordingly
} else
#line 699 "engines/sci/engine/savegame.cfsml"
{
@@ -3623,7 +3623,7 @@ _cfsml_read_list_t(Common::SeekableReadStream *fh, list_t* save_struc, const cha
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -3701,7 +3701,7 @@ _cfsml_read_sys_string_t(Common::SeekableReadStream *fh, sys_string_t* save_stru
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -3829,7 +3829,7 @@ _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const
return CFSML_FAILURE;
}
if (!assignment) {
- if (!strcmp(token, "}"))
+ if (!strcmp(token, "}"))
closed = 1;
else {
_cfsml_error("Expected assignment or closing braces in line %d\n", *line);
@@ -3953,10 +3953,10 @@ _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const
_cfsml_error("Token expected by _cfsml_read_object_t() for objects[i++] at line %d\n", *line);
return CFSML_FAILURE;
}
- } else
+ } else
done = 1;
} while (!done);
- save_struc->objects_allocated = max ; // Set array size accordingly
+ save_struc->objects_allocated = max ; // Set array size accordingly
} else
if (!strcmp(token, "locals_offset")) {
#line 690 "engines/sci/engine/savegame.cfsml"
@@ -3991,7 +3991,7 @@ _cfsml_read_script_t(Common::SeekableReadStream *fh, script_t* save_struc, const
// Auto-generated CFSML declaration and function block ends here
-// Auto-generation performed by cfsml.pl 0.8.2
+// Auto-generation performed by cfsml.pl 0.8.2
#line 447 "engines/sci/engine/savegame.cfsml"
void write_songlib_t(Common::WriteStream *fh, songlib_t *songlib) {
@@ -4974,9 +4974,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
}
*/
- retval = (EngineState *) sci_malloc(sizeof(EngineState));
-
- memset(retval, 0, sizeof(EngineState));
+ retval = new EngineState();
retval->savegame_version = -1;
_global_save_state = retval;
@@ -5014,7 +5012,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
}
}
// End of auto-generated CFSML data reader code
-#line 1038 "engines/sci/engine/savegame.cfsml"
+#line 1036 "engines/sci/engine/savegame.cfsml"
if ((meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION) ||
(meta->savegame_version > FREESCI_CURRENT_SAVEGAME_VERSION)) {
if (meta->savegame_version < FREESCI_MINIMUM_SAVEGAME_VERSION)
@@ -5066,7 +5064,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
}
}
// End of auto-generated CFSML data reader code
-#line 1061 "engines/sci/engine/savegame.cfsml"
+#line 1059 "engines/sci/engine/savegame.cfsml"
sfx_exit(&s->sound);
_gamestate_unfrob(retval);
@@ -5105,10 +5103,6 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
// Time state:
retval->last_wait_time = g_system->getMillis();
- // File IO state:
- retval->file_handles_nr = 2;
- retval->file_handles = (FILE **)sci_calloc(2, sizeof(FILE *));
-
// static parser information:
retval->parser_rules = s->parser_rules;
retval->parser_words_nr = s->parser_words_nr;
@@ -5190,7 +5184,7 @@ bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata*
}
}
// End of auto-generated CFSML data reader code
-#line 1156 "engines/sci/engine/savegame.cfsml"
+#line 1150 "engines/sci/engine/savegame.cfsml"
if (read_eof)
return false;
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index abaae46879..eaa39f777c 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -1049,7 +1049,6 @@ int c_parse(EngineState *s) {
int c_save_game(EngineState *s) {
int omit_check = cmd_params[0].str[0] == '_';
- int i;
if (!s) {
sciprintf("Not in debug state\n");
@@ -1058,8 +1057,8 @@ int c_save_game(EngineState *s) {
if (!omit_check) {
int result = 0;
- for (i = 0; i < s->file_handles_nr; i++)
- if (s->file_handles[i])
+ for (uint i = 0; i < s->_fileHandles.size(); i++)
+ if (s->_fileHandles[i]._file)
result++;
if (result) {
diff --git a/engines/sci/include/engine.h b/engines/sci/include/engine.h
index ec1f49b07e..2e29a0682a 100644
--- a/engines/sci/include/engine.h
+++ b/engines/sci/include/engine.h
@@ -27,6 +27,7 @@
#define _SCI_ENGINE_H
#include "common/scummsys.h"
+#include "common/array.h"
namespace Common {
class SeekableReadStream;
@@ -79,7 +80,22 @@ struct SavegameMetadata {
int savegame_time;
};
+class FileHandle {
+public:
+ FILE *_file;
+
+ FileHandle() : _file(0) {
+ }
+
+ ~FileHandle() {
+ if (_file)
+ fclose(_file);
+ }
+};
+
struct EngineState {
+ EngineState();
+
int savegame_version;
int widget_serial_counter; /* Used for savegames */
@@ -171,8 +187,7 @@ struct EngineState {
/* Kernel File IO stuff */
- int file_handles_nr; /* maximum numer of allowed file handles */
- FILE **file_handles; /* Array of file handles. Dynamically increased if required. */
+ Common::Array<FileHandle> _fileHandles; /* Array of file handles. Dynamically increased if required. */
DirSeeker *dirseeker;
diff --git a/engines/sci/include/kernel.h b/engines/sci/include/kernel.h
index c5d6452610..608a2b7b7c 100644
--- a/engines/sci/include/kernel.h
+++ b/engines/sci/include/kernel.h
@@ -172,7 +172,7 @@ byte *kernel_dereference_bulk_pointer(EngineState *s, reg_t pointer, int entries
int kernel_oops(EngineState *s, const char *file, int line, const char *reason);
/* Halts script execution and informs the user about an internal kernel error or failed assertion
-** Paramters: (EngineState *) s: The state to use
+** Parameters: (EngineState *) s: The state to use
** (const char *) file: The file the oops occured in
** (int) line: The line the oops occured in
** (const char *) reason: Reason for the kernel oops
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index 4d5a59343a..9fc08c9cd0 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -232,8 +232,7 @@ Common::Error SciEngine::go() {
map_MIDI_instruments(_resmgr);
#endif
- EngineState* gamestate = (EngineState *) sci_malloc(sizeof(EngineState));
- memset(gamestate, 0, sizeof(EngineState));
+ EngineState* gamestate = new EngineState();
gamestate->resmgr = _resmgr;
gamestate->gfx_state = NULL;
@@ -313,7 +312,8 @@ Common::Error SciEngine::go() {
script_free_engine(gamestate); // Uninitialize game state
script_free_breakpoints(gamestate);
free(gamestate->work_dir);
- free(gamestate);
+
+ delete gamestate;
delete _resmgr;