diff options
Diffstat (limited to 'src/games')
| -rw-r--r-- | src/games/Game.cpp | 8 | ||||
| -rw-r--r-- | src/games/Game.hpp | 5 | ||||
| -rw-r--r-- | src/games/tetris/Tetris.cpp | 78 | ||||
| -rw-r--r-- | src/games/tetris/Tetris.hpp | 3 |
4 files changed, 55 insertions, 39 deletions
diff --git a/src/games/Game.cpp b/src/games/Game.cpp index c403a40..7c63b4f 100644 --- a/src/games/Game.cpp +++ b/src/games/Game.cpp @@ -79,3 +79,11 @@ Game::DrawDefaultGamePausedMenu() ImGui::End(); } +Game::FrameString32 +Game::PushFrameString32(std::u32string&& str) +{ + m_frame_strings.emplace_back(str); + FrameString32 id = static_cast<uint32_t>(m_frame_strings.size()-1); + return id; +} + diff --git a/src/games/Game.hpp b/src/games/Game.hpp index aad3c1b..e9eed82 100644 --- a/src/games/Game.hpp +++ b/src/games/Game.hpp @@ -34,6 +34,9 @@ public: z_text }; + using FrameString32 = uint32_t; + + static std::unique_ptr<Game> Select(GameType type); @@ -47,10 +50,12 @@ protected: void DrawDefaultGamePausedMenu(); float ProcessDt(); + uint32_t PushFrameString32(std::u32string&& str); GameStatus m_game_status {game_starting}; float m_dt_remaining_seconds {0.0f}; uint64_t m_tlast_milliseconds {SDL_GetTicks()}; + std::vector<std::u32string> m_frame_strings; protected: 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); } diff --git a/src/games/tetris/Tetris.hpp b/src/games/tetris/Tetris.hpp index 905458a..44ed9ff 100644 --- a/src/games/tetris/Tetris.hpp +++ b/src/games/tetris/Tetris.hpp @@ -5,7 +5,6 @@ #include <games/tetris/Tetromino.hpp> #include <games/tetris/Board.hpp> #include <common/Font.hpp> -#include <common/Arena.hpp> class Tetris : public Game { @@ -51,8 +50,6 @@ private: int32_t m_level = 0; int32_t m_softdrop_counter = 0; int32_t m_highscore = 0; - - Arena m_frame_arena {KIBIBYTES(2)}; }; |
