removed preload motions
This commit is contained in:
@@ -534,7 +534,7 @@ void CGraphicThingInstance::RegisterMotionThing(DWORD dwMotionKey, CGraphicThing
|
||||
{
|
||||
CGraphicThing::TRef * pMotionRef = new CGraphicThing::TRef;
|
||||
pMotionRef->SetPointer(pMotionThing);
|
||||
m_roMotionThingMap.insert(std::make_pair(dwMotionKey, pMotionRef));
|
||||
m_roMotionThingMap.insert(std::map<DWORD, CGraphicThing::TRef *>::value_type(dwMotionKey, pMotionRef));
|
||||
}
|
||||
|
||||
void CGraphicThingInstance::ResetLocalTime()
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
bool CRaceManager::s_bPreloaded = false;
|
||||
|
||||
bool __IsGuildRace(unsigned race)
|
||||
{
|
||||
if (race >= 14000 && race < 15000)
|
||||
@@ -491,173 +489,3 @@ CRaceManager::~CRaceManager()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void CRaceManager::PreloadPlayerRaceMotions()
|
||||
{
|
||||
if (s_bPreloaded)
|
||||
return;
|
||||
|
||||
CRaceManager& rkRaceMgr = CRaceManager::Instance();
|
||||
|
||||
for (DWORD dwRace = 0; dwRace <= 7; ++dwRace)
|
||||
{
|
||||
TRaceDataIterator it = rkRaceMgr.m_RaceDataMap.find(dwRace);
|
||||
if (it == rkRaceMgr.m_RaceDataMap.end())
|
||||
{
|
||||
CRaceData* pRaceData = rkRaceMgr.__LoadRaceData(dwRace);
|
||||
if (pRaceData)
|
||||
{
|
||||
rkRaceMgr.m_RaceDataMap.insert(TRaceDataMap::value_type(pRaceData->GetRaceIndex(), pRaceData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::set<CGraphicThing*> uniqueMotions;
|
||||
|
||||
for (DWORD dwRace = 0; dwRace <= 7; ++dwRace)
|
||||
{
|
||||
CRaceData* pRaceData = NULL;
|
||||
TRaceDataIterator it = rkRaceMgr.m_RaceDataMap.find(dwRace);
|
||||
if (it != rkRaceMgr.m_RaceDataMap.end())
|
||||
pRaceData = it->second;
|
||||
|
||||
if (!pRaceData)
|
||||
continue;
|
||||
|
||||
CRaceData::TMotionModeDataIterator itor;
|
||||
if (pRaceData->CreateMotionModeIterator(itor))
|
||||
{
|
||||
do
|
||||
{
|
||||
CRaceData::TMotionModeData* pMotionModeData = itor->second;
|
||||
for (auto& itorMotion : pMotionModeData->MotionVectorMap)
|
||||
{
|
||||
const CRaceData::TMotionVector& c_rMotionVector = itorMotion.second;
|
||||
for (const auto& motion : c_rMotionVector)
|
||||
{
|
||||
if (motion.pMotion)
|
||||
uniqueMotions.insert(motion.pMotion);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (pRaceData->NextMotionModeIterator(itor));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<CGraphicThing*> motionVec(uniqueMotions.begin(), uniqueMotions.end());
|
||||
size_t total = motionVec.size();
|
||||
|
||||
if (total > 0)
|
||||
{
|
||||
CGameThreadPool* pThreadPool = CGameThreadPool::InstancePtr();
|
||||
if (pThreadPool && pThreadPool->IsInitialized())
|
||||
{
|
||||
size_t workerCount = pThreadPool->GetWorkerCount();
|
||||
size_t chunkSize = (total + workerCount - 1) / workerCount;
|
||||
|
||||
std::vector<std::future<void>> futures;
|
||||
futures.reserve(workerCount);
|
||||
|
||||
for (size_t i = 0; i < workerCount; ++i)
|
||||
{
|
||||
size_t start = i * chunkSize;
|
||||
size_t end = std::min(start + chunkSize, total);
|
||||
|
||||
if (start < end)
|
||||
{
|
||||
// Copy values instead of capturing by reference
|
||||
futures.push_back(pThreadPool->Enqueue([start, end, motionVec]() {
|
||||
for (size_t k = start; k < end; ++k)
|
||||
{
|
||||
motionVec[k]->AddReference();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for all tasks to complete
|
||||
for (auto& f : futures)
|
||||
{
|
||||
f.wait();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback to sequential if thread pool not available
|
||||
for (auto* pMotion : motionVec)
|
||||
{
|
||||
pMotion->AddReference();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_bPreloaded = true;
|
||||
}
|
||||
|
||||
void CRaceManager::RequestAsyncRaceLoad(DWORD dwRaceIndex)
|
||||
{
|
||||
// Mark as loading
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_LoadingRacesMutex);
|
||||
if (m_LoadingRaces.find(dwRaceIndex) != m_LoadingRaces.end())
|
||||
{
|
||||
// Already loading
|
||||
return;
|
||||
}
|
||||
m_LoadingRaces.insert(dwRaceIndex);
|
||||
}
|
||||
|
||||
// Enqueue async load to game thread pool
|
||||
CGameThreadPool* pThreadPool = CGameThreadPool::InstancePtr();
|
||||
if (pThreadPool)
|
||||
{
|
||||
pThreadPool->Enqueue([this, dwRaceIndex]()
|
||||
{
|
||||
CRaceData* pRaceData = __LoadRaceData(dwRaceIndex);
|
||||
|
||||
if (pRaceData)
|
||||
{
|
||||
// Thread-safe insertion
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_RaceDataMapMutex);
|
||||
m_RaceDataMap.insert(TRaceDataMap::value_type(dwRaceIndex, pRaceData));
|
||||
}
|
||||
|
||||
Tracef("CRaceManager::RequestAsyncRaceLoad: Successfully loaded race %lu asynchronously\n", dwRaceIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
TraceError("CRaceManager::RequestAsyncRaceLoad: Failed to load race %lu", dwRaceIndex);
|
||||
}
|
||||
|
||||
// Remove from loading set
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_LoadingRacesMutex);
|
||||
m_LoadingRaces.erase(dwRaceIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback to synchronous loading if thread pool not available
|
||||
CRaceData* pRaceData = __LoadRaceData(dwRaceIndex);
|
||||
|
||||
if (pRaceData)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_RaceDataMapMutex);
|
||||
m_RaceDataMap.insert(TRaceDataMap::value_type(dwRaceIndex, pRaceData));
|
||||
}
|
||||
|
||||
// Remove from loading set
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_LoadingRacesMutex);
|
||||
m_LoadingRaces.erase(dwRaceIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CRaceManager::IsRaceLoading(DWORD dwRaceIndex) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_LoadingRacesMutex);
|
||||
return m_LoadingRaces.find(dwRaceIndex) != m_LoadingRaces.end();
|
||||
}
|
||||
|
||||
@@ -31,14 +31,6 @@ class CRaceManager : public CSingleton<CRaceManager>
|
||||
|
||||
BOOL GetRaceDataPointer(DWORD dwRaceIndex, CRaceData ** ppRaceData);
|
||||
|
||||
// Async race loading
|
||||
void RequestAsyncRaceLoad(DWORD dwRaceIndex);
|
||||
bool IsRaceLoading(DWORD dwRaceIndex) const;
|
||||
|
||||
// Race motion preloading
|
||||
static void PreloadPlayerRaceMotions();
|
||||
static bool IsPreloaded() { return s_bPreloaded; }
|
||||
|
||||
protected:
|
||||
CRaceData* __LoadRaceData(DWORD dwRaceIndex);
|
||||
bool __LoadRaceMotionList(CRaceData& rkRaceData, const char* pathName, const char* motionListFileName);
|
||||
@@ -59,5 +51,4 @@ class CRaceManager : public CSingleton<CRaceManager>
|
||||
private:
|
||||
std::string m_strPathName;
|
||||
CRaceData * m_pSelectedRaceData;
|
||||
static bool s_bPreloaded;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -713,12 +713,6 @@ 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[] =
|
||||
@@ -752,7 +746,6 @@ 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 },
|
||||
|
||||
Reference in New Issue
Block a user