refactor(input): gamecontrollerdb.txt a l'arrel + target controllerdb + logs estil [Input]
This commit is contained in:
@@ -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
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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