eliminate freeze when encountering players by preloading race motions

This commit is contained in:
savis
2026-01-04 10:41:48 +01:00
parent 4c21fe697c
commit 2550008f6d
4 changed files with 57 additions and 1 deletions

View File

@@ -534,7 +534,7 @@ void CGraphicThingInstance::RegisterMotionThing(DWORD dwMotionKey, CGraphicThing
{
CGraphicThing::TRef * pMotionRef = new CGraphicThing::TRef;
pMotionRef->SetPointer(pMotionThing);
m_roMotionThingMap.insert(std::map<DWORD, CGraphicThing::TRef *>::value_type(dwMotionKey, pMotionRef));
m_roMotionThingMap.insert(std::make_pair(dwMotionKey, pMotionRef));
}
void CGraphicThingInstance::ResetLocalTime()

View File

@@ -3,6 +3,8 @@
#include "RaceMotionData.h"
#include "PackLib/PackManager.h"
bool CRaceManager::s_bPreloaded = false;
bool __IsGuildRace(unsigned race)
{
if (race >= 14000 && race < 15000)
@@ -448,3 +450,46 @@ CRaceManager::~CRaceManager()
{
Destroy();
}
void CRaceManager::PreloadPlayerRaceMotions()
{
if (s_bPreloaded)
return;
// Preload all player races (0-7)
for (DWORD dwRace = 0; dwRace <= 7; ++dwRace)
{
CRaceData* pRaceData = NULL;
if (!Instance().GetRaceDataPointer(dwRace, &pRaceData))
continue;
CRaceData::TMotionModeDataIterator itor;
if (pRaceData->CreateMotionModeIterator(itor))
{
do
{
CRaceData::TMotionModeData* pMotionModeData = itor->second;
CRaceData::TMotionVectorMap::iterator itorMotion = pMotionModeData->MotionVectorMap.begin();
for (; itorMotion != pMotionModeData->MotionVectorMap.end(); ++itorMotion)
{
const CRaceData::TMotionVector& c_rMotionVector = itorMotion->second;
CRaceData::TMotionVector::const_iterator it;
for (it = c_rMotionVector.begin(); it != c_rMotionVector.end(); ++it)
{
CGraphicThing* pMotion = it->pMotion;
if (pMotion)
{
pMotion->AddReference();
}
}
}
}
while (pRaceData->NextMotionModeIterator(itor));
}
}
s_bPreloaded = true;
}

View File

@@ -29,6 +29,9 @@ class CRaceManager : public CSingleton<CRaceManager>
BOOL GetRaceDataPointer(DWORD dwRaceIndex, CRaceData ** ppRaceData);
// Race motion preloading
static void PreloadPlayerRaceMotions();
static bool IsPreloaded() { return s_bPreloaded; }
protected:
CRaceData* __LoadRaceData(DWORD dwRaceIndex);
@@ -46,4 +49,5 @@ class CRaceManager : public CSingleton<CRaceManager>
private:
std::string m_strPathName;
CRaceData * m_pSelectedRaceData;
static bool s_bPreloaded;
};

View File

@@ -713,6 +713,12 @@ PyObject * chrmgrIsPossibleEmoticon(PyObject* poSelf, PyObject* poArgs)
return Py_BuildValue("i", result);
}
PyObject * chrmgrPreloadRaceMotions(PyObject* poSelf, PyObject* poArgs)
{
CRaceManager::PreloadPlayerRaceMotions();
return Py_BuildNone();
}
void initchrmgr()
{
static PyMethodDef s_methods[] =
@@ -746,6 +752,7 @@ void initchrmgr()
{ "SetAffect", chrmgrSetAffect, METH_VARARGS },
{ "SetEmoticon", chrmgrSetEmoticon, METH_VARARGS },
{ "IsPossibleEmoticon", chrmgrIsPossibleEmoticon, METH_VARARGS },
{ "PreloadRaceMotions", chrmgrPreloadRaceMotions, METH_VARARGS },
{ "RegisterEffect", chrmgrRegisterEffect, METH_VARARGS },
{ "RegisterCacheEffect", chrmgrRegisterCacheEffect, METH_VARARGS },
{ "RegisterPointEffect", chrmgrRegisterPointEffect, METH_VARARGS },