Fix conan script and deadlock in main()

This commit is contained in:
JackCarterSmith 2024-09-13 17:50:46 +02:00
parent 65d8d93ce4
commit 93547835c5
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
8 changed files with 73 additions and 57 deletions

2
.gitignore vendored
View File

@ -69,6 +69,7 @@ install_manifest.txt
compile_commands.json compile_commands.json
_deps _deps
logs/
.project .project
.vscode/ .vscode/
@ -78,3 +79,4 @@ conan.lock
conanbuildinfo.txt conanbuildinfo.txt
conaninfo.txt conaninfo.txt
graph_info.json graph_info.json
CMakeUserPresets.json

View File

@ -35,7 +35,7 @@ SOURCE_GROUP("Header Files" FILES ${AST_HRDS})
#set(CMAKE_BUILD_TYPE Debug) #set(CMAKE_BUILD_TYPE Debug)
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}) #include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(AST ${AST_SCRS} ${AST_HRDS}) add_executable(AST ${AST_SCRS} ${AST_HRDS})
#set_property(TARGET AST PROPERTY C_STANDARD 99) set_property(TARGET AST PROPERTY C_STANDARD 90)
set_target_properties(AST PROPERTIES OUTPUT_NAME ${AST_NAME}) set_target_properties(AST PROPERTIES OUTPUT_NAME ${AST_NAME})
if(MSVC) if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name # msvc does not append 'lib' - do it here to have consistent name

View File

@ -1,38 +1,40 @@
# Arena Survival Tournament # Arena Survival Tournament
This is one of my first game prototype. This is one of my first game prototype.
It's fully coded in C with SDL2 and SDL2_image libs. It's completely coded in C and use SDL2 and SDL2_image libs for the graphical backend.
All SDL2 parts and sub-parts are under the same license as SDL2 lib. All SDL2 parts and sub-parts are under the zlib license.
All code of AST are covered by the MIT license. All code of AST are covered by the MIT license.
## Functions ## Functions
The game can do following and you can learn from that like we do when you created this code: Here is a non-exhaustive list of the elements implemented in this demo:
- Generate random maps level - Random level generator,
- Control a simple IA - Simple AI behavior,
- Manage gold resources - Tiles management,
- Players movements - Players movements,
- Bad code practice - Bad code practices...
## Compiling ## Compiling
Before compiling, you need to install your favorite compiler (GCC or MSVC) with CMake and the lib manager Conan>=1.59 (https://conan.io): Before compiling, you need to install your favorite compiler (GCC or MSVC) with CMake.
The library manager Conan>=1.59 (https://conan.io) is supported too for SDL2 easy-setup.
```shell ```shell
# For debian based distribution: # For debian-based distribution:
apt-get update apt-get update
apt-get install build-essential cmake conan apt-get install build-essential cmake
python -m pip install -U conan
``` ```
Clone the repo and launch in order conan and cmake in order to compile the program: Clone the repo and launch in order conan and cmake in order to compile the program:
```shell ```shell
conan install . --build=missing -s build_type=Release -pr:b=default conan install . -of ./build --build=missing -s build_type=Release -pr:b=default #Conan v2
conan install . -of ./build -if ./build --build=missing -s build_type=Release -pr:b=default #Conan v1
cmake --preset release # or with '-G "MinGW Makefiles"/"Ninja"' if under Windows cmake --preset release # or with '-G "MinGW Makefiles"/"Ninja"' if under Windows
cmake --build --preset release cmake --build --preset release
cp -R data build/Release/.
``` ```
## Running ## Running
Simply run the program with `data` folder (required) and `logs` folder (optional) or use the launch script. Simply run the program with `data` folder (required) and `logs` folder (optional).

View File

@ -1,5 +1,5 @@
from conan import ConanFile from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, cmake_layout from conan.tools.cmake import CMakeToolchain
from conan.tools.files import copy from conan.tools.files import copy
required_conan_version = ">=1.59" required_conan_version = ">=1.59"
@ -16,18 +16,16 @@ class AST(ConanFile):
package_type = "application" package_type = "application"
revision_mode = "scm" revision_mode = "scm"
settings = "os", "compiler", "build_type", "arch" settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps" generators = "CMakeDeps"
# default_options = { # default_options = {
# "shared": True # "shared": True
# } # }
def configure(self): def configure(self):
self.options["sdl"].shared = True
self.options["sdl"].vulkan = False self.options["sdl"].vulkan = False
self.options["sdl"].opengles = False self.options["sdl"].opengles = False
self.options["sdl"].iconv = False self.options["sdl"].iconv = False
self.options["sdl_image"].shared = True
self.options["sdl_image"].with_libjpeg = False self.options["sdl_image"].with_libjpeg = False
self.options["sdl_image"].with_libtiff = False self.options["sdl_image"].with_libtiff = False
self.options["sdl_image"].with_libwebp = False self.options["sdl_image"].with_libwebp = False
@ -41,20 +39,31 @@ class AST(ConanFile):
self.options["sdl_image"].xv = False self.options["sdl_image"].xv = False
if self.settings.os == "Linux": if self.settings.os == "Linux":
self.options["sdl"].shared = False
self.options["sdl"].wayland = False self.options["sdl"].wayland = False
self.options["sdl"].nas = True self.options["sdl"].nas = True
self.options["sdl_image"].shared = False
if self.settings.os == "Windows": if self.settings.os == "Windows":
self.options["sdl"].shared = True
self.options["sdl"].directx = False self.options["sdl"].directx = False
self.options["sdl_image"].shared = True
def requirements(self): def requirements(self):
self.requires("sdl/2.28.5", override=True) self.requires("sdl/2.30.7", override=True)
self.requires("sdl_image/[>=2.6.3 <2.7]") self.requires("sdl_image/[>=2.6.3 <2.7]")
def layout(self): # def layout(self):
cmake_layout(self, src_folder='.', build_folder='build') # cmake_layout(self, src_folder='.', build_folder='build')
def generate(self): def generate(self):
# cmake = CMakeDeps(self)
# if self.options["AST"].shared:
# cmake.configuration = "ReleaseShared"
# cmake.generate()
tc = CMakeToolchain(self)
#tc.user_presets_path = False
tc.generate()
for dep in self.dependencies.values(): for dep in self.dependencies.values():
if self.settings.os == "Windows": if self.settings.os == "Windows":
copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder) copy(self, "*.dll", dep.cpp_info.bindirs[0], self.build_folder)

View File

@ -1,16 +0,0 @@
#!/bin/sh
DATA_DIR='data'
LOGS_DIR='logs'
if [ ! -d "$DATA_DIR" ]; then
echo "WARNING ! Missing DATA dir, can't launch program."
echo "Exit..."
fi
if [ ! -d "$LOGS_DIR" ]; then
mkdir logs
fi
chmod +x ArenaSurvivalTournament
./ArenaSurvivalTournament

View File

@ -47,30 +47,42 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *p_
SDL_UpdateWindowSurface(window); SDL_UpdateWindowSurface(window);
do { do {
action=0;actionIA=0;
oldposition.x = p1->PositionX * TILE_SIZE; oldposition.x = p1->PositionX * TILE_SIZE;
oldposition.y = p1->PositionY * TILE_SIZE; oldposition.y = p1->PositionY * TILE_SIZE;
oldIAposition.x = p2->PositionX * TILE_SIZE; oldIAposition.x = p2->PositionX * TILE_SIZE;
oldIAposition.y = p2->PositionY * TILE_SIZE; oldIAposition.y = p2->PositionY * TILE_SIZE;
while(action == 0) { while(!action) {
action=getKeyEvent(); action=getKeyEvent();
} }
if(action == -1){ switch (action)
return 0; {
} else if(action == 1) { case GAME_EVENT_UP:
ActionPlayer(arena,tiles,p_list,p1,1); //Déplacement vers le haut ActionPlayer(arena,tiles,p_list,p1,1); //Déplacement vers le haut
} else if(action == 2) { break;
ActionPlayer(arena,tiles,p_list,p1,2); //Déplacement vers la droite case GAME_EVENT_DOWN:
} else if(action == 3) {
ActionPlayer(arena,tiles,p_list,p1,3); //Déplacement vers le bas ActionPlayer(arena,tiles,p_list,p1,3); //Déplacement vers le bas
} else if(action == 4) { break;
case GAME_EVENT_LEFT:
ActionPlayer(arena,tiles,p_list,p1,4); //Déplacement vers la gauche ActionPlayer(arena,tiles,p_list,p1,4); //Déplacement vers la gauche
} else if(action == 5) { break;
case GAME_EVENT_RIGHT:
ActionPlayer(arena,tiles,p_list,p1,2); //Déplacement vers la droite
break;
case GAME_EVENT_ATTACK:
//Regarder le perso en face, le plus près //Regarder le perso en face, le plus près
if (canAttackPlayer(p1,p2)==1) { if (canAttackPlayer(p1,p2)==1) {
AttackPlayer(p1,p2); //Voir quel player on choisit d'attaquer AttackPlayer(p1,p2); //Voir quel player on choisit d'attaquer
} }
break;
case GAME_EVENT_QUIT:
default:
return 0;
break;
} }
// On place le joueur à la bonne position // On place le joueur à la bonne position
@ -108,8 +120,6 @@ int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *p_
SDL_UpdateWindowSurface(window); SDL_UpdateWindowSurface(window);
action=0;actionIA=0;
} while((p1->HealthPoints > 0) && (NumberPlayerAlive(p_list) > 1)); } while((p1->HealthPoints > 0) && (NumberPlayerAlive(p_list) > 1));
printf("La partie est terminée\n"); printf("La partie est terminée\n");
@ -133,27 +143,27 @@ int getKeyEvent()
/* Si c'est un événement de type "Quitter" */ /* Si c'est un événement de type "Quitter" */
case SDL_QUIT : case SDL_QUIT :
printf("QUITTER\n"); printf("QUITTER\n");
return -1; return GAME_EVENT_QUIT;
case SDL_KEYUP: case SDL_KEYUP:
switch(event.key.keysym.sym) { //La valeur de touche switch(event.key.keysym.sym) { //La valeur de touche
case SDLK_ESCAPE: case SDLK_ESCAPE:
printf("ESCAPE KEY\n"); printf("ESCAPE KEY\n");
return -1; return GAME_EVENT_QUIT;
case SDLK_UP: case SDLK_UP:
printf("FLECHE DU HAUT\n"); printf("FLECHE DU HAUT\n");
return 1; return GAME_EVENT_UP;
case SDLK_DOWN: case SDLK_DOWN:
printf("FLECHE DU BAS\n"); printf("FLECHE DU BAS\n");
return 3; return GAME_EVENT_DOWN;
case SDLK_RIGHT: case SDLK_RIGHT:
printf("FLECHE DE DROITE\n"); printf("FLECHE DE DROITE\n");
return 2; return GAME_EVENT_RIGHT;
case SDLK_LEFT: case SDLK_LEFT:
printf("FLECHE DE GAUCHE\n"); printf("FLECHE DE GAUCHE\n");
return 4; return GAME_EVENT_LEFT;
case SDLK_SPACE: case SDLK_SPACE:
printf("BARRE D'ESPACE\n"); printf("BARRE D'ESPACE\n");
return 5; return GAME_EVENT_ATTACK;
} }
} }

View File

@ -9,6 +9,15 @@
#ifndef ARENAGUI_H_ #ifndef ARENAGUI_H_
#define ARENAGUI_H_ #define ARENAGUI_H_
enum {
GAME_EVENT_QUIT = 1,
GAME_EVENT_UP,
GAME_EVENT_DOWN,
GAME_EVENT_LEFT,
GAME_EVENT_RIGHT,
GAME_EVENT_ATTACK
};
void displayArena(ARENA_H_TILE* arena, SDL_Window* windows, TILE *tiles, int size_h, int size_w, int tile_size); void displayArena(ARENA_H_TILE* arena, SDL_Window* windows, TILE *tiles, int size_h, int size_w, int tile_size);
int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *player); int updateArena(SDL_Window* window, ARENA_H_TILE* arena, TILE *tiles, PLAYER *player);
int getKeyEvent(); int getKeyEvent();

View File

@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
//IMG_Init(IMG_INIT_JPG & IMG_INIT_PNG); //IMG_Init(IMG_INIT_JPG & IMG_INIT_PNG);
displayArena(arena, gameWindows, tile_ressources, A_HEIGHT, A_WIDTH, TILE_SIZE); displayArena(arena, gameWindows, tile_ressources, A_HEIGHT, A_WIDTH, TILE_SIZE);
while (!updateArena(gameWindows,arena,tile_ressources,player_ressources)) {} while (updateArena(gameWindows,arena,tile_ressources,player_ressources)) {}
SDL_DestroyWindow(gameWindows); SDL_DestroyWindow(gameWindows);
deleteArena(arena); deleteArena(arena);