From fae99ff8d15b6ae182d6743573f82f251e61159d Mon Sep 17 00:00:00 2001 From: shavit Date: Thu, 25 Oct 2018 01:42:11 +0300 Subject: [PATCH] optimized replay writing to do less system calls --- addons/sourcemod/scripting/shavit-replay.sp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index d6797290..d837a511 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -34,6 +34,7 @@ #define REPLAY_FORMAT_FINAL "{SHAVITREPLAYFORMAT}{FINAL}" #define REPLAY_FORMAT_SUBVERSION 0x02 #define CELLS_PER_FRAME 8 // origin[3], angles[2], buttons, flags, movetype +#define FRAMES_PER_WRITE 100 // amounts of frames to write per read/write call // #define DEBUG @@ -972,7 +973,7 @@ bool LoadReplay(int style, int track, const char[] path) gH_SQL.Query(SQL_GetUserName_Callback, sQuery, pack, DBPrio_High); } - int cells = 8; + int cells = CELLS_PER_FRAME; // backwards compatibility if(gA_FrameCache[style][track][3] == 0x01) @@ -1087,12 +1088,25 @@ bool SaveReplay(int style, int track, float time, char[] authid, char[] name) // if REPLAY_FORMAT_SUBVERSION is over 0x01 i'll add variables here - any[] aFrameData = new any[CELLS_PER_FRAME]; + any aFrameData[CELLS_PER_FRAME]; + any aWriteData[CELLS_PER_FRAME * FRAMES_PER_WRITE]; + int iFramesWritten = 0; for(int i = 0; i < iSize; i++) { gA_Frames[style][track].GetArray(i, aFrameData, CELLS_PER_FRAME); - fFile.Write(aFrameData, CELLS_PER_FRAME, 4); + + for(int j = 0; j < CELLS_PER_FRAME; j++) + { + aWriteData[(CELLS_PER_FRAME * iFramesWritten) + j] = aFrameData[j]; + } + + if(++iFramesWritten == FRAMES_PER_WRITE || i == iSize - 1) + { + fFile.Write(aWriteData, CELLS_PER_FRAME * iFramesWritten, 4); + + iFramesWritten = 0; + } } delete fFile;