diff options
author | Greg Frieger | 2009-02-28 20:45:36 +0000 |
---|---|---|
committer | Greg Frieger | 2009-02-28 20:45:36 +0000 |
commit | 4dd1b7dad55333fdbfefb6c1ea7acb55a5127863 (patch) | |
tree | 07c7b74de7e3f50273dc53cc8927e90075f0ce4c | |
parent | 460131f5d35fffba4126cdf4ea24f2f32cfebc25 (diff) | |
download | scummvm-rg350-4dd1b7dad55333fdbfefb6c1ea7acb55a5127863.tar.gz scummvm-rg350-4dd1b7dad55333fdbfefb6c1ea7acb55a5127863.tar.bz2 scummvm-rg350-4dd1b7dad55333fdbfefb6c1ea7acb55a5127863.zip |
Turned ResourceManager into a class, along with all related functions
svn-id: r38978
24 files changed, 430 insertions, 464 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index fbccc9a7cc..9d5f20043b 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -142,7 +142,7 @@ int _reset_graphics_input(EngineState *s) { file.close(); _sci1_alloc_system_colors(s); } else { - resource = scir_find_resource(s->resmgr, sci_palette, 999, 1); + resource = s->resmgr->findResource(sci_palette, 999, 1); if (resource) { if (s->version < SCI_VERSION(1, 001, 000)) s->gfx_state->resstate->static_palette = gfxr_read_pal1(999, &s->gfx_state->resstate->static_palette_entries, @@ -151,7 +151,7 @@ int _reset_graphics_input(EngineState *s) { s->gfx_state->resstate->static_palette = gfxr_read_pal11(999, &s->gfx_state->resstate->static_palette_entries, resource->data, resource->size); _sci1_alloc_system_colors(s); - scir_unlock_resource(s->resmgr, resource, sci_palette, 999); + s->resmgr->unlockResource(resource, sci_palette, 999); } else { sciprintf("Couldn't find the default palette!\n"); } @@ -184,7 +184,7 @@ int _reset_graphics_input(EngineState *s) { font_nr = -1; do { - resource = scir_test_resource(s->resmgr, sci_font, ++font_nr); + resource = s->resmgr->testResource(sci_font, ++font_nr); } while ((!resource) && (font_nr < sci_max_resource_nr[s->resmgr->sci_version])); if (!resource) { @@ -295,7 +295,7 @@ int test_cursor_style(EngineState *s) { int ok = 0; do { - ok |= scir_test_resource(s->resmgr, sci_cursor, resource_nr++) != NULL; + ok |= s->resmgr->testResource(sci_cursor, resource_nr++) != NULL; } while (resource_nr < 1000 && !ok); return ok; @@ -307,7 +307,7 @@ int create_class_table_sci11(EngineState *s) { char *seeker_ptr; int classnr; - resource_t *vocab996 = scir_find_resource(s->resmgr, sci_vocab, 996, 1); + resource_t *vocab996 = s->resmgr->findResource(sci_vocab, 996, 1); if (!vocab996) s->classtable_size = 20; @@ -317,7 +317,7 @@ int create_class_table_sci11(EngineState *s) { s->classtable = (Class*)sci_calloc(sizeof(Class), s->classtable_size); for (scriptnr = 0; scriptnr < 1000; scriptnr++) { - resource_t *heap = scir_find_resource(s->resmgr, sci_heap, scriptnr, 0); + resource_t *heap = s->resmgr->findResource(sci_heap, scriptnr, 0); if (heap) { int global_vars = getUInt16(heap->data + 2); @@ -362,7 +362,7 @@ static int create_class_table_sci0(EngineState *s) { int classnr; int magic_offset; // For strange scripts in older SCI versions - resource_t *vocab996 = scir_find_resource(s->resmgr, sci_vocab, 996, 1); + resource_t *vocab996 = s->resmgr->findResource(sci_vocab, 996, 1); if (!vocab996) s->classtable_size = 20; @@ -373,7 +373,7 @@ static int create_class_table_sci0(EngineState *s) { for (scriptnr = 0; scriptnr < 1000; scriptnr++) { int objtype = 0; - resource_t *script = scir_find_resource(s->resmgr, sci_script, scriptnr, 0); + resource_t *script = s->resmgr->findResource(sci_script, scriptnr, 0); if (script) { if (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) @@ -435,7 +435,7 @@ static int create_class_table_sci0(EngineState *s) { } } - scir_unlock_resource(s->resmgr, vocab996, sci_vocab, 996); + s->resmgr->unlockResource(vocab996, sci_vocab, 996); vocab996 = NULL; return 0; } diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp index faa4801ed9..71c02e172e 100644 --- a/engines/sci/engine/kmenu.cpp +++ b/engines/sci/engine/kmenu.cpp @@ -210,7 +210,7 @@ void about_freesci(EngineState *s) { i = 999; while (!bodyfont_res && (i > -1)) - bodyfont_res = scir_test_resource(s->resmgr, sci_font, i--); + bodyfont_res = s->resmgr->testResource(sci_font, i--); if (i == -1) { sciprintf("Sorry, couldn't find a font...\n"); diff --git a/engines/sci/engine/kscripts.cpp b/engines/sci/engine/kscripts.cpp index 805a979701..f334bfddf8 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -133,11 +133,11 @@ reg_t kLock(EngineState *s, int funct_nr, int argc, reg_t *argv) { switch (state) { case 1 : - scir_find_resource(s->resmgr, restype, resnr, 1); + s->resmgr->findResource(restype, resnr, 1); break; case 0 : - which = scir_find_resource(s->resmgr, restype, resnr, 0); - scir_unlock_resource(s->resmgr, which, resnr, restype); + which = s->resmgr->findResource(restype, resnr, 0); + s->resmgr->unlockResource(which, resnr, restype); break; } return s->r_acc; diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index 3a60f77fff..3aec1add7d 100644 --- a/engines/sci/engine/ksound.cpp +++ b/engines/sci/engine/ksound.cpp @@ -93,7 +93,7 @@ namespace Sci { static void script_set_priority(EngineState *s, reg_t obj, int priority) { int song_nr = GET_SEL32V(obj, number); - resource_t *song = scir_find_resource(s->resmgr, sci_sound, song_nr, 0); + resource_t *song = s->resmgr->findResource(sci_sound, song_nr, 0); int flags = GET_SEL32V(obj, flags); if (priority == -1) { @@ -110,7 +110,7 @@ static void script_set_priority(EngineState *s, reg_t obj, int priority) { } song_iterator_t *build_iterator(EngineState *s, int song_nr, int type, songit_id_t id) { - resource_t *song = scir_find_resource(s->resmgr, sci_sound, song_nr, 0); + resource_t *song = s->resmgr->findResource(sci_sound, song_nr, 0); if (!song) return NULL; @@ -486,7 +486,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { //int vol = GET_SEL32V(obj, vol); //int pri = GET_SEL32V(obj, pri); - if (obj.segment && (scir_test_resource(s->resmgr, sci_sound, number))) { + if (obj.segment && (s->resmgr->testResource(sci_sound, number))) { sciprintf("Initializing song number %d\n", number); SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound, build_iterator(s, number, @@ -802,7 +802,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { } if (!GET_SEL32V(obj, nodePtr) && obj.segment) { - if (!scir_test_resource(s->resmgr, sci_sound, number)) { + if (!s->resmgr->testResource(sci_sound, number)) { sciprintf("Could not open song number %d\n", number); return NULL_REG; } @@ -839,7 +839,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { sfx_remove_song(&s->sound, handle); } - if (obj.segment && (scir_test_resource(s->resmgr, sci_sound, number))) { + if (obj.segment && (s->resmgr->testResource(sci_sound, number))) { sciprintf("Initializing song number %d\n", number); SCRIPT_ASSERT_ZERO(sfx_add_song(&s->sound, build_iterator(s, number, diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index ee1d02616e..ad02576f99 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -48,7 +48,7 @@ char *kernel_lookup_text(EngineState *s, reg_t address, int index) { else { int textlen; int _index = index; - textres = scir_find_resource(s->resmgr, sci_text, address.offset, 0); + textres = s->resmgr->findResource(sci_text, address.offset, 0); if (!textres) { SCIkwarn(SCIkERROR, "text.%03d not found\n", address); @@ -709,7 +709,7 @@ reg_t kStrLen(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kGetFarText(EngineState *s, int funct_nr, int argc, reg_t *argv) { - resource_t *textres = scir_find_resource(s->resmgr, sci_text, UKPV(0), 0); + resource_t *textres = s->resmgr->findResource(sci_text, UKPV(0), 0); char *seeker; int counter = UKPV(1); diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index a8f8eed6ec..4be5f10042 100644 --- a/engines/sci/engine/message.cpp +++ b/engines/sci/engine/message.cpp @@ -161,7 +161,7 @@ int message_state_load_res(MessageState *state, int module) { return 1; state->module = module; - state->current_res = scir_find_resource(state->resmgr, sci_message, module, 0); + state->current_res = state->resmgr->findResource(sci_message, module, 0); if (state->current_res == NULL || state->current_res->data == NULL) { sciprintf("Message subsystem: Failed to load %d.MSG\n", module); @@ -186,7 +186,7 @@ static MessageHandler fixed_handler = { }; void message_state_initialize(ResourceManager *resmgr, MessageState *state) { - //resource_t *tester = scir_find_resource(resmgr, sci_message, 0, 0); + //resource_t *tester = resmgr->findResource(sci_message, 0, 0); //int version; //if (tester == NULL) diff --git a/engines/sci/engine/savegame.cfsml b/engines/sci/engine/savegame.cfsml index 66eec5aed9..9d8833715e 100644 --- a/engines/sci/engine/savegame.cfsml +++ b/engines/sci/engine/savegame.cfsml @@ -851,9 +851,9 @@ static void load_script(EngineState *s, SegmentId seg) { scr->buf = (byte *)malloc(scr->buf_size); - script = scir_find_resource(s->resmgr, sci_script, scr->nr, 0); + script = s->resmgr->findResource(sci_script, scr->nr, 0); if (s->version >= SCI_VERSION(1,001,000)) - heap = scir_find_resource(s->resmgr, sci_heap, scr->nr, 0); + heap = s->resmgr->findResource(sci_heap, scr->nr, 0); switch (s->seg_manager->isSci1_1) { case 0 : diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index c6d2086436..3eaadf4c3b 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -4947,9 +4947,9 @@ static void load_script(EngineState *s, SegmentId seg) { scr->buf = (byte *)malloc(scr->buf_size); - script = scir_find_resource(s->resmgr, sci_script, scr->nr, 0); + script = s->resmgr->findResource(sci_script, scr->nr, 0); if (s->version >= SCI_VERSION(1,001,000)) - heap = scir_find_resource(s->resmgr, sci_heap, scr->nr, 0); + heap = s->resmgr->findResource(sci_heap, scr->nr, 0); switch (s->seg_manager->isSci1_1) { case 0 : diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h index fcc2f843f9..2a882cbb19 100644 --- a/engines/sci/engine/script.h +++ b/engines/sci/engine/script.h @@ -31,7 +31,7 @@ namespace Sci { struct EngineState; -struct ResourceManager; +class ResourceManager; /*#define SCRIPT_DEBUG */ diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp index 68146afc24..a8c79bd962 100644 --- a/engines/sci/engine/scriptconsole.cpp +++ b/engines/sci/engine/scriptconsole.cpp @@ -841,7 +841,7 @@ static int c_list(EngineState *s) { sciprintf("Unknown resource type: '%s'\n", cmd_params[0].str); else { for (i = 0; i < sci_max_resource_nr[s->resmgr->sci_version]; i++) - if (scir_test_resource(s->resmgr, res, i)) + if (s->resmgr->testResource(res, i)) sciprintf("%s.%03d\n", sci_resource_types[res], i); } } @@ -913,7 +913,7 @@ static int c_size(EngineState *s) { if (res == -1) sciprintf("Resource type '%s' is not valid\n", cmd_params[0].str); else { - resource_t *resource = scir_find_resource(s->resmgr, res, cmd_params[1].val, 0); + resource_t *resource = s->resmgr->findResource(res, cmd_params[1].val, 0); if (resource) { sciprintf("Size: %d\n", resource->size); } else @@ -929,7 +929,7 @@ static int c_dump(EngineState *s) { if (res == -1) sciprintf("Resource type '%s' is not valid\n", cmd_params[0].str); else { - resource_t *resource = scir_find_resource(s->resmgr, res, cmd_params[1].val, 0); + resource_t *resource = s->resmgr->findResource(res, cmd_params[1].val, 0); if (resource) sci_hexdump(resource->data, resource->size, 0); else @@ -975,7 +975,7 @@ static int c_hexgrep(EngineState *s) { } for (; resnr <= resmax; resnr++) - if ((script = scir_find_resource(s->resmgr, restype, resnr, 0))) { + if ((script = s->resmgr->findResource(restype, resnr, 0))) { unsigned int seeker = 0, seekerold = 0; int comppos = 0; int output_script_name = 0; diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 9307bc0b09..190a054e43 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -245,7 +245,7 @@ static void sci01_song_header_dump(byte *data, int size) { #undef SONGDATA int c_sfx_01_header(EngineState *s) { - resource_t *song = scir_find_resource(s->resmgr, sci_sound, cmd_params[0].val, 0); + resource_t *song = s->resmgr->findResource(sci_sound, cmd_params[0].val, 0); if (!song) { sciprintf("Doesn't exist\n"); @@ -258,7 +258,7 @@ int c_sfx_01_header(EngineState *s) { } int c_sfx_01_track(EngineState *s) { - resource_t *song = scir_find_resource(s->resmgr, sci_sound, cmd_params[0].val, 0); + resource_t *song = s->resmgr->findResource(sci_sound, cmd_params[0].val, 0); int offset = cmd_params[1].val; @@ -2406,7 +2406,7 @@ int c_simkey(EngineState *s) { } static int c_is_sample(EngineState *s) { - resource_t *song = scir_find_resource(s->resmgr, sci_sound, cmd_params[0].val, 0); + resource_t *song = s->resmgr->findResource(sci_sound, cmd_params[0].val, 0); song_iterator_t *songit; sfx_pcm_feed_t *data; diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index ec551fd672..949b04928b 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -152,8 +152,8 @@ MemObject *SegManager::allocateScript(EngineState *s, int script_nr, int* seg_id } void SegManager::setScriptSize(MemObject *mem, EngineState *s, int script_nr) { - resource_t *script = scir_find_resource(s->resmgr, sci_script, script_nr, 0); - resource_t *heap = scir_find_resource(s->resmgr, sci_heap, script_nr, 0); + resource_t *script = s->resmgr->findResource(sci_script, script_nr, 0); + resource_t *heap = s->resmgr->findResource(sci_heap, script_nr, 0); mem->data.script.script_size = script->size; mem->data.script.heap_size = 0; // Set later diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 16f33bb27f..b35736cd4a 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -1595,13 +1595,13 @@ void script_detect_versions(EngineState *s) { int c; resource_t *script = {0}; - if (scir_find_resource(s->resmgr, sci_heap, 0, 0)) { + if (s->resmgr->findResource(sci_heap, 0, 0)) { version_require_later_than(s, SCI_VERSION(1, 001, 000)); return; } for (c = 0; c < 1000; c++) { - if ((script = scir_find_resource(s->resmgr, sci_script, c, 0))) { + if ((script = s->resmgr->findResource(sci_script, c, 0))) { int id = getInt16(script->data); @@ -1679,9 +1679,9 @@ int script_instantiate_common(EngineState *s, int script_nr, resource_t **script *was_new = 1; - *script = scir_find_resource(s->resmgr, sci_script, script_nr, 0); + *script = s->resmgr->findResource(sci_script, script_nr, 0); if (s->version >= SCI_VERSION(1, 001, 000)) - *heap = scir_find_resource(s->resmgr, sci_heap, script_nr, 0); + *heap = s->resmgr->findResource(sci_heap, script_nr, 0); if (!*script || (s->version >= SCI_VERSION(1, 001, 000) && !heap)) { sciprintf("Script 0x%x requested but not found\n", script_nr); diff --git a/engines/sci/gfx/resource/sci_resmgr.cpp b/engines/sci/gfx/resource/sci_resmgr.cpp index a3817a4947..b77ff26be1 100644 --- a/engines/sci/gfx/resource/sci_resmgr.cpp +++ b/engines/sci/gfx/resource/sci_resmgr.cpp @@ -71,7 +71,7 @@ void gfxr_interpreter_clear_pic(int version, gfxr_pic_t *pic, void *internal) { int gfxr_interpreter_calculate_pic(gfx_resstate_t *state, gfxr_pic_t *scaled_pic, gfxr_pic_t *unscaled_pic, int flags, int default_palette, int nr, void *internal) { ResourceManager *resmgr = (ResourceManager *)state->misc_payload; - resource_t *res = scir_find_resource(resmgr, sci_pic, nr, 0); + resource_t *res = resmgr->findResource(sci_pic, nr, 0); int need_unscaled = unscaled_pic != NULL; gfxr_pic0_params_t style, basic_style; @@ -149,7 +149,7 @@ gfxr_view_t *gfxr_draw_view11(int id, byte *resource, int size); gfxr_view_t *gfxr_interpreter_get_view(gfx_resstate_t *state, int nr, void *internal, int palette) { ResourceManager *resmgr = (ResourceManager *) state->misc_payload; - resource_t *res = scir_find_resource(resmgr, sci_view, nr, 0); + resource_t *res = resmgr->findResource(sci_view, nr, 0); int resid = GFXR_RES_ID(GFX_RESOURCE_TYPE_VIEW, nr); gfxr_view_t *result = 0; @@ -188,7 +188,7 @@ gfxr_view_t *gfxr_interpreter_get_view(gfx_resstate_t *state, int nr, void *inte gfx_bitmap_font_t *gfxr_interpreter_get_font(gfx_resstate_t *state, int nr, void *internal) { ResourceManager *resmgr = (ResourceManager *)state->misc_payload; - resource_t *res = scir_find_resource(resmgr, sci_font, nr, 0); + resource_t *res = resmgr->findResource(sci_font, nr, 0); if (!res || !res->data) return NULL; @@ -197,7 +197,7 @@ gfx_bitmap_font_t *gfxr_interpreter_get_font(gfx_resstate_t *state, int nr, void gfx_pixmap_t *gfxr_interpreter_get_cursor(gfx_resstate_t *state, int nr, void *internal) { ResourceManager *resmgr = (ResourceManager *) state->misc_payload; - resource_t *res = scir_find_resource(resmgr, sci_cursor, nr, 0); + resource_t *res = resmgr->findResource(sci_cursor, nr, 0); int resid = GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, nr); if (!res || !res->data) @@ -247,7 +247,7 @@ int *gfxr_interpreter_get_resources(gfx_resstate_t *state, gfx_resource_type_t t resources = (int *)sci_malloc(sizeof(int) * top); for (i = 0; i < top; i++) - if (scir_test_resource(resmgr, restype, i)) + if (resmgr->testResource(restype, i)) resources[count++] = i; *entries_nr = count; @@ -270,7 +270,7 @@ gfx_pixmap_color_t *gfxr_interpreter_get_palette(gfx_resstate_t *state, int vers if (version < SCI_VERSION_01_VGA) return NULL; - res = scir_find_resource(resmgr, sci_palette, nr, 0); + res = resmgr->findResource(sci_palette, nr, 0); if (!res || !res->data) return NULL; diff --git a/engines/sci/scicore/resource.cpp b/engines/sci/scicore/resource.cpp index f68b50ef17..88efb1a4ce 100644 --- a/engines/sci/scicore/resource.cpp +++ b/engines/sci/scicore/resource.cpp @@ -25,8 +25,6 @@ // Resource library -#include "common/archive.h" -#include "common/file.h" #include "common/util.h" #include "sci/tools.h" @@ -126,7 +124,7 @@ int resourcecmp(const void *first, const void *second) { //-- Resmgr helper functions -- -void _scir_add_altsource(resource_t *res, ResourceSource *source, unsigned int file_offset) { +void ResourceManager::addAltSource(resource_t *res, ResourceSource *source, unsigned int file_offset) { resource_altsource_t *rsrc = (resource_altsource_t *)sci_malloc(sizeof(resource_altsource_t)); rsrc->next = res->alt_sources; @@ -135,7 +133,7 @@ void _scir_add_altsource(resource_t *res, ResourceSource *source, unsigned int f res->alt_sources = rsrc; } -resource_t *_scir_find_resource_unsorted(resource_t *res, int res_nr, int type, int number) { +resource_t *ResourceManager::findResourceUnsorted(resource_t *res, int res_nr, int type, int number) { int i; for (i = 0; i < res_nr; i++) if (res[i].number == number && res[i].type == type) @@ -145,12 +143,12 @@ resource_t *_scir_find_resource_unsorted(resource_t *res, int res_nr, int type, // Resource source list management -ResourceSource *scir_add_external_map(ResourceManager *mgr, const char *file_name) { +ResourceSource *ResourceManager::addExternalMap(const char *file_name) { ResourceSource *newsrc = new ResourceSource(); // Add the new source to the SLL of sources - newsrc->next = mgr->_sources; - mgr->_sources = newsrc; + newsrc->next = _sources; + _sources = newsrc; newsrc->source_type = RESSOURCE_TYPE_EXTERNAL_MAP; newsrc->location_name = file_name; @@ -160,12 +158,12 @@ ResourceSource *scir_add_external_map(ResourceManager *mgr, const char *file_nam return newsrc; } -ResourceSource *scir_add_volume(ResourceManager *mgr, ResourceSource *map, const char *filename, int number, int extended_addressing) { +ResourceSource *ResourceManager::addVolume(ResourceSource *map, const char *filename, int number, int extended_addressing) { ResourceSource *newsrc = new ResourceSource(); // Add the new source to the SLL of sources - newsrc->next = mgr->_sources; - mgr->_sources = newsrc; + newsrc->next = _sources; + _sources = newsrc; newsrc->source_type = RESSOURCE_TYPE_VOLUME; newsrc->scanned = false; @@ -176,12 +174,12 @@ ResourceSource *scir_add_volume(ResourceManager *mgr, ResourceSource *map, const return 0; } -ResourceSource *scir_add_patch_dir(ResourceManager *mgr, const char *dirname) { +ResourceSource *ResourceManager::addPatchDir(const char *dirname) { ResourceSource *newsrc = new ResourceSource(); // Add the new source to the SLL of sources - newsrc->next = mgr->_sources; - mgr->_sources = newsrc; + newsrc->next = _sources; + _sources = newsrc; newsrc->source_type = RESSOURCE_TYPE_DIRECTORY; newsrc->scanned = false; @@ -190,8 +188,8 @@ ResourceSource *scir_add_patch_dir(ResourceManager *mgr, const char *dirname) { return 0; } -ResourceSource *scir_get_volume(ResourceManager *mgr, ResourceSource *map, int volume_nr) { - ResourceSource *seeker = mgr->_sources; +ResourceSource *ResourceManager::getVolume(ResourceSource *map, int volume_nr) { + ResourceSource *seeker = _sources; while (seeker) { if (seeker->source_type == RESSOURCE_TYPE_VOLUME && seeker->associated_map == map && @@ -205,7 +203,7 @@ ResourceSource *scir_get_volume(ResourceManager *mgr, ResourceSource *map, int v // Resource manager constructors and operations -static void _scir_load_from_patch_file(Common::File &file, resource_t *res, char *filename) { +void ResourceManager::loadFromPatchFile(Common::File &file, resource_t *res, char *filename) { unsigned int really_read; res->data = (unsigned char *)sci_malloc(res->size); @@ -218,7 +216,7 @@ static void _scir_load_from_patch_file(Common::File &file, resource_t *res, char res->status = SCI_STATUS_ALLOCATED; } -static void _scir_load_resource(ResourceManager *mgr, resource_t *res, bool protect) { +void ResourceManager::loadResource(resource_t *res, bool protect) { char filename[MAXPATHLEN]; Common::File file; resource_t backup; @@ -227,12 +225,12 @@ static void _scir_load_resource(ResourceManager *mgr, resource_t *res, bool prot // First try lower-case name if (res->source->source_type == RESSOURCE_TYPE_DIRECTORY) { - if (!patch_sprintfers[mgr->sci_version]) { - error("Resource manager's SCI version (%d) has no patch file name printers", mgr->sci_version); + if (!patch_sprintfers[sci_version]) { + error("Resource manager's SCI version (%d) has no patch file name printers", sci_version); } // Get patch file name - patch_sprintfers[mgr->sci_version](filename, res); + patch_sprintfers[sci_version](filename, res); // FIXME: Instead of using SearchMan, maybe we should only search // a single dir specified by this RESSOURCE_TYPE_DIRECTORY ResourceSource? @@ -250,13 +248,13 @@ static void _scir_load_resource(ResourceManager *mgr, resource_t *res, bool prot file.seek(res->file_offset, SEEK_SET); if (res->source->source_type == RESSOURCE_TYPE_DIRECTORY) - _scir_load_from_patch_file(file, res, filename); - else if (!decompressors[mgr->sci_version]) { + loadFromPatchFile(file, res, filename); + else if (!decompressors[sci_version]) { // Check whether we support this at all - error("Resource manager's SCI version (%d) is invalid", mgr->sci_version); + error("Resource manager's SCI version (%d) is invalid", sci_version); } else { int error = // Decompress from regular resource file - decompressors[mgr->sci_version](res, file, mgr->sci_version); + decompressors[sci_version](res, file, sci_version); if (error) { sciprintf("Error %d occured while reading %s.%03d from resource file: %s\n", @@ -273,11 +271,11 @@ static void _scir_load_resource(ResourceManager *mgr, resource_t *res, bool prot } -resource_t *scir_test_resource(ResourceManager *mgr, int type, int number) { +resource_t *ResourceManager::testResource(int type, int number) { resource_t binseeker; binseeker.type = type; binseeker.number = number; - return (resource_t *)bsearch(&binseeker, mgr->_resources, mgr->_resourcesNr, sizeof(resource_t), resourcecmp); + return (resource_t *)bsearch(&binseeker, _resources, _resourcesNr, sizeof(resource_t), resourcecmp); } int sci0_get_compression_method(Common::ReadStream &stream); @@ -292,7 +290,7 @@ int sci_test_view_type(ResourceManager *mgr) { mgr->sci_version = SCI_VERSION_AUTODETECT; for (i = 0; i < 1000; i++) { - res = scir_test_resource(mgr, sci_view, i); + res = mgr->testResource(sci_view, i); if (!res) continue; @@ -317,7 +315,7 @@ int sci_test_view_type(ResourceManager *mgr) { // Try the same thing with pics for (i = 0; i < 1000; i++) { - res = scir_test_resource(mgr, sci_pic, i); + res = mgr->testResource(sci_pic, i); if (!res) continue; @@ -343,13 +341,13 @@ int sci_test_view_type(ResourceManager *mgr) { return mgr->sci_version; } -int scir_add_appropriate_sources(ResourceManager *mgr) { +int ResourceManager::addAppropriateSources() { //char path_separator; ResourceSource *map; if (!Common::File::exists("RESOURCE.MAP")) return 0; - map = scir_add_external_map(mgr, "RESOURCE.MAP"); + map = addExternalMap("RESOURCE.MAP"); Common::ArchiveMemberList files; SearchMan.listMatchingMembers(files, "RESOURCE.0??"); @@ -359,38 +357,37 @@ int scir_add_appropriate_sources(ResourceManager *mgr) { const char *dot = strrchr(name.c_str(), '.'); int number = atoi(dot + 1); - scir_add_volume(mgr, map, name.c_str(), number, 0); + addVolume(map, name.c_str(), number, 0); } - scir_add_patch_dir(mgr, ""); // FIXME: used to pass the 'current' instead of "" - + addPatchDir(""); // FIXME: used to pass the 'current' instead of "" return 1; } -static int _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, ResourceSource *source) { - int preset_version = mgr->sci_version; +int ResourceManager::scanNewSources(int *detected_version, ResourceSource *source) { + int preset_version = sci_version; int resource_error = 0; - int dummy = mgr->sci_version; + int dummy = sci_version; //resource_t **concat_ptr = &(mgr->_resources[mgr->_resourcesNr - 1].next); if (detected_version == NULL) detected_version = &dummy; - *detected_version = mgr->sci_version; + *detected_version = sci_version; if (source->next) - _scir_scan_new_sources(mgr, detected_version, source->next); + scanNewSources(detected_version, source->next); if (!source->scanned) { source->scanned = true; switch (source->source_type) { case RESSOURCE_TYPE_DIRECTORY: - if (mgr->sci_version <= SCI_VERSION_01) - sci0_read_resource_patches(source, &mgr->_resources, &mgr->_resourcesNr); + if (sci_version <= SCI_VERSION_01) + readResourcePatchesSCI0(source); else - sci1_read_resource_patches(source, &mgr->_resources, &mgr->_resourcesNr); + readResourcePatchesSCI1(source); break; case RESSOURCE_TYPE_EXTERNAL_MAP: if (preset_version <= SCI_VERSION_01_VGA_ODD /* || preset_version == SCI_VERSION_AUTODETECT -- subsumed by the above line */) { - resource_error = sci0_read_resource_map(mgr, source, &mgr->_resources, &mgr->_resourcesNr, detected_version); + resource_error = readResourceMapSCI0(source, detected_version); #if 0 if (resource_error >= SCI_ERROR_CRITICAL) { sciprintf("Resmgr: Error while loading resource map: %s\n", sci_error_types[resource_error]); @@ -415,8 +412,7 @@ static int _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, R if ((preset_version == SCI_VERSION_1_EARLY) || (preset_version == SCI_VERSION_1_LATE) || (preset_version == SCI_VERSION_1_1) || ((*detected_version == SCI_VERSION_AUTODETECT) && (preset_version == SCI_VERSION_AUTODETECT))) { - resource_error = sci1_read_resource_map(mgr, source, scir_get_volume(mgr, source, 0), - &mgr->_resources, &mgr->_resourcesNr, detected_version); + resource_error = readResourceMapSCI1(source, getVolume(source, 0), detected_version); if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND) { // FIXME: Try reading w/o resource.map resource_error = SCI_ERROR_NO_RESOURCE_FILES_FOUND; @@ -424,55 +420,48 @@ static int _scir_scan_new_sources(ResourceManager *mgr, int *detected_version, R if (resource_error == SCI_ERROR_NO_RESOURCE_FILES_FOUND) { // Initialize empty resource manager - mgr->_resourcesNr = 0; - mgr->_resources = 0; // FIXME: Was = (resource_t*)sci_malloc(1); + _resourcesNr = 0; + _resources = 0; // FIXME: Was = (resource_t*)sci_malloc(1); resource_error = 0; } } - mgr->sci_version = *detected_version; + sci_version = *detected_version; break; default: break; } - qsort(mgr->_resources, mgr->_resourcesNr, sizeof(resource_t), resourcecmp); // Sort resources + qsort(_resources, _resourcesNr, sizeof(resource_t), resourcecmp); // Sort resources } return resource_error; } -int scir_scan_new_sources(ResourceManager *mgr, int *detected_version) { - _scir_scan_new_sources(mgr, detected_version, mgr->_sources); - - return 0; -} - -static void _scir_free_resource_sources(ResourceSource *rss) { +void ResourceManager::freeResourceSources(ResourceSource *rss) { if (rss) { - _scir_free_resource_sources(rss->next); + freeResourceSources(rss->next); delete rss; } } ResourceManager::ResourceManager(int version, int maxMemory) { int resource_error = 0; - ResourceManager *mgr = this; int resmap_version = version; _maxMemory = maxMemory; - mgr->memory_locked = 0; - mgr->memory_lru = 0; + _memoryLocked = 0; + _memoryLRU = 0; _resources = NULL; _resourcesNr = 0; _sources = NULL; - mgr->sci_version = version; + sci_version = version; - mgr->lru_first = NULL; - mgr->lru_last = NULL; + lru_first = NULL; + lru_last = NULL; - scir_add_appropriate_sources(mgr); - scir_scan_new_sources(mgr, &resmap_version); + addAppropriateSources(); + scanNewSources(&resmap_version, _sources); if (!_resources || !_resourcesNr) { if (_resources) { @@ -480,7 +469,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) { _resources = NULL; } sciprintf("Resmgr: Could not retrieve a resource list!\n"); - _scir_free_resource_sources(mgr->_sources); + freeResourceSources(_sources); error("FIXME: Move this code to an init() method so that we can perform error handling"); // return NULL; } @@ -490,20 +479,20 @@ ResourceManager::ResourceManager(int version, int maxMemory) { if (version == SCI_VERSION_AUTODETECT) switch (resmap_version) { case SCI_VERSION_0: - if (scir_test_resource(mgr, sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) { - version = sci_test_view_type(mgr); + if (testResource(sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) { + version = sci_test_view_type(this); if (version == SCI_VERSION_01_VGA) { sciprintf("Resmgr: Detected KQ5 or similar\n"); } else { sciprintf("Resmgr: Detected SCI0\n"); version = SCI_VERSION_0; } - } else if (scir_test_resource(mgr, sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) { - version = sci_test_view_type(mgr); + } else if (testResource(sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) { + version = sci_test_view_type(this); if (version == SCI_VERSION_01_VGA) { sciprintf("Resmgr: Detected KQ5 or similar\n"); } else { - if (scir_test_resource(mgr, sci_vocab, 912)) { + if (testResource(sci_vocab, 912)) { sciprintf("Resmgr: Running KQ1 or similar, using SCI0 resource encoding\n"); version = SCI_VERSION_0; } else { @@ -512,7 +501,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) { } } } else { - version = sci_test_view_type(mgr); + version = sci_test_view_type(this); if (version == SCI_VERSION_01_VGA) { sciprintf("Resmgr: Detected KQ5 or similar\n"); } else { @@ -526,13 +515,13 @@ ResourceManager::ResourceManager(int version, int maxMemory) { sciprintf("Resmgr: Detected Jones/CD or similar\n"); break; case SCI_VERSION_1: { - resource_t *res = scir_test_resource(mgr, sci_script, 0); + resource_t *res = testResource(sci_script, 0); - mgr->sci_version = version = SCI_VERSION_1_EARLY; - _scir_load_resource(mgr, res, true); + sci_version = version = SCI_VERSION_1_EARLY; + loadResource(res, true); if (res->status == SCI_STATUS_NOMALLOC) - mgr->sci_version = version = SCI_VERSION_1_LATE; + sci_version = version = SCI_VERSION_1_LATE; break; } case SCI_VERSION_1_1: @@ -547,24 +536,24 @@ ResourceManager::ResourceManager(int version, int maxMemory) { qsort(_resources, _resourcesNr, sizeof(resource_t), resourcecmp); // Sort resources } - mgr->sci_version = version; + sci_version = version; } -static void _scir_free_altsources(resource_altsource_t *dynressrc) { +void ResourceManager::freeAltSources(resource_altsource_t *dynressrc) { if (dynressrc) { - _scir_free_altsources(dynressrc->next); + freeAltSources(dynressrc->next); free(dynressrc); } } -void _scir_free_resources(resource_t *resources, int _resourcesNr) { +void ResourceManager::freeResources(resource_t *resources, int _resourcesNr) { int i; for (i = 0; i < _resourcesNr; i++) { resource_t *res = resources + i; // FIXME: alt_sources->next may point to an invalid memory location - _scir_free_altsources(res->alt_sources); + freeAltSources(res->alt_sources); if (res->status != SCI_STATUS_NOMALLOC) free(res->data); @@ -574,18 +563,18 @@ void _scir_free_resources(resource_t *resources, int _resourcesNr) { } ResourceManager::~ResourceManager() { - _scir_free_resources(_resources, _resourcesNr); - _scir_free_resource_sources(_sources); + freeResources(_resources, _resourcesNr); + freeResourceSources(_sources); _resources = NULL; } -static void _scir_unalloc(resource_t *res) { +void ResourceManager::unalloc(resource_t *res) { free(res->data); res->data = NULL; res->status = SCI_STATUS_NOMALLOC; } -static void _scir_remove_from_lru(ResourceManager *mgr, resource_t *res) { +void ResourceManager::removeFromLRU(resource_t *res) { if (res->status != SCI_STATUS_ENQUEUED) { sciprintf("Resmgr: Oops: trying to remove resource that isn't enqueued\n"); return; @@ -595,45 +584,45 @@ static void _scir_remove_from_lru(ResourceManager *mgr, resource_t *res) { res->next->prev = res->prev; if (res->prev) res->prev->next = res->next; - if (mgr->lru_first == res) - mgr->lru_first = res->next; - if (mgr->lru_last == res) - mgr->lru_last = res->prev; + if (lru_first == res) + lru_first = res->next; + if (lru_last == res) + lru_last = res->prev; - mgr->memory_lru -= res->size; + _memoryLRU -= res->size; res->status = SCI_STATUS_ALLOCATED; } -static void _scir_add_to_lru(ResourceManager *mgr, resource_t *res) { +void ResourceManager::addToLRU(resource_t *res) { if (res->status != SCI_STATUS_ALLOCATED) { sciprintf("Resmgr: Oops: trying to enqueue resource with state %d\n", res->status); return; } res->prev = NULL; - res->next = mgr->lru_first; - mgr->lru_first = res; - if (!mgr->lru_last) - mgr->lru_last = res; + res->next = lru_first; + lru_first = res; + if (!lru_last) + lru_last = res; if (res->next) res->next->prev = res; - mgr->memory_lru += res->size; + _memoryLRU += res->size; #if (SCI_VERBOSE_RESMGR > 1) fprintf(stderr, "Adding %s.%03d (%d bytes) to lru control: %d bytes total\n", sci_resource_types[res->type], res->number, res->size, - mgr->memory_lru); + mgr->_memoryLRU); #endif res->status = SCI_STATUS_ENQUEUED; } -static void _scir_print_lru_list(ResourceManager *mgr) { +void ResourceManager::printLRU() { int mem = 0; int entries = 0; - resource_t *res = mgr->lru_first; + resource_t *res = lru_first; while (res) { fprintf(stderr, "\t%s.%03d: %d bytes\n", @@ -645,47 +634,47 @@ static void _scir_print_lru_list(ResourceManager *mgr) { } fprintf(stderr, "Total: %d entries, %d bytes (mgr says %d)\n", - entries, mem, mgr->memory_lru); + entries, mem, _memoryLRU); } -static void _scir_free_old_resources(ResourceManager *mgr, int last_invulnerable) { - while (mgr->_maxMemory < mgr->memory_lru && (!last_invulnerable || mgr->lru_first != mgr->lru_last)) { - resource_t *goner = mgr->lru_last; +void ResourceManager::freeOldResources(int last_invulnerable) { + while (_maxMemory < _memoryLRU && (!last_invulnerable || lru_first != lru_last)) { + resource_t *goner = lru_last; if (!goner) { fprintf(stderr, "Internal error: mgr->lru_last is NULL!\n"); - fprintf(stderr, "LRU-mem= %d\n", mgr->memory_lru); - fprintf(stderr, "lru_first = %p\n", (void *)mgr->lru_first); - _scir_print_lru_list(mgr); + fprintf(stderr, "LRU-mem= %d\n", _memoryLRU); + fprintf(stderr, "lru_first = %p\n", (void *)lru_first); + printLRU(); } - _scir_remove_from_lru(mgr, goner); - _scir_unalloc(goner); + removeFromLRU(goner); + unalloc(goner); #ifdef SCI_VERBOSE_RESMGR sciprintf("Resmgr-debug: LRU: Freeing %s.%03d (%d bytes)\n", sci_resource_types[goner->type], goner->number, goner->size); #endif } } -resource_t * scir_find_resource(ResourceManager *mgr, int type, int number, int lock) { +resource_t *ResourceManager::findResource(int type, int number, int lock) { resource_t *retval; - if (number >= sci_max_resource_nr[mgr->sci_version]) { - int modded_number = number % sci_max_resource_nr[mgr->sci_version]; + if (number >= sci_max_resource_nr[sci_version]) { + int modded_number = number % sci_max_resource_nr[sci_version]; sciprintf("[resmgr] Requested invalid resource %s.%d, mapped to %s.%d\n", sci_resource_types[type], number, sci_resource_types[type], modded_number); number = modded_number; } - retval = scir_test_resource(mgr, type, number); + retval = testResource(type, number); if (!retval) return NULL; if (!retval->status) - _scir_load_resource(mgr, retval, false); + loadResource(retval, false); else if (retval->status == SCI_STATUS_ENQUEUED) - _scir_remove_from_lru(mgr, retval); + removeFromLRU(retval); // Unless an error occured, the resource is now either // locked or allocated, but never queued or freed. @@ -693,17 +682,17 @@ resource_t * scir_find_resource(ResourceManager *mgr, int type, int number, int if (retval->status == SCI_STATUS_ALLOCATED) { retval->status = SCI_STATUS_LOCKED; retval->lockers = 0; - mgr->memory_locked += retval->size; + _memoryLocked += retval->size; } ++retval->lockers; } else if (retval->status != SCI_STATUS_LOCKED) { // Don't lock it if (retval->status == SCI_STATUS_ALLOCATED) - _scir_add_to_lru(mgr, retval); + addToLRU(retval); } - _scir_free_old_resources(mgr, retval->status == SCI_STATUS_ALLOCATED); + freeOldResources(retval->status == SCI_STATUS_ALLOCATED); if (retval->data) return retval; @@ -713,7 +702,7 @@ resource_t * scir_find_resource(ResourceManager *mgr, int type, int number, int } } -void scir_unlock_resource(ResourceManager *mgr, resource_t *res, int resnum, int restype) { +void ResourceManager::unlockResource(resource_t *res, int resnum, int restype) { if (!res) { if (restype >= ARRAYSIZE(sci_resource_types)) sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %03d.%03d!\n", restype, resnum); @@ -730,11 +719,11 @@ void scir_unlock_resource(ResourceManager *mgr, resource_t *res, int resnum, int if (!--res->lockers) { // No more lockers? res->status = SCI_STATUS_ALLOCATED; - mgr->memory_locked -= res->size; - _scir_add_to_lru(mgr, res); + _memoryLocked -= res->size; + addToLRU(res); } - _scir_free_old_resources(mgr, 0); + freeOldResources(0); } } // End of namespace Sci diff --git a/engines/sci/scicore/resource.h b/engines/sci/scicore/resource.h index 443c6c775a..e662e186d0 100644 --- a/engines/sci/scicore/resource.h +++ b/engines/sci/scicore/resource.h @@ -27,6 +27,8 @@ #define SCI_SCICORE_RESOURCE_H #include "common/str.h" +#include "common/file.h" +#include "common/archive.h" namespace Common { class ReadStream; @@ -160,21 +162,9 @@ struct resource_t { }; -struct ResourceManager { - int _maxMemory; /* Config option: Maximum total byte number allocated */ - int sci_version; /* SCI resource version to use */ - - int _resourcesNr; - ResourceSource *_sources; - resource_t *_resources; - - int memory_locked; /* Amount of resource bytes in locked memory */ - int memory_lru; /* Amount of resource bytes under LRU control */ - - resource_t *lru_first, *lru_last; /* Pointers to the first and last LRU queue entries */ - /* LRU queue: lru_first points to the most recent entry */ - +class ResourceManager { public: + int sci_version; /* SCI resource version to use */ /** * Creates a new FreeSCI resource manager. * @param version The SCI version to look for; use SCI_VERSION_AUTODETECT @@ -187,236 +177,227 @@ public: */ ResourceManager(int version, int maxMemory); ~ResourceManager(); + + /* Add a path to the resource manager's list of sources. + ** Returns: A pointer to the added source structure, or NULL if an error occurred. + */ + ResourceSource *addPatchDir(const char *path); + ResourceSource *getVolume(ResourceSource *map, int volume_nr); + //! Add a volume to the resource manager's list of sources. + /** @param map The map associated with this volume + * @param filename The name of the volume to add + * @param extended_addressing 1 if this volume uses extended addressing, + * 0 otherwise. + * @return A pointer to the added source structure, or NULL if an error occurred. + */ + ResourceSource *addVolume(ResourceSource *map, const char *filename, + int number, int extended_addressing); + //! Add an external (i.e. separate file) map resource to the resource manager's list of sources. + /** @param file_name The name of the volume to add + * @return A pointer to the added source structure, or NULL if an error occurred. + */ + ResourceSource *addExternalMap(const char *file_name); + //! Scans newly registered resource sources for resources, earliest addition first. + /** @param detected_version: Pointer to the detected version number, + * used during startup. May be NULL. + * @return One of SCI_ERROR_*. + */ + int scanNewSources(int *detected_version, ResourceSource *source); + //! Looks up a resource's data + /** @param type: The resource type to look for + * @param number: The resource number to search + * @param lock: non-zero iff the resource should be locked + * @return (resource_t *): The resource, or NULL if it doesn't exist + * @note Locked resources are guaranteed not to have their contents freed until + * they are unlocked explicitly (by unlockResource). + */ + resource_t *findResource(int type, int number, int lock); + /* Unlocks a previously locked resource + ** (resource_t *) res: The resource to free + ** (int) type: Type of the resource to check (for error checking) + ** (int) number: Number of the resource to check (ditto) + ** Returns : (void) + */ + void unlockResource(resource_t *res, int restype, int resnum); + /* Tests whether a resource exists + ** (int) type: Type of the resource to check + ** (int) number: Number of the resource to check + ** Returns : (resource_t *) non-NULL if the resource exists, NULL otherwise + ** This function may often be much faster than finding the resource + ** and should be preferred for simple tests. + ** The resource object returned is, indeed, the resource in question, but + ** it should be used with care, as it may be unallocated. + ** Use scir_find_resource() if you want to use the data contained in the resource. + */ + resource_t *testResource(int type, int number); + +protected: + int _maxMemory; /* Config option: Maximum total byte number allocated */ + int _resourcesNr; + ResourceSource *_sources; + resource_t *_resources; + int _memoryLocked; // Amount of resource bytes in locked memory + int _memoryLRU; // Amount of resource bytes under LRU control + resource_t *lru_first, *lru_last; // Pointers to the first and last LRU queue entries + // LRU queue: lru_first points to the most recent entry + + + /* Frees a block of resources and associated data + ** Parameters: (resource_t *) resources: The resources to free + ** (int) _resourcesNr: Number of resources in the block + ** Returns : (void) + */ + void freeResources(resource_t *resources, int _resourcesNr); + /* Finds a resource matching type.number in an unsorted resource_t block + ** To be used during initial resource loading, when the resource list + ** may not have been sorted yet. + ** Parameters: (resource_t *) res: Pointer to the block to search in + ** (int) res_nr: Number of resource_t structs allocated and defined + ** in the block pointed to by res + ** (int) type: Type of the resource to look for + ** (int) number: Number of the resource to look for + ** Returns : (resource_t) The matching resource entry, or NULL if not found + */ + resource_t *findResourceUnsorted(resource_t *res, int res_nr, int type, int number); + /* Adds an alternative source to a resource + ** Parameters: (resource_t *) res: The resource to add to + ** (ResourceSource *) source: The source of the resource + ** (unsigned int) file_offset: Offset in the file the resource + ** is stored at + ** Returns : (void) + */ + int addAppropriateSources(); + void addAltSource(resource_t *res, ResourceSource *source, unsigned int file_offset); + void freeResourceSources(ResourceSource *rss); + void freeAltSources(resource_altsource_t *dynressrc); + + void loadResource(resource_t *res, bool protect); + void loadFromPatchFile(Common::File &file, resource_t *res, char *filename); + void freeOldResources(int last_invulnerable); + void unalloc(resource_t *res); + + /**--- Resource map decoding functions ---*/ + + /* Reads the SCI0 resource.map file from a local directory + ** Parameters: (char *) path: (unused) + ** (int) sci_version: SCI resource version + ** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise + */ + int readResourceMapSCI0(ResourceSource *map, int *sci_version); + /* Reads the SCI1 resource.map file from a local directory + ** Parameters: (char *) path: (unused) + ** (int) sci_version: SCI resource version + ** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise + */ + int readResourceMapSCI1(ResourceSource *map, ResourceSource *vol, int *sci_version); + int isSCI10or11(int *types); + int detectOddSCI01(Common::File &file); + int resReadEntry(ResourceSource *map, byte *buf, resource_t *res, int sci_version); + int resTypeSCI1(int ofs, int *types, int lastrt); + int parseHeaderSCI1(Common::ReadStream &stream, int *types, int *lastrt); + + /**--- Patch management functions ---*/ + + /* Reads SCI0 patch files from a local directory + ** Parameters: (char *) path: (unused) + ** (resource_t **) resources: Pointer to a pointer + ** that will be set to the + ** location of the resources + ** (in one large chunk) + ** (int *) resource_nr_p: Pointer to an int the number of resources + ** read is stored in + ** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise + */ + int readResourcePatchesSCI0(ResourceSource *source); + + /* Reads SCI1 patch files from a local directory + ** Parameters: (char *) path: (unused) + ** (resource_t **) resources: Pointer to a pointer + ** that will be set to the + ** location of the resources + ** (in one large chunk) + ** (int *) resource_nr_p: Pointer to an int the number of resources + ** read is stored in + ** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise + */ + int readResourcePatchesSCI1(ResourceSource *source); + void process_patch(ResourceSource *source, Common::ArchiveMember &member, int restype, + int resnumber); + + void printLRU(); + void addToLRU(resource_t *res); + void removeFromLRU(resource_t *res); }; -/**** FUNCTION DECLARATIONS ****/ - -/**--- New Resource manager ---**/ - -ResourceSource *scir_add_patch_dir(ResourceManager *mgr, const char *path); -/* Add a path to the resource manager's list of sources. -** Parameters: (ResourceManager *) mgr: The resource manager to look up in -** (const char *) path: The path to add -** Returns: A pointer to the added source structure, or NULL if an error occurred. -*/ - -ResourceSource *scir_get_volume(ResourceManager *mgr, ResourceSource *map, int volume_nr); - -ResourceSource *scir_add_volume(ResourceManager *mgr, ResourceSource *map, const char *filename, - int number, int extended_addressing); -/* Add a volume to the resource manager's list of sources. -** Parameters: (ResourceManager *) mgr: The resource manager to look up in -** (ResourceSource *) map: The map associated with this volume -** (char *) filename: The name of the volume to add -** (int) extended_addressing: 1 if this volume uses extended addressing, -** 0 otherwise. -** Returns: A pointer to the added source structure, or NULL if an error occurred. -*/ - -ResourceSource *scir_add_external_map(ResourceManager *mgr, const char *file_name); -/* Add an external (i.e. separate file) map resource to the resource manager's list of sources. -** Parameters: (ResourceManager *) mgr: The resource manager to look up in -** (const char *) file_name: The name of the volume to add -** Returns: A pointer to the added source structure, or NULL if an error occurred. -*/ - -int scir_scan_new_sources(ResourceManager *mgr, int *detected_version); -/* Scans newly registered resource sources for resources, earliest addition first. -** Parameters: (ResourceManager *) mgr: The resource manager to look up in -** (int *) detected_version: Pointer to the detected version number, -** used during startup. May be NULL. -** Returns: One of SCI_ERROR_*. -*/ - -resource_t *scir_find_resource(ResourceManager *mgr, int type, int number, int lock); -/* Looks up a resource's data -** Parameters: (ResourceManager *) mgr: The resource manager to look up in -** (int) type: The resource type to look for -** (int) number: The resource number to search -** (int) lock: non-zero iff the resource should be locked -** Returns : (resource_t *): The resource, or NULL if it doesn't exist -** Locked resources are guaranteed not to have their contents freed until -** they are unlocked explicitly (by scir_unlock_resource). -*/ - -void scir_unlock_resource(ResourceManager *mgr, resource_t *res, int restype, int resnum); -/* Unlocks a previously locked resource -** Parameters: (ResourceManager *) mgr: The manager the resource should be freed from -** (resource_t *) res: The resource to free -** (int) type: Type of the resource to check (for error checking) -** (int) number: Number of the resource to check (ditto) -** Returns : (void) -*/ - -resource_t *scir_test_resource(ResourceManager *mgr, int type, int number); -/* Tests whether a resource exists -** Parameters: (ResourceManager *) mgr: The resource manager to search in -** (int) type: Type of the resource to check -** (int) number: Number of the resource to check -** Returns : (resource_t *) non-NULL if the resource exists, NULL otherwise -** This function may often be much faster than finding the resource -** and should be preferred for simple tests. -** The resource object returned is, indeed, the resource in question, but -** it should be used with care, as it may be unallocated. -** Use scir_find_resource() if you want to use the data contained in the resource. -*/ - -/**--- Resource map decoding functions ---*/ - -int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t **resources, int *resource_nr_p, int *sci_version); -/* Reads the SCI0 resource.map file from a local directory -** Parameters: (char *) path: (unused) -** (resource_t **) resources: Pointer to a pointer -** that will be set to the -** location of the resources -** (in one large chunk) -** (int *) resource_nr_p: Pointer to an int the number of resources -** read is stored in -** (int) sci_version: SCI resource version -** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise -*/ - -int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource *vol, - resource_t **resource_p, int *resource_nr_p, int *sci_version); -/* Reads the SCI1 resource.map file from a local directory -** Parameters: (char *) path: (unused) -** (resource_t **) resources: Pointer to a pointer -** that will be set to the -** location of the resources -** (in one large chunk) -** (int *) resource_nr_p: Pointer to an int the number of resources -** read is stored in -** (int) sci_version: SCI resource version -** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise -*/ - -/**--- Patch management functions ---*/ - -void sci0_sprintf_patch_file_name(char *string, resource_t *res); -/* Prints the name of a matching patch to a string buffer -** Parameters: (char *) string: The buffer to print to -** (resource_t *) res: Resource containing the number and type of the -** resource whose name is to be print -** Returns : (void) -*/ - -void sci1_sprintf_patch_file_name(char *string, resource_t *res); -/* Prints the name of a matching patch to a string buffer -** Parameters: (char *) string: The buffer to print to -** (resource_t *) res: Resource containing the number and type of the -** resource whose name is to be print -** Returns : (void) -*/ - -int sci0_read_resource_patches(ResourceSource *source, resource_t **resources, int *resource_nr_p); -/* Reads SCI0 patch files from a local directory -** Parameters: (char *) path: (unused) -** (resource_t **) resources: Pointer to a pointer -** that will be set to the -** location of the resources -** (in one large chunk) -** (int *) resource_nr_p: Pointer to an int the number of resources -** read is stored in -** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise -*/ - -int sci1_read_resource_patches(ResourceSource *source, resource_t **resources, int *resource_nr_p); -/* Reads SCI1 patch files from a local directory -** Parameters: (char *) path: (unused) -** (resource_t **) resources: Pointer to a pointer -** that will be set to the -** location of the resources -** (in one large chunk) -** (int *) resource_nr_p: Pointer to an int the number of resources -** read is stored in -** Returns : (int) 0 on success, an SCI_ERROR_* code otherwise -*/ - - -/**--- Decompression functions ---**/ - - -int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version); -/* Decrypts resource data and stores the result for SCI0-style compression. -** Parameters : result: The resource_t the decompressed data is stored in. -** stream: Stream of the resource file -** sci_version : Actual SCI resource version -** Returns : (int) 0 on success, one of SCI_ERROR_* if a problem was -** encountered. -*/ - -int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version); -/* Decrypts resource data and stores the result for SCI01-style compression. -** Parameters : result: The resource_t the decompressed data is stored in. -** stream: Stream of the resource file -** sci_version : Actual SCI resource version -** Returns : (int) 0 on success, one of SCI_ERROR_* if a problem was -** encountered. -*/ - -int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version); -/* Decrypts resource data and stores the result for SCI1.1-style compression. -** Parameters : result: The resource_t the decompressed data is stored in. -** sci_version : Actual SCI resource version -** stream: Stream of the resource file -** Returns : (int) 0 on success, one of SCI_ERROR_* if a problem was -** encountered. -*/ - - -int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version); -/* Decrypts resource data and stores the result for SCI1.1-style compression. -** Parameters : result: The resource_t the decompressed data is stored in. -** sci_version : Actual SCI resource version -** stream: Stream of the resource file -** Returns : (int) 0 on success, one of SCI_ERROR_* if a problem was -** encountered. -*/ - - -int decrypt2(uint8* dest, uint8* src, int length, int complength); -/* Huffman token decryptor - defined in decompress0.c and used in decompress01.c -*/ - -int decrypt4(uint8* dest, uint8* src, int length, int complength); -/* DCL inflate- implemented in decompress1.c -*/ - -byte *view_reorder(byte *inbuffer, int dsize); -/* SCI1 style view compression */ - -byte *pic_reorder(byte *inbuffer, int dsize); -/* SCI1 style pic compression */ - -/*--- Internal helper functions ---*/ - -void _scir_free_resources(resource_t *resources, int _resourcesNr); -/* Frees a block of resources and associated data -** Parameters: (resource_t *) resources: The resources to free -** (int) _resourcesNr: Number of resources in the block -** Returns : (void) -*/ - -resource_t *_scir_find_resource_unsorted(resource_t *res, int res_nr, int type, int number); -/* Finds a resource matching type.number in an unsorted resource_t block -** To be used during initial resource loading, when the resource list -** may not have been sorted yet. -** Parameters: (resource_t *) res: Pointer to the block to search in -** (int) res_nr: Number of resource_t structs allocated and defined -** in the block pointed to by res -** (int) type: Type of the resource to look for -** (int) number: Number of the resource to look for -** Returns : (resource_t) The matching resource entry, or NULL if not found -*/ - -void _scir_add_altsource(resource_t *res, ResourceSource *source, unsigned int file_offset); -/* Adds an alternative source to a resource -** Parameters: (resource_t *) res: The resource to add to -** (ResourceSource *) source: The source of the resource -** (unsigned int) file_offset: Offset in the file the resource -** is stored at -** Returns : (void) -*/ + + /* Prints the name of a matching patch to a string buffer + ** Parameters: (char *) string: The buffer to print to + ** (resource_t *) res: Resource containing the number and type of the + ** resource whose name is to be print + ** Returns : (void) + */ + void sci0_sprintf_patch_file_name(char *string, resource_t *res); + + /* Prints the name of a matching patch to a string buffer + ** Parameters: (char *) string: The buffer to print to + ** (resource_t *) res: Resource containing the number and type of the + ** resource whose name is to be print + ** Returns : (void) + */ + void sci1_sprintf_patch_file_name(char *string, resource_t *res); + + /**--- Decompression functions ---**/ + int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version); + /* Decrypts resource data and stores the result for SCI0-style compression. + ** Parameters : result: The resource_t the decompressed data is stored in. + ** stream: Stream of the resource file + ** sci_version : Actual SCI resource version + ** Returns : (int) 0 on success, one of SCI_ERROR_* if a problem was + ** encountered. + */ + + int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version); + /* Decrypts resource data and stores the result for SCI01-style compression. + ** Parameters : result: The resource_t the decompressed data is stored in. + ** stream: Stream of the resource file + ** sci_version : Actual SCI resource version + ** Returns : (int) 0 on success, one of SCI_ERROR_* if a problem was + ** encountered. + */ + + int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version); + /* Decrypts resource data and stores the result for SCI1.1-style compression. + ** Parameters : result: The resource_t the decompressed data is stored in. + ** sci_version : Actual SCI resource version + ** stream: Stream of the resource file + ** Returns : (int) 0 on success, one of SCI_ERROR_* if a problem was + ** encountered. + */ + + + int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version); + /* Decrypts resource data and stores the result for SCI1.1-style compression. + ** Parameters : result: The resource_t the decompressed data is stored in. + ** sci_version : Actual SCI resource version + ** stream: Stream of the resource file + ** Returns : (int) 0 on success, one of SCI_ERROR_* if a problem was + ** encountered. + */ + + + int decrypt2(uint8* dest, uint8* src, int length, int complength); + /* Huffman token decryptor - defined in decompress0.c and used in decompress01.c + */ + + int decrypt4(uint8* dest, uint8* src, int length, int complength); + /* DCL inflate- implemented in decompress1.c + */ + + byte *view_reorder(byte *inbuffer, int dsize); + /* SCI1 style view compression */ + + byte *pic_reorder(byte *inbuffer, int dsize); + /* SCI1 style pic compression */ } // End of namespace Sci diff --git a/engines/sci/scicore/resource_map.cpp b/engines/sci/scicore/resource_map.cpp index b5177185b6..650912a869 100644 --- a/engines/sci/scicore/resource_map.cpp +++ b/engines/sci/scicore/resource_map.cpp @@ -88,7 +88,7 @@ namespace Sci { | (((bytes)[3]) << 9) \ | (((bytes)[2]) << 1)) -static int detect_odd_sci01(Common::File &file) { +int ResourceManager::detectOddSCI01(Common::File &file) { byte buf[6]; int files_ok = 1; int fsize, resource_nr, read_ok; @@ -119,15 +119,14 @@ static int detect_odd_sci01(Common::File &file) { return files_ok; } -static int sci_res_read_entry(ResourceManager *mgr, ResourceSource *map, - byte *buf, resource_t *res, int sci_version) { +int ResourceManager::resReadEntry(ResourceSource *map, byte *buf, resource_t *res, int sci_version) { res->id = buf[0] | (buf[1] << 8); res->type = SCI0_RESID_GET_TYPE(buf); res->number = SCI0_RESID_GET_NUMBER(buf); res->status = SCI_STATUS_NOMALLOC; if (sci_version == SCI_VERSION_01_VGA_ODD) { - res->source = scir_get_volume(mgr, map, SCI01V_RESFILE_GET_FILE(buf + 2)); + res->source = getVolume(map, SCI01V_RESFILE_GET_FILE(buf + 2)); res->file_offset = SCI01V_RESFILE_GET_OFFSET(buf + 2); #if 0 @@ -135,7 +134,7 @@ static int sci_res_read_entry(ResourceManager *mgr, ResourceSource *map, return 1; #endif } else { - res->source = scir_get_volume(mgr, map, SCI0_RESFILE_GET_FILE(buf + 2)); + res->source = getVolume(map, SCI0_RESFILE_GET_FILE(buf + 2)); res->file_offset = SCI0_RESFILE_GET_OFFSET(buf + 2); #if 0 @@ -157,7 +156,7 @@ static int sci_res_read_entry(ResourceManager *mgr, ResourceSource *map, return 0; } -inline int sci1_res_type(int ofs, int *types, int lastrt) { +int ResourceManager::resTypeSCI1(int ofs, int *types, int lastrt) { int i, last = -1; for (i = 0; i <= sci1_last_resource;i++) @@ -170,7 +169,7 @@ inline int sci1_res_type(int ofs, int *types, int lastrt) { return lastrt; } -int sci1_parse_header(Common::ReadStream &stream, int *types, int *lastrt) { +int ResourceManager::parseHeaderSCI1(Common::ReadStream &stream, int *types, int *lastrt) { unsigned char rtype; unsigned char offset[2]; int read_ok; @@ -198,7 +197,7 @@ int sci1_parse_header(Common::ReadStream &stream, int *types, int *lastrt) { -int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t **resource_p, int *resource_nr_p, int *sci_version) { +int ResourceManager::readResourceMapSCI0(ResourceSource *map, int *sci_version) { int fsize; Common::File file; resource_t *resources; @@ -237,7 +236,7 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t file.seek(0, SEEK_SET); - switch (detect_odd_sci01(file)) { + switch (detectOddSCI01(file)) { case 0 : // Odd SCI01 if (*sci_version == SCI_VERSION_AUTODETECT) *sci_version = SCI_VERSION_01_VGA_ODD; @@ -279,7 +278,7 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t int addto = resource_index; int i; - if (sci_res_read_entry(mgr, map, buf, resources + resource_index, *sci_version)) { + if (resReadEntry(map, buf, resources + resource_index, *sci_version)) { free(resources); return SCI_ERROR_RESMAP_NOT_FOUND; } @@ -290,7 +289,7 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t fresh = 0; } - _scir_add_altsource(resources + addto, resources[resource_index].source, resources[resource_index].file_offset); + addAltSource(resources + addto, resources[resource_index].source, resources[resource_index].file_offset); if (fresh) ++resource_index; @@ -308,12 +307,12 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t if (!resource_index) { sciprintf("resource.map was empty!\n"); - _scir_free_resources(resources, resource_nr); + freeResources(resources, resource_nr); return SCI_ERROR_RESMAP_NOT_FOUND; } if (max_resfile_nr > 999) { - _scir_free_resources(resources, resource_nr); + freeResources(resources, resource_nr); return SCI_ERROR_INVALID_RESMAP_ENTRY; } else { #if 0 @@ -333,15 +332,15 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t if (resource_index < resource_nr) resources = (resource_t *)sci_realloc(resources, sizeof(resource_t) * resource_index); - *resource_p = resources; - *resource_nr_p = resource_index; + _resources = resources; + _resourcesNr = resource_index; return 0; } #define TEST fprintf(stderr, "OK in line %d\n", __LINE__); -static int sci10_or_11(int *types) { +int ResourceManager::isSCI10or11(int *types) { int this_restype = 0; int next_restype = 1; @@ -372,8 +371,7 @@ static int sci10_or_11(int *types) { return SCI_VERSION_AUTODETECT; } -int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSource *vol, - resource_t **resource_p, int *resource_nr_p, int *sci_version) { +int ResourceManager::readResourceMapSCI1(ResourceSource *map, ResourceSource *vol, int *sci_version) { int fsize; Common::File file; resource_t *resources, *resource_start; @@ -392,11 +390,11 @@ int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSo memset(types, 0, sizeof(int) * (sci1_last_resource + 1)); - if (!(sci1_parse_header(file, types, &lastrt))) { + if (!(parseHeaderSCI1(file, types, &lastrt))) { return SCI_ERROR_INVALID_RESMAP_ENTRY; } - entry_size_selector = sci10_or_11(types); + entry_size_selector = isSCI10or11(types); if (*sci_version == SCI_VERSION_AUTODETECT) *sci_version = entry_size_selector; @@ -414,8 +412,8 @@ int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSo } resource_nr = (fsize - types[0]) / entrysize; - resource_start = resources = (resource_t*)sci_realloc(mgr->_resources, (mgr->_resourcesNr + resource_nr) * sizeof(resource_t)); - resources += mgr->_resourcesNr; + resource_start = resources = (resource_t*)sci_realloc(_resources, (_resourcesNr + resource_nr) * sizeof(resource_t)); + resources += _resourcesNr; i = 0; while (types[i] == 0) @@ -443,12 +441,12 @@ int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSo } res = &(resources[resource_index]); - res->type = sci1_res_type(ofs, types, lastrt); + res->type = resTypeSCI1(ofs, types, lastrt); res->number = SCI1_RESFILE_GET_NUMBER(buf); res->status = SCI_STATUS_NOMALLOC; if (entry_size_selector < SCI_VERSION_1_1) { - res->source = scir_get_volume(mgr, map, SCI1_RESFILE_GET_FILE(buf)); + res->source = getVolume(map, SCI1_RESFILE_GET_FILE(buf)); res->file_offset = SCI1_RESFILE_GET_OFFSET(buf); } else { res->source = vol; @@ -470,7 +468,7 @@ int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSo res->file, res->file_offset, addto); #endif - _scir_add_altsource(resources + addto, resources[resource_index].source, resources[resource_index].file_offset); + addAltSource(resources + addto, resources[resource_index].source, resources[resource_index].file_offset); if (fresh) ++resource_index; @@ -480,8 +478,8 @@ int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSo free(types); - *resource_p = resource_start; - *resource_nr_p += resource_index; + _resources = resource_start; + _resourcesNr += resource_index; return 0; } diff --git a/engines/sci/scicore/resource_patch.cpp b/engines/sci/scicore/resource_patch.cpp index 25a36deb41..5a02b82dcf 100644 --- a/engines/sci/scicore/resource_patch.cpp +++ b/engines/sci/scicore/resource_patch.cpp @@ -40,8 +40,8 @@ void sci1_sprintf_patch_file_name(char *string, resource_t *res) { } // version-agnostic patch application -static void process_patch(ResourceSource *source, - Common::ArchiveMember &member, int restype, int resnumber, resource_t **resource_p, int *resource_nr_p) { +void ResourceManager::process_patch(ResourceSource *source, + Common::ArchiveMember &member, int restype, int resnumber) { Common::File file; if (restype == sci_invalid_resource) @@ -52,7 +52,7 @@ static void process_patch(ResourceSource *source, perror("""__FILE__"": (""__LINE__""): failed to open"); else { uint8 filehdr[2]; - resource_t *newrsc = _scir_find_resource_unsorted(*resource_p, *resource_nr_p, restype, resnumber); + resource_t *newrsc = findResourceUnsorted(_resources, _resourcesNr, restype, resnumber); int fsize = file.size(); if (fsize < 3) { printf("File too small\n"); @@ -76,9 +76,9 @@ static void process_patch(ResourceSource *source, // Prepare destination, if neccessary if (!newrsc) { // Completely new resource! - ++(*resource_nr_p); - *resource_p = (resource_t *)sci_realloc(*resource_p, *resource_nr_p * sizeof(resource_t)); - newrsc = (*resource_p - 1) + *resource_nr_p; + _resourcesNr++; + _resources = (resource_t *)sci_realloc(_resources, _resourcesNr * sizeof(resource_t)); + newrsc = (_resources - 1) + _resourcesNr; newrsc->alt_sources = NULL; } @@ -90,16 +90,14 @@ static void process_patch(ResourceSource *source, newrsc->type = restype; newrsc->source = source; newrsc->file_offset = 2 + patch_data_offset; - - _scir_add_altsource(newrsc, source, 2); - + addAltSource(newrsc, source, 2); printf("OK\n"); } } } -int sci0_read_resource_patches(ResourceSource *source, resource_t **resource_p, int *resource_nr_p) { +int ResourceManager::readResourcePatchesSCI0(ResourceSource *source) { Common::ArchiveMemberList files; SearchMan.listMatchingMembers(files, "*.???"); @@ -130,13 +128,13 @@ int sci0_read_resource_patches(ResourceSource *source, resource_t **resource_p, } } - process_patch(source, **x, restype, resnumber, resource_p, resource_nr_p); + process_patch(source, **x, restype, resnumber); } return 0; } -int sci1_read_resource_patches(ResourceSource *source, resource_t **resource_p, int *resource_nr_p) { +int ResourceManager::readResourcePatchesSCI1(ResourceSource *source) { Common::ArchiveMemberList files; SearchMan.listMatchingMembers(files, "*.*"); @@ -169,7 +167,7 @@ int sci1_read_resource_patches(ResourceSource *source, resource_t **resource_p, restype = sci_invalid_resource; } - process_patch(source, **x, restype, resnumber, resource_p, resource_nr_p); + process_patch(source, **x, restype, resnumber); } return 0; diff --git a/engines/sci/scicore/script.cpp b/engines/sci/scicore/script.cpp index ffa7fae332..09c66d1e63 100644 --- a/engines/sci/scicore/script.cpp +++ b/engines/sci/scicore/script.cpp @@ -329,7 +329,7 @@ static void script_dump_class(char *data, int seeker, int objsize, const Common: void script_dissect(ResourceManager *resmgr, int res_no, const Common::StringList &selectorNames) { int objectctr[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; unsigned int _seeker = 0; - resource_t *script = scir_find_resource(resmgr, sci_script, res_no, 0); + resource_t *script = resmgr->findResource(sci_script, res_no, 0); word_t **words; int word_count; diff --git a/engines/sci/scicore/vocab.cpp b/engines/sci/scicore/vocab.cpp index 45c26f424e..13f705a17f 100644 --- a/engines/sci/scicore/vocab.cpp +++ b/engines/sci/scicore/vocab.cpp @@ -75,12 +75,12 @@ word_t **vocab_get_words(ResourceManager *resmgr, int *word_counter) { resource_t *resource; // First try to load the SCI0 vocab resource. - resource = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB, 0); + resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB, 0); vocab_version = 0; if (!resource) { warning("SCI0: Could not find a main vocabulary, trying SCI01"); - resource = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB, 0); + resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB, 0); vocab_version = 1; } @@ -179,7 +179,7 @@ static inline unsigned int inverse_16(unsigned int foo) { suffix_t **vocab_get_suffices(ResourceManager *resmgr, int *suffices_nr) { int counter = 0; suffix_t **suffices; - resource_t *resource = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1); + resource_t *resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1); unsigned int seeker = 1; if (!resource) { @@ -226,7 +226,7 @@ suffix_t **vocab_get_suffices(ResourceManager *resmgr, int *suffices_nr) { void vocab_free_suffices(ResourceManager *resmgr, suffix_t **suffices, int suffices_nr) { int i; - scir_unlock_resource(resmgr, scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0), + resmgr->unlockResource(resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0), VOCAB_RESOURCE_SUFFIX_VOCAB, sci_vocab); for (i = 0; i < suffices_nr; i++) @@ -241,7 +241,7 @@ void vocab_free_branches(parse_tree_branch_t *parser_branches) { } parse_tree_branch_t *vocab_get_branches(ResourceManager * resmgr, int *branches_nr) { - resource_t *resource = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_PARSE_TREE_BRANCHES, 0); + resource_t *resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_PARSE_TREE_BRANCHES, 0); parse_tree_branch_t *retval; int i; diff --git a/engines/sci/scicore/vocab_debug.cpp b/engines/sci/scicore/vocab_debug.cpp index 2cb3f40e24..6a9eb4183b 100644 --- a/engines/sci/scicore/vocab_debug.cpp +++ b/engines/sci/scicore/vocab_debug.cpp @@ -159,7 +159,7 @@ int *vocabulary_get_classes(ResourceManager *resmgr, int* count) { int *c; unsigned int i; - if ((r = scir_find_resource(resmgr, sci_vocab, 996, 0)) == NULL) + if ((r = resmgr->findResource(sci_vocab, 996, 0)) == NULL) return 0; c = (int *)sci_malloc(sizeof(int) * r->size / 2); @@ -174,7 +174,7 @@ int *vocabulary_get_classes(ResourceManager *resmgr, int* count) { int vocabulary_get_class_count(ResourceManager *resmgr) { resource_t* r; - if ((r = scir_find_resource(resmgr, sci_vocab, 996, 0)) == 0) + if ((r = resmgr->findResource(sci_vocab, 996, 0)) == 0) return 0; return r->size / 4; @@ -183,7 +183,7 @@ int vocabulary_get_class_count(ResourceManager *resmgr) { bool vocabulary_get_snames(ResourceManager *resmgr, sci_version_t version, Common::StringList &selectorNames) { int count; - resource_t *r = scir_find_resource(resmgr, sci_vocab, 997, 0); + resource_t *r = resmgr->findResource(sci_vocab, 997, 0); if (!r) // No such resource? return false; @@ -218,7 +218,7 @@ int vocabulary_lookup_sname(const Common::StringList &selectorNames, const char opcode* vocabulary_get_opcodes(ResourceManager *resmgr) { opcode* o; int count, i = 0; - resource_t* r = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_OPCODES, 0); + resource_t* r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_OPCODES, 0); // if the resource couldn't be loaded, leave if (r == NULL) { @@ -295,7 +295,7 @@ static char **_vocabulary_get_knames0alt(int *names, resource_t *r) { static char **vocabulary_get_knames0(ResourceManager *resmgr, int* names) { char** t; int count, i, index = 2, empty_to_add = 1; - resource_t *r = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_KNAMES, 0); + resource_t *r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_KNAMES, 0); if (!r) { // No kernel name table found? Fall back to default table t = (char **)sci_malloc((SCI0_KNAMES_DEFAULT_ENTRIES_NR + 1) * sizeof(char*)); @@ -345,7 +345,7 @@ static char **vocabulary_get_knames0(ResourceManager *resmgr, int* names) { static char **vocabulary_get_knames1(ResourceManager *resmgr, int *count) { char **t = NULL; unsigned int size = 64, used = 0, pos = 0; - resource_t *r = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_KNAMES, 0); + resource_t *r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_KNAMES, 0); while (pos < r->size) { int len; diff --git a/engines/sci/scicore/vocabulary.h b/engines/sci/scicore/vocabulary.h index ec785a9c30..1652a57b3a 100644 --- a/engines/sci/scicore/vocabulary.h +++ b/engines/sci/scicore/vocabulary.h @@ -32,7 +32,7 @@ namespace Sci { -struct ResourceManager; +class ResourceManager; /*#define VOCABULARY_DEBUG */ /*#define SCI_SIMPLE_SAID_CODE */ /* Whether the simplified Said() matching should be used */ diff --git a/engines/sci/sfx/player/polled.cpp b/engines/sci/sfx/player/polled.cpp index 339b418a77..ff3feea6ed 100644 --- a/engines/sci/sfx/player/polled.cpp +++ b/engines/sci/sfx/player/polled.cpp @@ -176,11 +176,11 @@ static int pp_init(ResourceManager *resmgr, int expected_latency) { } if (seq->patch_nr != SFX_SEQ_PATCHFILE_NONE) { - res = scir_find_resource(resmgr, sci_patch, seq->patch_nr, 0); + res = resmgr->findResource(sci_patch, seq->patch_nr, 0); } if (seq->patch2_nr != SFX_SEQ_PATCHFILE_NONE) { - res2 = scir_find_resource(resmgr, sci_patch, seq->patch2_nr, 0); + res2 = resmgr->findResource(sci_patch, seq->patch2_nr, 0); } if (seq->init(seq, diff --git a/engines/sci/sfx/player/realtime.cpp b/engines/sci/sfx/player/realtime.cpp index 03c2b9ed04..a4554eafff 100644 --- a/engines/sci/sfx/player/realtime.cpp +++ b/engines/sci/sfx/player/realtime.cpp @@ -132,7 +132,7 @@ static resource_t *find_patch(ResourceManager *resmgr, const char *seq_name, int resource_t *res = NULL; if (patchfile != SFX_SEQ_PATCHFILE_NONE) { - res = scir_find_resource(resmgr, sci_patch, patchfile, 0); + res = resmgr->findResource(sci_patch, patchfile, 0); if (!res) { fprintf(stderr, "[SFX] " __FILE__": patch.%03d requested by sequencer (%s), but not found\n", patchfile, seq_name); |