diff options
author | Jordi Vilalta Prat | 2009-02-28 23:46:50 +0000 |
---|---|---|
committer | Jordi Vilalta Prat | 2009-02-28 23:46:50 +0000 |
commit | 7050c7b03f0f7b107df62488fd4dc2f37b704d3b (patch) | |
tree | 102ee5f2a5cecb29f1de285d0ea9f004477a37f7 /engines | |
parent | 8e39ac9f12fb95ffda80116389d03f050beabd90 (diff) | |
download | scummvm-rg350-7050c7b03f0f7b107df62488fd4dc2f37b704d3b.tar.gz scummvm-rg350-7050c7b03f0f7b107df62488fd4dc2f37b704d3b.tar.bz2 scummvm-rg350-7050c7b03f0f7b107df62488fd4dc2f37b704d3b.zip |
SCI: Use the ResourceType enum instead of integers where it makes sense
svn-id: r38988
Diffstat (limited to 'engines')
26 files changed, 233 insertions, 186 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 597735d771..16534dc910 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 = s->resmgr->findResource(sci_palette, 999, 1); + resource = s->resmgr->findResource(kResourceTypePalette, 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); - s->resmgr->unlockResource(resource, sci_palette, 999); + s->resmgr->unlockResource(resource, 999, kResourceTypePalette); } else { sciprintf("Couldn't find the default palette!\n"); } @@ -184,7 +184,7 @@ int _reset_graphics_input(EngineState *s) { font_nr = -1; do { - resource = s->resmgr->testResource(sci_font, ++font_nr); + resource = s->resmgr->testResource(kResourceTypeFont, ++font_nr); } while ((!resource) && (font_nr < sci_max_resource_nr[s->resmgr->_sciVersion])); if (!resource) { @@ -295,7 +295,7 @@ int test_cursor_style(EngineState *s) { int ok = 0; do { - ok |= s->resmgr->testResource(sci_cursor, resource_nr++) != NULL; + ok |= s->resmgr->testResource(kResourceTypeCursor, 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 *vocab996 = s->resmgr->findResource(sci_vocab, 996, 1); + Resource *vocab996 = s->resmgr->findResource(kResourceTypeVocab, 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 *heap = s->resmgr->findResource(sci_heap, scriptnr, 0); + Resource *heap = s->resmgr->findResource(kResourceTypeHeap, 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 *vocab996 = s->resmgr->findResource(sci_vocab, 996, 1); + Resource *vocab996 = s->resmgr->findResource(kResourceTypeVocab, 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 *script = s->resmgr->findResource(sci_script, scriptnr, 0); + Resource *script = s->resmgr->findResource(kResourceTypeScript, 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) { } } - s->resmgr->unlockResource(vocab996, sci_vocab, 996); + s->resmgr->unlockResource(vocab996, 996, kResourceTypeVocab); vocab996 = NULL; return 0; } diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp index cce2eb4d25..21f491e41c 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 = s->resmgr->testResource(sci_font, i--); + bodyfont_res = s->resmgr->testResource(kResourceTypeFont, 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 9517567e21..4e72401222 100644 --- a/engines/sci/engine/kscripts.cpp +++ b/engines/sci/engine/kscripts.cpp @@ -118,7 +118,8 @@ reg_t kLoad(EngineState *s, int funct_nr, int argc, reg_t *argv) { int restype = KP_UINT(argv[0]); int resnr = KP_UINT(argv[1]); - if (restype == sci_memory) // Request to dynamically allocate hunk memory for later use + // Request to dynamically allocate hunk memory for later use + if (restype == kResourceTypeMemory) return kalloc(s, "kLoad()", resnr); return make_reg(0, ((restype << 11) | resnr)); // Return the resource identifier as handle @@ -133,11 +134,11 @@ reg_t kLock(EngineState *s, int funct_nr, int argc, reg_t *argv) { switch (state) { case 1 : - s->resmgr->findResource(restype, resnr, 1); + s->resmgr->findResource((ResourceType)restype, resnr, 1); break; case 0 : - which = s->resmgr->findResource(restype, resnr, 0); - s->resmgr->unlockResource(which, resnr, restype); + which = s->resmgr->findResource((ResourceType)restype, resnr, 0); + s->resmgr->unlockResource(which, resnr, (ResourceType)restype); break; } return s->r_acc; @@ -148,7 +149,7 @@ reg_t kUnLoad(EngineState *s, int funct_nr, int argc, reg_t *argv) { int restype = KP_UINT(argv[0]); reg_t resnr = argv[1]; - if (restype == sci_memory) + if (restype == kResourceTypeMemory) kfree(s, resnr); return s->r_acc; diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index 42d0da4056..03d3a5d424 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 *song = s->resmgr->findResource(sci_sound, song_nr, 0); + Resource *song = s->resmgr->findResource(kResourceTypeSound, 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 *song = s->resmgr->findResource(sci_sound, song_nr, 0); + Resource *song = s->resmgr->findResource(kResourceTypeSound, 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 && (s->resmgr->testResource(sci_sound, number))) { + if (obj.segment && (s->resmgr->testResource(kResourceTypeSound, 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 (!s->resmgr->testResource(sci_sound, number)) { + if (!s->resmgr->testResource(kResourceTypeSound, 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 && (s->resmgr->testResource(sci_sound, number))) { + if (obj.segment && (s->resmgr->testResource(kResourceTypeSound, 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 ac113fa9a8..76e9f90c7f 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 = s->resmgr->findResource(sci_text, address.offset, 0); + textres = s->resmgr->findResource(kResourceTypeText, 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 *textres = s->resmgr->findResource(sci_text, UKPV(0), 0); + Resource *textres = s->resmgr->findResource(kResourceTypeText, UKPV(0), 0); char *seeker; int counter = UKPV(1); diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp index 32bd50401b..8ec403fa94 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 = state->resmgr->findResource(sci_message, module, 0); + state->current_res = state->resmgr->findResource(kResourceTypeMessage, 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 *tester = resmgr->findResource(sci_message, 0, 0); + //Resource *tester = resmgr->findResource(kResourceTypeMessage, 0, 0); //int version; //if (tester == NULL) diff --git a/engines/sci/engine/savegame.cfsml b/engines/sci/engine/savegame.cfsml index 6de4b737fc..8b1b0e03ef 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 = s->resmgr->findResource(sci_script, scr->nr, 0); + script = s->resmgr->findResource(kResourceTypeScript, scr->nr, 0); if (s->version >= SCI_VERSION(1,001,000)) - heap = s->resmgr->findResource(sci_heap, scr->nr, 0); + heap = s->resmgr->findResource(kResourceTypeHeap, 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 02c11a5d7a..c43c226940 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 = s->resmgr->findResource(sci_script, scr->nr, 0); + script = s->resmgr->findResource(kResourceTypeScript, scr->nr, 0); if (s->version >= SCI_VERSION(1,001,000)) - heap = s->resmgr->findResource(sci_heap, scr->nr, 0); + heap = s->resmgr->findResource(kResourceTypeHeap, scr->nr, 0); switch (s->seg_manager->isSci1_1) { case 0 : diff --git a/engines/sci/engine/scriptconsole.cpp b/engines/sci/engine/scriptconsole.cpp index ca7cdcfd18..d2f8417e4a 100644 --- a/engines/sci/engine/scriptconsole.cpp +++ b/engines/sci/engine/scriptconsole.cpp @@ -677,13 +677,13 @@ int con_hook_int(int *pointer, const char *name, const char *description) { // Console commands and support functions -static int get_resource_number(char *resid) { +static ResourceType parseResourceType(char *resid) { // Gets the resource number of a resource string, or returns -1 - int i, res = -1; + ResourceType res = kResourceTypeInvalid; - for (i = 0; i < sci_invalid_resource; i++) - if (strcmp(sci_resource_types[i], resid) == 0) - res = i; + for (int i = 0; i < kResourceTypeInvalid; i++) + if (strcmp(getResourceTypeName((ResourceType)i), resid) == 0) + res = (ResourceType)i; return res; } @@ -833,16 +833,16 @@ static int c_list(EngineState *s) { else if (!strcmp("words", cmd_params[0].str)) return c_list_words(s); else if (strcmp("restypes", cmd_params[0].str) == 0) { - for (i = 0; i < sci_invalid_resource; i++) - sciprintf("%s\n", sci_resource_types[i]); + for (i = 0; i < kResourceTypeInvalid; i++) + sciprintf("%s\n", getResourceTypeName((ResourceType)i)); } else { - int res = get_resource_number(cmd_params[0].str); - if (res == -1) + ResourceType res = parseResourceType(cmd_params[0].str); + if (res == kResourceTypeInvalid) sciprintf("Unknown resource type: '%s'\n", cmd_params[0].str); else { for (i = 0; i < sci_max_resource_nr[s->resmgr->_sciVersion]; i++) if (s->resmgr->testResource(res, i)) - sciprintf("%s.%03d\n", sci_resource_types[res], i); + sciprintf("%s.%03d\n", getResourceTypeName((ResourceType)res), i); } } } @@ -909,8 +909,8 @@ static int c_print(EngineState *s) { } static int c_size(EngineState *s) { - int res = get_resource_number(cmd_params[0].str); - if (res == -1) + ResourceType res = parseResourceType(cmd_params[0].str); + if (res == kResourceTypeInvalid) sciprintf("Resource type '%s' is not valid\n", cmd_params[0].str); else { Resource *resource = s->resmgr->findResource(res, cmd_params[1].val, 0); @@ -924,9 +924,9 @@ static int c_size(EngineState *s) { } static int c_dump(EngineState *s) { - int res = get_resource_number(cmd_params[0].str); + ResourceType res = parseResourceType(cmd_params[0].str); - if (res == -1) + if (res == kResourceTypeInvalid) sciprintf("Resource type '%s' is not valid\n", cmd_params[0].str); else { Resource *resource = s->resmgr->findResource(res, cmd_params[1].val, 0); @@ -940,10 +940,11 @@ static int c_dump(EngineState *s) { } static int c_hexgrep(EngineState *s) { - int i, seeklen, resnr, restype, resmax; + int i, seeklen, resnr, resmax; unsigned char *seekstr = NULL; Resource *script = NULL; char *dot = strchr(cmd_params[0].str, '.'); + ResourceType restype; if (NULL == s) { fprintf(stderr, "console.c: c_hexgrep(): NULL passed for s\r\n"); @@ -968,7 +969,8 @@ static int c_hexgrep(EngineState *s) { resmax = 999; } - if ((restype = get_resource_number(cmd_params[0].str)) == -1) { + restype = parseResourceType(cmd_params[0].str); + if (restype == kResourceTypeInvalid) { sciprintf("Unknown resource type \"%s\"\n", cmd_params[0].str); free(seekstr); return 1; @@ -992,7 +994,7 @@ static int c_hexgrep(EngineState *s) { seeker = seekerold + 1; if (!output_script_name) { - sciprintf("\nIn %s.%03d:\n", sci_resource_types[restype], resnr); + sciprintf("\nIn %s.%03d:\n", getResourceTypeName((ResourceType)restype), resnr); output_script_name = 1; } sciprintf(" 0x%04x\n", seekerold); diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index 30309a894b..34d628d44f 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -248,7 +248,7 @@ static void sci01_song_header_dump(byte *data, int size) { #undef SONGDATA int c_sfx_01_header(EngineState *s) { - Resource *song = s->resmgr->findResource(sci_sound, cmd_params[0].val, 0); + Resource *song = s->resmgr->findResource(kResourceTypeSound, cmd_params[0].val, 0); if (!song) { sciprintf("Doesn't exist\n"); @@ -261,7 +261,7 @@ int c_sfx_01_header(EngineState *s) { } int c_sfx_01_track(EngineState *s) { - Resource *song = s->resmgr->findResource(sci_sound, cmd_params[0].val, 0); + Resource *song = s->resmgr->findResource(kResourceTypeSound, cmd_params[0].val, 0); int offset = cmd_params[1].val; @@ -2204,7 +2204,7 @@ static int c_send(EngineState *s) { static int c_resource_id(EngineState *s) { int id = cmd_params[0].val; - sciprintf("%s.%d (0x%x)\n", sci_resource_types[id >> 11], id &0x7ff, id & 0x7ff); + sciprintf("%s.%d (0x%x)\n", getResourceTypeName((ResourceType)(id >> 11)), id & 0x7ff, id & 0x7ff); return 0; } @@ -2409,7 +2409,7 @@ int c_simkey(EngineState *s) { } static int c_is_sample(EngineState *s) { - Resource *song = s->resmgr->findResource(sci_sound, cmd_params[0].val, 0); + Resource *song = s->resmgr->findResource(kResourceTypeSound, 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 57ba65573c..f778b73da3 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 *script = s->resmgr->findResource(sci_script, script_nr, 0); - Resource *heap = s->resmgr->findResource(sci_heap, script_nr, 0); + Resource *script = s->resmgr->findResource(kResourceTypeScript, script_nr, 0); + Resource *heap = s->resmgr->findResource(kResourceTypeHeap, 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 746df27b80..5d45acb294 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 *script = {0}; - if (s->resmgr->findResource(sci_heap, 0, 0)) { + if (s->resmgr->findResource(kResourceTypeHeap, 0, 0)) { version_require_later_than(s, SCI_VERSION(1, 001, 000)); return; } for (c = 0; c < 1000; c++) { - if ((script = s->resmgr->findResource(sci_script, c, 0))) { + if ((script = s->resmgr->findResource(kResourceTypeScript, c, 0))) { int id = getInt16(script->data); @@ -1679,9 +1679,9 @@ int script_instantiate_common(EngineState *s, int script_nr, Resource **script, *was_new = 1; - *script = s->resmgr->findResource(sci_script, script_nr, 0); + *script = s->resmgr->findResource(kResourceTypeScript, script_nr, 0); if (s->version >= SCI_VERSION(1, 001, 000)) - *heap = s->resmgr->findResource(sci_heap, script_nr, 0); + *heap = s->resmgr->findResource(kResourceTypeHeap, 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 b2d1c0b9bb..585b3c6166 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 *res = resmgr->findResource(sci_pic, nr, 0); + Resource *res = resmgr->findResource(kResourceTypePic, 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 *res = resmgr->findResource(sci_view, nr, 0); + Resource *res = resmgr->findResource(kResourceTypeView, 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 *res = resmgr->findResource(sci_font, nr, 0); + Resource *res = resmgr->findResource(kResourceTypeFont, 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 *res = resmgr->findResource(sci_cursor, nr, 0); + Resource *res = resmgr->findResource(kResourceTypeCursor, nr, 0); int resid = GFXR_RES_ID(GFX_RESOURCE_TYPE_CURSOR, nr); if (!res || !res->data) @@ -216,7 +216,7 @@ gfx_pixmap_t *gfxr_interpreter_get_cursor(gfx_resstate_t *state, int nr, void *i int *gfxr_interpreter_get_resources(gfx_resstate_t *state, gfx_resource_type_t type, int version, int *entries_nr, void *internal) { ResourceManager *resmgr = (ResourceManager *) state->misc_payload; - int restype; + ResourceType restype; int *resources; int count = 0; int top = sci_max_resource_nr[version] + 1; @@ -224,19 +224,19 @@ int *gfxr_interpreter_get_resources(gfx_resstate_t *state, gfx_resource_type_t t switch (type) { case GFX_RESOURCE_TYPE_VIEW: - restype = sci_view; + restype = kResourceTypeView; break; case GFX_RESOURCE_TYPE_PIC: - restype = sci_pic; + restype = kResourceTypePic; break; case GFX_RESOURCE_TYPE_CURSOR: - restype = sci_cursor; + restype = kResourceTypeCursor; break; case GFX_RESOURCE_TYPE_FONT: - restype = sci_font; + restype = kResourceTypeFont; break; default: @@ -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 = resmgr->findResource(sci_palette, nr, 0); + res = resmgr->findResource(kResourceTypePalette, nr, 0); if (!res || !res->data) return NULL; diff --git a/engines/sci/scicore/decompress0.cpp b/engines/sci/scicore/decompress0.cpp index 6b3775ff5c..1e9c263845 100644 --- a/engines/sci/scicore/decompress0.cpp +++ b/engines/sci/scicore/decompress0.cpp @@ -244,11 +244,13 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) { return SCI_ERROR_IO_ERROR; result->number = result->id & 0x07ff; - result->type = result->id >> 11; + uint8 type = result->id >> 11; - if ((result->number > sci_max_resource_nr[sci_version]) || (result->type > sci_invalid_resource)) + if ((result->number > sci_max_resource_nr[sci_version]) || (type > kResourceTypeInvalid)) return SCI_ERROR_DECOMPRESSION_INSANE; + result->type = (ResourceType)type; + compressedLength = stream.readUint16LE(); result->size = stream.readUint16LE(); compressionMethod = stream.readUint16LE(); @@ -280,7 +282,7 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) { #ifdef _SCI_DECOMPRESS_DEBUG fprintf(stderr, "Resource %s.%03hi encrypted with method %hi at %.2f%%" " ratio\n", - sci_resource_types[result->type], result->number, compressionMethod, + getResourceTypeName(result->type), result->number, compressionMethod, (result->size == 0) ? -1.0 : (100.0 * compressedLength / result->size)); fprintf(stderr, " compressedLength = 0x%hx, actualLength=0x%hx\n", @@ -324,7 +326,7 @@ int decompress0(Resource *result, Common::ReadStream &stream, int sci_version) { default: fprintf(stderr, "Resource %s.%03hi: Compression method %hi not " - "supported!\n", sci_resource_types[result->type], result->number, + "supported!\n", getResourceTypeName(result->type), result->number, compressionMethod); free(result->data); result->data = 0; // So that we know that it didn't work diff --git a/engines/sci/scicore/decompress01.cpp b/engines/sci/scicore/decompress01.cpp index e74b85def7..e87d61cf28 100644 --- a/engines/sci/scicore/decompress01.cpp +++ b/engines/sci/scicore/decompress01.cpp @@ -500,11 +500,13 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version) return SCI_ERROR_IO_ERROR; result->number = result->id & 0x07ff; - result->type = result->id >> 11; + uint8 type = result->id >> 11; - if ((result->number > sci_max_resource_nr[sci_version] || (result->type > sci_invalid_resource))) + if ((result->number > sci_max_resource_nr[sci_version] || (type > kResourceTypeInvalid))) return SCI_ERROR_DECOMPRESSION_INSANE; + result->type = (ResourceType)type; + compressedLength = stream.readUint16LE(); result->size = stream.readUint16LE(); compressionMethod = stream.readUint16LE(); @@ -611,7 +613,7 @@ int decompress01(Resource *result, Common::ReadStream &stream, int sci_version) default: fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not " - "supported!\n", sci_resource_types[result->type], result->number, + "supported!\n", getResourceTypeName(result->type), result->number, compressionMethod); free(result->data); result->data = 0; // So that we know that it didn't work diff --git a/engines/sci/scicore/decompress1.cpp b/engines/sci/scicore/decompress1.cpp index 51b13e49a7..c42f436bba 100644 --- a/engines/sci/scicore/decompress1.cpp +++ b/engines/sci/scicore/decompress1.cpp @@ -278,22 +278,26 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) { return SCI_ERROR_IO_ERROR; result->number = result->id & 0x07ff; - result->type = result->id >> 11; + uint16 type = result->id >> 11; - if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_EARLY]) || (result->type > sci_invalid_resource)) + if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_EARLY]) || (type > kResourceTypeInvalid)) return SCI_ERROR_DECOMPRESSION_INSANE; + + result->type = (ResourceType)type; } else { result->id = stream.readByte(); if (stream.err()) return SCI_ERROR_IO_ERROR; - result->type = result->id & 0x7f; + uint16 type = result->id & 0x7f; result->number = stream.readUint16LE(); if (stream.err()) return SCI_ERROR_IO_ERROR; - if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_LATE]) || (result->type > sci_invalid_resource)) + if ((result->number >= sci_max_resource_nr[SCI_VERSION_1_LATE]) || (type > kResourceTypeInvalid)) return SCI_ERROR_DECOMPRESSION_INSANE; + + result->type = (ResourceType)type; } compressedLength = stream.readUint16LE(); @@ -399,7 +403,7 @@ int decompress1(Resource *result, Common::ReadStream &stream, int sci_version) { default: fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not " - "supported!\n", sci_resource_types[result->type], result->number, + "supported!\n", getResourceTypeName(result->type), result->number, compressionMethod); free(result->data); result->data = 0; // So that we know that it didn't work diff --git a/engines/sci/scicore/decompress11.cpp b/engines/sci/scicore/decompress11.cpp index 39ff53c070..aff87c9fdf 100644 --- a/engines/sci/scicore/decompress11.cpp +++ b/engines/sci/scicore/decompress11.cpp @@ -49,9 +49,10 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) if (stream.err()) return SCI_ERROR_IO_ERROR; - result->type = result->id & 0x7f; - if ((result->type > sci_invalid_resource)) + uint16 type = result->id & 0x7f; + if (type > kResourceTypeInvalid) return SCI_ERROR_DECOMPRESSION_INSANE; + result->type = (ResourceType)type; result->number = stream.readUint16LE(); compressedLength = stream.readUint16LE(); @@ -91,7 +92,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) #ifdef _SCI_DECOMPRESS_DEBUG fprintf(stderr, "Resource %i.%s encrypted with method SCI1.1/%hi at %.2f%%" " ratio\n", - result->number, sci_resource_type_suffixes[result->type], + result->number, getResourceTypeSuffix(result->type), compressionMethod, (result->size == 0) ? -1.0 : (100.0 * compressedLength / result->size)); @@ -130,7 +131,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) case 3: case 4: // NYI fprintf(stderr, "Resource %d.%s: Warning: compression type #%d not yet implemented\n", - result->number, sci_resource_type_suffixes[result->type], compressionMethod); + result->number, getResourceTypeSuffix(result->type), compressionMethod); free(result->data); result->data = NULL; result->status = SCI_STATUS_NOMALLOC; @@ -138,7 +139,7 @@ int decompress11(Resource *result, Common::ReadStream &stream, int sci_version) default: fprintf(stderr, "Resource %d.%s: Compression method SCI1/%hi not " - "supported!\n", result->number, sci_resource_type_suffixes[result->type], + "supported!\n", result->number, getResourceTypeSuffix(result->type), compressionMethod); free(result->data); result->data = NULL; // So that we know that it didn't work diff --git a/engines/sci/scicore/resource.cpp b/engines/sci/scicore/resource.cpp index 75448d6ab9..e7b9fc34c2 100644 --- a/engines/sci/scicore/resource.cpp +++ b/engines/sci/scicore/resource.cpp @@ -65,19 +65,28 @@ const char *sci_error_types[] = { "SCI version is unsupported" }; -const char *sci_resource_types[] = {"view", "pic", "script", "text", "sound", - "memory", "vocab", "font", "cursor", - "patch", "bitmap", "palette", "cdaudio", - "audio", "sync", "message", "map", "heap" - }; // These are the 18 resource types supported by SCI1 +const char *resourceTypeNames[] = { + "view", "pic", "script", "text", "sound", + "memory", "vocab", "font", "cursor", + "patch", "bitmap", "palette", "cdaudio", + "audio", "sync", "message", "map", "heap" +}; -const char *sci_resource_type_suffixes[] = {"v56", "p56", "scr", "tex", "snd", - " ", "voc", "fon", "cur", "pat", - "bit", "pal", "cda", "aud", "syn", - "msg", "map", "hep" - }; +const char *resourceTypeSuffixes[] = { + "v56", "p56", "scr", "tex", "snd", + " ", "voc", "fon", "cur", "pat", + "bit", "pal", "cda", "aud", "syn", + "msg", "map", "hep" +}; +const char *getResourceTypeName(ResourceType restype) { + return resourceTypeNames[restype]; +} + +const char *getResourceTypeSuffix(ResourceType restype) { + return resourceTypeSuffixes[restype]; +} int resourcecmp(const void *first, const void *second); @@ -133,7 +142,7 @@ void ResourceManager::addAltSource(Resource *res, ResourceSource *source, unsign res->alt_sources = rsrc; } -Resource *ResourceManager::findResourceUnsorted(Resource *res, int res_nr, int type, int number) { +Resource *ResourceManager::findResourceUnsorted(Resource *res, int res_nr, ResourceType type, int number) { int i; for (i = 0; i < res_nr; i++) if (res[i].number == number && res[i].type == type) @@ -258,7 +267,7 @@ void ResourceManager::loadResource(Resource *res, bool protect) { if (error) { sciprintf("Error %d occured while reading %s.%03d from resource file: %s\n", - error, sci_resource_types[res->type], res->number, sci_error_types[error]); + error, getResourceTypeName(res->type), res->number, sci_error_types[error]); if (protect) memcpy(res, &backup, sizeof(Resource)); @@ -271,7 +280,7 @@ void ResourceManager::loadResource(Resource *res, bool protect) { } -Resource *ResourceManager::testResource(int type, int number) { +Resource *ResourceManager::testResource(ResourceType type, int number) { Resource binseeker; binseeker.type = type; binseeker.number = number; @@ -290,7 +299,7 @@ int sci_test_view_type(ResourceManager *mgr) { mgr->_sciVersion = SCI_VERSION_AUTODETECT; for (i = 0; i < 1000; i++) { - res = mgr->testResource(sci_view, i); + res = mgr->testResource(kResourceTypeView, i); if (!res) continue; @@ -315,7 +324,7 @@ int sci_test_view_type(ResourceManager *mgr) { // Try the same thing with pics for (i = 0; i < 1000; i++) { - res = mgr->testResource(sci_pic, i); + res = mgr->testResource(kResourceTypePic, i); if (!res) continue; @@ -479,7 +488,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) { if (version == SCI_VERSION_AUTODETECT) switch (resmap_version) { case SCI_VERSION_0: - if (testResource(sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) { + if (testResource(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) { version = sci_test_view_type(this); if (version == SCI_VERSION_01_VGA) { sciprintf("Resmgr: Detected KQ5 or similar\n"); @@ -487,12 +496,12 @@ ResourceManager::ResourceManager(int version, int maxMemory) { sciprintf("Resmgr: Detected SCI0\n"); version = SCI_VERSION_0; } - } else if (testResource(sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) { + } else if (testResource(kResourceTypeVocab, 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 (testResource(sci_vocab, 912)) { + if (testResource(kResourceTypeVocab, 912)) { sciprintf("Resmgr: Running KQ1 or similar, using SCI0 resource encoding\n"); version = SCI_VERSION_0; } else { @@ -515,7 +524,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) { sciprintf("Resmgr: Detected Jones/CD or similar\n"); break; case SCI_VERSION_1: { - Resource *res = testResource(sci_script, 0); + Resource *res = testResource(kResourceTypeScript, 0); _sciVersion = version = SCI_VERSION_1_EARLY; loadResource(res, true); @@ -611,7 +620,7 @@ void ResourceManager::addToLRU(Resource *res) { _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, + getResourceTypeName(res->type), res->number, res->size, mgr->_memoryLRU); #endif @@ -626,7 +635,7 @@ void ResourceManager::printLRU() { while (res) { fprintf(stderr, "\t%s.%03d: %d bytes\n", - sci_resource_types[res->type], res->number, + getResourceTypeName(res->type), res->number, res->size); mem += res->size; ++entries; @@ -650,18 +659,18 @@ void ResourceManager::freeOldResources(int last_invulnerable) { 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); + sciprintf("Resmgr-debug: LRU: Freeing %s.%03d (%d bytes)\n", getResourceTypeName(goner->type), goner->number, goner->size); #endif } } -Resource *ResourceManager::findResource(int type, int number, int lock) { +Resource *ResourceManager::findResource(ResourceType type, int number, int lock) { Resource *retval; if (number >= sci_max_resource_nr[_sciVersion]) { int modded_number = number % sci_max_resource_nr[_sciVersion]; sciprintf("[resmgr] Requested invalid resource %s.%d, mapped to %s.%d\n", - sci_resource_types[type], number, sci_resource_types[type], modded_number); + getResourceTypeName(type), number, getResourceTypeName(type), modded_number); number = modded_number; } @@ -697,23 +706,23 @@ Resource *ResourceManager::findResource(int type, int number, int lock) { if (retval->data) return retval; else { - sciprintf("Resmgr: Failed to read %s.%03d\n", sci_resource_types[retval->type], retval->number); + sciprintf("Resmgr: Failed to read %s.%03d\n", getResourceTypeName(retval->type), retval->number); return NULL; } } -void ResourceManager::unlockResource(Resource *res, int resnum, int restype) { +void ResourceManager::unlockResource(Resource *res, int resnum, ResourceType restype) { if (!res) { - if (restype >= ARRAYSIZE(sci_resource_types)) + if (restype == kResourceTypeInvalid) sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %03d.%03d!\n", restype, resnum); else - sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %s.%03d!\n", sci_resource_types[restype], resnum); + sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %s.%03d!\n", getResourceTypeName(restype), resnum); return; } if (res->status != SCI_STATUS_LOCKED) { sciprintf("Resmgr: Warning: Attempt to unlock unlocked resource %s.%03d\n", - sci_resource_types[res->type], res->number); + getResourceTypeName(res->type), res->number); return; } diff --git a/engines/sci/scicore/resource.h b/engines/sci/scicore/resource.h index 3d74ecb982..abbe6a77ac 100644 --- a/engines/sci/scicore/resource.h +++ b/engines/sci/scicore/resource.h @@ -97,30 +97,48 @@ enum ResSourceType { extern const char *sci_error_types[]; extern const char *sci_version_types[]; -extern const char *sci_resource_types[]; -extern const char *sci_resource_type_suffixes[]; /* Suffixes for SCI1 patch files */ extern const int sci_max_resource_nr[]; /* Highest possible resource numbers */ -enum ResourceTypes { - sci_view = 0, sci_pic, sci_script, sci_text, - sci_sound, sci_memory, sci_vocab, sci_font, - sci_cursor, sci_patch, sci_bitmap, sci_palette, - sci_cdaudio, sci_audio, sci_sync, sci_message, - sci_map, sci_heap, sci_invalid_resource +enum ResourceType { + kResourceTypeView = 0, + kResourceTypePic, + kResourceTypeScript, + kResourceTypeText, + kResourceTypeSound, + kResourceTypeMemory, + kResourceTypeVocab, + kResourceTypeFont, + kResourceTypeCursor, + kResourceTypePatch, + kResourceTypeBitmap, + kResourceTypePalette, + kResourceTypeCdAudio, + kResourceTypeAudio, + kResourceTypeSync, + kResourceTypeMessage, + kResourceTypeMap, + kResourceTypeHeap, + kResourceTypeInvalid }; -#define sci0_last_resource sci_patch -#define sci1_last_resource sci_heap +const char *getResourceTypeName(ResourceType restype); +// Suffixes for SCI1 patch files +const char *getResourceTypeSuffix(ResourceType restype); + +#define sci0_last_resource kResourceTypePatch +#define sci1_last_resource kResourceTypeHeap /* Used for autodetection */ +#if 0 struct resource_index_struct { unsigned short resource_id; unsigned int resource_location; }; /* resource type as stored in the resource.map file */ typedef struct resource_index_struct resource_index_t; +#endif struct ResourceSource { ResSourceType source_type; @@ -147,7 +165,7 @@ public: // to let the rest of the engine compile without changes unsigned char *data; unsigned short number; - unsigned short type; + ResourceType type; uint16 id; /* contains number and type */ unsigned int size; unsigned int file_offset; /* Offset in file */ @@ -163,6 +181,7 @@ public: class ResourceManager { public: int _sciVersion; /* SCI resource version to use */ + /** * Creates a new FreeSCI resource manager. * @param version The SCI version to look for; use SCI_VERSION_AUTODETECT @@ -180,7 +199,9 @@ public: ** 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 @@ -190,17 +211,20 @@ public: */ 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 @@ -209,16 +233,18 @@ public: * @note Locked resources are guaranteed not to have their contents freed until * they are unlocked explicitly (by unlockResource). */ - Resource *findResource(int type, int number, int lock); + Resource *findResource(ResourceType type, int number, int lock); + /* Unlocks a previously locked resource ** (Resource *) 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) + ** (ResourceType) type: Type of the resource to check (for error checking) ** Returns : (void) */ - void unlockResource(Resource *res, int restype, int resnum); + void unlockResource(Resource *res, int restype, ResourceType resnum); + /* Tests whether a resource exists - ** (int) type: Type of the resource to check + ** (ResourceType) type: Type of the resource to check ** (int) number: Number of the resource to check ** Returns : (Resource *) non-NULL if the resource exists, NULL otherwise ** This function may often be much faster than finding the resource @@ -227,7 +253,7 @@ public: ** 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 *testResource(int type, int number); + Resource *testResource(ResourceType type, int number); protected: int _maxMemory; /* Config option: Maximum total byte number allocated */ @@ -239,24 +265,25 @@ protected: Resource *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 *) resources: The resources to free ** (int) _resourcesNr: Number of resources in the block ** Returns : (void) */ void freeResources(Resource *resources, int _resourcesNr); + /* Finds a resource matching type.number in an unsorted Resource block ** To be used during initial resource loading, when the resource list ** may not have been sorted yet. ** Parameters: (Resource *) res: Pointer to the block to search in ** (int) res_nr: Number of Resource structs allocated and defined ** in the block pointed to by res - ** (int) type: Type of the resource to look for + ** (ResourceType) type: Type of the resource to look for ** (int) number: Number of the resource to look for ** Returns : (Resource) The matching resource entry, or NULL if not found */ - Resource *findResourceUnsorted(Resource *res, int res_nr, int type, int number); + Resource *findResourceUnsorted(Resource *res, int res_nr, ResourceType type, int number); + /* Adds an alternative source to a resource ** Parameters: (Resource *) res: The resource to add to ** (ResourceSource *) source: The source of the resource @@ -264,8 +291,9 @@ protected: ** is stored at ** Returns : (void) */ - int addAppropriateSources(); void addAltSource(Resource *res, ResourceSource *source, unsigned int file_offset); + + int addAppropriateSources(); void freeResourceSources(ResourceSource *rss); void freeAltSources(resource_altsource_t *dynressrc); @@ -282,17 +310,19 @@ protected: ** 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 *res, int sci_version); - int resTypeSCI1(int ofs, int *types, int lastrt); - int parseHeaderSCI1(Common::ReadStream &stream, int *types, int *lastrt); + ResourceType resTypeSCI1(int ofs, int *types, ResourceType lastrt); + int parseHeaderSCI1(Common::ReadStream &stream, int *types, ResourceType *lastrt); /**--- Patch management functions ---*/ @@ -319,8 +349,9 @@ protected: ** 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 process_patch(ResourceSource *source, Common::ArchiveMember &member, + ResourceType restype, int resnumber); void printLRU(); void addToLRU(Resource *res); @@ -372,7 +403,6 @@ protected: ** encountered. */ - int decompress11(Resource *result, Common::ReadStream &stream, int sci_version); /* Decrypts resource data and stores the result for SCI1.1-style compression. ** Parameters : result: The Resource the decompressed data is stored in. @@ -382,7 +412,6 @@ protected: ** encountered. */ - int decrypt2(uint8* dest, uint8* src, int length, int complength); /* Huffman token decryptor - defined in decompress0.c and used in decompress01.c */ diff --git a/engines/sci/scicore/resource_map.cpp b/engines/sci/scicore/resource_map.cpp index dc2ad4f8bb..cb07c97d16 100644 --- a/engines/sci/scicore/resource_map.cpp +++ b/engines/sci/scicore/resource_map.cpp @@ -121,7 +121,7 @@ int ResourceManager::detectOddSCI01(Common::File &file) { int ResourceManager::resReadEntry(ResourceSource *map, byte *buf, Resource *res, int sci_version) { res->id = buf[0] | (buf[1] << 8); - res->type = SCI0_RESID_GET_TYPE(buf); + res->type = (ResourceType)SCI0_RESID_GET_TYPE(buf); res->number = SCI0_RESID_GET_NUMBER(buf); res->status = SCI_STATUS_NOMALLOC; @@ -156,20 +156,20 @@ int ResourceManager::resReadEntry(ResourceSource *map, byte *buf, Resource *res, return 0; } -int ResourceManager::resTypeSCI1(int ofs, int *types, int lastrt) { - int i, last = -1; +ResourceType ResourceManager::resTypeSCI1(int ofs, int *types, ResourceType lastrt) { + ResourceType last = kResourceTypeInvalid; - for (i = 0; i <= sci1_last_resource;i++) + for (int i = 0; i <= sci1_last_resource; i++) if (types[i]) { if (types[i] > ofs) return last; - last = i; + last = (ResourceType)i; } return lastrt; } -int ResourceManager::parseHeaderSCI1(Common::ReadStream &stream, int *types, int *lastrt) { +int ResourceManager::parseHeaderSCI1(Common::ReadStream &stream, int *types, ResourceType *lastrt) { unsigned char rtype; unsigned char offset[2]; int read_ok; @@ -184,7 +184,7 @@ int ResourceManager::parseHeaderSCI1(Common::ReadStream &stream, int *types, int read_ok = 0; if (rtype != 0xff) { types[rtype&0x7f] = (offset[1] << 8) | (offset[0]); - *lastrt = rtype & 0x7f; + *lastrt = (ResourceType)(rtype & 0x7f); } size += 3; } while (read_ok && (rtype != 0xFF)); @@ -344,7 +344,7 @@ int ResourceManager::isSCI10or11(int *types) { int this_restype = 0; int next_restype = 1; - while (next_restype <= sci_heap) { + while (next_restype <= kResourceTypeHeap) { int could_be_10 = 0; int could_be_11 = 0; @@ -381,7 +381,7 @@ int ResourceManager::readResourceMapSCI1(ResourceSource *map, ResourceSource *vo int *types = (int *)sci_malloc(sizeof(int) * (sci1_last_resource + 1)); int i; byte buf[SCI1_RESMAP_ENTRIES_SIZE]; - int lastrt; + ResourceType lastrt; int entrysize; int entry_size_selector; diff --git a/engines/sci/scicore/resource_patch.cpp b/engines/sci/scicore/resource_patch.cpp index 05d97f5e48..2cbeb2b52c 100644 --- a/engines/sci/scicore/resource_patch.cpp +++ b/engines/sci/scicore/resource_patch.cpp @@ -32,19 +32,19 @@ namespace Sci { void sci0_sprintf_patch_file_name(char *string, Resource *res) { - sprintf(string, "%s.%03i", sci_resource_types[res->type], res->number); + sprintf(string, "%s.%03i", getResourceTypeName(res->type), res->number); } void sci1_sprintf_patch_file_name(char *string, Resource *res) { - sprintf(string, "%d.%s", res->number, sci_resource_type_suffixes[res->type]); + sprintf(string, "%d.%s", res->number, getResourceTypeSuffix(res->type)); } // version-agnostic patch application void ResourceManager::process_patch(ResourceSource *source, - Common::ArchiveMember &member, int restype, int resnumber) { + Common::ArchiveMember &member, ResourceType restype, int resnumber) { Common::File file; - if (restype == sci_invalid_resource) + if (restype == kResourceTypeInvalid) return; printf("Patching \"%s\": ", member.getName().c_str()); @@ -103,28 +103,26 @@ int ResourceManager::readResourcePatchesSCI0(ResourceSource *source) { for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { const Common::String name = (*x)->getName(); - int restype = sci_invalid_resource; + ResourceType restype = kResourceTypeInvalid; int resnumber = -1; - int i; unsigned int resname_len; char *endptr; - for (i = sci_view; i < sci_invalid_resource; i++) - if (scumm_strnicmp(sci_resource_types[i], name.c_str(), strlen(sci_resource_types[i])) == 0) - restype = i; + for (int i = kResourceTypeView; i < kResourceTypeInvalid; i++) + if (scumm_strnicmp(getResourceTypeName((ResourceType)i), name.c_str(), strlen(getResourceTypeName((ResourceType)i))) == 0) + restype = (ResourceType)i; - if (restype != sci_invalid_resource) { - - resname_len = strlen(sci_resource_types[restype]); + if (restype != kResourceTypeInvalid) { + resname_len = strlen(getResourceTypeName(restype)); if (name[resname_len] != '.') - restype = sci_invalid_resource; + restype = kResourceTypeInvalid; else { resnumber = strtol(name.c_str() + 1 + resname_len, &endptr, 10); // Get resource number if ((*endptr != '\0') || (resname_len + 1 == name.size())) - restype = sci_invalid_resource; + restype = kResourceTypeInvalid; if ((resnumber < 0) || (resnumber > 1000)) - restype = sci_invalid_resource; + restype = kResourceTypeInvalid; } } @@ -140,31 +138,30 @@ int ResourceManager::readResourcePatchesSCI1(ResourceSource *source) { for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) { const Common::String name = (*x)->getName(); - int restype = sci_invalid_resource; + ResourceType restype = kResourceTypeInvalid; int resnumber = -1; - int i; char *endptr; const char *dot = strchr(name.c_str(), '.'); - for (i = sci_view; i < sci_invalid_resource; i++) { + for (int i = kResourceTypeView; i < kResourceTypeInvalid; i++) { if (dot != NULL) { - if (scumm_strnicmp(sci_resource_type_suffixes[i], dot + 1, 3) == 0) { - restype = i; + if (scumm_strnicmp(getResourceTypeSuffix((ResourceType)i), dot + 1, 3) == 0) { + restype = (ResourceType)i; } } } - if (restype != sci_invalid_resource) { + if (restype != kResourceTypeInvalid) { resnumber = strtol(name.c_str(), &endptr, 10); // Get resource number if (endptr != dot) - restype = sci_invalid_resource; + restype = kResourceTypeInvalid; if (*(dot + 4) != '\0') - restype = sci_invalid_resource; + restype = kResourceTypeInvalid; if ((resnumber < 0) || (resnumber > 8192)) - restype = sci_invalid_resource; + restype = kResourceTypeInvalid; } process_patch(source, **x, restype, resnumber); diff --git a/engines/sci/scicore/script.cpp b/engines/sci/scicore/script.cpp index ab8259c7ec..6651dfdcde 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 *script = resmgr->findResource(sci_script, res_no, 0); + Resource *script = resmgr->findResource(kResourceTypeScript, res_no, 0); word_t **words; int word_count; diff --git a/engines/sci/scicore/vocab.cpp b/engines/sci/scicore/vocab.cpp index e6d242328c..9af387b967 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 *resource; // First try to load the SCI0 vocab resource. - resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB, 0); + resource = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SCI0_MAIN_VOCAB, 0); vocab_version = 0; if (!resource) { warning("SCI0: Could not find a main vocabulary, trying SCI01"); - resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SCI1_MAIN_VOCAB, 0); + resource = resmgr->findResource(kResourceTypeVocab, 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 *resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1); + Resource *resource = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1); unsigned int seeker = 1; if (!resource) { @@ -226,8 +226,8 @@ suffix_t **vocab_get_suffices(ResourceManager *resmgr, int *suffices_nr) { void vocab_free_suffices(ResourceManager *resmgr, suffix_t **suffices, int suffices_nr) { int i; - resmgr->unlockResource(resmgr->findResource(sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0), - VOCAB_RESOURCE_SUFFIX_VOCAB, sci_vocab); + resmgr->unlockResource(resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0), + VOCAB_RESOURCE_SUFFIX_VOCAB, kResourceTypeVocab); for (i = 0; i < suffices_nr; i++) free(suffices[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 *resource = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_PARSE_TREE_BRANCHES, 0); + Resource *resource = resmgr->findResource(kResourceTypeVocab, 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 a2e2739a8f..622dbe559d 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 = resmgr->findResource(sci_vocab, 996, 0)) == NULL) + if ((r = resmgr->findResource(kResourceTypeVocab, 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* r; - if ((r = resmgr->findResource(sci_vocab, 996, 0)) == 0) + if ((r = resmgr->findResource(kResourceTypeVocab, 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 *r = resmgr->findResource(sci_vocab, 997, 0); + Resource *r = resmgr->findResource(kResourceTypeVocab, 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* r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_OPCODES, 0); + Resource* r = resmgr->findResource(kResourceTypeVocab, 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 *r) { static char **vocabulary_get_knames0(ResourceManager *resmgr, int* names) { char** t; int count, i, index = 2, empty_to_add = 1; - Resource *r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_KNAMES, 0); + Resource *r = resmgr->findResource(kResourceTypeVocab, 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 *r = resmgr->findResource(sci_vocab, VOCAB_RESOURCE_KNAMES, 0); + Resource *r = resmgr->findResource(kResourceTypeVocab, VOCAB_RESOURCE_KNAMES, 0); while (pos < r->size) { int len; diff --git a/engines/sci/sfx/player/polled.cpp b/engines/sci/sfx/player/polled.cpp index 2d9f4903e7..5519482b89 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 = resmgr->findResource(sci_patch, seq->patch_nr, 0); + res = resmgr->findResource(kResourceTypePatch, seq->patch_nr, 0); } if (seq->patch2_nr != SFX_SEQ_PATCHFILE_NONE) { - res2 = resmgr->findResource(sci_patch, seq->patch2_nr, 0); + res2 = resmgr->findResource(kResourceTypePatch, 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 59950bb9ad..bbdebbd305 100644 --- a/engines/sci/sfx/player/realtime.cpp +++ b/engines/sci/sfx/player/realtime.cpp @@ -132,7 +132,7 @@ static Resource *find_patch(ResourceManager *resmgr, const char *seq_name, int p Resource *res = NULL; if (patchfile != SFX_SEQ_PATCHFILE_NONE) { - res = resmgr->findResource(sci_patch, patchfile, 0); + res = resmgr->findResource(kResourceTypePatch, patchfile, 0); if (!res) { fprintf(stderr, "[SFX] " __FILE__": patch.%03d requested by sequencer (%s), but not found\n", patchfile, seq_name); |