forked from ZQuestClassic/ZQuestClassic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add (crude) RNG debugging option
- Loading branch information
Showing
4 changed files
with
70 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ src/user_object.cpp | |
src/ffc.cpp | ||
src/slopes.cpp | ||
src/zc/saves.cpp | ||
src/zc/db_rng.cpp | ||
|
||
## End of Zelda Core module | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "base/random.h" | ||
|
||
#if DEBUG_RAND | ||
#include "zc/replay.h" | ||
#include <fmt/format.h> | ||
|
||
static void db_print(char const* fname, int l, std::string const& extra) | ||
{ | ||
if(FILE* f = fopen("__db_rand.txt","a")) | ||
{ | ||
char replstr[128] = {0}; | ||
char buf[512] = {0}; | ||
if(replay_is_replaying()) sprintf(replstr, "%06d ", replay_get_frame()); | ||
sprintf(buf, "%s %s%s LINE %d\n", extra.c_str(), replstr, fname, l); | ||
fwrite(buf, 1, strlen(buf), f); | ||
fclose(f); | ||
} | ||
} | ||
|
||
int32_t db_oldrand(char const* fname, int l, zc_randgen* rng) | ||
{ | ||
if(!rng) db_print(fname,l,"OLD"); | ||
return zc_oldrand(rng); | ||
} | ||
int32_t db_rand(char const* fname, int l,zc_randgen* rng) | ||
{ | ||
if(!rng) db_print(fname,l,"NEW"); | ||
return zc_rand(rng); | ||
} | ||
int32_t db_rand(char const* fname, int l,int32_t upper,int32_t lower,zc_randgen* rng) | ||
{ | ||
if(!rng) db_print(fname,l,fmt::format("NEW {}-{}",lower,upper)); | ||
return zc_rand(upper,lower,rng); | ||
} | ||
void db_srand(char const* fname, int l, int32_t seedval, zc_randgen* rng) | ||
{ | ||
if(!rng) db_print(fname,l,fmt::format("SEED {}",seedval)); | ||
zc_srand(seedval,rng); | ||
} | ||
#endif | ||
|