add cheapCloneHandle parameter to Shavit_GetReplayFrames

This commit is contained in:
rtldg 2021-07-10 03:15:47 +00:00
parent 4a686ee440
commit 418676d26c
2 changed files with 10 additions and 3 deletions

View File

@ -1611,9 +1611,10 @@ native int Shavit_GetReplayCachePostFrame(int bot);
* *
* @param style Style. * @param style Style.
* @param track Track. * @param track Track.
* @param cheapCloneHandle False means we duplicate the frames (ArrayList.Clone). True means we clone the handle to the frames (CloneHandle).
* @return ArrayList with proper replay data, or null if there is no recorded data. * @return ArrayList with proper replay data, or null if there is no recorded data.
*/ */
native ArrayList Shavit_GetReplayFrames(int style, int track); native ArrayList Shavit_GetReplayFrames(int style, int track, bool cheapCloneHandle=false);
/** /**
* Retrieves a client's frame count. * Retrieves a client's frame count.

View File

@ -1107,13 +1107,19 @@ public int Native_GetReplayFrames(Handle plugin, int numParams)
{ {
int style = GetNativeCell(1); int style = GetNativeCell(1);
int track = GetNativeCell(2); int track = GetNativeCell(2);
bool cheapCloneHandle = (numParams > 2) && view_as<bool>(GetNativeCell(3));
Handle cloned = null; Handle cloned = null;
if(gA_FrameCache[style][track].aFrames != null) if(gA_FrameCache[style][track].aFrames != null)
{ {
ArrayList frames = gA_FrameCache[style][track].aFrames.Clone(); ArrayList frames = cheapCloneHandle ? gA_FrameCache[style][track].aFrames : gA_FrameCache[style][track].aFrames.Clone();
cloned = CloneHandle(frames, plugin); // set the calling plugin as the handle owner cloned = CloneHandle(frames, plugin); // set the calling plugin as the handle owner
CloseHandle(frames);
if (!cheapCloneHandle)
{
// Only hit for .Clone()'d handles. .Clone() != CloneHandle()
CloseHandle(frames);
}
} }
return view_as<int>(cloned); return view_as<int>(cloned);