diff --git a/src/EterLib/ResourceManager.cpp b/src/EterLib/ResourceManager.cpp index b25355a..4c572f2 100644 --- a/src/EterLib/ResourceManager.cpp +++ b/src/EterLib/ResourceManager.cpp @@ -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(); } diff --git a/src/GameLib/MapOutdoorRender.cpp b/src/GameLib/MapOutdoorRender.cpp index 5438b7a..15c964b 100644 --- a/src/GameLib/MapOutdoorRender.cpp +++ b/src/GameLib/MapOutdoorRender.cpp @@ -40,7 +40,8 @@ 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 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 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) { diff --git a/src/UserInterface/InstanceBase.h b/src/UserInterface/InstanceBase.h index cf2418a..02ab491 100644 --- a/src/UserInterface/InstanceBase.h +++ b/src/UserInterface/InstanceBase.h @@ -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); diff --git a/src/UserInterface/InstanceBaseBattle.cpp b/src/UserInterface/InstanceBaseBattle.cpp index ba810ed..eb8cfcc 100644 --- a/src/UserInterface/InstanceBaseBattle.cpp +++ b/src/UserInterface/InstanceBaseBattle.cpp @@ -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(); diff --git a/src/UserInterface/PythonCharacterManager.cpp b/src/UserInterface/PythonCharacterManager.cpp index 1e0ac34..9edaf23 100644 --- a/src/UserInterface/PythonCharacterManager.cpp +++ b/src/UserInterface/PythonCharacterManager.cpp @@ -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);