Sanejar codi

This commit is contained in:
2025-02-21 14:45:41 +01:00
parent ec73c5fa30
commit 6bb877b510
10 changed files with 98 additions and 107 deletions

View File

@@ -10,14 +10,17 @@ macosIntelRelease = $(executable)-$(version)-macos-intel.dmg
macosAppleSiliconRelease = $(executable)-$(version)-macos-apple-silicon.dmg
linuxRelease = $(executable)-$(version)-linux.tar.gz
# Specify the C++ standard
cpp_standard = c++20
windows:
@echo off
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe"
g++ $(source) -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe"
strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded
windows_debug:
@echo off
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable)_debug.exe"
g++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable)_debug.exe"
strip -s -R .comment -R .gnu.version "$(executable)_debug.exe" --strip-unneeded
windows_release:
@@ -38,7 +41,7 @@ windows_release:
powershell Copy-Item "release\*.dll" -Destination "$(releaseFolder)"
# Build
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe"
g++ $(source) -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe"
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded
# Create ZIP
@@ -49,10 +52,10 @@ windows_release:
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
macos:
clang++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
clang++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
macos_debug:
clang++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug"
clang++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug"
macos_release:
# Remove data and possible data from previous builds
@@ -87,7 +90,7 @@ macos_release:
ln -s /Applications "$(releaseFolder)"/Applications
# Build INTEL
clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
# Build INTEL DMG
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
@@ -95,7 +98,7 @@ macos_release:
rm -f tmp.dmg
# Build APPLE SILICON
clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
# Build APPLE SILICON DMG
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
@@ -107,11 +110,11 @@ macos_release:
rm -rdf "$(releaseFolder)"
linux:
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
linux_debug:
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
g++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded
linux_release:
@@ -131,7 +134,7 @@ linux_release:
rm -f "$(releaseFolder)/data/room/standard.tsx"
# Build
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable)" --strip-unneeded
# Pack files

View File

@@ -4,69 +4,64 @@
#include <string>
#include "utils.h"
#ifndef CONST_H
#define CONST_H
// Textos
#define WINDOW_CAPTION "JailDoctor's Dilemma"
#define TEXT_COPYRIGHT "@2022 JailDesigner"
#define VERSION "0.7"
constexpr const char* WINDOW_CAPTION = "JailDoctor's Dilemma";
constexpr const char* TEXT_COPYRIGHT = "@2022 JailDesigner";
constexpr const char* VERSION = "0.7";
// Tamaño de bloque
#define BLOCK 8
#define HALF_BLOCK 4
constexpr int BLOCK = 8;
constexpr int HALF_BLOCK = 4;
// Tamaño de la pantalla virtual
#define GAMECANVAS_WIDTH 256
#define GAMECANVAS_HEIGHT 192
constexpr int GAMECANVAS_WIDTH = 256;
constexpr int GAMECANVAS_HEIGHT = 192;
// Zona de juego
const int PLAY_AREA_TOP = (0 * BLOCK);
const int PLAY_AREA_BOTTOM = (16 * BLOCK);
const int PLAY_AREA_LEFT = (0 * BLOCK);
const int PLAY_AREA_RIGHT = (32 * BLOCK);
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
const int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
const int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
constexpr int PLAY_AREA_TOP = (0 * BLOCK);
constexpr int PLAY_AREA_BOTTOM = (16 * BLOCK);
constexpr int PLAY_AREA_LEFT = (0 * BLOCK);
constexpr int PLAY_AREA_RIGHT = (32 * BLOCK);
constexpr int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
constexpr int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
constexpr int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
constexpr int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
constexpr int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
constexpr int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
constexpr int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
constexpr int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
#define BORDER_TOP 0
#define BORDER_RIGHT 1
#define BORDER_BOTTOM 2
#define BORDER_LEFT 3
constexpr int BORDER_TOP = 0;
constexpr int BORDER_RIGHT = 1;
constexpr int BORDER_BOTTOM = 2;
constexpr int BORDER_LEFT = 3;
// Anclajes de pantalla
const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
const int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
const int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
constexpr int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
constexpr int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
constexpr int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
// Secciones del programa
#define SECTION_LOGO 0
#define SECTION_LOADING_SCREEN 1
#define SECTION_TITLE 2
#define SECTION_CREDITS 3
#define SECTION_GAME 4
#define SECTION_DEMO 5
#define SECTION_GAME_OVER 6
#define SECTION_ENDING 7
#define SECTION_ENDING2 8
#define SECTION_QUIT 9
constexpr int SECTION_LOGO = 0;
constexpr int SECTION_LOADING_SCREEN = 1;
constexpr int SECTION_TITLE = 2;
constexpr int SECTION_CREDITS = 3;
constexpr int SECTION_GAME = 4;
constexpr int SECTION_DEMO = 5;
constexpr int SECTION_GAME_OVER = 6;
constexpr int SECTION_ENDING = 7;
constexpr int SECTION_ENDING2 = 8;
constexpr int SECTION_QUIT = 9;
// Subsecciones
#define SUBSECTION_LOGO_TO_INTRO 0
#define SUBSECTION_LOGO_TO_TITLE 1
#define SUBSECTION_TITLE_WITH_LOADING_SCREEN 2
#define SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN 3
constexpr int SUBSECTION_LOGO_TO_INTRO = 0;
constexpr int SUBSECTION_LOGO_TO_TITLE = 1;
constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2;
constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3;
// Colores
const color_t borderColor = {0x27, 0x27, 0x36};
const color_t black = {0xFF, 0xFF, 0xFF};
#endif

View File

@@ -41,8 +41,10 @@
#endif
// Constructor
Director::Director(int argc, char *argv[])
Director::Director(int argc, const char *argv[])
{
std::cout << "Game start" << std::endl;
section = new section_t();
section->name = SECTION_LOGO;
section->subsection = SUBSECTION_LOGO_TO_INTRO;
@@ -112,6 +114,8 @@ Director::~Director()
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
std::cout << "\nBye!" << std::endl;
}
// Crea e inicializa las opciones del programa
@@ -165,7 +169,7 @@ void Director::initOptions()
}
// Comprueba los parametros del programa
void Director::checkProgramArguments(int argc, char *argv[])
void Director::checkProgramArguments(int argc, const char *argv[])
{
// Establece la ruta del programa
executablePath = argv[0];
@@ -360,7 +364,7 @@ bool Director::saveConfig()
}
else
{
file << "filter=FILTER_LINEAL\n";
file << "filter=FILTER_LINEAR\n";
}
file << "shaders=" + boolToString(options->shaders) + "\n";
@@ -1081,9 +1085,9 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
else if (var == "filter")
{
if (value == "FILTER_LINEAL")
if (value == "FILTER_LINEAR")
{
options->filter = FILTER_LINEAL;
options->filter = FILTER_LINEAR;
}
else
{
@@ -1843,7 +1847,7 @@ void Director::runGame()
resource->free();
}
void Director::run()
int Director::run()
{
// Bucle principal
while (section->name != SECTION_QUIT)
@@ -1887,4 +1891,6 @@ void Director::run()
break;
}
}
return 0;
}

View File

@@ -53,7 +53,7 @@ private:
void initOptions();
// Comprueba los parametros del programa
void checkProgramArguments(int argc, char *argv[]);
void checkProgramArguments(int argc, const char *argv[]);
// Carga el fichero de configuración
bool loadConfig();
@@ -111,11 +111,11 @@ private:
public:
// Constructor
Director(int argc, char *argv[]);
Director(int argc, const char *argv[]);
// Destructor
~Director();
// Bucle principal
void run();
int run();
};

View File

@@ -6,6 +6,15 @@
#include <string> // Para string, basic_string
#include <vector> // Para vector
// Definiciones de repetición
constexpr bool REPEAT_TRUE = true;
constexpr bool REPEAT_FALSE = false;
// Tipos de entrada
constexpr int INPUT_USE_KEYBOARD = 0;
constexpr int INPUT_USE_GAMECONTROLLER = 1;
constexpr int INPUT_USE_ANY = 2;
enum inputs_e
{
// Inputs obligatorios
@@ -33,13 +42,6 @@ enum inputs_e
input_number_of_inputs
};
#define REPEAT_TRUE true
#define REPEAT_FALSE false
#define INPUT_USE_KEYBOARD 0
#define INPUT_USE_GAMECONTROLLER 1
#define INPUT_USE_ANY 2
enum i_disable_e
{
d_notDisabled,

View File

@@ -1,5 +1,3 @@
#ifndef NO_SHADERS
#pragma once
#include <SDL2/SDL_render.h> // para SDL_Texture
@@ -44,5 +42,4 @@ namespace shader
const char *vertexShader, const char *fragmentShader = nullptr);
void render();
}
#endif
}

View File

@@ -5,26 +5,14 @@ Empezado en Castalla el 01/07/2022.
*/
#include <memory>
#include "director.h"
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Starting the game..." << endl;
// Crea el objeto Director
Director *director = new Director(argc, argv);
auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
// Bucle principal
director->run();
// Destruye el objeto Director
delete director;
director = nullptr;
cout << "\nShutting down the game..." << endl;
return 0;
return director->run();
}

View File

@@ -11,17 +11,17 @@ class Resource;
class Text;
struct JA_Sound_t;
// Tipos de fondos para el menu
#define MENU_BACKGROUND_TRANSPARENT 0
#define MENU_BACKGROUND_SOLID 1
// Tipos de fondos para el menú
constexpr int MENU_BACKGROUND_TRANSPARENT = 0;
constexpr int MENU_BACKGROUND_SOLID = 1;
// Tipos de archivos de audio
#define SOUND_ACCEPT 0
#define SOUND_MOVE 1
#define SOUND_CANCEL 2
constexpr int SOUND_ACCEPT = 0;
constexpr int SOUND_MOVE = 1;
constexpr int SOUND_CANCEL = 2;
// Opciones de menu
#define MENU_NO_OPTION -1
// Opciones de menú
constexpr int MENU_NO_OPTION = -1;
// Clase Menu
class Menu

View File

@@ -10,8 +10,8 @@
class Asset;
class Notify;
#define FILTER_NEAREST 0
#define FILTER_LINEAL 1
constexpr int FILTER_NEAREST = 0;
constexpr int FILTER_LINEAR = 1;
class Screen
{

View File

@@ -7,10 +7,10 @@ class Sprite;
class Texture;
#include "utils.h"
#define TXT_COLOR 1
#define TXT_SHADOW 2
#define TXT_CENTER 4
#define TXT_STROKE 8
constexpr int TXT_COLOR = 1;
constexpr int TXT_SHADOW = 2;
constexpr int TXT_CENTER = 4;
constexpr int TXT_STROKE = 8;
struct offset_t
{