diff --git a/src/config.c b/src/config.c index 4bb6b23ba..743a9f6b5 100644 --- a/src/config.c +++ b/src/config.c @@ -27,20 +27,19 @@ CONFIG g_Config = { 0 }; static const char *m_ConfigPath = "cfg/TR1X.json5"; -static void Config_LoadKeyboardLayout( +static void M_LoadKeyboardLayout( struct json_object_s *parent_obj, INPUT_LAYOUT layout); -static void Config_LoadControllerLayout( +static void M_LoadControllerLayout( struct json_object_s *parent_obj, INPUT_LAYOUT layout); -static void Config_LoadLegacyOptions(struct json_object_s *const parent_obj); -static void Config_DumpKeyboardLayout( +static void M_LoadLegacyOptions(struct json_object_s *const parent_obj); +static void M_DumpKeyboardLayout( struct json_object_s *parent_obj, INPUT_LAYOUT layout); -static void Config_DumpControllerLayout( +static void M_DumpControllerLayout( struct json_object_s *parent_obj, INPUT_LAYOUT layout); +static void M_Load(struct json_object_s *root_obj); +static void M_Dump(struct json_object_s *root_obj); -static void Config_Load(struct json_object_s *root_obj); -static void Config_Dump(struct json_object_s *root_obj); - -static void Config_LoadKeyboardLayout( +static void M_LoadKeyboardLayout( struct json_object_s *const parent_obj, const INPUT_LAYOUT layout) { char layout_name[20]; @@ -81,7 +80,7 @@ static void Config_LoadKeyboardLayout( } } -static void Config_LoadControllerLayout( +static void M_LoadControllerLayout( struct json_object_s *const parent_obj, const INPUT_LAYOUT layout) { char layout_name[20]; @@ -147,7 +146,7 @@ static void Config_LoadControllerLayout( } } -static void Config_LoadLegacyOptions(struct json_object_s *const parent_obj) +static void M_LoadLegacyOptions(struct json_object_s *const parent_obj) { // 0.10..4.0.3: enable_enemy_healthbar { @@ -174,7 +173,7 @@ static void Config_LoadLegacyOptions(struct json_object_s *const parent_obj) } } -static void Config_DumpKeyboardLayout( +static void M_DumpKeyboardLayout( struct json_object_s *const parent_obj, const INPUT_LAYOUT layout) { struct json_array_s *const arr = json_array_new(); @@ -206,7 +205,7 @@ static void Config_DumpKeyboardLayout( } } -static void Config_DumpControllerLayout( +static void M_DumpControllerLayout( struct json_object_s *const parent_obj, const INPUT_LAYOUT layout) { struct json_array_s *const arr = json_array_new(); @@ -247,39 +246,39 @@ static void Config_DumpControllerLayout( } } -static void Config_Load(struct json_object_s *root_obj) +static void M_Load(struct json_object_s *root_obj) { ConfigFile_LoadOptions(root_obj, g_ConfigOptionMap); for (INPUT_LAYOUT layout = INPUT_LAYOUT_CUSTOM_1; layout < INPUT_LAYOUT_NUMBER_OF; layout++) { - Config_LoadKeyboardLayout(root_obj, layout); - Config_LoadControllerLayout(root_obj, layout); + M_LoadKeyboardLayout(root_obj, layout); + M_LoadControllerLayout(root_obj, layout); } - Config_LoadLegacyOptions(root_obj); + M_LoadLegacyOptions(root_obj); Config_Sanitize(); } -static void Config_Dump(struct json_object_s *root_obj) +static void M_Dump(struct json_object_s *root_obj) { ConfigFile_DumpOptions(root_obj, g_ConfigOptionMap); for (INPUT_LAYOUT layout = INPUT_LAYOUT_CUSTOM_1; layout < INPUT_LAYOUT_NUMBER_OF; layout++) { - Config_DumpKeyboardLayout(root_obj, layout); + M_DumpKeyboardLayout(root_obj, layout); } for (INPUT_LAYOUT layout = INPUT_LAYOUT_CUSTOM_1; layout < INPUT_LAYOUT_NUMBER_OF; layout++) { - Config_DumpControllerLayout(root_obj, layout); + M_DumpControllerLayout(root_obj, layout); } } bool Config_Read(void) { - const bool result = ConfigFile_Read(m_ConfigPath, &Config_Load); + const bool result = ConfigFile_Read(m_ConfigPath, &M_Load); Input_CheckConflicts(CM_KEYBOARD, g_Config.input.layout); Input_CheckConflicts(CM_CONTROLLER, g_Config.input.cntlr_layout); Music_SetVolume(g_Config.music_volume); @@ -291,7 +290,7 @@ bool Config_Read(void) bool Config_Write(void) { - return ConfigFile_Write(m_ConfigPath, &Config_Dump); + return ConfigFile_Write(m_ConfigPath, &M_Dump); } void Config_Sanitize(void) diff --git a/src/game/camera.c b/src/game/camera.c index ff61909ed..1a1722a5c 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -25,36 +25,34 @@ static double m_ManualCameraMultiplier[11] = { 1.0, .5, .625, .75, .875, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, }; -static bool Camera_BadPosition( - int32_t x, int32_t y, int32_t z, int16_t room_num); -static int32_t Camera_ShiftClamp(GAME_VECTOR *pos, int32_t clamp); -static void Camera_SmartShift( +static bool M_BadPosition(int32_t x, int32_t y, int32_t z, int16_t room_num); +static int32_t M_ShiftClamp(GAME_VECTOR *pos, int32_t clamp); +static void M_SmartShift( GAME_VECTOR *ideal, void (*shift)( int32_t *x, int32_t *y, int32_t target_x, int32_t target_y, int32_t left, int32_t top, int32_t right, int32_t bottom)); -static void Camera_Clip( +static void M_Clip( int32_t *x, int32_t *y, int32_t target_x, int32_t target_y, int32_t left, int32_t top, int32_t right, int32_t bottom); -static void Camera_Shift( +static void M_Shift( int32_t *x, int32_t *y, int32_t target_x, int32_t target_y, int32_t left, int32_t top, int32_t right, int32_t bottom); -static void Camera_Move(GAME_VECTOR *ideal, int32_t speed); -static void Camera_LoadCutsceneFrame(void); -static void Camera_OffsetAdditionalAngle(int16_t delta); -static void Camera_OffsetAdditionalElevation(int16_t delta); -static void Camera_AdjustMusicVolume(bool underwater); -static void Camera_EnsureEnvironment(void); - -static bool Camera_BadPosition( - int32_t x, int32_t y, int32_t z, int16_t room_num) +static void M_Move(GAME_VECTOR *ideal, int32_t speed); +static void M_LoadCutsceneFrame(void); +static void M_OffsetAdditionalAngle(int16_t delta); +static void M_OffsetAdditionalElevation(int16_t delta); +static void M_AdjustMusicVolume(bool underwater); +static void M_EnsureEnvironment(void); + +static bool M_BadPosition(int32_t x, int32_t y, int32_t z, int16_t room_num) { const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num); return y >= Room_GetHeight(sector, x, y, z) || y <= Room_GetCeiling(sector, x, y, z); } -static int32_t Camera_ShiftClamp(GAME_VECTOR *pos, int32_t clamp) +static int32_t M_ShiftClamp(GAME_VECTOR *pos, int32_t clamp) { int32_t x = pos->x; int32_t y = pos->y; @@ -64,20 +62,19 @@ static int32_t Camera_ShiftClamp(GAME_VECTOR *pos, int32_t clamp) const BOX_INFO *const box = &g_Boxes[sector->box]; if (z < box->left + clamp - && Camera_BadPosition(x, y, z - clamp, pos->room_num)) { + && M_BadPosition(x, y, z - clamp, pos->room_num)) { pos->z = box->left + clamp; } else if ( z > box->right - clamp - && Camera_BadPosition(x, y, z + clamp, pos->room_num)) { + && M_BadPosition(x, y, z + clamp, pos->room_num)) { pos->z = box->right - clamp; } - if (x < box->top + clamp - && Camera_BadPosition(x - clamp, y, z, pos->room_num)) { + if (x < box->top + clamp && M_BadPosition(x - clamp, y, z, pos->room_num)) { pos->x = box->top + clamp; } else if ( x > box->bottom - clamp - && Camera_BadPosition(x + clamp, y, z, pos->room_num)) { + && M_BadPosition(x + clamp, y, z, pos->room_num)) { pos->x = box->bottom - clamp; } @@ -98,7 +95,7 @@ static int32_t Camera_ShiftClamp(GAME_VECTOR *pos, int32_t clamp) } } -static void Camera_SmartShift( +static void M_SmartShift( GAME_VECTOR *ideal, void (*shift)( int32_t *x, int32_t *y, int32_t target_x, int32_t target_y, @@ -130,8 +127,7 @@ static void Camera_SmartShift( int32_t bottom = box->bottom; int32_t test = (ideal->z - WALL_L) | (WALL_L - 1); - bool bad_left = - Camera_BadPosition(ideal->x, ideal->y, test, ideal->room_num); + bool bad_left = M_BadPosition(ideal->x, ideal->y, test, ideal->room_num); if (!bad_left) { camera_box = r->sectors[z_sector - 1 + x_sector * r->z_size].box; if (camera_box != NO_ITEM && g_Boxes[camera_box].left < left) { @@ -140,8 +136,7 @@ static void Camera_SmartShift( } test = (ideal->z + WALL_L) & (~(WALL_L - 1)); - bool bad_right = - Camera_BadPosition(ideal->x, ideal->y, test, ideal->room_num); + bool bad_right = M_BadPosition(ideal->x, ideal->y, test, ideal->room_num); if (!bad_right) { camera_box = r->sectors[z_sector + 1 + x_sector * r->z_size].box; if (camera_box != NO_ITEM && g_Boxes[camera_box].right > right) { @@ -150,8 +145,7 @@ static void Camera_SmartShift( } test = (ideal->x - WALL_L) | (WALL_L - 1); - bool bad_top = - Camera_BadPosition(test, ideal->y, ideal->z, ideal->room_num); + bool bad_top = M_BadPosition(test, ideal->y, ideal->z, ideal->room_num); if (!bad_top) { camera_box = r->sectors[z_sector + (x_sector - 1) * r->z_size].box; if (camera_box != NO_ITEM && g_Boxes[camera_box].top < top) { @@ -160,8 +154,7 @@ static void Camera_SmartShift( } test = (ideal->x + WALL_L) & (~(WALL_L - 1)); - bool bad_bottom = - Camera_BadPosition(test, ideal->y, ideal->z, ideal->room_num); + bool bad_bottom = M_BadPosition(test, ideal->y, ideal->z, ideal->room_num); if (!bad_bottom) { camera_box = r->sectors[z_sector + (x_sector + 1) * r->z_size].box; if (camera_box != NO_ITEM && g_Boxes[camera_box].bottom > bottom) { @@ -230,7 +223,7 @@ static void Camera_SmartShift( } } -static void Camera_Clip( +static void M_Clip( int32_t *x, int32_t *y, int32_t target_x, int32_t target_y, int32_t left, int32_t top, int32_t right, int32_t bottom) { @@ -246,7 +239,7 @@ static void Camera_Clip( } } -static void Camera_Shift( +static void M_Shift( int32_t *x, int32_t *y, int32_t target_x, int32_t target_y, int32_t left, int32_t top, int32_t right, int32_t bottom) { @@ -295,7 +288,7 @@ static void Camera_Shift( } } -static void Camera_Move(GAME_VECTOR *ideal, int32_t speed) +static void M_Move(GAME_VECTOR *ideal, int32_t speed) { g_Camera.pos.x += (ideal->x - g_Camera.pos.x) / speed; g_Camera.pos.z += (ideal->z - g_Camera.pos.z) / speed; @@ -357,7 +350,7 @@ static void Camera_Move(GAME_VECTOR *ideal, int32_t speed) } } -static void Camera_LoadCutsceneFrame(void) +static void M_LoadCutsceneFrame(void) { g_CineFrame++; if (g_CineFrame >= g_NumCineFrames) { @@ -385,12 +378,12 @@ static void Camera_LoadCutsceneFrame(void) Viewport_SetFOV(ref->fov); } -static void Camera_OffsetAdditionalAngle(int16_t delta) +static void M_OffsetAdditionalAngle(int16_t delta) { g_Camera.additional_angle += delta; } -static void Camera_OffsetAdditionalElevation(int16_t delta) +static void M_OffsetAdditionalElevation(int16_t delta) { // don't let this value wrap, so clamp it. if (delta > 0) { @@ -408,7 +401,7 @@ static void Camera_OffsetAdditionalElevation(int16_t delta) } } -static void Camera_AdjustMusicVolume(const bool underwater) +static void M_AdjustMusicVolume(const bool underwater) { const bool is_ambient = Music_GetCurrentPlayingTrack() == Music_GetCurrentLoopedTrack(); @@ -503,12 +496,12 @@ void Camera_Chase(ITEM_INFO *item) ideal.z = g_Camera.target.z - (distance * Math_Cos(angle) >> W2V_SHIFT); ideal.room_num = g_Camera.pos.room_num; - Camera_SmartShift(&ideal, Camera_Shift); + M_SmartShift(&ideal, M_Shift); if (g_Camera.fixed_camera) { - Camera_Move(&ideal, g_Camera.speed); + M_Move(&ideal, g_Camera.speed); } else { - Camera_Move(&ideal, CHASE_SPEED); + M_Move(&ideal, CHASE_SPEED); } } @@ -544,8 +537,8 @@ void Camera_Combat(ITEM_INFO *item) - (distance * Math_Cos(g_Camera.target_angle) >> W2V_SHIFT); ideal.room_num = g_Camera.pos.room_num; - Camera_SmartShift(&ideal, Camera_Shift); - Camera_Move(&ideal, g_Camera.speed); + M_SmartShift(&ideal, M_Shift); + M_Move(&ideal, g_Camera.speed); } void Camera_Look(ITEM_INFO *item) @@ -574,14 +567,14 @@ void Camera_Look(ITEM_INFO *item) g_Camera.target.z += g_Camera.shift * Math_Cos(item->rot.y) >> W2V_SHIFT; g_Camera.target.x += g_Camera.shift * Math_Sin(item->rot.y) >> W2V_SHIFT; - if (Camera_BadPosition( + if (M_BadPosition( g_Camera.target.x, g_Camera.target.y, g_Camera.target.z, g_Camera.target.room_num)) { g_Camera.target.x = item->pos.x; g_Camera.target.z = item->pos.z; } - g_Camera.target.y += Camera_ShiftClamp(&g_Camera.target, STEP_L + 50); + g_Camera.target.y += M_ShiftClamp(&g_Camera.target, STEP_L + 50); ideal.x = g_Camera.target.x - (distance * Math_Sin(g_Camera.target_angle) >> W2V_SHIFT); @@ -592,12 +585,12 @@ void Camera_Look(ITEM_INFO *item) - (distance * Math_Cos(g_Camera.target_angle) >> W2V_SHIFT); ideal.room_num = g_Camera.pos.room_num; - Camera_SmartShift(&ideal, Camera_Clip); + M_SmartShift(&ideal, M_Clip); g_Camera.target.z = old.z + (g_Camera.target.z - old.z) / g_Camera.speed; g_Camera.target.x = old.x + (g_Camera.target.x - old.x) / g_Camera.speed; - Camera_Move(&ideal, g_Camera.speed); + M_Move(&ideal, g_Camera.speed); } void Camera_Fixed(void) @@ -613,7 +606,7 @@ void Camera_Fixed(void) g_Camera.fixed_camera = 1; - Camera_Move(&ideal, g_Camera.speed); + M_Move(&ideal, g_Camera.speed); if (g_Camera.timer) { g_Camera.timer--; @@ -626,7 +619,7 @@ void Camera_Fixed(void) void Camera_Update(void) { if (g_Camera.type == CAM_CINEMATIC) { - Camera_LoadCutsceneFrame(); + M_LoadCutsceneFrame(); return; } @@ -775,18 +768,18 @@ void Camera_Update(void) g_ChunkyFlag = false; } -static void Camera_EnsureEnvironment(void) +static void M_EnsureEnvironment(void) { if (g_Camera.pos.room_num == NO_ROOM) { return; } if (g_RoomInfo[g_Camera.pos.room_num].flags & RF_UNDERWATER) { - Camera_AdjustMusicVolume(true); + M_AdjustMusicVolume(true); Sound_Effect(SFX_UNDERWATER, NULL, SPM_ALWAYS); g_Camera.underwater = true; } else { - Camera_AdjustMusicVolume(false); + M_AdjustMusicVolume(false); if (g_Camera.underwater) { Sound_StopEffect(SFX_UNDERWATER, NULL); g_Camera.underwater = false; @@ -863,14 +856,14 @@ void Camera_MoveManual(void) * (double)m_ManualCameraMultiplier[g_Config.camera_speed]; if (g_Input.camera_left) { - Camera_OffsetAdditionalAngle(camera_delta); + M_OffsetAdditionalAngle(camera_delta); } else if (g_Input.camera_right) { - Camera_OffsetAdditionalAngle(-camera_delta); + M_OffsetAdditionalAngle(-camera_delta); } if (g_Input.camera_up) { - Camera_OffsetAdditionalElevation(-camera_delta); + M_OffsetAdditionalElevation(-camera_delta); } else if (g_Input.camera_down) { - Camera_OffsetAdditionalElevation(camera_delta); + M_OffsetAdditionalElevation(camera_delta); } if (g_Input.camera_reset) { Camera_OffsetReset(); @@ -879,7 +872,7 @@ void Camera_MoveManual(void) void Camera_Apply(void) { - Camera_EnsureEnvironment(); + M_EnsureEnvironment(); Matrix_LookAt( g_Camera.interp.result.pos.x, g_Camera.interp.result.pos.y + g_Camera.interp.result.shift, diff --git a/src/game/carrier.c b/src/game/carrier.c index 23d63bba9..e2f7ff8c4 100644 --- a/src/game/carrier.c +++ b/src/game/carrier.c @@ -22,8 +22,8 @@ static int16_t m_AnimatingCount = 0; -static ITEM_INFO *Carrier_GetCarrier(int16_t item_num); -static void Carrier_AnimateDrop(CARRIED_ITEM *item); +static ITEM_INFO *M_GetCarrier(int16_t item_num); +static void M_AnimateDrop(CARRIED_ITEM *item); static const GAME_OBJECT_PAIR m_LegacyMap[] = { { O_PIERRE, O_SCION_ITEM_2 }, { O_COWBOY, O_MAGNUM_ITEM }, @@ -40,7 +40,7 @@ void Carrier_InitialiseLevel(int32_t level_num) for (int i = 0; i < level.item_drops.count; i++) { GAMEFLOW_DROP_ITEM_DATA *data = &level.item_drops.data[i]; - ITEM_INFO *item = Carrier_GetCarrier(data->enemy_num); + ITEM_INFO *item = M_GetCarrier(data->enemy_num); if (!item) { LOG_WARNING("%d does not refer to a loaded item", data->enemy_num); continue; @@ -92,7 +92,7 @@ void Carrier_InitialiseLevel(int32_t level_num) } } -static ITEM_INFO *Carrier_GetCarrier(int16_t item_num) +static ITEM_INFO *M_GetCarrier(int16_t item_num) { if (item_num < 0 || item_num >= g_LevelItemCount) { return NULL; @@ -115,7 +115,7 @@ static ITEM_INFO *Carrier_GetCarrier(int16_t item_num) int32_t Carrier_GetItemCount(int16_t item_num) { - ITEM_INFO *carrier = Carrier_GetCarrier(item_num); + ITEM_INFO *carrier = M_GetCarrier(item_num); if (!carrier) { return 0; } @@ -226,13 +226,13 @@ void Carrier_AnimateDrops(void) ITEM_INFO *carrier = &g_Items[i]; CARRIED_ITEM *item = carrier->carried_item; while (item) { - Carrier_AnimateDrop(item); + M_AnimateDrop(item); item = item->next_item; } } } -static void Carrier_AnimateDrop(CARRIED_ITEM *item) +static void M_AnimateDrop(CARRIED_ITEM *item) { if (item->status != DS_FALLING) { return; diff --git a/src/game/clock.c b/src/game/clock.c index c29027496..8488d2b7c 100644 --- a/src/game/clock.c +++ b/src/game/clock.c @@ -12,12 +12,12 @@ #include #include -static double Clock_GetElapsedUnit(CLOCK_TIMER *const timer, const double unit); -static bool Clock_CheckElapsedUnit( +static double M_GetElapsedUnit(CLOCK_TIMER *const timer, const double unit); +static bool M_CheckElapsedUnit( CLOCK_TIMER *const timer, const double how_often, const double unit, bool bypass_turbo_cheat); -static double Clock_GetElapsedUnit(CLOCK_TIMER *const timer, const double unit) +static double M_GetElapsedUnit(CLOCK_TIMER *const timer, const double unit) { assert(timer != NULL); const double delta = Clock_GetHighPrecisionCounter() - timer->prev_counter; @@ -27,7 +27,7 @@ static double Clock_GetElapsedUnit(CLOCK_TIMER *const timer, const double unit) return frames; } -static bool Clock_CheckElapsedUnit( +static bool M_CheckElapsedUnit( CLOCK_TIMER *const timer, const double how_often, const double unit, bool bypass_turbo_cheat) { @@ -111,40 +111,39 @@ void Clock_ResetTimer(CLOCK_TIMER *const timer) double Clock_GetElapsedLogicalFrames(CLOCK_TIMER *const timer) { - return Clock_GetElapsedUnit(timer, LOGIC_FPS); + return M_GetElapsedUnit(timer, LOGIC_FPS); } double Clock_GetElapsedDrawFrames(CLOCK_TIMER *const timer) { - return Clock_GetElapsedUnit(timer, g_Config.rendering.fps); + return M_GetElapsedUnit(timer, g_Config.rendering.fps); } double Clock_GetElapsedMilliseconds(CLOCK_TIMER *const timer) { - return Clock_GetElapsedUnit(timer, 1000.0); + return M_GetElapsedUnit(timer, 1000.0); } bool Clock_CheckElapsedLogicalFrames( CLOCK_TIMER *const timer, const int32_t how_often) { - return Clock_CheckElapsedUnit(timer, how_often, LOGIC_FPS, false); + return M_CheckElapsedUnit(timer, how_often, LOGIC_FPS, false); } bool Clock_CheckElapsedDrawFrames( CLOCK_TIMER *const timer, const int32_t how_often) { - return Clock_CheckElapsedUnit( - timer, how_often, g_Config.rendering.fps, false); + return M_CheckElapsedUnit(timer, how_often, g_Config.rendering.fps, false); } bool Clock_CheckElapsedMilliseconds( CLOCK_TIMER *const timer, const int32_t how_often) { - return Clock_CheckElapsedUnit(timer, how_often, 1000, false); + return M_CheckElapsedUnit(timer, how_often, 1000, false); } bool Clock_CheckElapsedRawMilliseconds( CLOCK_TIMER *const timer, const int32_t how_often) { - return Clock_CheckElapsedUnit(timer, how_often, 1000, true); + return M_CheckElapsedUnit(timer, how_often, 1000, true); } diff --git a/src/game/console.c b/src/game/console.c index 1d0778667..a774fbebf 100644 --- a/src/game/console.c +++ b/src/game/console.c @@ -49,18 +49,18 @@ static const int32_t m_TextHeight = 15; static const char m_ValidPromptChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.- "; -static void Console_UpdatePromptTextstring(void); -static void Console_UpdateCaretTextstring(void); -static COMMAND_RESULT Console_Eval(const char *const cmdline); +static void M_UpdatePromptTextstring(void); +static void M_UpdateCaretTextstring(void); +static COMMAND_RESULT M_Eval(const char *const cmdline); extern CONSOLE_COMMAND *g_ConsoleCommands[]; -static void Console_UpdatePromptTextstring(void) +static void M_UpdatePromptTextstring(void) { Text_ChangeText(m_Prompt.prompt_ts, m_Prompt.text); } -static void Console_UpdateCaretTextstring(void) +static void M_UpdateCaretTextstring(void) { const char old = m_Prompt.prompt_ts->string[m_Prompt.caret]; m_Prompt.prompt_ts->string[m_Prompt.caret] = '\0'; @@ -69,7 +69,7 @@ static void Console_UpdateCaretTextstring(void) Text_SetPos(m_Prompt.caret_ts, MARGIN + width, -MARGIN); } -static COMMAND_RESULT Console_Eval(const char *const cmdline) +static COMMAND_RESULT M_Eval(const char *const cmdline) { LOG_INFO("executing command: %s", cmdline); @@ -185,7 +185,7 @@ void Console_Confirm(void) return; } - Console_Eval(m_Prompt.text); + M_Eval(m_Prompt.text); Console_Close(); } @@ -208,25 +208,25 @@ void Console_HandleKeyDown(const SDL_Event event) case SDLK_LEFT: if (m_Prompt.caret > 0) { m_Prompt.caret--; - Console_UpdateCaretTextstring(); + M_UpdateCaretTextstring(); } break; case SDLK_RIGHT: if (m_Prompt.caret < strlen(m_Prompt.text)) { m_Prompt.caret++; - Console_UpdateCaretTextstring(); + M_UpdateCaretTextstring(); } break; case SDLK_HOME: m_Prompt.caret = 0; - Console_UpdateCaretTextstring(); + M_UpdateCaretTextstring(); break; case SDLK_END: m_Prompt.caret = strlen(m_Prompt.text); - Console_UpdateCaretTextstring(); + M_UpdateCaretTextstring(); break; case SDLK_BACKSPACE: @@ -235,8 +235,8 @@ void Console_HandleKeyDown(const SDL_Event event) m_Prompt.text[i - 1] = m_Prompt.text[i]; } m_Prompt.caret--; - Console_UpdatePromptTextstring(); - Console_UpdateCaretTextstring(); + M_UpdatePromptTextstring(); + M_UpdateCaretTextstring(); } break; } @@ -249,8 +249,8 @@ void Console_HandleTextEdit(const SDL_Event event) } strncpy(m_Prompt.text, event.text.text, MAX_PROMPT_LENGTH); m_Prompt.text[MAX_PROMPT_LENGTH - 1] = '\0'; - Console_UpdatePromptTextstring(); - Console_UpdateCaretTextstring(); + M_UpdatePromptTextstring(); + M_UpdateCaretTextstring(); } void Console_HandleTextInput(const SDL_Event event) @@ -280,8 +280,8 @@ void Console_HandleTextInput(const SDL_Event event) m_Prompt.caret += insert_length; m_Prompt.text[MAX_PROMPT_LENGTH - 1] = '\0'; - Console_UpdatePromptTextstring(); - Console_UpdateCaretTextstring(); + M_UpdatePromptTextstring(); + M_UpdateCaretTextstring(); } void Console_Log(const char *fmt, ...) diff --git a/src/game/console_cmd.c b/src/game/console_cmd.c index b189bd23f..3e586f9db 100644 --- a/src/game/console_cmd.c +++ b/src/game/console_cmd.c @@ -35,7 +35,7 @@ #include #include -static bool Console_Cmd_IsFloatRound(const float num); +static bool M_IsFloatRound(const float num); static COMMAND_RESULT Console_Cmd_Fps(const char *const args); static COMMAND_RESULT Console_Cmd_VSync(const char *const args); static COMMAND_RESULT Console_Cmd_Wireframe(const char *const args); @@ -56,7 +56,7 @@ static COMMAND_RESULT Console_Cmd_EndLevel(const char *args); static COMMAND_RESULT Console_Cmd_StartLevel(const char *args); static COMMAND_RESULT Console_Cmd_Abortion(const char *args); -static inline bool Console_Cmd_IsFloatRound(const float num) +static inline bool M_IsFloatRound(const float num) { return (fabsf(num) - roundf(num)) < 0.0001f; } @@ -111,10 +111,10 @@ static COMMAND_RESULT Console_Cmd_Teleport(const char *const args) { float x, y, z; if (sscanf(args, "%f %f %f", &x, &y, &z) == 3) { - if (Console_Cmd_IsFloatRound(x)) { + if (M_IsFloatRound(x)) { x += 0.5f; } - if (Console_Cmd_IsFloatRound(z)) { + if (M_IsFloatRound(z)) { z += 0.5f; } diff --git a/src/game/creature.c b/src/game/creature.c index 2309da10e..2a6a1ddde 100644 --- a/src/game/creature.c +++ b/src/game/creature.c @@ -21,12 +21,11 @@ #define MAX_CREATURE_DISTANCE (WALL_L * 30) -static bool Creature_SwitchToWater( +static bool M_SwitchToWater( int16_t item_num, const int32_t *wh, const HYBRID_INFO *info); -static bool Creature_SwitchToLand( +static bool M_SwitchToLand( int16_t item_num, const int32_t *wh, const HYBRID_INFO *info); -static bool Creature_TestSwitchOrKill( - int16_t item_num, GAME_OBJECT_ID target_id); +static bool M_TestSwitchOrKill(int16_t item_num, GAME_OBJECT_ID target_id); void Creature_Initialise(int16_t item_num) { @@ -722,8 +721,8 @@ bool Creature_EnsureHabitat( item->pos.x, item->pos.y, item->pos.z, item->room_num); return item->object_id == info->land.id - ? Creature_SwitchToWater(item_num, wh, info) - : Creature_SwitchToLand(item_num, wh, info); + ? M_SwitchToWater(item_num, wh, info) + : M_SwitchToLand(item_num, wh, info); } bool Creature_IsBoss(const int16_t item_num) @@ -732,7 +731,7 @@ bool Creature_IsBoss(const int16_t item_num) return Object_IsObjectType(item->object_id, g_BossObjects); } -static bool Creature_SwitchToWater( +static bool M_SwitchToWater( const int16_t item_num, const int32_t *const wh, const HYBRID_INFO *const info) { @@ -749,7 +748,7 @@ static bool Creature_SwitchToWater( // The land creature is alive and the room has been flooded. Switch to the // water creature. - if (!Creature_TestSwitchOrKill(item_num, info->water.id)) { + if (!M_TestSwitchOrKill(item_num, info->water.id)) { return false; } @@ -762,7 +761,7 @@ static bool Creature_SwitchToWater( return true; } -static bool Creature_SwitchToLand( +static bool M_SwitchToLand( const int16_t item_num, const int32_t *const wh, const HYBRID_INFO *const info) { @@ -770,7 +769,7 @@ static bool Creature_SwitchToLand( return false; } - if (!Creature_TestSwitchOrKill(item_num, info->land.id)) { + if (!M_TestSwitchOrKill(item_num, info->land.id)) { return false; } @@ -805,7 +804,7 @@ static bool Creature_SwitchToLand( return true; } -static bool Creature_TestSwitchOrKill( +static bool M_TestSwitchOrKill( const int16_t item_num, const GAME_OBJECT_ID target_id) { if (g_Objects[target_id].loaded) { diff --git a/src/game/effects/gun.c b/src/game/effects/gun.c index 51a162fe0..ac2d91bc5 100644 --- a/src/game/effects/gun.c +++ b/src/game/effects/gun.c @@ -12,9 +12,9 @@ #define SHARD_SPEED 250 #define ROCKET_SPEED 220 -static void ShootAtLara(FX_INFO *fx); +static void M_ShootAtLara(FX_INFO *fx); -void ShootAtLara(FX_INFO *fx) +void M_ShootAtLara(FX_INFO *fx) { int32_t x = g_LaraItem->pos.x - fx->pos.x; int32_t y = g_LaraItem->pos.y - fx->pos.y; @@ -48,7 +48,7 @@ int16_t Effect_ShardGun( fx->frame_num = 0; fx->speed = SHARD_SPEED; fx->shade = 3584; - ShootAtLara(fx); + M_ShootAtLara(fx); } return fx_num; } @@ -71,7 +71,7 @@ int16_t Effect_RocketGun( fx->frame_num = 0; fx->speed = ROCKET_SPEED; fx->shade = 4096; - ShootAtLara(fx); + M_ShootAtLara(fx); } return fx_num; } diff --git a/src/game/gamebuf.c b/src/game/gamebuf.c index 2eca88d27..7e24d294f 100644 --- a/src/game/gamebuf.c +++ b/src/game/gamebuf.c @@ -12,7 +12,7 @@ static char *m_GameMemoryPointer = NULL; static char *m_GameAllocMemPointer = NULL; static size_t m_GameAllocMemFree = 0; -static const char *GameBuf_GetBufferName(GAME_BUFFER buffer) +static const char *M_GetBufferName(GAME_BUFFER buffer) { // clang-format off switch (buffer) { @@ -88,8 +88,8 @@ void *GameBuf_Alloc(int32_t alloc_size, GAME_BUFFER buffer) if (aligned_size > m_GameAllocMemFree) { Shell_ExitSystemFmt( - "GameBuf_Alloc(): OUT OF MEMORY %s %d", - GameBuf_GetBufferName(buffer), aligned_size); + "GameBuf_Alloc(): OUT OF MEMORY %s %d", M_GetBufferName(buffer), + aligned_size); } void *result = m_GameAllocMemPointer; diff --git a/src/game/gameflow.c b/src/game/gameflow.c index 722cfc542..a94454eab 100644 --- a/src/game/gameflow.c +++ b/src/game/gameflow.c @@ -46,17 +46,16 @@ typedef struct GAMEFLOW_GIVE_ITEM_DATA { GAMEFLOW g_GameFlow = { 0 }; -static int32_t GameFlow_StringToEnumType( +static int32_t M_StringToEnumType( const char *const str, const STRING_TO_ENUM_TYPE *map); -static TRISTATE_BOOL GameFlow_ReadTristateBool( +static TRISTATE_BOOL M_ReadTristateBool( struct json_object_s *obj, const char *key); -static bool GameFlow_LoadScriptMeta(struct json_object_s *obj); -static bool GameFlow_LoadScriptGameStrings(struct json_object_s *obj); -static bool GameFlow_IsLegacySequence(const char *type_str); -static bool GameFlow_LoadLevelSequence( - struct json_object_s *obj, int32_t level_num); -static bool GameFlow_LoadScriptLevels(struct json_object_s *obj); -static bool GameFlow_LoadFromFileImpl(const char *file_name); +static bool M_LoadScriptMeta(struct json_object_s *obj); +static bool M_LoadScriptGameStrings(struct json_object_s *obj); +static bool M_IsLegacySequence(const char *type_str); +static bool M_LoadLevelSequence(struct json_object_s *obj, int32_t level_num); +static bool M_LoadScriptLevels(struct json_object_s *obj); +static bool M_LoadFromFileImpl(const char *file_name); static const STRING_TO_ENUM_TYPE m_GameflowLevelTypeEnumMap[] = { { "title", GFL_TITLE }, @@ -100,7 +99,7 @@ static const STRING_TO_ENUM_TYPE m_GameflowSeqTypeEnumMap[] = { { NULL, -1 }, }; -static int32_t GameFlow_StringToEnumType( +static int32_t M_StringToEnumType( const char *const str, const STRING_TO_ENUM_TYPE *map) { while (map->str) { @@ -112,7 +111,7 @@ static int32_t GameFlow_StringToEnumType( return map->val; } -static TRISTATE_BOOL GameFlow_ReadTristateBool( +static TRISTATE_BOOL M_ReadTristateBool( struct json_object_s *obj, const char *key) { struct json_value_s *value = json_object_get_value(obj, key); @@ -124,7 +123,7 @@ static TRISTATE_BOOL GameFlow_ReadTristateBool( return TB_UNSPECIFIED; } -static bool GameFlow_LoadScriptMeta(struct json_object_s *obj) +static bool M_LoadScriptMeta(struct json_object_s *obj) { const char *tmp_s; int tmp_i; @@ -162,15 +161,14 @@ static bool GameFlow_LoadScriptMeta(struct json_object_s *obj) } g_GameFlow.demo_delay = tmp_d; - g_GameFlow.force_game_modes = - GameFlow_ReadTristateBool(obj, "force_game_modes"); + g_GameFlow.force_game_modes = M_ReadTristateBool(obj, "force_game_modes"); if (json_object_get_bool(obj, "force_disable_game_modes", false)) { // backwards compatibility g_GameFlow.force_game_modes = TB_OFF; } g_GameFlow.force_save_crystals = - GameFlow_ReadTristateBool(obj, "force_save_crystals"); + M_ReadTristateBool(obj, "force_save_crystals"); if (json_object_get_bool(obj, "force_enable_save_crystals", false)) { // backwards compatibility g_GameFlow.force_save_crystals = TB_ON; @@ -233,7 +231,7 @@ static bool GameFlow_LoadScriptMeta(struct json_object_s *obj) return true; } -static bool GameFlow_LoadScriptGameStrings(struct json_object_s *obj) +static bool M_LoadScriptGameStrings(struct json_object_s *obj) { struct json_object_s *strings_obj = json_object_get_object(obj, "strings"); if (!strings_obj) { @@ -258,14 +256,13 @@ static bool GameFlow_LoadScriptGameStrings(struct json_object_s *obj) return true; } -static bool GameFlow_IsLegacySequence(const char *type_str) +static bool M_IsLegacySequence(const char *type_str) { return !strcmp(type_str, "fix_pyramid_secret") || !strcmp(type_str, "stop_cine"); } -static bool GameFlow_LoadLevelSequence( - struct json_object_s *obj, int32_t level_num) +static bool M_LoadLevelSequence(struct json_object_s *obj, int32_t level_num) { struct json_array_s *jseq_arr = json_object_get_array(obj, "sequence"); if (!jseq_arr) { @@ -294,8 +291,7 @@ static bool GameFlow_LoadLevelSequence( return false; } - seq->type = - GameFlow_StringToEnumType(type_str, m_GameflowSeqTypeEnumMap); + seq->type = M_StringToEnumType(type_str, m_GameflowSeqTypeEnumMap); switch (seq->type) { case GFS_START_GAME: @@ -507,7 +503,7 @@ static bool GameFlow_LoadLevelSequence( } default: - if (GameFlow_IsLegacySequence(type_str)) { + if (M_IsLegacySequence(type_str)) { seq->type = GFS_LEGACY; LOG_WARNING( "level %d, sequence %s: legacy type ignored", level_num, @@ -531,7 +527,7 @@ static bool GameFlow_LoadLevelSequence( return true; } -static bool GameFlow_LoadScriptLevels(struct json_object_s *obj) +static bool M_LoadScriptLevels(struct json_object_s *obj) { struct json_array_s *jlvl_arr = json_object_get_array(obj, "levels"); if (!jlvl_arr) { @@ -593,8 +589,7 @@ static bool GameFlow_LoadScriptLevels(struct json_object_s *obj) return false; } - cur->level_type = - GameFlow_StringToEnumType(tmp_s, m_GameflowLevelTypeEnumMap); + cur->level_type = M_StringToEnumType(tmp_s, m_GameflowLevelTypeEnumMap); switch (cur->level_type) { case GFL_TITLE: @@ -866,7 +861,7 @@ static bool GameFlow_LoadScriptLevels(struct json_object_s *obj) cur->item_drops.count = 0; } - if (!GameFlow_LoadLevelSequence(jlvl_obj, level_num)) { + if (!M_LoadLevelSequence(jlvl_obj, level_num)) { return false; } @@ -886,7 +881,7 @@ static bool GameFlow_LoadScriptLevels(struct json_object_s *obj) return true; } -static bool GameFlow_LoadFromFileImpl(const char *file_name) +static bool M_LoadFromFileImpl(const char *file_name) { GameFlow_Shutdown(); bool result = false; @@ -913,9 +908,9 @@ static bool GameFlow_LoadFromFileImpl(const char *file_name) struct json_object_s *root_obj = json_value_as_object(root); result = true; - result &= GameFlow_LoadScriptMeta(root_obj); - result &= GameFlow_LoadScriptGameStrings(root_obj); - result &= GameFlow_LoadScriptLevels(root_obj); + result &= M_LoadScriptMeta(root_obj); + result &= M_LoadScriptGameStrings(root_obj); + result &= M_LoadScriptLevels(root_obj); cleanup: if (root) { @@ -1021,7 +1016,7 @@ void GameFlow_Shutdown(void) bool GameFlow_LoadFromFile(const char *file_name) { - bool result = GameFlow_LoadFromFileImpl(file_name); + bool result = M_LoadFromFileImpl(file_name); g_InvItemMedi.string = GS(INV_ITEM_MEDI), g_InvItemBigMedi.string = GS(INV_ITEM_BIG_MEDI), diff --git a/src/game/inject.c b/src/game/inject.c index 86311ea6e..e5add3ac4 100644 --- a/src/game/inject.c +++ b/src/game/inject.c @@ -112,80 +112,59 @@ static int32_t m_NumInjections = 0; static INJECTION *m_Injections = NULL; static INJECTION_INFO *m_Aggregate = NULL; -static void Inject_LoadFromFile(INJECTION *injection, const char *filename); +static void M_LoadFromFile(INJECTION *injection, const char *filename); -static uint16_t Inject_RemapRGB(LEVEL_INFO *level_info, RGB_888 rgb); -static void Inject_AlignTextureReferences( +static uint16_t M_RemapRGB(LEVEL_INFO *level_info, RGB_888 rgb); +static void M_AlignTextureReferences( OBJECT_INFO *object, uint16_t *palette_map, int32_t page_base); -static void Inject_LoadTexturePages( +static void M_LoadTexturePages( INJECTION *injection, LEVEL_INFO *level_info, uint16_t *palette_map, RGBA_8888 *page_ptr); -static void Inject_TextureData( +static void M_TextureData( INJECTION *injection, LEVEL_INFO *level_info, int32_t page_base); -static void Inject_MeshData(INJECTION *injection, LEVEL_INFO *level_info); -static void Inject_AnimData(INJECTION *injection, LEVEL_INFO *level_info); -static void Inject_AnimRangeEdits(INJECTION *injection); -static void Inject_ObjectData( +static void M_MeshData(INJECTION *injection, LEVEL_INFO *level_info); +static void M_AnimData(INJECTION *injection, LEVEL_INFO *level_info); +static void M_AnimRangeEdits(INJECTION *injection); +static void M_ObjectData( INJECTION *injection, LEVEL_INFO *level_info, uint16_t *palette_map); -static void Inject_SFXData(INJECTION *injection, LEVEL_INFO *level_info); +static void M_SFXData(INJECTION *injection, LEVEL_INFO *level_info); -static int16_t *Inject_GetMeshTexture(FACE_EDIT *face_edit); +static int16_t *M_GetMeshTexture(FACE_EDIT *face_edit); -static void Inject_ApplyFaceEdit( +static void M_ApplyFaceEdit( FACE_EDIT *face_edit, int16_t *data_ptr, int16_t texture); -static void Inject_ApplyMeshEdit(MESH_EDIT *mesh_edit, uint16_t *palette_map); -static void Inject_MeshEdits(INJECTION *injection, uint16_t *palette_map); -static void Inject_TextureOverwrites( +static void M_ApplyMeshEdit(MESH_EDIT *mesh_edit, uint16_t *palette_map); +static void M_MeshEdits(INJECTION *injection, uint16_t *palette_map); +static void M_TextureOverwrites( INJECTION *injection, LEVEL_INFO *level_info, uint16_t *palette_map); -static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info); -static void Inject_TriggerParameterChange( - INJECTION *injection, SECTOR_INFO *sector); -static void Inject_SetMusicOneShot(SECTOR_INFO *sector); -static void Inject_InsertFloorData( +static void M_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info); +static void M_TriggerParameterChange(INJECTION *injection, SECTOR_INFO *sector); +static void M_SetMusicOneShot(SECTOR_INFO *sector); +static void M_InsertFloorData( INJECTION *injection, SECTOR_INFO *sector, LEVEL_INFO *level_info); -static void Inject_RoomShift(INJECTION *injection, int16_t room_num); -static void Inject_TriggeredItem(INJECTION *injection, LEVEL_INFO *level_info); - -static void Inject_RoomMeshEdits(INJECTION *injection); -static void Inject_TextureRoomFace(INJECTION *injection); -static void Inject_MoveRoomFace(INJECTION *injection); -static void Inject_AlterRoomVertex(INJECTION *injection); -static void Inject_RotateRoomFace(INJECTION *injection); -static void Inject_AddRoomFace(INJECTION *injection); -static void Inject_AddRoomVertex(INJECTION *injection); - -static int16_t *Inject_GetRoomTexture( +static void M_RoomShift(INJECTION *injection, int16_t room_num); +static void M_TriggeredItem(INJECTION *injection, LEVEL_INFO *level_info); + +static void M_RoomMeshEdits(INJECTION *injection); +static void M_TextureRoomFace(INJECTION *injection); +static void M_MoveRoomFace(INJECTION *injection); +static void M_AlterRoomVertex(INJECTION *injection); +static void M_RotateRoomFace(INJECTION *injection); +static void M_AddRoomFace(INJECTION *injection); +static void M_AddRoomVertex(INJECTION *injection); + +static int16_t *M_GetRoomTexture( int16_t room, FACE_TYPE face_type, int16_t face_index); -static int16_t *Inject_GetRoomFace( +static int16_t *M_GetRoomFace( int16_t room, FACE_TYPE face_type, int16_t face_index); -static void Inject_RoomDoorEdits(INJECTION *injection); +static void M_RoomDoorEdits(INJECTION *injection); -static void Inject_ItemPositions(INJECTION *injection); +static void M_ItemPositions(INJECTION *injection); -void Inject_Init( - int32_t num_injections, char *filenames[], INJECTION_INFO *aggregate) -{ - m_NumInjections = num_injections; - if (!num_injections) { - return; - } - - BENCHMARK *const benchmark = Benchmark_Start(); - - m_Injections = Memory_Alloc(sizeof(INJECTION) * num_injections); - m_Aggregate = aggregate; - - for (int32_t i = 0; i < num_injections; i++) { - Inject_LoadFromFile(&m_Injections[i], filenames[i]); - } - - Benchmark_End(benchmark, NULL); -} - -static void Inject_LoadFromFile(INJECTION *injection, const char *filename) +static void M_LoadFromFile(INJECTION *injection, const char *filename) { injection->relevant = false; injection->info = NULL; @@ -380,82 +359,7 @@ static void Inject_LoadFromFile(INJECTION *injection, const char *filename) LOG_INFO("%s queued for injection", filename); } -void Inject_AllInjections(LEVEL_INFO *level_info) -{ - if (!m_Injections) { - return; - } - - BENCHMARK *const benchmark = Benchmark_Start(); - - uint16_t palette_map[256]; - RGBA_8888 *source_pages = Memory_Alloc( - m_Aggregate->texture_page_count * PAGE_SIZE * sizeof(RGBA_8888)); - int32_t source_page_count = 0; - int32_t tpage_base = level_info->texture_page_count; - - for (int32_t i = 0; i < m_NumInjections; i++) { - INJECTION *injection = &m_Injections[i]; - if (!injection->relevant) { - continue; - } - - Inject_LoadTexturePages( - injection, level_info, palette_map, - source_pages + (source_page_count * PAGE_SIZE)); - - Inject_TextureData(injection, level_info, tpage_base); - Inject_MeshData(injection, level_info); - Inject_AnimData(injection, level_info); - Inject_ObjectData(injection, level_info, palette_map); - Inject_SFXData(injection, level_info); - - Inject_MeshEdits(injection, palette_map); - Inject_TextureOverwrites(injection, level_info, palette_map); - Inject_FloorDataEdits(injection, level_info); - Inject_RoomMeshEdits(injection); - Inject_RoomDoorEdits(injection); - Inject_AnimRangeEdits(injection); - - Inject_ItemPositions(injection); - - // Realign base indices for the next injection. - INJECTION_INFO *inj_info = injection->info; - level_info->anim_command_count += inj_info->anim_cmd_count; - level_info->anim_bone_count += inj_info->anim_bone_count; - level_info->anim_frame_data_count += inj_info->anim_frame_data_count; - level_info->anim_frame_count += inj_info->anim_frame_count; - level_info->anim_frame_mesh_rot_count += - inj_info->anim_frame_mesh_rot_count; - level_info->anim_count += inj_info->anim_count; - level_info->mesh_ptr_count += inj_info->mesh_ptr_count; - level_info->texture_count += inj_info->texture_count; - source_page_count += inj_info->texture_page_count; - tpage_base += inj_info->texture_page_count; - } - - if (source_page_count) { - PACKER_DATA *data = Memory_Alloc(sizeof(PACKER_DATA)); - data->level_page_count = level_info->texture_page_count; - data->source_page_count = source_page_count; - data->source_pages = source_pages; - data->level_pages = level_info->texture_rgb_page_ptrs; - data->object_count = level_info->texture_count; - data->sprite_count = level_info->sprite_info_count; - - if (Packer_Pack(data)) { - level_info->texture_page_count += Packer_GetAddedPageCount(); - level_info->texture_rgb_page_ptrs = data->level_pages; - } - - Memory_FreePointer(&source_pages); - Memory_FreePointer(&data); - } - - Benchmark_End(benchmark, NULL); -} - -static void Inject_LoadTexturePages( +static void M_LoadTexturePages( INJECTION *injection, LEVEL_INFO *level_info, uint16_t *palette_map, RGBA_8888 *page_ptr) { @@ -477,7 +381,7 @@ static void Inject_LoadTexturePages( source_palette[i].b *= 4; } for (int32_t i = 0; i < 256; i++) { - palette_map[i] = Inject_RemapRGB(level_info, source_palette[i]); + palette_map[i] = M_RemapRGB(level_info, source_palette[i]); } // Read in each page for this injection and realign the pixels @@ -504,7 +408,7 @@ static void Inject_LoadTexturePages( Benchmark_End(benchmark, NULL); } -static void Inject_TextureData( +static void M_TextureData( INJECTION *injection, LEVEL_INFO *level_info, int32_t page_base) { BENCHMARK *const benchmark = Benchmark_Start(); @@ -561,7 +465,7 @@ static void Inject_TextureData( Benchmark_End(benchmark, NULL); } -static void Inject_MeshData(INJECTION *injection, LEVEL_INFO *level_info) +static void M_MeshData(INJECTION *injection, LEVEL_INFO *level_info) { BENCHMARK *const benchmark = Benchmark_Start(); @@ -585,7 +489,7 @@ static void Inject_MeshData(INJECTION *injection, LEVEL_INFO *level_info) Benchmark_End(benchmark, NULL); } -static void Inject_AnimData(INJECTION *injection, LEVEL_INFO *level_info) +static void M_AnimData(INJECTION *injection, LEVEL_INFO *level_info) { BENCHMARK *const benchmark = Benchmark_Start(); @@ -694,7 +598,7 @@ static void Inject_AnimData(INJECTION *injection, LEVEL_INFO *level_info) Benchmark_End(benchmark, NULL); } -static void Inject_AnimRangeEdits(INJECTION *injection) +static void M_AnimRangeEdits(INJECTION *injection) { if (injection->version < INJ_VERSION_3) { return; @@ -756,7 +660,7 @@ static void Inject_AnimRangeEdits(INJECTION *injection) Benchmark_End(benchmark, NULL); } -static void Inject_ObjectData( +static void M_ObjectData( INJECTION *injection, LEVEL_INFO *level_info, uint16_t *palette_map) { BENCHMARK *const benchmark = Benchmark_Start(); @@ -804,7 +708,7 @@ static void Inject_ObjectData( } if (num_meshes) { - Inject_AlignTextureReferences( + M_AlignTextureReferences( object, palette_map, level_info->texture_count); } } @@ -812,7 +716,7 @@ static void Inject_ObjectData( Benchmark_End(benchmark, NULL); } -static void Inject_SFXData(INJECTION *injection, LEVEL_INFO *level_info) +static void M_SFXData(INJECTION *injection, LEVEL_INFO *level_info) { BENCHMARK *const benchmark = Benchmark_Start(); @@ -849,7 +753,7 @@ static void Inject_SFXData(INJECTION *injection, LEVEL_INFO *level_info) Benchmark_End(benchmark, NULL); } -static void Inject_AlignTextureReferences( +static void M_AlignTextureReferences( OBJECT_INFO *object, uint16_t *palette_map, int32_t page_base) { int16_t **mesh = &g_Meshes[object->mesh_index]; @@ -893,7 +797,7 @@ static void Inject_AlignTextureReferences( } } -static uint16_t Inject_RemapRGB(LEVEL_INFO *level_info, RGB_888 rgb) +static uint16_t M_RemapRGB(LEVEL_INFO *level_info, RGB_888 rgb) { // Find the index of the exact match to the given RGB for (int32_t i = 0; i < level_info->palette_size; i++) { @@ -911,7 +815,7 @@ static uint16_t Inject_RemapRGB(LEVEL_INFO *level_info, RGB_888 rgb) return level_info->palette_size - 1; } -static void Inject_MeshEdits(INJECTION *injection, uint16_t *palette_map) +static void M_MeshEdits(INJECTION *injection, uint16_t *palette_map) { INJECTION_INFO *inj_info = injection->info; VFILE *const fp = injection->fp; @@ -966,7 +870,7 @@ static void Inject_MeshEdits(INJECTION *injection, uint16_t *palette_map) vertex_edit->z_change = VFile_ReadS16(fp); } - Inject_ApplyMeshEdit(mesh_edit, palette_map); + M_ApplyMeshEdit(mesh_edit, palette_map); for (int32_t j = 0; j < mesh_edit->face_edit_count; j++) { FACE_EDIT *face_edit = &mesh_edit->face_edits[j]; @@ -981,7 +885,7 @@ static void Inject_MeshEdits(INJECTION *injection, uint16_t *palette_map) Benchmark_End(benchmark, NULL); } -static void Inject_ApplyMeshEdit(MESH_EDIT *mesh_edit, uint16_t *palette_map) +static void M_ApplyMeshEdit(MESH_EDIT *mesh_edit, uint16_t *palette_map) { OBJECT_INFO object = g_Objects[mesh_edit->object_id]; if (!object.loaded) { @@ -1027,7 +931,7 @@ static void Inject_ApplyMeshEdit(MESH_EDIT *mesh_edit, uint16_t *palette_map) if (face_edit->source_identifier < 0) { texture = palette_map[-face_edit->source_identifier]; } else { - int16_t *tex_ptr = Inject_GetMeshTexture(face_edit); + int16_t *tex_ptr = M_GetMeshTexture(face_edit); if (!tex_ptr) { continue; } @@ -1038,30 +942,30 @@ static void Inject_ApplyMeshEdit(MESH_EDIT *mesh_edit, uint16_t *palette_map) int32_t num_faces = *data_ptr++; if (face_edit->face_type == FT_TEXTURED_QUAD) { - Inject_ApplyFaceEdit(face_edit, data_ptr, texture); + M_ApplyFaceEdit(face_edit, data_ptr, texture); } data_ptr += 5 * num_faces; num_faces = *data_ptr++; if (face_edit->face_type == FT_TEXTURED_TRIANGLE) { - Inject_ApplyFaceEdit(face_edit, data_ptr, texture); + M_ApplyFaceEdit(face_edit, data_ptr, texture); } data_ptr += 4 * num_faces; num_faces = *data_ptr++; if (face_edit->face_type == FT_COLOURED_QUAD) { - Inject_ApplyFaceEdit(face_edit, data_ptr, texture); + M_ApplyFaceEdit(face_edit, data_ptr, texture); } data_ptr += 5 * num_faces; num_faces = *data_ptr++; if (face_edit->face_type == FT_COLOURED_TRIANGLE) { - Inject_ApplyFaceEdit(face_edit, data_ptr, texture); + M_ApplyFaceEdit(face_edit, data_ptr, texture); } } } -static void Inject_ApplyFaceEdit( +static void M_ApplyFaceEdit( FACE_EDIT *face_edit, int16_t *data_ptr, int16_t texture) { int32_t vertex_count; @@ -1085,7 +989,7 @@ static void Inject_ApplyFaceEdit( } } -static int16_t *Inject_GetMeshTexture(FACE_EDIT *face_edit) +static int16_t *M_GetMeshTexture(FACE_EDIT *face_edit) { OBJECT_INFO object = g_Objects[face_edit->object_id]; if (!object.loaded) { @@ -1132,7 +1036,7 @@ static int16_t *Inject_GetMeshTexture(FACE_EDIT *face_edit) return NULL; } -static void Inject_TextureOverwrites( +static void M_TextureOverwrites( INJECTION *injection, LEVEL_INFO *level_info, uint16_t *palette_map) { BENCHMARK *const benchmark = Benchmark_Start(); @@ -1177,7 +1081,7 @@ static void Inject_TextureOverwrites( Benchmark_End(benchmark, NULL); } -static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info) +static void M_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info) { BENCHMARK *const benchmark = Benchmark_Start(); @@ -1210,19 +1114,19 @@ static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info) const FLOOR_EDIT_TYPE edit_type = VFile_ReadS32(fp); switch (edit_type) { case FET_TRIGGER_PARAM: - Inject_TriggerParameterChange(injection, sector); + M_TriggerParameterChange(injection, sector); break; case FET_MUSIC_ONESHOT: - Inject_SetMusicOneShot(sector); + M_SetMusicOneShot(sector); break; case FET_FD_INSERT: - Inject_InsertFloorData(injection, sector, level_info); + M_InsertFloorData(injection, sector, level_info); break; case FET_ROOM_SHIFT: - Inject_RoomShift(injection, room); + M_RoomShift(injection, room); break; case FET_TRIGGER_ITEM: - Inject_TriggeredItem(injection, level_info); + M_TriggeredItem(injection, level_info); break; default: LOG_WARNING("Unknown floor data edit type: %d", edit_type); @@ -1234,8 +1138,7 @@ static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info) Benchmark_End(benchmark, NULL); } -static void Inject_TriggerParameterChange( - INJECTION *injection, SECTOR_INFO *sector) +static void M_TriggerParameterChange(INJECTION *injection, SECTOR_INFO *sector) { VFILE *const fp = injection->fp; @@ -1272,7 +1175,7 @@ static void Inject_TriggerParameterChange( } } -static void Inject_SetMusicOneShot(SECTOR_INFO *sector) +static void M_SetMusicOneShot(SECTOR_INFO *sector) { if (sector == NULL || sector->trigger == NULL) { return; @@ -1286,7 +1189,7 @@ static void Inject_SetMusicOneShot(SECTOR_INFO *sector) } } -static void Inject_InsertFloorData( +static void M_InsertFloorData( INJECTION *injection, SECTOR_INFO *sector, LEVEL_INFO *level_info) { VFILE *const fp = injection->fp; @@ -1306,7 +1209,7 @@ static void Inject_InsertFloorData( Room_PopulateSectorData(sector, data, 0, NULL_FD_INDEX); } -static void Inject_RoomShift(INJECTION *injection, int16_t room_num) +static void M_RoomShift(INJECTION *injection, int16_t room_num) { VFILE *const fp = injection->fp; @@ -1356,7 +1259,7 @@ static void Inject_RoomShift(INJECTION *injection, int16_t room_num) } } -static void Inject_TriggeredItem(INJECTION *injection, LEVEL_INFO *level_info) +static void M_TriggeredItem(INJECTION *injection, LEVEL_INFO *level_info) { VFILE *const fp = injection->fp; @@ -1383,32 +1286,7 @@ static void Inject_TriggeredItem(INJECTION *injection, LEVEL_INFO *level_info) g_LevelItemCount++; } -uint32_t Inject_GetExtraRoomMeshSize(int32_t room_index) -{ - uint32_t size = 0; - if (!m_Injections) { - return size; - } - - for (int32_t i = 0; i < m_NumInjections; i++) { - INJECTION *injection = &m_Injections[i]; - if (!injection->relevant || injection->version < INJ_VERSION_2) { - continue; - } - - INJECTION_INFO *inj_info = injection->info; - for (int32_t j = 0; j < inj_info->room_mesh_count; j++) { - INJECTION_ROOM_MESH *mesh = &inj_info->room_meshes[j]; - if (mesh->room_index == room_index) { - size += mesh->extra_size; - } - } - } - - return size; -} - -static void Inject_RoomMeshEdits(INJECTION *injection) +static void M_RoomMeshEdits(INJECTION *injection) { if (injection->version < INJ_VERSION_2) { return; @@ -1425,22 +1303,22 @@ static void Inject_RoomMeshEdits(INJECTION *injection) switch (edit_type) { case RMET_TEXTURE_FACE: - Inject_TextureRoomFace(injection); + M_TextureRoomFace(injection); break; case RMET_MOVE_FACE: - Inject_MoveRoomFace(injection); + M_MoveRoomFace(injection); break; case RMET_ALTER_VERTEX: - Inject_AlterRoomVertex(injection); + M_AlterRoomVertex(injection); break; case RMET_ROTATE_FACE: - Inject_RotateRoomFace(injection); + M_RotateRoomFace(injection); break; case RMET_ADD_FACE: - Inject_AddRoomFace(injection); + M_AddRoomFace(injection); break; case RMET_ADD_VERTEX: - Inject_AddRoomVertex(injection); + M_AddRoomVertex(injection); break; default: LOG_WARNING("Unknown room mesh edit type: %d", edit_type); @@ -1451,7 +1329,7 @@ static void Inject_RoomMeshEdits(INJECTION *injection) Benchmark_End(benchmark, NULL); } -static void Inject_TextureRoomFace(INJECTION *injection) +static void M_TextureRoomFace(INJECTION *injection) { VFILE *const fp = injection->fp; @@ -1463,15 +1341,15 @@ static void Inject_TextureRoomFace(INJECTION *injection) const int16_t source_face = VFile_ReadS16(fp); int16_t *source_texture = - Inject_GetRoomTexture(source_room, source_face_type, source_face); + M_GetRoomTexture(source_room, source_face_type, source_face); int16_t *target_texture = - Inject_GetRoomTexture(target_room, target_face_type, target_face); + M_GetRoomTexture(target_room, target_face_type, target_face); if (source_texture && target_texture) { *target_texture = *source_texture; } } -static void Inject_MoveRoomFace(INJECTION *injection) +static void M_MoveRoomFace(INJECTION *injection) { VFILE *const fp = injection->fp; @@ -1484,8 +1362,7 @@ static void Inject_MoveRoomFace(INJECTION *injection) const int16_t vertex_index = VFile_ReadS16(fp); const int16_t new_vertex = VFile_ReadS16(fp); - int16_t *target = - Inject_GetRoomFace(target_room, face_type, target_face); + int16_t *target = M_GetRoomFace(target_room, face_type, target_face); if (target) { target += vertex_index; *target = new_vertex; @@ -1493,7 +1370,7 @@ static void Inject_MoveRoomFace(INJECTION *injection) } } -static void Inject_AlterRoomVertex(INJECTION *injection) +static void M_AlterRoomVertex(INJECTION *injection) { VFILE *const fp = injection->fp; @@ -1529,7 +1406,7 @@ static void Inject_AlterRoomVertex(INJECTION *injection) CLAMPG(*(data_ptr + 4), MAX_LIGHTING); } -static void Inject_RotateRoomFace(INJECTION *injection) +static void M_RotateRoomFace(INJECTION *injection) { VFILE *const fp = injection->fp; @@ -1538,7 +1415,7 @@ static void Inject_RotateRoomFace(INJECTION *injection) const int16_t target_face = VFile_ReadS16(fp); const uint8_t num_rotations = VFile_ReadU8(fp); - int16_t *target = Inject_GetRoomFace(target_room, face_type, target_face); + int16_t *target = M_GetRoomFace(target_room, face_type, target_face); if (!target) { return; } @@ -1558,7 +1435,7 @@ static void Inject_RotateRoomFace(INJECTION *injection) } } -static void Inject_AddRoomFace(INJECTION *injection) +static void M_AddRoomFace(INJECTION *injection) { VFILE *const fp = injection->fp; @@ -1579,7 +1456,7 @@ static void Inject_AddRoomFace(INJECTION *injection) } int16_t *source_texture = - Inject_GetRoomTexture(source_room, face_type, source_face); + M_GetRoomTexture(source_room, face_type, source_face); if (!source_texture) { return; } @@ -1630,7 +1507,7 @@ static void Inject_AddRoomFace(INJECTION *injection) r->data[inject_pos] = *source_texture; } -static void Inject_AddRoomVertex(INJECTION *injection) +static void M_AddRoomVertex(INJECTION *injection) { VFILE *const fp = injection->fp; @@ -1671,17 +1548,17 @@ static void Inject_AddRoomVertex(INJECTION *injection) r->data[inject_pos] = lighting; } -static int16_t *Inject_GetRoomTexture( +static int16_t *M_GetRoomTexture( int16_t room, FACE_TYPE face_type, int16_t face_index) { - int16_t *face = Inject_GetRoomFace(room, face_type, face_index); + int16_t *face = M_GetRoomFace(room, face_type, face_index); if (face) { face += face_type == FT_TEXTURED_QUAD ? 4 : 3; } return face; } -static int16_t *Inject_GetRoomFace( +static int16_t *M_GetRoomFace( int16_t room, FACE_TYPE face_type, int16_t face_index) { ROOM_INFO *r = NULL; @@ -1721,7 +1598,7 @@ static int16_t *Inject_GetRoomFace( return NULL; } -static void Inject_RoomDoorEdits(INJECTION *injection) +static void M_RoomDoorEdits(INJECTION *injection) { if (injection->version < INJ_VERSION_2) { return; @@ -1779,7 +1656,7 @@ static void Inject_RoomDoorEdits(INJECTION *injection) Benchmark_End(benchmark, NULL); } -static void Inject_ItemPositions(INJECTION *injection) +static void M_ItemPositions(INJECTION *injection) { if (injection->version < INJ_VERSION_4) { return; @@ -1823,6 +1700,101 @@ static void Inject_ItemPositions(INJECTION *injection) Benchmark_End(benchmark, NULL); } +void Inject_Init( + int32_t num_injections, char *filenames[], INJECTION_INFO *aggregate) +{ + m_NumInjections = num_injections; + if (!num_injections) { + return; + } + + BENCHMARK *const benchmark = Benchmark_Start(); + + m_Injections = Memory_Alloc(sizeof(INJECTION) * num_injections); + m_Aggregate = aggregate; + + for (int32_t i = 0; i < num_injections; i++) { + M_LoadFromFile(&m_Injections[i], filenames[i]); + } + + Benchmark_End(benchmark, NULL); +} + +void Inject_AllInjections(LEVEL_INFO *level_info) +{ + if (!m_Injections) { + return; + } + + BENCHMARK *const benchmark = Benchmark_Start(); + + uint16_t palette_map[256]; + RGBA_8888 *source_pages = Memory_Alloc( + m_Aggregate->texture_page_count * PAGE_SIZE * sizeof(RGBA_8888)); + int32_t source_page_count = 0; + int32_t tpage_base = level_info->texture_page_count; + + for (int32_t i = 0; i < m_NumInjections; i++) { + INJECTION *injection = &m_Injections[i]; + if (!injection->relevant) { + continue; + } + + M_LoadTexturePages( + injection, level_info, palette_map, + source_pages + (source_page_count * PAGE_SIZE)); + + M_TextureData(injection, level_info, tpage_base); + M_MeshData(injection, level_info); + M_AnimData(injection, level_info); + M_ObjectData(injection, level_info, palette_map); + M_SFXData(injection, level_info); + + M_MeshEdits(injection, palette_map); + M_TextureOverwrites(injection, level_info, palette_map); + M_FloorDataEdits(injection, level_info); + M_RoomMeshEdits(injection); + M_RoomDoorEdits(injection); + M_AnimRangeEdits(injection); + + M_ItemPositions(injection); + + // Realign base indices for the next injection. + INJECTION_INFO *inj_info = injection->info; + level_info->anim_command_count += inj_info->anim_cmd_count; + level_info->anim_bone_count += inj_info->anim_bone_count; + level_info->anim_frame_data_count += inj_info->anim_frame_data_count; + level_info->anim_frame_count += inj_info->anim_frame_count; + level_info->anim_frame_mesh_rot_count += + inj_info->anim_frame_mesh_rot_count; + level_info->anim_count += inj_info->anim_count; + level_info->mesh_ptr_count += inj_info->mesh_ptr_count; + level_info->texture_count += inj_info->texture_count; + source_page_count += inj_info->texture_page_count; + tpage_base += inj_info->texture_page_count; + } + + if (source_page_count) { + PACKER_DATA *data = Memory_Alloc(sizeof(PACKER_DATA)); + data->level_page_count = level_info->texture_page_count; + data->source_page_count = source_page_count; + data->source_pages = source_pages; + data->level_pages = level_info->texture_rgb_page_ptrs; + data->object_count = level_info->texture_count; + data->sprite_count = level_info->sprite_info_count; + + if (Packer_Pack(data)) { + level_info->texture_page_count += Packer_GetAddedPageCount(); + level_info->texture_rgb_page_ptrs = data->level_pages; + } + + Memory_FreePointer(&source_pages); + Memory_FreePointer(&data); + } + + Benchmark_End(benchmark, NULL); +} + void Inject_Cleanup(void) { if (!m_NumInjections) { @@ -1847,3 +1819,28 @@ void Inject_Cleanup(void) Memory_FreePointer(&m_Injections); Benchmark_End(benchmark, NULL); } + +uint32_t Inject_GetExtraRoomMeshSize(int32_t room_index) +{ + uint32_t size = 0; + if (!m_Injections) { + return size; + } + + for (int32_t i = 0; i < m_NumInjections; i++) { + INJECTION *injection = &m_Injections[i]; + if (!injection->relevant || injection->version < INJ_VERSION_2) { + continue; + } + + INJECTION_INFO *inj_info = injection->info; + for (int32_t j = 0; j < inj_info->room_mesh_count; j++) { + INJECTION_ROOM_MESH *mesh = &inj_info->room_meshes[j]; + if (mesh->room_index == room_index) { + size += mesh->extra_size; + } + } + } + + return size; +} diff --git a/src/game/input.c b/src/game/input.c index 604d24037..1ffeace53 100644 --- a/src/game/input.c +++ b/src/game/input.c @@ -20,9 +20,9 @@ static bool m_BtnConflict[INPUT_ROLE_NUMBER_OF] = { false }; static int32_t m_HoldBack = 0; static int32_t m_HoldForward = 0; -static INPUT_STATE Input_GetDebounced(INPUT_STATE input); +static INPUT_STATE M_GetDebounced(INPUT_STATE input); -static INPUT_STATE Input_GetDebounced(INPUT_STATE input) +static INPUT_STATE M_GetDebounced(INPUT_STATE input) { INPUT_STATE result; result.any = input.any & ~g_OldInputDB.any; @@ -153,7 +153,7 @@ void Input_Update(void) g_Input.change_target = 0; } - g_InputDB = Input_GetDebounced(g_Input); + g_InputDB = M_GetDebounced(g_Input); } bool Input_IsKeyConflicted(CONTROL_MODE mode, INPUT_ROLE role) diff --git a/src/game/lara/lara_col.c b/src/game/lara/lara_col.c index f0ffc5df3..78176ef51 100644 --- a/src/game/lara/lara_col.c +++ b/src/game/lara/lara_col.c @@ -57,10 +57,10 @@ void (*g_LaraCollisionRoutines[])(ITEM_INFO *item, COLL_INFO *coll) = { Lara_Col_Twist, Lara_Col_UWRoll, }; -static void Lara_Col_Default(ITEM_INFO *item, COLL_INFO *coll); -static void Lara_Col_Jumper(ITEM_INFO *item, COLL_INFO *coll); +static void M_Default(ITEM_INFO *item, COLL_INFO *coll); +static void M_Jumper(ITEM_INFO *item, COLL_INFO *coll); -static void Lara_Col_Default(ITEM_INFO *item, COLL_INFO *coll) +static void M_Default(ITEM_INFO *item, COLL_INFO *coll) { g_Lara.move_angle = item->rot.y; coll->bad_pos = STEPUP_HEIGHT; @@ -71,7 +71,7 @@ static void Lara_Col_Default(ITEM_INFO *item, COLL_INFO *coll) Lara_GetCollisionInfo(item, coll); } -static void Lara_Col_Jumper(ITEM_INFO *item, COLL_INFO *coll) +static void M_Jumper(ITEM_INFO *item, COLL_INFO *coll) { coll->bad_pos = NO_BAD_POS; coll->bad_neg = -STEPUP_HEIGHT; @@ -522,7 +522,7 @@ void Lara_Col_Back(ITEM_INFO *item, COLL_INFO *coll) void Lara_Col_Null(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_FastTurn(ITEM_INFO *item, COLL_INFO *coll) @@ -601,19 +601,19 @@ void Lara_Col_Slide(ITEM_INFO *item, COLL_INFO *coll) void Lara_Col_BackJump(ITEM_INFO *item, COLL_INFO *coll) { g_Lara.move_angle = item->rot.y - PHD_180; - Lara_Col_Jumper(item, coll); + M_Jumper(item, coll); } void Lara_Col_RightJump(ITEM_INFO *item, COLL_INFO *coll) { g_Lara.move_angle = item->rot.y + PHD_90; - Lara_Col_Jumper(item, coll); + M_Jumper(item, coll); } void Lara_Col_LeftJump(ITEM_INFO *item, COLL_INFO *coll) { g_Lara.move_angle = item->rot.y - PHD_90; - Lara_Col_Jumper(item, coll); + M_Jumper(item, coll); } void Lara_Col_UpJump(ITEM_INFO *item, COLL_INFO *coll) @@ -706,32 +706,32 @@ void Lara_Col_SlideBack(ITEM_INFO *item, COLL_INFO *coll) void Lara_Col_PushBlock(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_PullBlock(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_PPReady(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_Pickup(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_Controlled(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_Twist(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_UWRoll(ITEM_INFO *item, COLL_INFO *coll) @@ -741,22 +741,22 @@ void Lara_Col_UWRoll(ITEM_INFO *item, COLL_INFO *coll) void Lara_Col_SwitchOn(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_SwitchOff(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_UseKey(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_UsePuzzle(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_Roll(ITEM_INFO *item, COLL_INFO *coll) @@ -829,12 +829,12 @@ void Lara_Col_Special(ITEM_INFO *item, COLL_INFO *coll) void Lara_Col_UseMidas(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_DieMidas(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_SwanDive(ITEM_INFO *item, COLL_INFO *coll) @@ -879,12 +879,12 @@ void Lara_Col_FastDive(ITEM_INFO *item, COLL_INFO *coll) void Lara_Col_Gymnast(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_WaterOut(ITEM_INFO *item, COLL_INFO *coll) { - Lara_Col_Default(item, coll); + M_Default(item, coll); } void Lara_Col_SurfSwim(ITEM_INFO *item, COLL_INFO *coll) diff --git a/src/game/lara/lara_control.c b/src/game/lara/lara_control.c index 7373aeb6e..434732974 100644 --- a/src/game/lara/lara_control.c +++ b/src/game/lara/lara_control.c @@ -26,10 +26,10 @@ static int32_t m_OpenDoorsCheatCooldown = 0; -static void Lara_WaterCurrent(COLL_INFO *coll); -static void Lara_BaddieCollision(ITEM_INFO *lara_item, COLL_INFO *coll); +static void M_WaterCurrent(COLL_INFO *coll); +static void M_BaddieCollision(ITEM_INFO *lara_item, COLL_INFO *coll); -static void Lara_WaterCurrent(COLL_INFO *coll) +static void M_WaterCurrent(COLL_INFO *coll) { XYZ_32 target; @@ -109,7 +109,7 @@ static void Lara_WaterCurrent(COLL_INFO *coll) coll->old.z = item->pos.z; } -static void Lara_BaddieCollision(ITEM_INFO *lara_item, COLL_INFO *coll) +static void M_BaddieCollision(ITEM_INFO *lara_item, COLL_INFO *coll) { lara_item->hit_status = 0; g_Lara.hit_direction = -1; @@ -235,7 +235,7 @@ void Lara_HandleAboveWater(ITEM_INFO *item, COLL_INFO *coll) item->rot.y += g_Lara.turn_rate; Lara_Animate(item); - Lara_BaddieCollision(item, coll); + M_BaddieCollision(item, coll); g_LaraCollisionRoutines[item->current_anim_state](item, coll); Item_UpdateRoom(item, -LARA_HEIGHT / 2); Gun_Control(); @@ -288,7 +288,7 @@ void Lara_HandleSurface(ITEM_INFO *item, COLL_INFO *coll) } if (g_Lara.current_active && g_Lara.water_status != LWS_CHEAT) { - Lara_WaterCurrent(coll); + M_WaterCurrent(coll); } else { LOT_ClearLOT(&g_Lara.LOT); } @@ -300,7 +300,7 @@ void Lara_HandleSurface(ITEM_INFO *item, COLL_INFO *coll) item->pos.z += (Math_Cos(g_Lara.move_angle) * item->fall_speed) >> (W2V_SHIFT + 2); - Lara_BaddieCollision(item, coll); + M_BaddieCollision(item, coll); g_LaraCollisionRoutines[item->current_anim_state](item, coll); Item_UpdateRoom(item, 100); @@ -360,7 +360,7 @@ void Lara_HandleUnderwater(ITEM_INFO *item, COLL_INFO *coll) } if (g_Lara.current_active && g_Lara.water_status != LWS_CHEAT) { - Lara_WaterCurrent(coll); + M_WaterCurrent(coll); } else { LOT_ClearLOT(&g_Lara.LOT); } @@ -379,7 +379,7 @@ void Lara_HandleUnderwater(ITEM_INFO *item, COLL_INFO *coll) >> W2V_SHIFT; if (g_Lara.water_status != LWS_CHEAT) { - Lara_BaddieCollision(item, coll); + M_BaddieCollision(item, coll); } if (g_Lara.water_status == LWS_CHEAT) { diff --git a/src/game/lara/lara_hair.c b/src/game/lara/lara_hair.c index 231b7c4db..fc1b74110 100644 --- a/src/game/lara/lara_hair.c +++ b/src/game/lara/lara_hair.c @@ -25,7 +25,26 @@ static GAME_OBJECT_ID m_LaraType = O_LARA; static HAIR_SEGMENT m_Hair[HAIR_SEGMENTS + 1] = { 0 }; static XYZ_32 m_HVel[HAIR_SEGMENTS + 1] = { 0 }; -static int16_t Lara_Hair_GetRoom(int32_t x, int32_t y, int32_t z); +static int16_t M_GetRoom(int32_t x, int32_t y, int32_t z); + +static int16_t M_GetRoom(int32_t x, int32_t y, int32_t z) +{ + int16_t room_num = Room_GetIndexFromPos(x, y, z); + if (room_num != NO_ROOM) { + return room_num; + } + return g_LaraItem->room_num; +} + +int32_t Lara_Hair_GetSegmentCount(void) +{ + return HAIR_SEGMENTS; +} + +HAIR_SEGMENT *Lara_Hair_GetSegment(int32_t n) +{ + return &m_Hair[n]; +} bool Lara_Hair_IsActive(void) { @@ -322,7 +341,7 @@ void Lara_Hair_Control(void) } } else { if (in_cutscene) { - room_num = Lara_Hair_GetRoom(pos.x, pos.y, pos.z); + room_num = M_GetRoom(pos.x, pos.y, pos.z); water_level = NO_HEIGHT; } else { room_num = g_LaraItem->room_num; @@ -450,22 +469,3 @@ void Lara_Hair_Draw(void) Matrix_Pop(); } } - -static int16_t Lara_Hair_GetRoom(int32_t x, int32_t y, int32_t z) -{ - int16_t room_num = Room_GetIndexFromPos(x, y, z); - if (room_num != NO_ROOM) { - return room_num; - } - return g_LaraItem->room_num; -} - -int32_t Lara_Hair_GetSegmentCount(void) -{ - return HAIR_SEGMENTS; -} - -HAIR_SEGMENT *Lara_Hair_GetSegment(int32_t n) -{ - return &m_Hair[n]; -} diff --git a/src/game/lara/lara_look.c b/src/game/lara/lara_look.c index 529814aff..e0aff8530 100644 --- a/src/game/lara/lara_look.c +++ b/src/game/lara/lara_look.c @@ -8,11 +8,11 @@ #include -static void Lara_LookLeftRightBase(int16_t max_head_rot, int16_t head_turn); -static void Lara_LookUpDownBase( +static void M_LeftRightBase(int16_t max_head_rot, int16_t head_turn); +static void M_UpDownBase( int16_t min_head_tilt, int16_t max_head_tilt, int16_t head_turn); -static void Lara_LookLeftRightBase(int16_t max_head_rot, int16_t head_turn) +static void M_LeftRightBase(int16_t max_head_rot, int16_t head_turn) { g_Camera.type = CAM_LOOK; if (g_Input.left) { @@ -31,7 +31,7 @@ static void Lara_LookLeftRightBase(int16_t max_head_rot, int16_t head_turn) } } -static void Lara_LookUpDownBase( +static void M_UpDownBase( int16_t min_head_tilt, int16_t max_head_tilt, int16_t head_turn) { if (g_Config.enabled_inverted_look) { @@ -59,23 +59,23 @@ static void Lara_LookUpDownBase( void Lara_LookLeftRight(void) { - Lara_LookLeftRightBase(MAX_HEAD_ROTATION, HEAD_TURN / 2); + M_LeftRightBase(MAX_HEAD_ROTATION, HEAD_TURN / 2); } void Lara_LookLeftRightSurf(void) { - Lara_LookLeftRightBase(MAX_HEAD_ROTATION_SURF, HEAD_TURN_SURF); + M_LeftRightBase(MAX_HEAD_ROTATION_SURF, HEAD_TURN_SURF); g_Lara.torso_rot.y = g_Lara.head_rot.y / 2; } void Lara_LookUpDown(void) { - Lara_LookUpDownBase(MIN_HEAD_TILT_LOOK, MAX_HEAD_TILT_LOOK, HEAD_TURN / 2); + M_UpDownBase(MIN_HEAD_TILT_LOOK, MAX_HEAD_TILT_LOOK, HEAD_TURN / 2); } void Lara_LookUpDownSurf(void) { - Lara_LookUpDownBase(MIN_HEAD_TILT_SURF, MAX_HEAD_TILT_SURF, HEAD_TURN_SURF); + M_UpDownBase(MIN_HEAD_TILT_SURF, MAX_HEAD_TILT_SURF, HEAD_TURN_SURF); g_Lara.torso_rot.x = 0; } diff --git a/src/game/lara/lara_state.c b/src/game/lara/lara_state.c index acd925f72..912e6b8b6 100644 --- a/src/game/lara/lara_state.c +++ b/src/game/lara/lara_state.c @@ -44,9 +44,9 @@ void (*g_LaraStateRoutines[])(ITEM_INFO *item, COLL_INFO *coll) = { static bool m_JumpPermitted = true; -static int16_t Lara_FloorFront(ITEM_INFO *item, PHD_ANGLE ang, int32_t dist); +static int16_t M_FloorFront(ITEM_INFO *item, PHD_ANGLE ang, int32_t dist); -static int16_t Lara_FloorFront(ITEM_INFO *item, PHD_ANGLE ang, int32_t dist) +static int16_t M_FloorFront(ITEM_INFO *item, PHD_ANGLE ang, int32_t dist) { int32_t x = item->pos.x + ((Math_Sin(ang) * dist) >> W2V_SHIFT); int32_t y = item->pos.y - LARA_HEIGHT; @@ -366,23 +366,22 @@ void Lara_State_Land(ITEM_INFO *item, COLL_INFO *coll) void Lara_State_Compress(ITEM_INFO *item, COLL_INFO *coll) { if (g_Input.forward - && Lara_FloorFront(item, item->rot.y, 256) >= -STEPUP_HEIGHT) { + && M_FloorFront(item, item->rot.y, 256) >= -STEPUP_HEIGHT) { item->goal_anim_state = LS_JUMP_FORWARD; g_Lara.move_angle = item->rot.y; } else if ( g_Input.left - && Lara_FloorFront(item, item->rot.y - PHD_90, 256) >= -STEPUP_HEIGHT) { + && M_FloorFront(item, item->rot.y - PHD_90, 256) >= -STEPUP_HEIGHT) { item->goal_anim_state = LS_JUMP_LEFT; g_Lara.move_angle = item->rot.y - PHD_90; } else if ( g_Input.right - && Lara_FloorFront(item, item->rot.y + PHD_90, 256) >= -STEPUP_HEIGHT) { + && M_FloorFront(item, item->rot.y + PHD_90, 256) >= -STEPUP_HEIGHT) { item->goal_anim_state = LS_JUMP_RIGHT; g_Lara.move_angle = item->rot.y + PHD_90; } else if ( g_Input.back - && Lara_FloorFront(item, item->rot.y - PHD_180, 256) - >= -STEPUP_HEIGHT) { + && M_FloorFront(item, item->rot.y - PHD_180, 256) >= -STEPUP_HEIGHT) { item->goal_anim_state = LS_JUMP_BACK; g_Lara.move_angle = item->rot.y - PHD_180; } diff --git a/src/game/level.c b/src/game/level.c index ac09bc4f8..9240f4496 100644 --- a/src/game/level.c +++ b/src/game/level.c @@ -38,45 +38,44 @@ static LEVEL_INFO m_LevelInfo = { 0 }; static INJECTION_INFO *m_InjectionInfo = NULL; -static void Level_LoadFromFile( +static void M_LoadFromFile( const char *filename, int32_t level_num, bool is_demo); -static void Level_LoadTexturePages(VFILE *file); -static void Level_LoadRooms(VFILE *file); -static void Level_LoadMeshBase(VFILE *file); -static void Level_LoadMeshes(VFILE *file); -static void Level_LoadAnims(VFILE *file); -static void Level_LoadAnimChanges(VFILE *file); -static void Level_LoadAnimRanges(VFILE *file); -static void Level_LoadAnimCommands(VFILE *file); -static void Level_LoadAnimBones(VFILE *file); -static void Level_LoadAnimFrames(VFILE *file); -static void Level_LoadObjects(VFILE *file); -static void Level_LoadStaticObjects(VFILE *file); -static void Level_LoadTextures(VFILE *file); -static void Level_LoadSprites(VFILE *file); -static void Level_LoadCameras(VFILE *file); -static void Level_LoadSoundEffects(VFILE *file); -static void Level_LoadBoxes(VFILE *file); -static void Level_LoadAnimatedTextures(VFILE *file); -static void Level_LoadItems(VFILE *file); -static void Level_LoadDepthQ(VFILE *file); -static void Level_LoadPalette(VFILE *file); -static void Level_LoadCinematic(VFILE *file); -static void Level_LoadDemo(VFILE *file); -static void Level_LoadSamples(VFILE *file); -static void Level_CompleteSetup(int32_t level_num); -static void Level_MarkWaterEdgeVertices(void); -static size_t Level_CalculateMaxVertices(void); - -static void Level_LoadFromFile( +static void M_LoadTexturePages(VFILE *file); +static void M_LoadRooms(VFILE *file); +static void M_LoadMeshBase(VFILE *file); +static void M_LoadMeshes(VFILE *file); +static void M_LoadAnims(VFILE *file); +static void M_LoadAnimChanges(VFILE *file); +static void M_LoadAnimRanges(VFILE *file); +static void M_LoadAnimCommands(VFILE *file); +static void M_LoadAnimBones(VFILE *file); +static void M_LoadAnimFrames(VFILE *file); +static void M_LoadObjects(VFILE *file); +static void M_LoadStaticObjects(VFILE *file); +static void M_LoadTextures(VFILE *file); +static void M_LoadSprites(VFILE *file); +static void M_LoadCameras(VFILE *file); +static void M_LoadSoundEffects(VFILE *file); +static void M_LoadBoxes(VFILE *file); +static void M_LoadAnimatedTextures(VFILE *file); +static void M_LoadItems(VFILE *file); +static void M_LoadDepthQ(VFILE *file); +static void M_LoadPalette(VFILE *file); +static void M_LoadCinematic(VFILE *file); +static void M_LoadDemo(VFILE *file); +static void M_LoadSamples(VFILE *file); +static void M_CompleteSetup(int32_t level_num); +static void M_MarkWaterEdgeVertices(void); +static size_t M_CalculateMaxVertices(void); + +static void M_LoadFromFile( const char *filename, int32_t level_num, bool is_demo) { GameBuf_Reset(); VFILE *file = VFile_CreateFromPath(filename); if (!file) { - Shell_ExitSystemFmt( - "Level_LoadFromFile(): Could not open %s", filename); + Shell_ExitSystemFmt("M_LoadFromFile(): Could not open %s", filename); } const int32_t version = VFile_ReadS32(file); @@ -86,49 +85,49 @@ static void Level_LoadFromFile( level_num, filename, version, 32); } - Level_LoadTexturePages(file); + M_LoadTexturePages(file); const int32_t file_level_num = VFile_ReadS32(file); LOG_INFO("file level num: %d", file_level_num); - Level_LoadRooms(file); - Level_LoadMeshBase(file); - Level_LoadMeshes(file); - Level_LoadAnims(file); - Level_LoadAnimChanges(file); - Level_LoadAnimRanges(file); - Level_LoadAnimCommands(file); - Level_LoadAnimBones(file); - Level_LoadAnimFrames(file); - Level_LoadObjects(file); - Level_LoadStaticObjects(file); - Level_LoadTextures(file); - Level_LoadSprites(file); + M_LoadRooms(file); + M_LoadMeshBase(file); + M_LoadMeshes(file); + M_LoadAnims(file); + M_LoadAnimChanges(file); + M_LoadAnimRanges(file); + M_LoadAnimCommands(file); + M_LoadAnimBones(file); + M_LoadAnimFrames(file); + M_LoadObjects(file); + M_LoadStaticObjects(file); + M_LoadTextures(file); + M_LoadSprites(file); if (is_demo) { - Level_LoadPalette(file); + M_LoadPalette(file); } - Level_LoadCameras(file); - Level_LoadSoundEffects(file); - Level_LoadBoxes(file); - Level_LoadAnimatedTextures(file); - Level_LoadItems(file); + M_LoadCameras(file); + M_LoadSoundEffects(file); + M_LoadBoxes(file); + M_LoadAnimatedTextures(file); + M_LoadItems(file); Stats_ObserveItemsLoad(); - Level_LoadDepthQ(file); + M_LoadDepthQ(file); if (!is_demo) { - Level_LoadPalette(file); + M_LoadPalette(file); } - Level_LoadCinematic(file); - Level_LoadDemo(file); - Level_LoadSamples(file); + M_LoadCinematic(file); + M_LoadDemo(file); + M_LoadSamples(file); VFile_Close(file); } -static void Level_LoadTexturePages(VFILE *file) +static void M_LoadTexturePages(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.texture_page_count = VFile_ReadS32(file); @@ -141,7 +140,7 @@ static void Level_LoadTexturePages(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadRooms(VFILE *file) +static void M_LoadRooms(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); g_RoomCount = VFile_ReadU16(file); @@ -272,7 +271,7 @@ static void Level_LoadRooms(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadMeshBase(VFILE *const file) +static void M_LoadMeshBase(VFILE *const file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.mesh_count = VFile_ReadS32(file); @@ -285,7 +284,7 @@ static void Level_LoadMeshBase(VFILE *const file) Benchmark_End(benchmark, NULL); } -static void Level_LoadMeshes(VFILE *const file) +static void M_LoadMeshes(VFILE *const file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.mesh_ptr_count = VFile_ReadS32(file); @@ -304,7 +303,7 @@ static void Level_LoadMeshes(VFILE *const file) Benchmark_End(benchmark, NULL); } -static void Level_LoadAnims(VFILE *file) +static void M_LoadAnims(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.anim_count = VFile_ReadS32(file); @@ -333,7 +332,7 @@ static void Level_LoadAnims(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadAnimChanges(VFILE *file) +static void M_LoadAnimChanges(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.anim_change_count = VFile_ReadS32(file); @@ -352,7 +351,7 @@ static void Level_LoadAnimChanges(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadAnimRanges(VFILE *file) +static void M_LoadAnimRanges(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.anim_range_count = VFile_ReadS32(file); @@ -372,7 +371,7 @@ static void Level_LoadAnimRanges(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadAnimCommands(VFILE *file) +static void M_LoadAnimCommands(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.anim_command_count = VFile_ReadS32(file); @@ -387,7 +386,7 @@ static void Level_LoadAnimCommands(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadAnimBones(VFILE *file) +static void M_LoadAnimBones(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.anim_bone_count = VFile_ReadS32(file); @@ -401,7 +400,7 @@ static void Level_LoadAnimBones(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadAnimFrames(VFILE *file) +static void M_LoadAnimFrames(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.anim_frame_data_count = VFile_ReadS32(file); @@ -479,7 +478,7 @@ static void Level_LoadAnimFrames(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadObjects(VFILE *file) +static void M_LoadObjects(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.object_count = VFile_ReadS32(file); @@ -509,7 +508,7 @@ static void Level_LoadObjects(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadStaticObjects(VFILE *file) +static void M_LoadStaticObjects(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.static_count = VFile_ReadS32(file); @@ -538,7 +537,7 @@ static void Level_LoadStaticObjects(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadTextures(VFILE *file) +static void M_LoadTextures(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.texture_count = VFile_ReadS32(file); @@ -559,7 +558,7 @@ static void Level_LoadTextures(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadSprites(VFILE *file) +static void M_LoadSprites(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.sprite_info_count = VFile_ReadS32(file); @@ -601,7 +600,7 @@ static void Level_LoadSprites(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadCameras(VFILE *file) +static void M_LoadCameras(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); g_NumberCameras = VFile_ReadS32(file); @@ -625,7 +624,7 @@ static void Level_LoadCameras(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadSoundEffects(VFILE *file) +static void M_LoadSoundEffects(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); g_NumberSoundEffects = VFile_ReadS32(file); @@ -649,7 +648,7 @@ static void Level_LoadSoundEffects(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadBoxes(VFILE *file) +static void M_LoadBoxes(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); g_NumberBoxes = VFile_ReadS32(file); @@ -686,7 +685,7 @@ static void Level_LoadBoxes(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadAnimatedTextures(VFILE *file) +static void M_LoadAnimatedTextures(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.anim_texture_range_count = VFile_ReadS32(file); @@ -730,7 +729,7 @@ cleanup: { } } -static void Level_LoadItems(VFILE *file) +static void M_LoadItems(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); m_LevelInfo.item_count = VFile_ReadS32(file); @@ -739,8 +738,7 @@ static void Level_LoadItems(VFILE *file) if (m_LevelInfo.item_count) { if (m_LevelInfo.item_count > MAX_ITEMS) { - Shell_ExitSystem( - "Level_LoadItems(): Too Many g_Items being Loaded!!"); + Shell_ExitSystem("M_LoadItems(): Too Many g_Items being Loaded!!"); } g_Items = GameBuf_Alloc(sizeof(ITEM_INFO) * MAX_ITEMS, GBUF_ITEMS); @@ -760,7 +758,7 @@ static void Level_LoadItems(VFILE *file) if (item->object_id < 0 || item->object_id >= O_NUMBER_OF) { Shell_ExitSystemFmt( - "Level_LoadItems(): Bad Object number (%d) on Item %d", + "M_LoadItems(): Bad Object number (%d) on Item %d", item->object_id, i); } } @@ -769,7 +767,7 @@ static void Level_LoadItems(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadDepthQ(VFILE *file) +static void M_LoadDepthQ(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); LOG_INFO(""); @@ -777,7 +775,7 @@ static void Level_LoadDepthQ(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadPalette(VFILE *file) +static void M_LoadPalette(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); LOG_INFO(""); @@ -800,7 +798,7 @@ static void Level_LoadPalette(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadCinematic(VFILE *file) +static void M_LoadCinematic(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); g_NumCineFrames = VFile_ReadS16(file); @@ -825,7 +823,7 @@ static void Level_LoadCinematic(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadDemo(VFILE *file) +static void M_LoadDemo(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); g_DemoData = @@ -839,7 +837,7 @@ static void Level_LoadDemo(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_LoadSamples(VFILE *file) +static void M_LoadSamples(VFILE *file) { BENCHMARK *const benchmark = Benchmark_Start(); VFile_Read(file, g_SampleLUT, sizeof(int16_t) * MAX_SAMPLES); @@ -890,7 +888,7 @@ static void Level_LoadSamples(VFILE *file) Benchmark_End(benchmark, NULL); } -static void Level_CompleteSetup(int32_t level_num) +static void M_CompleteSetup(int32_t level_num) { BENCHMARK *const benchmark = Benchmark_Start(); @@ -924,7 +922,7 @@ static void Level_CompleteSetup(int32_t level_num) Inject_AllInjections(&m_LevelInfo); - Level_MarkWaterEdgeVertices(); + M_MarkWaterEdgeVertices(); // Must be called post-injection to allow for floor data changes. Stats_ObserveRoomsLoad(); @@ -941,7 +939,7 @@ static void Level_CompleteSetup(int32_t level_num) // Configure enemies who carry and drop items Carrier_InitialiseLevel(level_num); - const size_t max_vertices = Level_CalculateMaxVertices(); + const size_t max_vertices = M_CalculateMaxVertices(); LOG_INFO("Maximum vertices: %d", max_vertices); Output_ReserveVertexBuffer(max_vertices); @@ -985,7 +983,7 @@ static void Level_CompleteSetup(int32_t level_num) Benchmark_End(benchmark, NULL); } -static void Level_MarkWaterEdgeVertices(void) +static void M_MarkWaterEdgeVertices(void) { if (!g_Config.fix_texture_issues) { return; @@ -1009,7 +1007,7 @@ static void Level_MarkWaterEdgeVertices(void) Benchmark_End(benchmark, NULL); } -static size_t Level_CalculateMaxVertices(void) +static size_t M_CalculateMaxVertices(void) { BENCHMARK *const benchmark = Benchmark_Start(); size_t max_vertices = 0; @@ -1064,9 +1062,8 @@ void Level_Load(int level_num) (g_GameFlow.levels[level_num].level_type == GFL_TITLE_DEMO_PC) | (g_GameFlow.levels[level_num].level_type == GFL_LEVEL_DEMO_PC); - Level_LoadFromFile( - g_GameFlow.levels[level_num].level_file, level_num, is_demo); - Level_CompleteSetup(level_num); + M_LoadFromFile(g_GameFlow.levels[level_num].level_file, level_num, is_demo); + M_CompleteSetup(level_num); Inject_Cleanup(); diff --git a/src/game/los.c b/src/game/los.c index 23dd96902..08ffc2d85 100644 --- a/src/game/los.c +++ b/src/game/los.c @@ -7,12 +7,12 @@ #include -static int32_t LOS_CheckX(const GAME_VECTOR *start, GAME_VECTOR *target); -static int32_t LOS_CheckZ(const GAME_VECTOR *start, GAME_VECTOR *target); -static bool LOS_ClipTarget( +static int32_t M_CheckX(const GAME_VECTOR *start, GAME_VECTOR *target); +static int32_t M_CheckZ(const GAME_VECTOR *start, GAME_VECTOR *target); +static bool M_ClipTarget( const GAME_VECTOR *start, GAME_VECTOR *target, const SECTOR_INFO *sector); -static int32_t LOS_CheckX( +static int32_t M_CheckX( const GAME_VECTOR *const start, GAME_VECTOR *const target) { const SECTOR_INFO *sector; @@ -98,7 +98,7 @@ static int32_t LOS_CheckX( return 1; } -static int32_t LOS_CheckZ( +static int32_t M_CheckZ( const GAME_VECTOR *const start, GAME_VECTOR *const target) { const SECTOR_INFO *sector; @@ -184,7 +184,7 @@ static int32_t LOS_CheckZ( return 1; } -static bool LOS_ClipTarget( +static bool M_ClipTarget( const GAME_VECTOR *const start, GAME_VECTOR *const target, const SECTOR_INFO *const sector) { @@ -219,11 +219,11 @@ bool LOS_Check(const GAME_VECTOR *const start, GAME_VECTOR *const target) int32_t los2; if (ABS(target->z - start->z) > ABS(target->x - start->x)) { - los1 = LOS_CheckX(start, target); - los2 = LOS_CheckZ(start, target); + los1 = M_CheckX(start, target); + los2 = M_CheckZ(start, target); } else { - los1 = LOS_CheckZ(start, target); - los2 = LOS_CheckX(start, target); + los1 = M_CheckZ(start, target); + los2 = M_CheckX(start, target); } if (!los2) { @@ -233,5 +233,5 @@ bool LOS_Check(const GAME_VECTOR *const start, GAME_VECTOR *const target) const SECTOR_INFO *const sector = Room_GetSector(target->x, target->y, target->z, &target->room_num); - return LOS_ClipTarget(start, target, sector) && los1 == 1 && los2 == 1; + return M_ClipTarget(start, target, sector) && los1 == 1 && los2 == 1; } diff --git a/src/game/music.c b/src/game/music.c index a2e15df85..c24810a58 100644 --- a/src/game/music.c +++ b/src/game/music.c @@ -21,13 +21,13 @@ static MUSIC_TRACK_ID m_TrackCurrent = MX_INACTIVE; static MUSIC_TRACK_ID m_TrackLastPlayed = MX_INACTIVE; static MUSIC_TRACK_ID m_TrackLooped = MX_INACTIVE; -static void Music_SyncVolume(const int32_t audio_stream_id); -static bool Music_IsBrokenTrack(MUSIC_TRACK_ID track); -static void Music_StopActiveStream(void); -static void Music_StreamFinished(int stream_id, void *user_data); -static char *Music_GetTrackFileName(MUSIC_TRACK_ID track); +static void M_SyncVolume(const int32_t audio_stream_id); +static bool M_IsBrokenTrack(MUSIC_TRACK_ID track); +static void M_StopActiveStream(void); +static void M_StreamFinished(int stream_id, void *user_data); +static char *M_GetTrackFileName(MUSIC_TRACK_ID track); -static void Music_SyncVolume(const int32_t audio_stream_id) +static void M_SyncVolume(const int32_t audio_stream_id) { if (audio_stream_id < 0) { return; @@ -36,18 +36,18 @@ static void Music_SyncVolume(const int32_t audio_stream_id) Audio_Stream_SetVolume(audio_stream_id, m_Muted ? 0 : multiplier); } -static bool Music_IsBrokenTrack(MUSIC_TRACK_ID track) +static bool M_IsBrokenTrack(MUSIC_TRACK_ID track) { return track == MX_UNUSED_0 || track == MX_UNUSED_1 || track == MX_UNUSED_2; } -static void Music_StopActiveStream(void) +static void M_StopActiveStream(void) { if (m_AudioStreamID < 0) { return; } - // We are only interested in calling Music_StreamFinished if a stream + // We are only interested in calling M_StreamFinished if a stream // finished by itself. In cases where we end the streams early by hand, // we clear the finish callback in order to avoid resuming the BGM playback // just after we stop it. @@ -55,14 +55,14 @@ static void Music_StopActiveStream(void) Audio_Stream_Close(m_AudioStreamID); } -static char *Music_GetTrackFileName(MUSIC_TRACK_ID track) +static char *M_GetTrackFileName(MUSIC_TRACK_ID track) { char file_path[64]; sprintf(file_path, "music/track%02d.flac", track); return File_GuessExtension(file_path, m_Extensions); } -static void Music_StreamFinished(int stream_id, void *user_data) +static void M_StreamFinished(int stream_id, void *user_data) { // When a stream finishes, play the remembered background BGM. @@ -88,7 +88,7 @@ void Music_Shutdown(void) bool Music_Play(MUSIC_TRACK_ID track) { if (track == m_TrackCurrent || track == m_TrackLastPlayed - || Music_IsBrokenTrack(track)) { + || M_IsBrokenTrack(track)) { return false; } @@ -102,9 +102,9 @@ bool Music_Play(MUSIC_TRACK_ID track) SFX_BALDY_SPEECH + track - MX_BALDY_SPEECH, NULL, SPM_ALWAYS); } - Music_StopActiveStream(); + M_StopActiveStream(); - char *file_path = Music_GetTrackFileName(track); + char *file_path = M_GetTrackFileName(track); m_AudioStreamID = Audio_Stream_CreateFromFile(file_path); Memory_FreePointer(&file_path); @@ -118,8 +118,8 @@ bool Music_Play(MUSIC_TRACK_ID track) m_TrackLastPlayed = track; } - Music_SyncVolume(m_AudioStreamID); - Audio_Stream_SetFinishCallback(m_AudioStreamID, Music_StreamFinished, NULL); + M_SyncVolume(m_AudioStreamID); + Audio_Stream_SetFinishCallback(m_AudioStreamID, M_StreamFinished, NULL); return true; } @@ -127,7 +127,7 @@ bool Music_Play(MUSIC_TRACK_ID track) bool Music_PlayLooped(MUSIC_TRACK_ID track) { if (track == m_TrackCurrent || track == m_TrackLastPlayed - || Music_IsBrokenTrack(track)) { + || M_IsBrokenTrack(track)) { return false; } @@ -136,9 +136,9 @@ bool Music_PlayLooped(MUSIC_TRACK_ID track) return false; } - Music_StopActiveStream(); + M_StopActiveStream(); - char *file_path = Music_GetTrackFileName(track); + char *file_path = M_GetTrackFileName(track); m_AudioStreamID = Audio_Stream_CreateFromFile(file_path); Memory_FreePointer(&file_path); @@ -147,8 +147,8 @@ bool Music_PlayLooped(MUSIC_TRACK_ID track) return false; } - Music_SyncVolume(m_AudioStreamID); - Audio_Stream_SetFinishCallback(m_AudioStreamID, Music_StreamFinished, NULL); + M_SyncVolume(m_AudioStreamID); + Audio_Stream_SetFinishCallback(m_AudioStreamID, M_StreamFinished, NULL); Audio_Stream_SetIsLooped(m_AudioStreamID, true); m_TrackLooped = track; @@ -161,16 +161,16 @@ void Music_Stop(void) m_TrackCurrent = MX_INACTIVE; m_TrackLastPlayed = MX_INACTIVE; m_TrackLooped = MX_INACTIVE; - Music_StopActiveStream(); + M_StopActiveStream(); } void Music_StopTrack(MUSIC_TRACK_ID track) { - if (track != m_TrackCurrent || Music_IsBrokenTrack(track)) { + if (track != m_TrackCurrent || M_IsBrokenTrack(track)) { return; } - Music_StopActiveStream(); + M_StopActiveStream(); m_TrackCurrent = MX_INACTIVE; if (m_TrackLooped >= 0) { @@ -181,13 +181,13 @@ void Music_StopTrack(MUSIC_TRACK_ID track) void Music_Mute(void) { m_Muted = true; - Music_SyncVolume(m_AudioStreamID); + M_SyncVolume(m_AudioStreamID); } void Music_Unmute(void) { m_Muted = false; - Music_SyncVolume(m_AudioStreamID); + M_SyncVolume(m_AudioStreamID); } int16_t Music_GetVolume(void) @@ -199,7 +199,7 @@ void Music_SetVolume(int16_t volume) { if (volume != m_Volume) { m_Volume = volume; - Music_SyncVolume(m_AudioStreamID); + M_SyncVolume(m_AudioStreamID); } } diff --git a/src/game/objects/creatures/ape.c b/src/game/objects/creatures/ape.c index 414672ef2..918390a67 100644 --- a/src/game/objects/creatures/ape.c +++ b/src/game/objects/creatures/ape.c @@ -48,9 +48,9 @@ typedef enum { static BITE_INFO m_ApeBite = { 0, -19, 75, 15 }; -static bool Ape_Vault(int16_t item_num, int16_t angle); +static bool M_Vault(int16_t item_num, int16_t angle); -static bool Ape_Vault(int16_t item_num, int16_t angle) +static bool M_Vault(int16_t item_num, int16_t angle) { ITEM_INFO *item = &g_Items[item_num]; CREATURE_INFO *ape = item->data; @@ -256,7 +256,7 @@ void Ape_Control(int16_t item_num) if (item->current_anim_state == APE_VAULT) { Creature_Animate(item_num, angle, 0); - } else if (Ape_Vault(item_num, angle)) { + } else if (M_Vault(item_num, angle)) { ape->maximum_turn = 0; item->current_anim_state = APE_VAULT; Item_SwitchToAnim(item, APE_VAULT_ANIM, 0); diff --git a/src/game/objects/creatures/bat.c b/src/game/objects/creatures/bat.c index fa2ed434a..111359de5 100644 --- a/src/game/objects/creatures/bat.c +++ b/src/game/objects/creatures/bat.c @@ -29,9 +29,9 @@ typedef enum { static BITE_INFO m_BatBite = { 0, 16, 45, 4 }; -static void Bat_FixEmbeddedPosition(int16_t item_num); +static void M_FixEmbeddedPosition(int16_t item_num); -static void Bat_FixEmbeddedPosition(int16_t item_num) +static void M_FixEmbeddedPosition(int16_t item_num) { ITEM_INFO *item = &g_Items[item_num]; if (item->status == IS_ACTIVE) { @@ -151,5 +151,5 @@ void Bat_Initialise(int16_t item_num) // Almost all of the bats in the OG levels are embedded in the ceiling. // This will move all bats up to the ceiling of their rooms and down // by the height of their hanging animation. - Bat_FixEmbeddedPosition(item_num); + M_FixEmbeddedPosition(item_num); } diff --git a/src/game/objects/creatures/lion.c b/src/game/objects/creatures/lion.c index ba4e96b1d..af804699d 100644 --- a/src/game/objects/creatures/lion.c +++ b/src/game/objects/creatures/lion.c @@ -45,7 +45,7 @@ typedef enum { static BITE_INFO m_LionBite = { -2, -10, 132, 21 }; -static void Lion_SetupCommon(OBJECT_INFO *const obj) +static void M_SetupBase(OBJECT_INFO *const obj) { obj->initialise = Creature_Initialise; obj->control = Lion_Control; @@ -65,7 +65,7 @@ void Lion_SetupLion(OBJECT_INFO *obj) if (!obj->loaded) { return; } - Lion_SetupCommon(obj); + M_SetupBase(obj); obj->hit_points = LION_HITPOINTS; obj->radius = LION_RADIUS; obj->smartness = LION_SMARTNESS; @@ -76,7 +76,7 @@ void Lion_SetupLioness(OBJECT_INFO *obj) if (!obj->loaded) { return; } - Lion_SetupCommon(obj); + M_SetupBase(obj); obj->hit_points = LIONESS_HITPOINTS; obj->radius = LIONESS_RADIUS; obj->smartness = LIONESS_SMARTNESS; @@ -87,7 +87,7 @@ void Lion_SetupPuma(OBJECT_INFO *obj) if (!obj->loaded) { return; } - Lion_SetupCommon(obj); + M_SetupBase(obj); obj->hit_points = PUMA_HITPOINTS; obj->radius = PUMA_RADIUS; obj->smartness = PUMA_SMARTNESS; diff --git a/src/game/objects/general/bridge_flat.c b/src/game/objects/general/bridge_flat.c index 46ff1717d..11fdd9f21 100644 --- a/src/game/objects/general/bridge_flat.c +++ b/src/game/objects/general/bridge_flat.c @@ -3,18 +3,18 @@ #include "config.h" #include "game/objects/general/bridge_common.h" -static void BridgeFlat_Initialise(int16_t item_num); -static int16_t BridgeFlat_GetFloorHeight( +static void M_Initialise(int16_t item_num); +static int16_t M_GetFloorHeight( const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height); -static int16_t BridgeFlat_GetCeilingHeight( +static int16_t M_GetCeilingHeight( const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height); -static void BridgeFlat_Initialise(const int16_t item_num) +static void M_Initialise(const int16_t item_num) { Bridge_FixEmbeddedPosition(item_num); } -static int16_t BridgeFlat_GetFloorHeight( +static int16_t M_GetFloorHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { @@ -33,7 +33,7 @@ static int16_t BridgeFlat_GetFloorHeight( return item->pos.y; } -static int16_t BridgeFlat_GetCeilingHeight( +static int16_t M_GetCeilingHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { @@ -54,7 +54,7 @@ static int16_t BridgeFlat_GetCeilingHeight( void BridgeFlat_Setup(OBJECT_INFO *const obj) { - obj->initialise = BridgeFlat_Initialise; - obj->floor_height_func = BridgeFlat_GetFloorHeight; - obj->ceiling_height_func = BridgeFlat_GetCeilingHeight; + obj->initialise = M_Initialise; + obj->floor_height_func = M_GetFloorHeight; + obj->ceiling_height_func = M_GetCeilingHeight; } diff --git a/src/game/objects/general/bridge_tilt1.c b/src/game/objects/general/bridge_tilt1.c index 6c11fa7cf..4f9778f92 100644 --- a/src/game/objects/general/bridge_tilt1.c +++ b/src/game/objects/general/bridge_tilt1.c @@ -3,18 +3,18 @@ #include "config.h" #include "game/objects/general/bridge_common.h" -static void BridgeTilt1_Initialise(int16_t item_num); -static int16_t BridgeTilt1_GetFloorHeight( +static void M_Initialise(int16_t item_num); +static int16_t M_GetFloorHeight( const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height); -static int16_t BridgeTilt1_GetCeilingHeight( +static int16_t M_GetCeilingHeight( const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height); -static void BridgeTilt1_Initialise(const int16_t item_num) +static void M_Initialise(const int16_t item_num) { Bridge_FixEmbeddedPosition(item_num); } -int16_t BridgeTilt1_GetFloorHeight( +int16_t M_GetFloorHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { @@ -35,7 +35,7 @@ int16_t BridgeTilt1_GetFloorHeight( return offset_height; } -int16_t BridgeTilt1_GetCeilingHeight( +int16_t M_GetCeilingHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { @@ -58,7 +58,7 @@ int16_t BridgeTilt1_GetCeilingHeight( void BridgeTilt1_Setup(OBJECT_INFO *obj) { - obj->initialise = BridgeTilt1_Initialise; - obj->floor_height_func = BridgeTilt1_GetFloorHeight; - obj->ceiling_height_func = BridgeTilt1_GetCeilingHeight; + obj->initialise = M_Initialise; + obj->floor_height_func = M_GetFloorHeight; + obj->ceiling_height_func = M_GetCeilingHeight; } diff --git a/src/game/objects/general/bridge_tilt2.c b/src/game/objects/general/bridge_tilt2.c index cb841e767..560df2ce9 100644 --- a/src/game/objects/general/bridge_tilt2.c +++ b/src/game/objects/general/bridge_tilt2.c @@ -2,18 +2,18 @@ #include "game/objects/general/bridge_common.h" #include "game/objects/general/bridge_tilt1.h" -static void BridgeTilt2_Initialise(int16_t item_num); -static int16_t BridgeTilt2_GetFloorHeight( +static void M_Initialise(int16_t item_num); +static int16_t M_GetFloorHeight( const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height); -static int16_t BridgeTilt2_GetCeilingHeight( +static int16_t M_GetCeilingHeight( const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height); -static void BridgeTilt2_Initialise(const int16_t item_num) +static void M_Initialise(const int16_t item_num) { Bridge_FixEmbeddedPosition(item_num); } -int16_t BridgeTilt2_GetFloorHeight( +int16_t M_GetFloorHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { @@ -34,7 +34,7 @@ int16_t BridgeTilt2_GetFloorHeight( return offset_height; } -int16_t BridgeTilt2_GetCeilingHeight( +int16_t M_GetCeilingHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { @@ -57,7 +57,7 @@ int16_t BridgeTilt2_GetCeilingHeight( void BridgeTilt2_Setup(OBJECT_INFO *obj) { - obj->initialise = BridgeTilt2_Initialise; - obj->floor_height_func = BridgeTilt2_GetFloorHeight; - obj->ceiling_height_func = BridgeTilt2_GetCeilingHeight; + obj->initialise = M_Initialise; + obj->floor_height_func = M_GetFloorHeight; + obj->ceiling_height_func = M_GetCeilingHeight; } diff --git a/src/game/objects/general/door.c b/src/game/objects/general/door.c index babe28e94..3267f3767 100644 --- a/src/game/objects/general/door.c +++ b/src/game/objects/general/door.c @@ -11,12 +11,12 @@ #include -static bool Door_LaraDoorCollision(const SECTOR_INFO *sector); -static void Door_Check(DOORPOS_DATA *d); -static void Door_Open(DOORPOS_DATA *d); -static void Door_Shut(DOORPOS_DATA *d); +static bool M_LaraDoorCollision(const SECTOR_INFO *sector); +static void M_Check(DOORPOS_DATA *d); +static void M_Open(DOORPOS_DATA *d); +static void M_Shut(DOORPOS_DATA *d); -static bool Door_LaraDoorCollision(const SECTOR_INFO *const sector) +static bool M_LaraDoorCollision(const SECTOR_INFO *const sector) { // Check if Lara is on the same tile as the invisible block. if (g_LaraItem == NULL) { @@ -29,18 +29,18 @@ static bool Door_LaraDoorCollision(const SECTOR_INFO *const sector) return lara_sector == sector; } -static void Door_Check(DOORPOS_DATA *const d) +static void M_Check(DOORPOS_DATA *const d) { // Forcefully remove the invisible block if Lara happens to occupy the same // tile. This ensures that Lara doesn't void if a timed door happens to // close right on her, or the player loads the game while standing on a // closed door's block tile. - if (Door_LaraDoorCollision(d->sector)) { - Door_Open(d); + if (M_LaraDoorCollision(d->sector)) { + M_Open(d); } } -static void Door_Shut(DOORPOS_DATA *const d) +static void M_Shut(DOORPOS_DATA *const d) { // Change the level geometry so that the door tile is impassable. SECTOR_INFO *const sector = d->sector; @@ -61,7 +61,7 @@ static void Door_Shut(DOORPOS_DATA *const d) } } -static void Door_Open(DOORPOS_DATA *const d) +static void M_Open(DOORPOS_DATA *const d) { // Restore the level geometry so that the door tile is passable. SECTOR_INFO *const sector = d->sector; @@ -155,8 +155,8 @@ void Door_Initialise(int16_t item_num) } room_num = door->d1.sector->portal_room.wall; - Door_Shut(&door->d1); - Door_Shut(&door->d1flip); + M_Shut(&door->d1); + M_Shut(&door->d1flip); if (room_num == NO_ROOM) { door->d2.sector = NULL; @@ -206,8 +206,8 @@ void Door_Initialise(int16_t item_num) door->d2flip.sector = NULL; } - Door_Shut(&door->d2); - Door_Shut(&door->d2flip); + M_Shut(&door->d2); + M_Shut(&door->d2flip); } void Door_Control(int16_t item_num) @@ -219,26 +219,26 @@ void Door_Control(int16_t item_num) if (item->current_anim_state == DOOR_CLOSED) { item->goal_anim_state = DOOR_OPEN; } else { - Door_Open(&door->d1); - Door_Open(&door->d2); - Door_Open(&door->d1flip); - Door_Open(&door->d2flip); + M_Open(&door->d1); + M_Open(&door->d2); + M_Open(&door->d1flip); + M_Open(&door->d2flip); } } else { if (item->current_anim_state == DOOR_OPEN) { item->goal_anim_state = DOOR_CLOSED; } else { - Door_Shut(&door->d1); - Door_Shut(&door->d2); - Door_Shut(&door->d1flip); - Door_Shut(&door->d2flip); + M_Shut(&door->d1); + M_Shut(&door->d2); + M_Shut(&door->d1flip); + M_Shut(&door->d2flip); } } - Door_Check(&door->d1); - Door_Check(&door->d2); - Door_Check(&door->d1flip); - Door_Check(&door->d2flip); + M_Check(&door->d1); + M_Check(&door->d2); + M_Check(&door->d1flip); + M_Check(&door->d2flip); Item_Animate(item); } diff --git a/src/game/objects/general/drawbridge.c b/src/game/objects/general/drawbridge.c index 631f22e42..7fd131d6f 100644 --- a/src/game/objects/general/drawbridge.c +++ b/src/game/objects/general/drawbridge.c @@ -10,16 +10,16 @@ typedef enum { DRAWBRIDGE_OPEN, } DRAWBRIDGE_STATE; -static bool Drawbridge_IsLaraOnTop(const ITEM_INFO *item, int32_t x, int32_t z); -static int16_t Drawbridge_GetFloorHeight( +static bool M_IsItemOnTop(const ITEM_INFO *item, int32_t x, int32_t z); +static int16_t M_GetFloorHeight( const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height); -static int16_t Drawbridge_GetCeilingHeight( +static int16_t M_GetCeilingHeight( const ITEM_INFO *item, int32_t x, int32_t y, int32_t z, int16_t height); -static void Drawbridge_Collision( +static void M_Collision( int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll); -static void Drawbridge_Control(int16_t item_num); +static void M_Control(int16_t item_num); -static bool Drawbridge_IsLaraOnTop(const ITEM_INFO *item, int32_t x, int32_t z) +static bool M_IsItemOnTop(const ITEM_INFO *item, int32_t x, int32_t z) { int32_t ix = item->pos.x >> WALL_SHIFT; int32_t iz = item->pos.z >> WALL_SHIFT; @@ -42,13 +42,13 @@ static bool Drawbridge_IsLaraOnTop(const ITEM_INFO *item, int32_t x, int32_t z) return false; } -static int16_t Drawbridge_GetFloorHeight( +static int16_t M_GetFloorHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { if (item->current_anim_state != DOOR_OPEN) { return height; - } else if (!Drawbridge_IsLaraOnTop(item, x, z)) { + } else if (!M_IsItemOnTop(item, x, z)) { return height; } else if (y > item->pos.y) { return height; @@ -58,13 +58,13 @@ static int16_t Drawbridge_GetFloorHeight( return item->pos.y; } -static int16_t Drawbridge_GetCeilingHeight( +static int16_t M_GetCeilingHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { if (item->current_anim_state != DOOR_OPEN) { return height; - } else if (!Drawbridge_IsLaraOnTop(item, x, z)) { + } else if (!M_IsItemOnTop(item, x, z)) { return height; } else if (y <= item->pos.y) { return height; @@ -74,8 +74,7 @@ static int16_t Drawbridge_GetCeilingHeight( return item->pos.y + STEP_L; } -static void Drawbridge_Collision( - int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll) +static void M_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll) { ITEM_INFO *item = &g_Items[item_num]; if (item->current_anim_state == DOOR_CLOSED) { @@ -83,7 +82,7 @@ static void Drawbridge_Collision( } } -static void Drawbridge_Control(int16_t item_num) +static void M_Control(int16_t item_num) { ITEM_INFO *item = &g_Items[item_num]; if (Item_IsTriggerActive(item)) { @@ -106,10 +105,10 @@ void Drawbridge_Setup(OBJECT_INFO *obj) if (!obj->loaded) { return; } - obj->ceiling_height_func = Drawbridge_GetCeilingHeight; - obj->collision = Drawbridge_Collision; - obj->control = Drawbridge_Control; + obj->ceiling_height_func = M_GetCeilingHeight; + obj->collision = M_Collision; + obj->control = M_Control; obj->save_anim = 1; obj->save_flags = 1; - obj->floor_height_func = Drawbridge_GetFloorHeight; + obj->floor_height_func = M_GetFloorHeight; } diff --git a/src/game/objects/general/keyhole.c b/src/game/objects/general/keyhole.c index da869a73b..e617f7b98 100644 --- a/src/game/objects/general/keyhole.c +++ b/src/game/objects/general/keyhole.c @@ -21,21 +21,12 @@ static const OBJECT_BOUNDS m_KeyHoleBounds = { }, }; -static const OBJECT_BOUNDS *KeyHole_Bounds(void); +static void M_Collision( + int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll); +; +static const OBJECT_BOUNDS *M_Bounds(void); -static const OBJECT_BOUNDS *KeyHole_Bounds(void) -{ - return &m_KeyHoleBounds; -} - -void KeyHole_Setup(OBJECT_INFO *obj) -{ - obj->collision = KeyHole_Collision; - obj->save_flags = 1; - obj->bounds = KeyHole_Bounds; -} - -void KeyHole_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll) +static void M_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll) { ITEM_INFO *item = &g_Items[item_num]; const OBJECT_INFO *const obj = &g_Objects[item->object_id]; @@ -68,6 +59,18 @@ void KeyHole_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll) Inv_Display(INV_KEYS_MODE); } +static const OBJECT_BOUNDS *M_Bounds(void) +{ + return &m_KeyHoleBounds; +} + +void KeyHole_Setup(OBJECT_INFO *obj) +{ + obj->collision = M_Collision; + obj->save_flags = 1; + obj->bounds = M_Bounds; +} + bool KeyHole_Trigger(int16_t item_num) { ITEM_INFO *item = &g_Items[item_num]; diff --git a/src/game/objects/general/keyhole.h b/src/game/objects/general/keyhole.h index dacaefa7d..42649381d 100644 --- a/src/game/objects/general/keyhole.h +++ b/src/game/objects/general/keyhole.h @@ -5,5 +5,4 @@ extern XYZ_32 g_KeyHolePosition; void KeyHole_Setup(OBJECT_INFO *obj); -void KeyHole_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll); bool KeyHole_Trigger(int16_t item_num); diff --git a/src/game/objects/general/pickup.c b/src/game/objects/general/pickup.c index 3e544a3d8..5164575ff 100644 --- a/src/game/objects/general/pickup.c +++ b/src/game/objects/general/pickup.c @@ -50,12 +50,10 @@ static const OBJECT_BOUNDS m_PickUpBoundsUW = { }, }; -static void PickUp_GetItem( - int16_t item_num, ITEM_INFO *item, ITEM_INFO *lara_item); -static void PickUp_GetAllAtLaraPos(ITEM_INFO *item, ITEM_INFO *lara_item); +static void M_GetItem(int16_t item_num, ITEM_INFO *item, ITEM_INFO *lara_item); +static void M_GetAllAtLaraPos(ITEM_INFO *item, ITEM_INFO *lara_item); -static void PickUp_GetItem( - int16_t item_num, ITEM_INFO *item, ITEM_INFO *lara_item) +static void M_GetItem(int16_t item_num, ITEM_INFO *item, ITEM_INFO *lara_item) { Overlay_AddPickup(item->object_id); Inv_AddItem(item->object_id); @@ -65,14 +63,14 @@ static void PickUp_GetItem( g_Lara.interact_target.is_moving = false; } -static void PickUp_GetAllAtLaraPos(ITEM_INFO *item, ITEM_INFO *lara_item) +static void M_GetAllAtLaraPos(ITEM_INFO *item, ITEM_INFO *lara_item) { int16_t pickup_num = g_RoomInfo[item->room_num].item_num; while (pickup_num != NO_ITEM) { ITEM_INFO *check_item = &g_Items[pickup_num]; if (check_item->pos.x == item->pos.x && check_item->pos.z == item->pos.z && g_Objects[check_item->object_id].collision == Pickup_Collision) { - PickUp_GetItem(pickup_num, check_item, lara_item); + M_GetItem(pickup_num, check_item, lara_item); } pickup_num = check_item->next_item; } @@ -122,7 +120,7 @@ void Pickup_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll) if (!Item_TestFrameEqual(lara_item, LF_PICKUP_ERASE)) { goto cleanup; } - PickUp_GetAllAtLaraPos(item, lara_item); + M_GetAllAtLaraPos(item, lara_item); goto cleanup; } @@ -145,7 +143,7 @@ void Pickup_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll) if (!Item_TestFrameEqual(lara_item, LF_PICKUP_UW)) { goto cleanup; } - PickUp_GetAllAtLaraPos(item, lara_item); + M_GetAllAtLaraPos(item, lara_item); goto cleanup; } @@ -218,7 +216,7 @@ void Pickup_CollisionControlled( g_Lara.interact_target.item_num == item_num && lara_item->current_anim_state == LS_PICKUP) { if (Item_TestFrameEqual(lara_item, LF_PICKUP_ERASE)) { - PickUp_GetAllAtLaraPos(item, lara_item); + M_GetAllAtLaraPos(item, lara_item); } } } else if (g_Lara.water_status == LWS_UNDERWATER) { @@ -251,7 +249,7 @@ void Pickup_CollisionControlled( g_Lara.interact_target.item_num == item_num && lara_item->current_anim_state == LS_PICKUP && Item_TestFrameEqual(lara_item, LF_PICKUP_UW)) { - PickUp_GetAllAtLaraPos(item, lara_item); + M_GetAllAtLaraPos(item, lara_item); g_Lara.gun_status = LGS_ARMLESS; } } diff --git a/src/game/objects/general/puzzle_hole.c b/src/game/objects/general/puzzle_hole.c index 77e838d92..3aa99155a 100644 --- a/src/game/objects/general/puzzle_hole.c +++ b/src/game/objects/general/puzzle_hole.c @@ -33,9 +33,9 @@ static const OBJECT_BOUNDS m_PuzzleHoleBounds = { }, }; -static const OBJECT_BOUNDS *PuzzleHole_Bounds(void); +static const OBJECT_BOUNDS *M_Bounds(void); -static const OBJECT_BOUNDS *PuzzleHole_Bounds(void) +static const OBJECT_BOUNDS *M_Bounds(void) { return &m_PuzzleHoleBounds; } @@ -44,7 +44,7 @@ void PuzzleHole_Setup(OBJECT_INFO *obj) { obj->collision = PuzzleHole_Collision; obj->save_flags = 1; - obj->bounds = PuzzleHole_Bounds; + obj->bounds = M_Bounds; } void PuzzleHole_SetupDone(OBJECT_INFO *obj) diff --git a/src/game/objects/general/save_crystal.c b/src/game/objects/general/save_crystal.c index 7335077dd..e5b824abc 100644 --- a/src/game/objects/general/save_crystal.c +++ b/src/game/objects/general/save_crystal.c @@ -20,9 +20,9 @@ static const OBJECT_BOUNDS m_SaveCrystal_Bounds = { }, }; -static const OBJECT_BOUNDS *SaveCrystal_Bounds(void); +static const OBJECT_BOUNDS *M_Bounds(void); -static const OBJECT_BOUNDS *SaveCrystal_Bounds(void) +static const OBJECT_BOUNDS *M_Bounds(void) { return &m_SaveCrystal_Bounds; } @@ -35,7 +35,7 @@ void SaveCrystal_Setup(OBJECT_INFO *obj) obj->collision = SaveCrystal_Collision; obj->save_flags = 1; } - obj->bounds = SaveCrystal_Bounds; + obj->bounds = M_Bounds; Object_SetReflective(O_SAVEGAME_ITEM, true); } diff --git a/src/game/objects/general/scion1.c b/src/game/objects/general/scion1.c index a57faa492..02ef77eaf 100644 --- a/src/game/objects/general/scion1.c +++ b/src/game/objects/general/scion1.c @@ -24,9 +24,9 @@ static const OBJECT_BOUNDS m_Scion1_Bounds = { }, }; -static const OBJECT_BOUNDS *Scion1_Bounds(void); +static const OBJECT_BOUNDS *M_Bounds(void); -static const OBJECT_BOUNDS *Scion1_Bounds(void) +static const OBJECT_BOUNDS *M_Bounds(void) { return &m_Scion1_Bounds; } @@ -36,7 +36,7 @@ void Scion1_Setup(OBJECT_INFO *obj) obj->draw_routine = Object_DrawPickupItem; obj->collision = Scion1_Collision; obj->save_flags = 1; - obj->bounds = Scion1_Bounds; + obj->bounds = M_Bounds; } void Scion1_Collision(int16_t item_num, ITEM_INFO *lara_item, COLL_INFO *coll) diff --git a/src/game/objects/general/scion4.c b/src/game/objects/general/scion4.c index eb8a8487b..7b4673e2e 100644 --- a/src/game/objects/general/scion4.c +++ b/src/game/objects/general/scion4.c @@ -20,9 +20,9 @@ static const OBJECT_BOUNDS m_Scion4_Bounds = { }, }; -static const OBJECT_BOUNDS *Scion4_Bounds(void); +static const OBJECT_BOUNDS *M_Bounds(void); -static const OBJECT_BOUNDS *Scion4_Bounds(void) +static const OBJECT_BOUNDS *M_Bounds(void) { return &m_Scion4_Bounds; } @@ -32,7 +32,7 @@ void Scion4_Setup(OBJECT_INFO *obj) obj->control = Scion4_Control; obj->collision = Scion4_Collision; obj->save_flags = 1; - obj->bounds = Scion4_Bounds; + obj->bounds = M_Bounds; } void Scion4_Control(int16_t item_num) diff --git a/src/game/objects/general/switch.c b/src/game/objects/general/switch.c index a68af9d6d..5785abefb 100644 --- a/src/game/objects/general/switch.c +++ b/src/game/objects/general/switch.c @@ -41,10 +41,10 @@ static const OBJECT_BOUNDS m_Switch_BoundsUW = { }, }; -static const OBJECT_BOUNDS *Switch_Bounds(void); -static const OBJECT_BOUNDS *Switch_BoundsUW(void); +static const OBJECT_BOUNDS *M_Bounds(void); +static const OBJECT_BOUNDS *M_BoundsUW(void); -static const OBJECT_BOUNDS *Switch_Bounds(void) +static const OBJECT_BOUNDS *M_Bounds(void) { if (g_Config.walk_to_items) { return &m_Switch_BoundsControlled; @@ -52,7 +52,7 @@ static const OBJECT_BOUNDS *Switch_Bounds(void) return &m_Switch_Bounds; } -static const OBJECT_BOUNDS *Switch_BoundsUW(void) +static const OBJECT_BOUNDS *M_BoundsUW(void) { return &m_Switch_BoundsUW; } @@ -63,7 +63,7 @@ void Switch_Setup(OBJECT_INFO *obj) obj->collision = Switch_Collision; obj->save_anim = 1; obj->save_flags = 1; - obj->bounds = Switch_Bounds; + obj->bounds = M_Bounds; } void Switch_SetupUW(OBJECT_INFO *obj) @@ -72,7 +72,7 @@ void Switch_SetupUW(OBJECT_INFO *obj) obj->collision = Switch_CollisionUW; obj->save_anim = 1; obj->save_flags = 1; - obj->bounds = Switch_BoundsUW; + obj->bounds = M_BoundsUW; } void Switch_Control(int16_t item_num) diff --git a/src/game/objects/general/trapdoor.c b/src/game/objects/general/trapdoor.c index 19d37a57e..11f8b0a90 100644 --- a/src/game/objects/general/trapdoor.c +++ b/src/game/objects/general/trapdoor.c @@ -3,9 +3,9 @@ #include "game/items.h" #include "global/const.h" -static bool TrapDoor_StandingOn(const ITEM_INFO *item, int32_t x, int32_t z); +static bool M_IsItemOnTop(const ITEM_INFO *item, int32_t x, int32_t z); -static bool TrapDoor_StandingOn(const ITEM_INFO *item, int32_t x, int32_t z) +static bool M_IsItemOnTop(const ITEM_INFO *item, int32_t x, int32_t z) { int32_t tx = item->pos.x >> WALL_SHIFT; int32_t tz = item->pos.z >> WALL_SHIFT; @@ -50,7 +50,7 @@ int16_t TrapDoor_GetFloorHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { - if (!TrapDoor_StandingOn(item, x, z)) { + if (!M_IsItemOnTop(item, x, z)) { return height; } @@ -66,7 +66,7 @@ int16_t TrapDoor_GetCeilingHeight( const ITEM_INFO *item, const int32_t x, const int32_t y, const int32_t z, const int16_t height) { - if (!TrapDoor_StandingOn(item, x, z)) { + if (!M_IsItemOnTop(item, x, z)) { return height; } diff --git a/src/game/objects/setup.c b/src/game/objects/setup.c index d29707889..e157142a4 100644 --- a/src/game/objects/setup.c +++ b/src/game/objects/setup.c @@ -85,11 +85,11 @@ #include "global/types.h" #include "global/vars.h" -static void Object_SetupCreatures(void); -static void Object_SetupTraps(void); -static void Object_SetupMiscObjects(void); +static void M_SetupCreatures(void); +static void M_SetupTraps(void); +static void M_SetupMiscObjects(void); -static void Object_SetupCreatures(void) +static void M_SetupCreatures(void) { g_Objects[O_LARA].initialise = Lara_InitialiseLoad; g_Objects[O_LARA].draw_routine = Object_DrawDummyItem; @@ -133,7 +133,7 @@ static void Object_SetupCreatures(void) Statue_Setup(&g_Objects[O_STATUE]); } -static void Object_SetupTraps(void) +static void M_SetupTraps(void) { FallingBlock_Setup(&g_Objects[O_FALLING_BLOCK]); Pendulum_Setup(&g_Objects[O_PENDULUM]); @@ -162,7 +162,7 @@ static void Object_SetupTraps(void) LavaWedge_Setup(&g_Objects[O_LAVA_WEDGE]); } -static void Object_SetupMiscObjects(void) +static void M_SetupMiscObjects(void) { CameraTarget_Setup(&g_Objects[O_CAMERA_TARGET]); BridgeFlat_Setup(&g_Objects[O_BRIDGE_FLAT]); @@ -274,9 +274,9 @@ void Object_SetupAllObjects(void) obj->hit_points = DONT_TARGET; } - Object_SetupCreatures(); - Object_SetupTraps(); - Object_SetupMiscObjects(); + M_SetupCreatures(); + M_SetupTraps(); + M_SetupMiscObjects(); Lara_Hair_Initialise(); diff --git a/src/game/objects/traps/midas_touch.c b/src/game/objects/traps/midas_touch.c index b6e43c278..003d36566 100644 --- a/src/game/objects/traps/midas_touch.c +++ b/src/game/objects/traps/midas_touch.c @@ -26,7 +26,7 @@ static const OBJECT_BOUNDS m_MidasTouch_Bounds = { }, }; -static const OBJECT_BOUNDS *MidasTouch_Bounds(void) +static const OBJECT_BOUNDS *M_Bounds(void) { return &m_MidasTouch_Bounds; } @@ -35,7 +35,7 @@ void MidasTouch_Setup(OBJECT_INFO *obj) { obj->collision = MidasTouch_Collision; obj->draw_routine = Object_DrawDummyItem; - obj->bounds = MidasTouch_Bounds; + obj->bounds = M_Bounds; } void MidasTouch_Collision( diff --git a/src/game/objects/traps/movable_block.c b/src/game/objects/traps/movable_block.c index 506d1b127..ed25860fa 100644 --- a/src/game/objects/traps/movable_block.c +++ b/src/game/objects/traps/movable_block.c @@ -32,20 +32,20 @@ static const OBJECT_BOUNDS m_MovableBlock_Bounds = { }, }; -static const OBJECT_BOUNDS *MovableBlock_Bounds(void); -static bool MovableBlock_TestDoor(ITEM_INFO *lara_item, COLL_INFO *coll); -static bool MovableBlock_TestDestination(ITEM_INFO *item, int32_t block_height); -static bool MovableBlock_TestPush( +static const OBJECT_BOUNDS *M_Bounds(void); +static bool M_TestDoor(ITEM_INFO *lara_item, COLL_INFO *coll); +static bool M_TestDestination(ITEM_INFO *item, int32_t block_height); +static bool M_TestPush( ITEM_INFO *item, int32_t block_height, DIRECTION quadrant); -static bool MovableBlock_TestPull( +static bool M_TestPull( ITEM_INFO *item, int32_t block_height, DIRECTION quadrant); -static const OBJECT_BOUNDS *MovableBlock_Bounds(void) +static const OBJECT_BOUNDS *M_Bounds(void) { return &m_MovableBlock_Bounds; } -static bool MovableBlock_TestDoor(ITEM_INFO *lara_item, COLL_INFO *coll) +static bool M_TestDoor(ITEM_INFO *lara_item, COLL_INFO *coll) { // OG fix: stop pushing blocks through doors @@ -73,7 +73,7 @@ static bool MovableBlock_TestDoor(ITEM_INFO *lara_item, COLL_INFO *coll) return false; } -static bool MovableBlock_TestDestination(ITEM_INFO *item, int32_t block_height) +static bool M_TestDestination(ITEM_INFO *item, int32_t block_height) { int16_t room_num = item->room_num; const SECTOR_INFO *const sector = @@ -91,10 +91,10 @@ static bool MovableBlock_TestDestination(ITEM_INFO *item, int32_t block_height) return true; } -static bool MovableBlock_TestPush( +static bool M_TestPush( ITEM_INFO *item, int32_t block_height, DIRECTION quadrant) { - if (!MovableBlock_TestDestination(item, block_height)) { + if (!M_TestDestination(item, block_height)) { return false; } @@ -138,10 +138,10 @@ static bool MovableBlock_TestPush( return true; } -static bool MovableBlock_TestPull( +static bool M_TestPull( ITEM_INFO *item, int32_t block_height, DIRECTION quadrant) { - if (!MovableBlock_TestDestination(item, block_height)) { + if (!M_TestDestination(item, block_height)) { return false; } @@ -221,7 +221,7 @@ void MovableBlock_Setup(OBJECT_INFO *obj) obj->save_position = 1; obj->save_anim = 1; obj->save_flags = 1; - obj->bounds = MovableBlock_Bounds; + obj->bounds = M_Bounds; } void MovableBlock_Initialise(int16_t item_num) @@ -320,7 +320,7 @@ void MovableBlock_Collision( } // OG fix: stop pushing blocks through doors - if (MovableBlock_TestDoor(lara_item, coll)) { + if (M_TestDoor(lara_item, coll)) { return; } @@ -361,13 +361,13 @@ void MovableBlock_Collision( } if (g_Input.forward) { - if (!MovableBlock_TestPush(item, WALL_L, quadrant)) { + if (!M_TestPush(item, WALL_L, quadrant)) { return; } item->goal_anim_state = MBS_PUSH; lara_item->goal_anim_state = LS_PUSH_BLOCK; } else if (g_Input.back) { - if (!MovableBlock_TestPull(item, WALL_L, quadrant)) { + if (!M_TestPull(item, WALL_L, quadrant)) { return; } item->goal_anim_state = MBS_PULL; diff --git a/src/game/objects/traps/teeth_trap.c b/src/game/objects/traps/teeth_trap.c index 35d31647b..a5aaed043 100644 --- a/src/game/objects/traps/teeth_trap.c +++ b/src/game/objects/traps/teeth_trap.c @@ -20,9 +20,9 @@ static BITE_INFO m_Teeth2B = { 71, 10, -1718, 1 }; static BITE_INFO m_Teeth3A = { -23, -10, -1718, 0 }; static BITE_INFO m_Teeth3B = { 71, -10, -1718, 1 }; -static void TeethTrap_BiteEffect(ITEM_INFO *item, BITE_INFO *bite); +static void M_BiteEffect(ITEM_INFO *item, BITE_INFO *bite); -static void TeethTrap_BiteEffect(ITEM_INFO *item, BITE_INFO *bite) +static void M_BiteEffect(ITEM_INFO *item, BITE_INFO *bite) { XYZ_32 pos = { .x = bite->x, @@ -48,12 +48,12 @@ void TeethTrap_Control(int16_t item_num) item->goal_anim_state = TT_NASTY; if (item->touch_bits && item->current_anim_state == TT_NASTY) { Lara_TakeDamage(TEETH_TRAP_DAMAGE, true); - TeethTrap_BiteEffect(item, &m_Teeth1A); - TeethTrap_BiteEffect(item, &m_Teeth1B); - TeethTrap_BiteEffect(item, &m_Teeth2A); - TeethTrap_BiteEffect(item, &m_Teeth2B); - TeethTrap_BiteEffect(item, &m_Teeth3A); - TeethTrap_BiteEffect(item, &m_Teeth3B); + M_BiteEffect(item, &m_Teeth1A); + M_BiteEffect(item, &m_Teeth1B); + M_BiteEffect(item, &m_Teeth2A); + M_BiteEffect(item, &m_Teeth2B); + M_BiteEffect(item, &m_Teeth3A); + M_BiteEffect(item, &m_Teeth3B); } } else { item->goal_anim_state = TT_NICE; diff --git a/src/game/option/option_compass.c b/src/game/option/option_compass.c index 311c0b04f..b32cda726 100644 --- a/src/game/option/option_compass.c +++ b/src/game/option/option_compass.c @@ -28,9 +28,10 @@ static TEXTSTRING *m_Text[TEXT_NUMBER_OF] = { 0 }; static int16_t m_CompassNeedle = 0; static int16_t m_CompassSpeed = 0; -static void Option_Compass_InitText(void); +static void M_InitText(void); +static void M_ShutdownText(void); -static void Option_Compass_InitText(void) +static void M_InitText(void) { char buf[100]; const int top_y = -60; @@ -106,7 +107,7 @@ static void Option_Compass_InitText(void) } } -static void Option_Compass_ShutdownText(void) +static void M_ShutdownText(void) { for (int i = 0; i < TEXT_NUMBER_OF; i++) { Text_Remove(m_Text[i]); @@ -121,7 +122,7 @@ void Option_Compass(INVENTORY_ITEM *inv_item) char time_buf[100]; if (!m_Text[0]) { - Option_Compass_InitText(); + M_InitText(); } int32_t seconds = @@ -141,7 +142,7 @@ void Option_Compass(INVENTORY_ITEM *inv_item) } if (g_InputDB.menu_confirm || g_InputDB.menu_back) { - Option_Compass_ShutdownText(); + M_ShutdownText(); inv_item->goal_frame = inv_item->frames_total - 1; inv_item->anim_direction = 1; } @@ -149,7 +150,7 @@ void Option_Compass(INVENTORY_ITEM *inv_item) void Option_Compass_Shutdown(void) { - Option_Compass_ShutdownText(); + M_ShutdownText(); } void Option_Compass_UpdateNeedle(const INVENTORY_ITEM *const inv_item) diff --git a/src/game/option/option_control.c b/src/game/option/option_control.c index 7346d1b27..c8bfa1baf 100644 --- a/src/game/option/option_control.c +++ b/src/game/option/option_control.c @@ -188,21 +188,17 @@ static const TEXT_COLUMN_PLACEMENT CtrlTextPlacementCheats[] = { { COL_END, NULL, false }, }; -static void Option_Control_InitMenu(void); -static void Option_Control_InitText(CONTROL_MODE mode, INPUT_LAYOUT layout_num); -static void Option_Control_UpdateText( - CONTROL_MODE mode, INPUT_LAYOUT layout_num); -static void Option_Control_ShutdownText(void); -static void Option_Control_FlashConflicts( - CONTROL_MODE mode, INPUT_LAYOUT layout_num); -static INPUT_LAYOUT Option_Control_ChangeLayout(CONTROL_MODE mode); -static void Option_Control_CheckResetKeys( - CONTROL_MODE mode, INPUT_LAYOUT layout_num); -static void Option_Control_CheckUnbindKey( - CONTROL_MODE mode, INPUT_LAYOUT layout_num); -static void Option_Control_ProgressBar(TEXTSTRING *txt, int32_t timer); - -static void Option_Control_InitMenu(void) +static void M_InitMenu(void); +static void M_InitText(CONTROL_MODE mode, INPUT_LAYOUT layout_num); +static void M_UpdateText(CONTROL_MODE mode, INPUT_LAYOUT layout_num); +static void M_ShutdownText(void); +static void M_FlashConflicts(CONTROL_MODE mode, INPUT_LAYOUT layout_num); +static INPUT_LAYOUT M_ChangeLayout(CONTROL_MODE mode); +static void M_CheckResetKeys(CONTROL_MODE mode, INPUT_LAYOUT layout_num); +static void M_CheckUnbindKey(CONTROL_MODE mode, INPUT_LAYOUT layout_num); +static void M_ProgressBar(TEXTSTRING *txt, int32_t timer); + +static void M_InitMenu(void) { int32_t visible_lines = 0; if (Screen_GetResHeightDownscaled(RSR_TEXT) <= 240) { @@ -233,9 +229,9 @@ static void Option_Control_InitMenu(void) MIN(m_ControlMenu.num_options, m_ControlMenu.vis_options); } -static void Option_Control_InitText(CONTROL_MODE mode, INPUT_LAYOUT layout_num) +static void M_InitText(CONTROL_MODE mode, INPUT_LAYOUT layout_num) { - Option_Control_InitMenu(); + M_InitMenu(); m_Text[TEXT_TITLE_BORDER] = Text_Create(0, TOP_Y - BORDER, " "); Text_CentreH(m_Text[TEXT_TITLE_BORDER], true); @@ -341,12 +337,11 @@ static void Option_Control_InitText(CONTROL_MODE mode, INPUT_LAYOUT layout_num) Text_Hide(m_Text[TEXT_UNBIND], true); } - Option_Control_UpdateText(mode, layout_num); - Option_Control_FlashConflicts(mode, layout_num); + M_UpdateText(mode, layout_num); + M_FlashConflicts(mode, layout_num); } -static void Option_Control_UpdateText( - CONTROL_MODE mode, INPUT_LAYOUT layout_num) +static void M_UpdateText(CONTROL_MODE mode, INPUT_LAYOUT layout_num) { if (layout_num == INPUT_LAYOUT_DEFAULT) { Text_Hide(m_Text[TEXT_RESET], true); @@ -466,7 +461,7 @@ static void Option_Control_UpdateText( } } -static void Option_Control_ShutdownText(void) +static void M_ShutdownText(void) { for (int i = 0; i < TEXT_NUMBER_OF; i++) { Text_Remove(m_Text[i]); @@ -496,8 +491,7 @@ static void Option_Control_ShutdownText(void) m_UnbindKeyDelay = 0; } -static void Option_Control_FlashConflicts( - CONTROL_MODE mode, INPUT_LAYOUT layout_num) +static void M_FlashConflicts(CONTROL_MODE mode, INPUT_LAYOUT layout_num) { const TEXT_COLUMN_PLACEMENT *cols = g_Config.enable_cheats ? CtrlTextPlacementCheats @@ -514,7 +508,7 @@ static void Option_Control_FlashConflicts( } } -static INPUT_LAYOUT Option_Control_ChangeLayout(CONTROL_MODE mode) +static INPUT_LAYOUT M_ChangeLayout(CONTROL_MODE mode) { INPUT_LAYOUT layout_num = INPUT_LAYOUT_DEFAULT; if (mode == CM_KEYBOARD) { @@ -534,13 +528,13 @@ static INPUT_LAYOUT Option_Control_ChangeLayout(CONTROL_MODE mode) } Input_CheckConflicts(mode, layout_num); - Option_Control_UpdateText(mode, layout_num); - Option_Control_FlashConflicts(mode, layout_num); + M_UpdateText(mode, layout_num); + M_FlashConflicts(mode, layout_num); Config_Write(); return layout_num; } -static void Option_Control_ProgressBar(TEXTSTRING *txt, int32_t timer) +static void M_ProgressBar(TEXTSTRING *txt, int32_t timer) { int32_t width = Text_GetWidth(txt); int32_t height = TEXT_HEIGHT; @@ -566,8 +560,7 @@ static void Option_Control_ProgressBar(TEXTSTRING *txt, int32_t timer) txt, width, height, x, y, percent, g_Config.ui.menu_style); } -static void Option_Control_CheckResetKeys( - CONTROL_MODE mode, INPUT_LAYOUT layout_num) +static void M_CheckResetKeys(CONTROL_MODE mode, INPUT_LAYOUT layout_num) { const int32_t frame = Clock_GetLogicalFrame(); @@ -584,8 +577,8 @@ static void Option_Control_CheckResetKeys( Sound_Effect(SFX_MENU_GAMEBOY, NULL, SPM_NORMAL); Input_ResetLayout(mode, layout_num); Input_CheckConflicts(mode, layout_num); - Option_Control_UpdateText(mode, layout_num); - Option_Control_FlashConflicts(mode, layout_num); + M_UpdateText(mode, layout_num); + M_FlashConflicts(mode, layout_num); Config_Write(); m_ResetKeyMode = KM_CHANGEKEYUP; m_ResetTimer = 0; @@ -604,11 +597,10 @@ static void Option_Control_CheckResetKeys( int32_t progress = m_ResetTimer > 0 ? frame - m_ResetTimer : 0; CLAMP(progress, 0, LOGIC_FPS * BUTTON_HOLD_TIME); - Option_Control_ProgressBar(m_Text[TEXT_RESET], progress); + M_ProgressBar(m_Text[TEXT_RESET], progress); } -static void Option_Control_CheckUnbindKey( - CONTROL_MODE mode, INPUT_LAYOUT layout_num) +static void M_CheckUnbindKey(CONTROL_MODE mode, INPUT_LAYOUT layout_num) { const int32_t frame = Clock_GetLogicalFrame(); @@ -631,8 +623,8 @@ static void Option_Control_CheckUnbindKey( layout_num, m_ControlMenu.cur_role, UNBIND_ENUM); } Input_CheckConflicts(mode, layout_num); - Option_Control_UpdateText(mode, layout_num); - Option_Control_FlashConflicts(mode, layout_num); + M_UpdateText(mode, layout_num); + M_FlashConflicts(mode, layout_num); Config_Write(); m_UnbindKeyMode = KM_CHANGEKEYUP; m_UnbindTimer = 0; @@ -651,7 +643,7 @@ static void Option_Control_CheckUnbindKey( int32_t progress = m_UnbindTimer > 0 ? frame - m_UnbindTimer : 0; CLAMP(progress, 0, LOGIC_FPS * BUTTON_HOLD_TIME); - Option_Control_ProgressBar(m_Text[TEXT_UNBIND], progress); + M_ProgressBar(m_Text[TEXT_UNBIND], progress); } CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode) @@ -665,7 +657,7 @@ CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode) if (!m_Text[TEXT_TITLE]) { m_KeyMode = KM_BROWSE; - Option_Control_InitText(mode, layout_num); + M_InitText(mode, layout_num); } const TEXT_COLUMN_PLACEMENT *cols = g_Config.enable_cheats @@ -676,12 +668,12 @@ CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode) case KM_BROWSE: if (layout_num > INPUT_LAYOUT_DEFAULT) { if (m_UnbindKeyMode == KM_INACTIVE) { - Option_Control_CheckResetKeys(mode, layout_num); + M_CheckResetKeys(mode, layout_num); } if (m_ResetKeyMode == KM_INACTIVE && m_ControlMenu.cur_row->can_unbind) { - Option_Control_CheckUnbindKey(mode, layout_num); + M_CheckUnbindKey(mode, layout_num); } } @@ -691,7 +683,7 @@ CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode) if (g_InputDB.menu_back || (g_InputDB.menu_confirm && m_ControlMenu.cur_role == KC_TITLE)) { - Option_Control_ShutdownText(); + M_ShutdownText(); m_KeyMode = KM_INACTIVE; g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; @@ -700,7 +692,7 @@ CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode) if ((g_InputDB.menu_left || g_InputDB.menu_right) && m_ControlMenu.cur_role == KC_TITLE) { - layout_num = Option_Control_ChangeLayout(mode); + layout_num = M_ChangeLayout(mode); } if (g_InputDB.menu_confirm) { @@ -734,8 +726,8 @@ CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode) m_ControlMenu.cur_row--; m_ControlMenu.cur_role = m_ControlMenu.cur_row->role; } - Option_Control_UpdateText(mode, layout_num); - Option_Control_FlashConflicts(mode, layout_num); + M_UpdateText(mode, layout_num); + M_FlashConflicts(mode, layout_num); } else if (g_InputDB.menu_down) { if (m_ControlMenu.cur_role == KC_TITLE) { m_ControlMenu.row_num++; @@ -758,30 +750,30 @@ CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode) m_ControlMenu.cur_row++; m_ControlMenu.cur_role = m_ControlMenu.cur_row->role; } - Option_Control_UpdateText(mode, layout_num); - Option_Control_FlashConflicts(mode, layout_num); + M_UpdateText(mode, layout_num); + M_FlashConflicts(mode, layout_num); } break; case KM_BROWSEKEYUP: if (!g_Input.any) { - Option_Control_UpdateText(mode, layout_num); + M_UpdateText(mode, layout_num); m_KeyMode = KM_CHANGE; } break; case KM_CHANGE: if (Input_ReadAndAssignKey(mode, layout_num, m_ControlMenu.cur_role)) { - Option_Control_UpdateText(mode, layout_num); + M_UpdateText(mode, layout_num); m_KeyMode = KM_CHANGEKEYUP; - Option_Control_FlashConflicts(mode, layout_num); + M_FlashConflicts(mode, layout_num); Config_Write(); } break; case KM_CHANGEKEYUP: if (!g_Input.any) { - Option_Control_UpdateText(mode, layout_num); + M_UpdateText(mode, layout_num); m_KeyMode = KM_BROWSE; } break; @@ -797,5 +789,5 @@ CONTROL_MODE Option_Control(INVENTORY_ITEM *inv_item, CONTROL_MODE mode) void Option_Control_Shutdown(void) { - Option_Control_ShutdownText(); + M_ShutdownText(); } diff --git a/src/game/option/option_control_pick.c b/src/game/option/option_control_pick.c index a5c1de610..f7b6aafaa 100644 --- a/src/game/option/option_control_pick.c +++ b/src/game/option/option_control_pick.c @@ -19,10 +19,10 @@ typedef enum PICK_TEXT { static TEXTSTRING *m_Text[TEXT_NUMBER_OF] = { 0 }; -static void Option_ControlPick_InitText(void); -static void Option_ControlPick_ShutdownText(void); +static void M_InitText(void); +static void M_ShutdownText(void); -static void Option_ControlPick_InitText(void) +static void M_InitText(void) { m_Text[TEXT_TITLE_BORDER] = Text_Create(0, -32, " "); Text_AddBackground(m_Text[TEXT_TITLE_BORDER], 180, 85, 0, 0, TS_BACKGROUND); @@ -44,7 +44,7 @@ static void Option_ControlPick_InitText(void) } } -static void Option_ControlPick_ShutdownText(void) +static void M_ShutdownText(void) { for (int i = 0; i < TEXT_NUMBER_OF; i++) { Text_Remove(m_Text[i]); @@ -55,7 +55,7 @@ static void Option_ControlPick_ShutdownText(void) CONTROL_MODE Option_ControlPick(void) { if (!m_Text[TEXT_KEYBOARD]) { - Option_ControlPick_InitText(); + M_InitText(); } if (g_InputDB.menu_up && g_OptionSelected > TEXT_OPTION_MIN) { @@ -79,7 +79,7 @@ CONTROL_MODE Option_ControlPick(void) switch (g_OptionSelected) { case TEXT_KEYBOARD: if (g_InputDB.menu_confirm) { - Option_ControlPick_ShutdownText(); + M_ShutdownText(); g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; return CM_KEYBOARD; @@ -88,7 +88,7 @@ CONTROL_MODE Option_ControlPick(void) case TEXT_CONTROLLER: if (g_InputDB.menu_confirm) { - Option_ControlPick_ShutdownText(); + M_ShutdownText(); g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; return CM_CONTROLLER; @@ -97,7 +97,7 @@ CONTROL_MODE Option_ControlPick(void) } if (g_InputDB.menu_back) { - Option_ControlPick_ShutdownText(); + M_ShutdownText(); } return CM_PICK; @@ -105,5 +105,5 @@ CONTROL_MODE Option_ControlPick(void) void Option_ControlPick_Shutdown(void) { - Option_ControlPick_ShutdownText(); + M_ShutdownText(); } diff --git a/src/game/option/option_graphics.c b/src/game/option/option_graphics.c index 4ff1f707d..f704ac887 100644 --- a/src/game/option/option_graphics.c +++ b/src/game/option/option_graphics.c @@ -100,21 +100,22 @@ static bool m_HideArrowLeft = false; static bool m_HideArrowRight = false; static TEXTSTRING *m_Text[TEXT_NUMBER_OF] = { 0 }; -static void Option_Graphics_UpdateMenuVisible(void); -static void Option_Graphics_Reinitialize(GRAPHICS_OPTION_NAME starting_option); -static void Option_Graphics_MenuUp(void); -static void Option_Graphics_MenuDown(void); -static void Option_Graphics_InitText(void); -static void Option_Graphics_UpdateText(void); -static void Option_Graphics_UpdateArrows( +static void M_InitMenu(void); +static void M_UpdateMenuVisible(void); +static void M_Reinitialize(GRAPHICS_OPTION_NAME starting_option); +static void M_MenuUp(void); +static void M_MenuDown(void); +static void M_InitText(void); +static void M_UpdateText(void); +static void M_UpdateArrows( GRAPHICS_OPTION_NAME option_name, TEXTSTRING value_text, bool more_up, bool more_down); -static void Option_Graphics_ChangeTextOption( +static void M_ChangeTextOption( const GRAPHICS_OPTION_ROW *row, TEXTSTRING *option_text, TEXTSTRING *value_text); -static int16_t Option_Graphics_PlaceColumns(bool create); +static int16_t M_PlaceColumns(bool create); -static void Option_Graphics_InitMenu(void) +static void M_InitMenu(void) { m_GraphicsMenu.first_option = &m_GfxOptionRows[OPTION_MIN]; m_GraphicsMenu.last_option = &m_GfxOptionRows[OPTION_MAX]; @@ -125,7 +126,7 @@ static void Option_Graphics_InitMenu(void) m_GraphicsMenu.last_visible = &m_GfxOptionRows[OPTION_MIN]; } -static void Option_Graphics_UpdateMenuVisible(void) +static void M_UpdateMenuVisible(void) { int32_t visible_lines = 0; if (Screen_GetResHeightDownscaled(RSR_TEXT) <= 240) { @@ -143,18 +144,18 @@ static void Option_Graphics_UpdateMenuVisible(void) &m_GfxOptionRows[OPTION_MIN] + m_GraphicsMenu.num_vis_options - 1; } -static void Option_Graphics_Reinitialize(GRAPHICS_OPTION_NAME starting_option) +static void M_Reinitialize(GRAPHICS_OPTION_NAME starting_option) { Option_Graphics_Shutdown(); - Option_Graphics_InitText(); + M_InitText(); m_IsTextInit = true; for (const GRAPHICS_OPTION_ROW *row = m_GraphicsMenu.first_option; row->option_name != starting_option; row++) { - Option_Graphics_MenuDown(); + M_MenuDown(); } } -static void Option_Graphics_MenuUp(void) +static void M_MenuUp(void) { if (m_GraphicsMenu.cur_option != m_GraphicsMenu.first_option) { if (m_GraphicsMenu.cur_option == m_GraphicsMenu.first_visible) { @@ -164,11 +165,11 @@ static void Option_Graphics_MenuUp(void) m_GraphicsMenu.row_num--; } m_GraphicsMenu.cur_option--; - Option_Graphics_UpdateText(); + M_UpdateText(); } } -static void Option_Graphics_MenuDown(void) +static void M_MenuDown(void) { if (m_GraphicsMenu.cur_option != m_GraphicsMenu.last_option) { if (m_GraphicsMenu.cur_option == m_GraphicsMenu.last_visible) { @@ -178,14 +179,14 @@ static void Option_Graphics_MenuDown(void) m_GraphicsMenu.row_num++; } m_GraphicsMenu.cur_option++; - Option_Graphics_UpdateText(); + M_UpdateText(); } } -static void Option_Graphics_InitText(void) +static void M_InitText(void) { - Option_Graphics_InitMenu(); - Option_Graphics_UpdateMenuVisible(); + M_InitMenu(); + M_UpdateMenuVisible(); m_Text[TEXT_TITLE_BORDER] = Text_Create(0, TOP_Y - 2, " "); Text_CentreH(m_Text[TEXT_TITLE_BORDER], 1); @@ -197,7 +198,7 @@ static void Option_Graphics_InitText(void) Text_AddBackground(m_Text[TEXT_TITLE], ROW_WIDTH - 4, 0, 0, 0, TS_HEADING); Text_AddOutline(m_Text[TEXT_TITLE], true, TS_HEADING); - int16_t max_y = Option_Graphics_PlaceColumns(true); + int16_t max_y = M_PlaceColumns(true); int16_t width = ROW_WIDTH; int16_t height = max_y + BORDER * 2 - TOP_Y; @@ -239,21 +240,21 @@ static void Option_Graphics_InitText(void) // m_Text[TEXT_ROW_SELECT], ROW_WIDTH - 7, 0, 0, 0, TS_REQUESTED); // Text_AddOutline(m_Text[TEXT_ROW_SELECT], true, TS_REQUESTED); - Option_Graphics_UpdateText(); + M_UpdateText(); } -static void Option_Graphics_UpdateText(void) +static void M_UpdateText(void) { int i; const GRAPHICS_OPTION_ROW *row; for (i = 0, row = m_GraphicsMenu.first_visible; row <= m_GraphicsMenu.last_visible; i++, row++) { - Option_Graphics_ChangeTextOption( + M_ChangeTextOption( row, m_GraphicsMenu.option_texts[i], m_GraphicsMenu.value_texts[i]); } } -static void Option_Graphics_UpdateArrows( +static void M_UpdateArrows( GRAPHICS_OPTION_NAME option_name, TEXTSTRING value_text, bool more_up, bool more_down) { @@ -340,7 +341,7 @@ static void Option_Graphics_UpdateArrows( } } -static int16_t Option_Graphics_PlaceColumns(bool create) +static int16_t M_PlaceColumns(bool create) { const int16_t centre = Screen_GetResWidthDownscaled(RSR_TEXT) / 2; const GRAPHICS_OPTION_ROW *row = m_GraphicsMenu.first_visible; @@ -374,7 +375,7 @@ static int16_t Option_Graphics_PlaceColumns(bool create) return MAX(name_y, value_y); } -static void Option_Graphics_ChangeTextOption( +static void M_ChangeTextOption( const GRAPHICS_OPTION_ROW *row, TEXTSTRING *option_text, TEXTSTRING *value_text) { @@ -470,16 +471,16 @@ static void Option_Graphics_ChangeTextOption( void Option_Graphics(INVENTORY_ITEM *inv_item) { if (!m_IsTextInit) { - Option_Graphics_InitText(); + M_InitText(); m_IsTextInit = true; } if (g_InputDB.menu_up) { - Option_Graphics_MenuUp(); + M_MenuUp(); } if (g_InputDB.menu_down) { - Option_Graphics_MenuDown(); + M_MenuDown(); } Text_AddBackground( @@ -529,7 +530,7 @@ void Option_Graphics(INVENTORY_ITEM *inv_item) case OPTION_UI_TEXT_SCALE: g_Config.ui.text_scale += 0.1; CLAMP(g_Config.ui.text_scale, MIN_TEXT_SCALE, MAX_TEXT_SCALE); - Option_Graphics_Reinitialize(OPTION_UI_TEXT_SCALE); + M_Reinitialize(OPTION_UI_TEXT_SCALE); reset = OPTION_UI_TEXT_SCALE; break; @@ -553,7 +554,7 @@ void Option_Graphics(INVENTORY_ITEM *inv_item) if (Screen_SetNextRes()) { g_Config.resolution_width = Screen_GetResWidth(); g_Config.resolution_height = Screen_GetResHeight(); - Option_Graphics_Reinitialize(OPTION_RESOLUTION); + M_Reinitialize(OPTION_RESOLUTION); reset = OPTION_RESOLUTION; } break; @@ -624,7 +625,7 @@ void Option_Graphics(INVENTORY_ITEM *inv_item) case OPTION_UI_TEXT_SCALE: g_Config.ui.text_scale -= 0.1; CLAMP(g_Config.ui.text_scale, MIN_TEXT_SCALE, MAX_TEXT_SCALE); - Option_Graphics_Reinitialize(OPTION_UI_TEXT_SCALE); + M_Reinitialize(OPTION_UI_TEXT_SCALE); reset = OPTION_UI_TEXT_SCALE; break; @@ -649,7 +650,7 @@ void Option_Graphics(INVENTORY_ITEM *inv_item) reset = OPTION_RESOLUTION; g_Config.resolution_width = Screen_GetResWidth(); g_Config.resolution_height = Screen_GetResHeight(); - Option_Graphics_Reinitialize(OPTION_RESOLUTION); + M_Reinitialize(OPTION_RESOLUTION); } break; @@ -685,14 +686,14 @@ void Option_Graphics(INVENTORY_ITEM *inv_item) } if (reset > -1) { - Option_Graphics_ChangeTextOption( + M_ChangeTextOption( m_GraphicsMenu.cur_option, m_GraphicsMenu.option_texts[m_GraphicsMenu.row_num], m_GraphicsMenu.value_texts[m_GraphicsMenu.row_num]); Config_Write(); } - Option_Graphics_UpdateArrows( + M_UpdateArrows( m_GraphicsMenu.cur_option->option_name, *m_GraphicsMenu.value_texts[m_GraphicsMenu.row_num], m_GraphicsMenu.first_visible != m_GraphicsMenu.first_option, @@ -719,5 +720,5 @@ void Option_Graphics_Shutdown(void) m_IsTextInit = false; m_HideArrowLeft = false; m_HideArrowRight = false; - Option_Graphics_InitMenu(); + M_InitMenu(); } diff --git a/src/game/option/option_passport.c b/src/game/option/option_passport.c index fb270a195..a9df3a679 100644 --- a/src/game/option/option_passport.c +++ b/src/game/option/option_passport.c @@ -96,25 +96,25 @@ REQUEST_INFO g_SavegameRequester = { .items = NULL, }; -static void Option_Passport_InitRequesters(void); -static void Option_Passport_InitText(void); -static void Option_Passport_ShutdownText(void); -static void Option_Passport_Close(INVENTORY_ITEM *inv_item); -static void Option_Passport_DeterminePages(void); -static void Option_Passport_InitSaveRequester(int16_t page_num); -static void Option_Passport_InitSelectLevelRequester(void); -static void Option_Passport_InitNewGameRequester(void); -static void Option_Passport_ShowSaves(PASSPORT_MODE pending_mode); -static void Option_Passport_ShowSelectLevel(void); -static void Option_Passport_LoadGame(void); -static void Option_Passport_SelectLevel(void); -static void Option_Passport_SaveGame(void); -static void Option_Passport_NewGame(void); -static void Option_Passport_Restart(INVENTORY_ITEM *inv_item); -static void Option_Passport_FlipRight(INVENTORY_ITEM *inv_item); -static void Option_Passport_FlipLeft(INVENTORY_ITEM *inv_item); - -void Option_Passport_InitRequesters(void) +static void M_InitRequesters(void); +static void M_InitText(void); +static void M_ShutdownText(void); +static void M_Close(INVENTORY_ITEM *inv_item); +static void M_DeterminePages(void); +static void M_InitSaveRequester(int16_t page_num); +static void M_InitSelectLevelRequester(void); +static void M_InitNewGameRequester(void); +static void M_ShowSaves(PASSPORT_MODE pending_mode); +static void M_ShowSelectLevel(void); +static void M_LoadGame(void); +static void M_SelectLevel(void); +static void M_SaveGame(void); +static void M_NewGame(void); +static void M_Restart(INVENTORY_ITEM *inv_item); +static void M_FlipRight(INVENTORY_ITEM *inv_item); +static void M_FlipLeft(INVENTORY_ITEM *inv_item); + +void M_InitRequesters(void) { Requester_Shutdown(&m_SelectLevelRequester); Requester_Shutdown(&m_NewGameRequester); @@ -122,7 +122,7 @@ void Option_Passport_InitRequesters(void) Requester_Init(&m_NewGameRequester, MAX_GAME_MODES); } -static void Option_Passport_InitText(void) +static void M_InitText(void) { m_Text[TEXT_LEFT_ARROW] = Text_Create(-85, -15, "\200"); Text_Hide(m_Text[TEXT_LEFT_ARROW], true); @@ -144,7 +144,7 @@ static void Option_Passport_InitText(void) } } -static void Option_Passport_ShutdownText(void) +static void M_ShutdownText(void) { for (int i = 0; i < TEXT_NUMBER_OF; i++) { Text_Remove(m_Text[i]); @@ -153,7 +153,7 @@ static void Option_Passport_ShutdownText(void) m_IsTextInit = false; } -static void Option_Passport_Close(INVENTORY_ITEM *inv_item) +static void M_Close(INVENTORY_ITEM *inv_item) { if (m_PassportStatus.page == PAGE_3) { inv_item->anim_direction = 1; @@ -162,10 +162,10 @@ static void Option_Passport_Close(INVENTORY_ITEM *inv_item) inv_item->anim_direction = -1; inv_item->goal_frame = 0; } - Option_Passport_ShutdownText(); + M_ShutdownText(); } -static void Option_Passport_DeterminePages(void) +static void M_DeterminePages(void) { switch (g_InvMode) { case INV_TITLE_MODE: @@ -201,7 +201,7 @@ static void Option_Passport_DeterminePages(void) m_PassportStatus.page_role[PAGE_1] = PASSPORT_MODE_LOAD_GAME; m_PassportStatus.page_role[PAGE_2] = PASSPORT_MODE_UNAVAILABLE; m_PassportStatus.page_role[PAGE_3] = PASSPORT_MODE_UNAVAILABLE; - Option_Passport_InitSaveRequester(PAGE_1); + M_InitSaveRequester(PAGE_1); break; case INV_SAVE_MODE: @@ -221,7 +221,7 @@ static void Option_Passport_DeterminePages(void) m_PassportStatus.page_available[PAGE_3] = true; m_PassportStatus.page_role[PAGE_3] = PASSPORT_MODE_EXIT_TITLE; } - Option_Passport_InitSaveRequester(PAGE_2); + M_InitSaveRequester(PAGE_2); break; case INV_SAVE_CRYSTAL_MODE: @@ -232,7 +232,7 @@ static void Option_Passport_DeterminePages(void) m_PassportStatus.page_role[PAGE_1] = PASSPORT_MODE_UNAVAILABLE; m_PassportStatus.page_role[PAGE_2] = PASSPORT_MODE_SAVE_GAME; m_PassportStatus.page_role[PAGE_3] = PASSPORT_MODE_UNAVAILABLE; - Option_Passport_InitSaveRequester(PAGE_2); + M_InitSaveRequester(PAGE_2); break; case INV_DEATH_MODE: @@ -257,7 +257,7 @@ static void Option_Passport_DeterminePages(void) } } -static void Option_Passport_InitSaveRequester(int16_t page_num) +static void M_InitSaveRequester(int16_t page_num) { REQUEST_INFO *req = &g_SavegameRequester; Requester_ClearTextstrings(req); @@ -287,7 +287,7 @@ static void Option_Passport_InitSaveRequester(int16_t page_num) Savegame_ScanSavedGames(); } -static void Option_Passport_InitSelectLevelRequester(void) +static void M_InitSelectLevelRequester(void) { REQUEST_INFO *req = &m_SelectLevelRequester; req->is_blockable = true; @@ -316,7 +316,7 @@ static void Option_Passport_InitSelectLevelRequester(void) Savegame_ScanAvailableLevels(req); } -static void Option_Passport_InitNewGameRequester(void) +static void M_InitNewGameRequester(void) { REQUEST_INFO *req = &m_NewGameRequester; Requester_ClearTextstrings(req); @@ -340,7 +340,7 @@ static void Option_Passport_InitNewGameRequester(void) } } -static void Option_Passport_ShowSaves(PASSPORT_MODE pending_mode) +static void M_ShowSaves(PASSPORT_MODE pending_mode) { int32_t select = Requester_Display(&g_SavegameRequester); if (select == 0) { @@ -361,7 +361,7 @@ static void Option_Passport_ShowSaves(PASSPORT_MODE pending_mode) } } -static void Option_Passport_ShowSelectLevel(void) +static void M_ShowSelectLevel(void) { int32_t select = Requester_Display(&m_SelectLevelRequester); if (select) { @@ -385,14 +385,14 @@ static void Option_Passport_ShowSelectLevel(void) } } -static void Option_Passport_LoadGame(void) +static void M_LoadGame(void) { Text_ChangeText(m_Text[TEXT_PAGE_NAME], GS(PASSPORT_LOAD_GAME)); g_SavegameRequester.is_blockable = true; if (m_PassportStatus.mode == PASSPORT_MODE_BROWSE) { if (g_InputDB.menu_confirm) { - Option_Passport_InitSaveRequester(m_PassportStatus.page); + M_InitSaveRequester(m_PassportStatus.page); g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; m_PassportStatus.mode = PASSPORT_MODE_LOAD_GAME; @@ -404,13 +404,13 @@ static void Option_Passport_LoadGame(void) g_GameInfo.current_save_slot = g_SavegameRequester.requested; Text_Hide(m_Text[TEXT_LEVEL_ARROW_RIGHT], true); Requester_ClearTextstrings(&g_SavegameRequester); - Option_Passport_InitSelectLevelRequester(); + M_InitSelectLevelRequester(); m_PassportStatus.mode = PASSPORT_MODE_SELECT_LEVEL; g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; - Option_Passport_ShowSelectLevel(); + M_ShowSelectLevel(); } else { - Option_Passport_ShowSaves(PASSPORT_MODE_LOAD_GAME); + M_ShowSaves(PASSPORT_MODE_LOAD_GAME); if (m_PassportStatus.mode == PASSPORT_MODE_LOAD_GAME) { Text_SetPos( m_Text[TEXT_LEVEL_ARROW_RIGHT], 130, @@ -425,7 +425,7 @@ static void Option_Passport_LoadGame(void) } } } else { - Option_Passport_ShowSaves(PASSPORT_MODE_LOAD_GAME); + M_ShowSaves(PASSPORT_MODE_LOAD_GAME); Text_Hide(m_Text[TEXT_LEVEL_ARROW_RIGHT], true); } @@ -434,22 +434,22 @@ static void Option_Passport_LoadGame(void) Text_Hide(m_Text[TEXT_LEVEL_ARROW_RIGHT], true); } } else if (m_PassportStatus.mode == PASSPORT_MODE_SELECT_LEVEL) { - Option_Passport_SelectLevel(); + M_SelectLevel(); } } -static void Option_Passport_SelectLevel(void) +static void M_SelectLevel(void) { if (g_InputDB.menu_left) { Text_Hide(m_Text[TEXT_LEVEL_ARROW_LEFT], true); Requester_ClearTextstrings(&m_SelectLevelRequester); - Option_Passport_InitSaveRequester(m_PassportStatus.page); + M_InitSaveRequester(m_PassportStatus.page); m_PassportStatus.mode = PASSPORT_MODE_LOAD_GAME; g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; - Option_Passport_ShowSaves(PASSPORT_MODE_LOAD_GAME); + M_ShowSaves(PASSPORT_MODE_LOAD_GAME); } else { - Option_Passport_ShowSelectLevel(); + M_ShowSelectLevel(); if (m_PassportStatus.mode == PASSPORT_MODE_SELECT_LEVEL) { Text_SetPos( m_Text[TEXT_LEVEL_ARROW_LEFT], -130, @@ -465,24 +465,24 @@ static void Option_Passport_SelectLevel(void) } } -static void Option_Passport_SaveGame(void) +static void M_SaveGame(void) { Text_ChangeText(m_Text[TEXT_PAGE_NAME], GS(PASSPORT_SAVE_GAME)); g_SavegameRequester.is_blockable = false; if (m_PassportStatus.mode == PASSPORT_MODE_BROWSE) { if (g_InputDB.menu_confirm) { - Option_Passport_InitSaveRequester(m_PassportStatus.page); + M_InitSaveRequester(m_PassportStatus.page); g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; m_PassportStatus.mode = PASSPORT_MODE_SAVE_GAME; } } else if (m_PassportStatus.mode == PASSPORT_MODE_SAVE_GAME) { - Option_Passport_ShowSaves(PASSPORT_MODE_SAVE_GAME); + M_ShowSaves(PASSPORT_MODE_SAVE_GAME); } } -static void Option_Passport_NewGame(void) +static void M_NewGame(void) { Text_ChangeText(m_Text[TEXT_PAGE_NAME], GS(PASSPORT_NEW_GAME)); @@ -490,7 +490,7 @@ static void Option_Passport_NewGame(void) if (g_InputDB.menu_confirm && (g_Config.enable_game_modes || g_Config.profile.new_game_plus_unlock)) { - Option_Passport_InitNewGameRequester(); + M_InitNewGameRequester(); g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; m_PassportStatus.mode = PASSPORT_MODE_NEW_GAME; @@ -539,7 +539,7 @@ static void Option_Passport_NewGame(void) } } -static void Option_Passport_Restart(INVENTORY_ITEM *inv_item) +static void M_Restart(INVENTORY_ITEM *inv_item) { Text_ChangeText(m_Text[TEXT_PAGE_NAME], GS(PASSPORT_RESTART_LEVEL)); @@ -553,7 +553,7 @@ static void Option_Passport_Restart(INVENTORY_ITEM *inv_item) } } -static void Option_Passport_FlipRight(INVENTORY_ITEM *inv_item) +static void M_FlipRight(INVENTORY_ITEM *inv_item) { g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; @@ -570,7 +570,7 @@ static void Option_Passport_FlipRight(INVENTORY_ITEM *inv_item) } } -static void Option_Passport_FlipLeft(INVENTORY_ITEM *inv_item) +static void M_FlipLeft(INVENTORY_ITEM *inv_item) { g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; @@ -590,19 +590,19 @@ static void Option_Passport_FlipLeft(INVENTORY_ITEM *inv_item) void Option_Passport(INVENTORY_ITEM *inv_item) { if (!m_IsTextInit) { - Option_Passport_InitRequesters(); + M_InitRequesters(); Text_Remove(g_InvItemText[IT_NAME]); g_InvItemText[IT_NAME] = NULL; Text_Remove(g_InvRingText); g_InvRingText = NULL; - Option_Passport_InitText(); + M_InitText(); m_IsTextInit = true; - Option_Passport_DeterminePages(); + M_DeterminePages(); } m_PassportStatus.page = (inv_item->goal_frame - inv_item->open_frame) / 5; if (!m_PassportStatus.page_available[m_PassportStatus.page]) { - Option_Passport_FlipRight(inv_item); + M_FlipRight(inv_item); return; } @@ -627,19 +627,19 @@ void Option_Passport(INVENTORY_ITEM *inv_item) switch (m_PassportStatus.page_role[m_PassportStatus.page]) { case PASSPORT_MODE_LOAD_GAME: - Option_Passport_LoadGame(); + M_LoadGame(); break; case PASSPORT_MODE_SAVE_GAME: - Option_Passport_SaveGame(); + M_SaveGame(); break; case PASSPORT_MODE_NEW_GAME: - Option_Passport_NewGame(); + M_NewGame(); break; case PASSPORT_MODE_RESTART: - Option_Passport_Restart(inv_item); + M_Restart(inv_item); break; case PASSPORT_MODE_EXIT_TITLE: @@ -666,11 +666,11 @@ void Option_Passport(INVENTORY_ITEM *inv_item) if (g_InputDB.menu_right || !m_PassportStatus.page_available[m_PassportStatus.page]) { - Option_Passport_FlipRight(inv_item); + M_FlipRight(inv_item); } if (g_InputDB.menu_left) { - Option_Passport_FlipLeft(inv_item); + M_FlipLeft(inv_item); } if (g_InputDB.menu_back) { @@ -678,18 +678,18 @@ void Option_Passport(INVENTORY_ITEM *inv_item) g_Input = (INPUT_STATE) { 0 }; g_InputDB = (INPUT_STATE) { 0 }; } else { - Option_Passport_Close(inv_item); + M_Close(inv_item); } } if (g_InputDB.menu_confirm) { - Option_Passport_Close(inv_item); + M_Close(inv_item); } } void Option_Passport_Shutdown(void) { - Option_Passport_ShutdownText(); + M_ShutdownText(); Requester_Shutdown(&m_SelectLevelRequester); Requester_Shutdown(&m_NewGameRequester); Requester_ClearTextstrings(&g_SavegameRequester); diff --git a/src/game/option/option_sound.c b/src/game/option/option_sound.c index 49e265ca1..26f9c0eb3 100644 --- a/src/game/option/option_sound.c +++ b/src/game/option/option_sound.c @@ -25,9 +25,9 @@ typedef enum SOUND_TEXT { static TEXTSTRING *m_Text[TEXT_NUMBER_OF] = { 0 }; -static void Option_Sound_InitText(void); +static void M_InitText(void); -static void Option_Sound_InitText(void) +static void M_InitText(void) { char buf[20]; @@ -67,7 +67,7 @@ void Option_Sound(INVENTORY_ITEM *inv_item) char buf[20]; if (!m_Text[TEXT_MUSIC_VOLUME]) { - Option_Sound_InitText(); + M_InitText(); } if (g_InputDB.menu_up && g_OptionSelected > TEXT_OPTION_MIN) { diff --git a/src/game/output.c b/src/game/output.c index 65e0582e5..3ac543963 100644 --- a/src/game/output.c +++ b/src/game/output.c @@ -68,28 +68,26 @@ static const char *m_ImageExtensions[] = { ".png", ".jpg", ".jpeg", ".pcx", NULL, }; -static void Output_DrawBlackOverlay(uint8_t alpha); - -static const int16_t *Output_DrawObjectG3( - const int16_t *obj_ptr, int32_t number); -static const int16_t *Output_DrawObjectG4( - const int16_t *obj_ptr, int32_t number); -static const int16_t *Output_DrawObjectGT3( - const int16_t *obj_ptr, int32_t number); -static const int16_t *Output_DrawObjectGT4( - const int16_t *obj_ptr, int32_t number); -static const int16_t *Output_DrawRoomSprites( +static void M_DrawBlackOverlay(uint8_t alpha); + +static const int16_t *M_DrawObjectG3(const int16_t *obj_ptr, int32_t number); +static const int16_t *M_DrawObjectG4(const int16_t *obj_ptr, int32_t number); +static const int16_t *M_DrawObjectGT3(const int16_t *obj_ptr, int32_t number); +static const int16_t *M_DrawObjectGT4(const int16_t *obj_ptr, int32_t number); +static const int16_t *M_DrawObjectEnvMap( + const int16_t *obj_ptr, int32_t poly_count, int32_t vertex_count, + bool textured); +static const int16_t *M_DrawRoomSprites( const int16_t *obj_ptr, int32_t vertex_count); -static const int16_t *Output_CalcObjectVertices(const int16_t *obj_ptr); -static const int16_t *Output_CalcVerticeLight(const int16_t *obj_ptr); -static const int16_t *Output_CalcVerticeEnvMap(const int16_t *obj_ptr); -static const int16_t *Output_CalcSkyboxLight(const int16_t *obj_ptr); -static const int16_t *Output_CalcRoomVertices(const int16_t *obj_ptr); -static int32_t Output_CalcFogShade(int32_t depth); -static void Output_CalcWibbleTable(void); +static const int16_t *M_CalcObjectVertices(const int16_t *obj_ptr); +static const int16_t *M_CalcVerticeLight(const int16_t *obj_ptr); +static const int16_t *M_CalcVerticeEnvMap(const int16_t *obj_ptr); +static const int16_t *M_CalcSkyboxLight(const int16_t *obj_ptr); +static const int16_t *M_CalcRoomVertices(const int16_t *obj_ptr); +static int32_t M_CalcFogShade(int32_t depth); +static void M_CalcWibbleTable(void); -static const int16_t *Output_DrawObjectG3( - const int16_t *obj_ptr, int32_t number) +static const int16_t *M_DrawObjectG3(const int16_t *obj_ptr, int32_t number) { S_Output_DisableTextureMode(); @@ -107,8 +105,7 @@ static const int16_t *Output_DrawObjectG3( return obj_ptr; } -static const int16_t *Output_DrawObjectG4( - const int16_t *obj_ptr, int32_t number) +static const int16_t *M_DrawObjectG4(const int16_t *obj_ptr, int32_t number) { S_Output_DisableTextureMode(); @@ -129,8 +126,7 @@ static const int16_t *Output_DrawObjectG4( return obj_ptr; } -static const int16_t *Output_DrawObjectGT3( - const int16_t *obj_ptr, int32_t number) +static const int16_t *M_DrawObjectGT3(const int16_t *obj_ptr, int32_t number) { S_Output_EnableTextureMode(); @@ -151,8 +147,7 @@ static const int16_t *Output_DrawObjectGT3( return obj_ptr; } -static const int16_t *Output_DrawObjectGT4( - const int16_t *obj_ptr, int32_t number) +static const int16_t *M_DrawObjectGT4(const int16_t *obj_ptr, int32_t number) { S_Output_EnableTextureMode(); @@ -174,7 +169,7 @@ static const int16_t *Output_DrawObjectGT4( return obj_ptr; } -static const int16_t *Output_DrawObjectEnvMap( +static const int16_t *M_DrawObjectEnvMap( const int16_t *obj_ptr, const int32_t poly_count, const int32_t vertex_count, const bool textured) { @@ -205,7 +200,7 @@ static const int16_t *Output_DrawObjectEnvMap( return obj_ptr; } -static const int16_t *Output_DrawRoomSprites( +static const int16_t *M_DrawRoomSprites( const int16_t *obj_ptr, int32_t vertex_count) { for (int i = 0; i < vertex_count; i++) { @@ -238,7 +233,7 @@ static const int16_t *Output_DrawRoomSprites( return obj_ptr; } -static const int16_t *Output_CalcObjectVertices(const int16_t *obj_ptr) +static const int16_t *M_CalcObjectVertices(const int16_t *obj_ptr) { int16_t total_clip = -1; @@ -301,7 +296,7 @@ static const int16_t *Output_CalcObjectVertices(const int16_t *obj_ptr) return total_clip == 0 ? obj_ptr : NULL; } -static const int16_t *Output_CalcVerticeLight(const int16_t *obj_ptr) +static const int16_t *M_CalcVerticeLight(const int16_t *obj_ptr) { int32_t vertex_count = *obj_ptr++; if (vertex_count > 0) { @@ -345,7 +340,7 @@ static const int16_t *Output_CalcVerticeLight(const int16_t *obj_ptr) return obj_ptr; } -static const int16_t *Output_CalcVerticeEnvMap(const int16_t *obj_ptr) +static const int16_t *M_CalcVerticeEnvMap(const int16_t *obj_ptr) { const int32_t vtx_count = *obj_ptr++; if (vtx_count <= 0) { @@ -360,7 +355,7 @@ static const int16_t *Output_CalcVerticeEnvMap(const int16_t *obj_ptr) m_VBuf[i].g = 0x1000; const int32_t depth = g_MatrixPtr->_23 >> W2V_SHIFT; - m_VBuf[i].g += Output_CalcFogShade(depth); + m_VBuf[i].g += M_CalcFogShade(depth); // reflection can be darker but not brighter CLAMP(m_VBuf[i].g, 0x1000, 0x1FFF); @@ -390,7 +385,7 @@ static const int16_t *Output_CalcVerticeEnvMap(const int16_t *obj_ptr) return obj_ptr; } -static const int16_t *Output_CalcSkyboxLight(const int16_t *obj_ptr) +static const int16_t *M_CalcSkyboxLight(const int16_t *obj_ptr) { int32_t vertex_count = *obj_ptr++; if (vertex_count > 0) { @@ -407,7 +402,7 @@ static const int16_t *Output_CalcSkyboxLight(const int16_t *obj_ptr) return obj_ptr; } -static const int16_t *Output_CalcRoomVertices(const int16_t *obj_ptr) +static const int16_t *M_CalcRoomVertices(const int16_t *obj_ptr) { int32_t vertex_count = *obj_ptr++; @@ -452,7 +447,7 @@ static const int16_t *Output_CalcRoomVertices(const int16_t *obj_ptr) clip_flags |= 16; } } else if (depth) { - m_VBuf[i].g += Output_CalcFogShade(depth); + m_VBuf[i].g += M_CalcFogShade(depth); if (!m_IsWaterEffect) { CLAMPG(m_VBuf[i].g, MAX_LIGHTING); } @@ -496,7 +491,7 @@ static const int16_t *Output_CalcRoomVertices(const int16_t *obj_ptr) return obj_ptr; } -static int32_t Output_CalcFogShade(int32_t depth) +static int32_t M_CalcFogShade(int32_t depth) { int32_t fog_begin = Output_GetDrawDistFade(); int32_t fog_end = Output_GetDrawDistMax(); @@ -511,7 +506,7 @@ static int32_t Output_CalcFogShade(int32_t depth) return (depth - fog_begin) * 0x1FFF / (fog_end - fog_begin); } -static void Output_CalcWibbleTable(void) +static void M_CalcWibbleTable(void) { for (int i = 0; i < WIBBLE_SIZE; i++) { PHD_ANGLE angle = (i * PHD_360) / WIBBLE_SIZE; @@ -523,7 +518,7 @@ static void Output_CalcWibbleTable(void) bool Output_Init(void) { - Output_CalcWibbleTable(); + M_CalcWibbleTable(); return S_Output_Init(); } @@ -566,7 +561,7 @@ RGBA_8888 Output_RGB2RGBA(const RGB_888 color) void Output_DrawBlack(void) { - Output_DrawBlackOverlay(255); + M_DrawBlackOverlay(255); } void Output_FlushTranslucentObjects(void) @@ -657,7 +652,7 @@ void Output_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t room_num) } int32_t distance = g_MatrixPtr->_23 >> W2V_SHIFT; - g_LsAdder += Output_CalcFogShade(distance); + g_LsAdder += M_CalcFogShade(distance); CLAMPG(g_LsAdder, 0x1FFF); } @@ -665,7 +660,7 @@ void Output_CalculateStaticLight(int16_t adder) { g_LsAdder = adder - 16 * 256; int32_t distance = g_MatrixPtr->_23 >> W2V_SHIFT; - g_LsAdder += Output_CalcFogShade(distance); + g_LsAdder += M_CalcFogShade(distance); CLAMPG(g_LsAdder, 0x1FFF); } @@ -700,26 +695,26 @@ void Output_DrawPolygons(const int16_t *obj_ptr, int clip) const bool has_reflections = IS_REFLECTION_ENABLED(obj_ptr[3]); obj_ptr += 4; - obj_ptr = Output_CalcObjectVertices(obj_ptr); + obj_ptr = M_CalcObjectVertices(obj_ptr); if (obj_ptr == NULL) { return; } const int16_t *obj_ptr_old = obj_ptr; - obj_ptr = Output_CalcVerticeLight(obj_ptr); - obj_ptr = Output_DrawObjectGT4(obj_ptr + 1, *obj_ptr); - obj_ptr = Output_DrawObjectGT3(obj_ptr + 1, *obj_ptr); - obj_ptr = Output_DrawObjectG4(obj_ptr + 1, *obj_ptr); - obj_ptr = Output_DrawObjectG3(obj_ptr + 1, *obj_ptr); + obj_ptr = M_CalcVerticeLight(obj_ptr); + obj_ptr = M_DrawObjectGT4(obj_ptr + 1, *obj_ptr); + obj_ptr = M_DrawObjectGT3(obj_ptr + 1, *obj_ptr); + obj_ptr = M_DrawObjectG4(obj_ptr + 1, *obj_ptr); + obj_ptr = M_DrawObjectG3(obj_ptr + 1, *obj_ptr); if (has_reflections && g_Config.rendering.enable_reflections) { obj_ptr = obj_ptr_old; - obj_ptr = Output_CalcVerticeEnvMap(obj_ptr); + obj_ptr = M_CalcVerticeEnvMap(obj_ptr); if (obj_ptr != NULL) { - obj_ptr = Output_DrawObjectEnvMap(obj_ptr + 1, *obj_ptr, 4, true); - obj_ptr = Output_DrawObjectEnvMap(obj_ptr + 1, *obj_ptr, 3, true); - obj_ptr = Output_DrawObjectEnvMap(obj_ptr + 1, *obj_ptr, 4, false); - obj_ptr = Output_DrawObjectEnvMap(obj_ptr + 1, *obj_ptr, 3, false); + obj_ptr = M_DrawObjectEnvMap(obj_ptr + 1, *obj_ptr, 4, true); + obj_ptr = M_DrawObjectEnvMap(obj_ptr + 1, *obj_ptr, 3, true); + obj_ptr = M_DrawObjectEnvMap(obj_ptr + 1, *obj_ptr, 4, false); + obj_ptr = M_DrawObjectEnvMap(obj_ptr + 1, *obj_ptr, 3, false); } } } @@ -749,26 +744,26 @@ void Output_DrawSkybox(const int16_t *obj_ptr) g_PhdRight = Viewport_GetMaxX(); g_PhdBottom = Viewport_GetMaxY(); - obj_ptr = Output_CalcObjectVertices(obj_ptr + 4); + obj_ptr = M_CalcObjectVertices(obj_ptr + 4); if (!obj_ptr) { return; } S_Output_DisableDepthTest(); - obj_ptr = Output_CalcSkyboxLight(obj_ptr); - obj_ptr = Output_DrawObjectGT4(obj_ptr + 1, *obj_ptr); - obj_ptr = Output_DrawObjectGT3(obj_ptr + 1, *obj_ptr); - obj_ptr = Output_DrawObjectG4(obj_ptr + 1, *obj_ptr); - obj_ptr = Output_DrawObjectG3(obj_ptr + 1, *obj_ptr); + obj_ptr = M_CalcSkyboxLight(obj_ptr); + obj_ptr = M_DrawObjectGT4(obj_ptr + 1, *obj_ptr); + obj_ptr = M_DrawObjectGT3(obj_ptr + 1, *obj_ptr); + obj_ptr = M_DrawObjectG4(obj_ptr + 1, *obj_ptr); + obj_ptr = M_DrawObjectG3(obj_ptr + 1, *obj_ptr); S_Output_EnableDepthTest(); } void Output_DrawRoom(const int16_t *obj_ptr) { - obj_ptr = Output_CalcRoomVertices(obj_ptr); - obj_ptr = Output_DrawObjectGT4(obj_ptr + 1, *obj_ptr); - obj_ptr = Output_DrawObjectGT3(obj_ptr + 1, *obj_ptr); - obj_ptr = Output_DrawRoomSprites(obj_ptr + 1, *obj_ptr); + obj_ptr = M_CalcRoomVertices(obj_ptr); + obj_ptr = M_DrawObjectGT4(obj_ptr + 1, *obj_ptr); + obj_ptr = M_DrawObjectGT3(obj_ptr + 1, *obj_ptr); + obj_ptr = M_DrawRoomSprites(obj_ptr + 1, *obj_ptr); } void Output_DrawShadow( @@ -802,7 +797,7 @@ void Output_DrawShadow( item->interp.result.pos.x, item->floor, item->interp.result.pos.z); Matrix_RotY(item->rot.y); - if (Output_CalcObjectVertices(&g_ShadowInfo.poly_count)) { + if (M_CalcObjectVertices(&g_ShadowInfo.poly_count)) { int16_t clip_and = 1; int16_t clip_positive = 1; int16_t clip_or = 0; @@ -909,7 +904,7 @@ void Output_DrawSprite( if (x2 >= Viewport_GetMinX() && y2 >= Viewport_GetMinY() && x1 <= Viewport_GetMaxX() && y1 <= Viewport_GetMaxY()) { int32_t depth = zv >> W2V_SHIFT; - shade += Output_CalcFogShade(depth); + shade += M_CalcFogShade(depth); CLAMPG(shade, 0x1FFF); S_Output_DrawSprite(x1, y1, x2, y2, zv, sprnum, shade); } @@ -1030,7 +1025,7 @@ void Output_DrawSpriteRel( if (x2 >= Viewport_GetMinX() && y2 >= Viewport_GetMinY() && x1 <= Viewport_GetMaxX() && y1 <= Viewport_GetMaxY()) { int32_t depth = zv >> W2V_SHIFT; - shade += Output_CalcFogShade(depth); + shade += M_CalcFogShade(depth); CLAMPG(shade, 0x1FFF); S_Output_DrawSprite(x1, y1, x2, y2, zv, sprnum, shade); } @@ -1204,7 +1199,7 @@ void Output_RotateLight(int16_t pitch, int16_t yaw) >> W2V_SHIFT; } -static void Output_DrawBlackOverlay(uint8_t alpha) +static void M_DrawBlackOverlay(uint8_t alpha) { int32_t sx = 0; int32_t sy = 0; @@ -1220,12 +1215,12 @@ static void Output_DrawBlackOverlay(uint8_t alpha) void Output_DrawBackdropScreen(void) { - Output_DrawBlackOverlay(m_BackdropCurAlpha); + M_DrawBlackOverlay(m_BackdropCurAlpha); } void Output_DrawOverlayScreen(void) { - Output_DrawBlackOverlay(m_OverlayCurAlpha); + M_DrawBlackOverlay(m_OverlayCurAlpha); } void Output_FadeReset(void) diff --git a/src/game/overlay.c b/src/game/overlay.c index 2f4594eed..49f11630c 100644 --- a/src/game/overlay.c +++ b/src/game/overlay.c @@ -120,25 +120,26 @@ static BAR_INFO m_HealthBar = { 0 }; static BAR_INFO m_AirBar = { 0 }; static BAR_INFO m_EnemyBar = { 0 }; -static void Overlay_BarSetupHealth(void); -static void Overlay_BarSetupAir(void); -static void Overlay_BarSetupEnemy(void); -static void Overlay_BarBlink(BAR_INFO *bar_info); -static int32_t Overlay_BarGetPercent(BAR_INFO *bar_info); -static void Overlay_BarGetLocation( +static void M_BarSetupHealth(void); +static void M_BarSetupAir(void); +static void M_BarSetupEnemy(void); +static void M_BarBlink(BAR_INFO *bar_info); +static int32_t M_BarGetPercent(BAR_INFO *bar_info); +static void M_BarGetLocation( BAR_INFO *bar_info, int32_t *width, int32_t *height, int32_t *x, int32_t *y); -static float Overlay_Ease(int32_t cur_frame, int32_t max_frames); -static void Overlay_DrawPickup3D(DISPLAY_PICKUP_INFO *pu); -static void Overlay_DrawPickups3D(void); -static void Overlay_DrawPickupsSprites(void); -static void Overlay_BarDrawAir(void); -static void Overlay_BarDrawEnemy(void); -static void Overlay_ResetBarLocations(void); -static void Overlay_RemoveAmmoText(void); -static void Overlay_DrawAmmoInfo(void); - -static void Overlay_BarSetupHealth(void) +static float M_Ease(int32_t cur_frame, int32_t max_frames); +static void M_DrawPickup3D(DISPLAY_PICKUP_INFO *pu); +static void M_DrawPickups3D(void); +static void M_DrawPickupsSprites(void); +static void M_BarDrawAir(void); +static void M_BarDrawEnemy(void); +static void M_ResetBarLocations(void); +static void M_RemoveAmmoText(void); +static void M_DrawAmmoInfo(void); +static void M_DrawPickups(void); + +static void M_BarSetupHealth(void) { m_HealthBar.type = BT_LARA_HEALTH; m_HealthBar.value = 0; @@ -151,7 +152,7 @@ static void Overlay_BarSetupHealth(void) m_HealthBar.location = g_Config.healthbar_location; } -static void Overlay_BarSetupAir(void) +static void M_BarSetupAir(void) { m_AirBar.type = BT_LARA_MAX_AIR; m_AirBar.value = LARA_MAX_AIR; @@ -164,7 +165,7 @@ static void Overlay_BarSetupAir(void) m_AirBar.location = g_Config.airbar_location; } -static void Overlay_BarSetupEnemy(void) +static void M_BarSetupEnemy(void) { m_EnemyBar.type = BT_ENEMY_HEALTH; m_EnemyBar.value = 0; @@ -177,12 +178,12 @@ static void Overlay_BarSetupEnemy(void) m_EnemyBar.location = g_Config.enemy_healthbar_location; } -static int32_t Overlay_BarGetPercent(BAR_INFO *bar_info) +static int32_t M_BarGetPercent(BAR_INFO *bar_info) { return bar_info->value * 100 / bar_info->max_value; } -static void Overlay_BarBlink(BAR_INFO *bar_info) +static void M_BarBlink(BAR_INFO *bar_info) { if (bar_info->show_mode == BSM_PS1 || bar_info->type == BT_ENEMY_HEALTH || bar_info->type == BT_PROGRESS) { @@ -190,7 +191,7 @@ static void Overlay_BarBlink(BAR_INFO *bar_info) return; } - const int32_t percent = Overlay_BarGetPercent(bar_info); + const int32_t percent = M_BarGetPercent(bar_info); if (percent > BLINK_THRESHOLD) { bar_info->blink = false; return; @@ -201,7 +202,7 @@ static void Overlay_BarBlink(BAR_INFO *bar_info) } } -static void Overlay_BarGetLocation( +static void M_BarGetLocation( BAR_INFO *bar_info, int32_t *width, int32_t *height, int32_t *x, int32_t *y) { const int32_t screen_margin_h = 25; @@ -258,7 +259,7 @@ void Overlay_BarDraw(BAR_INFO *bar_info, RENDER_SCALE_REF scale_ref) int32_t x = 0; int32_t y = 0; - Overlay_BarGetLocation(bar_info, &width, &height, &x, &y); + M_BarGetLocation(bar_info, &width, &height, &x, &y); int32_t padding = Screen_GetRenderScale(2, scale_ref); int32_t border = Screen_GetRenderScale(2, scale_ref); @@ -275,10 +276,10 @@ void Overlay_BarDraw(BAR_INFO *bar_info, RENDER_SCALE_REF scale_ref) // background Output_DrawScreenFlatQuad(sx, sy, sw, sh, rgb_bgnd); - int32_t percent = Overlay_BarGetPercent(bar_info); + int32_t percent = M_BarGetPercent(bar_info); // Check if bar should flash or not - Overlay_BarBlink(bar_info); + M_BarBlink(bar_info); if (percent && !bar_info->blink) { width = width * percent / 100; @@ -307,7 +308,7 @@ void Overlay_BarDraw(BAR_INFO *bar_info, RENDER_SCALE_REF scale_ref) } } -static float Overlay_Ease(int32_t cur_frame, int32_t max_frames) +static float M_Ease(int32_t cur_frame, int32_t max_frames) { float ratio = cur_frame / (float)max_frames; if (ratio < 0.5f) { @@ -317,7 +318,7 @@ static float Overlay_Ease(int32_t cur_frame, int32_t max_frames) return 1.0f - 2.0f * new_ratio * new_ratio; } -static void Overlay_DrawPickup3D(DISPLAY_PICKUP_INFO *pu) +static void M_DrawPickup3D(DISPLAY_PICKUP_INFO *pu) { int32_t screen_width = Screen_GetResWidth(); int32_t screen_height = Screen_GetResHeight(); @@ -342,10 +343,10 @@ static void Overlay_DrawPickup3D(DISPLAY_PICKUP_INFO *pu) float ease = 1.0f; switch (pu->phase) { case DPP_EASE_IN: - ease = Overlay_Ease(pu->duration, MAX_PICKUP_DURATION_EASE_IN); + ease = M_Ease(pu->duration, MAX_PICKUP_DURATION_EASE_IN); break; case DPP_EASE_OUT: - ease = Overlay_Ease( + ease = M_Ease( MAX_PICKUP_DURATION_EASE_OUT - pu->duration, MAX_PICKUP_DURATION_EASE_OUT); break; @@ -418,7 +419,7 @@ static void Overlay_DrawPickup3D(DISPLAY_PICKUP_INFO *pu) Viewport_SetFOV(old_fov); } -static void Overlay_DrawPickups3D(void) +static void M_DrawPickups3D(void) { const double ticks = Clock_GetElapsedLogicalFrames(&m_PickupsTimer); @@ -456,11 +457,11 @@ static void Overlay_DrawPickups3D(void) pu->rot_y += 4 * PHD_DEGREE * ticks; - Overlay_DrawPickup3D(pu); + M_DrawPickup3D(pu); } } -static void Overlay_DrawPickupsSprites(void) +static void M_DrawPickupsSprites(void) { const double ticks = Clock_GetElapsedLogicalFrames(&m_PickupsTimer); @@ -490,16 +491,16 @@ static void Overlay_DrawPickupsSprites(void) } } -static void Overlay_DrawPickups(void) +static void M_DrawPickups(void) { if (g_Config.enable_3d_pickups) { - Overlay_DrawPickups3D(); + M_DrawPickups3D(); } else { - Overlay_DrawPickupsSprites(); + M_DrawPickupsSprites(); } } -static void Overlay_BarDrawAir(void) +static void M_BarDrawAir(void) { m_AirBar.value = g_Lara.air; CLAMP(m_AirBar.value, 0, m_AirBar.max_value); @@ -533,7 +534,7 @@ static void Overlay_BarDrawAir(void) Overlay_BarDraw(&m_AirBar, RSR_BAR); } -static void Overlay_BarDrawEnemy(void) +static void M_BarDrawEnemy(void) { if (!g_Lara.target) { return; @@ -569,14 +570,14 @@ static void Overlay_BarDrawEnemy(void) Overlay_BarDraw(&m_EnemyBar, RSR_BAR); } -static void Overlay_ResetBarLocations(void) +static void M_ResetBarLocations(void) { for (int i = 0; i < 6; i++) { m_BarOffsetY[i] = 0; } } -static void Overlay_RemoveAmmoText(void) +static void M_RemoveAmmoText(void) { if (m_AmmoText) { Text_Remove(m_AmmoText); @@ -584,7 +585,7 @@ static void Overlay_RemoveAmmoText(void) } } -static void Overlay_DrawAmmoInfo(void) +static void M_DrawAmmoInfo(void) { const double scale = 1.5; const int32_t text_height = 17 * scale; @@ -598,7 +599,7 @@ static void Overlay_DrawAmmoInfo(void) if (g_Lara.gun_status != LGS_READY || (g_GameInfo.bonus_flag & GBF_NGPLUS)) { - Overlay_RemoveAmmoText(); + M_RemoveAmmoText(); return; } @@ -650,9 +651,9 @@ void Overlay_Init(void) m_Pickups[i].phase = DPP_DEAD; } - Overlay_BarSetupHealth(); - Overlay_BarSetupAir(); - Overlay_BarSetupEnemy(); + M_BarSetupHealth(); + M_BarSetupAir(); + M_BarSetupEnemy(); } void Overlay_BarSetHealthTimer(int16_t timer) @@ -707,18 +708,18 @@ void Overlay_BarDrawHealth(void) void Overlay_HideGameInfo(void) { - Overlay_ResetBarLocations(); - Overlay_RemoveAmmoText(); + M_ResetBarLocations(); + M_RemoveAmmoText(); } void Overlay_DrawGameInfo(void) { - Overlay_ResetBarLocations(); + M_ResetBarLocations(); Overlay_BarDrawHealth(); - Overlay_BarDrawAir(); - Overlay_BarDrawEnemy(); - Overlay_DrawPickups(); - Overlay_DrawAmmoInfo(); + M_BarDrawAir(); + M_BarDrawEnemy(); + M_DrawPickups(); + M_DrawAmmoInfo(); } void Overlay_DrawFPSInfo(void) diff --git a/src/game/packer.c b/src/game/packer.c index 5e0a776dd..e960cc019 100644 --- a/src/game/packer.c +++ b/src/game/packer.c @@ -46,27 +46,27 @@ typedef struct TEX_PAGE { RGBA_8888 data[PAGE_SIZE]; } TEX_PAGE; -static void Packer_AllocateNewPage(void); -static void Packer_FillVirtualData(TEX_PAGE *page, RECTANGLE *bounds); -static void Packer_Cleanup(void); - -static RECTANGLE_COMPARISON Packer_Compare(RECTANGLE *r1, RECTANGLE *r2); -static void Packer_EnqueueTexInfo(TEX_INFO *info); -static RECTANGLE *Packer_GetObjectBounds(PHD_TEXTURE *texture); -static RECTANGLE *Packer_GetSpriteBounds(PHD_SPRITE *texture); -static void Packer_PrepareObject(int object_index); -static void Packer_PrepareSprite(int sprite_index); - -static void Packer_MoveObject( +static void M_AllocateNewPage(void); +static void M_FillVirtualData(TEX_PAGE *page, RECTANGLE *bounds); +static void M_Cleanup(void); + +static RECTANGLE_COMPARISON M_Compare(RECTANGLE *r1, RECTANGLE *r2); +static void M_EnqueueTexInfo(TEX_INFO *info); +static RECTANGLE *M_GetObjectBounds(PHD_TEXTURE *texture); +static RECTANGLE *M_GetSpriteBounds(PHD_SPRITE *texture); +static void M_PrepareObject(int object_index); +static void M_PrepareSprite(int sprite_index); + +static void M_MoveObject( int index, RECTANGLE *old_bounds, uint16_t tpage, uint16_t new_x, uint16_t new_y); -static void Packer_MoveSprite( +static void M_MoveSprite( int index, RECTANGLE *old_bounds, uint16_t tpage, uint16_t new_x, uint16_t new_y); -static bool Packer_PackContainerAt( +static bool M_PackContainerAt( TEX_CONTAINER *container, TEX_PAGE *page, int x_pos, int y_pos); -static bool Packer_PackContainer(TEX_CONTAINER *container); +static bool M_PackContainer(TEX_CONTAINER *container); static PACKER_DATA *m_Data = NULL; static int32_t m_StartPage = 0; @@ -85,26 +85,26 @@ bool Packer_Pack(PACKER_DATA *data) m_UsedPageCount = 0; m_QueueSize = 0; - Packer_AllocateNewPage(); + M_AllocateNewPage(); for (int i = 0; i < data->object_count; i++) { - Packer_PrepareObject(i); + M_PrepareObject(i); } for (int i = 0; i < data->sprite_count; i++) { - Packer_PrepareSprite(i); + M_PrepareSprite(i); } bool result = true; for (int i = 0; i < m_QueueSize; i++) { TEX_CONTAINER *container = &m_Queue[i]; - if (!Packer_PackContainer(container)) { + if (!M_PackContainer(container)) { LOG_ERROR("Failed to pack container %d of %d", i, m_QueueSize); result = false; break; } } - Packer_Cleanup(); + M_Cleanup(); return result; } @@ -113,42 +113,42 @@ int32_t Packer_GetAddedPageCount(void) return m_UsedPageCount - 1; } -static void Packer_PrepareObject(int object_index) +static void M_PrepareObject(int object_index) { PHD_TEXTURE *object_texture = &g_PhdTextureInfo[object_index]; if (object_texture->tpage == m_StartPage) { - RECTANGLE *bounds = Packer_GetObjectBounds(object_texture); - Packer_FillVirtualData(m_VirtualPages, bounds); + RECTANGLE *bounds = M_GetObjectBounds(object_texture); + M_FillVirtualData(m_VirtualPages, bounds); Memory_FreePointer(&bounds); } else if (object_texture->tpage > m_StartPage) { TEX_INFO *info = Memory_Alloc(sizeof(TEX_INFO)); info->index = object_index; info->tpage = object_texture->tpage; - info->bounds = Packer_GetObjectBounds(object_texture); - info->move = Packer_MoveObject; - Packer_EnqueueTexInfo(info); + info->bounds = M_GetObjectBounds(object_texture); + info->move = M_MoveObject; + M_EnqueueTexInfo(info); } } -static void Packer_PrepareSprite(int sprite_index) +static void M_PrepareSprite(int sprite_index) { PHD_SPRITE *sprite_texture = &g_PhdSpriteInfo[sprite_index]; if (sprite_texture->tpage == m_StartPage) { - RECTANGLE *bounds = Packer_GetSpriteBounds(sprite_texture); - Packer_FillVirtualData(m_VirtualPages, bounds); + RECTANGLE *bounds = M_GetSpriteBounds(sprite_texture); + M_FillVirtualData(m_VirtualPages, bounds); Memory_FreePointer(&bounds); } else if (sprite_texture->tpage > m_StartPage) { TEX_INFO *info = Memory_Alloc(sizeof(TEX_INFO)); info->index = sprite_index; info->tpage = sprite_texture->tpage; - info->bounds = Packer_GetSpriteBounds(sprite_texture); - info->move = Packer_MoveSprite; - Packer_EnqueueTexInfo(info); + info->bounds = M_GetSpriteBounds(sprite_texture); + info->move = M_MoveSprite; + M_EnqueueTexInfo(info); } } -static void Packer_FillVirtualData(TEX_PAGE *page, RECTANGLE *bounds) +static void M_FillVirtualData(TEX_PAGE *page, RECTANGLE *bounds) { int y_end = bounds->y + bounds->h; int x_end = bounds->x + bounds->w; @@ -164,7 +164,7 @@ static void Packer_FillVirtualData(TEX_PAGE *page, RECTANGLE *bounds) page->free_space -= bounds->w * bounds->h; } -static void Packer_EnqueueTexInfo(TEX_INFO *info) +static void M_EnqueueTexInfo(TEX_INFO *info) { // This may be a child of another, so try to find its // parent first and add it there. @@ -176,7 +176,7 @@ static void Packer_EnqueueTexInfo(TEX_INFO *info) } RECTANGLE_COMPARISON comparison = - Packer_Compare(container->bounds, info->bounds); + M_Compare(container->bounds, info->bounds); if (comparison == RC_UNRELATED) { continue; } @@ -203,7 +203,7 @@ static void Packer_EnqueueTexInfo(TEX_INFO *info) new_container->tex_infos = info; } -static RECTANGLE *Packer_GetObjectBounds(PHD_TEXTURE *texture) +static RECTANGLE *M_GetObjectBounds(PHD_TEXTURE *texture) { RECTANGLE *rectangle = Memory_Alloc(sizeof(RECTANGLE)); @@ -232,7 +232,7 @@ static RECTANGLE *Packer_GetObjectBounds(PHD_TEXTURE *texture) return rectangle; } -static RECTANGLE *Packer_GetSpriteBounds(PHD_SPRITE *texture) +static RECTANGLE *M_GetSpriteBounds(PHD_SPRITE *texture) { RECTANGLE *rectangle = Memory_Alloc(sizeof(RECTANGLE)); @@ -244,7 +244,7 @@ static RECTANGLE *Packer_GetSpriteBounds(PHD_SPRITE *texture) return rectangle; } -static bool Packer_PackContainer(TEX_CONTAINER *container) +static bool M_PackContainer(TEX_CONTAINER *container) { int size = container->bounds->w * container->bounds->h; if (size > PAGE_SIZE) { @@ -255,7 +255,7 @@ static bool Packer_PackContainer(TEX_CONTAINER *container) int y, x, y_end, x_end; for (int i = 0; i < m_EndPage; i++) { if (i == m_UsedPageCount) { - Packer_AllocateNewPage(); + M_AllocateNewPage(); } TEX_PAGE *page = &m_VirtualPages[i]; @@ -267,7 +267,7 @@ static bool Packer_PackContainer(TEX_CONTAINER *container) x_end = PAGE_WIDTH - container->bounds->w; for (y = 0; y <= y_end; y++) { for (x = 0; x <= x_end; x++) { - if (Packer_PackContainerAt(container, page, x, y)) { + if (M_PackContainerAt(container, page, x, y)) { return true; } } @@ -278,7 +278,7 @@ static bool Packer_PackContainer(TEX_CONTAINER *container) return false; } -static void Packer_AllocateNewPage(void) +static void M_AllocateNewPage(void) { m_VirtualPages = Memory_Realloc( m_VirtualPages, sizeof(TEX_PAGE) * (m_UsedPageCount + 1)); @@ -299,7 +299,7 @@ static void Packer_AllocateNewPage(void) m_UsedPageCount++; } -static bool Packer_PackContainerAt( +static bool M_PackContainerAt( TEX_CONTAINER *container, TEX_PAGE *page, int x_pos, int y_pos) { int y_end = y_pos + container->bounds->h; @@ -349,7 +349,7 @@ static bool Packer_PackContainerAt( return true; } -static void Packer_MoveObject( +static void M_MoveObject( int index, RECTANGLE *old_bounds, uint16_t tpage, uint16_t new_x, uint16_t new_y) { @@ -371,7 +371,7 @@ static void Packer_MoveObject( } } -static void Packer_MoveSprite( +static void M_MoveSprite( int index, RECTANGLE *old_bounds, uint16_t tpage, uint16_t new_x, uint16_t new_y) { @@ -380,7 +380,7 @@ static void Packer_MoveSprite( texture->offset = (new_y << 8) | new_x; } -static RECTANGLE_COMPARISON Packer_Compare(RECTANGLE *r1, RECTANGLE *r2) +static RECTANGLE_COMPARISON M_Compare(RECTANGLE *r1, RECTANGLE *r2) { if (r1->x == r2->x && r1->w == r2->w && r1->y == r2->y && r1->h == r2->h) { return RC_EQUALS; @@ -399,7 +399,7 @@ static RECTANGLE_COMPARISON Packer_Compare(RECTANGLE *r1, RECTANGLE *r2) return RC_UNRELATED; } -static void Packer_Cleanup(void) +static void M_Cleanup(void) { for (int i = 0; i < m_QueueSize; i++) { TEX_CONTAINER *container = &m_Queue[i]; diff --git a/src/game/phase/phase.c b/src/game/phase/phase.c index 7b983ae3a..5edce5f4c 100644 --- a/src/game/phase/phase.c +++ b/src/game/phase/phase.c @@ -25,12 +25,12 @@ static bool m_Running = false; static PHASE m_PhaseToSet = PHASE_NULL; static void *m_PhaseToSetArg = NULL; -static PHASE_CONTROL Phase_Control(int32_t nframes); -static void Phase_Draw(void); -static int32_t Phase_Wait(void); -static void Phase_SetUnconditionally(const PHASE phase, void *arg); +static PHASE_CONTROL M_Control(int32_t nframes); +static void M_Draw(void); +static int32_t M_Wait(void); +static void M_SetUnconditionally(const PHASE phase, void *arg); -static PHASE_CONTROL Phase_Control(int32_t nframes) +static PHASE_CONTROL M_Control(int32_t nframes) { if (g_GameInfo.override_gf_command.action != GF_CONTINUE_SEQUENCE) { const GAMEFLOW_COMMAND override = g_GameInfo.override_gf_command; @@ -45,7 +45,7 @@ static PHASE_CONTROL Phase_Control(int32_t nframes) return (PHASE_CONTROL) { .end = false }; } -static void Phase_Draw(void) +static void M_Draw(void) { Output_BeginScene(); if (m_Phaser && m_Phaser->draw) { @@ -54,7 +54,7 @@ static void Phase_Draw(void) Output_EndScene(); } -static void Phase_SetUnconditionally(const PHASE phase, void *arg) +static void M_SetUnconditionally(const PHASE phase, void *arg) { if (m_Phaser && m_Phaser->end) { m_Phaser->end(); @@ -119,10 +119,10 @@ void Phase_Set(const PHASE phase, void *arg) m_PhaseToSetArg = arg; return; } - Phase_SetUnconditionally(phase, arg); + M_SetUnconditionally(phase, arg); } -static int32_t Phase_Wait(void) +static int32_t M_Wait(void) { if (m_Phaser && m_Phaser->wait) { return m_Phaser->wait(); @@ -140,17 +140,17 @@ GAMEFLOW_COMMAND Phase_Run(void) LOG_DEBUG("phase start, phase=%d", m_Phase); while (1) { - control = Phase_Control(nframes); + control = M_Control(nframes); if (m_PhaseToSet != PHASE_NULL) { Interpolation_SetRate(1.0); - Phase_Draw(); + M_Draw(); - Phase_SetUnconditionally(m_PhaseToSet, m_PhaseToSetArg); + M_SetUnconditionally(m_PhaseToSet, m_PhaseToSetArg); m_PhaseToSet = PHASE_NULL; m_PhaseToSetArg = NULL; if (control.end) { - Phase_Draw(); + M_Draw(); break; } nframes = 2; @@ -159,19 +159,19 @@ GAMEFLOW_COMMAND Phase_Run(void) } if (control.end) { - Phase_Draw(); + M_Draw(); break; } if (Interpolation_IsEnabled()) { Interpolation_SetRate(0.5); - Phase_Draw(); - Phase_Wait(); + M_Draw(); + M_Wait(); } Interpolation_SetRate(1.0); - Phase_Draw(); - nframes = Phase_Wait(); + M_Draw(); + nframes = M_Wait(); } m_Running = false; diff --git a/src/game/phase/phase_cutscene.c b/src/game/phase/phase_cutscene.c index 4d152ecda..46d38dd86 100644 --- a/src/game/phase/phase_cutscene.c +++ b/src/game/phase/phase_cutscene.c @@ -22,14 +22,14 @@ #include #include -static void Phase_Cutscene_InitialiseHair(int32_t level_num); +static void M_InitialiseHair(int32_t level_num); -static void Phase_Cutscene_Start(void *arg); -static void Phase_Cutscene_End(void); -static PHASE_CONTROL Phase_Cutscene_Control(int32_t nframes); -static void Phase_Cutscene_Draw(void); +static void M_Start(void *arg); +static void M_End(void); +static PHASE_CONTROL M_Control(int32_t nframes); +static void M_Draw(void); -static void Phase_Cutscene_InitialiseHair(int32_t level_num) +static void M_InitialiseHair(int32_t level_num) { const GAME_OBJECT_ID lara_type = g_GameFlow.levels[level_num].lara_type; Lara_Hair_SetLaraType(lara_type); @@ -62,7 +62,7 @@ static void Phase_Cutscene_InitialiseHair(int32_t level_num) g_LaraItem->required_anim_state = cut_anim->current_anim_state; } -static void Phase_Cutscene_Start(void *arg) +static void M_Start(void *arg) { Output_FadeReset(); @@ -71,7 +71,7 @@ static void Phase_Cutscene_Start(void *arg) return; } - Phase_Cutscene_InitialiseHair(data->level_num); + M_InitialiseHair(data->level_num); for (int16_t room_num = 0; room_num < g_RoomCount; room_num++) { if (g_RoomInfo[room_num].flipped_room >= 0) { @@ -91,13 +91,13 @@ static void Phase_Cutscene_Start(void *arg) g_CineFrame = 0; } -static void Phase_Cutscene_End(void) +static void M_End(void) { Music_Stop(); Sound_StopAllSamples(); } -static PHASE_CONTROL Phase_Cutscene_Control(int32_t nframes) +static PHASE_CONTROL M_Control(int32_t nframes) { Interpolation_Remember(); @@ -139,7 +139,7 @@ static PHASE_CONTROL Phase_Cutscene_Control(int32_t nframes) return (PHASE_CONTROL) { .end = false }; } -static void Phase_Cutscene_Draw(void) +static void M_Draw(void) { Game_DrawScene(true); Output_AnimateTextures(); @@ -147,9 +147,9 @@ static void Phase_Cutscene_Draw(void) } PHASER g_CutscenePhaser = { - .start = Phase_Cutscene_Start, - .end = Phase_Cutscene_End, - .control = Phase_Cutscene_Control, - .draw = Phase_Cutscene_Draw, + .start = M_Start, + .end = M_End, + .control = M_Control, + .draw = M_Draw, .wait = NULL, }; diff --git a/src/game/phase/phase_demo.c b/src/game/phase/phase_demo.c index 4d3bdd884..5ac9d7eb8 100644 --- a/src/game/phase/phase_demo.c +++ b/src/game/phase/phase_demo.c @@ -51,17 +51,17 @@ static INPUT_STATE m_OldInput = { 0 }; static int32_t m_DemoLevel = -1; static uint32_t *m_DemoPtr = NULL; -static bool Phase_Demo_ProcessInput(void); -static int32_t Phase_Demo_ChooseLevel(void); +static bool M_ProcessInput(void); +static int32_t M_ChooseLevel(void); -static void Phase_Demo_Start(void *arg); -static void Phase_Demo_End(void); -static PHASE_CONTROL Phase_Demo_Run(int32_t nframes); -static PHASE_CONTROL Phase_Demo_FadeOut(void); -static PHASE_CONTROL Phase_Demo_Control(int32_t nframes); -static void Phase_Demo_Draw(void); +static void M_Start(void *arg); +static void M_End(void); +static PHASE_CONTROL M_Run(int32_t nframes); +static PHASE_CONTROL M_FadeOut(void); +static PHASE_CONTROL M_Control(int32_t nframes); +static void M_Draw(void); -static bool Phase_Demo_ProcessInput(void) +static bool M_ProcessInput(void) { if (m_DemoPtr >= &g_DemoData[DEMO_COUNT_MAX] || (int)*m_DemoPtr == -1) { return false; @@ -93,7 +93,7 @@ static bool Phase_Demo_ProcessInput(void) return true; } -static int32_t Phase_Demo_ChooseLevel(void) +static int32_t M_ChooseLevel(void) { bool any_demos = false; for (int i = g_GameFlow.first_level_num; i < g_GameFlow.last_level_num; @@ -116,9 +116,9 @@ static int32_t Phase_Demo_ChooseLevel(void) return level_num; } -static void Phase_Demo_Start(void *arg) +static void M_Start(void *arg) { - m_DemoLevel = Phase_Demo_ChooseLevel(); + m_DemoLevel = M_ChooseLevel(); if (m_DemoLevel == -1) { m_State = STATE_INVALID; @@ -204,7 +204,7 @@ static void Phase_Demo_Start(void *arg) g_GameInfo.current_level_type = GFL_DEMO; } -static void Phase_Demo_End(void) +static void M_End(void) { if (m_DemoLevel == -1) { return; @@ -221,7 +221,7 @@ static void Phase_Demo_End(void) g_Config.fix_bear_ai = m_oldFixBearAI; } -static PHASE_CONTROL Phase_Demo_Run(int32_t nframes) +static PHASE_CONTROL M_Run(int32_t nframes) { Interpolation_Remember(); CLAMPG(nframes, MAX_FRAMES); @@ -233,7 +233,7 @@ static PHASE_CONTROL Phase_Demo_Run(int32_t nframes) goto end; } - if (!Phase_Demo_ProcessInput()) { + if (!M_ProcessInput()) { m_State = STATE_FADE_OUT; goto end; } @@ -265,7 +265,7 @@ static PHASE_CONTROL Phase_Demo_Run(int32_t nframes) return (PHASE_CONTROL) { .end = false }; } -static PHASE_CONTROL Phase_Demo_FadeOut(void) +static PHASE_CONTROL M_FadeOut(void) { Text_Flash(m_DemoModeText, 0, 0); Input_Update(); @@ -281,7 +281,7 @@ static PHASE_CONTROL Phase_Demo_FadeOut(void) return (PHASE_CONTROL) { .end = false }; } -static PHASE_CONTROL Phase_Demo_Control(int32_t nframes) +static PHASE_CONTROL M_Control(int32_t nframes) { switch (m_State) { case STATE_INVALID: @@ -291,10 +291,10 @@ static PHASE_CONTROL Phase_Demo_Control(int32_t nframes) }; case STATE_RUN: - return Phase_Demo_Run(nframes); + return M_Run(nframes); case STATE_FADE_OUT: - return Phase_Demo_FadeOut(); + return M_FadeOut(); } assert(false); @@ -304,7 +304,7 @@ static PHASE_CONTROL Phase_Demo_Control(int32_t nframes) }; } -static void Phase_Demo_Draw(void) +static void M_Draw(void) { if (m_State == STATE_FADE_OUT) { Interpolation_Disable(); @@ -320,9 +320,9 @@ static void Phase_Demo_Draw(void) } PHASER g_DemoPhaser = { - .start = Phase_Demo_Start, - .end = Phase_Demo_End, - .control = Phase_Demo_Control, - .draw = Phase_Demo_Draw, + .start = M_Start, + .end = M_End, + .control = M_Control, + .draw = M_Draw, .wait = NULL, }; diff --git a/src/game/phase/phase_game.c b/src/game/phase/phase_game.c index 719bfc91c..fa61b40c3 100644 --- a/src/game/phase/phase_game.c +++ b/src/game/phase/phase_game.c @@ -26,12 +26,12 @@ #include #include -static void Phase_Game_Start(void *arg); -static void Phase_Game_End(void); -static PHASE_CONTROL Phase_Game_Control(int32_t nframes); -static void Phase_Game_Draw(void); +static void M_Start(void *arg); +static void M_End(void); +static PHASE_CONTROL M_Control(int32_t nframes); +static void M_Draw(void); -static void Phase_Game_Start(void *arg) +static void M_Start(void *arg) { Interpolation_Remember(); Stats_StartTimer(); @@ -40,11 +40,11 @@ static void Phase_Game_Start(void *arg) } } -static void Phase_Game_End(void) +static void M_End(void) { } -static PHASE_CONTROL Phase_Game_Control(int32_t nframes) +static PHASE_CONTROL M_Control(int32_t nframes) { Interpolation_Remember(); Stats_UpdateTimer(); @@ -129,7 +129,7 @@ static PHASE_CONTROL Phase_Game_Control(int32_t nframes) return (PHASE_CONTROL) { .end = false }; } -static void Phase_Game_Draw(void) +static void M_Draw(void) { Game_DrawScene(true); Output_AnimateTextures(); @@ -138,9 +138,9 @@ static void Phase_Game_Draw(void) } PHASER g_GamePhaser = { - .start = Phase_Game_Start, - .end = Phase_Game_End, - .control = Phase_Game_Control, - .draw = Phase_Game_Draw, + .start = M_Start, + .end = M_End, + .control = M_Control, + .draw = M_Draw, .wait = NULL, }; diff --git a/src/game/phase/phase_inventory.c b/src/game/phase/phase_inventory.c index 1b563c7c8..b1ba906ba 100644 --- a/src/game/phase/phase_inventory.c +++ b/src/game/phase/phase_inventory.c @@ -70,11 +70,11 @@ static int32_t InvItem_GetFrames( static void Inv_DrawItem(INVENTORY_ITEM *inv_item, int32_t frames); static bool Inv_CheckDemoTimer(const IMOTION_INFO *motion); -static void Phase_Inventory_Start(void *arg); -static void Phase_Inventory_End(void); -static PHASE_CONTROL Phase_Inventory_ControlFrame(void); -static PHASE_CONTROL Phase_Inventory_Control(int32_t nframes); -static void Phase_Inventory_Draw(void); +static void M_Start(void *arg); +static void M_End(void); +static PHASE_CONTROL M_ControlFrame(void); +static PHASE_CONTROL M_Control(int32_t nframes); +static void M_Draw(void); static void Inv_Draw(RING_INFO *ring, IMOTION_INFO *motion) { @@ -579,7 +579,7 @@ static bool Inv_CheckDemoTimer(const IMOTION_INFO *const motion) &m_DemoTimer, g_GameFlow.demo_delay * 1000.0); } -static void Phase_Inventory_Start(void *arg) +static void M_Start(void *arg) { Interpolation_Remember(); if (g_Config.enable_timer_in_inventory) { @@ -650,7 +650,7 @@ static void Phase_Inventory_Start(void *arg) } } -static PHASE_CONTROL Phase_Inventory_ControlFrame(void) +static PHASE_CONTROL M_ControlFrame(void) { RING_INFO *ring = &m_Ring; IMOTION_INFO *motion = &m_Motion; @@ -1095,14 +1095,14 @@ static PHASE_CONTROL Phase_Inventory_ControlFrame(void) return (PHASE_CONTROL) { .end = false }; } -static PHASE_CONTROL Phase_Inventory_Control(int32_t nframes) +static PHASE_CONTROL M_Control(int32_t nframes) { Interpolation_Remember(); if (g_Config.enable_timer_in_inventory) { Stats_UpdateTimer(); } for (int32_t i = 0; i < nframes; i++) { - const PHASE_CONTROL result = Phase_Inventory_ControlFrame(); + const PHASE_CONTROL result = M_ControlFrame(); if (result.end) { return result; } @@ -1111,7 +1111,7 @@ static PHASE_CONTROL Phase_Inventory_Control(int32_t nframes) return (PHASE_CONTROL) { .end = false }; } -static void Phase_Inventory_End(void) +static void M_End(void) { INVENTORY_ITEM *const inv_item = m_Ring.list[m_Ring.current_object]; if (inv_item != NULL) { @@ -1128,7 +1128,7 @@ static void Phase_Inventory_End(void) } } -static void Phase_Inventory_Draw(void) +static void M_Draw(void) { RING_INFO *ring = &m_Ring; IMOTION_INFO *motion = &m_Motion; @@ -1138,9 +1138,9 @@ static void Phase_Inventory_Draw(void) } PHASER g_InventoryPhaser = { - .start = Phase_Inventory_Start, - .end = Phase_Inventory_End, - .control = Phase_Inventory_Control, - .draw = Phase_Inventory_Draw, + .start = M_Start, + .end = M_End, + .control = M_Control, + .draw = M_Draw, .wait = NULL, }; diff --git a/src/game/phase/phase_pause.c b/src/game/phase/phase_pause.c index d1476fd0a..40d046cc9 100644 --- a/src/game/phase/phase_pause.c +++ b/src/game/phase/phase_pause.c @@ -50,23 +50,23 @@ static REQUEST_INFO m_PauseRequester = { .items = NULL, }; -static void Phase_Pause_RemoveText(void); -static void Phase_Pause_UpdateText(void); -static int32_t Phase_Pause_DisplayRequester( +static void M_RemoveText(void); +static void M_UpdateText(void); +static int32_t M_DisplayRequester( const char *header, const char *option1, const char *option2, int16_t requested); -static void Phase_Pause_Start(void *arg); -static void Phase_Pause_End(void); -static PHASE_CONTROL Phase_Pause_Control(int32_t nframes); -static void Phase_Pause_Draw(void); +static void M_Start(void *arg); +static void M_End(void); +static PHASE_CONTROL M_Control(int32_t nframes); +static void M_Draw(void); -static void Phase_Pause_RemoveText(void) +static void M_RemoveText(void) { Text_Remove(m_PausedText); m_PausedText = NULL; } -static void Phase_Pause_UpdateText(void) +static void M_UpdateText(void) { if (m_PausedText == NULL) { m_PausedText = Text_Create(0, -24, GS(PAUSE_PAUSED)); @@ -75,7 +75,7 @@ static void Phase_Pause_UpdateText(void) } } -static int32_t Phase_Pause_DisplayRequester( +static int32_t M_DisplayRequester( const char *header, const char *option1, const char *option2, int16_t requested) { @@ -108,7 +108,7 @@ static int32_t Phase_Pause_DisplayRequester( return select; } -static void Phase_Pause_Start(void *arg) +static void M_Start(void *arg) { g_OldInputDB = g_Input; @@ -124,17 +124,17 @@ static void Phase_Pause_Start(void *arg) m_PauseState = STATE_DEFAULT; } -static void Phase_Pause_End(void) +static void M_End(void) { Output_FadeToTransparent(true); - Phase_Pause_RemoveText(); + M_RemoveText(); Requester_Shutdown(&m_PauseRequester); } -static PHASE_CONTROL Phase_Pause_Control(int32_t nframes) +static PHASE_CONTROL M_Control(int32_t nframes) { - Phase_Pause_UpdateText(); + M_UpdateText(); Input_Update(); Shell_ProcessInput(); @@ -152,7 +152,7 @@ static PHASE_CONTROL Phase_Pause_Control(int32_t nframes) break; case STATE_ASK: { - int32_t choice = Phase_Pause_DisplayRequester( + int32_t choice = M_DisplayRequester( GS(PAUSE_EXIT_TO_TITLE), GS(PAUSE_CONTINUE), GS(PAUSE_QUIT), 1); if (choice == 1) { Music_Unpause(); @@ -165,7 +165,7 @@ static PHASE_CONTROL Phase_Pause_Control(int32_t nframes) } case STATE_CONFIRM: { - int32_t choice = Phase_Pause_DisplayRequester( + int32_t choice = M_DisplayRequester( GS(PAUSE_ARE_YOU_SURE), GS(PAUSE_YES), GS(PAUSE_NO), 1); if (choice == 1) { return (PHASE_CONTROL) { @@ -184,7 +184,7 @@ static PHASE_CONTROL Phase_Pause_Control(int32_t nframes) return (PHASE_CONTROL) { .end = false }; } -static void Phase_Pause_Draw(void) +static void M_Draw(void) { Interpolation_Disable(); Game_DrawScene(false); @@ -194,9 +194,9 @@ static void Phase_Pause_Draw(void) } PHASER g_PausePhaser = { - .start = Phase_Pause_Start, - .end = Phase_Pause_End, - .control = Phase_Pause_Control, - .draw = Phase_Pause_Draw, + .start = M_Start, + .end = M_End, + .control = M_Control, + .draw = M_Draw, .wait = NULL, }; diff --git a/src/game/phase/phase_picture.c b/src/game/phase/phase_picture.c index 48f745ebe..03dc0a899 100644 --- a/src/game/phase/phase_picture.c +++ b/src/game/phase/phase_picture.c @@ -20,12 +20,12 @@ static STATE m_State = STATE_FADE_IN; static double m_DisplayTime = 0.0; static CLOCK_TIMER m_DisplayTimer = { 0 }; -static void Phase_Picture_Start(void *arg); -static void Phase_Picture_End(void); -static PHASE_CONTROL Phase_Picture_Control(int32_t nframes); -static void Phase_Picture_Draw(void); +static void M_Start(void *arg); +static void M_End(void); +static PHASE_CONTROL M_Control(int32_t nframes); +static void M_Draw(void); -static void Phase_Picture_Start(void *arg) +static void M_Start(void *arg) { const PHASE_PICTURE_DATA *data = (const PHASE_PICTURE_DATA *)arg; m_State = STATE_FADE_IN; @@ -36,11 +36,11 @@ static void Phase_Picture_Start(void *arg) Output_FadeToTransparent(true); } -static void Phase_Picture_End(void) +static void M_End(void) { } -static PHASE_CONTROL Phase_Picture_Control(int32_t nframes) +static PHASE_CONTROL M_Control(int32_t nframes) { Input_Update(); Shell_ProcessInput(); @@ -78,15 +78,15 @@ static PHASE_CONTROL Phase_Picture_Control(int32_t nframes) return (PHASE_CONTROL) { .end = false }; } -static void Phase_Picture_Draw(void) +static void M_Draw(void) { Output_AnimateFades(); } PHASER g_PicturePhaser = { - .start = Phase_Picture_Start, - .end = Phase_Picture_End, - .control = Phase_Picture_Control, - .draw = Phase_Picture_Draw, + .start = M_Start, + .end = M_End, + .control = M_Control, + .draw = M_Draw, .wait = NULL, }; diff --git a/src/game/phase/phase_stats.c b/src/game/phase/phase_stats.c index 7cf2eb257..cc355a8c2 100644 --- a/src/game/phase/phase_stats.c +++ b/src/game/phase/phase_stats.c @@ -34,13 +34,14 @@ static bool m_Total = false; static STATE m_State = STATE_DISPLAY; static TEXTSTRING *m_Texts[MAX_TEXTSTRINGS] = { 0 }; -static void Phase_Stats_CreateTexts(int32_t level_num); -static void Phase_Stats_Start(void *arg); -static void Phase_Stats_End(void); -static PHASE_CONTROL Phase_Stats_Control(int32_t nframes); -static void Phase_Stats_Draw(void); - -static void Phase_Stats_CreateTexts(int32_t level_num) +static void M_CreateTexts(int32_t level_num); +static void M_CreateTextsTotal(GAMEFLOW_LEVEL_TYPE level_type); +static void M_Start(void *arg); +static void M_End(void); +static PHASE_CONTROL M_Control(int32_t nframes); +static void M_Draw(void); + +static void M_CreateTexts(int32_t level_num) { char buf[100]; char time_str[100]; @@ -132,7 +133,7 @@ static void Phase_Stats_CreateTexts(int32_t level_num) y += row_height; } -static void Phase_Stats_CreateTextsTotal(GAMEFLOW_LEVEL_TYPE level_type) +static void M_CreateTextsTotal(GAMEFLOW_LEVEL_TYPE level_type) { TOTAL_STATS stats; Stats_ComputeTotal(level_type, &stats); @@ -235,7 +236,7 @@ static void Phase_Stats_CreateTextsTotal(GAMEFLOW_LEVEL_TYPE level_type) cur_txt++; } -static void Phase_Stats_Start(void *arg) +static void M_Start(void *arg) { const PHASE_STATS_DATA *data = (const PHASE_STATS_DATA *)arg; if (data && data->total) { @@ -255,18 +256,18 @@ static void Phase_Stats_Start(void *arg) m_Total = data && data->total; if (data && data->total) { - Phase_Stats_CreateTextsTotal(data->level_type); + M_CreateTextsTotal(data->level_type); Output_FadeReset(); Output_FadeResetToBlack(); Output_FadeToTransparent(true); } else { - Phase_Stats_CreateTexts( + M_CreateTexts( data && data->level_num != -1 ? data->level_num : g_CurrentLevel); Output_FadeToSemiBlack(true); } } -static void Phase_Stats_End(void) +static void M_End(void) { Music_Stop(); @@ -278,7 +279,7 @@ static void Phase_Stats_End(void) } } -static PHASE_CONTROL Phase_Stats_Control(int32_t nframes) +static PHASE_CONTROL M_Control(int32_t nframes) { Input_Update(); Shell_ProcessInput(); @@ -314,7 +315,7 @@ static PHASE_CONTROL Phase_Stats_Control(int32_t nframes) return (PHASE_CONTROL) { .end = false }; } -static void Phase_Stats_Draw(void) +static void M_Draw(void) { if (!m_Total) { Interpolation_Disable(); @@ -326,9 +327,9 @@ static void Phase_Stats_Draw(void) } PHASER g_StatsPhaser = { - .start = Phase_Stats_Start, - .end = Phase_Stats_End, - .control = Phase_Stats_Control, - .draw = Phase_Stats_Draw, + .start = M_Start, + .end = M_End, + .control = M_Control, + .draw = M_Draw, .wait = NULL, }; diff --git a/src/game/requester.c b/src/game/requester.c index f337b1827..10d500702 100644 --- a/src/game/requester.c +++ b/src/game/requester.c @@ -16,11 +16,11 @@ #define BOX_BORDER 2 #define BOX_PADDING 10 -static void Requester_SetItem( +static void M_SetItem( REQUEST_INFO *req, const int32_t idx, const bool is_blocked, const char *const fmt, va_list va); -static void Requester_SetItem( +static void M_SetItem( REQUEST_INFO *req, const int32_t idx, const bool is_blocked, const char *const fmt, va_list va) { @@ -228,7 +228,7 @@ void Requester_ChangeItem( va_list va; va_start(va, fmt); - Requester_SetItem(req, idx, is_blocked, fmt, va); + M_SetItem(req, idx, is_blocked, fmt, va); va_end(va); } @@ -241,7 +241,7 @@ void Requester_AddItem( va_list va; va_start(va, fmt); - Requester_SetItem(req, req->items_used, is_blocked, fmt, va); + M_SetItem(req, req->items_used, is_blocked, fmt, va); va_end(va); req->items_used++; } diff --git a/src/game/room.c b/src/game/room.c index 2a3c33e56..141a19f57 100644 --- a/src/game/room.c +++ b/src/game/room.c @@ -29,21 +29,21 @@ int32_t g_FlipEffect = -1; int32_t g_FlipStatus = 0; int32_t g_FlipMapTable[MAX_FLIP_MAPS] = { 0 }; -static void Room_TriggerMusicTrack(int16_t track, const TRIGGER *const trigger); -static void Room_AddFlipItems(ROOM_INFO *r); -static void Room_RemoveFlipItems(ROOM_INFO *r); +static void M_TriggerMusicTrack(int16_t track, const TRIGGER *const trigger); +static void M_AddFlipItems(ROOM_INFO *r); +static void M_RemoveFlipItems(ROOM_INFO *r); -static int16_t Room_GetFloorTiltHeight( +static int16_t M_GetFloorTiltHeight( const SECTOR_INFO *sector, const int32_t x, const int32_t z); -static int16_t Room_GetCeilingTiltHeight( +static int16_t M_GetCeilingTiltHeight( const SECTOR_INFO *sector, const int32_t x, const int32_t z); -static SECTOR_INFO *Room_GetSkySector( +static SECTOR_INFO *M_GetSkySector( const SECTOR_INFO *sector, int32_t x, int32_t z); -static void Room_TestSectorTrigger( +static void M_TestSectorTrigger( const ITEM_INFO *item, const SECTOR_INFO *sector); -static bool Room_TestLava(const ITEM_INFO *const item); +static bool M_TestLava(const ITEM_INFO *const item); -static void Room_TriggerMusicTrack(int16_t track, const TRIGGER *const trigger) +static void M_TriggerMusicTrack(int16_t track, const TRIGGER *const trigger) { if (track == MX_UNUSED_0 && trigger->type == TT_ANTIPAD) { Music_Stop(); @@ -125,7 +125,7 @@ static void Room_TriggerMusicTrack(int16_t track, const TRIGGER *const trigger) } } -static void Room_AddFlipItems(ROOM_INFO *r) +static void M_AddFlipItems(ROOM_INFO *r) { for (int16_t item_num = r->item_num; item_num != NO_ITEM; item_num = g_Items[item_num].next_item) { @@ -149,7 +149,7 @@ static void Room_AddFlipItems(ROOM_INFO *r) } } -static void Room_RemoveFlipItems(ROOM_INFO *r) +static void M_RemoveFlipItems(ROOM_INFO *r) { for (int16_t item_num = r->item_num; item_num != NO_ITEM; item_num = g_Items[item_num].next_item) { @@ -247,7 +247,7 @@ SECTOR_INFO *Room_GetPitSector( return (SECTOR_INFO *)sector; } -static SECTOR_INFO *Room_GetSkySector( +static SECTOR_INFO *M_GetSkySector( const SECTOR_INFO *sector, const int32_t x, const int32_t z) { while (sector->portal_room.sky != NO_ROOM) { @@ -335,8 +335,8 @@ int16_t Room_GetCeiling( int16_t type; int16_t trigger; - const SECTOR_INFO *const sky_sector = Room_GetSkySector(sector, x, z); - int16_t height = Room_GetCeilingTiltHeight(sky_sector, x, z); + const SECTOR_INFO *const sky_sector = M_GetSkySector(sector, x, z); + int16_t height = M_GetCeilingTiltHeight(sky_sector, x, z); sector = Room_GetPitSector(sector, x, z); if (sector->trigger == NULL) { @@ -366,7 +366,7 @@ int16_t Room_GetHeight( g_HeightType = HT_WALL; sector = Room_GetPitSector(sector, x, z); - int16_t height = Room_GetFloorTiltHeight(sector, x, z); + int16_t height = M_GetFloorTiltHeight(sector, x, z); if (sector->trigger == NULL) { return height; @@ -389,7 +389,7 @@ int16_t Room_GetHeight( return height; } -static int16_t Room_GetFloorTiltHeight( +static int16_t M_GetFloorTiltHeight( const SECTOR_INFO *sector, const int32_t x, const int32_t z) { int16_t height = sector->floor.height; @@ -423,7 +423,7 @@ static int16_t Room_GetFloorTiltHeight( return height; } -static int16_t Room_GetCeilingTiltHeight( +static int16_t M_GetCeilingTiltHeight( const SECTOR_INFO *sector, const int32_t x, const int32_t z) { int16_t height = sector->ceiling.height; @@ -566,7 +566,7 @@ void Room_AlterFloorHeight(ITEM_INFO *item, int32_t height) } while (portal_room != NO_ROOM); const SECTOR_INFO *const sky_sector = - Room_GetSkySector(sector, item->pos.x, item->pos.z); + M_GetSkySector(sector, item->pos.x, item->pos.z); sector = Room_GetPitSector(sector, item->pos.x, item->pos.z); if (sector->floor.height != NO_HEIGHT) { @@ -598,7 +598,7 @@ void Room_FlipMap(void) continue; } - Room_RemoveFlipItems(r); + M_RemoveFlipItems(r); ROOM_INFO *flipped = &g_RoomInfo[r->flipped_room]; ROOM_INFO temp = *r; @@ -612,7 +612,7 @@ void Room_FlipMap(void) r->item_num = flipped->item_num; r->fx_num = flipped->fx_num; - Room_AddFlipItems(r); + M_AddFlipItems(r); } g_FlipStatus = !g_FlipStatus; @@ -742,7 +742,7 @@ void Room_TestTriggers(const ITEM_INFO *const item) const SECTOR_INFO *sector = Room_GetSector(item->pos.x, MAX_HEIGHT, item->pos.z, &room_num); - Room_TestSectorTrigger(item, sector); + M_TestSectorTrigger(item, sector); if (item->object_id != O_TORSO) { return; } @@ -757,12 +757,12 @@ void Room_TestTriggers(const ITEM_INFO *const item) sector = Room_GetSector( item->pos.x + dx * WALL_L, MAX_HEIGHT, item->pos.z + dz * WALL_L, &room_num); - Room_TestSectorTrigger(item, sector); + M_TestSectorTrigger(item, sector); } } } -static bool Room_TestLava(const ITEM_INFO *const item) +static bool M_TestLava(const ITEM_INFO *const item) { if (item->hit_points < 0 || g_Lara.water_status == LWS_CHEAT || (g_Lara.water_status == LWS_ABOVE_WATER @@ -777,11 +777,11 @@ static bool Room_TestLava(const ITEM_INFO *const item) return sector->is_death_sector; } -static void Room_TestSectorTrigger( +static void M_TestSectorTrigger( const ITEM_INFO *const item, const SECTOR_INFO *const sector) { const bool is_heavy = item->object_id != O_LARA; - if (!is_heavy && sector->is_death_sector && Room_TestLava(item)) { + if (!is_heavy && sector->is_death_sector && M_TestLava(item)) { Lara_CatchFire(); } @@ -1019,7 +1019,7 @@ static void Room_TestSectorTrigger( break; case TO_CD: - Room_TriggerMusicTrack((int16_t)(intptr_t)cmd->parameter, trigger); + M_TriggerMusicTrack((int16_t)(intptr_t)cmd->parameter, trigger); break; case TO_SECRET: { diff --git a/src/game/room_draw.c b/src/game/room_draw.c index 063c412f9..e00cdea4a 100644 --- a/src/game/room_draw.c +++ b/src/game/room_draw.c @@ -18,20 +18,20 @@ static int32_t m_RoomNumStack[MAX_ROOMS_TO_DRAW] = { 0 }; static int32_t m_RoomNumStackIdx = 0; -static void Room_PrintDrawStack(void); -static bool Room_SetBounds(const DOOR_INFO *door, const ROOM_INFO *parent); -static void Room_GetBounds(int16_t room_num); -static void Room_PrepareToDraw(int16_t room_num); -static void Room_DrawSkybox(void); +static void M_PrintDrawStack(void); +static bool M_SetBounds(const DOOR_INFO *door, const ROOM_INFO *parent); +static void M_GetBounds(int16_t room_num); +static void M_PrepareToDraw(int16_t room_num); +static void M_DrawSkybox(void); -static void Room_PrintDrawStack(void) +static void M_PrintDrawStack(void) { for (int i = 0; i < m_RoomNumStackIdx; i++) { LOG_ERROR("Room Number %d", m_RoomNumStack[i]); } } -static bool Room_SetBounds(const DOOR_INFO *door, const ROOM_INFO *parent) +static bool M_SetBounds(const DOOR_INFO *door, const ROOM_INFO *parent) { const int32_t x = door->normal.x * (parent->x + door->vertex[0].x - g_W2VMatrix._03); @@ -172,11 +172,11 @@ static bool Room_SetBounds(const DOOR_INFO *door, const ROOM_INFO *parent) return true; } -static void Room_GetBounds(int16_t room_num) +static void M_GetBounds(int16_t room_num) { ROOM_INFO *r = &g_RoomInfo[room_num]; if (!Matrix_Push()) { - Room_PrintDrawStack(); + M_PrintDrawStack(); Shell_ExitSystem("Matrix stack overflow."); } m_RoomNumStack[m_RoomNumStackIdx++] = room_num; @@ -184,8 +184,8 @@ static void Room_GetBounds(int16_t room_num) if (r->doors) { for (int i = 0; i < r->doors->count; i++) { const DOOR_INFO *door = &r->doors->door[i]; - if (Room_SetBounds(door, r)) { - Room_GetBounds(door->room_num); + if (M_SetBounds(door, r)) { + M_GetBounds(door->room_num); } } } @@ -202,16 +202,16 @@ void Room_DrawAllRooms(int16_t base_room, int16_t target_room) g_RoomsToDrawCount = 0; - Room_PrepareToDraw(base_room); - Room_PrepareToDraw(target_room); - Room_DrawSkybox(); + M_PrepareToDraw(base_room); + M_PrepareToDraw(target_room); + M_DrawSkybox(); for (int i = 0; i < g_RoomsToDrawCount; i++) { Room_DrawSingleRoom(g_RoomsToDraw[i]); } } -static void Room_PrepareToDraw(int16_t room_num) +static void M_PrepareToDraw(int16_t room_num) { ROOM_INFO *r = &g_RoomInfo[room_num]; if (r->bound_active) { @@ -233,15 +233,15 @@ static void Room_PrepareToDraw(int16_t room_num) if (r->doors) { for (int i = 0; i < r->doors->count; i++) { const DOOR_INFO *door = &r->doors->door[i]; - if (Room_SetBounds(door, r)) { - Room_GetBounds(door->room_num); + if (M_SetBounds(door, r)) { + M_GetBounds(door->room_num); } } } Matrix_Pop(); } -static void Room_DrawSkybox(void) +static void M_DrawSkybox(void) { if (!Output_IsSkyboxEnabled()) { return; diff --git a/src/game/savegame/savegame.c b/src/game/savegame/savegame.c index 26db7e145..47c2cbea0 100644 --- a/src/game/savegame/savegame.c +++ b/src/game/savegame/savegame.c @@ -73,15 +73,15 @@ static const SAVEGAME_STRATEGY m_Strategies[] = { { 0 }, }; -static void Savegame_LoadPreprocess(void); -static void Savegame_LoadPostprocess(void); +static void M_LoadPreprocess(void); +static void M_LoadPostprocess(void); -static void Savegame_LoadPreprocess(void) +static void M_LoadPreprocess(void) { Savegame_InitCurrentInfo(); } -static void Savegame_LoadPostprocess(void) +static void M_LoadPostprocess(void) { for (int i = 0; i < g_LevelItemCount; i++) { ITEM_INFO *item = &g_Items[i]; @@ -402,7 +402,7 @@ bool Savegame_Load(int32_t slot_num, GAME_INFO *game_info) SAVEGAME_INFO *savegame_info = &m_SavegameInfo[slot_num]; assert(savegame_info->format); - Savegame_LoadPreprocess(); + M_LoadPreprocess(); bool ret = false; const SAVEGAME_STRATEGY *strategy = &m_Strategies[0]; @@ -419,7 +419,7 @@ bool Savegame_Load(int32_t slot_num, GAME_INFO *game_info) } if (ret) { - Savegame_LoadPostprocess(); + M_LoadPostprocess(); } g_GameInfo.save_initial_version = m_SavegameInfo[slot_num].initial_version; diff --git a/src/game/savegame/savegame_bson.c b/src/game/savegame/savegame_bson.c index 2ed8fdece..0cd49dcea 100644 --- a/src/game/savegame/savegame_bson.c +++ b/src/game/savegame/savegame_bson.c @@ -43,57 +43,50 @@ typedef struct SAVEGAME_BSON_FX_ORDER { int16_t id_map[NUM_EFFECTS]; } SAVEGAME_BSON_FX_ORDER; -static void SaveGame_BSON_SaveRaw( - MYFILE *fp, struct json_value_s *root, int32_t version); -static struct json_value_s *Savegame_BSON_ParseFromBuffer( +static void M_SaveRaw(MYFILE *fp, struct json_value_s *root, int32_t version); +static struct json_value_s *M_ParseFromBuffer( const char *buffer, size_t buffer_size, int32_t *version_out); -static struct json_value_s *Savegame_BSON_ParseFromFile( - MYFILE *fp, int32_t *version_out); -static bool Savegame_BSON_LoadResumeInfo( +static struct json_value_s *M_ParseFromFile(MYFILE *fp, int32_t *version_out); +static bool M_LoadResumeInfo( struct json_array_s *levels_arr, RESUME_INFO *resume_info); -static bool Savegame_BSON_LoadDiscontinuedStartInfo( +static bool M_LoadDiscontinuedStartInfo( struct json_array_s *start_arr, GAME_INFO *game_info); -static bool Savegame_BSON_LoadDiscontinuedEndInfo( +static bool M_LoadDiscontinuedEndInfo( struct json_array_s *end_arr, GAME_INFO *game_info); -static bool Savegame_BSON_LoadMisc( +static bool M_LoadMisc( struct json_object_s *misc_obj, GAME_INFO *game_info, uint16_t header_version); -static bool Savegame_BSON_LoadInventory(struct json_object_s *inv_obj); -static bool Savegame_BSON_LoadFlipmaps(struct json_object_s *flipmap_obj); -static bool Savegame_BSON_LoadCameras(struct json_array_s *cameras_arr); -static bool Savegame_BSON_LoadItems( +static bool M_LoadInventory(struct json_object_s *inv_obj); +static bool M_LoadFlipmaps(struct json_object_s *flipmap_obj); +static bool M_LoadCameras(struct json_array_s *cameras_arr); +static bool M_LoadItems( struct json_array_s *items_arr, uint16_t header_version); -static bool SaveGame_BSON_LoadFx(struct json_array_s *fx_arr); -static bool Savegame_BSON_LoadArm(struct json_object_s *arm_obj, LARA_ARM *arm); -static bool Savegame_BSON_LoadAmmo( - struct json_object_s *ammo_obj, AMMO_INFO *ammo); -static bool Savegame_BSON_LoadLOT(struct json_object_s *lot_obj, LOT_INFO *lot); -static bool Savegame_BSON_LoadLara( - struct json_object_s *lara_obj, LARA_INFO *lara); -static bool SaveGame_BSON_LoadCurrentMusic(struct json_object_s *music_obj); -static bool SaveGame_BSON_LoadMusicTrackFlags( - struct json_array_s *music_track_arr); -static struct json_array_s *Savegame_BSON_DumpResumeInfo( - RESUME_INFO *game_info); -static struct json_object_s *Savegame_BSON_DumpMisc(GAME_INFO *game_info); -static struct json_object_s *Savegame_BSON_DumpInventory(void); -static struct json_object_s *Savegame_BSON_DumpFlipmaps(void); -static struct json_array_s *Savegame_BSON_DumpCameras(void); -static struct json_array_s *Savegame_BSON_DumpItems(void); -static struct json_array_s *SaveGame_BSON_DumpFx(void); -static struct json_object_s *Savegame_BSON_DumpArm(LARA_ARM *arm); -static struct json_object_s *Savegame_BSON_DumpAmmo(AMMO_INFO *ammo); -static struct json_object_s *Savegame_BSON_DumpLOT(LOT_INFO *lot); -static struct json_object_s *Savegame_BSON_DumpLara(LARA_INFO *lara); -static struct json_object_s *SaveGame_BSON_DumpCurrentMusic(void); -static struct json_array_s *SaveGame_BSON_DumpMusicTrackFlags(void); - -static void SaveGame_BSON_GetFXOrder(SAVEGAME_BSON_FX_ORDER *order); -static bool Savegame_BSON_IsValidItemObject( +static bool M_LoadFx(struct json_array_s *fx_arr); +static bool M_LoadArm(struct json_object_s *arm_obj, LARA_ARM *arm); +static bool M_LoadAmmo(struct json_object_s *ammo_obj, AMMO_INFO *ammo); +static bool M_LoadLOT(struct json_object_s *lot_obj, LOT_INFO *lot); +static bool M_LoadLara(struct json_object_s *lara_obj, LARA_INFO *lara); +static bool M_LoadCurrentMusic(struct json_object_s *music_obj); +static bool M_LoadMusicTrackFlags(struct json_array_s *music_track_arr); +static struct json_array_s *M_DumpResumeInfo(RESUME_INFO *game_info); +static struct json_object_s *M_DumpMisc(GAME_INFO *game_info); +static struct json_object_s *M_DumpInventory(void); +static struct json_object_s *M_DumpFlipmaps(void); +static struct json_array_s *M_DumpCameras(void); +static struct json_array_s *M_DumpItems(void); +static struct json_array_s *M_DumpFx(void); +static struct json_object_s *M_DumpArm(LARA_ARM *arm); +static struct json_object_s *M_DumpAmmo(AMMO_INFO *ammo); +static struct json_object_s *M_DumpLOT(LOT_INFO *lot); +static struct json_object_s *M_DumpLara(LARA_INFO *lara); +static struct json_object_s *M_DumpCurrentMusic(void); +static struct json_array_s *M_DumpMusicTrackFlags(void); + +static void M_GetFXOrder(SAVEGAME_BSON_FX_ORDER *order); +static bool M_IsValidItemObject( GAME_OBJECT_ID saved_object_id, GAME_OBJECT_ID current_object_id); -static void SaveGame_BSON_SaveRaw( - MYFILE *fp, struct json_value_s *root, int32_t version) +static void M_SaveRaw(MYFILE *fp, struct json_value_s *root, int32_t version) { size_t uncompressed_size; char *uncompressed = bson_write(root, &uncompressed_size); @@ -123,7 +116,7 @@ static void SaveGame_BSON_SaveRaw( Memory_FreePointer(&compressed); } -static void SaveGame_BSON_GetFXOrder(SAVEGAME_BSON_FX_ORDER *order) +static void M_GetFXOrder(SAVEGAME_BSON_FX_ORDER *order) { order->count = 0; for (int i = 0; i < NUM_EFFECTS; i++) { @@ -137,7 +130,7 @@ static void SaveGame_BSON_GetFXOrder(SAVEGAME_BSON_FX_ORDER *order) } } -static bool Savegame_BSON_IsValidItemObject( +static bool M_IsValidItemObject( const GAME_OBJECT_ID saved_object_id, const GAME_OBJECT_ID initial_object_id) { @@ -168,7 +161,7 @@ static bool Savegame_BSON_IsValidItemObject( // clang-format on } -static struct json_value_s *Savegame_BSON_ParseFromBuffer( +static struct json_value_s *M_ParseFromBuffer( const char *buffer, size_t buffer_size, int32_t *version_out) { SAVEGAME_BSON_HEADER *header = (SAVEGAME_BSON_HEADER *)buffer; @@ -199,8 +192,7 @@ static struct json_value_s *Savegame_BSON_ParseFromBuffer( return root; } -static struct json_value_s *Savegame_BSON_ParseFromFile( - MYFILE *fp, int32_t *version_out) +static struct json_value_s *M_ParseFromFile(MYFILE *fp, int32_t *version_out) { const size_t buffer_size = File_Size(fp); char *buffer = Memory_Alloc(buffer_size); @@ -208,12 +200,12 @@ static struct json_value_s *Savegame_BSON_ParseFromFile( File_ReadData(fp, buffer, buffer_size); struct json_value_s *ret = - Savegame_BSON_ParseFromBuffer(buffer, buffer_size, version_out); + M_ParseFromBuffer(buffer, buffer_size, version_out); Memory_FreePointer(&buffer); return ret; } -static bool Savegame_BSON_LoadResumeInfo( +static bool M_LoadResumeInfo( struct json_array_s *resume_arr, RESUME_INFO *resume_info) { assert(resume_info); @@ -284,7 +276,7 @@ static bool Savegame_BSON_LoadResumeInfo( return true; } -static bool Savegame_BSON_LoadDiscontinuedStartInfo( +static bool M_LoadDiscontinuedStartInfo( struct json_array_s *start_arr, GAME_INFO *game_info) { // This function solely exists for backward compatibility with 2.6 and 2.7 @@ -338,7 +330,7 @@ static bool Savegame_BSON_LoadDiscontinuedStartInfo( return true; } -static bool Savegame_BSON_LoadDiscontinuedEndInfo( +static bool M_LoadDiscontinuedEndInfo( struct json_array_s *end_arr, GAME_INFO *game_info) { // This function solely exists for backward compatibility with 2.6 and 2.7 @@ -382,7 +374,7 @@ static bool Savegame_BSON_LoadDiscontinuedEndInfo( return true; } -static bool Savegame_BSON_LoadMisc( +static bool M_LoadMisc( struct json_object_s *misc_obj, GAME_INFO *game_info, uint16_t header_version) { @@ -399,7 +391,7 @@ static bool Savegame_BSON_LoadMisc( return true; } -static bool Savegame_BSON_LoadInventory(struct json_object_s *inv_obj) +static bool M_LoadInventory(struct json_object_s *inv_obj) { if (!inv_obj) { LOG_ERROR("Malformed save: invalid or missing inventory info"); @@ -427,7 +419,7 @@ static bool Savegame_BSON_LoadInventory(struct json_object_s *inv_obj) return true; } -static bool Savegame_BSON_LoadFlipmaps(struct json_object_s *flipmap_obj) +static bool M_LoadFlipmaps(struct json_object_s *flipmap_obj) { if (!flipmap_obj) { LOG_ERROR("Malformed save: invalid or missing flipmap info"); @@ -460,7 +452,7 @@ static bool Savegame_BSON_LoadFlipmaps(struct json_object_s *flipmap_obj) return true; } -static bool Savegame_BSON_LoadCameras(struct json_array_s *cameras_arr) +static bool M_LoadCameras(struct json_array_s *cameras_arr) { if (!cameras_arr) { LOG_ERROR("Malformed save: invalid or missing cameras array"); @@ -478,8 +470,7 @@ static bool Savegame_BSON_LoadCameras(struct json_array_s *cameras_arr) return true; } -static bool Savegame_BSON_LoadItems( - struct json_array_s *items_arr, uint16_t header_version) +static bool M_LoadItems(struct json_array_s *items_arr, uint16_t header_version) { if (!items_arr) { LOG_ERROR("Malformed save: invalid or missing items array"); @@ -505,7 +496,7 @@ static bool Savegame_BSON_LoadItems( const GAME_OBJECT_ID object_id = json_object_get_int(item_obj, "obj_num", -1); - if (!Savegame_BSON_IsValidItemObject(object_id, item->object_id)) { + if (!M_IsValidItemObject(object_id, item->object_id)) { LOG_ERROR( "Malformed save: expected object %d, got %d", item->object_id, object_id); @@ -646,7 +637,7 @@ static bool Savegame_BSON_LoadItems( return true; } -static bool SaveGame_BSON_LoadFx(struct json_array_s *fx_arr) +static bool M_LoadFx(struct json_array_s *fx_arr) { if (!g_Config.enable_enhanced_saves) { return true; @@ -701,7 +692,7 @@ static bool SaveGame_BSON_LoadFx(struct json_array_s *fx_arr) return true; } -static bool Savegame_BSON_LoadArm(struct json_object_s *arm_obj, LARA_ARM *arm) +static bool M_LoadArm(struct json_object_s *arm_obj, LARA_ARM *arm) { assert(arm); if (!arm_obj) { @@ -718,8 +709,7 @@ static bool Savegame_BSON_LoadArm(struct json_object_s *arm_obj, LARA_ARM *arm) return true; } -static bool Savegame_BSON_LoadAmmo( - struct json_object_s *ammo_obj, AMMO_INFO *ammo) +static bool M_LoadAmmo(struct json_object_s *ammo_obj, AMMO_INFO *ammo) { assert(ammo); if (!ammo_obj) { @@ -733,7 +723,7 @@ static bool Savegame_BSON_LoadAmmo( return true; } -static bool Savegame_BSON_LoadLOT(struct json_object_s *lot_obj, LOT_INFO *lot) +static bool M_LoadLOT(struct json_object_s *lot_obj, LOT_INFO *lot) { assert(lot); if (!lot_obj) { @@ -762,8 +752,7 @@ static bool Savegame_BSON_LoadLOT(struct json_object_s *lot_obj, LOT_INFO *lot) return true; } -static bool Savegame_BSON_LoadLara( - struct json_object_s *lara_obj, LARA_INFO *lara) +static bool M_LoadLara(struct json_object_s *lara_obj, LARA_INFO *lara) { assert(lara); if (!lara_obj) { @@ -847,45 +836,43 @@ static bool Savegame_BSON_LoadLara( lara->torso_rot.z = json_object_get_int(lara_obj, "torso_rot.z", lara->torso_rot.z); - if (!Savegame_BSON_LoadArm( + if (!M_LoadArm( json_object_get_object(lara_obj, "left_arm"), &lara->left_arm)) { return false; } - if (!Savegame_BSON_LoadArm( + if (!M_LoadArm( json_object_get_object(lara_obj, "right_arm"), &lara->right_arm)) { return false; } - if (!Savegame_BSON_LoadAmmo( + if (!M_LoadAmmo( json_object_get_object(lara_obj, "pistols"), &lara->pistols)) { return false; } - if (!Savegame_BSON_LoadAmmo( + if (!M_LoadAmmo( json_object_get_object(lara_obj, "magnums"), &lara->magnums)) { return false; } - if (!Savegame_BSON_LoadAmmo( - json_object_get_object(lara_obj, "uzis"), &lara->uzis)) { + if (!M_LoadAmmo(json_object_get_object(lara_obj, "uzis"), &lara->uzis)) { return false; } - if (!Savegame_BSON_LoadAmmo( + if (!M_LoadAmmo( json_object_get_object(lara_obj, "shotgun"), &lara->shotgun)) { return false; } - if (!Savegame_BSON_LoadLOT( - json_object_get_object(lara_obj, "lot"), &lara->LOT)) { + if (!M_LoadLOT(json_object_get_object(lara_obj, "lot"), &lara->LOT)) { return false; } return true; } -static bool SaveGame_BSON_LoadCurrentMusic(struct json_object_s *music_obj) +static bool M_LoadCurrentMusic(struct json_object_s *music_obj) { if (!g_Config.load_current_music) { return true; @@ -909,8 +896,7 @@ static bool SaveGame_BSON_LoadCurrentMusic(struct json_object_s *music_obj) return true; } -static bool SaveGame_BSON_LoadMusicTrackFlags( - struct json_array_s *music_track_arr) +static bool M_LoadMusicTrackFlags(struct json_array_s *music_track_arr) { if (!g_Config.load_music_triggers) { return true; @@ -935,8 +921,7 @@ static bool SaveGame_BSON_LoadMusicTrackFlags( return true; } -static struct json_array_s *Savegame_BSON_DumpResumeInfo( - RESUME_INFO *resume_info) +static struct json_array_s *M_DumpResumeInfo(RESUME_INFO *resume_info) { struct json_array_s *resume_arr = json_array_new(); assert(resume_info); @@ -989,7 +974,7 @@ static struct json_array_s *Savegame_BSON_DumpResumeInfo( return resume_arr; } -static struct json_object_s *Savegame_BSON_DumpMisc(GAME_INFO *game_info) +static struct json_object_s *M_DumpMisc(GAME_INFO *game_info) { assert(game_info); struct json_object_s *misc_obj = json_object_new(); @@ -999,7 +984,7 @@ static struct json_object_s *Savegame_BSON_DumpMisc(GAME_INFO *game_info) return misc_obj; } -static struct json_object_s *Savegame_BSON_DumpInventory(void) +static struct json_object_s *M_DumpInventory(void) { struct json_object_s *inv_obj = json_object_new(); json_object_append_int( @@ -1022,7 +1007,7 @@ static struct json_object_s *Savegame_BSON_DumpInventory(void) return inv_obj; } -static struct json_object_s *Savegame_BSON_DumpFlipmaps(void) +static struct json_object_s *M_DumpFlipmaps(void) { struct json_object_s *flipmap_obj = json_object_new(); json_object_append_bool(flipmap_obj, "status", g_FlipStatus); @@ -1036,7 +1021,7 @@ static struct json_object_s *Savegame_BSON_DumpFlipmaps(void) return flipmap_obj; } -static struct json_array_s *Savegame_BSON_DumpCameras(void) +static struct json_array_s *M_DumpCameras(void) { struct json_array_s *cameras_arr = json_array_new(); for (int i = 0; i < g_NumberCameras; i++) { @@ -1045,12 +1030,12 @@ static struct json_array_s *Savegame_BSON_DumpCameras(void) return cameras_arr; } -static struct json_array_s *Savegame_BSON_DumpItems(void) +static struct json_array_s *M_DumpItems(void) { Savegame_ProcessItemsBeforeSave(); SAVEGAME_BSON_FX_ORDER fx_order; - SaveGame_BSON_GetFXOrder(&fx_order); + M_GetFXOrder(&fx_order); struct json_array_s *items_arr = json_array_new(); for (int i = 0; i < g_LevelItemCount; i++) { @@ -1150,12 +1135,12 @@ static struct json_array_s *Savegame_BSON_DumpItems(void) return items_arr; } -static struct json_array_s *SaveGame_BSON_DumpFx(void) +static struct json_array_s *M_DumpFx(void) { struct json_array_s *fx_arr = json_array_new(); SAVEGAME_BSON_FX_ORDER fx_order; - SaveGame_BSON_GetFXOrder(&fx_order); + M_GetFXOrder(&fx_order); for (int16_t linknum = g_NextFxActive; linknum != NO_ITEM; linknum = g_Effects[linknum].next_active) { @@ -1177,7 +1162,7 @@ static struct json_array_s *SaveGame_BSON_DumpFx(void) return fx_arr; } -static struct json_object_s *Savegame_BSON_DumpArm(LARA_ARM *arm) +static struct json_object_s *M_DumpArm(LARA_ARM *arm) { assert(arm); struct json_object_s *arm_obj = json_object_new(); @@ -1190,7 +1175,7 @@ static struct json_object_s *Savegame_BSON_DumpArm(LARA_ARM *arm) return arm_obj; } -static struct json_object_s *Savegame_BSON_DumpAmmo(AMMO_INFO *ammo) +static struct json_object_s *M_DumpAmmo(AMMO_INFO *ammo) { assert(ammo); struct json_object_s *ammo_obj = json_object_new(); @@ -1200,7 +1185,7 @@ static struct json_object_s *Savegame_BSON_DumpAmmo(AMMO_INFO *ammo) return ammo_obj; } -static struct json_object_s *Savegame_BSON_DumpLOT(LOT_INFO *lot) +static struct json_object_s *M_DumpLOT(LOT_INFO *lot) { assert(lot); struct json_object_s *lot_obj = json_object_new(); @@ -1221,7 +1206,7 @@ static struct json_object_s *Savegame_BSON_DumpLOT(LOT_INFO *lot) return lot_obj; } -static struct json_object_s *Savegame_BSON_DumpLara(LARA_INFO *lara) +static struct json_object_s *M_DumpLara(LARA_INFO *lara) { assert(lara); struct json_object_s *lara_obj = json_object_new(); @@ -1264,25 +1249,19 @@ static struct json_object_s *Savegame_BSON_DumpLara(LARA_INFO *lara) json_object_append_int(lara_obj, "torso_rot.x", lara->torso_rot.x); json_object_append_int(lara_obj, "torso_rot.z", lara->torso_rot.z); + json_object_append_object(lara_obj, "left_arm", M_DumpArm(&lara->left_arm)); json_object_append_object( - lara_obj, "left_arm", Savegame_BSON_DumpArm(&lara->left_arm)); - json_object_append_object( - lara_obj, "right_arm", Savegame_BSON_DumpArm(&lara->right_arm)); - json_object_append_object( - lara_obj, "pistols", Savegame_BSON_DumpAmmo(&lara->pistols)); - json_object_append_object( - lara_obj, "magnums", Savegame_BSON_DumpAmmo(&lara->magnums)); - json_object_append_object( - lara_obj, "uzis", Savegame_BSON_DumpAmmo(&lara->uzis)); - json_object_append_object( - lara_obj, "shotgun", Savegame_BSON_DumpAmmo(&lara->shotgun)); - json_object_append_object( - lara_obj, "lot", Savegame_BSON_DumpLOT(&lara->LOT)); + lara_obj, "right_arm", M_DumpArm(&lara->right_arm)); + json_object_append_object(lara_obj, "pistols", M_DumpAmmo(&lara->pistols)); + json_object_append_object(lara_obj, "magnums", M_DumpAmmo(&lara->magnums)); + json_object_append_object(lara_obj, "uzis", M_DumpAmmo(&lara->uzis)); + json_object_append_object(lara_obj, "shotgun", M_DumpAmmo(&lara->shotgun)); + json_object_append_object(lara_obj, "lot", M_DumpLOT(&lara->LOT)); return lara_obj; } -static struct json_object_s *SaveGame_BSON_DumpCurrentMusic(void) +static struct json_object_s *M_DumpCurrentMusic(void) { struct json_object_s *current_music_obj = json_object_new(); json_object_append_int( @@ -1293,7 +1272,7 @@ static struct json_object_s *SaveGame_BSON_DumpCurrentMusic(void) return current_music_obj; } -static struct json_array_s *SaveGame_BSON_DumpMusicTrackFlags(void) +static struct json_array_s *M_DumpMusicTrackFlags(void) { struct json_array_s *music_track_arr = json_array_new(); for (int i = 0; i < MAX_CD_TRACKS; i++) { @@ -1313,7 +1292,7 @@ char *Savegame_BSON_GetSaveFileName(int32_t slot) bool Savegame_BSON_FillInfo(MYFILE *fp, SAVEGAME_INFO *info) { bool ret = false; - struct json_value_s *root = Savegame_BSON_ParseFromFile(fp, NULL); + struct json_value_s *root = M_ParseFromFile(fp, NULL); struct json_object_s *root_obj = json_value_as_object(root); if (root_obj) { info->counter = json_object_get_int(root_obj, "save_counter", -1); @@ -1349,7 +1328,7 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) File_ReadData(fp, &header, sizeof(SAVEGAME_BSON_HEADER)); File_Seek(fp, 0, FILE_SEEK_SET); - struct json_value_s *root = Savegame_BSON_ParseFromFile(fp, NULL); + struct json_value_s *root = M_ParseFromFile(fp, NULL); struct json_object_s *root_obj = json_value_as_object(root); if (!root_obj) { LOG_ERROR("Malformed save: cannot parse BSON data"); @@ -1362,69 +1341,64 @@ bool Savegame_BSON_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) goto cleanup; } - if (!Savegame_BSON_LoadResumeInfo( + if (!M_LoadResumeInfo( json_object_get_array(root_obj, "current_info"), game_info->current)) { LOG_WARNING( "Failed to load RESUME_INFO current properly. " "Checking if save is legacy."); // Check for 2.6 and 2.7 legacy start and end info. - if (!Savegame_BSON_LoadDiscontinuedStartInfo( + if (!M_LoadDiscontinuedStartInfo( json_object_get_array(root_obj, "start_info"), game_info)) { goto cleanup; } - if (!Savegame_BSON_LoadDiscontinuedEndInfo( + if (!M_LoadDiscontinuedEndInfo( json_object_get_array(root_obj, "end_info"), game_info)) { goto cleanup; } } - if (!Savegame_BSON_LoadMisc( + if (!M_LoadMisc( json_object_get_object(root_obj, "misc"), game_info, header.version)) { goto cleanup; } - if (!Savegame_BSON_LoadInventory( - json_object_get_object(root_obj, "inventory"))) { + if (!M_LoadInventory(json_object_get_object(root_obj, "inventory"))) { goto cleanup; } - if (!Savegame_BSON_LoadFlipmaps( - json_object_get_object(root_obj, "flipmap"))) { + if (!M_LoadFlipmaps(json_object_get_object(root_obj, "flipmap"))) { goto cleanup; } - if (!Savegame_BSON_LoadCameras( - json_object_get_array(root_obj, "cameras"))) { + if (!M_LoadCameras(json_object_get_array(root_obj, "cameras"))) { goto cleanup; } Savegame_ProcessItemsBeforeLoad(); - if (!Savegame_BSON_LoadItems( + if (!M_LoadItems( json_object_get_array(root_obj, "items"), header.version)) { goto cleanup; } if (header.version >= VERSION_3) { - if (!SaveGame_BSON_LoadFx(json_object_get_array(root_obj, "fx"))) { + if (!M_LoadFx(json_object_get_array(root_obj, "fx"))) { goto cleanup; } } - if (!Savegame_BSON_LoadLara( - json_object_get_object(root_obj, "lara"), &g_Lara)) { + if (!M_LoadLara(json_object_get_object(root_obj, "lara"), &g_Lara)) { goto cleanup; } if (header.version >= VERSION_3) { - if (!SaveGame_BSON_LoadCurrentMusic( - json_object_get_object(root_obj, "music"))) { + if (!M_LoadCurrentMusic(json_object_get_object(root_obj, "music"))) { goto cleanup; } - if (!SaveGame_BSON_LoadMusicTrackFlags( + if (!M_LoadMusicTrackFlags( json_object_get_array(root_obj, "music_track_flags"))) { goto cleanup; } @@ -1442,25 +1416,25 @@ bool Savegame_BSON_LoadOnlyResumeInfo(MYFILE *fp, GAME_INFO *game_info) assert(game_info); bool ret = false; - struct json_value_s *root = Savegame_BSON_ParseFromFile(fp, NULL); + struct json_value_s *root = M_ParseFromFile(fp, NULL); struct json_object_s *root_obj = json_value_as_object(root); if (!root_obj) { LOG_ERROR("Malformed save: cannot parse BSON data"); goto cleanup; } - if (!Savegame_BSON_LoadResumeInfo( + if (!M_LoadResumeInfo( json_object_get_array(root_obj, "current_info"), game_info->current)) { LOG_WARNING( "Failed to load RESUME_INFO current properly. Checking if " "save is legacy."); // Check for 2.6 and 2.7 legacy start and end info. - if (!Savegame_BSON_LoadDiscontinuedStartInfo( + if (!M_LoadDiscontinuedStartInfo( json_object_get_array(root_obj, "start_info"), game_info)) { goto cleanup; } - if (!Savegame_BSON_LoadDiscontinuedEndInfo( + if (!M_LoadDiscontinuedEndInfo( json_object_get_array(root_obj, "end_info"), game_info)) { goto cleanup; } @@ -1484,27 +1458,21 @@ void Savegame_BSON_SaveToFile(MYFILE *fp, GAME_INFO *game_info) json_object_append_int(root_obj, "save_counter", g_SaveCounter); json_object_append_int(root_obj, "level_num", g_CurrentLevel); - json_object_append_object( - root_obj, "misc", Savegame_BSON_DumpMisc(game_info)); + json_object_append_object(root_obj, "misc", M_DumpMisc(game_info)); json_object_append_array( - root_obj, "current_info", - Savegame_BSON_DumpResumeInfo(game_info->current)); - json_object_append_object( - root_obj, "inventory", Savegame_BSON_DumpInventory()); - json_object_append_object( - root_obj, "flipmap", Savegame_BSON_DumpFlipmaps()); - json_object_append_array(root_obj, "cameras", Savegame_BSON_DumpCameras()); - json_object_append_array(root_obj, "items", Savegame_BSON_DumpItems()); - json_object_append_array(root_obj, "fx", SaveGame_BSON_DumpFx()); - json_object_append_object( - root_obj, "lara", Savegame_BSON_DumpLara(&g_Lara)); - json_object_append_object( - root_obj, "music", SaveGame_BSON_DumpCurrentMusic()); + root_obj, "current_info", M_DumpResumeInfo(game_info->current)); + json_object_append_object(root_obj, "inventory", M_DumpInventory()); + json_object_append_object(root_obj, "flipmap", M_DumpFlipmaps()); + json_object_append_array(root_obj, "cameras", M_DumpCameras()); + json_object_append_array(root_obj, "items", M_DumpItems()); + json_object_append_array(root_obj, "fx", M_DumpFx()); + json_object_append_object(root_obj, "lara", M_DumpLara(&g_Lara)); + json_object_append_object(root_obj, "music", M_DumpCurrentMusic()); json_object_append_array( - root_obj, "music_track_flags", SaveGame_BSON_DumpMusicTrackFlags()); + root_obj, "music_track_flags", M_DumpMusicTrackFlags()); struct json_value_s *root = json_value_from_object(root_obj); - SaveGame_BSON_SaveRaw(fp, root, SAVEGAME_CURRENT_VERSION); + M_SaveRaw(fp, root, SAVEGAME_CURRENT_VERSION); json_value_free(root); } @@ -1512,7 +1480,7 @@ bool Savegame_BSON_UpdateDeathCounters(MYFILE *fp, GAME_INFO *game_info) { bool ret = false; int32_t version; - struct json_value_s *root = Savegame_BSON_ParseFromFile(fp, &version); + struct json_value_s *root = M_ParseFromFile(fp, &version); struct json_object_s *root_obj = json_value_as_object(root); if (!root_obj) { LOG_ERROR("Cannot find the root object"); @@ -1546,7 +1514,7 @@ bool Savegame_BSON_UpdateDeathCounters(MYFILE *fp, GAME_INFO *game_info) } File_Seek(fp, 0, FILE_SEEK_SET); - SaveGame_BSON_SaveRaw(fp, root, version); + M_SaveRaw(fp, root, version); ret = true; cleanup: diff --git a/src/game/savegame/savegame_legacy.c b/src/game/savegame/savegame_legacy.c index bb74119eb..8b9447582 100644 --- a/src/game/savegame/savegame_legacy.c +++ b/src/game/savegame/savegame_legacy.c @@ -45,26 +45,26 @@ typedef struct SAVEGAME_LEGACY_ITEM_STATS { static int m_SGBufPos = 0; static char *m_SGBufPtr = NULL; -static bool Savegame_Legacy_ItemHasSaveFlags(OBJECT_INFO *obj, ITEM_INFO *item); -static bool Savegame_Legacy_ItemHasSaveAnim(const ITEM_INFO *item); -static bool Savegame_Legacy_NeedsBaconLaraFix(char *buffer); - -static void Savegame_Legacy_Reset(char *buffer); -static void Savegame_Legacy_Skip(int size); - -static void Savegame_Legacy_Read(void *pointer, int size); -static void Savegame_Legacy_ReadArm(LARA_ARM *arm); -static void Savegame_Legacy_ReadLara(LARA_INFO *lara); -static void Savegame_Legacy_ReadLOT(LOT_INFO *lot); -static void Savegame_Legacy_SetCurrentPosition(int level_num); -static void Savegame_Legacy_ReadResumeInfo(MYFILE *fp, GAME_INFO *game_info); - -static void Savegame_Legacy_Write(const void *pointer, int size); -static void Savegame_Legacy_WriteArm(LARA_ARM *arm); -static void Savegame_Legacy_WriteLara(LARA_INFO *lara); -static void Savegame_Legacy_WriteLOT(LOT_INFO *lot); - -static bool Savegame_Legacy_ItemHasSaveFlags(OBJECT_INFO *obj, ITEM_INFO *item) +static bool M_ItemHasSaveFlags(OBJECT_INFO *obj, ITEM_INFO *item); +static bool M_ItemHasSaveAnim(const ITEM_INFO *item); +static bool M_NeedsBaconLaraFix(char *buffer); + +static void M_Reset(char *buffer); +static void M_Skip(int size); + +static void M_Read(void *pointer, int size); +static void M_ReadArm(LARA_ARM *arm); +static void M_ReadLara(LARA_INFO *lara); +static void M_ReadLOT(LOT_INFO *lot); +static void M_SetCurrentPosition(int level_num); +static void M_ReadResumeInfo(MYFILE *fp, GAME_INFO *game_info); + +static void M_Write(const void *pointer, int size); +static void M_WriteArm(LARA_ARM *arm); +static void M_WriteLara(LARA_INFO *lara); +static void M_WriteLOT(LOT_INFO *lot); + +static bool M_ItemHasSaveFlags(OBJECT_INFO *obj, ITEM_INFO *item) { // TR1X savegame files are enhanced to store more information by having // changed the save_flags bit for certain item types. However, legacy @@ -81,13 +81,13 @@ static bool Savegame_Legacy_ItemHasSaveFlags(OBJECT_INFO *obj, ITEM_INFO *item) && item->object_id != O_DART_EMITTER); } -static bool Savegame_Legacy_ItemHasSaveAnim(const ITEM_INFO *const item) +static bool M_ItemHasSaveAnim(const ITEM_INFO *const item) { const OBJECT_INFO *const obj = &g_Objects[item->object_id]; return obj->save_anim && item->object_id != O_BACON_LARA; } -static bool Savegame_Legacy_NeedsBaconLaraFix(char *buffer) +static bool M_NeedsBaconLaraFix(char *buffer) { // Heuristic for issue #261. // TR1X enables save_flags for Bacon Lara, but OG TombATI does not. As @@ -108,31 +108,31 @@ static bool Savegame_Legacy_NeedsBaconLaraFix(char *buffer) return result; } - Savegame_Legacy_Reset(buffer); - Savegame_Legacy_Skip(SAVEGAME_LEGACY_TITLE_SIZE); // level title - Savegame_Legacy_Skip(sizeof(int32_t)); // save counter + M_Reset(buffer); + M_Skip(SAVEGAME_LEGACY_TITLE_SIZE); // level title + M_Skip(sizeof(int32_t)); // save counter for (int i = 0; i < g_GameFlow.level_count; i++) { - Savegame_Legacy_Skip(sizeof(uint16_t)); // pistol ammo - Savegame_Legacy_Skip(sizeof(uint16_t)); // magnum ammo - Savegame_Legacy_Skip(sizeof(uint16_t)); // uzi ammo - Savegame_Legacy_Skip(sizeof(uint16_t)); // shotgun ammo - Savegame_Legacy_Skip(sizeof(uint8_t)); // small medis - Savegame_Legacy_Skip(sizeof(uint8_t)); // big medis - Savegame_Legacy_Skip(sizeof(uint8_t)); // scions - Savegame_Legacy_Skip(sizeof(int8_t)); // gun status - Savegame_Legacy_Skip(sizeof(int8_t)); // gun type - Savegame_Legacy_Skip(sizeof(uint16_t)); // flags + M_Skip(sizeof(uint16_t)); // pistol ammo + M_Skip(sizeof(uint16_t)); // magnum ammo + M_Skip(sizeof(uint16_t)); // uzi ammo + M_Skip(sizeof(uint16_t)); // shotgun ammo + M_Skip(sizeof(uint8_t)); // small medis + M_Skip(sizeof(uint8_t)); // big medis + M_Skip(sizeof(uint8_t)); // scions + M_Skip(sizeof(int8_t)); // gun status + M_Skip(sizeof(int8_t)); // gun type + M_Skip(sizeof(uint16_t)); // flags } - Savegame_Legacy_Skip(sizeof(uint32_t)); // timer - Savegame_Legacy_Skip(sizeof(uint32_t)); // kills - Savegame_Legacy_Skip(sizeof(uint16_t)); // secrets - Savegame_Legacy_Skip(sizeof(uint16_t)); // current level - Savegame_Legacy_Skip(sizeof(uint8_t)); // pickups - Savegame_Legacy_Skip(sizeof(uint8_t)); // bonus_flag - Savegame_Legacy_Skip(sizeof(SAVEGAME_LEGACY_ITEM_STATS)); // item stats - Savegame_Legacy_Skip(sizeof(int32_t)); // flipmap status - Savegame_Legacy_Skip(MAX_FLIP_MAPS * sizeof(int8_t)); // flipmap table - Savegame_Legacy_Skip(g_NumberCameras * sizeof(int16_t)); // cameras + M_Skip(sizeof(uint32_t)); // timer + M_Skip(sizeof(uint32_t)); // kills + M_Skip(sizeof(uint16_t)); // secrets + M_Skip(sizeof(uint16_t)); // current level + M_Skip(sizeof(uint8_t)); // pickups + M_Skip(sizeof(uint8_t)); // bonus_flag + M_Skip(sizeof(SAVEGAME_LEGACY_ITEM_STATS)); // item stats + M_Skip(sizeof(int32_t)); // flipmap status + M_Skip(MAX_FLIP_MAPS * sizeof(int8_t)); // flipmap table + M_Skip(g_NumberCameras * sizeof(int16_t)); // cameras for (int i = 0; i < g_LevelItemCount; i++) { ITEM_INFO *item = &g_Items[i]; @@ -141,40 +141,36 @@ static bool Savegame_Legacy_NeedsBaconLaraFix(char *buffer) ITEM_INFO tmp_item; if (obj->save_position) { - Savegame_Legacy_Read(&tmp_item.pos.x, sizeof(int32_t)); - Savegame_Legacy_Read(&tmp_item.pos.y, sizeof(int32_t)); - Savegame_Legacy_Read(&tmp_item.pos.z, sizeof(int32_t)); - Savegame_Legacy_Read(&tmp_item.rot.x, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_item.rot.y, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_item.rot.z, sizeof(int16_t)); - Savegame_Legacy_Skip(sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_item.speed, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_item.fall_speed, sizeof(int16_t)); + M_Read(&tmp_item.pos.x, sizeof(int32_t)); + M_Read(&tmp_item.pos.y, sizeof(int32_t)); + M_Read(&tmp_item.pos.z, sizeof(int32_t)); + M_Read(&tmp_item.rot.x, sizeof(int16_t)); + M_Read(&tmp_item.rot.y, sizeof(int16_t)); + M_Read(&tmp_item.rot.z, sizeof(int16_t)); + M_Skip(sizeof(int16_t)); + M_Read(&tmp_item.speed, sizeof(int16_t)); + M_Read(&tmp_item.fall_speed, sizeof(int16_t)); } - if (Savegame_Legacy_ItemHasSaveAnim(item)) { - Savegame_Legacy_Read(&tmp_item.current_anim_state, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_item.goal_anim_state, sizeof(int16_t)); - Savegame_Legacy_Read( - &tmp_item.required_anim_state, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_item.anim_num, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_item.frame_num, sizeof(int16_t)); + if (M_ItemHasSaveAnim(item)) { + M_Read(&tmp_item.current_anim_state, sizeof(int16_t)); + M_Read(&tmp_item.goal_anim_state, sizeof(int16_t)); + M_Read(&tmp_item.required_anim_state, sizeof(int16_t)); + M_Read(&tmp_item.anim_num, sizeof(int16_t)); + M_Read(&tmp_item.frame_num, sizeof(int16_t)); } if (obj->save_hitpoints) { - Savegame_Legacy_Read(&tmp_item.hit_points, sizeof(int16_t)); + M_Read(&tmp_item.hit_points, sizeof(int16_t)); } - if (Savegame_Legacy_ItemHasSaveFlags(obj, item)) { - Savegame_Legacy_Read(&tmp_item.flags, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_item.timer, sizeof(int16_t)); + if (M_ItemHasSaveFlags(obj, item)) { + M_Read(&tmp_item.flags, sizeof(int16_t)); + M_Read(&tmp_item.timer, sizeof(int16_t)); if (tmp_item.flags & SAVE_CREATURE) { CREATURE_INFO tmp_creature; - Savegame_Legacy_Read( - &tmp_creature.head_rotation, sizeof(int16_t)); - Savegame_Legacy_Read( - &tmp_creature.neck_rotation, sizeof(int16_t)); - Savegame_Legacy_Read( - &tmp_creature.maximum_turn, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_creature.flags, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp_creature.mood, sizeof(int32_t)); + M_Read(&tmp_creature.head_rotation, sizeof(int16_t)); + M_Read(&tmp_creature.neck_rotation, sizeof(int16_t)); + M_Read(&tmp_creature.maximum_turn, sizeof(int16_t)); + M_Read(&tmp_creature.flags, sizeof(int16_t)); + M_Read(&tmp_creature.mood, sizeof(int32_t)); } } @@ -188,19 +184,19 @@ static bool Savegame_Legacy_NeedsBaconLaraFix(char *buffer) return result; } -static void Savegame_Legacy_Reset(char *buffer) +static void M_Reset(char *buffer) { m_SGBufPos = 0; m_SGBufPtr = buffer; } -static void Savegame_Legacy_Skip(int size) +static void M_Skip(int size) { m_SGBufPtr += size; m_SGBufPos += size; // missing from OG } -static void Savegame_Legacy_Write(const void *pointer, int size) +static void M_Write(const void *pointer, int size) { m_SGBufPos += size; if (m_SGBufPos >= SAVEGAME_LEGACY_MAX_BUFFER_SIZE) { @@ -213,106 +209,106 @@ static void Savegame_Legacy_Write(const void *pointer, int size) } } -static void Savegame_Legacy_WriteLara(LARA_INFO *lara) +static void M_WriteLara(LARA_INFO *lara) { int32_t tmp32 = 0; - Savegame_Legacy_Write(&lara->item_num, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->gun_status, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->gun_type, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->request_gun_type, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->calc_fall_speed, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->water_status, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->pose_count, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->hit_frame, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->hit_direction, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->air, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->dive_timer, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->death_timer, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->current_active, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->spaz_effect_count, sizeof(int16_t)); + M_Write(&lara->item_num, sizeof(int16_t)); + M_Write(&lara->gun_status, sizeof(int16_t)); + M_Write(&lara->gun_type, sizeof(int16_t)); + M_Write(&lara->request_gun_type, sizeof(int16_t)); + M_Write(&lara->calc_fall_speed, sizeof(int16_t)); + M_Write(&lara->water_status, sizeof(int16_t)); + M_Write(&lara->pose_count, sizeof(int16_t)); + M_Write(&lara->hit_frame, sizeof(int16_t)); + M_Write(&lara->hit_direction, sizeof(int16_t)); + M_Write(&lara->air, sizeof(int16_t)); + M_Write(&lara->dive_timer, sizeof(int16_t)); + M_Write(&lara->death_timer, sizeof(int16_t)); + M_Write(&lara->current_active, sizeof(int16_t)); + M_Write(&lara->spaz_effect_count, sizeof(int16_t)); // OG just writes the pointer address (!) if (lara->spaz_effect) { tmp32 = (size_t)lara->spaz_effect - (size_t)g_Effects; } - Savegame_Legacy_Write(&tmp32, sizeof(int32_t)); + M_Write(&tmp32, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->mesh_effects, sizeof(int32_t)); + M_Write(&lara->mesh_effects, sizeof(int32_t)); for (int i = 0; i < LM_NUMBER_OF; i++) { tmp32 = ((intptr_t)lara->mesh_ptrs[i] - (intptr_t)g_MeshBase); - Savegame_Legacy_Write(&tmp32, sizeof(int32_t)); + M_Write(&tmp32, sizeof(int32_t)); } // OG just writes the pointer address (!) assuming it's a non-existing mesh // 16 (!!) which happens to be g_Lara's current target. Just write NULL. tmp32 = 0; - Savegame_Legacy_Write(&tmp32, sizeof(int32_t)); - - Savegame_Legacy_Write(&lara->target_angles[0], sizeof(PHD_ANGLE)); - Savegame_Legacy_Write(&lara->target_angles[1], sizeof(PHD_ANGLE)); - Savegame_Legacy_Write(&lara->turn_rate, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->move_angle, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->head_rot.y, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->head_rot.x, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->head_rot.z, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->torso_rot.y, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->torso_rot.x, sizeof(int16_t)); - Savegame_Legacy_Write(&lara->torso_rot.z, sizeof(int16_t)); - - Savegame_Legacy_WriteArm(&lara->left_arm); - Savegame_Legacy_WriteArm(&lara->right_arm); - Savegame_Legacy_Write(&lara->pistols.ammo, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->pistols.hit, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->pistols.miss, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->magnums.ammo, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->magnums.hit, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->magnums.miss, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->uzis.ammo, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->uzis.hit, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->uzis.miss, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->shotgun.ammo, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->shotgun.hit, sizeof(int32_t)); - Savegame_Legacy_Write(&lara->shotgun.miss, sizeof(int32_t)); - Savegame_Legacy_WriteLOT(&lara->LOT); + M_Write(&tmp32, sizeof(int32_t)); + + M_Write(&lara->target_angles[0], sizeof(PHD_ANGLE)); + M_Write(&lara->target_angles[1], sizeof(PHD_ANGLE)); + M_Write(&lara->turn_rate, sizeof(int16_t)); + M_Write(&lara->move_angle, sizeof(int16_t)); + M_Write(&lara->head_rot.y, sizeof(int16_t)); + M_Write(&lara->head_rot.x, sizeof(int16_t)); + M_Write(&lara->head_rot.z, sizeof(int16_t)); + M_Write(&lara->torso_rot.y, sizeof(int16_t)); + M_Write(&lara->torso_rot.x, sizeof(int16_t)); + M_Write(&lara->torso_rot.z, sizeof(int16_t)); + + M_WriteArm(&lara->left_arm); + M_WriteArm(&lara->right_arm); + M_Write(&lara->pistols.ammo, sizeof(int32_t)); + M_Write(&lara->pistols.hit, sizeof(int32_t)); + M_Write(&lara->pistols.miss, sizeof(int32_t)); + M_Write(&lara->magnums.ammo, sizeof(int32_t)); + M_Write(&lara->magnums.hit, sizeof(int32_t)); + M_Write(&lara->magnums.miss, sizeof(int32_t)); + M_Write(&lara->uzis.ammo, sizeof(int32_t)); + M_Write(&lara->uzis.hit, sizeof(int32_t)); + M_Write(&lara->uzis.miss, sizeof(int32_t)); + M_Write(&lara->shotgun.ammo, sizeof(int32_t)); + M_Write(&lara->shotgun.hit, sizeof(int32_t)); + M_Write(&lara->shotgun.miss, sizeof(int32_t)); + M_WriteLOT(&lara->LOT); } -static void Savegame_Legacy_WriteArm(LARA_ARM *arm) +static void M_WriteArm(LARA_ARM *arm) { const LEVEL_INFO *const level_info = Level_GetInfo(); const int32_t frame_base = level_info->anim_frame_offsets[arm->frame_base - g_AnimFrames]; - Savegame_Legacy_Write(&frame_base, sizeof(int32_t)); - Savegame_Legacy_Write(&arm->frame_num, sizeof(int16_t)); - Savegame_Legacy_Write(&arm->lock, sizeof(int16_t)); - Savegame_Legacy_Write(&arm->rot.y, sizeof(PHD_ANGLE)); - Savegame_Legacy_Write(&arm->rot.x, sizeof(PHD_ANGLE)); - Savegame_Legacy_Write(&arm->rot.z, sizeof(PHD_ANGLE)); - Savegame_Legacy_Write(&arm->flash_gun, sizeof(int16_t)); + M_Write(&frame_base, sizeof(int32_t)); + M_Write(&arm->frame_num, sizeof(int16_t)); + M_Write(&arm->lock, sizeof(int16_t)); + M_Write(&arm->rot.y, sizeof(PHD_ANGLE)); + M_Write(&arm->rot.x, sizeof(PHD_ANGLE)); + M_Write(&arm->rot.z, sizeof(PHD_ANGLE)); + M_Write(&arm->flash_gun, sizeof(int16_t)); } -static void Savegame_Legacy_WriteLOT(LOT_INFO *lot) +static void M_WriteLOT(LOT_INFO *lot) { // it casually saves a pointer again! - Savegame_Legacy_Write(&lot->node, sizeof(int32_t)); - - Savegame_Legacy_Write(&lot->head, sizeof(int16_t)); - Savegame_Legacy_Write(&lot->tail, sizeof(int16_t)); - Savegame_Legacy_Write(&lot->search_num, sizeof(uint16_t)); - Savegame_Legacy_Write(&lot->block_mask, sizeof(uint16_t)); - Savegame_Legacy_Write(&lot->step, sizeof(int16_t)); - Savegame_Legacy_Write(&lot->drop, sizeof(int16_t)); - Savegame_Legacy_Write(&lot->fly, sizeof(int16_t)); - Savegame_Legacy_Write(&lot->zone_count, sizeof(int16_t)); - Savegame_Legacy_Write(&lot->target_box, sizeof(int16_t)); - Savegame_Legacy_Write(&lot->required_box, sizeof(int16_t)); - Savegame_Legacy_Write(&lot->target.x, sizeof(int32_t)); - Savegame_Legacy_Write(&lot->target.y, sizeof(int32_t)); - Savegame_Legacy_Write(&lot->target.z, sizeof(int32_t)); + M_Write(&lot->node, sizeof(int32_t)); + + M_Write(&lot->head, sizeof(int16_t)); + M_Write(&lot->tail, sizeof(int16_t)); + M_Write(&lot->search_num, sizeof(uint16_t)); + M_Write(&lot->block_mask, sizeof(uint16_t)); + M_Write(&lot->step, sizeof(int16_t)); + M_Write(&lot->drop, sizeof(int16_t)); + M_Write(&lot->fly, sizeof(int16_t)); + M_Write(&lot->zone_count, sizeof(int16_t)); + M_Write(&lot->target_box, sizeof(int16_t)); + M_Write(&lot->required_box, sizeof(int16_t)); + M_Write(&lot->target.x, sizeof(int32_t)); + M_Write(&lot->target.y, sizeof(int32_t)); + M_Write(&lot->target.z, sizeof(int32_t)); } -static void Savegame_Legacy_Read(void *pointer, int size) +static void M_Read(void *pointer, int size) { m_SGBufPos += size; char *data = (char *)pointer; @@ -320,99 +316,99 @@ static void Savegame_Legacy_Read(void *pointer, int size) *data++ = *m_SGBufPtr++; } -static void Savegame_Legacy_ReadLara(LARA_INFO *lara) +static void M_ReadLara(LARA_INFO *lara) { int32_t tmp32 = 0; - Savegame_Legacy_Read(&lara->item_num, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->gun_status, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->gun_type, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->request_gun_type, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->calc_fall_speed, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->water_status, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->pose_count, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->hit_frame, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->hit_direction, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->air, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->dive_timer, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->death_timer, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->current_active, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->spaz_effect_count, sizeof(int16_t)); + M_Read(&lara->item_num, sizeof(int16_t)); + M_Read(&lara->gun_status, sizeof(int16_t)); + M_Read(&lara->gun_type, sizeof(int16_t)); + M_Read(&lara->request_gun_type, sizeof(int16_t)); + M_Read(&lara->calc_fall_speed, sizeof(int16_t)); + M_Read(&lara->water_status, sizeof(int16_t)); + M_Read(&lara->pose_count, sizeof(int16_t)); + M_Read(&lara->hit_frame, sizeof(int16_t)); + M_Read(&lara->hit_direction, sizeof(int16_t)); + M_Read(&lara->air, sizeof(int16_t)); + M_Read(&lara->dive_timer, sizeof(int16_t)); + M_Read(&lara->death_timer, sizeof(int16_t)); + M_Read(&lara->current_active, sizeof(int16_t)); + M_Read(&lara->spaz_effect_count, sizeof(int16_t)); lara->spaz_effect = NULL; - Savegame_Legacy_Skip(4); // pointer to FX_INFO + M_Skip(4); // pointer to FX_INFO - Savegame_Legacy_Read(&lara->mesh_effects, sizeof(int32_t)); + M_Read(&lara->mesh_effects, sizeof(int32_t)); for (int i = 0; i < LM_NUMBER_OF; i++) { - Savegame_Legacy_Read(&tmp32, sizeof(int32_t)); + M_Read(&tmp32, sizeof(int32_t)); lara->mesh_ptrs[i] = (int16_t *)((intptr_t)g_MeshBase + (intptr_t)tmp32); } lara->target = NULL; - Savegame_Legacy_Skip(4); // pointer to ITEM_INFO - - Savegame_Legacy_Read(&lara->target_angles[0], sizeof(PHD_ANGLE)); - Savegame_Legacy_Read(&lara->target_angles[1], sizeof(PHD_ANGLE)); - Savegame_Legacy_Read(&lara->turn_rate, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->move_angle, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->head_rot.y, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->head_rot.x, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->head_rot.z, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->torso_rot.y, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->torso_rot.x, sizeof(int16_t)); - Savegame_Legacy_Read(&lara->torso_rot.z, sizeof(int16_t)); - - Savegame_Legacy_ReadArm(&lara->left_arm); - Savegame_Legacy_ReadArm(&lara->right_arm); - Savegame_Legacy_Read(&lara->pistols.ammo, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->pistols.hit, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->pistols.miss, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->magnums.ammo, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->magnums.hit, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->magnums.miss, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->uzis.ammo, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->uzis.hit, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->uzis.miss, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->shotgun.ammo, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->shotgun.hit, sizeof(int32_t)); - Savegame_Legacy_Read(&lara->shotgun.miss, sizeof(int32_t)); - Savegame_Legacy_ReadLOT(&lara->LOT); + M_Skip(4); // pointer to ITEM_INFO + + M_Read(&lara->target_angles[0], sizeof(PHD_ANGLE)); + M_Read(&lara->target_angles[1], sizeof(PHD_ANGLE)); + M_Read(&lara->turn_rate, sizeof(int16_t)); + M_Read(&lara->move_angle, sizeof(int16_t)); + M_Read(&lara->head_rot.y, sizeof(int16_t)); + M_Read(&lara->head_rot.x, sizeof(int16_t)); + M_Read(&lara->head_rot.z, sizeof(int16_t)); + M_Read(&lara->torso_rot.y, sizeof(int16_t)); + M_Read(&lara->torso_rot.x, sizeof(int16_t)); + M_Read(&lara->torso_rot.z, sizeof(int16_t)); + + M_ReadArm(&lara->left_arm); + M_ReadArm(&lara->right_arm); + M_Read(&lara->pistols.ammo, sizeof(int32_t)); + M_Read(&lara->pistols.hit, sizeof(int32_t)); + M_Read(&lara->pistols.miss, sizeof(int32_t)); + M_Read(&lara->magnums.ammo, sizeof(int32_t)); + M_Read(&lara->magnums.hit, sizeof(int32_t)); + M_Read(&lara->magnums.miss, sizeof(int32_t)); + M_Read(&lara->uzis.ammo, sizeof(int32_t)); + M_Read(&lara->uzis.hit, sizeof(int32_t)); + M_Read(&lara->uzis.miss, sizeof(int32_t)); + M_Read(&lara->shotgun.ammo, sizeof(int32_t)); + M_Read(&lara->shotgun.hit, sizeof(int32_t)); + M_Read(&lara->shotgun.miss, sizeof(int32_t)); + M_ReadLOT(&lara->LOT); } -static void Savegame_Legacy_ReadArm(LARA_ARM *arm) +static void M_ReadArm(LARA_ARM *arm) { // frame_base is superfluous - Savegame_Legacy_Skip(sizeof(int32_t)); - - Savegame_Legacy_Read(&arm->frame_num, sizeof(int16_t)); - Savegame_Legacy_Read(&arm->lock, sizeof(int16_t)); - Savegame_Legacy_Read(&arm->rot.y, sizeof(PHD_ANGLE)); - Savegame_Legacy_Read(&arm->rot.x, sizeof(PHD_ANGLE)); - Savegame_Legacy_Read(&arm->rot.z, sizeof(PHD_ANGLE)); - Savegame_Legacy_Read(&arm->flash_gun, sizeof(int16_t)); + M_Skip(sizeof(int32_t)); + + M_Read(&arm->frame_num, sizeof(int16_t)); + M_Read(&arm->lock, sizeof(int16_t)); + M_Read(&arm->rot.y, sizeof(PHD_ANGLE)); + M_Read(&arm->rot.x, sizeof(PHD_ANGLE)); + M_Read(&arm->rot.z, sizeof(PHD_ANGLE)); + M_Read(&arm->flash_gun, sizeof(int16_t)); } -static void Savegame_Legacy_ReadLOT(LOT_INFO *lot) +static void M_ReadLOT(LOT_INFO *lot) { - Savegame_Legacy_Skip(4); // pointer to BOX_NODE - - Savegame_Legacy_Read(&lot->head, sizeof(int16_t)); - Savegame_Legacy_Read(&lot->tail, sizeof(int16_t)); - Savegame_Legacy_Read(&lot->search_num, sizeof(uint16_t)); - Savegame_Legacy_Read(&lot->block_mask, sizeof(uint16_t)); - Savegame_Legacy_Read(&lot->step, sizeof(int16_t)); - Savegame_Legacy_Read(&lot->drop, sizeof(int16_t)); - Savegame_Legacy_Read(&lot->fly, sizeof(int16_t)); - Savegame_Legacy_Read(&lot->zone_count, sizeof(int16_t)); - Savegame_Legacy_Read(&lot->target_box, sizeof(int16_t)); - Savegame_Legacy_Read(&lot->required_box, sizeof(int16_t)); - Savegame_Legacy_Read(&lot->target.x, sizeof(int32_t)); - Savegame_Legacy_Read(&lot->target.y, sizeof(int32_t)); - Savegame_Legacy_Read(&lot->target.z, sizeof(int32_t)); + M_Skip(4); // pointer to BOX_NODE + + M_Read(&lot->head, sizeof(int16_t)); + M_Read(&lot->tail, sizeof(int16_t)); + M_Read(&lot->search_num, sizeof(uint16_t)); + M_Read(&lot->block_mask, sizeof(uint16_t)); + M_Read(&lot->step, sizeof(int16_t)); + M_Read(&lot->drop, sizeof(int16_t)); + M_Read(&lot->fly, sizeof(int16_t)); + M_Read(&lot->zone_count, sizeof(int16_t)); + M_Read(&lot->target_box, sizeof(int16_t)); + M_Read(&lot->required_box, sizeof(int16_t)); + M_Read(&lot->target.x, sizeof(int32_t)); + M_Read(&lot->target.y, sizeof(int32_t)); + M_Read(&lot->target.z, sizeof(int32_t)); } -static void Savegame_Legacy_SetCurrentPosition(int level_num) +static void M_SetCurrentPosition(int level_num) { for (int i = 0; i < g_GameFlow.level_count; i++) { if (g_GameFlow.levels[i].level_type == GFL_CURRENT) { @@ -421,24 +417,24 @@ static void Savegame_Legacy_SetCurrentPosition(int level_num) } } -static void Savegame_Legacy_ReadResumeInfo(MYFILE *fp, GAME_INFO *game_info) +static void M_ReadResumeInfo(MYFILE *fp, GAME_INFO *game_info) { assert(game_info->current); for (int i = 0; i < g_GameFlow.level_count; i++) { RESUME_INFO *current = &game_info->current[i]; - Savegame_Legacy_Read(¤t->pistol_ammo, sizeof(uint16_t)); - Savegame_Legacy_Read(¤t->magnum_ammo, sizeof(uint16_t)); - Savegame_Legacy_Read(¤t->uzi_ammo, sizeof(uint16_t)); - Savegame_Legacy_Read(¤t->shotgun_ammo, sizeof(uint16_t)); - Savegame_Legacy_Read(¤t->num_medis, sizeof(uint8_t)); - Savegame_Legacy_Read(¤t->num_big_medis, sizeof(uint8_t)); - Savegame_Legacy_Read(¤t->num_scions, sizeof(uint8_t)); - Savegame_Legacy_Read(¤t->gun_status, sizeof(int8_t)); - Savegame_Legacy_Read(¤t->equipped_gun_type, sizeof(int8_t)); + M_Read(¤t->pistol_ammo, sizeof(uint16_t)); + M_Read(¤t->magnum_ammo, sizeof(uint16_t)); + M_Read(¤t->uzi_ammo, sizeof(uint16_t)); + M_Read(¤t->shotgun_ammo, sizeof(uint16_t)); + M_Read(¤t->num_medis, sizeof(uint8_t)); + M_Read(¤t->num_big_medis, sizeof(uint8_t)); + M_Read(¤t->num_scions, sizeof(uint8_t)); + M_Read(¤t->gun_status, sizeof(int8_t)); + M_Read(¤t->equipped_gun_type, sizeof(int8_t)); current->holsters_gun_type = LGT_UNKNOWN; current->back_gun_type = LGT_UNKNOWN; uint16_t flags; - Savegame_Legacy_Read(&flags, sizeof(uint16_t)); + M_Read(&flags, sizeof(uint16_t)); current->flags.available = flags & 1 ? 1 : 0; current->flags.got_pistols = flags & 2 ? 1 : 0; current->flags.got_magnums = flags & 4 ? 1 : 0; @@ -454,18 +450,18 @@ static void Savegame_Legacy_ReadResumeInfo(MYFILE *fp, GAME_INFO *game_info) uint32_t temp_timer = 0; uint32_t temp_kill_count = 0; uint16_t temp_secret_flags = 0; - Savegame_Legacy_Read(&temp_timer, sizeof(uint32_t)); - Savegame_Legacy_Read(&temp_kill_count, sizeof(uint32_t)); - Savegame_Legacy_Read(&temp_secret_flags, sizeof(uint16_t)); - Savegame_Legacy_Read(&g_CurrentLevel, sizeof(uint16_t)); - Savegame_Legacy_SetCurrentPosition(g_CurrentLevel); + M_Read(&temp_timer, sizeof(uint32_t)); + M_Read(&temp_kill_count, sizeof(uint32_t)); + M_Read(&temp_secret_flags, sizeof(uint16_t)); + M_Read(&g_CurrentLevel, sizeof(uint16_t)); + M_SetCurrentPosition(g_CurrentLevel); game_info->current[g_CurrentLevel].stats.timer = temp_timer; game_info->current[g_CurrentLevel].stats.kill_count = temp_kill_count; game_info->current[g_CurrentLevel].stats.secret_flags = temp_secret_flags; - Savegame_Legacy_Read( + M_Read( &game_info->current[g_CurrentLevel].stats.pickup_count, sizeof(uint8_t)); - Savegame_Legacy_Read(&game_info->bonus_flag, sizeof(uint8_t)); + M_Read(&game_info->bonus_flag, sizeof(uint8_t)); game_info->death_counter_supported = false; } @@ -528,22 +524,22 @@ bool Savegame_Legacy_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) File_Seek(fp, 0, FILE_SEEK_SET); File_ReadData(fp, buffer, File_Size(fp)); - bool skip_reading_bacon_lara = Savegame_Legacy_NeedsBaconLaraFix(buffer); + bool skip_reading_bacon_lara = M_NeedsBaconLaraFix(buffer); if (skip_reading_bacon_lara) { LOG_INFO("Enabling Bacon Lara savegame fix"); } - Savegame_Legacy_Reset(buffer); - Savegame_Legacy_Skip(SAVEGAME_LEGACY_TITLE_SIZE); // level title - Savegame_Legacy_Skip(sizeof(int32_t)); // save counter + M_Reset(buffer); + M_Skip(SAVEGAME_LEGACY_TITLE_SIZE); // level title + M_Skip(sizeof(int32_t)); // save counter - Savegame_Legacy_ReadResumeInfo(fp, game_info); + M_ReadResumeInfo(fp, game_info); g_Lara.holsters_gun_type = LGT_UNKNOWN; g_Lara.back_gun_type = LGT_UNKNOWN; Lara_InitialiseInventory(g_CurrentLevel); SAVEGAME_LEGACY_ITEM_STATS item_stats = { 0 }; - Savegame_Legacy_Read(&item_stats, sizeof(SAVEGAME_LEGACY_ITEM_STATS)); + M_Read(&item_stats, sizeof(SAVEGAME_LEGACY_ITEM_STATS)); Inv_AddItemNTimes(O_PICKUP_ITEM_1, item_stats.num_pickup1); Inv_AddItemNTimes(O_PICKUP_ITEM_2, item_stats.num_pickup2); Inv_AddItemNTimes(O_PUZZLE_ITEM_1, item_stats.num_puzzle1); @@ -556,18 +552,18 @@ bool Savegame_Legacy_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) Inv_AddItemNTimes(O_KEY_ITEM_4, item_stats.num_key4); Inv_AddItemNTimes(O_LEADBAR_ITEM, item_stats.num_leadbar); - Savegame_Legacy_Read(&tmp32, sizeof(int32_t)); + M_Read(&tmp32, sizeof(int32_t)); if (tmp32) { Room_FlipMap(); } for (int i = 0; i < MAX_FLIP_MAPS; i++) { - Savegame_Legacy_Read(&tmp8, sizeof(int8_t)); + M_Read(&tmp8, sizeof(int8_t)); g_FlipMapTable[i] = tmp8 << 8; } for (int i = 0; i < g_NumberCameras; i++) { - Savegame_Legacy_Read(&g_Camera.fixed[i].flags, sizeof(int16_t)); + M_Read(&g_Camera.fixed[i].flags, sizeof(int16_t)); } Savegame_ProcessItemsBeforeLoad(); @@ -577,37 +573,37 @@ bool Savegame_Legacy_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) OBJECT_INFO *obj = &g_Objects[item->object_id]; if (obj->save_position) { - Savegame_Legacy_Read(&item->pos.x, sizeof(int32_t)); - Savegame_Legacy_Read(&item->pos.y, sizeof(int32_t)); - Savegame_Legacy_Read(&item->pos.z, sizeof(int32_t)); - Savegame_Legacy_Read(&item->rot.x, sizeof(int16_t)); - Savegame_Legacy_Read(&item->rot.y, sizeof(int16_t)); - Savegame_Legacy_Read(&item->rot.z, sizeof(int16_t)); - Savegame_Legacy_Read(&tmp16, sizeof(int16_t)); - Savegame_Legacy_Read(&item->speed, sizeof(int16_t)); - Savegame_Legacy_Read(&item->fall_speed, sizeof(int16_t)); + M_Read(&item->pos.x, sizeof(int32_t)); + M_Read(&item->pos.y, sizeof(int32_t)); + M_Read(&item->pos.z, sizeof(int32_t)); + M_Read(&item->rot.x, sizeof(int16_t)); + M_Read(&item->rot.y, sizeof(int16_t)); + M_Read(&item->rot.z, sizeof(int16_t)); + M_Read(&tmp16, sizeof(int16_t)); + M_Read(&item->speed, sizeof(int16_t)); + M_Read(&item->fall_speed, sizeof(int16_t)); if (item->room_num != tmp16) { Item_NewRoom(i, tmp16); } } - if (Savegame_Legacy_ItemHasSaveAnim(item)) { - Savegame_Legacy_Read(&item->current_anim_state, sizeof(int16_t)); - Savegame_Legacy_Read(&item->goal_anim_state, sizeof(int16_t)); - Savegame_Legacy_Read(&item->required_anim_state, sizeof(int16_t)); - Savegame_Legacy_Read(&item->anim_num, sizeof(int16_t)); - Savegame_Legacy_Read(&item->frame_num, sizeof(int16_t)); + if (M_ItemHasSaveAnim(item)) { + M_Read(&item->current_anim_state, sizeof(int16_t)); + M_Read(&item->goal_anim_state, sizeof(int16_t)); + M_Read(&item->required_anim_state, sizeof(int16_t)); + M_Read(&item->anim_num, sizeof(int16_t)); + M_Read(&item->frame_num, sizeof(int16_t)); } if (obj->save_hitpoints) { - Savegame_Legacy_Read(&item->hit_points, sizeof(int16_t)); + M_Read(&item->hit_points, sizeof(int16_t)); } if ((item->object_id != O_BACON_LARA || !skip_reading_bacon_lara) - && Savegame_Legacy_ItemHasSaveFlags(obj, item)) { - Savegame_Legacy_Read(&item->flags, sizeof(int16_t)); - Savegame_Legacy_Read(&item->timer, sizeof(int16_t)); + && M_ItemHasSaveFlags(obj, item)) { + M_Read(&item->flags, sizeof(int16_t)); + M_Read(&item->timer, sizeof(int16_t)); if (item->flags & IF_KILLED_ITEM) { Item_Kill(i); @@ -629,16 +625,13 @@ bool Savegame_Legacy_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) LOT_EnableBaddieAI(i, 1); CREATURE_INFO *creature = item->data; if (creature) { - Savegame_Legacy_Read( - &creature->head_rotation, sizeof(int16_t)); - Savegame_Legacy_Read( - &creature->neck_rotation, sizeof(int16_t)); - Savegame_Legacy_Read( - &creature->maximum_turn, sizeof(int16_t)); - Savegame_Legacy_Read(&creature->flags, sizeof(int16_t)); - Savegame_Legacy_Read(&creature->mood, sizeof(int32_t)); + M_Read(&creature->head_rotation, sizeof(int16_t)); + M_Read(&creature->neck_rotation, sizeof(int16_t)); + M_Read(&creature->maximum_turn, sizeof(int16_t)); + M_Read(&creature->flags, sizeof(int16_t)); + M_Read(&creature->mood, sizeof(int32_t)); } else { - Savegame_Legacy_Skip(4 * 2 + 4); + M_Skip(4 * 2 + 4); } } else if (obj->intelligent) { item->data = NULL; @@ -648,9 +641,9 @@ bool Savegame_Legacy_LoadFromFile(MYFILE *fp, GAME_INFO *game_info) Carrier_TestLegacyDrops(i); } - Savegame_Legacy_ReadLara(&g_Lara); - Savegame_Legacy_Read(&g_FlipEffect, sizeof(int32_t)); - Savegame_Legacy_Read(&g_FlipTimer, sizeof(int32_t)); + M_ReadLara(&g_Lara); + M_Read(&g_FlipEffect, sizeof(int32_t)); + M_Read(&g_FlipTimer, sizeof(int32_t)); Memory_FreePointer(&buffer); return true; } @@ -663,10 +656,10 @@ bool Savegame_Legacy_LoadOnlyResumeInfo(MYFILE *fp, GAME_INFO *game_info) File_Seek(fp, 0, FILE_SEEK_SET); File_ReadData(fp, buffer, File_Size(fp)); - Savegame_Legacy_Skip(SAVEGAME_LEGACY_TITLE_SIZE); // level title - Savegame_Legacy_Skip(sizeof(int32_t)); // save counter + M_Skip(SAVEGAME_LEGACY_TITLE_SIZE); // level title + M_Skip(sizeof(int32_t)); // save counter - Savegame_Legacy_ReadResumeInfo(fp, game_info); + M_ReadResumeInfo(fp, game_info); Memory_FreePointer(&buffer); return true; @@ -677,28 +670,28 @@ void Savegame_Legacy_SaveToFile(MYFILE *fp, GAME_INFO *game_info) assert(game_info); char *buffer = Memory_Alloc(SAVEGAME_LEGACY_MAX_BUFFER_SIZE); - Savegame_Legacy_Reset(buffer); + M_Reset(buffer); memset(m_SGBufPtr, 0, SAVEGAME_LEGACY_MAX_BUFFER_SIZE); char title[SAVEGAME_LEGACY_TITLE_SIZE]; snprintf( title, SAVEGAME_LEGACY_TITLE_SIZE, "%s", g_GameFlow.levels[g_CurrentLevel].level_title); - Savegame_Legacy_Write(title, SAVEGAME_LEGACY_TITLE_SIZE); - Savegame_Legacy_Write(&g_SaveCounter, sizeof(int32_t)); + M_Write(title, SAVEGAME_LEGACY_TITLE_SIZE); + M_Write(&g_SaveCounter, sizeof(int32_t)); assert(game_info->current); for (int i = 0; i < g_GameFlow.level_count; i++) { RESUME_INFO *current = &game_info->current[i]; - Savegame_Legacy_Write(¤t->pistol_ammo, sizeof(uint16_t)); - Savegame_Legacy_Write(¤t->magnum_ammo, sizeof(uint16_t)); - Savegame_Legacy_Write(¤t->uzi_ammo, sizeof(uint16_t)); - Savegame_Legacy_Write(¤t->shotgun_ammo, sizeof(uint16_t)); - Savegame_Legacy_Write(¤t->num_medis, sizeof(uint8_t)); - Savegame_Legacy_Write(¤t->num_big_medis, sizeof(uint8_t)); - Savegame_Legacy_Write(¤t->num_scions, sizeof(uint8_t)); - Savegame_Legacy_Write(¤t->gun_status, sizeof(int8_t)); - Savegame_Legacy_Write(¤t->equipped_gun_type, sizeof(int8_t)); + M_Write(¤t->pistol_ammo, sizeof(uint16_t)); + M_Write(¤t->magnum_ammo, sizeof(uint16_t)); + M_Write(¤t->uzi_ammo, sizeof(uint16_t)); + M_Write(¤t->shotgun_ammo, sizeof(uint16_t)); + M_Write(¤t->num_medis, sizeof(uint8_t)); + M_Write(¤t->num_big_medis, sizeof(uint8_t)); + M_Write(¤t->num_scions, sizeof(uint8_t)); + M_Write(¤t->gun_status, sizeof(int8_t)); + M_Write(¤t->equipped_gun_type, sizeof(int8_t)); uint16_t flags = 0; flags |= current->flags.available ? 1 : 0; flags |= current->flags.got_pistols ? 2 : 0; @@ -706,21 +699,20 @@ void Savegame_Legacy_SaveToFile(MYFILE *fp, GAME_INFO *game_info) flags |= current->flags.got_uzis ? 8 : 0; flags |= current->flags.got_shotgun ? 16 : 0; flags |= current->flags.costume ? 32 : 0; - Savegame_Legacy_Write(&flags, sizeof(uint16_t)); + M_Write(&flags, sizeof(uint16_t)); } - Savegame_Legacy_Write( - &game_info->current[g_CurrentLevel].stats.timer, sizeof(uint32_t)); - Savegame_Legacy_Write( + M_Write(&game_info->current[g_CurrentLevel].stats.timer, sizeof(uint32_t)); + M_Write( &game_info->current[g_CurrentLevel].stats.kill_count, sizeof(uint32_t)); - Savegame_Legacy_Write( + M_Write( &game_info->current[g_CurrentLevel].stats.secret_flags, sizeof(uint16_t)); - Savegame_Legacy_Write(&g_CurrentLevel, sizeof(uint16_t)); - Savegame_Legacy_Write( + M_Write(&g_CurrentLevel, sizeof(uint16_t)); + M_Write( &game_info->current[g_CurrentLevel].stats.pickup_count, sizeof(uint8_t)); - Savegame_Legacy_Write(&game_info->bonus_flag, sizeof(uint8_t)); + M_Write(&game_info->bonus_flag, sizeof(uint8_t)); SAVEGAME_LEGACY_ITEM_STATS item_stats = { .num_pickup1 = Inv_RequestItem(O_PICKUP_ITEM_1), @@ -737,16 +729,16 @@ void Savegame_Legacy_SaveToFile(MYFILE *fp, GAME_INFO *game_info) 0 }; - Savegame_Legacy_Write(&item_stats, sizeof(item_stats)); + M_Write(&item_stats, sizeof(item_stats)); - Savegame_Legacy_Write(&g_FlipStatus, sizeof(int32_t)); + M_Write(&g_FlipStatus, sizeof(int32_t)); for (int i = 0; i < MAX_FLIP_MAPS; i++) { int8_t flag = g_FlipMapTable[i] >> 8; - Savegame_Legacy_Write(&flag, sizeof(int8_t)); + M_Write(&flag, sizeof(int8_t)); } for (int i = 0; i < g_NumberCameras; i++) { - Savegame_Legacy_Write(&g_Camera.fixed[i].flags, sizeof(int16_t)); + M_Write(&g_Camera.fixed[i].flags, sizeof(int16_t)); } Savegame_ProcessItemsBeforeSave(); @@ -756,54 +748,52 @@ void Savegame_Legacy_SaveToFile(MYFILE *fp, GAME_INFO *game_info) OBJECT_INFO *obj = &g_Objects[item->object_id]; if (obj->save_position) { - Savegame_Legacy_Write(&item->pos.x, sizeof(int32_t)); - Savegame_Legacy_Write(&item->pos.y, sizeof(int32_t)); - Savegame_Legacy_Write(&item->pos.z, sizeof(int32_t)); - Savegame_Legacy_Write(&item->rot.x, sizeof(int16_t)); - Savegame_Legacy_Write(&item->rot.y, sizeof(int16_t)); - Savegame_Legacy_Write(&item->rot.z, sizeof(int16_t)); - Savegame_Legacy_Write(&item->room_num, sizeof(int16_t)); - Savegame_Legacy_Write(&item->speed, sizeof(int16_t)); - Savegame_Legacy_Write(&item->fall_speed, sizeof(int16_t)); + M_Write(&item->pos.x, sizeof(int32_t)); + M_Write(&item->pos.y, sizeof(int32_t)); + M_Write(&item->pos.z, sizeof(int32_t)); + M_Write(&item->rot.x, sizeof(int16_t)); + M_Write(&item->rot.y, sizeof(int16_t)); + M_Write(&item->rot.z, sizeof(int16_t)); + M_Write(&item->room_num, sizeof(int16_t)); + M_Write(&item->speed, sizeof(int16_t)); + M_Write(&item->fall_speed, sizeof(int16_t)); } - if (Savegame_Legacy_ItemHasSaveAnim(item)) { - Savegame_Legacy_Write(&item->current_anim_state, sizeof(int16_t)); - Savegame_Legacy_Write(&item->goal_anim_state, sizeof(int16_t)); - Savegame_Legacy_Write(&item->required_anim_state, sizeof(int16_t)); - Savegame_Legacy_Write(&item->anim_num, sizeof(int16_t)); - Savegame_Legacy_Write(&item->frame_num, sizeof(int16_t)); + if (M_ItemHasSaveAnim(item)) { + M_Write(&item->current_anim_state, sizeof(int16_t)); + M_Write(&item->goal_anim_state, sizeof(int16_t)); + M_Write(&item->required_anim_state, sizeof(int16_t)); + M_Write(&item->anim_num, sizeof(int16_t)); + M_Write(&item->frame_num, sizeof(int16_t)); } if (obj->save_hitpoints) { - Savegame_Legacy_Write(&item->hit_points, sizeof(int16_t)); + M_Write(&item->hit_points, sizeof(int16_t)); } - if (Savegame_Legacy_ItemHasSaveFlags(obj, item)) { + if (M_ItemHasSaveFlags(obj, item)) { uint16_t flags = item->flags + item->active + (item->status << 1) + (item->gravity << 3) + (item->collidable << 4); if (obj->intelligent && item->data) { flags |= SAVE_CREATURE; } - Savegame_Legacy_Write(&flags, sizeof(uint16_t)); - Savegame_Legacy_Write(&item->timer, sizeof(int16_t)); + M_Write(&flags, sizeof(uint16_t)); + M_Write(&item->timer, sizeof(int16_t)); if (flags & SAVE_CREATURE) { CREATURE_INFO *creature = item->data; - Savegame_Legacy_Write( - &creature->head_rotation, sizeof(int16_t)); - Savegame_Legacy_Write( - &creature->neck_rotation, sizeof(int16_t)); - Savegame_Legacy_Write(&creature->maximum_turn, sizeof(int16_t)); - Savegame_Legacy_Write(&creature->flags, sizeof(int16_t)); - Savegame_Legacy_Write(&creature->mood, sizeof(int32_t)); + M_Write(&creature->head_rotation, sizeof(int16_t)); + M_Write(&creature->neck_rotation, sizeof(int16_t)); + M_Write(&creature->maximum_turn, sizeof(int16_t)); + M_Write(&creature->flags, sizeof(int16_t)); + M_Write(&creature->mood, sizeof(int32_t)); } } } - Savegame_Legacy_WriteLara(&g_Lara); + M_WriteLara(&g_Lara); - Savegame_Legacy_Write(&g_FlipEffect, sizeof(int32_t)); - Savegame_Legacy_Write(&g_FlipTimer, sizeof(int32_t)); + M_Write(&g_FlipEffect, sizeof(int32_t)); + M_Write(&g_FlipTimer, sizeof(int32_t)); File_WriteData(fp, buffer, m_SGBufPos); Memory_FreePointer(&buffer); diff --git a/src/game/screen.c b/src/game/screen.c index bc801bc53..96e0544e7 100644 --- a/src/game/screen.c +++ b/src/game/screen.c @@ -30,11 +30,11 @@ static RESOLUTION m_Resolutions[] = { // clang-format on }; -static void Screen_ApplyResolution(void); -static int32_t Screen_GetRenderScaleBase( +static void M_ApplyResolution(void); +static int32_t M_GetRenderScaleBase( int32_t unit, int32_t base_width, int32_t base_height, double factor); -static void Screen_ApplyResolution(void) +static void M_ApplyResolution(void) { int32_t width = Screen_GetResWidth(); int32_t height = Screen_GetResHeight(); @@ -46,7 +46,7 @@ static void Screen_ApplyResolution(void) Viewport_SetFOV(Viewport_GetUserFOV()); } -static int32_t Screen_GetRenderScaleBase( +static int32_t M_GetRenderScaleBase( int32_t unit, int32_t base_width, int32_t base_height, double factor) { int32_t scale_x = Screen_GetResWidth() > base_width @@ -99,7 +99,7 @@ void Screen_Init(void) m_ResolutionIdx = 0; } - Screen_ApplyResolution(); + M_ApplyResolution(); } int32_t Screen_GetResWidth(void) @@ -126,12 +126,11 @@ int32_t Screen_GetResHeightDownscaled(RENDER_SCALE_REF ref) int32_t Screen_GetRenderScale(int32_t unit, RENDER_SCALE_REF ref) { if (ref == RSR_TEXT) { - return Screen_GetRenderScaleBase( - unit, 640, 480, g_Config.ui.text_scale); + return M_GetRenderScaleBase(unit, 640, 480, g_Config.ui.text_scale); } else if (ref == RSR_BAR) { - return Screen_GetRenderScaleBase(unit, 640, 480, g_Config.ui.bar_scale); + return M_GetRenderScaleBase(unit, 640, 480, g_Config.ui.bar_scale); } else { - return Screen_GetRenderScaleBase(unit, 640, 480, 0); + return M_GetRenderScaleBase(unit, 640, 480, 0); } } @@ -164,7 +163,7 @@ bool Screen_SetPrevRes(void) { if (m_ResolutionIdx - 1 >= 0) { m_ResolutionIdx--; - Screen_ApplyResolution(); + M_ApplyResolution(); return true; } return false; @@ -174,7 +173,7 @@ bool Screen_SetNextRes(void) { if (m_ResolutionIdx + 1 < m_ResolutionsCount) { m_ResolutionIdx++; - Screen_ApplyResolution(); + M_ApplyResolution(); return true; } return false; diff --git a/src/game/shell.c b/src/game/shell.c index 0322be2dd..c8c69dd57 100644 --- a/src/game/shell.c +++ b/src/game/shell.c @@ -39,9 +39,9 @@ static const char m_TR1XGameflowPath[] = "cfg/TR1X_gameflow.json5"; static const char m_TR1XGameflowGoldPath[] = "cfg/TR1X_gameflow_ub.json5"; static const char m_TR1XGameflowDemoPath[] = "cfg/TR1X_gameflow_demo_pc.json5"; -static char *Shell_GetScreenshotName(void); +static char *M_GetScreenshotName(void); -static char *Shell_GetScreenshotName(void) +static char *M_GetScreenshotName(void) { // Get level title of unknown length char level_title[100]; @@ -346,7 +346,7 @@ bool Shell_MakeScreenshot(void) { File_CreateDirectory(SCREENSHOTS_DIR); - char *filename = Shell_GetScreenshotName(); + char *filename = M_GetScreenshotName(); const char *ext; switch (g_Config.screenshot_format) { diff --git a/src/game/sound.c b/src/game/sound.c index 0e58457fd..d879c4ff0 100644 --- a/src/game/sound.c +++ b/src/game/sound.c @@ -58,21 +58,25 @@ static int32_t m_AmbientLookupIdx = 0; static int m_DecibelLUT[DECIBEL_LUT_SIZE] = { 0 }; static bool m_SoundIsActive = false; -static SOUND_SLOT *Sound_GetSlot( +static int32_t M_ConvertVolumeToDecibel(int volume); +static int32_t M_ConvertPanToDecibel(uint16_t pan); +static float M_CalcPitch(int pitch); + +static SOUND_SLOT *M_GetSlot( int32_t sfx_num, uint32_t loudness, const XYZ_32 *pos, int16_t mode); -static void Sound_UpdateSlotParams(SOUND_SLOT *slot); -static void Sound_ClearSlot(SOUND_SLOT *slot); -static void Sound_ClearSlotHandles(SOUND_SLOT *slot); -static void Sound_ResetAmbientLoudness(void); +static void M_UpdateSlotParams(SOUND_SLOT *slot); +static void M_ClearSlot(SOUND_SLOT *slot); +static void M_ClearSlotHandles(SOUND_SLOT *slot); +static void M_ResetAmbientLoudness(void); -static int32_t Sound_ConvertVolumeToDecibel(int volume) +static int32_t M_ConvertVolumeToDecibel(int volume) { return m_DecibelLUT [(volume & SOUND_MAX_VOLUME) * DECIBEL_LUT_SIZE / (SOUND_MAX_VOLUME + 1)]; } -static int32_t Sound_ConvertPanToDecibel(uint16_t pan) +static int32_t M_ConvertPanToDecibel(uint16_t pan) { int32_t result = sin((pan / 32767.0) * M_PI) * (DECIBEL_LUT_SIZE / 2); if (result > 0) { @@ -84,12 +88,12 @@ static int32_t Sound_ConvertPanToDecibel(uint16_t pan) } } -static float Sound_CalcPitch(int pitch) +static float M_CalcPitch(int pitch) { return pitch / 100.0f; } -static SOUND_SLOT *Sound_GetSlot( +static SOUND_SLOT *M_GetSlot( int32_t sfx_num, uint32_t loudness, const XYZ_32 *pos, int16_t mode) { switch (mode) { @@ -126,7 +130,7 @@ static SOUND_SLOT *Sound_GetSlot( return NULL; } -static void Sound_UpdateSlotParams(SOUND_SLOT *slot) +static void M_UpdateSlotParams(SOUND_SLOT *slot) { SAMPLE_INFO *s = &g_SampleInfos[g_SampleLUT[slot->fxnum]]; @@ -162,7 +166,7 @@ static void Sound_UpdateSlotParams(SOUND_SLOT *slot) slot->pan = angle; } -static void Sound_ClearSlot(SOUND_SLOT *slot) +static void M_ClearSlot(SOUND_SLOT *slot) { slot->sound_id = AUDIO_NO_SOUND; slot->pos = NULL; @@ -173,7 +177,7 @@ static void Sound_ClearSlot(SOUND_SLOT *slot) slot->fxnum = -1; } -static void Sound_ClearSlotHandles(SOUND_SLOT *slot) +static void M_ClearSlotHandles(SOUND_SLOT *slot) { for (int i = 0; i < MAX_PLAYING_FX; i++) { SOUND_SLOT *rslot = &m_SFXPlaying[i]; @@ -183,7 +187,7 @@ static void Sound_ClearSlotHandles(SOUND_SLOT *slot) } } -static void Sound_ResetAmbientLoudness(void) +static void M_ResetAmbientLoudness(void) { if (!m_SoundIsActive) { return; @@ -229,36 +233,36 @@ void Sound_UpdateEffects(void) if (slot->loudness != (uint32_t)SOUND_NOT_AUDIBLE && slot->sound_id != AUDIO_NO_SOUND) { Audio_Sample_SetPan( - slot->sound_id, Sound_ConvertPanToDecibel(slot->pan)); + slot->sound_id, M_ConvertPanToDecibel(slot->pan)); Audio_Sample_SetVolume( slot->sound_id, - Sound_ConvertVolumeToDecibel( + M_ConvertVolumeToDecibel( (m_MasterVolume * slot->volume) >> 6)); } else { if (slot->sound_id != AUDIO_NO_SOUND) { Audio_Sample_Close(slot->sound_id); } - Sound_ClearSlot(slot); + M_ClearSlot(slot); } } else if (Audio_Sample_IsPlaying(slot->sound_id)) { if (slot->pos != NULL) { - Sound_UpdateSlotParams(slot); + M_UpdateSlotParams(slot); if (slot->volume > 0 && slot->sound_id != AUDIO_NO_SOUND) { Audio_Sample_SetPan( - slot->sound_id, Sound_ConvertPanToDecibel(slot->pan)); + slot->sound_id, M_ConvertPanToDecibel(slot->pan)); Audio_Sample_SetVolume( slot->sound_id, - Sound_ConvertVolumeToDecibel( + M_ConvertVolumeToDecibel( (m_MasterVolume * slot->volume) >> 6)); } else { if (slot->sound_id != AUDIO_NO_SOUND) { Audio_Sample_Close(slot->sound_id); } - Sound_ClearSlot(slot); + M_ClearSlot(slot); } } } else { - Sound_ClearSlot(slot); + M_ClearSlot(slot); } } } @@ -344,7 +348,7 @@ bool Sound_Effect(int32_t sfx_num, const XYZ_32 *pos, uint32_t flags) switch (mode) { case SOUND_MODE_WAIT: { - SOUND_SLOT *fxslot = Sound_GetSlot(sfx_num, 0, pos, mode); + SOUND_SLOT *fxslot = M_GetSlot(sfx_num, 0, pos, mode); if (!fxslot) { return false; } @@ -353,12 +357,12 @@ bool Sound_Effect(int32_t sfx_num, const XYZ_32 *pos, uint32_t flags) return true; } fxslot->sound_id = Audio_Sample_Play( - sfx_id, Sound_ConvertVolumeToDecibel(volume), - Sound_CalcPitch(pitch), Sound_ConvertPanToDecibel(pan), false); + sfx_id, M_ConvertVolumeToDecibel(volume), M_CalcPitch(pitch), + M_ConvertPanToDecibel(pan), false); if (fxslot->sound_id == AUDIO_NO_SOUND) { return false; } - Sound_ClearSlotHandles(fxslot); + M_ClearSlotHandles(fxslot); fxslot->flags = SOUND_FLAG_USED; fxslot->fxnum = sfx_num; fxslot->pos = pos; @@ -366,26 +370,26 @@ bool Sound_Effect(int32_t sfx_num, const XYZ_32 *pos, uint32_t flags) } case SOUND_MODE_RESTART: { - SOUND_SLOT *fxslot = Sound_GetSlot(sfx_num, 0, pos, mode); + SOUND_SLOT *fxslot = M_GetSlot(sfx_num, 0, pos, mode); if (!fxslot) { return false; } if (fxslot->flags & SOUND_FLAG_RESTARTED) { Audio_Sample_Close(fxslot->sound_id); fxslot->sound_id = Audio_Sample_Play( - sfx_id, Sound_ConvertVolumeToDecibel(volume), - Sound_CalcPitch(pitch), Sound_ConvertPanToDecibel(pan), false); + sfx_id, M_ConvertVolumeToDecibel(volume), M_CalcPitch(pitch), + M_ConvertPanToDecibel(pan), false); - Sound_ClearSlotHandles(fxslot); + M_ClearSlotHandles(fxslot); return true; } fxslot->sound_id = Audio_Sample_Play( - sfx_id, Sound_ConvertVolumeToDecibel(volume), - Sound_CalcPitch(pitch), Sound_ConvertPanToDecibel(pan), false); + sfx_id, M_ConvertVolumeToDecibel(volume), M_CalcPitch(pitch), + M_ConvertPanToDecibel(pan), false); if (fxslot->sound_id == AUDIO_NO_SOUND) { return false; } - Sound_ClearSlotHandles(fxslot); + M_ClearSlotHandles(fxslot); fxslot->flags = SOUND_FLAG_USED; fxslot->fxnum = sfx_num; fxslot->pos = pos; @@ -394,7 +398,7 @@ bool Sound_Effect(int32_t sfx_num, const XYZ_32 *pos, uint32_t flags) case SOUND_MODE_AMBIENT: { uint32_t loudness = distance; - SOUND_SLOT *fxslot = Sound_GetSlot(sfx_num, loudness, pos, mode); + SOUND_SLOT *fxslot = M_GetSlot(sfx_num, loudness, pos, mode); if (!fxslot) { return false; } @@ -413,13 +417,13 @@ bool Sound_Effect(int32_t sfx_num, const XYZ_32 *pos, uint32_t flags) if (volume > 0) { fxslot->sound_id = Audio_Sample_Play( - sfx_id, Sound_ConvertVolumeToDecibel(volume), - Sound_CalcPitch(pitch), Sound_ConvertPanToDecibel(pan), true); + sfx_id, M_ConvertVolumeToDecibel(volume), M_CalcPitch(pitch), + M_ConvertPanToDecibel(pan), true); if (fxslot->sound_id == AUDIO_NO_SOUND) { - Sound_ClearSlot(fxslot); + M_ClearSlot(fxslot); return false; } - Sound_ClearSlotHandles(fxslot); + M_ClearSlotHandles(fxslot); fxslot->loudness = loudness; fxslot->fxnum = sfx_num; fxslot->pan = pan; @@ -451,7 +455,7 @@ bool Sound_StopEffect(int32_t sfx_num, const XYZ_32 *pos) || (pos && sfx_num >= 0 && slot->fxnum == sfx_num) || (pos && sfx_num < 0)) { Audio_Sample_Close(slot->sound_id); - Sound_ClearSlot(slot); + M_ClearSlot(slot); return true; } } @@ -468,7 +472,7 @@ void Sound_ResetEffects(void) m_MasterVolume = m_MasterVolumeDefault; for (int i = 0; i < MAX_PLAYING_FX; i++) { - Sound_ClearSlot(&m_SFXPlaying[i]); + M_ClearSlot(&m_SFXPlaying[i]); } Sound_StopAllSamples(); @@ -508,7 +512,7 @@ void Sound_StopAmbientSounds(void) SOUND_SLOT *slot = &m_SFXPlaying[i]; if (Audio_Sample_IsPlaying(slot->sound_id)) { Audio_Sample_Close(slot->sound_id); - Sound_ClearSlot(slot); + M_ClearSlot(slot); } } } @@ -558,7 +562,7 @@ int32_t Sound_GetMaxVolume(void) void Sound_ResetAmbient(void) { - Sound_ResetAmbientLoudness(); + M_ResetAmbientLoudness(); for (int i = 0; i < g_NumberSoundEffects; i++) { OBJECT_VECTOR *sound = &g_SoundEffectsTable[i]; diff --git a/src/game/stats.c b/src/game/stats.c index e7342cbb4..4d88f12b9 100644 --- a/src/game/stats.c +++ b/src/game/stats.c @@ -32,12 +32,12 @@ static struct { int32_t start_timer; } m_StatsTimer = { 0 }; -static void Stats_TraverseFloor(void); -static void Stats_CheckTriggers( +static void M_TraverseFloor(void); +static void M_CheckTriggers( ROOM_INFO *r, int room_num, int z_sector, int x_sector); -static void Stats_IncludeKillableItem(int16_t item_num); +static void M_IncludeKillableItem(int16_t item_num); -static void Stats_TraverseFloor(void) +static void M_TraverseFloor(void) { uint32_t secrets = 0; @@ -45,13 +45,13 @@ static void Stats_TraverseFloor(void) ROOM_INFO *r = &g_RoomInfo[i]; for (int z_sector = 0; z_sector < r->z_size; z_sector++) { for (int x_sector = 0; x_sector < r->x_size; x_sector++) { - Stats_CheckTriggers(r, i, z_sector, x_sector); + M_CheckTriggers(r, i, z_sector, x_sector); } } } } -static void Stats_CheckTriggers( +static void M_CheckTriggers( ROOM_INFO *r, int room_num, int z_sector, int x_sector) { if (z_sector == 0 || z_sector == r->z_size - 1) { @@ -87,7 +87,7 @@ static void Stats_CheckTriggers( if (item->object_id == O_PIERRE) { // Add Pierre pickup and kills if oneshot if (sector->trigger->one_shot) { - Stats_IncludeKillableItem(item_num); + M_IncludeKillableItem(item_num); } continue; } @@ -98,7 +98,7 @@ static void Stats_CheckTriggers( const int16_t bug_item_num = *(int16_t *)item->data; const ITEM_INFO *const bug_item = &g_Items[bug_item_num]; if (g_Objects[bug_item->object_id].loaded) { - Stats_IncludeKillableItem(item_num); + M_IncludeKillableItem(item_num); } } continue; @@ -106,13 +106,13 @@ static void Stats_CheckTriggers( // Add killable if object triggered if (Object_IsObjectType(item->object_id, g_EnemyObjects)) { - Stats_IncludeKillableItem(item_num); + M_IncludeKillableItem(item_num); } } } } -static void Stats_IncludeKillableItem(int16_t item_num) +static void M_IncludeKillableItem(int16_t item_num) { m_KillableItems[item_num] = true; m_LevelKillables += 1; @@ -201,7 +201,7 @@ void Stats_CalculateStats(void) } // Check triggers for special pickups / killables - Stats_TraverseFloor(); + M_TraverseFloor(); m_LevelPickups -= g_GameFlow.levels[g_CurrentLevel].unobtainable.pickups; m_LevelKillables -= g_GameFlow.levels[g_CurrentLevel].unobtainable.kills; diff --git a/src/game/text.c b/src/game/text.c index eb863398c..7d5b0caa4 100644 --- a/src/game/text.c +++ b/src/game/text.c @@ -91,15 +91,15 @@ typedef struct QUAD_INFO { int32_t h; } QUAD_INFO; -static uint8_t Text_MapLetterToSpriteNum(char letter); -static void Text_DrawTextBackground( +static uint8_t M_MapLetterToSpriteNum(char letter); +static void M_DrawTextBackground( UI_STYLE ui_style, int32_t sx, int32_t sy, int32_t w, int32_t h, TEXT_STYLE text_style); -static void Text_DrawTextOutline( +static void M_DrawTextOutline( UI_STYLE ui_style, int32_t sx, int32_t sy, int32_t w, int32_t h, TEXT_STYLE text_style); -static void Text_DrawTextBackground( +static void M_DrawTextBackground( UI_STYLE ui_style, int32_t sx, int32_t sy, int32_t w, int32_t h, TEXT_STYLE text_style) { @@ -137,7 +137,7 @@ static void Text_DrawTextBackground( } } -static void Text_DrawTextOutline( +static void M_DrawTextOutline( UI_STYLE ui_style, int32_t sx, int32_t sy, int32_t w, int32_t h, TEXT_STYLE text_style) { @@ -168,7 +168,7 @@ static void Text_DrawTextOutline( } } -static uint8_t Text_MapLetterToSpriteNum(char letter) +static uint8_t M_MapLetterToSpriteNum(char letter) { if (letter >= 16) { return m_TextASCIIMap[letter - 32]; @@ -446,7 +446,7 @@ int32_t Text_GetWidth(TEXTSTRING *textstring) continue; } - uint8_t sprite_num = Text_MapLetterToSpriteNum(letter); + uint8_t sprite_num = M_MapLetterToSpriteNum(letter); width += ((m_TextSpacing[sprite_num] + textstring->letter_spacing) * textstring->scale.h) / PHD_ONE; @@ -535,7 +535,7 @@ void Text_DrawText(TEXTSTRING *textstring) continue; } - uint8_t sprite_num = Text_MapLetterToSpriteNum(letter); + uint8_t sprite_num = M_MapLetterToSpriteNum(letter); sx = Screen_GetRenderScale(x, RSR_TEXT); sy = Screen_GetRenderScale(y, RSR_TEXT); sh = Screen_GetRenderScale(textstring->scale.h, RSR_TEXT); @@ -577,7 +577,7 @@ void Text_DrawText(TEXTSTRING *textstring) sh = Screen_GetRenderScale(bwidth, RSR_TEXT); sv = Screen_GetRenderScale(bheight, RSR_TEXT); - Text_DrawTextBackground( + M_DrawTextBackground( g_Config.ui.menu_style, sx, sy, sh, sv, textstring->background.style); } @@ -592,7 +592,7 @@ void Text_DrawText(TEXTSTRING *textstring) sh = Screen_GetRenderScale(bwidth, RSR_TEXT); sv = Screen_GetRenderScale(bheight, RSR_TEXT); - Text_DrawTextOutline( + M_DrawTextOutline( g_Config.ui.menu_style, sx, sy, sh, sv, textstring->outline.style); } } diff --git a/src/specific/s_fmv.c b/src/specific/s_fmv.c index 5d081ba33..489e9a151 100644 --- a/src/specific/s_fmv.c +++ b/src/specific/s_fmv.c @@ -300,14 +300,14 @@ static const struct TextureFormatEntry { { AV_PIX_FMT_NONE, SDL_PIXELFORMAT_UNKNOWN }, }; -static int S_FMV_GetAudioVolume(void) +static int M_GetAudioVolume(void) { const float volume_dbl = g_Config.sound_volume / (float)Sound_GetMaxVolume(); return volume_dbl * SDL_MIX_MAXVOLUME; } -static int S_FMV_PacketQueuePutPrivate(PacketQueue *q, AVPacket *pkt) +static int M_PacketQueuePutPrivate(PacketQueue *q, AVPacket *pkt) { MyAVPacketList pkt1; @@ -332,7 +332,7 @@ static int S_FMV_PacketQueuePutPrivate(PacketQueue *q, AVPacket *pkt) return 0; } -static int S_FMV_PacketQueuePut(PacketQueue *q, AVPacket *pkt) +static int M_PacketQueuePut(PacketQueue *q, AVPacket *pkt) { AVPacket *pkt1; int ret; @@ -345,7 +345,7 @@ static int S_FMV_PacketQueuePut(PacketQueue *q, AVPacket *pkt) av_packet_move_ref(pkt1, pkt); SDL_LockMutex(q->mutex); - ret = S_FMV_PacketQueuePutPrivate(q, pkt1); + ret = M_PacketQueuePutPrivate(q, pkt1); SDL_UnlockMutex(q->mutex); if (ret < 0) { @@ -355,14 +355,14 @@ static int S_FMV_PacketQueuePut(PacketQueue *q, AVPacket *pkt) return ret; } -static int S_FMV_PacketQueuePutNullPacket( +static int M_PacketQueuePutNullPacket( PacketQueue *q, AVPacket *pkt, int stream_index) { pkt->stream_index = stream_index; - return S_FMV_PacketQueuePut(q, pkt); + return M_PacketQueuePut(q, pkt); } -static int S_FMV_PacketQueueInit(PacketQueue *q) +static int M_PacketQueueInit(PacketQueue *q) { memset(q, 0, sizeof(PacketQueue)); q->pkt_list = av_fifo_alloc(sizeof(MyAVPacketList)); @@ -386,7 +386,7 @@ static int S_FMV_PacketQueueInit(PacketQueue *q) return 0; } -static void S_FMV_PacketQueueFlush(PacketQueue *q) +static void M_PacketQueueFlush(PacketQueue *q) { MyAVPacketList pkt1; @@ -402,15 +402,15 @@ static void S_FMV_PacketQueueFlush(PacketQueue *q) SDL_UnlockMutex(q->mutex); } -static void S_FMV_PacketQueueDestroy(PacketQueue *q) +static void M_PacketQueueDestroy(PacketQueue *q) { - S_FMV_PacketQueueFlush(q); + M_PacketQueueFlush(q); av_fifo_freep(&q->pkt_list); SDL_DestroyMutex(q->mutex); SDL_DestroyCond(q->cond); } -static void S_FMV_PacketQueueAbort(PacketQueue *q) +static void M_PacketQueueAbort(PacketQueue *q) { SDL_LockMutex(q->mutex); q->abort_request = true; @@ -418,7 +418,7 @@ static void S_FMV_PacketQueueAbort(PacketQueue *q) SDL_UnlockMutex(q->mutex); } -static void S_FMV_PacketQueueStart(PacketQueue *q) +static void M_PacketQueueStart(PacketQueue *q) { SDL_LockMutex(q->mutex); q->abort_request = false; @@ -426,7 +426,7 @@ static void S_FMV_PacketQueueStart(PacketQueue *q) SDL_UnlockMutex(q->mutex); } -static int S_FMV_PacketQueueGet( +static int M_PacketQueueGet( PacketQueue *q, AVPacket *pkt, int block, int *serial) { MyAVPacketList pkt1; @@ -463,7 +463,7 @@ static int S_FMV_PacketQueueGet( return ret; } -static int S_FMV_DecoderInit( +static int M_DecoderInit( Decoder *d, AVCodecContext *avctx, PacketQueue *queue, SDL_cond *empty_queue_cond) { @@ -480,7 +480,7 @@ static int S_FMV_DecoderInit( return 0; } -static int S_FMV_DecoderDecodeFrame(Decoder *d, AVFrame *frame, AVSubtitle *sub) +static int M_DecoderDecodeFrame(Decoder *d, AVFrame *frame, AVSubtitle *sub) { int ret = AVERROR(EAGAIN); @@ -540,8 +540,7 @@ static int S_FMV_DecoderDecodeFrame(Decoder *d, AVFrame *frame, AVSubtitle *sub) d->packet_pending = false; } else { int old_serial = d->pkt_serial; - if (S_FMV_PacketQueueGet(d->queue, d->pkt, 1, &d->pkt_serial) - < 0) { + if (M_PacketQueueGet(d->queue, d->pkt, 1, &d->pkt_serial) < 0) { return -1; } if (old_serial != d->pkt_serial) { @@ -582,19 +581,19 @@ static int S_FMV_DecoderDecodeFrame(Decoder *d, AVFrame *frame, AVSubtitle *sub) } } -static void S_FMV_DecoderShutdown(Decoder *d) +static void M_DecoderShutdown(Decoder *d) { av_packet_free(&d->pkt); avcodec_free_context(&d->avctx); } -static void S_FMV_FrameQueueUnrefItem(Frame *vp) +static void M_FrameQueueUnrefItem(Frame *vp) { av_frame_unref(vp->frame); avsubtitle_free(&vp->sub); } -static int S_FMV_FrameQueueInit( +static int M_FrameQueueInit( FrameQueue *f, PacketQueue *pktq, int max_size, int keep_last) { memset(f, 0, sizeof(FrameQueue)); @@ -617,40 +616,40 @@ static int S_FMV_FrameQueueInit( return 0; } -static void S_FMV_FrameQueueShutdown(FrameQueue *f) +static void M_FrameQueueShutdown(FrameQueue *f) { for (int i = 0; i < f->max_size; i++) { Frame *vp = &f->queue[i]; - S_FMV_FrameQueueUnrefItem(vp); + M_FrameQueueUnrefItem(vp); av_frame_free(&vp->frame); } SDL_DestroyMutex(f->mutex); SDL_DestroyCond(f->cond); } -static void S_FMV_FrameQueueSignal(FrameQueue *f) +static void M_FrameQueueSignal(FrameQueue *f) { SDL_LockMutex(f->mutex); SDL_CondSignal(f->cond); SDL_UnlockMutex(f->mutex); } -static Frame *S_FMV_FrameQueuePeek(FrameQueue *f) +static Frame *M_FrameQueuePeek(FrameQueue *f) { return &f->queue[(f->rindex + f->rindex_shown) % f->max_size]; } -static Frame *S_FMV_FrameQueuePeekNext(FrameQueue *f) +static Frame *M_FrameQueuePeekNext(FrameQueue *f) { return &f->queue[(f->rindex + f->rindex_shown + 1) % f->max_size]; } -static Frame *S_FMV_FrameQueuePeekLast(FrameQueue *f) +static Frame *M_FrameQueuePeekLast(FrameQueue *f) { return &f->queue[f->rindex]; } -static Frame *S_FMV_FrameQueuePeekWritable(FrameQueue *f) +static Frame *M_FrameQueuePeekWritable(FrameQueue *f) { SDL_LockMutex(f->mutex); while (f->size >= f->max_size && !f->pktq->abort_request) { @@ -665,7 +664,7 @@ static Frame *S_FMV_FrameQueuePeekWritable(FrameQueue *f) return &f->queue[f->windex]; } -static Frame *S_FMV_FrameQueuePeekReadable(FrameQueue *f) +static Frame *M_FrameQueuePeekReadable(FrameQueue *f) { SDL_LockMutex(f->mutex); while (f->size - f->rindex_shown <= 0 && !f->pktq->abort_request) { @@ -680,7 +679,7 @@ static Frame *S_FMV_FrameQueuePeekReadable(FrameQueue *f) return &f->queue[(f->rindex + f->rindex_shown) % f->max_size]; } -static void S_FMV_FrameQueuePush(FrameQueue *f) +static void M_FrameQueuePush(FrameQueue *f) { if (++f->windex == f->max_size) { f->windex = 0; @@ -691,13 +690,13 @@ static void S_FMV_FrameQueuePush(FrameQueue *f) SDL_UnlockMutex(f->mutex); } -static void S_FMV_FrameQueueNext(FrameQueue *f) +static void M_FrameQueueNext(FrameQueue *f) { if (f->keep_last && !f->rindex_shown) { f->rindex_shown = 1; return; } - S_FMV_FrameQueueUnrefItem(&f->queue[f->rindex]); + M_FrameQueueUnrefItem(&f->queue[f->rindex]); if (++f->rindex == f->max_size) { f->rindex = 0; } @@ -707,21 +706,21 @@ static void S_FMV_FrameQueueNext(FrameQueue *f) SDL_UnlockMutex(f->mutex); } -static int S_FMV_FrameQueueNBRemaining(FrameQueue *f) +static int M_FrameQueueNBRemaining(FrameQueue *f) { return f->size - f->rindex_shown; } -static void S_FMV_DecoderAbort(Decoder *d, FrameQueue *fq) +static void M_DecoderAbort(Decoder *d, FrameQueue *fq) { - S_FMV_PacketQueueAbort(d->queue); - S_FMV_FrameQueueSignal(fq); + M_PacketQueueAbort(d->queue); + M_FrameQueueSignal(fq); SDL_WaitThread(d->decoder_tid, NULL); d->decoder_tid = NULL; - S_FMV_PacketQueueFlush(d->queue); + M_PacketQueueFlush(d->queue); } -static int S_FMV_ReallocPrimarySurface( +static int M_ReallocPrimarySurface( VideoState *is, int frame_width, int frame_height, bool clear) { int surface_width = Screen_GetResWidth(); @@ -775,7 +774,7 @@ static int S_FMV_ReallocPrimarySurface( return 0; } -static void S_FMV_CalculateDisplayRect( +static void M_CalculateDisplayRect( SDL_Rect *rect, int scr_xleft, int scr_ytop, int scr_width, int scr_height, int pic_width, int pic_height, AVRational pic_sar) { @@ -802,10 +801,9 @@ static void S_FMV_CalculateDisplayRect( rect->h = FFMAX((int)height, 1); } -static int S_FMV_UploadTexture(VideoState *is, AVFrame *frame) +static int M_UploadTexture(VideoState *is, AVFrame *frame) { - if (S_FMV_ReallocPrimarySurface(is, frame->width, frame->height, false) - < 0) { + if (M_ReallocPrimarySurface(is, frame->width, frame->height, false) < 0) { return -1; } @@ -847,7 +845,7 @@ static int S_FMV_UploadTexture(VideoState *is, AVFrame *frame) return ret; } -static void S_FMV_VideoImageDisplay(VideoState *is) +static void M_VideoImageDisplay(VideoState *is) { S_Output_RenderBegin(); @@ -855,10 +853,10 @@ static void S_FMV_VideoImageDisplay(VideoState *is) Frame *sp = NULL; SDL_Rect rect; - vp = S_FMV_FrameQueuePeekLast(&is->pictq); + vp = M_FrameQueuePeekLast(&is->pictq); if (is->subtitle_st) { - if (S_FMV_FrameQueueNBRemaining(&is->subpq) > 0) { - sp = S_FMV_FrameQueuePeek(&is->subpq); + if (M_FrameQueueNBRemaining(&is->subpq) > 0) { + sp = M_FrameQueuePeek(&is->subpq); if (vp->pts >= sp->pts + ((float)sp->sub.start_display_time / 1000)) { @@ -870,7 +868,7 @@ static void S_FMV_VideoImageDisplay(VideoState *is) sp->height = vp->height; } #if ENABLE_SUBTITLES - if (S_FMV_ReallocPrimarySurface( + if (M_ReallocPrimarySurface( SDL_PIXELFORMAT_ARGB8888, sp->width, sp->height, SDL_BLENDMODE_BLEND, true) < 0) { @@ -918,11 +916,11 @@ static void S_FMV_VideoImageDisplay(VideoState *is) } } - S_FMV_CalculateDisplayRect( + M_CalculateDisplayRect( &rect, 0, 0, is->width, is->height, vp->width, vp->height, vp->sar); if (!vp->uploaded) { - if (S_FMV_UploadTexture(is, vp->frame) < 0) { + if (M_UploadTexture(is, vp->frame) < 0) { return; } vp->uploaded = true; @@ -933,7 +931,7 @@ static void S_FMV_VideoImageDisplay(VideoState *is) S_Output_FlipScreen(); } -static void S_FMV_StreamComponentClose(VideoState *is, int stream_index) +static void M_StreamComponentClose(VideoState *is, int stream_index) { AVFormatContext *ic = is->ic; AVCodecParameters *codecpar; @@ -945,9 +943,9 @@ static void S_FMV_StreamComponentClose(VideoState *is, int stream_index) switch (codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - S_FMV_DecoderAbort(&is->auddec, &is->sampq); + M_DecoderAbort(&is->auddec, &is->sampq); SDL_CloseAudioDevice(m_AudioDevice); - S_FMV_DecoderShutdown(&is->auddec); + M_DecoderShutdown(&is->auddec); swr_free(&is->swr_ctx); av_freep(&is->audio_buf1); is->audio_buf1_size = 0; @@ -955,12 +953,12 @@ static void S_FMV_StreamComponentClose(VideoState *is, int stream_index) break; case AVMEDIA_TYPE_VIDEO: - S_FMV_DecoderAbort(&is->viddec, &is->pictq); - S_FMV_DecoderShutdown(&is->viddec); + M_DecoderAbort(&is->viddec, &is->pictq); + M_DecoderShutdown(&is->viddec); break; case AVMEDIA_TYPE_SUBTITLE: - S_FMV_DecoderAbort(&is->subdec, &is->subpq); - S_FMV_DecoderShutdown(&is->subdec); + M_DecoderAbort(&is->subdec, &is->subpq); + M_DecoderShutdown(&is->subdec); break; default: break; @@ -985,29 +983,29 @@ static void S_FMV_StreamComponentClose(VideoState *is, int stream_index) } } -static void S_FMV_StreamClose(VideoState *is) +static void M_StreamClose(VideoState *is) { SDL_WaitThread(is->read_tid, NULL); if (is->audio_stream >= 0) { - S_FMV_StreamComponentClose(is, is->audio_stream); + M_StreamComponentClose(is, is->audio_stream); } if (is->video_stream >= 0) { - S_FMV_StreamComponentClose(is, is->video_stream); + M_StreamComponentClose(is, is->video_stream); } if (is->subtitle_stream >= 0) { - S_FMV_StreamComponentClose(is, is->subtitle_stream); + M_StreamComponentClose(is, is->subtitle_stream); } avformat_close_input(&is->ic); - S_FMV_PacketQueueDestroy(&is->videoq); - S_FMV_PacketQueueDestroy(&is->audioq); - S_FMV_PacketQueueDestroy(&is->subtitleq); + M_PacketQueueDestroy(&is->videoq); + M_PacketQueueDestroy(&is->audioq); + M_PacketQueueDestroy(&is->subtitleq); - S_FMV_FrameQueueShutdown(&is->pictq); - S_FMV_FrameQueueShutdown(&is->sampq); - S_FMV_FrameQueueShutdown(&is->subpq); + M_FrameQueueShutdown(&is->pictq); + M_FrameQueueShutdown(&is->sampq); + M_FrameQueueShutdown(&is->subpq); SDL_DestroyCond(is->continue_read_thread); sws_freeContext(is->img_convert_ctx); sws_freeContext(is->sub_convert_ctx); @@ -1018,14 +1016,14 @@ static void S_FMV_StreamClose(VideoState *is) av_free(is); } -static void S_FMV_VideoDisplay(VideoState *is) +static void M_VideoDisplay(VideoState *is) { if (is->video_st) { - S_FMV_VideoImageDisplay(is); + M_VideoImageDisplay(is); } } -static double S_FMV_GetClock(Clock *c) +static double M_GetClock(Clock *c) { if (*c->queue_serial != c->serial) { return NAN; @@ -1039,7 +1037,7 @@ static double S_FMV_GetClock(Clock *c) } } -static void S_FMV_SetClockAt(Clock *c, double pts, int serial, double time) +static void M_SetClockAt(Clock *c, double pts, int serial, double time) { c->pts = pts; c->last_updated = time; @@ -1047,31 +1045,31 @@ static void S_FMV_SetClockAt(Clock *c, double pts, int serial, double time) c->serial = serial; } -static void S_FMV_SetClock(Clock *c, double pts, int serial) +static void M_SetClock(Clock *c, double pts, int serial) { double time = av_gettime_relative() / 1000000.0; - S_FMV_SetClockAt(c, pts, serial, time); + M_SetClockAt(c, pts, serial, time); } -static void S_FMV_InitClock(Clock *c, int *queue_serial) +static void M_InitClock(Clock *c, int *queue_serial) { c->speed = 1.0; c->paused = false; c->queue_serial = queue_serial; - S_FMV_SetClock(c, NAN, -1); + M_SetClock(c, NAN, -1); } -static void S_FMV_SyncClockToSlave(Clock *c, Clock *slave) +static void M_SyncClockToSlave(Clock *c, Clock *slave) { - double clock = S_FMV_GetClock(c); - double slave_clock = S_FMV_GetClock(slave); + double clock = M_GetClock(c); + double slave_clock = M_GetClock(slave); if (!isnan(slave_clock) && (isnan(clock) || fabs(clock - slave_clock) > AV_NOSYNC_THRESHOLD)) { - S_FMV_SetClock(c, slave_clock, slave->serial); + M_SetClock(c, slave_clock, slave->serial); } } -static int S_FMV_GetMasterSyncType(VideoState *is) +static int M_GetMasterSyncType(VideoState *is) { if (is->av_sync_type == AV_SYNC_VIDEO_MASTER) { if (is->video_st) { @@ -1090,26 +1088,26 @@ static int S_FMV_GetMasterSyncType(VideoState *is) } } -static double S_FMV_GetMasterClock(VideoState *is) +static double M_GetMasterClock(VideoState *is) { - switch (S_FMV_GetMasterSyncType(is)) { + switch (M_GetMasterSyncType(is)) { case AV_SYNC_VIDEO_MASTER: - return S_FMV_GetClock(&is->vidclk); + return M_GetClock(&is->vidclk); case AV_SYNC_AUDIO_MASTER: - return S_FMV_GetClock(&is->audclk); + return M_GetClock(&is->audclk); default: - return S_FMV_GetClock(&is->extclk); + return M_GetClock(&is->extclk); } } -static double S_FMV_ComputeTargetDelay(double delay, VideoState *is) +static double M_ComputeTargetDelay(double delay, VideoState *is) { double sync_threshold, diff = 0; - if (S_FMV_GetMasterSyncType(is) != AV_SYNC_VIDEO_MASTER) { - diff = S_FMV_GetClock(&is->vidclk) - S_FMV_GetMasterClock(is); + if (M_GetMasterSyncType(is) != AV_SYNC_VIDEO_MASTER) { + diff = M_GetClock(&is->vidclk) - M_GetMasterClock(is); sync_threshold = FFMAX(AV_SYNC_THRESHOLD_MIN, FFMIN(AV_SYNC_THRESHOLD_MAX, delay)); @@ -1128,7 +1126,7 @@ static double S_FMV_ComputeTargetDelay(double delay, VideoState *is) return delay; } -static double S_FMV_VPDuration(VideoState *is, Frame *vp, Frame *nextvp) +static double M_VPDuration(VideoState *is, Frame *vp, Frame *nextvp) { if (vp->serial == nextvp->serial) { double duration = nextvp->pts - vp->pts; @@ -1143,14 +1141,14 @@ static double S_FMV_VPDuration(VideoState *is, Frame *vp, Frame *nextvp) } } -static void S_FMV_UpdateVideoPTS( +static void M_UpdateVideoPTS( VideoState *is, double pts, int64_t pos, int serial) { - S_FMV_SetClock(&is->vidclk, pts, serial); - S_FMV_SyncClockToSlave(&is->extclk, &is->vidclk); + M_SetClock(&is->vidclk, pts, serial); + M_SyncClockToSlave(&is->extclk, &is->vidclk); } -static void S_FMV_VideoRefresh(void *opaque, double *remaining_time) +static void M_VideoRefresh(void *opaque, double *remaining_time) { VideoState *is = opaque; double time; @@ -1159,15 +1157,15 @@ static void S_FMV_VideoRefresh(void *opaque, double *remaining_time) if (is->video_st) { retry: - if (S_FMV_FrameQueueNBRemaining(&is->pictq) != 0) { + if (M_FrameQueueNBRemaining(&is->pictq) != 0) { double last_duration, duration, delay; Frame *vp, *lastvp; - lastvp = S_FMV_FrameQueuePeekLast(&is->pictq); - vp = S_FMV_FrameQueuePeek(&is->pictq); + lastvp = M_FrameQueuePeekLast(&is->pictq); + vp = M_FrameQueuePeek(&is->pictq); if (vp->serial != is->videoq.serial) { - S_FMV_FrameQueueNext(&is->pictq); + M_FrameQueueNext(&is->pictq); goto retry; } @@ -1179,8 +1177,8 @@ static void S_FMV_VideoRefresh(void *opaque, double *remaining_time) goto display; } - last_duration = S_FMV_VPDuration(is, lastvp, vp); - delay = S_FMV_ComputeTargetDelay(last_duration, is); + last_duration = M_VPDuration(is, lastvp, vp); + delay = M_ComputeTargetDelay(last_duration, is); time = av_gettime_relative() / 1000000.0; if (time < is->frame_timer + delay) { @@ -1196,27 +1194,27 @@ static void S_FMV_VideoRefresh(void *opaque, double *remaining_time) SDL_LockMutex(is->pictq.mutex); if (!isnan(vp->pts)) { - S_FMV_UpdateVideoPTS(is, vp->pts, vp->pos, vp->serial); + M_UpdateVideoPTS(is, vp->pts, vp->pos, vp->serial); } SDL_UnlockMutex(is->pictq.mutex); - if (S_FMV_FrameQueueNBRemaining(&is->pictq) > 1) { - Frame *nextvp = S_FMV_FrameQueuePeekNext(&is->pictq); - duration = S_FMV_VPDuration(is, vp, nextvp); - if (S_FMV_GetMasterSyncType(is) != AV_SYNC_VIDEO_MASTER + if (M_FrameQueueNBRemaining(&is->pictq) > 1) { + Frame *nextvp = M_FrameQueuePeekNext(&is->pictq); + duration = M_VPDuration(is, vp, nextvp); + if (M_GetMasterSyncType(is) != AV_SYNC_VIDEO_MASTER && time > is->frame_timer + duration) { is->frame_drops_late++; - S_FMV_FrameQueueNext(&is->pictq); + M_FrameQueueNext(&is->pictq); goto retry; } } if (is->subtitle_st) { - while (S_FMV_FrameQueueNBRemaining(&is->subpq) > 0) { - sp = S_FMV_FrameQueuePeek(&is->subpq); + while (M_FrameQueueNBRemaining(&is->subpq) > 0) { + sp = M_FrameQueuePeek(&is->subpq); - if (S_FMV_FrameQueueNBRemaining(&is->subpq) > 1) { - sp2 = S_FMV_FrameQueuePeekNext(&is->subpq); + if (M_FrameQueueNBRemaining(&is->subpq) > 1) { + sp2 = M_FrameQueuePeekNext(&is->subpq); } else { sp2 = NULL; } @@ -1250,32 +1248,32 @@ static void S_FMV_VideoRefresh(void *opaque, double *remaining_time) #endif } } - S_FMV_FrameQueueNext(&is->subpq); + M_FrameQueueNext(&is->subpq); } else { break; } } } - S_FMV_FrameQueueNext(&is->pictq); + M_FrameQueueNext(&is->pictq); is->force_refresh = true; } display: if (is->force_refresh && is->pictq.rindex_shown) { - S_FMV_VideoDisplay(is); + M_VideoDisplay(is); } } is->force_refresh = false; } -static int S_FMV_QueuePicture( +static int M_QueuePicture( VideoState *is, AVFrame *src_frame, double pts, double duration, int64_t pos, int serial) { Frame *vp; - if (!(vp = S_FMV_FrameQueuePeekWritable(&is->pictq))) { + if (!(vp = M_FrameQueuePeekWritable(&is->pictq))) { return -1; } @@ -1292,16 +1290,15 @@ static int S_FMV_QueuePicture( vp->serial = serial; av_frame_move_ref(vp->frame, src_frame); - S_FMV_FrameQueuePush(&is->pictq); + M_FrameQueuePush(&is->pictq); return 0; } -static int S_FMV_GetVideoFrame(VideoState *is, AVFrame *frame) +static int M_GetVideoFrame(VideoState *is, AVFrame *frame) { int got_picture; - if ((got_picture = S_FMV_DecoderDecodeFrame(&is->viddec, frame, NULL)) - < 0) { + if ((got_picture = M_DecoderDecodeFrame(&is->viddec, frame, NULL)) < 0) { return -1; } @@ -1315,9 +1312,9 @@ static int S_FMV_GetVideoFrame(VideoState *is, AVFrame *frame) frame->sample_aspect_ratio = av_guess_sample_aspect_ratio(is->ic, is->video_st, frame); - if (S_FMV_GetMasterSyncType(is) != AV_SYNC_VIDEO_MASTER) { + if (M_GetMasterSyncType(is) != AV_SYNC_VIDEO_MASTER) { if (frame->pts != AV_NOPTS_VALUE) { - double diff = dpts - S_FMV_GetMasterClock(is); + double diff = dpts - M_GetMasterClock(is); if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD && diff < 0 && is->viddec.pkt_serial == is->vidclk.serial && is->videoq.nb_packets) { @@ -1332,7 +1329,7 @@ static int S_FMV_GetVideoFrame(VideoState *is, AVFrame *frame) return got_picture; } -static int S_FMV_AudioThread(void *arg) +static int M_AudioThread(void *arg) { VideoState *is = arg; AVFrame *frame = av_frame_alloc(); @@ -1346,15 +1343,14 @@ static int S_FMV_AudioThread(void *arg) } do { - if ((got_frame = S_FMV_DecoderDecodeFrame(&is->auddec, frame, NULL)) - < 0) { + if ((got_frame = M_DecoderDecodeFrame(&is->auddec, frame, NULL)) < 0) { goto the_end; } if (got_frame) { tb = (AVRational) { 1, frame->sample_rate }; - if (!(af = S_FMV_FrameQueuePeekWritable(&is->sampq))) { + if (!(af = M_FrameQueuePeekWritable(&is->sampq))) { goto the_end; } @@ -1366,7 +1362,7 @@ static int S_FMV_AudioThread(void *arg) av_q2d((AVRational) { frame->nb_samples, frame->sample_rate }); av_frame_move_ref(af->frame, frame); - S_FMV_FrameQueuePush(&is->sampq); + M_FrameQueuePush(&is->sampq); } } while (ret >= 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF); the_end: @@ -1374,10 +1370,10 @@ static int S_FMV_AudioThread(void *arg) return ret; } -static int S_FMV_DecoderStart( +static int M_DecoderStart( Decoder *d, int (*fn)(void *), const char *thread_name, void *arg) { - S_FMV_PacketQueueStart(d->queue); + M_PacketQueueStart(d->queue); d->decoder_tid = SDL_CreateThread(fn, thread_name, arg); if (!d->decoder_tid) { LOG_ERROR("SDL_CreateThread(): %s", SDL_GetError()); @@ -1386,7 +1382,7 @@ static int S_FMV_DecoderStart( return 0; } -static int S_FMV_VideoThread(void *arg) +static int M_VideoThread(void *arg) { VideoState *is = arg; AVFrame *frame = av_frame_alloc(); @@ -1401,7 +1397,7 @@ static int S_FMV_VideoThread(void *arg) } while (1) { - ret = S_FMV_GetVideoFrame(is, frame); + ret = M_GetVideoFrame(is, frame); if (ret < 0) { goto the_end; } @@ -1414,7 +1410,7 @@ static int S_FMV_VideoThread(void *arg) ? av_q2d((AVRational) { frame_rate.den, frame_rate.num }) : 0); pts = (frame->pts == AV_NOPTS_VALUE) ? NAN : frame->pts * av_q2d(tb); - ret = S_FMV_QueuePicture( + ret = M_QueuePicture( is, frame, pts, duration, frame->pkt_pos, is->viddec.pkt_serial); av_frame_unref(frame); @@ -1427,7 +1423,7 @@ static int S_FMV_VideoThread(void *arg) return 0; } -static int S_FMV_SubtitleThread(void *arg) +static int M_SubtitleThread(void *arg) { VideoState *is = arg; Frame *sp; @@ -1435,12 +1431,11 @@ static int S_FMV_SubtitleThread(void *arg) double pts; while (1) { - if (!(sp = S_FMV_FrameQueuePeekWritable(&is->subpq))) { + if (!(sp = M_FrameQueuePeekWritable(&is->subpq))) { return 0; } - if ((got_subtitle = - S_FMV_DecoderDecodeFrame(&is->subdec, NULL, &sp->sub)) + if ((got_subtitle = M_DecoderDecodeFrame(&is->subdec, NULL, &sp->sub)) < 0) { break; } @@ -1457,7 +1452,7 @@ static int S_FMV_SubtitleThread(void *arg) sp->height = is->subdec.avctx->height; sp->uploaded = false; - S_FMV_FrameQueuePush(&is->subpq); + M_FrameQueuePush(&is->subpq); } else if (got_subtitle) { avsubtitle_free(&sp->sub); } @@ -1466,15 +1461,15 @@ static int S_FMV_SubtitleThread(void *arg) return 0; } -static int S_FMV_SynchronizeAudio(VideoState *is, int nb_samples) +static int M_SynchronizeAudio(VideoState *is, int nb_samples) { int wanted_nb_samples = nb_samples; - if (S_FMV_GetMasterSyncType(is) != AV_SYNC_AUDIO_MASTER) { + if (M_GetMasterSyncType(is) != AV_SYNC_AUDIO_MASTER) { double diff, avg_diff; int min_nb_samples, max_nb_samples; - diff = S_FMV_GetClock(&is->audclk) - S_FMV_GetMasterClock(is); + diff = M_GetClock(&is->audclk) - M_GetMasterClock(is); if (!isnan(diff) && fabs(diff) < AV_NOSYNC_THRESHOLD) { is->audio_diff_cum = @@ -1506,7 +1501,7 @@ static int S_FMV_SynchronizeAudio(VideoState *is, int nb_samples) return wanted_nb_samples; } -static int S_FMV_AudioDecodeFrame(VideoState *is) +static int M_AudioDecodeFrame(VideoState *is) { int data_size, resampled_data_size; av_unused double audio_clock0; @@ -1518,10 +1513,10 @@ static int S_FMV_AudioDecodeFrame(VideoState *is) } do { - if (!(af = S_FMV_FrameQueuePeekReadable(&is->sampq))) { + if (!(af = M_FrameQueuePeekReadable(&is->sampq))) { return -1; } - S_FMV_FrameQueueNext(&is->sampq); + M_FrameQueueNext(&is->sampq); } while (af->serial != is->audioq.serial); data_size = av_samples_get_buffer_size( @@ -1533,7 +1528,7 @@ static int S_FMV_AudioDecodeFrame(VideoState *is) == av_get_channel_layout_nb_channels(af->frame->channel_layout)) ? (signed)af->frame->channel_layout : av_get_default_channel_layout(af->frame->channels); - wanted_nb_samples = S_FMV_SynchronizeAudio(is, af->frame->nb_samples); + wanted_nb_samples = M_SynchronizeAudio(is, af->frame->nb_samples); if (af->frame->format != is->audio_src.fmt || dec_channel_layout != is->audio_src.channel_layout @@ -1620,7 +1615,7 @@ static int S_FMV_AudioDecodeFrame(VideoState *is) return resampled_data_size; } -static void S_FMV_SDLAudioCallback(void *opaque, Uint8 *stream, int len) +static void M_SDLAudioCallback(void *opaque, Uint8 *stream, int len) { VideoState *is = opaque; int audio_size, len1; @@ -1629,7 +1624,7 @@ static void S_FMV_SDLAudioCallback(void *opaque, Uint8 *stream, int len) while (len > 0) { if (is->audio_buf_index >= (signed)is->audio_buf_size) { - audio_size = S_FMV_AudioDecodeFrame(is); + audio_size = M_AudioDecodeFrame(is); if (audio_size < 0) { is->audio_buf = NULL; is->audio_buf_size = SDL_AUDIO_MIN_BUFFER_SIZE @@ -1660,17 +1655,17 @@ static void S_FMV_SDLAudioCallback(void *opaque, Uint8 *stream, int len) } is->audio_write_buf_size = is->audio_buf_size - is->audio_buf_index; if (!isnan(is->audio_clock)) { - S_FMV_SetClockAt( + M_SetClockAt( &is->audclk, is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / is->audio_tgt.bytes_per_sec, is->audio_clock_serial, m_AudioCallbackTime / 1000000.0); - S_FMV_SyncClockToSlave(&is->extclk, &is->audclk); + M_SyncClockToSlave(&is->extclk, &is->audclk); } } -static int S_FMV_AudioOpen( +static int M_AudioOpen( void *opaque, int64_t wanted_channel_layout, int wanted_nb_channels, int wanted_sample_rate, struct AudioParams *audio_hw_params) { @@ -1709,7 +1704,7 @@ static int S_FMV_AudioOpen( wanted_spec.samples = FFMAX( SDL_AUDIO_MIN_BUFFER_SIZE, 2 << av_log2(wanted_spec.freq / SDL_AUDIO_MAX_CALLBACKS_PER_SEC)); - wanted_spec.callback = S_FMV_SDLAudioCallback; + wanted_spec.callback = M_SDLAudioCallback; wanted_spec.userdata = opaque; while ( !(m_AudioDevice = SDL_OpenAudioDevice( @@ -1759,7 +1754,7 @@ static int S_FMV_AudioOpen( return spec.size; } -static int S_FMV_StreamComponentOpen(VideoState *is, int stream_index) +static int M_StreamComponentOpen(VideoState *is, int stream_index) { AVFormatContext *ic = is->ic; AVCodecContext *avctx = NULL; @@ -1813,7 +1808,7 @@ static int S_FMV_StreamComponentOpen(VideoState *is, int stream_index) nb_channels = avctx->channels; channel_layout = avctx->channel_layout; - if ((ret = S_FMV_AudioOpen( + if ((ret = M_AudioOpen( is, channel_layout, nb_channels, sample_rate, &is->audio_tgt)) < 0) { goto fail; @@ -1831,7 +1826,7 @@ static int S_FMV_StreamComponentOpen(VideoState *is, int stream_index) is->audio_stream = stream_index; is->audio_st = ic->streams[stream_index]; - if ((ret = S_FMV_DecoderInit( + if ((ret = M_DecoderInit( &is->auddec, avctx, &is->audioq, is->continue_read_thread)) < 0) { goto fail; @@ -1842,8 +1837,8 @@ static int S_FMV_StreamComponentOpen(VideoState *is, int stream_index) is->auddec.start_pts = is->audio_st->start_time; is->auddec.start_pts_tb = is->audio_st->time_base; } - if ((ret = S_FMV_DecoderStart( - &is->auddec, S_FMV_AudioThread, "audio_decoder", is)) + if ((ret = M_DecoderStart( + &is->auddec, M_AudioThread, "audio_decoder", is)) < 0) { goto out; } @@ -1854,13 +1849,13 @@ static int S_FMV_StreamComponentOpen(VideoState *is, int stream_index) is->video_stream = stream_index; is->video_st = ic->streams[stream_index]; - if ((ret = S_FMV_DecoderInit( + if ((ret = M_DecoderInit( &is->viddec, avctx, &is->videoq, is->continue_read_thread)) < 0) { goto fail; } - if ((ret = S_FMV_DecoderStart( - &is->viddec, S_FMV_VideoThread, "video_decoder", is)) + if ((ret = M_DecoderStart( + &is->viddec, M_VideoThread, "video_decoder", is)) < 0) { goto out; } @@ -1871,13 +1866,13 @@ static int S_FMV_StreamComponentOpen(VideoState *is, int stream_index) is->subtitle_stream = stream_index; is->subtitle_st = ic->streams[stream_index]; - if ((ret = S_FMV_DecoderInit( + if ((ret = M_DecoderInit( &is->subdec, avctx, &is->subtitleq, is->continue_read_thread)) < 0) { goto fail; } - if ((ret = S_FMV_DecoderStart( - &is->subdec, S_FMV_SubtitleThread, "subtitle_decoder", is)) + if ((ret = M_DecoderStart( + &is->subdec, M_SubtitleThread, "subtitle_decoder", is)) < 0) { goto out; } @@ -1895,13 +1890,13 @@ static int S_FMV_StreamComponentOpen(VideoState *is, int stream_index) return ret; } -static int S_FMV_DecodeInterruptCB(void *ctx) +static int M_DecodeInterruptCB(void *ctx) { VideoState *is = ctx; return is->abort_request; } -static int S_FMV_StreamHasEnoughPackets( +static int M_StreamHasEnoughPackets( AVStream *st, int stream_id, PacketQueue *queue) { return stream_id < 0 || queue->abort_request @@ -1911,7 +1906,7 @@ static int S_FMV_StreamHasEnoughPackets( || av_q2d(st->time_base) * queue->duration > 1.0)); } -static int S_FMV_ReadThread(void *arg) +static int M_ReadThread(void *arg) { VideoState *is = arg; AVFormatContext *ic = NULL; @@ -1943,7 +1938,7 @@ static int S_FMV_ReadThread(void *arg) ret = AVERROR(ENOMEM); goto fail; } - ic->interrupt_callback.callback = S_FMV_DecodeInterruptCB; + ic->interrupt_callback.callback = M_DecodeInterruptCB; ic->interrupt_callback.opaque = is; err = avformat_open_input(&ic, is->filename, NULL, NULL); if (err < 0) { @@ -1992,16 +1987,16 @@ static int S_FMV_ReadThread(void *arg) } if (st_index[AVMEDIA_TYPE_AUDIO] >= 0) { - S_FMV_StreamComponentOpen(is, st_index[AVMEDIA_TYPE_AUDIO]); + M_StreamComponentOpen(is, st_index[AVMEDIA_TYPE_AUDIO]); } ret = -1; if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) { - ret = S_FMV_StreamComponentOpen(is, st_index[AVMEDIA_TYPE_VIDEO]); + ret = M_StreamComponentOpen(is, st_index[AVMEDIA_TYPE_VIDEO]); } if (st_index[AVMEDIA_TYPE_SUBTITLE] >= 0) { - S_FMV_StreamComponentOpen(is, st_index[AVMEDIA_TYPE_SUBTITLE]); + M_StreamComponentOpen(is, st_index[AVMEDIA_TYPE_SUBTITLE]); } if (is->video_stream < 0 && is->audio_stream < 0) { @@ -2029,20 +2024,19 @@ static int S_FMV_ReadThread(void *arg) < 0) { goto fail; } - S_FMV_PacketQueuePut(&is->videoq, pkt); - S_FMV_PacketQueuePutNullPacket( - &is->videoq, pkt, is->video_stream); + M_PacketQueuePut(&is->videoq, pkt); + M_PacketQueuePutNullPacket(&is->videoq, pkt, is->video_stream); } is->queue_attachments_req = false; } if (is->audioq.size + is->videoq.size + is->subtitleq.size > MAX_QUEUE_SIZE - || (S_FMV_StreamHasEnoughPackets( + || (M_StreamHasEnoughPackets( is->audio_st, is->audio_stream, &is->audioq) - && S_FMV_StreamHasEnoughPackets( + && M_StreamHasEnoughPackets( is->video_st, is->video_stream, &is->videoq) - && S_FMV_StreamHasEnoughPackets( + && M_StreamHasEnoughPackets( is->subtitle_st, is->subtitle_stream, &is->subtitleq))) { SDL_LockMutex(wait_mutex); SDL_CondWaitTimeout(is->continue_read_thread, wait_mutex, 10); @@ -2052,10 +2046,10 @@ static int S_FMV_ReadThread(void *arg) if (!is->paused && (!is->audio_st || (is->auddec.finished == is->audioq.serial - && S_FMV_FrameQueueNBRemaining(&is->sampq) == 0)) + && M_FrameQueueNBRemaining(&is->sampq) == 0)) && (!is->video_st || (is->viddec.finished == is->videoq.serial - && S_FMV_FrameQueueNBRemaining(&is->pictq) == 0))) { + && M_FrameQueueNBRemaining(&is->pictq) == 0))) { ret = AVERROR_EOF; goto fail; } @@ -2063,15 +2057,15 @@ static int S_FMV_ReadThread(void *arg) if (ret < 0) { if ((ret == AVERROR_EOF || avio_feof(ic->pb)) && !is->eof) { if (is->video_stream >= 0) { - S_FMV_PacketQueuePutNullPacket( + M_PacketQueuePutNullPacket( &is->videoq, pkt, is->video_stream); } if (is->audio_stream >= 0) { - S_FMV_PacketQueuePutNullPacket( + M_PacketQueuePutNullPacket( &is->audioq, pkt, is->audio_stream); } if (is->subtitle_stream >= 0) { - S_FMV_PacketQueuePutNullPacket( + M_PacketQueuePutNullPacket( &is->subtitleq, pkt, is->subtitle_stream); } is->eof = true; @@ -2088,13 +2082,13 @@ static int S_FMV_ReadThread(void *arg) } pkt_ts = pkt->pts == AV_NOPTS_VALUE ? pkt->dts : pkt->pts; if (pkt->stream_index == is->audio_stream) { - S_FMV_PacketQueuePut(&is->audioq, pkt); + M_PacketQueuePut(&is->audioq, pkt); } else if ( pkt->stream_index == is->video_stream && !(is->video_st->disposition & AV_DISPOSITION_ATTACHED_PIC)) { - S_FMV_PacketQueuePut(&is->videoq, pkt); + M_PacketQueuePut(&is->videoq, pkt); } else if (pkt->stream_index == is->subtitle_stream) { - S_FMV_PacketQueuePut(&is->subtitleq, pkt); + M_PacketQueuePut(&is->subtitleq, pkt); } else { av_packet_unref(pkt); } @@ -2118,7 +2112,7 @@ static int S_FMV_ReadThread(void *arg) return 0; } -static VideoState *S_FMV_StreamOpen(const char *filename) +static VideoState *M_StreamOpen(const char *filename) { VideoState *is; @@ -2139,24 +2133,20 @@ static VideoState *S_FMV_StreamOpen(const char *filename) SDL_GetWindowSize(m_Window, &is->width, &is->height); - if (S_FMV_FrameQueueInit( - &is->pictq, &is->videoq, VIDEO_PICTURE_QUEUE_SIZE, 1) + if (M_FrameQueueInit(&is->pictq, &is->videoq, VIDEO_PICTURE_QUEUE_SIZE, 1) < 0) { goto fail; } - if (S_FMV_FrameQueueInit( - &is->subpq, &is->subtitleq, SUBPICTURE_QUEUE_SIZE, 0) + if (M_FrameQueueInit(&is->subpq, &is->subtitleq, SUBPICTURE_QUEUE_SIZE, 0) < 0) { goto fail; } - if (S_FMV_FrameQueueInit(&is->sampq, &is->audioq, SAMPLE_QUEUE_SIZE, 1) - < 0) { + if (M_FrameQueueInit(&is->sampq, &is->audioq, SAMPLE_QUEUE_SIZE, 1) < 0) { goto fail; } - if (S_FMV_PacketQueueInit(&is->videoq) < 0 - || S_FMV_PacketQueueInit(&is->audioq) < 0 - || S_FMV_PacketQueueInit(&is->subtitleq) < 0) + if (M_PacketQueueInit(&is->videoq) < 0 || M_PacketQueueInit(&is->audioq) < 0 + || M_PacketQueueInit(&is->subtitleq) < 0) goto fail; if (!(is->continue_read_thread = SDL_CreateCond())) { @@ -2164,23 +2154,23 @@ static VideoState *S_FMV_StreamOpen(const char *filename) goto fail; } - S_FMV_InitClock(&is->vidclk, &is->videoq.serial); - S_FMV_InitClock(&is->audclk, &is->audioq.serial); - S_FMV_InitClock(&is->extclk, &is->extclk.serial); + M_InitClock(&is->vidclk, &is->videoq.serial); + M_InitClock(&is->audclk, &is->audioq.serial); + M_InitClock(&is->extclk, &is->extclk.serial); is->audio_clock_serial = -1; - is->audio_volume = S_FMV_GetAudioVolume(); + is->audio_volume = M_GetAudioVolume(); is->av_sync_type = AV_SYNC_AUDIO_MASTER; - is->read_tid = SDL_CreateThread(S_FMV_ReadThread, "read_thread", is); + is->read_tid = SDL_CreateThread(M_ReadThread, "read_thread", is); if (!is->read_tid) { LOG_ERROR("SDL_CreateThread(): %s", SDL_GetError()); fail: - S_FMV_StreamClose(is); + M_StreamClose(is); return NULL; } return is; } -static void S_FMV_RefreshLoopWaitEvent(VideoState *is, SDL_Event *event) +static void M_RefreshLoopWaitEvent(VideoState *is, SDL_Event *event) { double remaining_time = 0.0; SDL_PumpEvents(); @@ -2201,18 +2191,18 @@ static void S_FMV_RefreshLoopWaitEvent(VideoState *is, SDL_Event *event) } remaining_time = REFRESH_RATE; if (!is->paused || is->force_refresh) { - S_FMV_VideoRefresh(is, &remaining_time); + M_VideoRefresh(is, &remaining_time); } SDL_PumpEvents(); } } -static void S_FMV_EventLoop(VideoState *is) +static void M_EventLoop(VideoState *is) { SDL_Event event; while (!is->abort_request) { - S_FMV_RefreshLoopWaitEvent(is, &event); + M_RefreshLoopWaitEvent(is, &event); switch (event.type) { case SDL_QUIT: @@ -2237,7 +2227,7 @@ static void S_FMV_EventLoop(VideoState *is) case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: - is->audio_volume = S_FMV_GetAudioVolume(); + is->audio_volume = M_GetAudioVolume(); break; case SDL_WINDOWEVENT_FOCUS_LOST: @@ -2301,19 +2291,19 @@ bool S_FMV_Play(const char *file_path) m_Window = (SDL_Window *)S_Shell_GetWindowHandle(); - is = S_FMV_StreamOpen(file_path); + is = M_StreamOpen(file_path); if (!is) { LOG_ERROR("Failed to initialize VideoState!"); goto cleanup; } - S_FMV_EventLoop(is); + M_EventLoop(is); ret = true; cleanup: if (is) { - S_FMV_StreamClose(is); + M_StreamClose(is); } LOG_DEBUG("Finished playing FMV: %s", file_path); diff --git a/src/specific/s_input.c b/src/specific/s_input.c index f61202cef..38f2b59b8 100644 --- a/src/specific/s_input.c +++ b/src/specific/s_input.c @@ -345,19 +345,17 @@ static SDL_GameController *m_Controller = NULL; static const char *m_ControllerName = NULL; static SDL_GameControllerType m_ControllerType = SDL_CONTROLLER_TYPE_UNKNOWN; -static const char *S_Input_GetScancodeName(INPUT_SCANCODE scancode); -static const char *S_Input_GetButtonName(SDL_GameControllerButton button); -static const char *S_Input_GetAxisName( - SDL_GameControllerAxis axis, int16_t axis_dir); -static bool S_Input_Key(INPUT_ROLE role, INPUT_LAYOUT layout_num); -static bool S_Input_JoyBtn(SDL_GameControllerButton button); -static int16_t S_Input_JoyAxis(SDL_GameControllerAxis axis); -static bool S_Input_GetBindState( - INPUT_ROLE role, INPUT_LAYOUT cntlr_layout_num); -static INPUT_STATE S_Input_GetControllerState( +static const char *M_GetScancodeName(INPUT_SCANCODE scancode); +static const char *M_GetButtonName(SDL_GameControllerButton button); +static const char *M_GetAxisName(SDL_GameControllerAxis axis, int16_t axis_dir); +static bool M_Key(INPUT_ROLE role, INPUT_LAYOUT layout_num); +static bool M_JoyBtn(SDL_GameControllerButton button); +static int16_t M_JoyAxis(SDL_GameControllerAxis axis); +static bool M_GetBindState(INPUT_ROLE role, INPUT_LAYOUT cntlr_layout_num); +static INPUT_STATE M_GetControllerState( INPUT_STATE state, INPUT_LAYOUT cntlr_layout_num); -static const char *S_Input_GetScancodeName(INPUT_SCANCODE scancode) +static const char *M_GetScancodeName(INPUT_SCANCODE scancode) { // clang-format off switch (scancode) { @@ -599,7 +597,7 @@ static const char *S_Input_GetScancodeName(INPUT_SCANCODE scancode) return "????"; } -static const char *S_Input_GetButtonName(SDL_GameControllerButton button) +static const char *M_GetButtonName(SDL_GameControllerButton button) { // clang-format off switch (m_ControllerType) { @@ -724,8 +722,7 @@ static const char *S_Input_GetButtonName(SDL_GameControllerButton button) return "????"; } -static const char *S_Input_GetAxisName( - SDL_GameControllerAxis axis, int16_t axis_dir) +static const char *M_GetAxisName(SDL_GameControllerAxis axis, int16_t axis_dir) { // clang-format off switch (m_ControllerType) { @@ -778,7 +775,7 @@ static const char *S_Input_GetAxisName( return "????"; } -static bool S_Input_Key(INPUT_ROLE role, INPUT_LAYOUT layout_num) +static bool M_Key(INPUT_ROLE role, INPUT_LAYOUT layout_num) { INPUT_SCANCODE scancode = m_Layout[layout_num][role]; if (KEY_DOWN(scancode)) { @@ -805,12 +802,12 @@ static bool S_Input_Key(INPUT_ROLE role, INPUT_LAYOUT layout_num) return false; } -static bool S_Input_JoyBtn(SDL_GameControllerButton button) +static bool M_JoyBtn(SDL_GameControllerButton button) { return SDL_GameControllerGetButton(m_Controller, button); } -static int16_t S_Input_JoyAxis(SDL_GameControllerAxis axis) +static int16_t M_JoyAxis(SDL_GameControllerAxis axis) { Sint16 value = SDL_GameControllerGetAxis(m_Controller, axis); if (value < -SDL_JOYSTICK_AXIS_MAX / 2) { @@ -822,59 +819,59 @@ static int16_t S_Input_JoyAxis(SDL_GameControllerAxis axis) return 0; } -static bool S_Input_GetBindState(INPUT_ROLE role, INPUT_LAYOUT cntlr_layout_num) +static bool M_GetBindState(INPUT_ROLE role, INPUT_LAYOUT cntlr_layout_num) { CONTROLLER_MAP assigned = m_ControllerLayout[cntlr_layout_num][role]; if (assigned.type == BT_BUTTON) { - return (S_Input_JoyBtn(assigned.bind.button)); + return (M_JoyBtn(assigned.bind.button)); } else { - return (S_Input_JoyAxis(assigned.bind.axis) == assigned.axis_dir); + return (M_JoyAxis(assigned.bind.axis) == assigned.axis_dir); } } -static INPUT_STATE S_Input_GetControllerState( +static INPUT_STATE M_GetControllerState( INPUT_STATE state, INPUT_LAYOUT cntlr_layout_num) { for (int role = 0; role < INPUT_ROLE_NUMBER_OF; role++) { // clang-format off - state.forward |= S_Input_GetBindState(INPUT_ROLE_UP, cntlr_layout_num); - state.back |= S_Input_GetBindState(INPUT_ROLE_DOWN, cntlr_layout_num); - state.left |= S_Input_GetBindState(INPUT_ROLE_LEFT, cntlr_layout_num); - state.right |= S_Input_GetBindState(INPUT_ROLE_RIGHT, cntlr_layout_num); - state.step_left |= S_Input_GetBindState(INPUT_ROLE_STEP_L, cntlr_layout_num); - state.step_right |= S_Input_GetBindState(INPUT_ROLE_STEP_R, cntlr_layout_num); - state.slow |= S_Input_GetBindState(INPUT_ROLE_SLOW, cntlr_layout_num); - state.jump |= S_Input_GetBindState(INPUT_ROLE_JUMP, cntlr_layout_num); - state.action |= S_Input_GetBindState(INPUT_ROLE_ACTION, cntlr_layout_num); - state.draw |= S_Input_GetBindState(INPUT_ROLE_DRAW, cntlr_layout_num); - state.look |= S_Input_GetBindState(INPUT_ROLE_LOOK, cntlr_layout_num); - state.roll |= S_Input_GetBindState(INPUT_ROLE_ROLL, cntlr_layout_num); - state.option |= S_Input_GetBindState(INPUT_ROLE_OPTION, cntlr_layout_num); - state.pause |= S_Input_GetBindState(INPUT_ROLE_PAUSE, cntlr_layout_num); - state.camera_up |= S_Input_GetBindState(INPUT_ROLE_CAMERA_UP, cntlr_layout_num); - state.camera_down |= S_Input_GetBindState(INPUT_ROLE_CAMERA_DOWN, cntlr_layout_num); - state.camera_left |= S_Input_GetBindState(INPUT_ROLE_CAMERA_LEFT, cntlr_layout_num); - state.camera_right |= S_Input_GetBindState(INPUT_ROLE_CAMERA_RIGHT, cntlr_layout_num); - state.camera_reset |= S_Input_GetBindState(INPUT_ROLE_CAMERA_RESET, cntlr_layout_num); - state.item_cheat |= S_Input_GetBindState(INPUT_ROLE_ITEM_CHEAT, cntlr_layout_num); - state.fly_cheat |= S_Input_GetBindState(INPUT_ROLE_FLY_CHEAT, cntlr_layout_num); - state.level_skip_cheat |= S_Input_GetBindState(INPUT_ROLE_LEVEL_SKIP_CHEAT, cntlr_layout_num); - state.turbo_cheat |= S_Input_GetBindState(INPUT_ROLE_TURBO_CHEAT, cntlr_layout_num); - state.equip_pistols |= S_Input_GetBindState(INPUT_ROLE_EQUIP_PISTOLS, cntlr_layout_num); - state.equip_shotgun |= S_Input_GetBindState(INPUT_ROLE_EQUIP_SHOTGUN, cntlr_layout_num); - state.equip_magnums |= S_Input_GetBindState(INPUT_ROLE_EQUIP_MAGNUMS, cntlr_layout_num); - state.equip_uzis |= S_Input_GetBindState(INPUT_ROLE_EQUIP_UZIS, cntlr_layout_num); - state.use_small_medi |= S_Input_GetBindState(INPUT_ROLE_USE_SMALL_MEDI, cntlr_layout_num); - state.use_big_medi |= S_Input_GetBindState(INPUT_ROLE_USE_BIG_MEDI, cntlr_layout_num); - state.save |= S_Input_GetBindState(INPUT_ROLE_SAVE, cntlr_layout_num); - state.load |= S_Input_GetBindState(INPUT_ROLE_LOAD, cntlr_layout_num); - state.toggle_fps_counter |= S_Input_GetBindState(INPUT_ROLE_FPS, cntlr_layout_num); - state.toggle_bilinear_filter |= S_Input_GetBindState(INPUT_ROLE_BILINEAR, cntlr_layout_num); - state.change_target |= S_Input_GetBindState(INPUT_ROLE_CHANGE_TARGET, cntlr_layout_num); - state.menu_confirm |= S_Input_JoyBtn(SDL_CONTROLLER_BUTTON_A); - state.menu_back |= S_Input_JoyBtn(SDL_CONTROLLER_BUTTON_B); - state.menu_back |= S_Input_JoyBtn(SDL_CONTROLLER_BUTTON_Y); + state.forward |= M_GetBindState(INPUT_ROLE_UP, cntlr_layout_num); + state.back |= M_GetBindState(INPUT_ROLE_DOWN, cntlr_layout_num); + state.left |= M_GetBindState(INPUT_ROLE_LEFT, cntlr_layout_num); + state.right |= M_GetBindState(INPUT_ROLE_RIGHT, cntlr_layout_num); + state.step_left |= M_GetBindState(INPUT_ROLE_STEP_L, cntlr_layout_num); + state.step_right |= M_GetBindState(INPUT_ROLE_STEP_R, cntlr_layout_num); + state.slow |= M_GetBindState(INPUT_ROLE_SLOW, cntlr_layout_num); + state.jump |= M_GetBindState(INPUT_ROLE_JUMP, cntlr_layout_num); + state.action |= M_GetBindState(INPUT_ROLE_ACTION, cntlr_layout_num); + state.draw |= M_GetBindState(INPUT_ROLE_DRAW, cntlr_layout_num); + state.look |= M_GetBindState(INPUT_ROLE_LOOK, cntlr_layout_num); + state.roll |= M_GetBindState(INPUT_ROLE_ROLL, cntlr_layout_num); + state.option |= M_GetBindState(INPUT_ROLE_OPTION, cntlr_layout_num); + state.pause |= M_GetBindState(INPUT_ROLE_PAUSE, cntlr_layout_num); + state.camera_up |= M_GetBindState(INPUT_ROLE_CAMERA_UP, cntlr_layout_num); + state.camera_down |= M_GetBindState(INPUT_ROLE_CAMERA_DOWN, cntlr_layout_num); + state.camera_left |= M_GetBindState(INPUT_ROLE_CAMERA_LEFT, cntlr_layout_num); + state.camera_right |= M_GetBindState(INPUT_ROLE_CAMERA_RIGHT, cntlr_layout_num); + state.camera_reset |= M_GetBindState(INPUT_ROLE_CAMERA_RESET, cntlr_layout_num); + state.item_cheat |= M_GetBindState(INPUT_ROLE_ITEM_CHEAT, cntlr_layout_num); + state.fly_cheat |= M_GetBindState(INPUT_ROLE_FLY_CHEAT, cntlr_layout_num); + state.level_skip_cheat |= M_GetBindState(INPUT_ROLE_LEVEL_SKIP_CHEAT, cntlr_layout_num); + state.turbo_cheat |= M_GetBindState(INPUT_ROLE_TURBO_CHEAT, cntlr_layout_num); + state.equip_pistols |= M_GetBindState(INPUT_ROLE_EQUIP_PISTOLS, cntlr_layout_num); + state.equip_shotgun |= M_GetBindState(INPUT_ROLE_EQUIP_SHOTGUN, cntlr_layout_num); + state.equip_magnums |= M_GetBindState(INPUT_ROLE_EQUIP_MAGNUMS, cntlr_layout_num); + state.equip_uzis |= M_GetBindState(INPUT_ROLE_EQUIP_UZIS, cntlr_layout_num); + state.use_small_medi |= M_GetBindState(INPUT_ROLE_USE_SMALL_MEDI, cntlr_layout_num); + state.use_big_medi |= M_GetBindState(INPUT_ROLE_USE_BIG_MEDI, cntlr_layout_num); + state.save |= M_GetBindState(INPUT_ROLE_SAVE, cntlr_layout_num); + state.load |= M_GetBindState(INPUT_ROLE_LOAD, cntlr_layout_num); + state.toggle_fps_counter |= M_GetBindState(INPUT_ROLE_FPS, cntlr_layout_num); + state.toggle_bilinear_filter |= M_GetBindState(INPUT_ROLE_BILINEAR, cntlr_layout_num); + state.change_target |= M_GetBindState(INPUT_ROLE_CHANGE_TARGET, cntlr_layout_num); + state.menu_confirm |= M_JoyBtn(SDL_CONTROLLER_BUTTON_A); + state.menu_back |= M_JoyBtn(SDL_CONTROLLER_BUTTON_B); + state.menu_back |= M_JoyBtn(SDL_CONTROLLER_BUTTON_Y); // clang-format on } @@ -936,39 +933,39 @@ INPUT_STATE S_Input_GetCurrentState( INPUT_STATE linput = { 0 }; // clang-format off - linput.forward = S_Input_Key(INPUT_ROLE_UP, layout_num); - linput.back = S_Input_Key(INPUT_ROLE_DOWN, layout_num); - linput.left = S_Input_Key(INPUT_ROLE_LEFT, layout_num); - linput.right = S_Input_Key(INPUT_ROLE_RIGHT, layout_num); - linput.step_left = S_Input_Key(INPUT_ROLE_STEP_L, layout_num); - linput.step_right = S_Input_Key(INPUT_ROLE_STEP_R, layout_num); - linput.slow = S_Input_Key(INPUT_ROLE_SLOW, layout_num); - linput.jump = S_Input_Key(INPUT_ROLE_JUMP, layout_num); - linput.action = S_Input_Key(INPUT_ROLE_ACTION, layout_num); - linput.draw = S_Input_Key(INPUT_ROLE_DRAW, layout_num); - linput.look = S_Input_Key(INPUT_ROLE_LOOK, layout_num); - linput.roll = S_Input_Key(INPUT_ROLE_ROLL, layout_num); - linput.option = S_Input_Key(INPUT_ROLE_OPTION, layout_num); - linput.pause = S_Input_Key(INPUT_ROLE_PAUSE, layout_num); - linput.camera_up = S_Input_Key(INPUT_ROLE_CAMERA_UP, layout_num); - linput.camera_down = S_Input_Key(INPUT_ROLE_CAMERA_DOWN, layout_num); - linput.camera_left = S_Input_Key(INPUT_ROLE_CAMERA_LEFT, layout_num); - linput.camera_right = S_Input_Key(INPUT_ROLE_CAMERA_RIGHT, layout_num); - linput.camera_reset = S_Input_Key(INPUT_ROLE_CAMERA_RESET, layout_num); - linput.change_target = S_Input_Key(INPUT_ROLE_CHANGE_TARGET, layout_num); - - linput.item_cheat = S_Input_Key(INPUT_ROLE_ITEM_CHEAT, layout_num); - linput.fly_cheat = S_Input_Key(INPUT_ROLE_FLY_CHEAT, layout_num); - linput.level_skip_cheat = S_Input_Key(INPUT_ROLE_LEVEL_SKIP_CHEAT, layout_num); - linput.turbo_cheat = S_Input_Key(INPUT_ROLE_TURBO_CHEAT, layout_num); + linput.forward = M_Key(INPUT_ROLE_UP, layout_num); + linput.back = M_Key(INPUT_ROLE_DOWN, layout_num); + linput.left = M_Key(INPUT_ROLE_LEFT, layout_num); + linput.right = M_Key(INPUT_ROLE_RIGHT, layout_num); + linput.step_left = M_Key(INPUT_ROLE_STEP_L, layout_num); + linput.step_right = M_Key(INPUT_ROLE_STEP_R, layout_num); + linput.slow = M_Key(INPUT_ROLE_SLOW, layout_num); + linput.jump = M_Key(INPUT_ROLE_JUMP, layout_num); + linput.action = M_Key(INPUT_ROLE_ACTION, layout_num); + linput.draw = M_Key(INPUT_ROLE_DRAW, layout_num); + linput.look = M_Key(INPUT_ROLE_LOOK, layout_num); + linput.roll = M_Key(INPUT_ROLE_ROLL, layout_num); + linput.option = M_Key(INPUT_ROLE_OPTION, layout_num); + linput.pause = M_Key(INPUT_ROLE_PAUSE, layout_num); + linput.camera_up = M_Key(INPUT_ROLE_CAMERA_UP, layout_num); + linput.camera_down = M_Key(INPUT_ROLE_CAMERA_DOWN, layout_num); + linput.camera_left = M_Key(INPUT_ROLE_CAMERA_LEFT, layout_num); + linput.camera_right = M_Key(INPUT_ROLE_CAMERA_RIGHT, layout_num); + linput.camera_reset = M_Key(INPUT_ROLE_CAMERA_RESET, layout_num); + linput.change_target = M_Key(INPUT_ROLE_CHANGE_TARGET, layout_num); + + linput.item_cheat = M_Key(INPUT_ROLE_ITEM_CHEAT, layout_num); + linput.fly_cheat = M_Key(INPUT_ROLE_FLY_CHEAT, layout_num); + linput.level_skip_cheat = M_Key(INPUT_ROLE_LEVEL_SKIP_CHEAT, layout_num); + linput.turbo_cheat = M_Key(INPUT_ROLE_TURBO_CHEAT, layout_num); linput.health_cheat = KEY_DOWN(SDL_SCANCODE_F11); - linput.equip_pistols = S_Input_Key(INPUT_ROLE_EQUIP_PISTOLS, layout_num); - linput.equip_shotgun = S_Input_Key(INPUT_ROLE_EQUIP_SHOTGUN, layout_num); - linput.equip_magnums = S_Input_Key(INPUT_ROLE_EQUIP_MAGNUMS, layout_num); - linput.equip_uzis = S_Input_Key(INPUT_ROLE_EQUIP_UZIS, layout_num); - linput.use_small_medi = S_Input_Key(INPUT_ROLE_USE_SMALL_MEDI, layout_num); - linput.use_big_medi = S_Input_Key(INPUT_ROLE_USE_BIG_MEDI, layout_num); + linput.equip_pistols = M_Key(INPUT_ROLE_EQUIP_PISTOLS, layout_num); + linput.equip_shotgun = M_Key(INPUT_ROLE_EQUIP_SHOTGUN, layout_num); + linput.equip_magnums = M_Key(INPUT_ROLE_EQUIP_MAGNUMS, layout_num); + linput.equip_uzis = M_Key(INPUT_ROLE_EQUIP_UZIS, layout_num); + linput.use_small_medi = M_Key(INPUT_ROLE_USE_SMALL_MEDI, layout_num); + linput.use_big_medi = M_Key(INPUT_ROLE_USE_BIG_MEDI, layout_num); linput.menu_up = KEY_DOWN(SDL_SCANCODE_UP); linput.menu_down = KEY_DOWN(SDL_SCANCODE_DOWN); @@ -978,16 +975,16 @@ INPUT_STATE S_Input_GetCurrentState( linput.menu_confirm |= linput.action; // we only do this for keyboard input linput.menu_back = KEY_DOWN(SDL_SCANCODE_ESCAPE); - linput.save = S_Input_Key(INPUT_ROLE_SAVE, layout_num); - linput.load = S_Input_Key(INPUT_ROLE_LOAD, layout_num); + linput.save = M_Key(INPUT_ROLE_SAVE, layout_num); + linput.load = M_Key(INPUT_ROLE_LOAD, layout_num); - linput.toggle_fps_counter = S_Input_Key(INPUT_ROLE_FPS, layout_num); - linput.toggle_bilinear_filter = S_Input_Key(INPUT_ROLE_BILINEAR, layout_num); + linput.toggle_fps_counter = M_Key(INPUT_ROLE_FPS, layout_num); + linput.toggle_bilinear_filter = M_Key(INPUT_ROLE_BILINEAR, layout_num); linput.toggle_perspective_filter = KEY_DOWN(SDL_SCANCODE_F4); // clang-format on if (m_Controller) { - linput = S_Input_GetControllerState(linput, cntlr_layout_num); + linput = M_GetControllerState(linput, cntlr_layout_num); } return linput; @@ -1081,14 +1078,14 @@ bool S_Input_ReadAndAssignKey( } else { for (SDL_GameControllerButton button = 0; button < SDL_CONTROLLER_BUTTON_MAX; button++) { - if (S_Input_JoyBtn(button)) { + if (M_JoyBtn(button)) { S_Input_AssignButton(layout_num, role, button); return true; } } for (SDL_GameControllerAxis axis = 0; axis < SDL_CONTROLLER_AXIS_MAX; axis++) { - int16_t axis_dir = S_Input_JoyAxis(axis); + int16_t axis_dir = M_JoyAxis(axis); if (axis_dir != 0) { S_Input_AssignAxis(layout_num, role, axis, axis_dir); return true; @@ -1102,13 +1099,13 @@ const char *S_Input_GetKeyName( CONTROL_MODE mode, INPUT_LAYOUT layout_num, INPUT_ROLE role) { if (mode == CM_KEYBOARD) { - return S_Input_GetScancodeName(m_Layout[layout_num][role]); + return M_GetScancodeName(m_Layout[layout_num][role]); } else { CONTROLLER_MAP check = m_ControllerLayout[layout_num][role]; if (check.type == BT_BUTTON) { - return S_Input_GetButtonName(check.bind.button); + return M_GetButtonName(check.bind.button); } else { - return S_Input_GetAxisName(check.bind.axis, check.axis_dir); + return M_GetAxisName(check.bind.axis, check.axis_dir); } } } @@ -1118,7 +1115,7 @@ const char *S_Input_GetButtonNameFromString( { SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(button_name); - return S_Input_GetButtonName(button); + return M_GetButtonName(button); } bool S_Input_CheckKeypress(const char *key_name) @@ -1136,5 +1133,5 @@ bool S_Input_CheckButtonPress(const char *button_name) SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(button_name); - return S_Input_JoyBtn(button); + return M_JoyBtn(button); } diff --git a/src/specific/s_output.c b/src/specific/s_output.c index e8ce36a40..4c9e1115e 100644 --- a/src/specific/s_output.c +++ b/src/specific/s_output.c @@ -45,21 +45,21 @@ static GFX_2D_Surface *m_PrimarySurface = NULL; static GFX_2D_Surface *m_PictureSurface = NULL; static GFX_2D_Surface *m_TextureSurfaces[GFX_MAX_TEXTURES] = { NULL }; -static void S_Output_ReleaseTextures(void); -static void S_Output_ReleaseSurfaces(void); -static void S_Output_FlipPrimaryBuffer(void); -static void S_Output_ClearSurface(GFX_2D_Surface *surface); -static void S_Output_DrawTriangleFan(GFX_3D_Vertex *vertices, int vertex_count); -static void S_Output_DrawTriangleStrip( - GFX_3D_Vertex *vertices, int vertex_count); -static int32_t S_Output_ClipVertices( +static inline float M_GetUV(const uint16_t uv); +static void M_ReleaseTextures(void); +static void M_ReleaseSurfaces(void); +static void M_FlipPrimaryBuffer(void); +static void M_ClearSurface(GFX_2D_Surface *surface); +static void M_DrawTriangleFan(GFX_3D_Vertex *vertices, int vertex_count); +static void M_DrawTriangleStrip(GFX_3D_Vertex *vertices, int vertex_count); +static int32_t M_ClipVertices( GFX_3D_Vertex *vertices, int vertex_count, size_t vertices_capacity); -static int32_t S_Output_VisibleZClip( +static int32_t M_VisibleZClip( const PHD_VBUF *vn1, const PHD_VBUF *vn2, const PHD_VBUF *vn3); -static int32_t S_Output_ZedClipper( +static int32_t M_ZedClipper( int32_t vertex_count, POINT_INFO *pts, GFX_3D_Vertex *vertices); -static inline float S_Output_GetUV(const uint16_t uv) +static inline float M_GetUV(const uint16_t uv) { return g_Config.rendering.pretty_pixels && g_Config.rendering.texture_filter == GFX_TF_NN @@ -67,7 +67,7 @@ static inline float S_Output_GetUV(const uint16_t uv) : ((uv & 0xFF00) + 127) / 256.0f; } -static void S_Output_ReleaseTextures(void) +static void M_ReleaseTextures(void) { if (!m_Renderer3D) { return; @@ -84,10 +84,10 @@ static void S_Output_ReleaseTextures(void) } } -static void S_Output_ReleaseSurfaces(void) +static void M_ReleaseSurfaces(void) { if (m_PrimarySurface) { - S_Output_ClearSurface(m_PrimarySurface); + M_ClearSurface(m_PrimarySurface); GFX_2D_Surface_Free(m_PrimarySurface); m_PrimarySurface = NULL; @@ -111,29 +111,28 @@ void Output_FillEnvironmentMap(void) GFX_3D_Renderer_FillEnvironmentMap(m_Renderer3D); } -static void S_Output_FlipPrimaryBuffer(void) +static void M_FlipPrimaryBuffer(void) { GFX_Context_SwapBuffers(); } -static void S_Output_ClearSurface(GFX_2D_Surface *surface) +static void M_ClearSurface(GFX_2D_Surface *surface) { bool result = GFX_2D_Surface_Clear(surface); S_Output_CheckError(result); } -static void S_Output_DrawTriangleFan(GFX_3D_Vertex *vertices, int vertex_count) +static void M_DrawTriangleFan(GFX_3D_Vertex *vertices, int vertex_count) { GFX_3D_Renderer_RenderPrimFan(m_Renderer3D, vertices, vertex_count); } -static void S_Output_DrawTriangleStrip( - GFX_3D_Vertex *vertices, int vertex_count) +static void M_DrawTriangleStrip(GFX_3D_Vertex *vertices, int vertex_count) { GFX_3D_Renderer_RenderPrimStrip(m_Renderer3D, vertices, vertex_count); } -static int32_t S_Output_ClipVertices( +static int32_t M_ClipVertices( GFX_3D_Vertex *vertices, int vertex_count, size_t vertices_capacity) { float scale; @@ -327,7 +326,7 @@ static int32_t S_Output_ClipVertices( return j; } -static int32_t S_Output_VisibleZClip( +static int32_t M_VisibleZClip( const PHD_VBUF *const vn1, const PHD_VBUF *const vn2, const PHD_VBUF *const vn3) { @@ -346,7 +345,7 @@ static int32_t S_Output_VisibleZClip( return a * v2z + b * v2y + c * v2x < 0.0; } -static int32_t S_Output_ZedClipper( +static int32_t M_ZedClipper( int32_t vertex_count, POINT_INFO *pts, GFX_3D_Vertex *vertices) { const float multiplier = g_Config.brightness / 16.0f; @@ -451,7 +450,7 @@ void S_Output_RenderEnd(void) void S_Output_FlipScreen(void) { - S_Output_FlipPrimaryBuffer(); + M_FlipPrimaryBuffer(); m_SelectedTexture = -1; } @@ -572,7 +571,7 @@ void S_Output_DrawSprite( if (x1 < 0 || y1 < 0 || x2 > Viewport_GetWidth() || y2 > Viewport_GetHeight()) { - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); } @@ -583,10 +582,10 @@ void S_Output_DrawSprite( if (m_TextureMap[sprite->tpage] != GFX_NO_TEXTURE) { S_Output_EnableTextureMode(); S_Output_SelectTexture(sprite->tpage); - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); } else { S_Output_DisableTextureMode(); - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); } } @@ -662,7 +661,7 @@ void S_Output_Draw2DQuad( S_Output_DisableTextureMode(); GFX_3D_Renderer_SetBlendingMode(m_Renderer3D, GFX_BlendMode_Normal); - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); GFX_3D_Renderer_SetBlendingMode(m_Renderer3D, GFX_BlendMode_Off); } @@ -708,10 +707,10 @@ void S_Output_DrawLightningSegment( vertices[3].b = 255.0f; vertices[3].a = 128.0f; - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); if (vertex_count) { - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); } vertex_count = 4; @@ -747,10 +746,10 @@ void S_Output_DrawLightningSegment( vertices[3].r = 255.0f; vertices[3].a = 128.0f; - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); if (vertex_count) { - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); } GFX_3D_Renderer_SetBlendingMode(m_Renderer3D, GFX_BlendMode_Off); } @@ -773,7 +772,7 @@ void S_Output_DrawShadow(PHD_VBUF *vbufs, int clip, int vertex_count) } if (clip) { - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); } @@ -784,7 +783,7 @@ void S_Output_DrawShadow(PHD_VBUF *vbufs, int clip, int vertex_count) S_Output_DisableTextureMode(); GFX_3D_Renderer_SetBlendingMode(m_Renderer3D, GFX_BlendMode_Normal); - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); GFX_3D_Renderer_SetBlendingMode(m_Renderer3D, GFX_BlendMode_Off); } @@ -816,7 +815,7 @@ void S_Output_ApplyRenderSettings(void) GFX_2D_SurfaceDesc surface_desc = { 0 }; m_PrimarySurface = GFX_2D_Surface_Create(&surface_desc); } - S_Output_ClearSurface(m_PrimarySurface); + M_ClearSurface(m_PrimarySurface); for (int i = 0; i < GFX_MAX_TEXTURES; i++) { GFX_2D_SurfaceDesc surface_desc = { @@ -853,8 +852,8 @@ bool S_Output_Init(void) void S_Output_Shutdown(void) { - S_Output_ReleaseTextures(); - S_Output_ReleaseSurfaces(); + M_ReleaseTextures(); + M_ReleaseSurfaces(); GFX_Context_Detach(); m_Renderer3D = NULL; } @@ -893,11 +892,11 @@ void S_Output_DrawFlatTriangle( } if (vn1->clip || vn2->clip || vn3->clip) { - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); } } else { - if (!S_Output_VisibleZClip(vn1, vn2, vn3)) { + if (!M_VisibleZClip(vn1, vn2, vn3)) { return; } @@ -911,7 +910,7 @@ void S_Output_DrawFlatTriangle( points[i].g = src_vbuf[i]->g; } - vertex_count = S_Output_ZedClipper(vertex_count, points, vertices); + vertex_count = M_ZedClipper(vertex_count, points, vertices); if (!vertex_count) { return; } @@ -921,7 +920,7 @@ void S_Output_DrawFlatTriangle( vertices[i].b *= color.b / 255.0f; } - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); } @@ -929,7 +928,7 @@ void S_Output_DrawFlatTriangle( return; } - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); } void S_Output_DrawEnvMapTriangle( @@ -960,10 +959,8 @@ void S_Output_DrawEnvMapTriangle( vertices[i].z = src_vbuf[i]->zv * 0.0001f; vertices[i].w = 65536.0f / src_vbuf[i]->zv; - vertices[i].s = - S_Output_GetUV(src_uv[i]->u) * (vertices[i].w / 256.0f); - vertices[i].t = - S_Output_GetUV(src_uv[i]->v) * (vertices[i].w / 256.0f); + vertices[i].s = M_GetUV(src_uv[i]->u) * (vertices[i].w / 256.0f); + vertices[i].t = M_GetUV(src_uv[i]->v) * (vertices[i].w / 256.0f); vertices[i].r = vertices[i].g = vertices[i].b = (8192.0f - src_vbuf[i]->g) * multiplier; @@ -972,11 +969,11 @@ void S_Output_DrawEnvMapTriangle( } if (vn1->clip || vn2->clip || vn3->clip) { - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); } } else { - if (!S_Output_VisibleZClip(vn1, vn2, vn3)) { + if (!M_VisibleZClip(vn1, vn2, vn3)) { return; } @@ -988,15 +985,15 @@ void S_Output_DrawEnvMapTriangle( points[i].xs = src_vbuf[i]->xs; points[i].ys = src_vbuf[i]->ys; points[i].g = src_vbuf[i]->g; - points[i].u = S_Output_GetUV(src_uv[i]->u); - points[i].v = S_Output_GetUV(src_uv[i]->v); + points[i].u = M_GetUV(src_uv[i]->u); + points[i].v = M_GetUV(src_uv[i]->v); } - vertex_count = S_Output_ZedClipper(vertex_count, points, vertices); + vertex_count = M_ZedClipper(vertex_count, points, vertices); if (!vertex_count) { return; } - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); } @@ -1007,7 +1004,7 @@ void S_Output_DrawEnvMapTriangle( S_Output_EnableTextureMode(); GFX_3D_Renderer_SelectTexture(m_Renderer3D, m_EnvMapTexture); GFX_3D_Renderer_SetBlendingMode(m_Renderer3D, GFX_BlendMode_Multiply); - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); GFX_3D_Renderer_SetBlendingMode(m_Renderer3D, GFX_BlendMode_Off); m_SelectedTexture = -1; } @@ -1031,7 +1028,7 @@ void S_Output_DrawEnvMapQuad( if (!VBUF_VISIBLE(*vn1, *vn2, *vn3)) { return; } - } else if (!S_Output_VisibleZClip(vn1, vn2, vn3)) { + } else if (!M_VisibleZClip(vn1, vn2, vn3)) { return; } @@ -1055,8 +1052,8 @@ void S_Output_DrawEnvMapQuad( vertices[i].z = src_vbuf[i]->zv * 0.0001f; vertices[i].w = 65536.0f / src_vbuf[i]->zv; - vertices[i].s = S_Output_GetUV(src_uv[i]->u) * (vertices[i].w / 256.0f); - vertices[i].t = S_Output_GetUV(src_uv[i]->v) * (vertices[i].w / 256.0f); + vertices[i].s = M_GetUV(src_uv[i]->u) * (vertices[i].w / 256.0f); + vertices[i].t = M_GetUV(src_uv[i]->v) * (vertices[i].w / 256.0f); vertices[i].r = vertices[i].g = vertices[i].b = (8192.0f - src_vbuf[i]->g) * multiplier; @@ -1107,10 +1104,8 @@ void S_Output_DrawTexturedTriangle( vertices[i].z = src_vbuf[i]->zv * 0.0001f; vertices[i].w = 65536.0f / src_vbuf[i]->zv; - vertices[i].s = - S_Output_GetUV(src_uv[i]->u) * (vertices[i].w / 256.0f); - vertices[i].t = - S_Output_GetUV(src_uv[i]->v) * (vertices[i].w / 256.0f); + vertices[i].s = M_GetUV(src_uv[i]->u) * (vertices[i].w / 256.0f); + vertices[i].t = M_GetUV(src_uv[i]->v) * (vertices[i].w / 256.0f); vertices[i].r = vertices[i].g = vertices[i].b = (8192.0f - src_vbuf[i]->g) * multiplier; @@ -1119,11 +1114,11 @@ void S_Output_DrawTexturedTriangle( } if (vn1->clip || vn2->clip || vn3->clip) { - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); } } else { - if (!S_Output_VisibleZClip(vn1, vn2, vn3)) { + if (!M_VisibleZClip(vn1, vn2, vn3)) { return; } @@ -1134,15 +1129,15 @@ void S_Output_DrawTexturedTriangle( points[i].xs = src_vbuf[i]->xs; points[i].ys = src_vbuf[i]->ys; points[i].g = src_vbuf[i]->g; - points[i].u = S_Output_GetUV(src_uv[i]->u); - points[i].v = S_Output_GetUV(src_uv[i]->v); + points[i].u = M_GetUV(src_uv[i]->u); + points[i].v = M_GetUV(src_uv[i]->v); } - vertex_count = S_Output_ZedClipper(vertex_count, points, vertices); + vertex_count = M_ZedClipper(vertex_count, points, vertices); if (!vertex_count) { return; } - vertex_count = S_Output_ClipVertices( + vertex_count = M_ClipVertices( vertices, vertex_count, sizeof(vertices) / sizeof(vertices[0])); } @@ -1153,10 +1148,10 @@ void S_Output_DrawTexturedTriangle( if (m_TextureMap[tpage] != GFX_NO_TEXTURE) { S_Output_EnableTextureMode(); S_Output_SelectTexture(tpage); - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); } else { S_Output_DisableTextureMode(); - S_Output_DrawTriangleFan(vertices, vertex_count); + M_DrawTriangleFan(vertices, vertex_count); } } @@ -1179,7 +1174,7 @@ void S_Output_DrawTexturedQuad( if (!VBUF_VISIBLE(*vn1, *vn2, *vn3)) { return; } - } else if (!S_Output_VisibleZClip(vn1, vn2, vn3)) { + } else if (!M_VisibleZClip(vn1, vn2, vn3)) { return; } @@ -1212,8 +1207,8 @@ void S_Output_DrawTexturedQuad( vertices[i].z = src_vbuf[i]->zv * 0.0001f; vertices[i].w = 65536.0f / src_vbuf[i]->zv; - vertices[i].s = S_Output_GetUV(src_uv[i]->u) * (vertices[i].w / 256.0f); - vertices[i].t = S_Output_GetUV(src_uv[i]->v) * (vertices[i].w / 256.0f); + vertices[i].s = M_GetUV(src_uv[i]->u) * (vertices[i].w / 256.0f); + vertices[i].t = M_GetUV(src_uv[i]->v) * (vertices[i].w / 256.0f); vertices[i].r = vertices[i].g = vertices[i].b = (8192.0f - src_vbuf[i]->g) * multiplier; @@ -1237,7 +1232,7 @@ void S_Output_DownloadTextures(int32_t pages) Shell_ExitSystem("Attempt to download more than texture page limit"); } - S_Output_ReleaseTextures(); + M_ReleaseTextures(); for (int i = 0; i < pages; i++) { GFX_2D_SurfaceDesc surface_desc = { 0 }; @@ -1430,7 +1425,7 @@ void S_Output_ScreenBox( screen_box_verticies[i].a = col_light.a; } - S_Output_DrawTriangleStrip( + M_DrawTriangleStrip( screen_box_verticies, SB_NUM_VERTS_DARK + SB_NUM_VERTS_LIGHT); } @@ -1508,7 +1503,7 @@ void S_Output_4ColourTextBox( screen_box_verticies[8].b = screen_box_verticies[9].b = tl.b; screen_box_verticies[8].a = screen_box_verticies[9].a = tl.a; - S_Output_DrawTriangleStrip(screen_box_verticies, 10); + M_DrawTriangleStrip(screen_box_verticies, 10); } void S_Output_2ToneColourTextBox( @@ -1635,5 +1630,5 @@ void S_Output_2ToneColourTextBox( screen_box_verticies[16].b = screen_box_verticies[17].b = edge.b; screen_box_verticies[16].a = screen_box_verticies[17].a = edge.a; - S_Output_DrawTriangleStrip(screen_box_verticies, 18); + M_DrawTriangleStrip(screen_box_verticies, 18); } diff --git a/src/specific/s_shell.c b/src/specific/s_shell.c index 02dfd2be8..7f20bb274 100644 --- a/src/specific/s_shell.c +++ b/src/specific/s_shell.c @@ -39,13 +39,13 @@ static int m_ArgCount = 0; static char **m_ArgStrings = NULL; static SDL_Window *m_Window = NULL; -static void S_Shell_SeedRandom(void); -static void S_Shell_SetWindowPos(int32_t x, int32_t y, bool update); -static void S_Shell_SetWindowSize(int32_t width, int32_t height, bool update); -static void S_Shell_SetWindowMaximized(bool is_enabled, bool update); -static void S_Shell_SetFullscreen(bool is_enabled, bool update); +static void M_SeedRandom(void); +static void M_SetWindowPos(int32_t x, int32_t y, bool update); +static void M_SetWindowSize(int32_t width, int32_t height, bool update); +static void M_SetWindowMaximized(bool is_enabled, bool update); +static void M_SetFullscreen(bool is_enabled, bool update); -static void S_Shell_SeedRandom(void) +static void M_SeedRandom(void) { time_t lt = time(0); struct tm *tptr = localtime(<); @@ -53,7 +53,7 @@ static void S_Shell_SeedRandom(void) Random_SeedDraw(tptr->tm_sec + 43 * tptr->tm_min + 3477 * tptr->tm_hour); } -static void S_Shell_SetWindowPos(int32_t x, int32_t y, bool update) +static void M_SetWindowPos(int32_t x, int32_t y, bool update) { if (x <= 0 || y <= 0) { return; @@ -71,7 +71,7 @@ static void S_Shell_SetWindowPos(int32_t x, int32_t y, bool update) } } -static void S_Shell_SetWindowSize(int32_t width, int32_t height, bool update) +static void M_SetWindowSize(int32_t width, int32_t height, bool update) { if (width <= 0 || height <= 0) { return; @@ -91,7 +91,7 @@ static void S_Shell_SetWindowSize(int32_t width, int32_t height, bool update) } } -static void S_Shell_SetWindowMaximized(bool is_enabled, bool update) +static void M_SetWindowMaximized(bool is_enabled, bool update) { g_Config.rendering.enable_maximized = is_enabled; @@ -100,7 +100,7 @@ static void S_Shell_SetWindowMaximized(bool is_enabled, bool update) } } -static void S_Shell_SetFullscreen(bool is_enabled, bool update) +static void M_SetFullscreen(bool is_enabled, bool update) { g_Config.rendering.enable_fullscreen = is_enabled; @@ -113,7 +113,7 @@ static void S_Shell_SetFullscreen(bool is_enabled, bool update) void S_Shell_ToggleFullscreen(void) { - S_Shell_SetFullscreen(!g_Config.rendering.enable_fullscreen, true); + M_SetFullscreen(!g_Config.rendering.enable_fullscreen, true); // save the updated config, but ensure it was loaded first if (g_Config.loaded) { @@ -135,9 +135,9 @@ void S_Shell_HandleWindowResize(void) SDL_GetWindowPosition(m_Window, &x, &y); LOG_INFO("%dx%d+%d,%d (maximized: %d)", width, height, x, y, is_maximized); - S_Shell_SetWindowMaximized(is_maximized, false); - S_Shell_SetWindowPos(x, y, false); - S_Shell_SetWindowSize(width, height, false); + M_SetWindowMaximized(is_maximized, false); + M_SetWindowPos(x, y, false); + M_SetWindowSize(width, height, false); // save the updated config, but ensure it was loaded first if (g_Config.loaded) { @@ -147,15 +147,15 @@ void S_Shell_HandleWindowResize(void) void S_Shell_Init(void) { - S_Shell_SeedRandom(); + M_SeedRandom(); - S_Shell_SetFullscreen(g_Config.rendering.enable_fullscreen, true); - S_Shell_SetWindowPos( + M_SetFullscreen(g_Config.rendering.enable_fullscreen, true); + M_SetWindowPos( g_Config.rendering.window_x, g_Config.rendering.window_y, true); - S_Shell_SetWindowSize( + M_SetWindowSize( g_Config.rendering.window_width, g_Config.rendering.window_height, true); - S_Shell_SetWindowMaximized(g_Config.rendering.enable_maximized, true); + M_SetWindowMaximized(g_Config.rendering.enable_maximized, true); } void S_Shell_ShowFatalError(const char *message)