Review SDL2 implementation with Conan support

This commit is contained in:
JackCarterSmith 2021-10-19 19:37:32 +02:00
parent 1c2c47bb1f
commit 42a2dc80e5
Signed by: JackCarterSmith
GPG Key ID: DB362B740828F843
8 changed files with 190 additions and 249 deletions

143
.gitignore vendored
View File

@ -1,72 +1,71 @@
# Prerequisites # Prerequisites
*.d *.d
# Object files # Object files
*.o *.o
*.ko *.ko
*.obj *.obj
*.elf *.elf
# Linker output # Linker output
*.ilk *.ilk
*.map *.map
*.exp *.exp
# Precompiled Headers # Precompiled Headers
*.gch *.gch
*.pch *.pch
src/config.h src/config.h
# Libraries # Libraries
*.lib *.lib
*.a *.a
*.la *.la
*.lo *.lo
# Shared objects (inc. Windows DLLs) # Shared objects (inc. Windows DLLs)
*.dll *.dll
*.so *.so
*.so.* *.so.*
*.dylib *.dylib
# Executables # Executables
*.exe *.exe
*.out *.out
*.app *.app
*.i*86 *.i*86
*.x86_64 *.x86_64
*.hex *.hex
# Debug files # Debug files
*.dSYM/ *.dSYM/
*.su *.su
*.idb *.idb
*.pdb *.pdb
docs\ docs\
latex\ latex\
html\ html\
# Kernel Module Compile Results # Kernel Module Compile Results
*.mod* *.mod*
*.cmd *.cmd
.tmp_versions/ .tmp_versions/
modules.order modules.order
Module.symvers Module.symvers
Mkfile.old Mkfile.old
dkms.conf dkms.conf
# CMake files # CMake files
build/ build/
CMakeLists.txt.user CMakeLists.txt.user
CMakeCache.txt CMakeCache.txt
CMakeFiles CMakeFiles
CMakeScripts CMakeScripts
Testing Testing
Makefile Makefile
cmake_install.cmake *.cmake
install_manifest.txt install_manifest.txt
compile_commands.json compile_commands.json
CTestTestfile.cmake _deps
_deps
.project
.project

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "cmake/sdl2"]
path = cmake/sdl2
url = https://git.jcsmith.fr/jackcartersmith/sdl2-cmake-modules.git

View File

@ -1,52 +1,56 @@
# CMakeLists.txt # CMakeLists.txt
# Written by JackCarterSmith, 2021 # Written by JackCarterSmith, 2021
# This code is released under the AST license. # This code is released under the AST license.
cmake_minimum_required(VERSION 3.5.1) cmake_minimum_required(VERSION 3.5.1)
cmake_policy(VERSION 3.5.1)
# define project set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
set(APPEND CMAKE_EXE_LINKER_FLAGS -Wl,-subsystem,console) # define project
project(AST VERSION 1.0.0 DESCRIPTION "Arena Survival Tournament" LANGUAGES C) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
set(AST_NAME AST-${PROJECT_VERSION}) set(APPEND CMAKE_EXE_LINKER_FLAGS -Wl,-subsystem,console)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h @ONLY) project(AST VERSION 1.0.0 DESCRIPTION "Arena Survival Tournament" LANGUAGES C)
set(AST_NAME AST-${PROJECT_VERSION})
include(FindPkgConfig) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h @ONLY)
include(CheckIncludeFile)
include(CheckCSourceCompiles) include(FindPkgConfig)
include(CheckIncludeFile)
# define src/headers files include(CheckCSourceCompiles)
#include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
FILE(GLOB AST_SCRS src/*.c) #conan_basic_setup()
FILE(GLOB AST_HRDS src/*.h)
SOURCE_GROUP("Source Files" FILES ${AST_SCRS}) # Find SDL2, SDL2_image and SDL2_gfx libraries
SOURCE_GROUP("Header Files" FILES ${AST_HRDS}) find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
# begin building AST find_package(SDL2_image REQUIRED)
include_directories(${SDL2_image_INCLUDE_DIR})
#set(CMAKE_BUILD_TYPE Debug)
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}) # define src/headers files
add_executable(AST ${AST_SCRS} ${AST_HRDS})
#set_property(TARGET AST PROPERTY C_STANDARD 99) FILE(GLOB AST_SCRS src/*.c)
set_target_properties(AST PROPERTIES OUTPUT_NAME ${AST_NAME}) FILE(GLOB AST_HRDS src/*.h)
if(MSVC) SOURCE_GROUP("Source Files" FILES ${AST_SCRS})
# msvc does not append 'lib' - do it here to have consistent name SOURCE_GROUP("Header Files" FILES ${AST_HRDS})
set_target_properties(AST PROPERTIES PREFIX "lib")
set_target_properties(AST PROPERTIES IMPORT_PREFIX "lib") # begin building AST
endif()
#set(CMAKE_BUILD_TYPE Debug)
target_include_directories(${PROJECT_NAME} PRIVATE include) #include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(AST ${AST_SCRS} ${AST_HRDS})
# Find SDL2, SDL2_image and SDL2_gfx libraries #set_property(TARGET AST PROPERTY C_STANDARD 99)
find_package(SDL2 REQUIRED) set_target_properties(AST PROPERTIES OUTPUT_NAME ${AST_NAME})
find_package(SDL2_image REQUIRED) if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
# Link SDL2::Main, SDL2::Image and SDL2::GFX to our project #set_target_properties(AST PROPERTIES PREFIX "lib")
target_link_libraries(${PROJECT_NAME} SDL2::Main SDL2::Image) set_target_properties(AST PROPERTIES IMPORT_PREFIX "lib")
endif()
# install executable
# Link SDL2::Main, SDL2::Image and SDL2::GFX to our project
install(TARGETS AST target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2_image_LIBRARIES})
RUNTIME DESTINATION bin
# install executable
install(TARGETS AST
RUNTIME DESTINATION bin
) )

View File

@ -1,8 +0,0 @@
The MIT License (MIT)
Copyright (c) 2016 Simon Eisenmann <simon@longsleep.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,79 +0,0 @@
BUILD_DIR := build
RM := rm -rf $(BUILD_DIR)
OBJ_SRCS :=
ASM_SRCS :=
C_SRCS :=
O_SRCS :=
S_UPPER_SRCS :=
EXECUTABLES :=
OBJS :=
C_DEPS :=
# Every subdirectory with source files must be described here
SUBDIRS := \
. \
C_SRCS += \
src/IAEngine.c \
src/arenaEngine.c \
src/arenaGUI.c \
src/fileHandler.c \
src/logHelper.c \
src/main.c \
src/menuGUI.c
OBJS += \
build/IAEngine.o \
build/arenaEngine.o \
build/arenaGUI.o \
build/fileHandler.o \
build/logHelper.o \
build/main.o \
build/menuGUI.o
C_DEPS += \
build/IAEngine.d \
build/arenaEngine.d \
build/arenaGUI.d \
build/fileHandler.d \
build/logHelper.d \
build/main.d \
build/menuGUI.d
build/%.o: src/%.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
LIBS := -lSDL2 -lSDL2main -lSDL2_image
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
.PHONY: all buildDir clean dependents
# All Target
all: buildDir ArenaSurvivalTournament
buildDir:
[ -d $(BUILD_DIR) ] || mkdir -p $(BUILD_DIR)
# Tool invocations
ArenaSurvivalTournament: $(OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
gcc -o "ArenaSurvivalTournament" $(OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(EXECUTABLES)$(OBJS)$(C_DEPS) ArenaSurvivalTournament
-@echo ' '

View File

@ -1,36 +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 libs. It's fully coded in C with SDL2 and SDL2_image libs.
All SDL2 parts and sub-parts are under the same license as SDL2 lib.
## Functions All code of AST are covered by the MIT license.
The game can do following: ## Functions
- Generate random maps level
- Control a simple IA The game can do following and you can learn from that like we do when you created this code:
- Manage gold resources - Generate random maps level
- Players movements - Control a simple IA
- Bad code practice - Manage gold resources
- Players movements
## Compiling - Bad code practice
Before compiling, you need to install both build suite (GCC/MSVC) with CMake and SDL2 libs: ## Compiling
```shell Before compiling, you need to install your favorite compiler (GCC or MSVC) with CMake and the lib manager Conan (https://conan.io):
apt update
apt install build-essential cmake libsdl2-dev libsdl2-image-dev ```shell
``` # For debian based distribution:
apt update
Clone the repo with submodules updated and launch cmake to prepare compile: apt install build-essential cmake conan
```
```shell
cd AST Clone the repo and launch in order conan and cmake in order to compile the program:
mkdir build && cd build
cp -R ../data . ```shell
cmake .. cd AST
make mkdir build && cd build
``` cp -R ../data .
conan install .. --build=missing
## Running cmake .. # or with '-G "MinGW Makefiles"' if under Windows
make
```
## 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) or use the launch script.

@ -1 +0,0 @@
Subproject commit f12dd8f3c33863b5109ae17082a5b2c5257aeae7

25
conanfile.txt Normal file
View File

@ -0,0 +1,25 @@
[requires]
sdl/2.0.16
sdl_image/2.0.5
[generators]
cmake
cmake_find_package
[options]
sdl:shared=True
sdl_image:shared=True
sdl_image:with_libjpeg=False
sdl_image:with_libtiff=False
sdl_image:with_libwebp=False
sdl_image:lbm=False
sdl_image:pcx=False
sdl_image:pnm=False
sdl_image:svg=False
sdl_image:tga=False
sdl_image:xcf=False
sdl_image:xpm=False
sdl_image:xv=False
[imports]
bin, *.dll -> .