feat(scenes): afegir placeholders LogoScene/TitleScene/IntroScene

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.
This commit is contained in:
JailDesigner committed 2026-04-22 10:31:48 +02:00
1 parent 2883df57da
commit d31483124e
10 files changed
+382

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
#include "game/scenes/intro_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).
const char* const SCENE_NAME = "INTRO";
} // namespace
IntroScene::IntroScene(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";
}
IntroScene::~IntroScene() = default;
void IntroScene::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 IntroScene::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();
}
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include <functional>
#include <memory>
#include "core/scene/scene.hpp"
class Text;
// Escena placeholder de la introducció. Com la resta de placeholders, durada
// fixa i skip amb tecla no reservada; quan expira encadena a la factory
// injectada (en producció: GameScene).
class IntroScene : public Scene {
public:
using SceneFactory = std::function<std::unique_ptr<Scene>()>;
static constexpr int DURATION_MS = 5000;
IntroScene(std::shared_ptr<Text> font, SceneFactory next_factory);
~IntroScene() override;
void update(int delta_ms) override;
void render() override;
private:
std::shared_ptr<Text> font_;
SceneFactory next_factory_;
int timer_ms_{DURATION_MS};
};
+86
View File
@@ -0,0 +1,86 @@
#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();
}
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#include <functional>
#include <memory>
#include "core/scene/scene.hpp"
class Text;
// Escena placeholder del logotip. Durada fixa (5 s) o skip amb qualsevol tecla
// no reservada. Quan expira, encadena amb la `SceneFactory` que se li injecta
// al ctor — així l'escena no coneix el tipus concret de la següent, i es pot
// exercir en tests sense arrossegar GameScene.
class LogoScene : public Scene {
public:
using SceneFactory = std::function<std::unique_ptr<Scene>()>;
static constexpr int DURATION_MS = 5000;
LogoScene(std::shared_ptr<Text> font, SceneFactory next_factory);
~LogoScene() override;
void update(int delta_ms) override;
void render() override;
private:
std::shared_ptr<Text> font_;
SceneFactory next_factory_;
int timer_ms_{DURATION_MS};
};
+15
View File
@@ -0,0 +1,15 @@
#include "game/scenes/placeholder_input.hpp"
#include <algorithm>
#include "core/input/key_config.hpp"
namespace Placeholder {
auto isReservedScancode(SDL_Scancode sc) -> bool {
if (sc == SDL_SCANCODE_UNKNOWN) { return false; }
const auto& bindings = KeyConfig::get().bindings();
return std::ranges::any_of(bindings, [sc](const auto& kv) { return kv.second == sc; });
}
} // namespace Placeholder
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include <SDL3/SDL.h>
// Helper per als placeholders del flux LOGO → TITLE → INTRO → GAME. Les escenes
// placeholder avancen amb qualsevol tecla excepte les registrades a KeyConfig
// (F1–F12, Escape), que mantenen el seu comportament habitual via GlobalInputs.
namespace Placeholder {
// Retorna true si el scancode coincideix amb alguna tecla declarada al
// KeyConfig::get() (les carregades de data/input/keys.yaml). Si KeyConfig
// no s'ha carregat, totes les consultes retornaran SDL_SCANCODE_UNKNOWN i
// aquesta funció tornarà false, de manera que el test/smoke no depèn de
// l'estat global de la configuració.
[[nodiscard]] auto isReservedScancode(SDL_Scancode sc) -> bool;
} // namespace Placeholder
+85
View File
@@ -0,0 +1,85 @@
#include "game/scenes/title_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).
const char* const SCENE_NAME = "TITLE";
} // namespace
TitleScene::TitleScene(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";
}
TitleScene::~TitleScene() = default;
void TitleScene::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 TitleScene::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();
}
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#include <functional>
#include <memory>
#include "core/scene/scene.hpp"
class Text;
// Escena placeholder del títol. Mateix comportament que LogoScene — duració
// fixa de 5 s i skip amb tecla no reservada —, però classe separada perquè
// quan divergeixi en contingut real (menú, seleccions, animacions) creixi en
// el seu propi fitxer sense haver de refactoritzar cap base comuna.
class TitleScene : public Scene {
public:
using SceneFactory = std::function<std::unique_ptr<Scene>()>;
static constexpr int DURATION_MS = 5000;
TitleScene(std::shared_ptr<Text> font, SceneFactory next_factory);
~TitleScene() override;
void update(int delta_ms) override;
void render() override;
private:
std::shared_ptr<Text> font_;
SceneFactory next_factory_;
int timer_ms_{DURATION_MS};
};