diff options
Diffstat (limited to 'saga')
-rw-r--r-- | saga/scene.cpp | 565 | ||||
-rw-r--r-- | saga/scene.h | 107 | ||||
-rw-r--r-- | saga/scene_mod.h | 52 |
3 files changed, 171 insertions, 553 deletions
diff --git a/saga/scene.cpp b/saga/scene.cpp index e2c9aa6f05..7a525174fe 100644 --- a/saga/scene.cpp +++ b/saga/scene.cpp @@ -20,21 +20,13 @@ * $Header$ * */ -/* - Description: - - Scene management module - Notes: -*/ +// Scene management module #include "reinherit.h" #include "yslib.h" -/* - * Uses the following modules: -\*--------------------------------------------------------------------------*/ #include "game_mod.h" #include "animation_mod.h" #include "console_mod.h" @@ -51,9 +43,6 @@ #include "rscfile_mod.h" #include "text_mod.h" -/* - * Begin module component -\*--------------------------------------------------------------------------*/ #include "scene_mod.h" #include "scene.h" @@ -61,86 +50,57 @@ namespace Saga { static R_SCENE_MODULE SceneModule; -int SCENE_Register(void) -{ - - CVAR_Register_I(&SceneModule.scene_number, - "scene", NULL, R_CVAR_READONLY, 0, 0); - - CVAR_RegisterFunc(CF_scenechange, - "scene_change", "<Scene number>", R_CVAR_NONE, 1, 1); - +int SCENE_Register() { + CVAR_Register_I(&SceneModule.scene_number, "scene", NULL, R_CVAR_READONLY, 0, 0); + CVAR_RegisterFunc(CF_scenechange, "scene_change", "<Scene number>", R_CVAR_NONE, 1, 1); CVAR_RegisterFunc(CF_sceneinfo, "scene_info", NULL, R_CVAR_NONE, 0, 0); return R_SUCCESS; } -int SCENE_Init(void) -{ - +int SCENE_Init() { R_GAME_SCENEDESC gs_desc; - byte *scene_lut_p; size_t scene_lut_len; - const byte *read_p; - int result; int i; - /* Load game-specific scene data - * \*------------------------------------------------------------ */ + // Load game-specific scene data GAME_GetSceneInfo(&gs_desc); - /* Load scene module resource context - * \*------------------------------------------------------------ */ - result = GAME_GetFileContext(&SceneModule.scene_ctxt, - R_GAME_RESOURCEFILE, 0); + // Load scene module resource context + result = GAME_GetFileContext(&SceneModule.scene_ctxt, R_GAME_RESOURCEFILE, 0); if (result != R_SUCCESS) { - R_printf(R_STDERR, "Couldn't load scene resource context.\n"); - return R_FAILURE; } - /* Initialize scene queue - * \*------------------------------------------------------------ */ + // Initialize scene queue SceneModule.scene_queue = ys_dll_create(); if (SceneModule.scene_queue == NULL) { - return R_FAILURE; } - /* Load scene lookup table - * \*------------------------------------------------------------ */ - R_printf(R_STDOUT, - "SCENE_Init(): Loading scene LUT from resource %u.\n", - gs_desc.scene_lut_rn); - - result = RSC_LoadResource(SceneModule.scene_ctxt, - gs_desc.scene_lut_rn, &scene_lut_p, &scene_lut_len); + // Load scene lookup table + R_printf(R_STDOUT, "SCENE_Init(): Loading scene LUT from resource %u.\n", gs_desc.scene_lut_rn); + result = RSC_LoadResource(SceneModule.scene_ctxt, gs_desc.scene_lut_rn, &scene_lut_p, &scene_lut_len); if (result != R_SUCCESS) { - R_printf(R_STDERR, "Error: couldn't load scene LUT.\n"); - return R_FAILURE; } SceneModule.scene_count = scene_lut_len / 2; SceneModule.scene_max = SceneModule.scene_count - 1; - - SceneModule.scene_lut = (int *)malloc(SceneModule.scene_max * - sizeof *SceneModule.scene_lut); + SceneModule.scene_lut = (int *)malloc(SceneModule.scene_max * sizeof *SceneModule.scene_lut); if (SceneModule.scene_lut == NULL) { - R_printf(R_STDERR, - "SCENE_Init(): Memory allocation failed.\n"); + R_printf(R_STDERR, "SCENE_Init(): Memory allocation failed.\n"); return R_MEM; } read_p = scene_lut_p; for (i = 0; i < SceneModule.scene_max; i++) { - SceneModule.scene_lut[i] = ys_read_u16_le(read_p, &read_p); } @@ -153,17 +113,13 @@ int SCENE_Init(void) R_printf(R_STDOUT, "SCENE_Init(): First scene set to %d.\n", SceneModule.first_scene); - R_printf(R_STDOUT, - "SCENE_Init(): LUT has %d entries.\n", SceneModule.scene_max); + R_printf(R_STDOUT, "SCENE_Init(): LUT has %d entries.\n", SceneModule.scene_max); - /* Create scene module text list - * \*------------------------------------------------------------ */ + // Create scene module text list SceneModule.text_list = TEXT_CreateList(); if (SceneModule.text_list == NULL) { - R_printf(R_STDERR, - "Error: Couldn't create scene text list.\n"); - + R_printf(R_STDERR, "Error: Couldn't create scene text list.\n"); return R_FAILURE; } @@ -172,9 +128,7 @@ int SCENE_Init(void) return R_SUCCESS; } -int SCENE_Shutdown(void) -{ - +int SCENE_Shutdown() { if (SceneModule.init) { SCENE_End(); free(SceneModule.scene_lut); @@ -183,19 +137,16 @@ int SCENE_Shutdown(void) return R_SUCCESS; } -int SCENE_Queue(R_SCENE_QUEUE * scene_queue) -{ +int SCENE_Queue(R_SCENE_QUEUE *scene_queue) { assert(SceneModule.init); assert(scene_queue != NULL); - ys_dll_add_tail(SceneModule.scene_queue, - scene_queue, sizeof *scene_queue); + ys_dll_add_tail(SceneModule.scene_queue, scene_queue, sizeof *scene_queue); return R_SUCCESS; } -int SCENE_ClearQueue(void) -{ +int SCENE_ClearQueue() { assert(SceneModule.init); ys_dll_delete_all(SceneModule.scene_queue); @@ -203,46 +154,35 @@ int SCENE_ClearQueue(void) return R_SUCCESS; } -int SCENE_Start(void) -{ - +int SCENE_Start() { YS_DL_NODE *node; R_SCENE_QUEUE *scene_qdat; assert(SceneModule.init); if (SceneModule.scene_loaded) { - R_printf(R_STDERR, - "Error: Can't start game...scene already loaded!\n"); - + R_printf(R_STDERR, "Error: Can't start game...scene already loaded!\n"); return R_FAILURE; } if (SceneModule.in_game) { - R_printf(R_STDERR, - "Error: Can't start game...game already started!\n"); - + R_printf(R_STDERR, "Error: Can't start game...game already started!\n"); return R_FAILURE; } switch (GAME_GetGameType()) { - case R_GAMETYPE_ITE: ITE_StartProc(); break; - case R_GAMETYPE_IHNM: IHNM_StartProc(); break; - default: - R_printf(R_STDERR, - "Error: Can't start game... gametype not supported.\n"); + R_printf(R_STDERR, "Error: Can't start game... gametype not supported.\n"); break; } - /* Load the head node in scene queue - * \*------------------------------------------------------------- */ + // Load the head node in scene queue node = ys_dll_head(SceneModule.scene_queue); if (node == NULL) { return R_SUCCESS; @@ -251,39 +191,30 @@ int SCENE_Start(void) scene_qdat = (R_SCENE_QUEUE *)ys_dll_get_data(node); assert(scene_qdat != NULL); - SCENE_Load(scene_qdat->scene_n, - scene_qdat->load_flag, - scene_qdat->scene_proc, scene_qdat->scene_desc); + SCENE_Load(scene_qdat->scene_n, scene_qdat->load_flag, scene_qdat->scene_proc, scene_qdat->scene_desc); return R_SUCCESS; } -int SCENE_Next(void) -{ - +int SCENE_Next() { YS_DL_NODE *node; R_SCENE_QUEUE *scene_qdat; assert(SceneModule.init); if (!SceneModule.scene_loaded) { - R_printf(R_STDERR, - "Error: Can't advance scene...no scene loaded!\n"); - + R_printf(R_STDERR, "Error: Can't advance scene...no scene loaded!\n"); return R_FAILURE; } if (SceneModule.in_game) { - R_printf(R_STDERR, - "Error: Can't advance scene...game already started!\n"); - + R_printf(R_STDERR, "Error: Can't advance scene...game already started!\n"); return R_FAILURE; } SCENE_End(); - /* Delete the current head node in scene queue - * \*------------------------------------------------------------- */ + // Delete the current head node in scene queue node = ys_dll_head(SceneModule.scene_queue); if (node == NULL) { return R_SUCCESS; @@ -291,8 +222,7 @@ int SCENE_Next(void) ys_dll_delete(node); - /* Load the head node in scene queue - * \*------------------------------------------------------------- */ + // Load the head node in scene queue node = ys_dll_head(SceneModule.scene_queue); if (node == NULL) { return R_SUCCESS; @@ -301,16 +231,12 @@ int SCENE_Next(void) scene_qdat = (R_SCENE_QUEUE *)ys_dll_get_data(node); assert(scene_qdat != NULL); - SCENE_Load(scene_qdat->scene_n, - scene_qdat->load_flag, - scene_qdat->scene_proc, scene_qdat->scene_desc); + SCENE_Load(scene_qdat->scene_n, scene_qdat->load_flag, scene_qdat->scene_proc, scene_qdat->scene_desc); return R_SUCCESS; } -int SCENE_Skip(void) -{ - +int SCENE_Skip() { YS_DL_NODE *node; YS_DL_NODE *prev_node; YS_DL_NODE *skip_node = NULL; @@ -321,96 +247,62 @@ int SCENE_Skip(void) assert(SceneModule.init); if (!SceneModule.scene_loaded) { - - R_printf(R_STDERR, - "Error: Can't skip scene...no scene loaded.\n"); - + R_printf(R_STDERR, "Error: Can't skip scene...no scene loaded.\n"); return R_FAILURE; } if (SceneModule.in_game) { - - R_printf(R_STDERR, - "Error: Can't skip scene...game already started.\n"); - + R_printf(R_STDERR, "Error: Can't skip scene...game already started.\n"); return R_FAILURE; } - /* Walk down scene queue and try to find a skip target - * \*------------------------------------------------------------- */ + // Walk down scene queue and try to find a skip target node = ys_dll_head(SceneModule.scene_queue); if (node == NULL) { - - R_printf(R_STDERR, - "Error: Can't skip scene...no scenes in queue.\n"); - + R_printf(R_STDERR, "Error: Can't skip scene...no scenes in queue.\n"); return R_FAILURE; } for (node = ys_dll_next(node); node != NULL; node = ys_dll_next(node)) { - scene_qdat = (R_SCENE_QUEUE *)ys_dll_get_data(node); assert(scene_qdat != NULL); if (scene_qdat->scene_skiptarget) { - skip_node = node; skip_qdat = scene_qdat; break; } } - /* If skip target found, remove preceding scenes and load - * \*------------------------------------------------------------- */ + // If skip target found, remove preceding scenes and load if (skip_node != NULL) { - - for (node = ys_dll_prev(skip_node); - node != NULL; node = prev_node) { - + for (node = ys_dll_prev(skip_node); node != NULL; node = prev_node) { prev_node = ys_dll_prev(node); - ys_dll_delete(node); } - SCENE_End(); - - SCENE_Load(skip_qdat->scene_n, - skip_qdat->load_flag, - skip_qdat->scene_proc, skip_qdat->scene_desc); + SCENE_Load(skip_qdat->scene_n, skip_qdat->load_flag, skip_qdat->scene_proc, skip_qdat->scene_desc); } - - /* Search for a scene to skip to */ + // Search for a scene to skip to return R_SUCCESS; } -int SCENE_Change(int scene_num) -{ - +int SCENE_Change(int scene_num) { assert(SceneModule.init); if (!SceneModule.scene_loaded) { - R_printf(R_STDERR, - "Error: Can't change scene. No scene currently loaded. " - "Game in invalid state.\n"); - + R_printf(R_STDERR, "Error: Can't change scene. No scene currently loaded. Game in invalid state.\n"); return R_FAILURE; } if ((scene_num < 0) || (scene_num > SceneModule.scene_max)) { - - R_printf(R_STDERR, - "Error: Can't change scene. Invalid scene number.\n"); - + R_printf(R_STDERR, "Error: Can't change scene. Invalid scene number.\n"); return R_FAILURE; } if (SceneModule.scene_lut[scene_num] == 0) { - - R_printf(R_STDERR, - "Error: Can't change scene; invalid scene descriptor " - "resource number (0)\n"); - + R_printf(R_STDERR, "Error: Can't change scene; invalid scene descriptor resource number (0)\n"); return R_FAILURE; } @@ -420,16 +312,13 @@ int SCENE_Change(int scene_num) return R_SUCCESS; } -int SCENE_GetMode(void) -{ +int SCENE_GetMode() { assert(SceneModule.init); return SceneModule.scene_mode; } -int SCENE_GetZInfo(SCENE_ZINFO * zinfo) -{ - +int SCENE_GetZInfo(SCENE_ZINFO *zinfo) { assert(SceneModule.init); zinfo->begin_slope = SceneModule.desc.begin_slope; @@ -438,8 +327,7 @@ int SCENE_GetZInfo(SCENE_ZINFO * zinfo) return R_SUCCESS; } -int SCENE_GetBGInfo(SCENE_BGINFO * bginfo) -{ +int SCENE_GetBGInfo(SCENE_BGINFO *bginfo) { R_GAME_DISPLAYINFO di; int x, y; @@ -469,18 +357,14 @@ int SCENE_GetBGInfo(SCENE_BGINFO * bginfo) return R_SUCCESS; } -int SCENE_GetBGPal(PALENTRY ** pal) -{ +int SCENE_GetBGPal(PALENTRY **pal) { assert(SceneModule.init); - *pal = SceneModule.bg.pal; return R_SUCCESS; } -int SCENE_GetBGMaskInfo(int *w, int *h, byte ** buf, size_t * buf_len) -{ - +int SCENE_GetBGMaskInfo(int *w, int *h, byte **buf, size_t *buf_len) { assert(SceneModule.init); if (!SceneModule.bg_mask.loaded) { @@ -495,16 +379,13 @@ int SCENE_GetBGMaskInfo(int *w, int *h, byte ** buf, size_t * buf_len) return R_SUCCESS; } -int SCENE_IsBGMaskPresent(void) -{ - +int SCENE_IsBGMaskPresent() { assert(SceneModule.init); return SceneModule.bg_mask.loaded; } -int SCENE_GetInfo(R_SCENE_INFO * si) -{ +int SCENE_GetInfo(R_SCENE_INFO *si) { assert(SceneModule.init); assert(si != NULL); @@ -513,11 +394,7 @@ int SCENE_GetInfo(R_SCENE_INFO * si) return R_SUCCESS; } -int -SCENE_Load(int scene_num, - int load_flag, R_SCENE_PROC scene_proc, R_SCENE_DESC * scene_desc_param) -{ - +int SCENE_Load(int scene_num, int load_flag, R_SCENE_PROC scene_proc, R_SCENE_DESC *scene_desc_param) { R_SCENE_INFO scene_info; uint32 res_number = 0; int result; @@ -526,7 +403,6 @@ SCENE_Load(int scene_num, assert(SceneModule.init); if (SceneModule.scene_loaded == 1) { - R_printf(R_STDERR, "Error, a scene is already loaded.\n"); return R_FAILURE; } @@ -536,102 +412,67 @@ SCENE_Load(int scene_num, SceneModule.load_desc = 1; switch (load_flag) { - case BY_RESOURCE: res_number = scene_num; break; - case BY_SCENE: assert((scene_num > 0) && (scene_num < SceneModule.scene_max)); - res_number = SceneModule.scene_lut[scene_num]; SceneModule.scene_number = scene_num; break; - case BY_DESC: - assert(scene_desc_param != NULL); assert(scene_desc_param->res_list != NULL); - SceneModule.load_desc = 0; - SceneModule.desc = *scene_desc_param; SceneModule.reslist = scene_desc_param->res_list; SceneModule.reslist_entries = scene_desc_param->res_list_ct; break; - default: R_printf(R_STDERR, "Error: Invalid scene load flag.\n"); return R_FAILURE; break; - } - /* - * Load scene descriptor and resource list resources - \*-------------------------------------------------------------*/ + // Load scene descriptor and resource list resources if (SceneModule.load_desc) { SceneModule.scene_rn = res_number; assert(SceneModule.scene_rn != 0); - R_printf(R_STDOUT, "Loading scene resource %u:\n", res_number); if (LoadSceneDescriptor(res_number) != R_SUCCESS) { - R_printf(R_STDERR, - "Error reading scene descriptor.\n"); - + R_printf(R_STDERR, "Error reading scene descriptor.\n"); return R_FAILURE; } - if (LoadSceneResourceList(SceneModule.desc.res_list_rn) - != R_SUCCESS) { - - R_printf(R_STDERR, - "Error reading scene resource list.\n"); - + if (LoadSceneResourceList(SceneModule.desc.res_list_rn) != R_SUCCESS) { + R_printf(R_STDERR, "Error reading scene resource list.\n"); return R_FAILURE; } } else { - R_printf(R_STDOUT, "Loading memory scene resource.\n"); } - /* - * Load resources from scene resource list - \*-------------------------------------------------------------*/ + // Load resources from scene resource list for (i = 0; i < SceneModule.reslist_entries; i++) { - - result = RSC_LoadResource(SceneModule.scene_ctxt, - SceneModule.reslist[i].res_number, - &SceneModule.reslist[i].res_data, - &SceneModule.reslist[i].res_data_len); + result = RSC_LoadResource(SceneModule.scene_ctxt, SceneModule.reslist[i].res_number, + &SceneModule.reslist[i].res_data, &SceneModule.reslist[i].res_data_len); if (result != R_SUCCESS) { - - R_printf(R_STDERR, - "Error: Allocation failure loading scene " - "resource list.\n"); - + R_printf(R_STDERR, "Error: Allocation failure loading scene resource list.\n"); return R_FAILURE; } - } - /* - * Process resources from scene resource list - \*-------------------------------------------------------------*/ + // Process resources from scene resource list if (ProcessSceneResources() != R_SUCCESS) { - R_printf(R_STDERR, "Error loading scene resources.\n"); - return R_FAILURE; } - /* Load scene script data */ + // Load scene script data if (SceneModule.desc.script_num > 0) { - if (SCRIPT_Load(SceneModule.desc.script_num) != R_SUCCESS) { - R_printf(R_STDERR, "Error loading scene script.\n"); return R_FAILURE; } @@ -652,28 +493,20 @@ SCENE_Load(int scene_num, return R_SUCCESS; } -int LoadSceneDescriptor(uint32 res_number) -{ - +int LoadSceneDescriptor(uint32 res_number) { byte *scene_desc_data; size_t scene_desc_len; - const byte *read_p; - int result; - result = RSC_LoadResource(SceneModule.scene_ctxt, - res_number, &scene_desc_data, &scene_desc_len); + result = RSC_LoadResource(SceneModule.scene_ctxt, res_number, &scene_desc_data, &scene_desc_len); if (result != R_SUCCESS) { R_printf(R_STDERR, "Error: couldn't load scene descriptor.\n"); - return R_FAILURE; } if (scene_desc_len != SAGA_SCENE_DESC_LEN) { - R_printf(R_STDERR, - "Error: scene descriptor length invalid.\n"); - + R_printf(R_STDERR, "Error: scene descriptor length invalid.\n"); return R_FAILURE; } @@ -686,7 +519,6 @@ int LoadSceneDescriptor(uint32 res_number) SceneModule.desc.script_num = ys_read_u16_le(read_p, &read_p); SceneModule.desc.scene_scriptnum = ys_read_u16_le(read_p, &read_p); SceneModule.desc.start_scriptnum = ys_read_u16_le(read_p, &read_p); - SceneModule.desc.music_rn = ys_read_s16_le(read_p, &read_p); RSC_FreeResource(scene_desc_data); @@ -694,61 +526,39 @@ int LoadSceneDescriptor(uint32 res_number) return R_SUCCESS; } -int LoadSceneResourceList(uint32 reslist_rn) -{ - +int LoadSceneResourceList(uint32 reslist_rn) { byte *resource_list; size_t resource_list_len; - const byte *read_p; - int result; int i; - /* - * Load the scene resource table - \*-------------------------------------------------------------*/ - result = RSC_LoadResource(SceneModule.scene_ctxt, - reslist_rn, &resource_list, &resource_list_len); + // Load the scene resource table + result = RSC_LoadResource(SceneModule.scene_ctxt, reslist_rn, &resource_list, &resource_list_len); if (result != R_SUCCESS) { - - R_printf(R_STDERR, - "Error: couldn't load scene resource list.\n"); - + R_printf(R_STDERR, "Error: couldn't load scene resource list.\n"); return R_FAILURE; } read_p = resource_list; - /* Allocate memory for scene resource list - * \*----------------------------------------- */ - SceneModule.reslist_entries = - resource_list_len / SAGA_RESLIST_ENTRY_LEN; - - R_printf(R_STDOUT, - "Scene resource list contains %d entries.\n", - SceneModule.reslist_entries); - - SceneModule.reslist = - (R_SCENE_RESLIST *)calloc(SceneModule.reslist_entries, sizeof *SceneModule.reslist); + // Allocate memory for scene resource list + SceneModule.reslist_entries = resource_list_len / SAGA_RESLIST_ENTRY_LEN; + R_printf(R_STDOUT, "Scene resource list contains %d entries.\n", SceneModule.reslist_entries); + SceneModule.reslist = (R_SCENE_RESLIST *)calloc(SceneModule.reslist_entries, sizeof *SceneModule.reslist); if (SceneModule.reslist == NULL) { R_printf(R_STDERR, "Error: Memory allocation failed.\n"); - return R_MEM; } - /* Load scene resource list from raw scene - * resource table - \*-----------------------------------------*/ + // Load scene resource list from raw scene + // resource table R_printf(R_STDOUT, "Loading scene resource list...\n"); for (i = 0; i < SceneModule.reslist_entries; i++) { - - SceneModule.reslist[i].res_number = - ys_read_u16_le(read_p, &read_p); - SceneModule.reslist[i].res_type = - ys_read_u16_le(read_p, &read_p); + SceneModule.reslist[i].res_number = ys_read_u16_le(read_p, &read_p); + SceneModule.reslist[i].res_type = ys_read_u16_le(read_p, &read_p); } RSC_FreeResource(resource_list); @@ -756,43 +566,26 @@ int LoadSceneResourceList(uint32 reslist_rn) return R_SUCCESS; } -int ProcessSceneResources(void) -{ - +int ProcessSceneResources() { const byte *res_data; size_t res_data_len; - const byte *pal_p; - int i; - /* - * Process the scene resource list - \*-------------------------------------------------------------*/ + // Process the scene resource list for (i = 0; i < SceneModule.reslist_entries; i++) { - res_data = SceneModule.reslist[i].res_data; res_data_len = SceneModule.reslist[i].res_data_len; - switch (SceneModule.reslist[i].res_type) { - - /* Scene background resource */ - case SAGA_BG_IMAGE: - + case SAGA_BG_IMAGE: // Scene background resource if (SceneModule.bg.loaded) { - - R_printf(R_STDERR, - "Error: Multiple background resources " - "encountered.\n"); + R_printf(R_STDERR, "Error: Multiple background resources encountered.\n"); return R_FAILURE; } R_printf(R_STDOUT, "Loading background resource.\n"); - - SceneModule.bg.res_buf = - SceneModule.reslist[i].res_data; - SceneModule.bg.res_len = - SceneModule.reslist[i].res_data_len; + SceneModule.bg.res_buf = SceneModule.reslist[i].res_data; + SceneModule.bg.res_len = SceneModule.reslist[i].res_data_len; SceneModule.bg.loaded = 1; if (IMG_DecodeBGImage(SceneModule.bg.res_buf, @@ -801,147 +594,89 @@ int ProcessSceneResources(void) &SceneModule.bg.buf_len, &SceneModule.bg.w, &SceneModule.bg.h) != R_SUCCESS) { - R_printf(R_STDERR, - "Error loading background resource: %u\n", - SceneModule.reslist[i].res_number); - + R_printf(R_STDERR, "Error loading background resource: %u\n", SceneModule.reslist[i].res_number); return R_FAILURE; } - pal_p = IMG_GetImagePal(SceneModule.bg.res_buf, - SceneModule.bg.res_len); - - memcpy(SceneModule.bg.pal, - pal_p, sizeof SceneModule.bg.pal); - + pal_p = IMG_GetImagePal(SceneModule.bg.res_buf, SceneModule.bg.res_len); + memcpy(SceneModule.bg.pal, pal_p, sizeof SceneModule.bg.pal); SceneModule.scene_mode = R_SCENE_MODE_NORMAL; - break; - - /* Scene background mask resource */ - case SAGA_BG_MASK: - + case SAGA_BG_MASK: // Scene background mask resource if (SceneModule.bg_mask.loaded) { - R_printf(R_STDERR, - "Error: Duplicate background mask resource " - "encountered.\n"); + R_printf(R_STDERR, "Error: Duplicate background mask resource encountered.\n"); } - - R_printf(R_STDOUT, - "Loading BACKGROUND MASK resource.\n"); - - SceneModule.bg_mask.res_buf = - SceneModule.reslist[i].res_data; - SceneModule.bg_mask.res_len = - SceneModule.reslist[i].res_data_len; + R_printf(R_STDOUT, "Loading BACKGROUND MASK resource.\n"); + SceneModule.bg_mask.res_buf = SceneModule.reslist[i].res_data; + SceneModule.bg_mask.res_len = SceneModule.reslist[i].res_data_len; SceneModule.bg_mask.loaded = 1; - - IMG_DecodeBGImage(SceneModule.bg_mask.res_buf, - SceneModule.bg_mask.res_len, - &SceneModule.bg_mask.buf, - &SceneModule.bg_mask.buf_len, - &SceneModule.bg_mask.w, &SceneModule.bg_mask.h); + IMG_DecodeBGImage(SceneModule.bg_mask.res_buf, SceneModule.bg_mask.res_len, &SceneModule.bg_mask.buf, + &SceneModule.bg_mask.buf_len, &SceneModule.bg_mask.w, &SceneModule.bg_mask.h); break; - case SAGA_OBJECT_NAME_LIST: - - R_printf(R_STDOUT, - "Loading object name list resource...\n"); - - OBJECTMAP_LoadNames(SceneModule.reslist[i].res_data, - SceneModule.reslist[i].res_data_len); + R_printf(R_STDOUT, "Loading object name list resource...\n"); + OBJECTMAP_LoadNames(SceneModule.reslist[i].res_data, SceneModule.reslist[i].res_data_len); break; - case SAGA_OBJECT_MAP: - R_printf(R_STDOUT, "Loading object map resource...\n"); - if (OBJECTMAP_Load(res_data, res_data_len) != R_SUCCESS) { - - R_printf(R_STDERR, - "Error loading object map resource.\n"); + R_printf(R_STDERR, "Error loading object map resource.\n"); return R_FAILURE; } break; - case SAGA_ACTION_MAP: - R_printf(R_STDOUT, "Loading exit map resource...\n"); - - if (ACTIONMAP_Load(res_data, - res_data_len) != R_SUCCESS) { - R_printf(R_STDERR, - "Error loading exit map resource.\n"); + if (ACTIONMAP_Load(res_data, res_data_len) != R_SUCCESS) { + R_printf(R_STDERR, "Error loading exit map resource.\n"); return R_FAILURE; } break; - case SAGA_ISO_TILESET: - if (SceneModule.scene_mode == R_SCENE_MODE_NORMAL) { - R_printf(R_STDERR, - "Isometric tileset incompatible with normal " - "scene mode.\n"); + R_printf(R_STDERR, "Isometric tileset incompatible with normal scene mode.\n"); return R_FAILURE; } - R_printf(R_STDOUT, - "Loading isometric tileset resource.\n"); + R_printf(R_STDOUT, "Loading isometric tileset resource.\n"); - if (ISOMAP_LoadTileset(res_data, - res_data_len) != R_SUCCESS) { - R_printf(R_STDERR, - "Error loading isometric tileset resource.\n"); + if (ISOMAP_LoadTileset(res_data, res_data_len) != R_SUCCESS) { + R_printf(R_STDERR, "Error loading isometric tileset resource.\n"); return R_FAILURE; } SceneModule.scene_mode = R_SCENE_MODE_ISO; break; - case SAGA_ISO_METAMAP: - if (SceneModule.scene_mode == R_SCENE_MODE_NORMAL) { - R_printf(R_STDERR, - "Isometric metamap incompatible with normal " - "scene mode.\n"); + R_printf(R_STDERR, "Isometric metamap incompatible with normal scene mode.\n"); return R_FAILURE; } - R_printf(R_STDOUT, - "Loading isometric metamap resource.\n"); + R_printf(R_STDOUT, "Loading isometric metamap resource.\n"); - if (ISOMAP_LoadMetamap(res_data, - res_data_len) != R_SUCCESS) { - R_printf(R_STDERR, - "Error loading isometric metamap resource.\n"); + if (ISOMAP_LoadMetamap(res_data, res_data_len) != R_SUCCESS) { + R_printf(R_STDERR, "Error loading isometric metamap resource.\n"); return R_FAILURE; } SceneModule.scene_mode = R_SCENE_MODE_ISO; break; - case SAGA_ISO_METATILESET: if (SceneModule.scene_mode == R_SCENE_MODE_NORMAL) { - R_printf(R_STDERR, - "Isometric metatileset incompatible with " - "normal scene mode.\n"); + R_printf(R_STDERR, "Isometric metatileset incompatible with normal scene mode.\n"); return R_FAILURE; } - R_printf(R_STDOUT, - "Loading isometric metatileset resource.\n"); + R_printf(R_STDOUT, "Loading isometric metatileset resource.\n"); - if (ISOMAP_LoadMetaTileset(res_data, - res_data_len) != R_SUCCESS) { - R_printf(R_STDERR, - "Error loading isometric tileset resource.\n"); + if (ISOMAP_LoadMetaTileset(res_data, res_data_len) != R_SUCCESS) { + R_printf(R_STDERR, "Error loading isometric tileset resource.\n"); return R_FAILURE; } SceneModule.scene_mode = R_SCENE_MODE_ISO; break; - case SAGA_ANIM_1: case SAGA_ANIM_2: case SAGA_ANIM_3: @@ -953,15 +688,11 @@ int ProcessSceneResources(void) SCENE_ANIMINFO *new_animinfo; uint16 new_anim_id; - R_printf(R_STDOUT, - "Loading animation resource...\n"); + R_printf(R_STDOUT, "Loading animation resource...\n"); new_animinfo = (SCENE_ANIMINFO *)malloc(sizeof *new_animinfo); if (new_animinfo == NULL) { - - R_printf(R_STDERR, - "Memory allocation error.\n"); - + R_printf(R_STDERR, "Memory allocation error.\n"); return R_MEM; } @@ -969,47 +700,30 @@ int ProcessSceneResources(void) SceneModule.reslist[i].res_data_len, &new_anim_id) == R_SUCCESS) { } else { - R_printf(R_STDERR, - "Error loading animation resource\n"); - + R_printf(R_STDERR, "Error loading animation resource\n"); return R_FAILURE; } new_animinfo->anim_handle = new_anim_id; - new_animinfo->anim_res_number = - SceneModule.reslist[i].res_number; - - ys_dll_add_tail(SceneModule.anim_list, - new_animinfo, sizeof *new_animinfo); - + new_animinfo->anim_res_number = SceneModule.reslist[i].res_number; + ys_dll_add_tail(SceneModule.anim_list, new_animinfo, sizeof *new_animinfo); SceneModule.anim_entries++; } break; - case SAGA_PAL_ANIM: - - R_printf(R_STDOUT, - "Loading palette animation resource.\n"); - - PALANIM_Load(SceneModule.reslist[i].res_data, - SceneModule.reslist[i].res_data_len); + R_printf(R_STDOUT, "Loading palette animation resource.\n"); + PALANIM_Load(SceneModule.reslist[i].res_data, SceneModule.reslist[i].res_data_len); break; - default: - - R_printf(R_STDERR, - "Encountered unknown resource type: %d\n", - SceneModule.reslist[i].res_type); + R_printf(R_STDERR, "Encountered unknown resource type: %d\n", SceneModule.reslist[i].res_type); break; - } } return R_SUCCESS; } -int SCENE_Draw(R_SURFACE * dst_s) -{ +int SCENE_Draw(R_SURFACE *dst_s) { R_GAME_DISPLAYINFO disp_info; R_BUFFER_INFO buf_info; R_POINT bg_pt; @@ -1025,30 +739,22 @@ int SCENE_Draw(R_SURFACE * dst_s) switch (SceneModule.scene_mode) { case R_SCENE_MODE_NORMAL: - - GFX_BufToSurface(dst_s, - buf_info.r_bg_buf, - disp_info.logical_w, - MAX(disp_info.scene_h, SceneModule.bg.h), NULL, &bg_pt); + GFX_BufToSurface(dst_s, buf_info.r_bg_buf, disp_info.logical_w, + MAX(disp_info.scene_h, SceneModule.bg.h), NULL, &bg_pt); break; - case R_SCENE_MODE_ISO: - ISOMAP_Draw(dst_s); break; - default: - /* Unknown scene mode */ + // Unknown scene mode return R_FAILURE; break; - }; return R_SUCCESS; } -int SCENE_End(void) -{ +int SCENE_End() { R_SCENE_INFO scene_info; assert(SceneModule.init); @@ -1065,29 +771,28 @@ int SCENE_End(void) SceneModule.scene_proc(SCENE_END, &scene_info); if (SceneModule.desc.script_num > 0) { - SCRIPT_Free(); } - /* Free scene background */ + // Free scene background if (SceneModule.bg.loaded) { free(SceneModule.bg.buf); SceneModule.bg.loaded = 0; } - /* Free scene background mask */ + // Free scene background mask if (SceneModule.bg_mask.loaded) { free(SceneModule.bg_mask.buf); SceneModule.bg_mask.loaded = 0; } - /* Free scene resource list */ + // Free scene resource list if (SceneModule.load_desc) { free(SceneModule.reslist); } - /* Free animation info list */ + // Free animation info list ANIM_Reset(); PALANIM_Free(); @@ -1106,9 +811,7 @@ int SCENE_End(void) return R_SUCCESS; } -void CF_scenechange(int argc, char *argv[]) -{ - +void CF_scenechange(int argc, char *argv[]) { int scene_num = 0; if ((argc == 0) || (argc > 1)) { @@ -1129,13 +832,9 @@ void CF_scenechange(int argc, char *argv[]) } else { CON_Print("Couldn't change scene!"); } - - return; } -void CF_sceneinfo(int argc, char *argv[]) -{ - +void CF_sceneinfo(int argc, char *argv[]) { const char *fmt = "%-20s %d"; YS_IGNORE_PARAM(argc); @@ -1152,8 +851,6 @@ void CF_sceneinfo(int argc, char *argv[]) CON_Print(fmt, "Scene script:", SceneModule.desc.scene_scriptnum); CON_Print(fmt, "Start script:", SceneModule.desc.start_scriptnum); CON_Print(fmt, "Music R#", SceneModule.desc.music_rn); - - return; } } // End of namespace Saga diff --git a/saga/scene.h b/saga/scene.h index cc5af55644..d6480038c1 100644 --- a/saga/scene.h +++ b/saga/scene.h @@ -20,13 +20,8 @@ * $Header$ * */ -/* - Description: - - Scene management module private header file - Notes: -*/ +// Scene management module private header file #ifndef SAGA_SCENE_H #define SAGA_SCENE_H @@ -34,21 +29,18 @@ namespace Saga { enum SCENE_LOAD_FLAGS { - BY_RESOURCE = 0, BY_SCENE, BY_DESC }; enum SCENE_PROC_PARAMS { - SCENE_BEGIN = 0, SCENE_END }; -/* Resource type numbers */ +// Resource type numbers enum SAGA_RESOURCE_TYPES { - SAGA_BG_IMAGE = 2, SAGA_BG_MASK = 3, SAGA_OBJECT_NAME_LIST = 5, @@ -70,19 +62,15 @@ enum SAGA_RESOURCE_TYPES { #define SAGA_RESLIST_ENTRY_LEN 4 struct R_SCENE_RESLIST { - uint32 res_number; int res_type; - byte *res_data; size_t res_data_len; - }; #define SAGA_SCENE_DESC_LEN 16 struct R_SCENE_DESC { - int unknown0; int res_list_rn; int end_slope; @@ -91,139 +79,94 @@ struct R_SCENE_DESC { int scene_scriptnum; int start_scriptnum; int music_rn; - R_SCENE_RESLIST *res_list; size_t res_list_ct; - }; struct SCENE_IMAGE { - int loaded; - int w; int h; int p; - byte *buf; size_t buf_len; - byte *res_buf; size_t res_len; - PALENTRY pal[256]; - }; struct SCENE_ANIMINFO { - int anim_res_number; int anim_handle; - SCENE_ANIMINFO *next; - }; struct R_SCENE_QUEUE { - uint32 scene_n; R_SCENE_DESC *scene_desc; int load_flag; - R_SCENE_PROC *scene_proc; int scene_skiptarget; - }; struct R_SCENE_MODULE { - int init; - R_RSCFILE_CONTEXT *scene_ctxt; - int *scene_lut; int scene_count; int scene_max; - YS_DL_LIST *scene_queue; - int first_scene; - int scene_loaded; int scene_mode; int scene_number; int scene_rn; int in_game; - int load_desc; R_SCENE_DESC desc; - int reslist_loaded; int reslist_entries; R_SCENE_RESLIST *reslist; - int anim_entries; YS_DL_LIST *anim_list; - R_SCENE_PROC *scene_proc; - R_TEXTLIST *text_list; - SCENE_IMAGE bg; SCENE_IMAGE bg_mask; - }; int SCENE_Queue(R_SCENE_QUEUE * scene_queue); int SCENE_ClearQueue(void); -int -SCENE_Load(int scene, - int load_flag, R_SCENE_PROC scene_proc, R_SCENE_DESC *); - +int SCENE_Load(int scene, int load_flag, R_SCENE_PROC scene_proc, R_SCENE_DESC *); int LoadSceneDescriptor(uint32 res_number); - int LoadSceneResourceList(uint32 res_number); +int ProcessSceneResources(); +void CF_scenechange(int argc, char *argv[]); +void CF_sceneinfo(int argc, char *argv[]); -int ProcessSceneResources(void); +int IHNM_StartProc(); -void CF_scenechange(int argc, char *argv[]); +int InitialSceneProc(int param, R_SCENE_INFO *scene_info); +int DefaultSceneProc(int param, R_SCENE_INFO *scene_info); -void CF_sceneinfo(int argc, char *argv[]); +int ITE_StartProc(); +int ITE_IntroAnimProc(int param, R_SCENE_INFO *scene_info); +int ITE_IntroCave1Proc(int param, R_SCENE_INFO *scene_info); +int ITE_IntroCave2Proc(int param, R_SCENE_INFO *scene_info); +int ITE_IntroCave3Proc(int param, R_SCENE_INFO *scene_info); +int ITE_IntroCave4Proc(int param, R_SCENE_INFO *scene_info); +int ITE_IntroValleyProc(int param, R_SCENE_INFO *scene_info); +int ITE_IntroTreeHouseProc(int param, R_SCENE_INFO *scene_info); +int ITE_IntroFairePathProc(int param, R_SCENE_INFO *scene_info); +int ITE_IntroFaireTentProc(int param, R_SCENE_INFO *scene_info); -/* - * r_sceneproc.c -\*--------------------------------------------------------------------------*/ - -int IHNM_StartProc(void); - -int InitialSceneProc(int param, R_SCENE_INFO * scene_info); -int DefaultSceneProc(int param, R_SCENE_INFO * scene_info); - -/* - * r_ite_introproc.c -\*--------------------------------------------------------------------------*/ - -int ITE_StartProc(void); -int ITE_IntroAnimProc(int param, R_SCENE_INFO * scene_info); -int ITE_IntroCave1Proc(int param, R_SCENE_INFO * scene_info); -int ITE_IntroCave2Proc(int param, R_SCENE_INFO * scene_info); -int ITE_IntroCave3Proc(int param, R_SCENE_INFO * scene_info); -int ITE_IntroCave4Proc(int param, R_SCENE_INFO * scene_info); -int ITE_IntroValleyProc(int param, R_SCENE_INFO * scene_info); -int ITE_IntroTreeHouseProc(int param, R_SCENE_INFO * scene_info); -int ITE_IntroFairePathProc(int param, R_SCENE_INFO * scene_info); -int ITE_IntroFaireTentProc(int param, R_SCENE_INFO * scene_info); - -/* - * r_ihnm_introproc.c -\*--------------------------------------------------------------------------*/ -int IHNM_StartProc(void); -int IHNM_IntroMovieProc1(int param, R_SCENE_INFO * scene_info); -int IHNM_IntroMovieProc2(int param, R_SCENE_INFO * scene_info); -int IHNM_IntroMovieProc3(int param, R_SCENE_INFO * scene_info); -int IHNM_HateProc(int param, R_SCENE_INFO * scene_info); +int IHNM_StartProc(); +int IHNM_IntroMovieProc1(int param, R_SCENE_INFO *scene_info); +int IHNM_IntroMovieProc2(int param, R_SCENE_INFO *scene_info); +int IHNM_IntroMovieProc3(int param, R_SCENE_INFO *scene_info); +int IHNM_HateProc(int param, R_SCENE_INFO *scene_info); } // End of namespace Saga -#endif /* SAGA_SCENE_H_ */ +#endif diff --git a/saga/scene_mod.h b/saga/scene_mod.h index 9f3c007122..84430c8679 100644 --- a/saga/scene_mod.h +++ b/saga/scene_mod.h @@ -20,13 +20,8 @@ * $Header$ * */ -/* - Description: - - Scene management module public header file - Notes: -*/ +// Scene management module public header file #ifndef SAGA_SCENE_MOD_H__ #define SAGA_SCENE_MOD_H__ @@ -35,69 +30,52 @@ namespace Saga { -/* - * r_scene.c -\*--------------------------------------------------------------------------*/ enum R_SCENE_MODES { - R_SCENE_MODE_INVALID, R_SCENE_MODE_NORMAL, R_SCENE_MODE_ISO }; struct SCENE_ZINFO { - int begin_slope; int end_slope; }; struct SCENE_BGINFO { - int bg_x; int bg_y; - int bg_w; int bg_h; int bg_p; - byte *bg_buf; size_t bg_buflen; - }; struct R_SCENE_INFO { - SCENE_ZINFO z_info; SCENE_BGINFO bg_info; - R_TEXTLIST *text_list; - }; typedef int (R_SCENE_PROC) (int, R_SCENE_INFO *); -int SCENE_Register(void); -int SCENE_Init(void); -int SCENE_Shutdown(void); - -int SCENE_Start(void); -int SCENE_Next(void); -int SCENE_Skip(void); -int SCENE_End(void); - +int SCENE_Register(); +int SCENE_Init(); +int SCENE_Shutdown(); +int SCENE_Start(); +int SCENE_Next(); +int SCENE_Skip(); +int SCENE_End(); int SCENE_Draw(R_SURFACE *); - -int SCENE_GetMode(void); -int SCENE_GetBGMaskInfo(int *w, int *h, byte ** buf, size_t * buf_len); - +int SCENE_GetMode(); +int SCENE_GetBGMaskInfo(int *w, int *h, byte **buf, size_t *buf_len); int SCENE_IsBGMaskPresent(void); -int SCENE_GetBGInfo(SCENE_BGINFO * bginfo); -int SCENE_GetZInfo(SCENE_ZINFO * zinfo); -int SCENE_GetBGPal(PALENTRY ** pal); - -int SCENE_GetInfo(R_SCENE_INFO * si); +int SCENE_GetBGInfo(SCENE_BGINFO *bginfo); +int SCENE_GetZInfo(SCENE_ZINFO *zinfo); +int SCENE_GetBGPal(PALENTRY **pal); +int SCENE_GetInfo(R_SCENE_INFO *si); } // End of namespace Saga -#endif /* SAGA_SCENE_MOD_H__ */ +#endif |