aboutsummaryrefslogtreecommitdiff
path: root/src/games/tetris/Tetris.cpp
diff options
context:
space:
mode:
authorfschildt <florian.schildt@protonmail.com>2025-11-25 06:21:26 +0100
committerfschildt <florian.schildt@protonmail.com>2025-11-25 06:21:26 +0100
commit3f95bc6b463f629c620ba5811ca3ce53ed9c03a2 (patch)
tree8e2637270472b3ff787f95b24c9567d0c4d3df2b /src/games/tetris/Tetris.cpp
parent746819470de51c4f7331b64980f3da9bfb750a12 (diff)
add MemoryManager, enhance cmake,compile.sh
Diffstat (limited to 'src/games/tetris/Tetris.cpp')
-rw-r--r--src/games/tetris/Tetris.cpp78
1 files changed, 42 insertions, 36 deletions
diff --git a/src/games/tetris/Tetris.cpp b/src/games/tetris/Tetris.cpp
index ecc2c3a..8db772f 100644
--- a/src/games/tetris/Tetris.cpp
+++ b/src/games/tetris/Tetris.cpp
@@ -2,6 +2,7 @@
#include <games/tetris/Tetromino.hpp>
#include <games/tetris/Tetris.hpp>
#include <renderer/Renderer.hpp>
+#include <common/MemoryManager.hpp>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_timer.h>
@@ -51,7 +52,7 @@ Tetris::Start()
bool
Tetris::Update(std::vector<SDL_Event>& events)
{
- m_frame_arena.Reset();
+ m_frame_strings.clear();
if (m_game_status == game_starting) {
Start();
@@ -270,21 +271,25 @@ Tetris::DrawGameOverMenu()
void
Tetris::DrawLineCounter()
{
- std::u32string& text = m_frame_arena.Allocate<std::u32string>(U"Lines: xxx");
V2F32 pos = {0.5f, 2.6f};
Color color = {0.9f, 0.9f, 0.9f, 1.0f};
+
+ String32Id str_id = MemoryManager::EmplaceString32_Frame(U"Lines: xxx");
+ std::u32string& str = MemoryManager::GetString32(str_id);
int line_count = std::min(m_line_counter, 999);
- text[9] = U'0' + char32_t(line_count % 10);
+ str[9] = U'0' + char32_t(line_count % 10);
line_count /= 10;
- text[8] = U'0' + char32_t(line_count % 10);
+
+ str[8] = U'0' + char32_t(line_count % 10);
line_count /= 10;
- text[7] = U'0' + char32_t(line_count % 10);
+
+ str[7] = U'0' + char32_t(line_count % 10);
line_count /= 10;
- g_renderer.PushText(text, m_font, pos, color, z_text);
+ g_renderer.PushString32(str_id, m_font, pos, color, z_text);
pos.x += 0.2f;
}
@@ -294,9 +299,9 @@ Tetris::DrawStatistics()
V2F32 pos = {0.4f, 0.5f};
- std::u32string& title_text = m_frame_arena.Allocate<std::u32string>(U"Statistics");
+ String32Id title_text = MemoryManager::EmplaceString32_Frame(U"Statistics");
V2F32 title_pos = {pos.x + 0.02f, pos.y + 1.64f};
- g_renderer.PushText(title_text, m_font, title_pos, s_text_color, z_text);
+ g_renderer.PushString32(title_text, m_font, title_pos, s_text_color, z_text);
float yadvance = -0.2f;
float tetrominoes_x0 = pos.x;
@@ -331,27 +336,28 @@ Tetris::DrawStatistics()
float counters_y0 = pos.y + 0.05f - yadvance * (float)Tetromino::id_count;
V2F32 counters_pos = {counters_x0, counters_y0};
- std::u32string& t_count = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_tetromino_counters[Tetromino::t_piece]));
- std::u32string& j_count = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_tetromino_counters[Tetromino::j_piece]));
- std::u32string& z_count = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_tetromino_counters[Tetromino::z_piece]));
- std::u32string& o_count = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_tetromino_counters[Tetromino::o_piece]));
- std::u32string& s_count = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_tetromino_counters[Tetromino::s_piece]));
- std::u32string& l_count = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_tetromino_counters[Tetromino::l_piece]));
- std::u32string& i_count = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_tetromino_counters[Tetromino::i_piece]));
- g_renderer.PushText(t_count, m_font, counters_pos, s_text_color, z_text);
+ String32Id t_count = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_tetromino_counters[Tetromino::t_piece]));
+ String32Id j_count = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_tetromino_counters[Tetromino::j_piece]));
+ String32Id z_count = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_tetromino_counters[Tetromino::z_piece]));
+ String32Id o_count = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_tetromino_counters[Tetromino::o_piece]));
+ String32Id s_count = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_tetromino_counters[Tetromino::s_piece]));
+ String32Id l_count = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_tetromino_counters[Tetromino::l_piece]));
+ String32Id i_count = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_tetromino_counters[Tetromino::i_piece]));
+
+ g_renderer.PushString32(t_count, m_font, counters_pos, s_text_color, z_text);
counters_pos.y += yadvance;
- g_renderer.PushText(j_count, m_font, counters_pos, s_text_color, z_text);
+ g_renderer.PushString32(j_count, m_font, counters_pos, s_text_color, z_text);
counters_pos.y += yadvance;
- g_renderer.PushText(z_count, m_font, counters_pos, s_text_color, z_text);
+ g_renderer.PushString32(z_count, m_font, counters_pos, s_text_color, z_text);
counters_pos.y += yadvance;
- g_renderer.PushText(o_count, m_font, counters_pos, s_text_color, z_text);
+ g_renderer.PushString32(o_count, m_font, counters_pos, s_text_color, z_text);
counters_pos.y += yadvance;
- g_renderer.PushText(s_count, m_font, counters_pos, s_text_color, z_text);
+ g_renderer.PushString32(s_count, m_font, counters_pos, s_text_color, z_text);
counters_pos.y += yadvance;
- g_renderer.PushText(l_count, m_font, counters_pos, s_text_color, z_text);
+ g_renderer.PushString32(l_count, m_font, counters_pos, s_text_color, z_text);
counters_pos.y += yadvance;
- g_renderer.PushText(i_count, m_font, counters_pos, s_text_color, z_text);
+ g_renderer.PushString32(i_count, m_font, counters_pos, s_text_color, z_text);
}
void
@@ -360,21 +366,21 @@ Tetris::DrawScore()
V2F32 pos = {3.0f, 2.6f};
- std::u32string& top_label = m_frame_arena.Allocate<std::u32string>(U"Top");
- std::u32string& top_value = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_highscore));
+ String32Id top_label = MemoryManager::EmplaceString32_Frame(U"Top");
+ String32Id top_value = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_highscore));
- std::u32string& score_label = m_frame_arena.Allocate<std::u32string>(U"Score");
- std::u32string& score_value = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_score));
+ String32Id score_label = MemoryManager::EmplaceString32_Frame(U"Score");
+ String32Id score_value = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_score));
- g_renderer.PushText(top_label, m_font, pos, s_text_color, z_text);
+ g_renderer.PushString32(top_label, m_font, pos, s_text_color, z_text);
pos.y -= 0.1f;
- g_renderer.PushText(top_value, m_font, pos, s_text_color, z_text);
+ g_renderer.PushString32(top_value, m_font, pos, s_text_color, z_text);
pos.y -= 0.2f;
- g_renderer.PushText(score_label, m_font, pos, s_text_color, z_text);
+ g_renderer.PushString32(score_label, m_font, pos, s_text_color, z_text);
pos.y -= 0.1f;
- g_renderer.PushText(score_value, m_font, pos, s_text_color, z_text);
+ g_renderer.PushString32(score_value, m_font, pos, s_text_color, z_text);
}
void
@@ -384,8 +390,8 @@ Tetris::DrawNextTetromino()
V2F32 label_pos = {pos.x, pos.y + 0.4f};
- std::u32string& label_text = m_frame_arena.Allocate<std::u32string>(U"Next:");
- g_renderer.PushText(label_text, m_font, label_pos, s_text_color, z_layer1);
+ String32Id label_text = MemoryManager::EmplaceString32_Frame(U"Next:");
+ g_renderer.PushString32(label_text, m_font, label_pos, s_text_color, z_layer1);
V2F32 tetromino_pos = {pos.x, pos.y};
@@ -397,11 +403,11 @@ Tetris::DrawLevel()
{
V2F32 pos = {3.0f, 1.1f};
- std::u32string& label = m_frame_arena.Allocate<std::u32string>(U"Level");
- g_renderer.PushText(label, m_font, pos, s_text_color, z_text);
+ String32Id label = MemoryManager::EmplaceString32_Frame(U"Level");
+ g_renderer.PushString32(label, m_font, pos, s_text_color, z_text);
pos.y -= 0.1f;
- std::u32string& level = m_frame_arena.Allocate<std::u32string>(int32_to_u32string(m_level));
- g_renderer.PushText(level, m_font, pos, s_text_color, z_text);
+ String32Id level = MemoryManager::EmplaceString32_Frame(int32_to_u32string(m_level));
+ g_renderer.PushString32(level, m_font, pos, s_text_color, z_text);
}