Skip to content

Commit

Permalink
output: use common texture animation routine
Browse files Browse the repository at this point in the history
This moves the specifics of cycling through animated textures to TRX.
  • Loading branch information
lahm86 committed Jan 28, 2025
1 parent ba819a8 commit 19c66ba
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 62 deletions.
30 changes: 30 additions & 0 deletions src/libtrx/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 1 addition & 26 deletions src/tr1/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
40 changes: 5 additions & 35 deletions src/tr2/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/tr2/game/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 19c66ba

Please sign in to comment.