Major build system refactoring: **CMake (build authority)**: - Auto-discovers .cpp files (GLOB_RECURSE in source/core/ and source/game/) - No manual file list maintenance needed - Excludes source/legacy/ automatically - Generates build/project.h from template **Makefile (simplified wrapper)**: - Delegates compilation to CMake (make → cmake --build build) - Contains 5 release packaging targets: * macos_release: .app bundle + .dmg (Apple Silicon) * linux_release: .tar.gz * windows_release: .zip with .exe + DLLs * windows_cross: cross-compile from Linux/macOS * rpi_release: ARM64 cross-compile - Complex packaging logic preserved (code signing, symlinks, DMG creation) **Benefits**: - Add new .cpp file → automatically compiled (no manual updates) - Single source of truth in CMakeLists.txt (no duplication) - IDE-friendly (VSCode, CLion, etc.) - Complete packaging support (5 platforms) **Files changed**: - CMakeLists.txt: GLOB_RECURSE replaces 23-file hardcoded list - Makefile: Simplified compilation + added 5 release targets (~220 lines) - CLAUDE.md: Updated build system documentation - escena_titol.cpp: Fixed include path (build/project.h → project.h) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
177 lines
5.1 KiB
C++
177 lines
5.1 KiB
C++
// escena_titol.cpp - Implementació de l'escena de títol
|
|
// © 2025 Port a C++20
|
|
|
|
#include "escena_titol.hpp"
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
#include "../../core/audio/audio.hpp"
|
|
#include "../../core/system/gestor_escenes.hpp"
|
|
#include "../../core/system/global_events.hpp"
|
|
#include "project.h"
|
|
|
|
EscenaTitol::EscenaTitol(SDLManager& sdl)
|
|
: sdl_(sdl),
|
|
text_(sdl.obte_renderer()),
|
|
estat_actual_(EstatTitol::INIT),
|
|
temps_acumulat_(0.0f) {
|
|
std::cout << "Escena Titol: Inicialitzant...\n";
|
|
|
|
// Crear starfield de fons
|
|
Punt centre_pantalla{
|
|
Defaults::Game::WIDTH / 2.0f,
|
|
Defaults::Game::HEIGHT / 2.0f};
|
|
|
|
SDL_FRect area_completa{
|
|
0, 0,
|
|
static_cast<float>(Defaults::Game::WIDTH),
|
|
static_cast<float>(Defaults::Game::HEIGHT)};
|
|
|
|
starfield_ = std::make_unique<Graphics::Starfield>(
|
|
sdl_.obte_renderer(),
|
|
centre_pantalla,
|
|
area_completa,
|
|
150 // densitat: 150 estrelles (50 per capa)
|
|
);
|
|
}
|
|
|
|
void EscenaTitol::executar() {
|
|
SDL_Event event;
|
|
Uint64 last_time = SDL_GetTicks();
|
|
|
|
while (GestorEscenes::actual == GestorEscenes::Escena::TITOL) {
|
|
// Calcular delta_time real
|
|
Uint64 current_time = SDL_GetTicks();
|
|
float delta_time = (current_time - last_time) / 1000.0f;
|
|
last_time = current_time;
|
|
|
|
// Limitar delta_time per evitar grans salts
|
|
if (delta_time > 0.05f) {
|
|
delta_time = 0.05f;
|
|
}
|
|
|
|
// Actualitzar comptador de FPS
|
|
sdl_.updateFPS(delta_time);
|
|
|
|
// Processar events SDL
|
|
while (SDL_PollEvent(&event)) {
|
|
// Manejo de finestra
|
|
if (sdl_.handleWindowEvent(event)) {
|
|
continue;
|
|
}
|
|
|
|
// Events globals (F1/F2/F3/F4/ESC/QUIT)
|
|
if (GlobalEvents::handle(event, sdl_)) {
|
|
continue;
|
|
}
|
|
|
|
// Processar events de l'escena
|
|
processar_events(event);
|
|
}
|
|
|
|
// Actualitzar lògica
|
|
actualitzar(delta_time);
|
|
|
|
// Actualitzar sistema d'audio
|
|
Audio::update();
|
|
|
|
// Actualitzar colors oscil·lats
|
|
sdl_.updateColors(delta_time);
|
|
|
|
// Netejar pantalla
|
|
sdl_.neteja(0, 0, 0);
|
|
|
|
// Dibuixar
|
|
dibuixar();
|
|
|
|
// Presentar renderer (swap buffers)
|
|
sdl_.presenta();
|
|
}
|
|
|
|
std::cout << "Escena Titol: Finalitzant...\n";
|
|
}
|
|
|
|
void EscenaTitol::actualitzar(float delta_time) {
|
|
// Actualitzar starfield (sempre actiu)
|
|
if (starfield_) {
|
|
starfield_->actualitzar(delta_time);
|
|
}
|
|
|
|
switch (estat_actual_) {
|
|
case EstatTitol::INIT:
|
|
temps_acumulat_ += delta_time;
|
|
if (temps_acumulat_ >= DURACIO_INIT) {
|
|
estat_actual_ = EstatTitol::MAIN;
|
|
}
|
|
break;
|
|
case EstatTitol::MAIN:
|
|
// No hi ha lògica d'actualització en l'estat MAIN
|
|
break;
|
|
}
|
|
}
|
|
|
|
void EscenaTitol::dibuixar() {
|
|
// Dibuixar starfield de fons (sempre, en tots els estats)
|
|
if (starfield_) {
|
|
starfield_->dibuixar();
|
|
}
|
|
|
|
// En l'estat INIT, només mostrar starfield (sense text)
|
|
if (estat_actual_ == EstatTitol::INIT) {
|
|
return;
|
|
}
|
|
|
|
// Estat MAIN: Dibuixar text de títol i copyright (sobre el starfield)
|
|
if (estat_actual_ == EstatTitol::MAIN) {
|
|
// Text principal centrat (vertical i horitzontalment)
|
|
const std::string main_text = "PRESS BUTTON TO PLAY";
|
|
const float escala_main = 1.0f;
|
|
const float spacing = 2.0f;
|
|
|
|
float text_width = text_.get_text_width(main_text, escala_main, spacing);
|
|
float text_height = text_.get_text_height(escala_main);
|
|
|
|
float x_center = (Defaults::Game::WIDTH - text_width) / 2.0f;
|
|
float y_center = (Defaults::Game::HEIGHT - text_height) / 2.0f;
|
|
|
|
text_.render(main_text, Punt{x_center, y_center}, escala_main, spacing);
|
|
|
|
// Copyright a la part inferior (centrat horitzontalment)
|
|
// Convert to uppercase since VectorText only supports A-Z
|
|
std::string copyright = Project::COPYRIGHT;
|
|
for (char& c : copyright) {
|
|
if (c >= 'a' && c <= 'z') {
|
|
c = c - 32; // Convert to uppercase
|
|
}
|
|
}
|
|
const float escala_copy = 0.6f;
|
|
|
|
float copy_width = text_.get_text_width(copyright, escala_copy, spacing);
|
|
float copy_height = text_.get_text_height(escala_copy);
|
|
|
|
float x_copy = (Defaults::Game::WIDTH - copy_width) / 2.0f;
|
|
float y_copy = Defaults::Game::HEIGHT - copy_height - 20.0f; // 20px des del fons
|
|
|
|
text_.render(copyright, Punt{x_copy, y_copy}, escala_copy, spacing);
|
|
}
|
|
}
|
|
|
|
void EscenaTitol::processar_events(const SDL_Event& event) {
|
|
// Qualsevol tecla o clic de ratolí
|
|
if (event.type == SDL_EVENT_KEY_DOWN ||
|
|
event.type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
|
|
|
|
switch (estat_actual_) {
|
|
case EstatTitol::INIT:
|
|
// Saltar a MAIN
|
|
estat_actual_ = EstatTitol::MAIN;
|
|
break;
|
|
case EstatTitol::MAIN:
|
|
// Anar al joc
|
|
GestorEscenes::actual = GestorEscenes::Escena::JOC;
|
|
break;
|
|
}
|
|
}
|
|
}
|