From 144dddb518ba76d03ec7193082cf5e378383f4f6 Mon Sep 17 00:00:00 2001 From: savis <106487343+savisxss@users.noreply.github.com> Date: Wed, 7 Jan 2026 15:22:32 +0100 Subject: [PATCH] removed preload motions --- src/EterGrnLib/ThingInstance.cpp | 2 +- src/GameLib/RaceManager.cpp | 172 ------------------ src/GameLib/RaceManager.h | 11 +- .../PythonCharacterManagerModule.cpp | 7 - 4 files changed, 2 insertions(+), 190 deletions(-) diff --git a/src/EterGrnLib/ThingInstance.cpp b/src/EterGrnLib/ThingInstance.cpp index 765c4bf..a418584 100644 --- a/src/EterGrnLib/ThingInstance.cpp +++ b/src/EterGrnLib/ThingInstance.cpp @@ -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::value_type(dwMotionKey, pMotionRef)); } void CGraphicThingInstance::ResetLocalTime() diff --git a/src/GameLib/RaceManager.cpp b/src/GameLib/RaceManager.cpp index 306a4cb..de67957 100644 --- a/src/GameLib/RaceManager.cpp +++ b/src/GameLib/RaceManager.cpp @@ -8,8 +8,6 @@ #include #include -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 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 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> 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 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 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 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 lock(m_RaceDataMapMutex); - m_RaceDataMap.insert(TRaceDataMap::value_type(dwRaceIndex, pRaceData)); - } - - // Remove from loading set - { - std::lock_guard lock(m_LoadingRacesMutex); - m_LoadingRaces.erase(dwRaceIndex); - } - } -} - -bool CRaceManager::IsRaceLoading(DWORD dwRaceIndex) const -{ - std::lock_guard lock(m_LoadingRacesMutex); - return m_LoadingRaces.find(dwRaceIndex) != m_LoadingRaces.end(); -} diff --git a/src/GameLib/RaceManager.h b/src/GameLib/RaceManager.h index e2e5f27..efcbaa8 100644 --- a/src/GameLib/RaceManager.h +++ b/src/GameLib/RaceManager.h @@ -31,14 +31,6 @@ class CRaceManager : public CSingleton 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 private: std::string m_strPathName; CRaceData * m_pSelectedRaceData; - static bool s_bPreloaded; -}; \ No newline at end of file +}; diff --git a/src/UserInterface/PythonCharacterManagerModule.cpp b/src/UserInterface/PythonCharacterManagerModule.cpp index e1d6690..5549755 100644 --- a/src/UserInterface/PythonCharacterManagerModule.cpp +++ b/src/UserInterface/PythonCharacterManagerModule.cpp @@ -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 },