diff options
Diffstat (limited to 'src/renderer.cpp')
| -rw-r--r-- | src/renderer.cpp | 61 | 
1 files changed, 61 insertions, 0 deletions
| 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 @@ | |||
| 7 | #include "camera_system.h" | 7 | #include "camera_system.h" | 
| 8 | #include "message_system.h" | 8 | #include "message_system.h" | 
| 9 | #include "effect_system.h" | 9 | #include "effect_system.h" | 
| 10 | #include "input_system.h" | ||
| 10 | 11 | ||
| 11 | Renderer::Renderer() { | 12 | Renderer::Renderer() { | 
| 12 | win_ = window_ptr( | 13 | win_ = window_ptr( | 
| @@ -333,6 +334,61 @@ void Renderer::render(Game& game) { | |||
| 333 | SDL_RenderFillRect(ren_.get(), nullptr); | 334 | SDL_RenderFillRect(ren_.get(), nullptr); | 
| 334 | } | 335 | } | 
| 335 | 336 | ||
| 337 | if (game.getSystem<InputSystem>().isDebugConsoleOpen()) { | ||
| 338 | // Not sure why I'm supposed to copy the cached texture to the screen | ||
| 339 | // BEFORE rendering it, but we get flickering if we don't, so. | ||
| 340 | SDL_RenderCopy(ren_.get(), debugConsoleTex_.get(), nullptr, &debugDestRect_); | ||
| 341 | |||
| 342 | if (!debugConsoleTex_ || cachedDebugText_ != game.getSystem<InputSystem>().getDebugText()) { | ||
| 343 | cachedDebugText_ = game.getSystem<InputSystem>().getDebugText(); | ||
| 344 | |||
| 345 | std::vector<texture_ptr> textLines; | ||
| 346 | std::string remaining = "`" + cachedDebugText_; | ||
| 347 | |||
| 348 | while (!remaining.empty()) { | ||
| 349 | MessageCache output; | ||
| 350 | renderMessageLine(output, remaining, game); | ||
| 351 | textLines.push_back(std::move(output.renderedTex)); | ||
| 352 | remaining = output.overflow; | ||
| 353 | |||
| 354 | if (!remaining.empty()) { | ||
| 355 | remaining = " " + remaining; | ||
| 356 | } | ||
| 357 | } | ||
| 358 | |||
| 359 | int height = 16 * textLines.size() + 4 + 4; | ||
| 360 | |||
| 361 | debugConsoleTex_.reset( | ||
| 362 | SDL_CreateTexture( | ||
| 363 | ren_.get(), | ||
| 364 | SDL_PIXELFORMAT_RGBA8888, | ||
| 365 | SDL_TEXTUREACCESS_TARGET, | ||
| 366 | CANVAS_WIDTH, | ||
| 367 | height)); | ||
| 368 | |||
| 369 | SDL_SetRenderTarget(ren_.get(), debugConsoleTex_.get()); | ||
| 370 | SDL_SetTextureBlendMode(debugConsoleTex_.get(), SDL_BLENDMODE_BLEND); | ||
| 371 | SDL_SetRenderDrawBlendMode(ren_.get(), SDL_BLENDMODE_BLEND); | ||
| 372 | SDL_SetRenderDrawColor(ren_.get(), 30, 0, 110, 127); | ||
| 373 | //SDL_RenderFillRect(ren_.get(), nullptr); | ||
| 374 | SDL_RenderClear(ren_.get()); | ||
| 375 | |||
| 376 | for (int i=0; i<textLines.size(); i++) { | ||
| 377 | SDL_Rect destRect { | ||
| 378 | 18, | ||
| 379 | 4 + 16 * i, | ||
| 380 | MESSAGE_TEXT_WIDTH, | ||
| 381 | game.getFont().getCharacterHeight() }; | ||
| 382 | |||
| 383 | SDL_RenderCopy(ren_.get(), textLines[i].get(), nullptr, &destRect); | ||
| 384 | } | ||
| 385 | |||
| 386 | SDL_SetRenderTarget(ren_.get(), nullptr); | ||
| 387 | |||
| 388 | debugDestRect_ = SDL_Rect { 0, 0, CANVAS_WIDTH, height }; | ||
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 336 | SDL_SetRenderTarget(ren_.get(), nullptr); | 392 | SDL_SetRenderTarget(ren_.get(), nullptr); | 
| 337 | SDL_RenderCopy(ren_.get(), cameraTex.get(), nullptr, nullptr); | 393 | SDL_RenderCopy(ren_.get(), cameraTex.get(), nullptr, nullptr); | 
| 338 | SDL_RenderPresent(ren_.get()); | 394 | SDL_RenderPresent(ren_.get()); | 
| @@ -383,6 +439,11 @@ void Renderer::renderMessageLine(MessageCache& line, const std::string& text, Ga | |||
| 383 | 439 | ||
| 384 | for (int i=0; i<line.line.size(); i++) { | 440 | for (int i=0; i<line.line.size(); i++) { | 
| 385 | if (line.line[i] != ' ') { | 441 | if (line.line[i] != ' ') { | 
| 442 | if (length + game.getFont().getCharacterWidth(line.line[i]) > MESSAGE_TEXT_WIDTH) { | ||
| 443 | line.overflow = line.line.substr(i); | ||
| 444 | break; | ||
| 445 | } | ||
| 446 | |||
| 386 | vec2i charLoc = game.getFont().getCharacterLocation(line.line[i]); | 447 | vec2i charLoc = game.getFont().getCharacterLocation(line.line[i]); | 
| 387 | vec2i charSize = game.getFont().getCharacterSize(line.line[i]); | 448 | vec2i charSize = game.getFont().getCharacterSize(line.line[i]); | 
| 388 | SDL_Rect srcRect { charLoc.x(), charLoc.y(), charSize.w(), charSize.h() }; | 449 | SDL_Rect srcRect { charLoc.x(), charLoc.y(), charSize.w(), charSize.h() }; | 
