- logo_scene, title_scene, intro_scene, room_fsm: missatges de cicle d'escena com a Log::info amb tag "scene" o "RoomFsm". Eliminats els TODO obsolets sobre el logger pendent. - game_scene (16 logs): events del bus (LEVEL COMPLETE, PLAYER HIT, PLAYER KILLED) com a info; transicions de ROOM com a info; warns als casos d'àudio absent o música no arrencada. - hud (3 logs): init i events com a info. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
88 lines
2.6 KiB
C++
88 lines
2.6 KiB
C++
#include "game/scenes/intro_scene.hpp"
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#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 "core/ui/ui_config.hpp"
|
|
#include "game/options.hpp"
|
|
#include "game/scenes/placeholder_input.hpp"
|
|
#include "game/scenes/scene_flow.hpp"
|
|
#include "utils/defaults.hpp"
|
|
#include "utils/defines.hpp"
|
|
#include "utils/log.hpp"
|
|
|
|
namespace {
|
|
|
|
constexpr int NAME_Y_OFFSET = -8;
|
|
constexpr int TIMER_Y_OFFSET = 8;
|
|
const char* const SCENE_NAME = "INTRO";
|
|
|
|
} // namespace
|
|
|
|
IntroScene::IntroScene(std::shared_ptr<Text> font, DebugConfig::StartingPlayers starting_players)
|
|
: font_(std::move(font)),
|
|
starting_players_(starting_players) {
|
|
Log::info("scene", "{} start (players={})", SCENE_NAME, DebugConfig::toString(starting_players_));
|
|
}
|
|
|
|
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) {
|
|
exit_request_ = ExitRequest{
|
|
.next = SceneId::GAME,
|
|
.params = GameParams{.starting_players = starting_players_},
|
|
};
|
|
}
|
|
|
|
Notifier::get().update(delta_ms);
|
|
RenderInfo::get().update(delta_ms, Options::buildRenderInfoFrame(UiConfig::get().renderInfoText(), UiConfig::get().renderInfoShadow()));
|
|
}
|
|
|
|
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,
|
|
UiConfig::get().notificationText());
|
|
font_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
|
GameCanvas::CENTER_X,
|
|
GameCanvas::CENTER_Y + TIMER_Y_OFFSET,
|
|
std::to_string(SECS_LEFT),
|
|
1,
|
|
UiConfig::get().notificationText());
|
|
}
|
|
|
|
Notifier::get().render();
|
|
RenderInfo::get().render();
|
|
Screen::get().present();
|
|
}
|