Compare commits
5 Commits
4f5421191d
...
v0.8.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 491992a4d7 | |||
| e5b727216c | |||
| f03e337b9a | |||
| 99e99e7e08 | |||
| b93761eb1e |
+1
-1
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(orni VERSION 0.8.0 LANGUAGES CXX)
|
||||
project(orni VERSION 0.8.1 LANGUAGES CXX)
|
||||
|
||||
# Info del projecte (font de veritat per a project.h)
|
||||
set(PROJECT_LONG_NAME "Orni Attack")
|
||||
|
||||
@@ -84,9 +84,18 @@ else
|
||||
endif
|
||||
|
||||
.PHONY: all debug release _windows-release _macos-release _linux-release \
|
||||
run run-debug clean rebuild show-version pack \
|
||||
run run-debug clean rebuild show-version pack controllerdb \
|
||||
format format-check tidy tidy-fix cppcheck hooks-install help
|
||||
|
||||
# Còpia del gamecontrollerdb.txt (si existeix) al directori de build, perquè
|
||||
# director.cpp el resolgui via resource_base = directori de l'executable.
|
||||
# Silenciós si el fitxer no existeix (l'usuari encara no ha fet `make controllerdb`).
|
||||
ifeq ($(OS),Windows_NT)
|
||||
CP_CONTROLLERDB = @powershell -Command "if (Test-Path 'gamecontrollerdb.txt') { Copy-Item 'gamecontrollerdb.txt' -Destination '$(BUILDDIR)' -Force }"
|
||||
else
|
||||
CP_CONTROLLERDB = @if [ -f gamecontrollerdb.txt ]; then cp gamecontrollerdb.txt $(BUILDDIR)/; fi
|
||||
endif
|
||||
|
||||
# ==============================================================================
|
||||
# COMPILACIÓ
|
||||
# ==============================================================================
|
||||
@@ -98,10 +107,12 @@ endif
|
||||
all:
|
||||
@cmake -S . -B $(BUILDDIR) $(CMAKE_GEN) -DCMAKE_BUILD_TYPE=Release $(CMAKE_DEFS)
|
||||
@cmake --build $(BUILDDIR) -j$(JOBS)
|
||||
$(CP_CONTROLLERDB)
|
||||
|
||||
debug:
|
||||
@cmake -S . -B $(BUILDDIR) $(CMAKE_GEN) -DCMAKE_BUILD_TYPE=Debug $(CMAKE_DEFS)
|
||||
@cmake --build $(BUILDDIR) -j$(JOBS)
|
||||
$(CP_CONTROLLERDB)
|
||||
|
||||
run: all
|
||||
@./$(BUILDDIR)/$(PROJECT)
|
||||
@@ -138,6 +149,7 @@ _linux-release:
|
||||
|
||||
# Còpia de fitxers
|
||||
cp $(BUILDDIR)/resources.pack "$(RELEASE_FOLDER)"
|
||||
cp gamecontrollerdb.txt "$(RELEASE_FOLDER)"
|
||||
cp README.md "$(RELEASE_FOLDER)"
|
||||
@[ -f LICENSE ] && cp LICENSE "$(RELEASE_FOLDER)" || true
|
||||
cp "$(TARGET_FILE)" "$(RELEASE_FILE)"
|
||||
@@ -166,6 +178,7 @@ _windows-release:
|
||||
@powershell -Command "if (-not (Test-Path '$(RELEASE_FOLDER)')) {New-Item '$(RELEASE_FOLDER)' -ItemType Directory}"
|
||||
|
||||
@powershell -Command "Copy-Item -Path '$(BUILDDIR)/resources.pack' -Destination '$(RELEASE_FOLDER)'"
|
||||
@powershell -Command "Copy-Item 'gamecontrollerdb.txt' -Destination '$(RELEASE_FOLDER)'"
|
||||
@powershell -Command "if (Test-Path 'LICENSE') { Copy-Item 'LICENSE' -Destination '$(RELEASE_FOLDER)' }"
|
||||
@powershell -Command "Copy-Item 'README.md' -Destination '$(RELEASE_FOLDER)'"
|
||||
@powershell -Command "if (Test-Path 'release\windows\dll') { Copy-Item 'release\windows\dll\*.dll' -Destination '$(RELEASE_FOLDER)' }"
|
||||
@@ -206,6 +219,7 @@ _macos-release:
|
||||
|
||||
# Còpia de recursos i metadades del bundle
|
||||
cp $(BUILDDIR)/arm/resources.pack "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
|
||||
cp gamecontrollerdb.txt "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
|
||||
cp -R release/macos/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks"
|
||||
cp release/icons/icon.icns "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
|
||||
cp release/macos/Info.plist "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents"
|
||||
@@ -274,6 +288,19 @@ pack:
|
||||
@cmake --build $(BUILDDIR) --target pack_resources
|
||||
@./$(BUILDDIR)/pack_resources data $(BUILDDIR)/resources.pack
|
||||
|
||||
# ==============================================================================
|
||||
# DESCÀRREGA DE GAMECONTROLLERDB
|
||||
# ==============================================================================
|
||||
# Descarrega l'última versió de gamecontrollerdb.txt (mappings de gamepads
|
||||
# mantinguts per la comunitat) a l'arrel del projecte. SDL el carrega via
|
||||
# filesystem real (no dins resources.pack) i s'ha de copiar al costat del binari
|
||||
# en cada build (gestionat per CP_CONTROLLERDB a `all`/`debug` i pels release targets).
|
||||
controllerdb:
|
||||
@echo "Descargando gamecontrollerdb.txt..."
|
||||
curl -fsSL https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/master/gamecontrollerdb.txt \
|
||||
-o gamecontrollerdb.txt
|
||||
@echo "gamecontrollerdb.txt actualizado"
|
||||
|
||||
# ==============================================================================
|
||||
# CODE QUALITY (delegats a cmake)
|
||||
# ==============================================================================
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,8 +14,8 @@ namespace Defaults::Hud {
|
||||
|
||||
// Colors per segment del marcador. Jerarquia per funció (score/vides/nivell)
|
||||
// + diferenciació de jugador (P1 blanc vs P2 rosa) sense xocar amb els
|
||||
// colors d'enemics (cyan/roig). Si alpha=255 desactiva l'oscil·lador global
|
||||
// i mostra el color estable (en lloc del pulse verd genèric).
|
||||
// colors d'enemics (cyan/roig). Amb alpha=255 el line_renderer usa el color
|
||||
// directament sense caure al fallback verd (Rendering::DEFAULT_LINE_COLOR).
|
||||
namespace Colors {
|
||||
constexpr SDL_Color SCORE_P1 = {.r = 255, .g = 255, .b = 255, .a = 255}; // blanc
|
||||
constexpr SDL_Color SCORE_P2 = {.r = 255, .g = 130, .b = 200, .a = 255}; // rosa magenta
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
// Paleta semántica por tipo de entidad. Si una entity declara color, lo
|
||||
// pasa al pipeline con alpha=255 (sentinela "color válido"); si no, se
|
||||
// usa el color global del oscilador (g_current_line_color).
|
||||
// pasa al pipeline con alpha=255 (sentinela "color válido"); si no,
|
||||
// line_renderer::linea() cau a DEFAULT_LINE_COLOR (verd fòsfor fallback).
|
||||
namespace Defaults::Palette {
|
||||
|
||||
// Paleta neon: pujada lleugera dels canals secundaris per millorar la
|
||||
|
||||
@@ -51,12 +51,12 @@ namespace Graphics {
|
||||
|
||||
namespace {
|
||||
|
||||
// Lerp de l'oscil·lador (color base actual) cap a un color "flash" en
|
||||
// funció de f ∈ [0, 1]. Retorna sempre amb alpha>0 perquè el line_renderer
|
||||
// l'use directament (sense barrejar amb el global).
|
||||
// Lerp del color base verd fòsfor cap a un color "flash" en funció de
|
||||
// f ∈ [0, 1]. Retorna sempre amb alpha>0 perquè el line_renderer l'usi
|
||||
// directament (sense caure al fallback DEFAULT_LINE_COLOR).
|
||||
auto lerpColor(SDL_Color flash, float f) -> SDL_Color {
|
||||
const float CLAMPED = std::clamp(f, 0.0F, 1.0F);
|
||||
const SDL_Color BASE = Rendering::getLineColor();
|
||||
constexpr SDL_Color BASE = Rendering::DEFAULT_LINE_COLOR;
|
||||
const auto LERP_U8 = [&](unsigned char a, unsigned char b) {
|
||||
const float OUT = (static_cast<float>(a) * (1.0F - CLAMPED)) + (static_cast<float>(b) * CLAMPED);
|
||||
return static_cast<unsigned char>(OUT);
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Graphics {
|
||||
// - scale: factor de scale (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a scale 1.0)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
// - color: color RGBA explícit; si alpha==0 (default) s'usa l'oscil·lador global
|
||||
// - color: color RGBA explícit; si alpha==0 (default) es fa fallback a Rendering::DEFAULT_LINE_COLOR
|
||||
void render(const std::string& text, const Vec2& position, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F, SDL_Color color = {0, 0, 0, 0}) const;
|
||||
|
||||
// Renderizar string centrado en un punto
|
||||
@@ -35,7 +35,7 @@ namespace Graphics {
|
||||
// - scale: factor de scale (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a scale 1.0)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
// - color: color RGBA explícit; si alpha==0 (default) s'usa l'oscil·lador global
|
||||
// - color: color RGBA explícit; si alpha==0 (default) es fa fallback a Rendering::DEFAULT_LINE_COLOR
|
||||
void renderCentered(const std::string& text, const Vec2& centre_point, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F, SDL_Color color = {0, 0, 0, 0}) const;
|
||||
|
||||
// Calcular ancho total de un string (útil para centrado).
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// Mesh3D = llista de vèrtexs Vec3 + llista d'arestes (parells d'índexs).
|
||||
// drawWireframe() aplica una Transform3D al mesh, projecta amb Camera3D i
|
||||
// emet cada aresta com una línia 2D pel pipeline `Rendering::linea` (mateix
|
||||
// pipeline que la resta del joc: glow verd via ColorOscillator si color.a==0).
|
||||
// pipeline que la resta del joc: verd fòsfor via Rendering::DEFAULT_LINE_COLOR si color.a==0).
|
||||
//
|
||||
// Sense depth buffer: el caller és responsable d'ordenar els meshos per
|
||||
// profunditat decreixent si vol oclusió coherent (la pipeline és LINE_LIST
|
||||
|
||||
@@ -309,8 +309,11 @@ auto Input::checkTriggerInput(Action action, const std::shared_ptr<Gamepad>& gam
|
||||
}
|
||||
|
||||
void Input::addGamepadMappingsFromFile() {
|
||||
if (SDL_AddGamepadMappingsFromFile(gamepad_mappings_file_.c_str()) < 0) {
|
||||
std::cout << "Error, could not load " << gamepad_mappings_file_.c_str() << " file: " << SDL_GetError() << '\n';
|
||||
const int COUNT = SDL_AddGamepadMappingsFromFile(gamepad_mappings_file_.c_str());
|
||||
if (COUNT < 0) {
|
||||
std::cerr << "[Input] Error carregant " << gamepad_mappings_file_ << ": " << SDL_GetError() << '\n';
|
||||
} else {
|
||||
std::cout << "[Input] " << gamepad_mappings_file_ << " carregat (" << COUNT << " mappings)\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,8 +331,7 @@ void Input::initSDLGamePad() {
|
||||
} else {
|
||||
addGamepadMappingsFromFile();
|
||||
discoverGamepads();
|
||||
std::cout << "\n** INPUT SYSTEM **\n";
|
||||
std::cout << "Input System initialized successfully\n";
|
||||
std::cout << "[Input] inicialitzat\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Color global compartido para líneas sin paleta propia (HUD, debug, texto
|
||||
// genérico). Equivale al "color máximo" de la antigua oscilación CPU: verde
|
||||
// fósforo CRT. El pulso de brillo lo aplica ahora el shader de postpro.
|
||||
SDL_Color g_current_line_color = {100, 255, 100, 255};
|
||||
|
||||
// Grosor global por defecto. Configurable via setLineThickness.
|
||||
float g_current_line_thickness = Defaults::Rendering::LINE_THICKNESS_DEFAULT;
|
||||
|
||||
@@ -36,8 +31,8 @@ namespace Rendering {
|
||||
const auto FX2 = static_cast<float>(x2);
|
||||
const auto FY2 = static_cast<float>(y2);
|
||||
|
||||
// color.alpha==0 → usar color global (verde fósforo). alpha>0 → color directo.
|
||||
const SDL_Color SOURCE = (color.a > 0) ? color : g_current_line_color;
|
||||
// color.alpha==0 → fallback a DEFAULT_LINE_COLOR (verd fòsfor). alpha>0 → color directo.
|
||||
const SDL_Color SOURCE = (color.a > 0) ? color : DEFAULT_LINE_COLOR;
|
||||
const float R = (static_cast<float>(SOURCE.r) * brightness) / 255.0F;
|
||||
const float G = (static_cast<float>(SOURCE.g) * brightness) / 255.0F;
|
||||
const float B = (static_cast<float>(SOURCE.b) * brightness) / 255.0F;
|
||||
@@ -68,10 +63,6 @@ namespace Rendering {
|
||||
}
|
||||
}
|
||||
|
||||
void setLineColor(SDL_Color color) { g_current_line_color = color; }
|
||||
|
||||
auto getLineColor() -> SDL_Color { return g_current_line_color; }
|
||||
|
||||
void setLineThickness(float thickness) {
|
||||
if (thickness > 0.0F) {
|
||||
g_current_line_thickness = thickness;
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
//
|
||||
// El dibujo de líneas pasa por el pipeline GPU. Las coordenadas (x1,y1,x2,y2)
|
||||
// son lógicas (1280×720); el shader las mapea a NDC y el viewport del SDLManager
|
||||
// hace el letterbox a píxeles físicos. El brillo modula el color global de
|
||||
// línea (lo gestiona ColorOscillator). El grosor es configurable por línea
|
||||
// (parámetro thickness>0) o global (g_current_line_thickness vía setLineThickness).
|
||||
// hace el letterbox a píxeles físicos. El pulse de brillo lo aplica el shader
|
||||
// de postpro (ya no hi ha un ColorOscillator a CPU). El grosor es configurable
|
||||
// per línia (parámetro thickness>0) o global (g_current_line_thickness vía
|
||||
// setLineThickness).
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -15,12 +16,17 @@
|
||||
|
||||
namespace Rendering {
|
||||
|
||||
// Color verd fòsfor CRT per defecte: s'usa quan el caller passa color amb
|
||||
// alpha==0 (sentinella "sense color propi"). Constant immutable: la
|
||||
// semàntica de "color global" ja no existeix (era de l'antic ColorOscillator).
|
||||
constexpr SDL_Color DEFAULT_LINE_COLOR = {.r = 100, .g = 255, .b = 100, .a = 255};
|
||||
|
||||
// Dibuja una línea entre dos puntos en coordenadas lógicas (1280×720).
|
||||
// brightness: factor de brillo (0.0..1.0, default 1.0 = brillo máximo).
|
||||
// Pre-multiplica el RGB del color (color dim sobre fons negre).
|
||||
// thickness: grosor en píxeles lógicos. Si <= 0 usa g_current_line_thickness.
|
||||
// color: si alpha==0, se usa el color global del oscilador; si alpha>0 se
|
||||
// usa este color directo (paleta semántica por entidad).
|
||||
// color: si alpha==0, se usa DEFAULT_LINE_COLOR (verd fòsfor fallback);
|
||||
// si alpha>0 se usa este color directo (paleta semántica por entidad).
|
||||
// alpha: alpha que arriba al GPU (default 1.0 = opac, behavior original).
|
||||
// Valors <1.0 fan que la línia es barregi de veritat sobre el dest
|
||||
// en comptes de sobrepintar-lo (útil per halos translúcids).
|
||||
@@ -49,10 +55,6 @@ namespace Rendering {
|
||||
SDL_Color color = {0, 0, 0, 0},
|
||||
SDL_Color glow_color = {0, 0, 0, 0});
|
||||
|
||||
// Color global de las líneas (lo actualiza ColorOscillator vía SDLManager).
|
||||
void setLineColor(SDL_Color color);
|
||||
[[nodiscard]] auto getLineColor() -> SDL_Color;
|
||||
|
||||
// Grosor global por defecto (en píxeles lógicos). Default: 1.5.
|
||||
void setLineThickness(float thickness);
|
||||
[[nodiscard]] auto getLineThickness() -> float;
|
||||
|
||||
@@ -106,8 +106,11 @@ Director::Director(int argc, char* argv[])
|
||||
// falla, Locale::text() retorna la clau crua i el joc segueix funcionant.
|
||||
Locale::get().load(std::string("locale/") + cfg_->locale + ".yaml");
|
||||
|
||||
// Inicialitzar sistema de input
|
||||
Input::init("data/gamecontrollerdb.txt");
|
||||
// Inicialitzar sistema de input. El gamecontrollerdb.txt viu al costat del
|
||||
// binari (no dins de resources.pack, perquè SDL_AddGamepadMappingsFromFile
|
||||
// necessita una ruta real de filesystem). resource_base ja apunta al directori
|
||||
// de l'executable (o a Contents/Resources en bundles de macOS).
|
||||
Input::init(resource_base + "/gamecontrollerdb.txt");
|
||||
|
||||
// Autoassignacio de primer arranque: si cap dels dos jugadors te mando
|
||||
// assignat al config, repartim els que hi haja detectats (P1 = pad 0,
|
||||
|
||||
Reference in New Issue
Block a user