Significantly Update CMakeFile to reduce clutter
This is to reduce repetition and better integrate Tracy. Some options are added as well.main
parent
ee65e3c974
commit
f3defcf656
229
CMakeLists.txt
229
CMakeLists.txt
|
@ -2,10 +2,18 @@ set(PROJECT_NAME HATPC_remake)
|
||||||
set(CMAKE_C_COMPILER clang)
|
set(CMAKE_C_COMPILER clang)
|
||||||
set(CMAKE_C_FLAGS "-Wall -Wextra")
|
set(CMAKE_C_FLAGS "-Wall -Wextra")
|
||||||
cmake_minimum_required(VERSION 3.22.1)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
project(${PROJECT_NAME} C CXX)
|
project(${PROJECT_NAME} C CXX)
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
||||||
set(LIBZSTD_DIR /usr/local/lib CACHE FILEPATH "directory to zstd")
|
set(LIBZSTD_DIR /usr/local/lib CACHE FILEPATH "directory to zstd")
|
||||||
|
option(RUN_PROFILER OFF)
|
||||||
|
option(INCLUDE_ASAN ON)
|
||||||
|
option(EXPORT_MMAP OFF)
|
||||||
|
option(BUILD_EXTRAS OFF)
|
||||||
|
|
||||||
|
# If you want to use Heaptrack to profile the memory
|
||||||
|
# Do not compile in ASAN
|
||||||
|
|
||||||
if (EMSCRIPTEN)
|
if (EMSCRIPTEN)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||||
|
@ -24,208 +32,69 @@ set(GAME_LIBS
|
||||||
lib_scenes
|
lib_scenes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (${RUN_PROFILER})
|
||||||
|
set(GAME_LIBS
|
||||||
|
lib_scenes
|
||||||
|
pthread
|
||||||
|
dl
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_subdirectory(engine)
|
add_subdirectory(engine)
|
||||||
add_subdirectory(scenes)
|
add_subdirectory(scenes)
|
||||||
if (NOT EMSCRIPTEN)
|
if (NOT EMSCRIPTEN)
|
||||||
add_subdirectory(res)
|
add_subdirectory(res)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
macro(add_target_exe name)
|
||||||
main.c
|
add_executable(${name}
|
||||||
)
|
${name}.c
|
||||||
|
|
||||||
# Use Heaptrack to profile the main application
|
|
||||||
# Do not compile in ASAN
|
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(level_player
|
|
||||||
level_test.c
|
|
||||||
)
|
|
||||||
|
|
||||||
# Use Heaptrack to profile the main application
|
|
||||||
# Do not compile in ASAN
|
|
||||||
|
|
||||||
target_include_directories(level_player
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(level_player
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(sandbox_trace
|
|
||||||
scene_test.c
|
|
||||||
tracy/public/TracyClient.cpp
|
tracy/public/TracyClient.cpp
|
||||||
)
|
)
|
||||||
target_compile_definitions(sandbox_trace
|
target_include_directories(${name}
|
||||||
PUBLIC
|
|
||||||
TRACY_ENABLE
|
|
||||||
TRACY_ON_DEMAND
|
|
||||||
)
|
|
||||||
target_include_directories(sandbox_trace
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
tracy/public/
|
tracy/public/
|
||||||
)
|
)
|
||||||
|
if (RUN_PROFILER)
|
||||||
target_link_libraries(sandbox_trace
|
target_compile_definitions(${name}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
lib_scenes_trace
|
TRACY_ENABLE
|
||||||
pthread
|
TRACY_ON_DEMAND
|
||||||
dl
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(scene_test
|
|
||||||
scene_test.c
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(scene_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT EMSCRIPTEN)
|
|
||||||
target_compile_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(scene_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(scene_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if (NOT EMSCRIPTEN)
|
if (NOT EMSCRIPTEN)
|
||||||
|
if (INCLUDE_ASAN)
|
||||||
add_executable(EntManager_test
|
target_compile_options(${name} PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
entManager_test.c
|
target_link_options(${name} PRIVATE -fsanitize=address -gdwarf-4)
|
||||||
)
|
endif ()
|
||||||
target_compile_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
if (EXPORT_MMAP)
|
||||||
target_link_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
target_link_options(${name} PRIVATE -Xlinker -Map=scene_test.map)
|
||||||
target_include_directories(EntManager_test
|
endif()
|
||||||
PRIVATE
|
endif ()
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
target_link_libraries(${name}
|
||||||
)
|
PUBLIC
|
||||||
target_link_libraries(EntManager_test
|
|
||||||
${GAME_LIBS}
|
${GAME_LIBS}
|
||||||
)
|
)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
add_target_exe(main)
|
||||||
|
add_target_exe(level_test)
|
||||||
|
add_target_exe(scene_test)
|
||||||
|
|
||||||
add_executable(scene_test_mem
|
if (NOT EMSCRIPTEN)
|
||||||
scene_test.c
|
if (BUILD_EXTRAS AND NOT RUN_PROFILER)
|
||||||
)
|
add_target_exe(entManager_test)
|
||||||
target_include_directories(scene_test_mem
|
add_target_exe(water_test)
|
||||||
PRIVATE
|
add_target_exe(level_load_test)
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
add_target_exe(menu_test)
|
||||||
)
|
add_target_exe(assets_test)
|
||||||
target_link_options(scene_test_mem PRIVATE -Xlinker -Map=scene_test.map)
|
add_target_exe(particle_test)
|
||||||
|
add_target_exe(scene_man_test)
|
||||||
target_link_libraries(scene_test_mem
|
add_target_exe(level_select_test)
|
||||||
${GAME_LIBS}
|
endif()
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(water_test
|
|
||||||
water_test.c
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(water_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(water_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
target_compile_options(water_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(water_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
|
|
||||||
add_executable(level_load_test
|
|
||||||
level_load_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(level_load_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_link_libraries(level_load_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
target_compile_options(level_load_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(level_load_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
|
|
||||||
add_executable(menu_test
|
|
||||||
menu_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(menu_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(menu_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(menu_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(assets_test
|
|
||||||
assets_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(assets_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(assets_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(assets_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(particle_test
|
|
||||||
particle_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(particle_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(particle_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(particle_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(particle_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(scene_man_test
|
|
||||||
scene_man_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(scene_man_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(scene_man_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(scene_man_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(scene_man_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
add_executable(level_select_test
|
|
||||||
level_select_test.c
|
|
||||||
)
|
|
||||||
target_include_directories(level_select_test
|
|
||||||
PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
target_compile_options(level_select_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_options(level_select_test PRIVATE -fsanitize=address -gdwarf-4)
|
|
||||||
target_link_libraries(level_select_test
|
|
||||||
${GAME_LIBS}
|
|
||||||
)
|
|
||||||
|
|
||||||
if (BUILD_TESTING)
|
if (BUILD_TESTING)
|
||||||
find_package(cmocka 1.1.0 REQUIRED)
|
find_package(cmocka 1.1.0 REQUIRED)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
15
level_test.c
15
level_test.c
|
@ -7,6 +7,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "tracy/TracyC.h"
|
||||||
#define N_SCENES 1
|
#define N_SCENES 1
|
||||||
|
|
||||||
Scene_t *scenes[N_SCENES];
|
Scene_t *scenes[N_SCENES];
|
||||||
|
@ -30,13 +32,8 @@ int main(int argc, char** argv)
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||||
init_engine(&engine, (Vector2){screenWidth, screenHeight});
|
init_engine(&engine, (Vector2){screenWidth, screenHeight});
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
#ifndef NDEBUG
|
|
||||||
load_from_infofile("res/assets.info.raw", &engine.assets);
|
load_from_infofile("res/assets.info.raw", &engine.assets);
|
||||||
init_player_creation("res/player_spr.info", &engine.assets);
|
init_player_creation("res/player_spr.info", &engine.assets);
|
||||||
#else
|
|
||||||
load_from_rres("res/myresources.rres", &engine.assets);
|
|
||||||
init_player_creation_rres("res/myresources.rres", "player_spr.info", &engine.assets);
|
|
||||||
#endif
|
|
||||||
init_item_creation(&engine.assets);
|
init_item_creation(&engine.assets);
|
||||||
|
|
||||||
load_sfx(&engine, "snd_jump", PLAYER_JMP_SFX);
|
load_sfx(&engine, "snd_jump", PLAYER_JMP_SFX);
|
||||||
|
@ -91,6 +88,7 @@ int main(int argc, char** argv)
|
||||||
const float DT = 1.0f/60.0f;
|
const float DT = 1.0f/60.0f;
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
|
TracyCFrameMark;
|
||||||
// This entire key processing relies on the assumption that a pressed key will
|
// This entire key processing relies on the assumption that a pressed key will
|
||||||
// appear in the polling of raylib
|
// appear in the polling of raylib
|
||||||
Scene_t* curr_scene = engine.scenes[engine.curr_scene];
|
Scene_t* curr_scene = engine.scenes[engine.curr_scene];
|
||||||
|
@ -106,11 +104,16 @@ int main(int argc, char** argv)
|
||||||
float frame_time = GetFrameTime();
|
float frame_time = GetFrameTime();
|
||||||
float delta_time = fminf(frame_time, DT);
|
float delta_time = fminf(frame_time, DT);
|
||||||
|
|
||||||
|
{
|
||||||
|
TracyCZoneN(ctx, "Update", true)
|
||||||
update_scene(curr_scene, delta_time);
|
update_scene(curr_scene, delta_time);
|
||||||
update_entity_manager(&curr_scene->ent_manager);
|
update_entity_manager(&curr_scene->ent_manager);
|
||||||
|
update_sfx_list(&engine);
|
||||||
|
TracyCZoneEnd(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// This is needed to advance time delta
|
// This is needed to advance time delta
|
||||||
render_scene(curr_scene);
|
render_scene(curr_scene);
|
||||||
update_sfx_list(&engine);
|
|
||||||
|
|
||||||
if (curr_scene->state != 0)
|
if (curr_scene->state != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,37 +15,18 @@ add_library(lib_scenes STATIC
|
||||||
target_include_directories(lib_scenes
|
target_include_directories(lib_scenes
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
)
|
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
|
||||||
target_link_libraries(lib_scenes
|
|
||||||
PUBLIC
|
|
||||||
lib_engine
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(lib_scenes_trace STATIC
|
if (${RUN_PROFILER})
|
||||||
assets_loader.c
|
target_compile_definitions(lib_scenes
|
||||||
player_ent.c
|
|
||||||
items_ent.c
|
|
||||||
water_flow.c
|
|
||||||
editor_scene.c
|
|
||||||
menu_scene.c
|
|
||||||
level_select_scene.c
|
|
||||||
game_scene.c
|
|
||||||
game_systems.c
|
|
||||||
scene_systems.c
|
|
||||||
camera_systems.c
|
|
||||||
engine_impl.c
|
|
||||||
)
|
|
||||||
target_compile_definitions(lib_scenes_trace
|
|
||||||
PUBLIC
|
PUBLIC
|
||||||
TRACY_ENABLE
|
TRACY_ENABLE
|
||||||
TRACY_ON_DEMAND
|
TRACY_ON_DEMAND
|
||||||
)
|
)
|
||||||
target_include_directories(lib_scenes_trace
|
endif()
|
||||||
PUBLIC
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
target_link_libraries(lib_scenes
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
|
|
||||||
)
|
|
||||||
target_link_libraries(lib_scenes_trace
|
|
||||||
PUBLIC
|
PUBLIC
|
||||||
lib_engine
|
lib_engine
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include "tracy/TracyC.h"
|
||||||
|
|
||||||
#include "scene_impl.h"
|
#include "scene_impl.h"
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
#include "water_flow.h"
|
#include "water_flow.h"
|
||||||
|
@ -135,6 +137,7 @@ static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
|
||||||
|
|
||||||
static void render_regular_game_scene(Scene_t* scene)
|
static void render_regular_game_scene(Scene_t* scene)
|
||||||
{
|
{
|
||||||
|
TracyCZoneN(ctx, "GameRender", true)
|
||||||
// This function will render the game scene outside of the intended draw function
|
// This function will render the game scene outside of the intended draw function
|
||||||
// Just for clarity and separation of logic
|
// Just for clarity and separation of logic
|
||||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
||||||
|
@ -464,6 +467,7 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
}
|
}
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
TracyCZoneEnd(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void at_level_start(Scene_t* scene)
|
static void at_level_start(Scene_t* scene)
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "assets_tag.h"
|
#include "assets_tag.h"
|
||||||
#ifdef TRACY_ENABLE
|
|
||||||
#include "tracy/TracyC.h"
|
#include "tracy/TracyC.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "game_systems.h"
|
#include "game_systems.h"
|
||||||
|
|
||||||
|
@ -781,9 +779,7 @@ void spike_collision_system(Scene_t* scene)
|
||||||
|
|
||||||
void tile_collision_system(Scene_t* scene)
|
void tile_collision_system(Scene_t* scene)
|
||||||
{
|
{
|
||||||
#ifdef TRACY_ENABLE
|
|
||||||
TracyCZoneN(ctx, "TileCol", true)
|
TracyCZoneN(ctx, "TileCol", true)
|
||||||
#endif
|
|
||||||
static bool checked_entities[MAX_COMP_POOL_SIZE] = {0};
|
static bool checked_entities[MAX_COMP_POOL_SIZE] = {0};
|
||||||
|
|
||||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
||||||
|
@ -924,9 +920,7 @@ void tile_collision_system(Scene_t* scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TRACY_ENABLE
|
|
||||||
TracyCZoneEnd(ctx)
|
TracyCZoneEnd(ctx)
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void friction_coefficient_update_system(Scene_t* scene)
|
void friction_coefficient_update_system(Scene_t* scene)
|
||||||
|
|
Loading…
Reference in New Issue