Skip to content

Commit

Permalink
packer: move packer module to TRX
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 committed Jan 26, 2025
1 parent 4a4f4ef commit b8e8b06
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
85 changes: 41 additions & 44 deletions src/tr1/game/packer.c → src/libtrx/game/packer.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#include "game/packer.h"

#include "global/const.h"
#include "global/types.h"
#include "global/vars.h"

#include <libtrx/log.h>
#include <libtrx/memory.h>
#include <libtrx/utils.h>
#include "game/output.h"
#include "log.h"
#include "memory.h"
#include "utils.h"

#include <stddef.h>
#include <string.h>
Expand Down Expand Up @@ -76,43 +73,6 @@ static TEX_PAGE *m_VirtualPages = NULL;
static int32_t m_QueueSize = 0;
static TEX_CONTAINER *m_Queue = NULL;

bool Packer_Pack(PACKER_DATA *data)
{
m_Data = data;

m_StartPage = m_Data->level_page_count - 1;
m_EndPage = MAX_TEXTURE_PAGES - m_StartPage;
m_UsedPageCount = 0;
m_QueueSize = 0;

M_AllocateNewPage();

for (int i = 0; i < data->object_count; i++) {
M_PrepareObject(i);
}
for (int i = 0; i < data->sprite_count; i++) {
M_PrepareSprite(i);
}

bool result = true;
for (int i = 0; i < m_QueueSize; i++) {
TEX_CONTAINER *container = &m_Queue[i];
if (!M_PackContainer(container)) {
LOG_ERROR("Failed to pack container %d of %d", i, m_QueueSize);
result = false;
break;
}
}

M_Cleanup();
return result;
}

int32_t Packer_GetAddedPageCount(void)
{
return m_UsedPageCount - 1;
}

static void M_PrepareObject(int object_index)
{
const OBJECT_TEXTURE *const object_texture =
Expand Down Expand Up @@ -423,3 +383,40 @@ static void M_Cleanup(void)
Memory_FreePointer(&m_VirtualPages);
Memory_FreePointer(&m_Queue);
}

bool Packer_Pack(PACKER_DATA *const data)
{
m_Data = data;

m_StartPage = m_Data->level_page_count - 1;
m_EndPage = MAX_TEXTURE_PAGES - m_StartPage;
m_UsedPageCount = 0;
m_QueueSize = 0;

M_AllocateNewPage();

for (int i = 0; i < data->object_count; i++) {
M_PrepareObject(i);
}
for (int i = 0; i < data->sprite_count; i++) {
M_PrepareSprite(i);
}

bool result = true;
for (int i = 0; i < m_QueueSize; i++) {
TEX_CONTAINER *container = &m_Queue[i];
if (!M_PackContainer(container)) {
LOG_ERROR("Failed to pack container %d of %d", i, m_QueueSize);
result = false;
break;
}
}

M_Cleanup();
return result;
}

int32_t Packer_GetAddedPageCount(void)
{
return m_UsedPageCount - 1;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "global/types.h"
#include "./output/types.h"

#include <stdint.h>

Expand Down
1 change: 1 addition & 0 deletions src/libtrx/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ sources = [
'game/objects/names.c',
'game/objects/vars.c',
'game/output.c',
'game/packer.c',
'game/phase/executor.c',
'game/phase/phase_cutscene.c',
'game/phase/phase_demo.c',
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "game/camera.h"
#include "game/output.h"
#include "game/packer.h"
#include "game/room.h"
#include "global/const.h"
#include "global/vars.h"
Expand All @@ -13,6 +12,7 @@
#include <libtrx/debug.h>
#include <libtrx/game/game_buf.h>
#include <libtrx/game/level.h>
#include <libtrx/game/packer.h>
#include <libtrx/log.h>
#include <libtrx/memory.h>
#include <libtrx/utils.h>
Expand Down
1 change: 0 additions & 1 deletion src/tr1/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ sources = [
'game/option/option_sound.c',
'game/output.c',
'game/overlay.c',
'game/packer.c',
'game/requester.c',
'game/room.c',
'game/room_draw.c',
Expand Down

0 comments on commit b8e8b06

Please sign in to comment.