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_FLAGS "-Wall -Wextra")
|
||||
cmake_minimum_required(VERSION 3.22.1)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
project(${PROJECT_NAME} C CXX)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(RAYLIB_DIR /usr/local/lib CACHE FILEPATH "directory to Raylib")
|
||||
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)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
|
@ -24,208 +32,69 @@ set(GAME_LIBS
|
|||
lib_scenes
|
||||
)
|
||||
|
||||
if (${RUN_PROFILER})
|
||||
set(GAME_LIBS
|
||||
lib_scenes
|
||||
pthread
|
||||
dl
|
||||
)
|
||||
endif()
|
||||
|
||||
add_subdirectory(engine)
|
||||
add_subdirectory(scenes)
|
||||
if (NOT EMSCRIPTEN)
|
||||
add_subdirectory(res)
|
||||
endif ()
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.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
|
||||
macro(add_target_exe name)
|
||||
add_executable(${name}
|
||||
${name}.c
|
||||
tracy/public/TracyClient.cpp
|
||||
)
|
||||
target_compile_definitions(sandbox_trace
|
||||
PUBLIC
|
||||
TRACY_ENABLE
|
||||
TRACY_ON_DEMAND
|
||||
)
|
||||
target_include_directories(sandbox_trace
|
||||
target_include_directories(${name}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
PUBLIC
|
||||
tracy/public/
|
||||
)
|
||||
|
||||
target_link_libraries(sandbox_trace
|
||||
if (RUN_PROFILER)
|
||||
target_compile_definitions(${name}
|
||||
PUBLIC
|
||||
lib_scenes_trace
|
||||
pthread
|
||||
dl
|
||||
TRACY_ENABLE
|
||||
TRACY_ON_DEMAND
|
||||
)
|
||||
|
||||
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()
|
||||
target_link_libraries(scene_test
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
|
||||
if (NOT EMSCRIPTEN)
|
||||
|
||||
add_executable(EntManager_test
|
||||
entManager_test.c
|
||||
)
|
||||
target_compile_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(EntManager_test PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_include_directories(EntManager_test
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(EntManager_test
|
||||
if (INCLUDE_ASAN)
|
||||
target_compile_options(${name} PRIVATE -fsanitize=address -gdwarf-4)
|
||||
target_link_options(${name} PRIVATE -fsanitize=address -gdwarf-4)
|
||||
endif ()
|
||||
if (EXPORT_MMAP)
|
||||
target_link_options(${name} PRIVATE -Xlinker -Map=scene_test.map)
|
||||
endif()
|
||||
endif ()
|
||||
target_link_libraries(${name}
|
||||
PUBLIC
|
||||
${GAME_LIBS}
|
||||
)
|
||||
endmacro()
|
||||
|
||||
add_target_exe(main)
|
||||
add_target_exe(level_test)
|
||||
add_target_exe(scene_test)
|
||||
|
||||
add_executable(scene_test_mem
|
||||
scene_test.c
|
||||
)
|
||||
target_include_directories(scene_test_mem
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_options(scene_test_mem PRIVATE -Xlinker -Map=scene_test.map)
|
||||
|
||||
target_link_libraries(scene_test_mem
|
||||
${GAME_LIBS}
|
||||
)
|
||||
|
||||
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 (NOT EMSCRIPTEN)
|
||||
if (BUILD_EXTRAS AND NOT RUN_PROFILER)
|
||||
add_target_exe(entManager_test)
|
||||
add_target_exe(water_test)
|
||||
add_target_exe(level_load_test)
|
||||
add_target_exe(menu_test)
|
||||
add_target_exe(assets_test)
|
||||
add_target_exe(particle_test)
|
||||
add_target_exe(scene_man_test)
|
||||
add_target_exe(level_select_test)
|
||||
endif()
|
||||
if (BUILD_TESTING)
|
||||
find_package(cmocka 1.1.0 REQUIRED)
|
||||
add_subdirectory(tests)
|
||||
|
|
15
level_test.c
15
level_test.c
|
@ -7,6 +7,8 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tracy/TracyC.h"
|
||||
#define N_SCENES 1
|
||||
|
||||
Scene_t *scenes[N_SCENES];
|
||||
|
@ -30,13 +32,8 @@ int main(int argc, char** argv)
|
|||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
init_engine(&engine, (Vector2){screenWidth, screenHeight});
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
#ifndef NDEBUG
|
||||
load_from_infofile("res/assets.info.raw", &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);
|
||||
|
||||
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;
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
TracyCFrameMark;
|
||||
// This entire key processing relies on the assumption that a pressed key will
|
||||
// appear in the polling of raylib
|
||||
Scene_t* curr_scene = engine.scenes[engine.curr_scene];
|
||||
|
@ -106,11 +104,16 @@ int main(int argc, char** argv)
|
|||
float frame_time = GetFrameTime();
|
||||
float delta_time = fminf(frame_time, DT);
|
||||
|
||||
{
|
||||
TracyCZoneN(ctx, "Update", true)
|
||||
update_scene(curr_scene, delta_time);
|
||||
update_entity_manager(&curr_scene->ent_manager);
|
||||
update_sfx_list(&engine);
|
||||
TracyCZoneEnd(ctx)
|
||||
}
|
||||
|
||||
// This is needed to advance time delta
|
||||
render_scene(curr_scene);
|
||||
update_sfx_list(&engine);
|
||||
|
||||
if (curr_scene->state != 0)
|
||||
{
|
||||
|
|
|
@ -15,37 +15,18 @@ add_library(lib_scenes STATIC
|
|||
target_include_directories(lib_scenes
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_link_libraries(lib_scenes
|
||||
PUBLIC
|
||||
lib_engine
|
||||
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
|
||||
)
|
||||
|
||||
add_library(lib_scenes_trace STATIC
|
||||
assets_loader.c
|
||||
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
|
||||
if (${RUN_PROFILER})
|
||||
target_compile_definitions(lib_scenes
|
||||
PUBLIC
|
||||
TRACY_ENABLE
|
||||
TRACY_ON_DEMAND
|
||||
)
|
||||
target_include_directories(lib_scenes_trace
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/../tracy/public/
|
||||
)
|
||||
target_link_libraries(lib_scenes_trace
|
||||
endif()
|
||||
|
||||
target_link_libraries(lib_scenes
|
||||
PUBLIC
|
||||
lib_engine
|
||||
)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include "tracy/TracyC.h"
|
||||
|
||||
#include "scene_impl.h"
|
||||
#include "game_systems.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)
|
||||
{
|
||||
TracyCZoneN(ctx, "GameRender", true)
|
||||
// This function will render the game scene outside of the intended draw function
|
||||
// Just for clarity and separation of logic
|
||||
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
|
||||
|
@ -464,6 +467,7 @@ static void render_regular_game_scene(Scene_t* scene)
|
|||
}
|
||||
EndMode2D();
|
||||
EndTextureMode();
|
||||
TracyCZoneEnd(ctx)
|
||||
}
|
||||
|
||||
static void at_level_start(Scene_t* scene)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include "assets_tag.h"
|
||||
#ifdef TRACY_ENABLE
|
||||
#include "tracy/TracyC.h"
|
||||
#endif
|
||||
|
||||
#include "game_systems.h"
|
||||
|
||||
|
@ -781,9 +779,7 @@ void spike_collision_system(Scene_t* scene)
|
|||
|
||||
void tile_collision_system(Scene_t* scene)
|
||||
{
|
||||
#ifdef TRACY_ENABLE
|
||||
TracyCZoneN(ctx, "TileCol", true)
|
||||
#endif
|
||||
static bool checked_entities[MAX_COMP_POOL_SIZE] = {0};
|
||||
|
||||
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)
|
||||
#endif
|
||||
}
|
||||
|
||||
void friction_coefficient_update_system(Scene_t* scene)
|
||||
|
|
Loading…
Reference in New Issue