Merge pull request #112 from ReDucTor/vscript-fix-bad-restore

Fixing bug with vscript restore cache not updating soon enough
This commit is contained in:
Blixibon 2021-04-22 12:55:24 -05:00 committed by GitHub
commit bb250dbae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,8 +65,16 @@ struct WriteStateMap
struct ReadStateMap
{
CUtlMap<int, HSQOBJECT> cache;
#ifdef _DEBUG
CUtlMap<int, bool> allocated;
#endif
HSQUIRRELVM vm_;
ReadStateMap(HSQUIRRELVM vm) : cache(DefLessFunc(int)), vm_(vm)
ReadStateMap(HSQUIRRELVM vm) :
cache(DefLessFunc(int)),
#ifdef _DEBUG
allocated(DefLessFunc(int)),
#endif
vm_(vm)
{}
~ReadStateMap()
@ -83,6 +91,16 @@ struct ReadStateMap
int marker = pBuffer->GetInt();
auto idx = cache.Find(marker);
#ifdef _DEBUG
auto allocatedIdx = allocated.Find(marker);
bool hasSeen = allocatedIdx != allocated.InvalidIndex();
if (!hasSeen)
{
allocated.Insert(marker, true);
}
#endif
if (idx != cache.InvalidIndex())
{
sq_pushobject(vm, cache[idx]);
@ -90,6 +108,9 @@ struct ReadStateMap
}
else
{
#ifdef _DEBUG
Assert(!hasSeen);
#endif
*outmarker = marker;
return false;
}
@ -3395,6 +3416,7 @@ void SquirrelVM::WriteState(CUtlBuffer* pBuffer)
int count = sq_getsize(vm_, 1);
sq_pushnull(vm_);
pBuffer->PutInt(count);
while (SQ_SUCCEEDED(sq_next(vm_, -2)))
{
WriteObject(pBuffer, writeState, -2);
@ -3528,6 +3550,9 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
break;
}
vm_->Push(ret);
readState.StoreTopInCache(marker);
int noutervalues = _closure(ret)->_function->_noutervalues;
for (int i = 0; i < noutervalues; ++i)
{
@ -3549,9 +3574,6 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
_closure(ret)->_defaultparams[i] = obj;
sq_poptop(vm_);
}
vm_->Push(ret);
readState.StoreTopInCache(marker);
}
ReadObject(pBuffer, readState);
@ -3823,16 +3845,17 @@ void SquirrelVM::ReadObject(CUtlBuffer* pBuffer, ReadStateMap& readState)
break;
}
SQOuter* outer = SQOuter::Create(_ss(vm_), nullptr);
vm_->Push(outer);
readState.StoreTopInCache(marker);
ReadObject(pBuffer, readState);
HSQOBJECT inner;
sq_resetobject(&inner);
sq_getstackobj(vm_, -1, &inner);
SQOuter* outer = SQOuter::Create(_ss(vm_), nullptr);
outer->_value = inner;
outer->_valptr = &(outer->_value);
sq_poptop(vm_);
vm_->Push(outer);
readState.StoreTopInCache(marker);
break;
}