Skip to content

Commit

Permalink
Only allow --record and --replay for DEBUG/COVERAGE build
Browse files Browse the repository at this point in the history
  • Loading branch information
casavaca committed Jan 17, 2024
1 parent 3a91e4d commit 7d842a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ set_tests_properties(smoketest PROPERTIES TIMEOUT 30)

# Include the custom build type configuration file
# add -DNDEBUG because the coverage tool is still not accurate around assert, even at -O0
set(CMAKE_CXX_FLAGS_COVERAGE "-fprofile-instr-generate -fcoverage-mapping -g -O0 -DNDEBUG")
set(CMAKE_CXX_FLAGS_COVERAGE "-fprofile-instr-generate -fcoverage-mapping -g -O0 -DCOVERAGE -DNDEBUG")
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# This is just a wrapper of cmake

debug:
cmake -S . -B build -DCMAKE_BUILD_TYPE=DEBUG && cmake --build build
CC=clang CXX=clang++ cmake -S . -B build -DCMAKE_BUILD_TYPE=DEBUG && cmake --build build
gcc:
CC=gcc CXX=g++ cmake -S . -B gcc-build -DCMAKE_BUILD_TYPE=DEBUG && cmake --build gcc-build
CC=gcc CXX=g++ cmake -S . -B gcc-build -DCMAKE_BUILD_TYPE=RELEASE && cmake --build gcc-build
coverage:
cmake -S . -B coverage-build -DCMAKE_BUILD_TYPE=COVERAGE && cmake --build coverage-build
release:
cmake -S . -B release-build -DCMAKE_BUILD_TYPE=RELEASE && cmake --build release-build
CC=clang CXX=clang++ cmake -S . -B coverage-build -DCMAKE_BUILD_TYPE=COVERAGE && cmake --build coverage-build
emscripten:
emcmake cmake -S . -B emscripten-build -DPLATFORM=Web && cmake --build emscripten-build

all: debug release emscripten
all: debug gcc coverage emscripten
16 changes: 13 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ int main(int argc, char** argv) {
CLI::App app{"Sokoban"};
string raylibEventFile;
int FPS = 60;
#if defined(DEBUG) || defined(COVERAGE)
auto* option_record = app.add_option("--record", raylibEventFile, "record input event");
[[maybe_unused]] auto* _1 = app.add_option("--replay", raylibEventFile, "replay events from file")
->excludes(option_record);
#endif
[[maybe_unused]] auto* _2 = app.add_option("--fps", FPS, "Set FPS (intended for testing only)")
->default_val(60);

Expand All @@ -40,7 +42,8 @@ int main(int argc, char** argv) {
SetExitKey(KEY_NULL); // Disable quit-on-ESC
//---------------------------------------------------------------------------------------

// raylib event record and replay.
#if defined(DEBUG) || defined(COVERAGE)
// raylib event record and replay, testing only.
vector<AutomationEvent> raylibEvents;
AutomationEventList raylibEventList;
if (app.count("--record")) {
Expand All @@ -51,9 +54,11 @@ int main(int argc, char** argv) {

SetAutomationEventList(&raylibEventList);
StartAutomationEventRecording();
} else if (app.count("--replay")) {
}
if (app.count("--replay")) {
raylibEventList = LoadAutomationEventList(raylibEventFile.c_str());
}
#endif

// Main game loop
bool shouldClose = false;
Expand All @@ -80,6 +85,7 @@ int main(int argc, char** argv) {
//----------------------------------------------------------------------------------
// Replay input events
//----------------------------------------------------------------------------------
#if defined(DEBUG) || defined(COVERAGE)
if (app.count("--replay")) {
static int current_frame = 0;
if (raylibEventList.count == 0)
Expand All @@ -95,16 +101,20 @@ int main(int argc, char** argv) {
}
current_frame++;
}
#endif
}

// raylib event record and replay.
#if defined(DEBUG) || defined(COVERAGE)
if (app.count("--replay")) {
assert(raylibEventList.count == 0);
}
#endif
#if defined(DEBUG)
if (app.count("--record")) {
StopAutomationEventRecording();
ExportAutomationEventList(raylibEventList, raylibEventFile.c_str());
}

#endif
return 0;
}

0 comments on commit 7d842a6

Please sign in to comment.