From 19c66bacd33992a69a7b918c813e80e0eb3bbb4b Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Mon, 27 Jan 2025 21:22:07 +0000 Subject: [PATCH] output: use common texture animation routine This moves the specifics of cycling through animated textures to TRX. --- src/libtrx/game/output.c | 30 +++++++++++++++++++ src/libtrx/include/libtrx/game/output.h | 1 + src/tr1/game/output.c | 27 +---------------- src/tr2/game/output.c | 40 ++++--------------------- src/tr2/game/output.h | 1 - 5 files changed, 37 insertions(+), 62 deletions(-) diff --git a/src/libtrx/game/output.c b/src/libtrx/game/output.c index 1d4aca915..d30db9ae9 100644 --- a/src/libtrx/game/output.c +++ b/src/libtrx/game/output.c @@ -3,6 +3,7 @@ #include "game/const.h" #include "game/game_buf.h" #include "game/matrix.h" +#include "game/objects/common.h" #include "utils.h" #define MAX_DYNAMIC_LIGHTS 10 @@ -111,6 +112,35 @@ void Output_InitialiseAnimatedTextures(const int32_t num_ranges) GBUF_ANIMATED_TEXTURE_RANGES); } +void Output_CycleAnimatedTextures(void) +{ + const ANIMATED_TEXTURE_RANGE *range = g_AnimTextureRanges; + for (; range != NULL; range = range->next_range) { + int32_t i = 0; + const OBJECT_TEXTURE temp = g_ObjectTextures[range->textures[i]]; + for (; i < range->num_textures - 1; i++) { + g_ObjectTextures[range->textures[i]] = + g_ObjectTextures[range->textures[i + 1]]; + } + g_ObjectTextures[range->textures[i]] = temp; + } + + for (int32_t i = 0; i < MAX_STATIC_OBJECTS; i++) { + const STATIC_OBJECT_2D *const object = Object_GetStaticObject2D(i); + if (!object->loaded || object->frame_count == 1) { + continue; + } + + const int16_t frame_count = object->frame_count; + const SPRITE_TEXTURE temp = g_SpriteTextures[object->texture_idx]; + for (int32_t j = 0; j < frame_count - 1; j++) { + g_SpriteTextures[object->texture_idx + j] = + g_SpriteTextures[object->texture_idx + j + 1]; + } + g_SpriteTextures[object->texture_idx + frame_count - 1] = temp; + } +} + void Output_CalculateLight(const XYZ_32 pos, const int16_t room_num) { const ROOM *const room = Room_Get(room_num); diff --git a/src/libtrx/include/libtrx/game/output.h b/src/libtrx/include/libtrx/game/output.h index b4bb3736e..009f6c40b 100644 --- a/src/libtrx/include/libtrx/game/output.h +++ b/src/libtrx/include/libtrx/game/output.h @@ -37,6 +37,7 @@ extern int32_t Output_GetRoomLightShade(ROOM_LIGHT_MODE mode); extern void Output_LightRoomVertices(const ROOM *room); void Output_InitialiseAnimatedTextures(int32_t num_ranges); +void Output_CycleAnimatedTextures(void); void Output_CalculateLight(XYZ_32 pos, int16_t room_num); void Output_CalculateStaticLight(int16_t adder); diff --git a/src/tr1/game/output.c b/src/tr1/game/output.c index 8ff6d54fd..952e807b1 100644 --- a/src/tr1/game/output.c +++ b/src/tr1/game/output.c @@ -1081,32 +1081,7 @@ void Output_AnimateTextures(const int32_t num_frames) m_WibbleOffset = (m_WibbleOffset + num_frames) % WIBBLE_SIZE; m_AnimatedTexturesOffset += num_frames; while (m_AnimatedTexturesOffset > 5) { - const ANIMATED_TEXTURE_RANGE *range = g_AnimTextureRanges; - while (range != NULL) { - int32_t i = 0; - const OBJECT_TEXTURE temp = g_ObjectTextures[range->textures[i]]; - for (; i < range->num_textures - 1; i++) { - g_ObjectTextures[range->textures[i]] = - g_ObjectTextures[range->textures[i + 1]]; - } - g_ObjectTextures[range->textures[i]] = temp; - range = range->next_range; - } - - for (int32_t i = 0; i < MAX_STATIC_OBJECTS; i++) { - const STATIC_OBJECT_2D *const object = Object_GetStaticObject2D(i); - if (!object->loaded || object->frame_count == 1) { - continue; - } - - const int16_t frame_count = object->frame_count; - const SPRITE_TEXTURE temp = g_SpriteTextures[object->texture_idx]; - for (int32_t j = 0; j < frame_count - 1; j++) { - g_SpriteTextures[object->texture_idx + j] = - g_SpriteTextures[object->texture_idx + j + 1]; - } - g_SpriteTextures[object->texture_idx + frame_count - 1] = temp; - } + Output_CycleAnimatedTextures(); m_AnimatedTexturesOffset -= 5; } } diff --git a/src/tr2/game/output.c b/src/tr2/game/output.c index 60f3ec99a..bdd5476ef 100644 --- a/src/tr2/game/output.c +++ b/src/tr2/game/output.c @@ -742,40 +742,6 @@ int16_t Output_FindColor( return best_idx; } -void Output_DoAnimateTextures(const int32_t ticks) -{ - m_TickComp += ticks; - while (m_TickComp > TICKS_PER_FRAME * 5) { - const ANIMATED_TEXTURE_RANGE *range = g_AnimTextureRanges; - while (range != NULL) { - int32_t i = 0; - const OBJECT_TEXTURE temp = g_ObjectTextures[range->textures[i]]; - for (; i < range->num_textures - 1; i++) { - g_ObjectTextures[range->textures[i]] = - g_ObjectTextures[range->textures[i + 1]]; - } - g_ObjectTextures[range->textures[i]] = temp; - range = range->next_range; - } - - for (int32_t i = 0; i < MAX_STATIC_OBJECTS; i++) { - const STATIC_OBJECT_2D *const object = Object_GetStaticObject2D(i); - if (!object->loaded || object->frame_count == 1) { - continue; - } - - const int16_t frame_count = object->frame_count; - const SPRITE_TEXTURE temp = g_SpriteTextures[object->texture_idx]; - for (int32_t j = 0; j < frame_count - 1; j++) { - g_SpriteTextures[object->texture_idx + j] = - g_SpriteTextures[object->texture_idx + j + 1]; - } - g_SpriteTextures[object->texture_idx + frame_count - 1] = temp; - } - m_TickComp -= TICKS_PER_FRAME * 5; - } -} - void Output_InsertShadow( int16_t radius, const BOUNDS_16 *bounds, const ITEM *item) { @@ -933,7 +899,11 @@ void Output_AnimateTextures(const int32_t ticks) g_SunsetTimer * (WIBBLE_SIZE - 1) / SUNSET_TIMEOUT; } - Output_DoAnimateTextures(ticks); + m_TickComp += ticks; + while (m_TickComp > TICKS_PER_FRAME * 5) { + Output_CycleAnimatedTextures(); + m_TickComp -= TICKS_PER_FRAME * 5; + } } void Output_SetLightAdder(const int32_t adder) diff --git a/src/tr2/game/output.h b/src/tr2/game/output.h index 17376ce6f..4f3166c20 100644 --- a/src/tr2/game/output.h +++ b/src/tr2/game/output.h @@ -74,7 +74,6 @@ void Output_DrawAirBar(int32_t percent); void Output_LoadBackgroundFromObject(void); int16_t Output_FindColor(int32_t red, int32_t green, int32_t blue); -void Output_DoAnimateTextures(int32_t ticks); void Output_InsertShadow( int16_t radius, const BOUNDS_16 *bounds, const ITEM *item);