|
79 | 79 | #include "System/FileSystem/FileHandler.h" |
80 | 80 | #include "System/FileSystem/FileSystem.h" |
81 | 81 | #include "System/StringUtil.h" |
| 82 | +#include "System/Sync/SyncChecker.h" |
82 | 83 |
|
83 | 84 | #include <cctype> |
84 | 85 | #include <functional> |
@@ -121,6 +122,7 @@ bool LuaSyncedRead::PushEntries(lua_State* L) |
121 | 122 |
|
122 | 123 | REGISTER_LUA_CFUNC(GetGameFrame); |
123 | 124 | REGISTER_LUA_CFUNC(GetGameSeconds); |
| 125 | + REGISTER_LUA_CFUNC(GetPrevFrameChecksum); |
124 | 126 |
|
125 | 127 | REGISTER_LUA_CFUNC(GetGameRulesParam); |
126 | 128 | REGISTER_LUA_CFUNC(GetGameRulesParams); |
@@ -931,6 +933,38 @@ int LuaSyncedRead::GetGameSeconds(lua_State* L) |
931 | 933 | } |
932 | 934 |
|
933 | 935 |
|
| 936 | +/*** |
| 937 | + * |
| 938 | + * Returns the engine's final sync checksum for the previous simulation |
| 939 | + * frame as an 8-character lowercase hex string (e.g. `"fade1eaf"`). |
| 940 | + * The value is stable for the entire duration of the current frame |
| 941 | + * (independent of gadget/callin ordering) and is identical across all |
| 942 | + * in-sync clients, so it can be folded into a deterministic per-run |
| 943 | + * artifact for sync testing (e.g. fightertest). |
| 944 | + * |
| 945 | + * Returned as a string rather than a number because Spring's Lua is |
| 946 | + * built with `LUA_NUMBER = float`, which cannot represent a 32-bit |
| 947 | + * checksum losslessly. |
| 948 | + * |
| 949 | + * Returns `nil` on builds without `SYNCCHECK`. |
| 950 | + * |
| 951 | + * @function Spring.GetPrevFrameChecksum |
| 952 | + * |
| 953 | + * @return string|nil checksum |
| 954 | + */ |
| 955 | +int LuaSyncedRead::GetPrevFrameChecksum(lua_State* L) |
| 956 | +{ |
| 957 | +#ifdef SYNCCHECK |
| 958 | + char buf[16]; |
| 959 | + snprintf(buf, sizeof(buf), "%08x", CSyncChecker::GetPrevChecksum()); |
| 960 | + lua_pushstring(L, buf); |
| 961 | +#else |
| 962 | + lua_pushnil(L); |
| 963 | +#endif |
| 964 | + return 1; |
| 965 | +} |
| 966 | + |
| 967 | + |
934 | 968 | /****************************************************************************** |
935 | 969 | * Environment |
936 | 970 | * @section environment |
|
0 commit comments