Tres escenes de 5 s cadascuna, activables al flux que precedeix GameScene. Classes separades (sense base comuna) perquè divergiran quan es desenvolupi contingut real. Avancen per timeout o per qualsevol tecla no reservada. Les tecles reservades (F1-F12, Escape) són les declarades a data/input/keys.yaml i mantenen el seu comportament habitual via GlobalInputs. La classificació viu a Placeholder::isReservedScancode, i KeyConfig exposa bindings() per enumerar-les sense duplicar la llista. Encara no integrats al Director: això es fa al següent commit quan s'afegeix el selector d'escena inicial.
87 lines
2.6 KiB
C++
87 lines
2.6 KiB
C++
#include "game/scenes/logo_scene.hpp"
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "core/input/global_inputs.hpp"
|
|
#include "core/rendering/notifier.hpp"
|
|
#include "core/rendering/render_info.hpp"
|
|
#include "core/rendering/screen.hpp"
|
|
#include "core/rendering/text.hpp"
|
|
#include "core/system/event_buffer.hpp"
|
|
#include "game/options.hpp"
|
|
#include "game/scenes/placeholder_input.hpp"
|
|
#include "game/ui/ui_palette.hpp"
|
|
#include "utils/defaults.hpp"
|
|
#include "utils/defines.hpp"
|
|
|
|
namespace {
|
|
|
|
constexpr int NAME_Y_OFFSET = -8;
|
|
constexpr int TIMER_Y_OFFSET = 8;
|
|
// TODO: migrar a un logger unificat quan es decideixi (veure INC-03 a
|
|
// docs/audit-core-rendering.md). De moment std::cout per rastrejar el
|
|
// flux d'escenes als smoke runs.
|
|
const char* const SCENE_NAME = "LOGO";
|
|
|
|
} // namespace
|
|
|
|
LogoScene::LogoScene(std::shared_ptr<Text> font, SceneFactory next_factory)
|
|
: font_(std::move(font)),
|
|
next_factory_(std::move(next_factory)) {
|
|
std::cout << "[scene] " << SCENE_NAME << " start\n";
|
|
}
|
|
|
|
LogoScene::~LogoScene() = default;
|
|
|
|
void LogoScene::update(int delta_ms) {
|
|
GlobalInputs::update(delta_ms);
|
|
if (GlobalInputs::wantsQuit()) {
|
|
wants_quit_ = true;
|
|
return;
|
|
}
|
|
|
|
timer_ms_ -= delta_ms;
|
|
|
|
const bool SKIPPED = std::ranges::any_of(EventBuffer::events, [](const SDL_Event& ev) {
|
|
return ev.type == SDL_EVENT_KEY_DOWN && !Placeholder::isReservedScancode(ev.key.scancode);
|
|
});
|
|
|
|
if ((timer_ms_ <= 0 || SKIPPED) && next_factory_) {
|
|
next_scene_ = next_factory_();
|
|
}
|
|
|
|
Notifier::get().update(delta_ms);
|
|
RenderInfo::get().update(delta_ms, Options::buildRenderInfoFrame(UiColor::RENDER_INFO_TEXT, UiColor::RENDER_INFO_SHADOW));
|
|
}
|
|
|
|
void LogoScene::render() {
|
|
constexpr std::uint32_t BLACK_ARGB = 0xFF000000U;
|
|
Screen::get().fillRect(0, 0, GameCanvas::WIDTH, GameCanvas::HEIGHT, BLACK_ARGB);
|
|
|
|
if (font_) {
|
|
const int SECS_LEFT = std::max(1, (timer_ms_ + 999) / 1000);
|
|
font_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
|
GameCanvas::CENTER_X,
|
|
GameCanvas::CENTER_Y + NAME_Y_OFFSET,
|
|
SCENE_NAME,
|
|
1,
|
|
Defaults::UI::NOTIFICATION_TEXT);
|
|
font_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
|
GameCanvas::CENTER_X,
|
|
GameCanvas::CENTER_Y + TIMER_Y_OFFSET,
|
|
std::to_string(SECS_LEFT),
|
|
1,
|
|
Defaults::UI::NOTIFICATION_TEXT);
|
|
}
|
|
|
|
Notifier::get().render();
|
|
RenderInfo::get().render();
|
|
Screen::get().present();
|
|
}
|