Files
vibe3_physics/source/main.cpp
Sergio Valor f5d6c993d3 Fix: Buscar resources.pack relativo al ejecutable, no al working directory
- Movido getExecutableDirectory() a defines.h como función inline
- Actualizado main.cpp para construir path absoluto a resources.pack
- Eliminadas definiciones duplicadas en engine.cpp y main.cpp
- Ahora funciona correctamente ejecutando desde cualquier carpeta (ej. build/)

TEST confirmado:
- Ejecutar desde raíz:  Carga resources.pack
- Ejecutar desde build/:  Carga resources.pack

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-05 09:36:37 +02:00

93 lines
3.4 KiB
C++

#include <iostream>
#include <cstring>
#include "engine.h"
// getExecutableDirectory() ya está definido en defines.h como inline
void printHelp() {
std::cout << "ViBe3 Physics - Simulador de físicas avanzadas\n";
std::cout << "\nUso: vibe3_physics [opciones]\n\n";
std::cout << "Opciones:\n";
std::cout << " -w, --width <px> Ancho de resolución (default: 320)\n";
std::cout << " -h, --height <px> Alto de resolución (default: 240)\n";
std::cout << " -z, --zoom <n> Zoom de ventana (default: 3)\n";
std::cout << " -f, --fullscreen Modo pantalla completa\n";
std::cout << " --help Mostrar esta ayuda\n\n";
std::cout << "Ejemplos:\n";
std::cout << " vibe3_physics # 320x240 zoom 3 (ventana 960x720)\n";
std::cout << " vibe3_physics -w 1920 -h 1080 # 1920x1080 zoom 1 (auto)\n";
std::cout << " vibe3_physics -w 640 -h 480 -z 2 # 640x480 zoom 2 (ventana 1280x960)\n";
std::cout << " vibe3_physics -w 1920 -h 1080 -f # 1920x1080 fullscreen\n\n";
std::cout << "Nota: Si resolución > pantalla, se usa default. Zoom se ajusta automáticamente.\n";
}
int main(int argc, char* argv[]) {
int width = 0;
int height = 0;
int zoom = 0;
bool fullscreen = false;
// Parsear argumentos
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--help") == 0) {
printHelp();
return 0;
} else if (strcmp(argv[i], "-w") == 0 || strcmp(argv[i], "--width") == 0) {
if (i + 1 < argc) {
width = atoi(argv[++i]);
if (width < 640) {
std::cerr << "Error: Ancho mínimo es 640px\n";
return -1;
}
} else {
std::cerr << "Error: -w/--width requiere un valor\n";
return -1;
}
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--height") == 0) {
if (i + 1 < argc) {
height = atoi(argv[++i]);
if (height < 480) {
std::cerr << "Error: Alto mínimo es 480px\n";
return -1;
}
} else {
std::cerr << "Error: -h/--height requiere un valor\n";
return -1;
}
} else if (strcmp(argv[i], "-z") == 0 || strcmp(argv[i], "--zoom") == 0) {
if (i + 1 < argc) {
zoom = atoi(argv[++i]);
if (zoom < 1) {
std::cerr << "Error: Zoom mínimo es 1\n";
return -1;
}
} else {
std::cerr << "Error: -z/--zoom requiere un valor\n";
return -1;
}
} else if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--fullscreen") == 0) {
fullscreen = true;
} else {
std::cerr << "Error: Opción desconocida '" << argv[i] << "'\n";
printHelp();
return -1;
}
}
// Inicializar sistema de recursos empaquetados (intentar cargar resources.pack)
std::string exe_dir = getExecutableDirectory();
std::string pack_path = exe_dir + "/resources.pack";
Texture::initResourceSystem(pack_path);
Engine engine;
if (!engine.initialize(width, height, zoom, fullscreen)) {
std::cout << "¡Error al inicializar el engine!" << std::endl;
return -1;
}
engine.run();
engine.shutdown();
return 0;
}