From 5df0d0616ee3996add0b14e0fb0becd6257d04a2 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 21 Feb 2021 17:56:17 -0500 Subject: Added a debug console Open it by pressing backtick, close it by hitting escape. Pressing backtick does not open it in release builds. Current shortcomings: opening it for the first time also types a backtick for some reason, but not on subsequent times. Also, it doesn't create a coroutine, so any script function that yields is going to fail. This also added a "is gameplay paused" flag to Game, which will be useful for adding a pause menu. --- src/renderer.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/renderer.cpp') diff --git a/src/renderer.cpp b/src/renderer.cpp index 5aeb232..f8b2482 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -7,6 +7,7 @@ #include "camera_system.h" #include "message_system.h" #include "effect_system.h" +#include "input_system.h" Renderer::Renderer() { win_ = window_ptr( @@ -333,6 +334,61 @@ void Renderer::render(Game& game) { SDL_RenderFillRect(ren_.get(), nullptr); } + if (game.getSystem().isDebugConsoleOpen()) { + // Not sure why I'm supposed to copy the cached texture to the screen + // BEFORE rendering it, but we get flickering if we don't, so. + SDL_RenderCopy(ren_.get(), debugConsoleTex_.get(), nullptr, &debugDestRect_); + + if (!debugConsoleTex_ || cachedDebugText_ != game.getSystem().getDebugText()) { + cachedDebugText_ = game.getSystem().getDebugText(); + + std::vector textLines; + std::string remaining = "`" + cachedDebugText_; + + while (!remaining.empty()) { + MessageCache output; + renderMessageLine(output, remaining, game); + textLines.push_back(std::move(output.renderedTex)); + remaining = output.overflow; + + if (!remaining.empty()) { + remaining = " " + remaining; + } + } + + int height = 16 * textLines.size() + 4 + 4; + + debugConsoleTex_.reset( + SDL_CreateTexture( + ren_.get(), + SDL_PIXELFORMAT_RGBA8888, + SDL_TEXTUREACCESS_TARGET, + CANVAS_WIDTH, + height)); + + SDL_SetRenderTarget(ren_.get(), debugConsoleTex_.get()); + SDL_SetTextureBlendMode(debugConsoleTex_.get(), SDL_BLENDMODE_BLEND); + SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_BLEND); + SDL_SetRenderDrawColor(ren_.get(), 30, 0, 110, 127); + //SDL_RenderFillRect(ren_.get(), nullptr); + SDL_RenderClear(ren_.get()); + + for (int i=0; i MESSAGE_TEXT_WIDTH) { + line.overflow = line.line.substr(i); + break; + } + vec2i charLoc = game.getFont().getCharacterLocation(line.line[i]); vec2i charSize = game.getFont().getCharacterSize(line.line[i]); SDL_Rect srcRect { charLoc.x(), charLoc.y(), charSize.w(), charSize.h() }; -- cgit 1.4.1