From 30ff18e98221d5d2d07c7ca5a1e4db567be99ae8 Mon Sep 17 00:00:00 2001 From: d1str4ught <> Date: Fri, 30 Jan 2026 03:29:58 +0100 Subject: [PATCH] helping branch prediction --- src/EffectLib/EffectInstance.cpp | 2 +- src/EffectLib/EffectManager.cpp | 13 ++- src/EffectLib/ParticleSystemInstance.cpp | 6 +- src/EterGrnLib/Deform.cpp | 4 +- src/EterLib/GrpTextInstance.cpp | 6 +- src/UserInterface/AbstractApplication.h | 1 - src/UserInterface/InstanceBase.cpp | 2 - src/UserInterface/PythonApplication.cpp | 84 ++----------------- src/UserInterface/PythonApplication.h | 2 - src/UserInterface/PythonApplicationCamera.cpp | 6 -- src/UserInterface/PythonCharacterManager.cpp | 20 ++--- 11 files changed, 28 insertions(+), 118 deletions(-) diff --git a/src/EffectLib/EffectInstance.cpp b/src/EffectLib/EffectInstance.cpp index b542378..da35248 100644 --- a/src/EffectLib/EffectInstance.cpp +++ b/src/EffectLib/EffectInstance.cpp @@ -71,7 +71,7 @@ struct FEffectUpdator } void operator () (CEffectElementBaseInstance * pInstance) { - if (pInstance->Update(fElapsedTime)) + if (pInstance->Update(fElapsedTime)) [[likely]] isAlive = TRUE; } }; diff --git a/src/EffectLib/EffectManager.cpp b/src/EffectLib/EffectManager.cpp index 2037c39..011f293 100644 --- a/src/EffectLib/EffectManager.cpp +++ b/src/EffectLib/EffectManager.cpp @@ -67,16 +67,13 @@ void CEffectManager::Update() pEffectInstance->Update(/*fElapsedTime*/); - if (!pEffectInstance->isAlive()) - { - itor = m_kEftInstMap.erase(itor); - - CEffectInstance::Delete(pEffectInstance); - } - else - { + if (pEffectInstance->isAlive()) [[likely]] { ++itor; + continue; } + + itor = m_kEftInstMap.erase(itor); + CEffectInstance::Delete(pEffectInstance); } } diff --git a/src/EffectLib/ParticleSystemInstance.cpp b/src/EffectLib/ParticleSystemInstance.cpp index 7b20f2c..b7a25d2 100644 --- a/src/EffectLib/ParticleSystemInstance.cpp +++ b/src/EffectLib/ParticleSystemInstance.cpp @@ -300,15 +300,13 @@ bool CParticleSystemInstance::OnUpdate(float fElapsedTime) { CParticleInstance * pInstance = *itor; - if (!pInstance->Update(fElapsedTime,fAngularVelocity)) - { + if (!pInstance->Update(fElapsedTime,fAngularVelocity)) [[unlikely]] { pInstance->DeleteThis(); itor = m_ParticleInstanceListVector[dwFrameIndex].erase(itor); m_dwCurrentEmissionCount--; } - else - { + else [[likely]] { if (pInstance->m_byFrameIndex != dwFrameIndex) { m_ParticleInstanceListVector[dwFrameCount+pInstance->m_byFrameIndex].push_back(*itor); diff --git a/src/EterGrnLib/Deform.cpp b/src/EterGrnLib/Deform.cpp index fd9b3b7..1fbd1ab 100644 --- a/src/EterGrnLib/Deform.cpp +++ b/src/EterGrnLib/Deform.cpp @@ -144,10 +144,10 @@ void DeformPWNT3432toGrannyPNGBT33332(granny_int32x Count, void const* SourceIni granny_int32x const* TransformTable, granny_matrix_4x4 const* Transforms, granny_int32x CopySize, granny_int32x SourceStride, granny_int32x DestStride) { - if (TransformTable) { + if (TransformTable) [[likely]] { DeformPWNT3432toGrannyPNGBT33332I(Count, SourceInit, DestInit, TransformTable, Transforms, CopySize, SourceStride, DestStride); } - else { + else [[unlikely]] { DeformPWNT3432toGrannyPNGBT33332D(Count, SourceInit, DestInit, Transforms, CopySize, SourceStride, DestStride); } } diff --git a/src/EterLib/GrpTextInstance.cpp b/src/EterLib/GrpTextInstance.cpp index 214a0a8..b576b48 100644 --- a/src/EterLib/GrpTextInstance.cpp +++ b/src/EterLib/GrpTextInstance.cpp @@ -591,8 +591,7 @@ void CGraphicTextInstance::Render(RECT * pClipRect) fFontHeight=float(pCurCharInfo->height); fFontAdvance=float(pCurCharInfo->advance); - if ((fCurX+fFontWidth)-m_v3Position.x > m_fLimitWidth) - { + if ((fCurX+fFontWidth)-m_v3Position.x > m_fLimitWidth) [[unlikely]] { if (m_isMultiLine) { fCurX=fStanX; @@ -693,8 +692,7 @@ void CGraphicTextInstance::Render(RECT * pClipRect) fFontMaxHeight=(std::max)(fFontHeight, (float)pCurCharInfo->height); fFontAdvance=float(pCurCharInfo->advance); - if ((fCurX+fFontWidth)-m_v3Position.x > m_fLimitWidth) - { + if ((fCurX + fFontWidth) - m_v3Position.x > m_fLimitWidth) [[unlikely]] { if (m_isMultiLine) { fCurX=fStanX; diff --git a/src/UserInterface/AbstractApplication.h b/src/UserInterface/AbstractApplication.h index 5b01fdb..47aff70 100644 --- a/src/UserInterface/AbstractApplication.h +++ b/src/UserInterface/AbstractApplication.h @@ -36,7 +36,6 @@ class IAbstractApplication : public TAbstractSingleton virtual float GetGlobalTime() = 0; virtual float GetGlobalElapsedTime() = 0; - virtual void SkipRenderBuffering(DWORD dwSleepMSec) = 0; virtual void SetServerTime(time_t tTime) = 0; virtual void SetCenterPosition(float fx, float fy, float fz) = 0; diff --git a/src/UserInterface/InstanceBase.cpp b/src/UserInterface/InstanceBase.cpp index ca9205d..ca709ea 100644 --- a/src/UserInterface/InstanceBase.cpp +++ b/src/UserInterface/InstanceBase.cpp @@ -718,8 +718,6 @@ bool CInstanceBase::__FindRaceType(DWORD dwRace, BYTE* pbType) bool CInstanceBase::Create(const SCreateData& c_rkCreateData) { - IAbstractApplication::GetSingleton().SkipRenderBuffering(300); - SetInstanceType(c_rkCreateData.m_bType); diff --git a/src/UserInterface/PythonApplication.cpp b/src/UserInterface/PythonApplication.cpp index fe40388..0e64143 100644 --- a/src/UserInterface/PythonApplication.cpp +++ b/src/UserInterface/PythonApplication.cpp @@ -256,11 +256,6 @@ void CPythonApplication::UpdateGame() SetCenterPosition(kPPosMainActor.x, kPPosMainActor.y, kPPosMainActor.z); } -void CPythonApplication::SkipRenderBuffering(DWORD dwSleepMSec) -{ - m_dwBufSleepSkipTime=ELTimer_GetMSec()+dwSleepMSec; -} - bool CPythonApplication::Process() { ELTimer_SetFrameMSec(); @@ -275,8 +270,7 @@ bool CPythonApplication::Process() static UINT s_uiLoad = 0; static DWORD s_dwCheckTime = ELTimer_GetMSec(); - if (ELTimer_GetMSec() - s_dwCheckTime > 1000) - { + if (ELTimer_GetMSec() - s_dwCheckTime > 1000) [[unlikely]] { m_dwUpdateFPS = s_dwUpdateFrameCount; m_dwRenderFPS = s_dwRenderFrameCount; m_dwLoad = s_uiLoad; @@ -329,8 +323,7 @@ bool CPythonApplication::Process() #endif // Mouse POINT Point; - if (GetCursorPos(&Point)) - { + if (GetCursorPos(&Point)) [[likely]] { ScreenToClient(m_hWnd, &Point); OnMouseMove(Point.x, Point.y); } @@ -531,14 +524,11 @@ bool CPythonApplication::Process() bool canRender = true; - if (m_isMinimizedWnd) - { + if (m_isMinimizedWnd) [[unlikely]] { canRender = false; } - else - { - if (m_pyGraphic.IsLostDevice()) - { + else [[likely]] { + if (m_pyGraphic.IsLostDevice()) [[unlikely]] { CPythonBackground& rkBG = CPythonBackground::Instance(); rkBG.ReleaseCharacterShadowTexture(); @@ -549,22 +539,11 @@ bool CPythonApplication::Process() } } - if (!IsActive()) - { - SkipRenderBuffering(3000); - } - - // ¸®½ºÅä¾î 󸮶§¸¦ °í·ÁÇØ ÀÏÁ¤ ½Ã°£µ¿¾ÈÀº ¹öÆÛ¸µÀ» ÇÏÁö ¾Ê´Â´Ù - if (!canRender) - { - SkipRenderBuffering(3000); - } - else + if (canRender) [[likely]] { // RestoreLostDevice CCullingManager::Instance().Update(); - if (m_pyGraphic.Begin()) - { + if (m_pyGraphic.Begin()) [[likely]] { m_pyGraphic.ClearDepthBuffer(); @@ -597,8 +576,7 @@ bool CPythonApplication::Process() s_dwRenderRangeTime += m_dwCurRenderTime; ++s_dwRenderRangeFrame; - if (dwRenderEndTime-s_dwRenderCheckTime>1000) - { + if (dwRenderEndTime-s_dwRenderCheckTime>1000) [[unlikely]] { m_fAveRenderTime=float(double(s_dwRenderRangeTime)/double(s_dwRenderRangeFrame)); s_dwRenderCheckTime=ELTimer_GetMSec(); @@ -612,52 +590,6 @@ bool CPythonApplication::Process() if (dwCurFaceCount > 5000) { - // ÇÁ·¹ÀÓ ¿ÏÃæ ó¸® - if (dwRenderEndTime > m_dwBufSleepSkipTime) - { - static float s_fBufRenderTime = 0.0f; - - float fCurRenderTime = m_dwCurRenderTime; - - if (fCurRenderTime > s_fBufRenderTime) - { - float fRatio = fMAX(0.5f, (fCurRenderTime - s_fBufRenderTime) / 30.0f); - s_fBufRenderTime = (s_fBufRenderTime * (100.0f - fRatio) + (fCurRenderTime + 5) * fRatio) / 100.0f; - } - else - { - float fRatio = 0.5f; - s_fBufRenderTime = (s_fBufRenderTime * (100.0f - fRatio) + fCurRenderTime * fRatio) / 100.0f; - } - - // ÇѰèÄ¡¸¦ Á¤ÇÑ´Ù - if (s_fBufRenderTime > 100.0f) - s_fBufRenderTime = 100.0f; - - DWORD dwBufRenderTime = s_fBufRenderTime; - - if (m_isWindowed) - { - if (dwBufRenderTime>58) - dwBufRenderTime=64; - else if (dwBufRenderTime>42) - dwBufRenderTime=48; - else if (dwBufRenderTime>26) - dwBufRenderTime=32; - else if (dwBufRenderTime>10) - dwBufRenderTime=16; - else - dwBufRenderTime=8; - } - - // ÀÏÁ¤ ÇÁ·¹ÀÓ ¼Óµµ¿¡ ¸ÂÃß¾îÁÖ´ÂÂÊ¿¡ ´«¿¡ ÆíÇÏ´Ù - // ¾Æ·¡¿¡¼­ Çѹø ÇÏ¸é ‰ç´? - //if (m_dwCurRenderTimeMoveVertical(m_kCmrPos.m_fUpDir); - ////////////////////// - - if (pMainCamera->IsDraging()) - SkipRenderBuffering(3000); - - ////////////////////// // Sound Setting const D3DXVECTOR3 & c_rv3CameraDirection = pMainCamera->GetView(); const D3DXVECTOR3 & c_rv3CameraUp = pMainCamera->GetUp(); diff --git a/src/UserInterface/PythonCharacterManager.cpp b/src/UserInterface/PythonCharacterManager.cpp index 1bb16bd..21b9211 100644 --- a/src/UserInterface/PythonCharacterManager.cpp +++ b/src/UserInterface/PythonCharacterManager.cpp @@ -172,8 +172,7 @@ void CPythonCharacterManager::Update() if (pkInstMain) { - if (pkInstEach->IsForceVisible()) - { + if (pkInstEach->IsForceVisible()) [[unlikely]] { dwForceVisibleInstCount++; continue; } @@ -181,8 +180,7 @@ void CPythonCharacterManager::Update() // 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) - { + if (fDistanceSquared > fViewBoundSquared) [[unlikely]] { __DeleteBlendOutInstance(pkInstEach); m_kAliveInstMap.erase(c); dwDeadInstCount++; @@ -342,12 +340,10 @@ void CPythonCharacterManager::UpdateDeleting() { CInstanceBase * pInstance = *itor; - if (pInstance->UpdateDeleting()) - { + if (pInstance->UpdateDeleting()) [[likely]] { ++itor; } - else - { + else [[unlikely]] { CInstanceBase::Delete(pInstance); itor = m_kDeadInstList.erase(itor); } @@ -473,7 +469,7 @@ void CPythonCharacterManager::__RenderSortedAliveActorList() s_kVct_pkInstAliveSort.clear(); CCamera* pCamera = CCameraManager::instance().GetCurrentCamera(); - if (!pCamera) + if (!pCamera) [[unlikely]] return; TCharacterInstanceMap& rkMap_pkInstAlive=m_kAliveInstMap; @@ -495,7 +491,7 @@ void CPythonCharacterManager::__RenderSortedDeadActorList() s_kVct_pkInstDeadSort.clear(); CCamera* pCamera = CCameraManager::instance().GetCurrentCamera(); - if (!pCamera) + if (!pCamera) [[unlikely]] return; TCharacterInstanceList& rkLst_pkInstDead=m_kDeadInstList; @@ -575,13 +571,13 @@ void CPythonCharacterManager::RenderCollision() CInstanceBase * CPythonCharacterManager::CreateInstance(const CInstanceBase::SCreateData& c_rkCreateData) { CInstanceBase * pCharacterInstance = RegisterInstance(c_rkCreateData.m_dwVID); - if (!pCharacterInstance) + if (!pCharacterInstance) [[unlikely]] { TraceError("CPythonCharacterManager::CreateInstance: VID[%d] - ALREADY EXIST\n", c_rkCreateData); return NULL; } - if (!pCharacterInstance->Create(c_rkCreateData)) + if (!pCharacterInstance->Create(c_rkCreateData)) [[unlikely]] { TraceError("CPythonCharacterManager::CreateInstance VID[%d] Race[%d]", c_rkCreateData.m_dwVID, c_rkCreateData.m_dwRace); DeleteInstance(c_rkCreateData.m_dwVID);