forked from metin-server/m2dev-client-src
removed preload motions
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user