dep/ggpo-x: Use a callback for copying state buffers

This commit is contained in:
Stenzek 2023-04-12 00:22:17 +10:00
parent bc6a86b5bb
commit f104b91a3e
3 changed files with 14 additions and 5 deletions

View File

@ -231,6 +231,12 @@ typedef struct {
*/
bool (__cdecl *load_game_state)(void* context, unsigned char* buffer, int len, int framesToRollback, int frameToLoad);
/*
* copy_game_state - creates a copy of an existing save state.
*/
bool(__cdecl* copy_game_state)(void* context, unsigned char** out_buffer, int* out_len, int* out_checksum,
const unsigned char* in_buffer, const int in_len, const int in_checksum);
/*
* log_game_state - Used in diagnostic testing. The client should use
* the ggpo_log function to write the contents of the specified save

View File

@ -126,9 +126,12 @@ SyncTestBackend::IncrementFrame(uint16_t cs)
SavedInfo info;
info.frame = frame;
info.input = _last_input;
info.cbuf = _sync.GetLastSavedFrame().cbuf;
info.buf = (char *)malloc(info.cbuf);
memcpy(info.buf, _sync.GetLastSavedFrame().buf, info.cbuf);
const Sync::SavedFrame& lsf = _sync.GetLastSavedFrame();
info.cbuf = 0;
info.buf = nullptr;
info.checksum = 0;
_callbacks.copy_game_state(_callbacks.context, &info.buf, &info.cbuf, &info.checksum, lsf.buf, lsf.cbuf, lsf.checksum);
info.checksum = _sync.GetLastSavedFrame().checksum;
_saved_frames.push(info);
@ -155,7 +158,7 @@ SyncTestBackend::IncrementFrame(uint16_t cs)
RaiseSyncError("Checksum for frame %d does not match saved (%d != %d)", frame, checksum, info.checksum);
}
printf("Checksum %08d for frame %d matches.\n", checksum, info.frame);
free(info.buf);
_callbacks.free_buffer(_callbacks.context, info.buf);
}
_last_verified = frame;
_rollingback = false;

View File

@ -31,7 +31,7 @@ protected:
struct SavedInfo {
int frame;
int checksum;
char *buf;
byte *buf;
int cbuf;
GameInput input;
};