forked from metin-server/m2dev-client-src
enable async loading, optimize rendering and distance checks
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "ResourceManager.h"
|
||||
#include "GrpImage.h"
|
||||
|
||||
int g_iLoadingDelayTime = 20;
|
||||
int g_iLoadingDelayTime = 1; // Reduced from 20ms to 1ms for faster async loading
|
||||
|
||||
const long c_Deleting_Wait_Time = 30000; // 삭제 대기 시간 (30초)
|
||||
const long c_DeletingCountPerFrame = 30; // 프레임당 체크 리소스 갯수
|
||||
@@ -16,6 +16,21 @@ const long c_Reference_Decrease_Wait_Time = 30000; // 선로딩 리소스의 해
|
||||
|
||||
CFileLoaderThread CResourceManager::ms_loadingThread;
|
||||
|
||||
void CResourceManager::BeginThreadLoading()
|
||||
{
|
||||
// Already started in constructor, nothing to do
|
||||
}
|
||||
|
||||
void CResourceManager::EndThreadLoading()
|
||||
{
|
||||
// Wait for all pending requests to complete
|
||||
while (!m_RequestMap.empty() || !m_WaitingMap.empty())
|
||||
{
|
||||
ProcessBackgroundLoading();
|
||||
Sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
void CResourceManager::LoadStaticCache(const char* c_szFileName)
|
||||
{
|
||||
CResource* pkRes=GetResourcePointer(c_szFileName);
|
||||
@@ -514,11 +529,11 @@ void CResourceManager::ReserveDeletingResource(CResource * pResource)
|
||||
|
||||
CResourceManager::CResourceManager()
|
||||
{
|
||||
//ms_loadingThread.Create(0);
|
||||
ms_loadingThread.Create(0);
|
||||
}
|
||||
|
||||
CResourceManager::~CResourceManager()
|
||||
{
|
||||
Destroy();
|
||||
//ms_loadingThread.Shutdown();
|
||||
ms_loadingThread.Shutdown();
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ void CMapOutdoor::RenderTerrain()
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Push
|
||||
m_PatchVector.clear();
|
||||
m_PatchVector.reserve(256); // Pre-allocate to avoid reallocations
|
||||
|
||||
__RenderTerrain_RecurseRenderQuadTree(m_pRootNode);
|
||||
|
||||
@@ -491,6 +492,7 @@ void CMapOutdoor::RenderArea(bool bRenderAmbience)
|
||||
{
|
||||
static std::vector<CGraphicThingInstance*> s_kVct_pkOpaqueThingInstSort;
|
||||
s_kVct_pkOpaqueThingInstSort.clear();
|
||||
s_kVct_pkOpaqueThingInstSort.reserve(512); // Pre-allocate to avoid reallocations
|
||||
|
||||
for (int i = 0; i < AROUND_AREA_NUM; ++i)
|
||||
{
|
||||
@@ -522,6 +524,7 @@ void CMapOutdoor::RenderBlendArea()
|
||||
|
||||
static std::vector<CGraphicThingInstance*> s_kVct_pkBlendThingInstSort;
|
||||
s_kVct_pkBlendThingInstSort.clear();
|
||||
s_kVct_pkBlendThingInstSort.reserve(256); // Pre-allocate to avoid reallocations
|
||||
|
||||
for (int i = 0; i < AROUND_AREA_NUM; ++i)
|
||||
{
|
||||
|
||||
@@ -640,6 +640,7 @@ class CInstanceBase
|
||||
float NEW_GetDistanceFromDirPixelPosition(const TPixelPosition& c_rkPPosDir);
|
||||
float NEW_GetDistanceFromDestPixelPosition(const TPixelPosition& c_rkPPosDst);
|
||||
float NEW_GetDistanceFromDestInstance(CInstanceBase& rkInstDst);
|
||||
float NEW_GetDistanceFromDestInstanceSquared(CInstanceBase& rkInstDst); // Optimized: no sqrt
|
||||
|
||||
float NEW_GetRotation();
|
||||
float NEW_GetRotationFromDestPixelPosition(const TPixelPosition& c_rkPPosDst);
|
||||
|
||||
@@ -91,6 +91,19 @@ float CInstanceBase::NEW_GetDistanceFromDirPixelPosition(const TPixelPosition& c
|
||||
return sqrtf(c_rkPPosDir.x*c_rkPPosDir.x+c_rkPPosDir.y*c_rkPPosDir.y);
|
||||
}
|
||||
|
||||
// Optimized: Get squared distance (avoid sqrt for comparisons)
|
||||
float CInstanceBase::NEW_GetDistanceFromDestInstanceSquared(CInstanceBase& rkInstDst)
|
||||
{
|
||||
TPixelPosition kPPosDst;
|
||||
rkInstDst.NEW_GetPixelPosition(&kPPosDst);
|
||||
|
||||
TPixelPosition kPPosCur;
|
||||
NEW_GetPixelPosition(&kPPosCur);
|
||||
|
||||
TPixelPosition kPPosDir = kPPosDst - kPPosCur;
|
||||
return kPPosDir.x * kPPosDir.x + kPPosDir.y * kPPosDir.y;
|
||||
}
|
||||
|
||||
float CInstanceBase::NEW_GetRotation()
|
||||
{
|
||||
float fCurRot=GetRotation();
|
||||
|
||||
@@ -178,8 +178,10 @@ void CPythonCharacterManager::Update()
|
||||
continue;
|
||||
}
|
||||
|
||||
int nDistance = int(pkInstEach->NEW_GetDistanceFromDestInstance(*pkInstMain));
|
||||
if (nDistance > CHAR_STAGE_VIEW_BOUND + 10)
|
||||
// Optimized: Use squared distance to avoid sqrt
|
||||
float fDistanceSquared = pkInstEach->NEW_GetDistanceFromDestInstanceSquared(*pkInstMain);
|
||||
const float fViewBoundSquared = (CHAR_STAGE_VIEW_BOUND + 10) * (CHAR_STAGE_VIEW_BOUND + 10);
|
||||
if (fDistanceSquared > fViewBoundSquared)
|
||||
{
|
||||
__DeleteBlendOutInstance(pkInstEach);
|
||||
m_kAliveInstMap.erase(c);
|
||||
|
||||
Reference in New Issue
Block a user