mirror of
https://github.com/GearsProgress/Poke_Transporter_GB.git
synced 2026-09-10 10:05:35 -05:00
Replace text_data_table with FileContainerReader
text_data_table was very similar in concept to FileContainerReader. But FileContainerReader is generally more flexible, as it allows you to split up your table into several chunks. This takes away the worry of these files getting too big to compress. However, we now have a maintenance duty for the text_tables file, which maps a table index to the list of chunks. We also need to be careful about every use of FileContainerReader::getPointerToFileInDecompressionBuffer(). Using it is fine when you're dealing with a single chunk or if you're sure the file doesn't span multiple chunks. But the moment you seek to a different chunk, any pointer obtained from getPointerToFileInDecompressionBuffer() becomes stale as the decompression buffer gets overwritten. Still, this function is necessary for high memory pressure situations, such as mystery_gift_builder, because we can't maintain multiple lineBuffers there.
This commit is contained in:
116
source/main.cpp
116
source/main.cpp
@@ -27,7 +27,9 @@
|
||||
#include "multiboot_upload.h"
|
||||
#include "rom_data.h"
|
||||
#include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h"
|
||||
#include "text_data_table.h"
|
||||
#include "FileContainerReader.h"
|
||||
#include "translated_text.h"
|
||||
#include "text_tables.h"
|
||||
#include "custom_malloc.h"
|
||||
#include "sound.h"
|
||||
|
||||
@@ -111,18 +113,23 @@ void initialization_script(void)
|
||||
PTGB_MGBA_INFO("Hello from PTGB!");
|
||||
};
|
||||
|
||||
void game_load_error(void)
|
||||
// attribute noinline is used to make sure it doesn't get inlined and permanently use IWRAM for the decompression_buffer
|
||||
void __attribute__((noinline)) game_load_error(void)
|
||||
{
|
||||
u8 general_text_buffer[2048];
|
||||
u8 lineBuffer[1024];
|
||||
const u8 **chunkList;
|
||||
u32 numChunks;
|
||||
u32 chunkSize;
|
||||
|
||||
get_text_table_chunks(GENERAL_INDEX, &chunkList, &numChunks, &chunkSize);
|
||||
FileContainerReader text_reader(chunkList, numChunks, chunkSize);
|
||||
|
||||
text_reader.init(general_text_buffer, sizeof(general_text_buffer));
|
||||
|
||||
BG_TEXTBOX = (BG_TEXTBOX & ~BG_PRIO_MASK) | BG_PRIO(1);
|
||||
|
||||
{
|
||||
u8 general_text_table_buffer[2048];
|
||||
text_data_table general_text(general_text_table_buffer);
|
||||
|
||||
general_text.decompress(get_compressed_text_table(GENERAL_INDEX));
|
||||
ptgb_write_textbox(general_text.get_text_entry(GENERAL_cart_load_error), true, false,
|
||||
GENERAL_INDEX, GENERAL_cart_load_error, false);
|
||||
}
|
||||
text_reader.readFile(GENERAL_cart_load_error, lineBuffer);
|
||||
ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, GENERAL_cart_load_error, false);
|
||||
|
||||
// key_poll();
|
||||
do
|
||||
@@ -153,39 +160,28 @@ void game_load_error(void)
|
||||
}
|
||||
}
|
||||
|
||||
void first_load_message(void)
|
||||
// avoid inlining to avoid permanently storing the credits_decompression_buffer in IWRAM
|
||||
int __attribute__((noinline)) credits()
|
||||
{
|
||||
tte_set_ink(INK_ROM_COLOR);
|
||||
u8 credits_decompression_buffer[2048];
|
||||
u8 lineBuffer[1024];
|
||||
const u8 **chunkList;
|
||||
u32 numChunks;
|
||||
u32 chunkSize;
|
||||
|
||||
{
|
||||
u8 general_text_table_buffer[2048];
|
||||
text_data_table general_text(general_text_table_buffer);
|
||||
get_text_table_chunks(CREDITS_INDEX, &chunkList, &numChunks, &chunkSize);
|
||||
FileContainerReader creditsReader(chunkList, numChunks, chunkSize);
|
||||
u32 curr_credits_num = 0;
|
||||
|
||||
general_text.decompress(get_compressed_text_table(GENERAL_INDEX));
|
||||
ptgb_write_simple(general_text.get_text_entry(GENERAL_intro_first), true);
|
||||
}
|
||||
|
||||
while (!key_hit(KEY_A))
|
||||
{
|
||||
VBlankIntrWait();
|
||||
}
|
||||
}
|
||||
|
||||
int credits()
|
||||
{
|
||||
u8 text_decompression_buffer[2048];
|
||||
text_data_table credits_text_table(text_decompression_buffer);
|
||||
int curr_credits_num = 0;
|
||||
|
||||
credits_text_table.decompress(get_compressed_text_table(CREDITS_INDEX));
|
||||
creditsReader.init(credits_decompression_buffer, sizeof(credits_decompression_buffer));
|
||||
bool update = true;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (update)
|
||||
{
|
||||
ptgb_write_textbox(credits_text_table.get_text_entry(curr_credits_num), true, false,
|
||||
CREDITS_INDEX, curr_credits_num, false);
|
||||
creditsReader.readFile(curr_credits_num, lineBuffer);
|
||||
ptgb_write_textbox(lineBuffer, true, false, CREDITS_INDEX, curr_credits_num, false);
|
||||
update = false;
|
||||
}
|
||||
|
||||
@@ -201,7 +197,7 @@ int credits()
|
||||
curr_credits_num--;
|
||||
update = true;
|
||||
}
|
||||
if (key_hit(KEY_RIGHT) && curr_credits_num < (credits_text_table.get_number_of_text_entries() - 1))
|
||||
if (key_hit(KEY_RIGHT) && curr_credits_num < (creditsReader.getNumberOfFiles() - 1))
|
||||
{
|
||||
curr_credits_num++;
|
||||
update = true;
|
||||
@@ -211,19 +207,24 @@ int credits()
|
||||
}
|
||||
};
|
||||
|
||||
int main_menu_loop()
|
||||
// attribute noinline is used to avoid permanently storing the general_text_table_buffer in IWRAM
|
||||
int __attribute__((noinline)) main_menu_loop()
|
||||
{
|
||||
uint8_t general_text_table_buffer[2048];
|
||||
u8 lineBuffer[1024];
|
||||
#define NUM_MENU_OPTIONS 3
|
||||
const uint8_t menu_options[NUM_MENU_OPTIONS] = {GENERAL_option_transfer, GENERAL_option_dreamdex, GENERAL_option_credits};
|
||||
int return_values[NUM_MENU_OPTIONS] = {BTN_TRANSFER, BTN_POKEDEX, BTN_CREDITS};
|
||||
const u8 **chunkList;
|
||||
u32 numChunks;
|
||||
u32 chunkSize;
|
||||
|
||||
uint8_t general_text_table_buffer[2048];
|
||||
text_data_table general_text(general_text_table_buffer);
|
||||
get_text_table_chunks(GENERAL_INDEX, &chunkList, &numChunks, &chunkSize);
|
||||
FileContainerReader text_reader(chunkList, numChunks, chunkSize);
|
||||
bool update = true;
|
||||
const uint8_t *text_entry;
|
||||
u16 test = 0;
|
||||
|
||||
general_text.decompress(get_compressed_text_table(GENERAL_INDEX));
|
||||
text_reader.init(general_text_table_buffer, sizeof(general_text_table_buffer));
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -231,8 +232,8 @@ int main_menu_loop()
|
||||
{
|
||||
for (int i = 0; i < NUM_MENU_OPTIONS; i++)
|
||||
{
|
||||
text_entry = general_text.get_text_entry(menu_options[i]);
|
||||
int string_length = get_string_length(text_entry);
|
||||
text_reader.readFile(menu_options[i], lineBuffer);
|
||||
int string_length = get_string_length(lineBuffer);
|
||||
int x = ((240 - string_length) / 2);
|
||||
tte_set_pos(x, ((i * (16 + 10)) + 70));
|
||||
if (i == curr_selection)
|
||||
@@ -243,7 +244,7 @@ int main_menu_loop()
|
||||
{
|
||||
tte_set_ink(INK_ROM_COLOR);
|
||||
}
|
||||
ptgb_write_simple(text_entry, true);
|
||||
ptgb_write_simple(lineBuffer, true);
|
||||
test++;
|
||||
}
|
||||
}
|
||||
@@ -296,18 +297,21 @@ static void show_gears_of_progress()
|
||||
// this decision was based on the output of build/main.su after adding the -fstack-usage compile flag
|
||||
static void __attribute__((noinline)) show_intro()
|
||||
{
|
||||
bool start_pressed = false;
|
||||
u8 general_text_table_buffer[2048];
|
||||
u8 lineBuffer[1024];
|
||||
const u8 **chunkList;
|
||||
u32 numChunks;
|
||||
u32 chunkSize;
|
||||
|
||||
text_data_table general_text(general_text_table_buffer);
|
||||
const u8 *text_entry;
|
||||
get_text_table_chunks(GENERAL_INDEX, &chunkList, &numChunks, &chunkSize);
|
||||
FileContainerReader general_text_reader(chunkList, numChunks, chunkSize);
|
||||
bool start_pressed = false;
|
||||
|
||||
general_text.decompress(get_compressed_text_table(GENERAL_INDEX));
|
||||
text_entry = general_text.get_text_entry(GENERAL_intro_legal);
|
||||
general_text_reader.init(general_text_table_buffer, sizeof(general_text_table_buffer));
|
||||
|
||||
tte_set_ink(INK_ROM_COLOR);
|
||||
ptgb_write_textbox(text_entry, true, true,
|
||||
GENERAL_INDEX, GENERAL_intro_legal, true);
|
||||
general_text_reader.readFile(GENERAL_intro_legal, lineBuffer);
|
||||
ptgb_write_textbox(lineBuffer, true, true, GENERAL_INDEX, GENERAL_intro_legal, true);
|
||||
|
||||
show_gears_of_progress();
|
||||
|
||||
@@ -322,12 +326,11 @@ static void __attribute__((noinline)) show_intro()
|
||||
|
||||
REG_BLDCNT = BLD_BUILD(BLD_BG3, BLD_BG0, 1);
|
||||
|
||||
general_text.decompress(get_compressed_text_table(GENERAL_INDEX));
|
||||
text_entry = general_text.get_text_entry(GENERAL_press_start);
|
||||
general_text_reader.readFile(GENERAL_press_start, lineBuffer);
|
||||
|
||||
tte_set_pos(0, 12 * 8);
|
||||
tte_set_ink(INK_DARK_GREY);
|
||||
ptgb_write_simple(text_entry, true);
|
||||
ptgb_write_simple(lineBuffer, true);
|
||||
|
||||
int fade = 0;
|
||||
while (!start_pressed)
|
||||
@@ -347,11 +350,6 @@ int main(void)
|
||||
// Set colors based on current ROM
|
||||
set_background_pal(0, false, false);
|
||||
|
||||
/* First load message doesn't really make sense anymore, since you have to load the ROM first.
|
||||
if (!get_tutorial_flag())
|
||||
{
|
||||
first_load_message();
|
||||
}*/
|
||||
show_intro();
|
||||
|
||||
// key_poll();
|
||||
|
||||
Reference in New Issue
Block a user