Honorable Member Distraught 5895 Posted December 16, 2020 Honorable Member Share Posted December 16, 2020 (edited) Our mapper made a map with really-really a lot of effects on it. Some of our testers mentioned that the game started to lag for them on that map so much. I checked it in debug mode and actually the FPS dropped to actually 0. I started to profile the game what could be the bottleneck and so that I found the effects. When the game is dealing with effects for maps most of the time went in CMapOutdoor::RenderEffect. In this function it calls RenderEffects for each Area around you (that is 9 normally if you're not on some edge area). In the Area's render effect somewhy they did the effect update (but why?) and that took the most of time. We didn't wanna make the map less beautiful so I fixed it in the code. Now the game only updates and renders effects that are around your character and are not in the fog zone. With this we brought back our FPS to normal and we can have maps with a lot of effects too. First, open EffectLib/EffectInstance.h and add this to CEffectInstance class: const D3DXMATRIX& GetGlobalMatrix() const { return m_matGlobal; }; Now go to GameLib/Area.cpp and add these to the includes #include "../UserInterface/StdAfx.h" #include "../UserInterface/PythonCharacterManager.h" #include "../UserInterface/PythonBackground.h" Now modify CArea::__UpdateEffectList function to look like this void CArea::__UpdateEffectList() { int peNum; float pfStart, pfEnd, pfFarClip; D3DXVECTOR3 chrPos; CPythonBackground::instance().GetDistanceSetInfo(&peNum, &pfStart, &pfEnd, &pfFarClip); CInstanceBase* pInst = CPythonCharacterManager::instance().GetMainInstancePtr(); if (!pInst) return; chrPos = pInst->GetGraphicThingInstanceRef().GetPosition(); CEffectManager& rkEftMgr=CEffectManager::Instance(); TEffectInstanceIterator i; for (i = m_EffectInstanceMap.begin(); i != m_EffectInstanceMap.end();) { CEffectInstance * pEffectInstance = i->second; const D3DMATRIX& gMatrix = pEffectInstance->GetGlobalMatrix(); if (pfStart < GetPixelPositionDistance(chrPos, TPixelPosition(gMatrix._41, gMatrix._42, gMatrix._43))) { pEffectInstance->Hide(); ++i; continue; } pEffectInstance->Show(); pEffectInstance->Update(); if (!pEffectInstance->isAlive()) { i = m_EffectInstanceMap.erase(i); rkEftMgr.DestroyUnsafeEffectInstance(pEffectInstance); } else { ++i; } } } Hope you guys like it and will be useful! Edited September 15, 2021 by Distraught 1 1 42 Link to comment Share on other sites More sharing options...
ImPerial 1 Posted December 16, 2020 Share Posted December 16, 2020 Thanks @Distraught 1 Link to comment Share on other sites More sharing options...
Forum Moderator Gurgarath 2511 Posted December 16, 2020 Forum Moderator Share Posted December 16, 2020 This there is an insanely useful fix, congrats 1 Gurgarath coming soon Link to comment Share on other sites More sharing options...
Matteo 46 Posted December 16, 2020 Share Posted December 16, 2020 As always, good job! Thank you! 1 System Administrator @ Hungarian Government System Administrator @ Vibestro Freelancer Developer @ Various projects Link to comment Share on other sites More sharing options...
Active Member hachiwari 138 Posted December 17, 2020 Active Member Share Posted December 17, 2020 hm what will happen if pInst is null? GetPixelPositionDistance method is save for null? Link to comment Share on other sites More sharing options...
Honorable Member Distraught 5895 Posted December 17, 2020 Author Honorable Member Share Posted December 17, 2020 (edited) 1 hour ago, hachiwari said: hm what will happen if pInst is null? GetPixelPositionDistance method is save for null? In that case this would be the smallest problem. But just for the code design we can fairly afford to skip updating the effects in that frame. I edited the code. Edited December 17, 2020 by Distraught 1 Link to comment Share on other sites More sharing options...
Hik 108 Posted December 17, 2020 Share Posted December 17, 2020 Error (active) E0266 ambiguous "byte" Error C2872 'bitset': ambiguous symbol Visual Studio 2019 :/ Link to comment Share on other sites More sharing options...
Forum Moderator Gurgarath 2511 Posted December 17, 2020 Forum Moderator Share Posted December 17, 2020 1 minute ago, Hik said: Error (active) E0266 ambiguous "byte" Error C2872 'bitset': ambiguous symbol Visual Studio 2019 :/ Reorganize include order, place them above "Area.h" and below "Timer.h" 1 Gurgarath coming soon Link to comment Share on other sites More sharing options...
Hik 108 Posted December 17, 2020 Share Posted December 17, 2020 Same error #include "../SpeedTreeLib/SpeedTreeForestDirectX8.h" #include "../eterBase/Timer.h" #ifdef Map_Area_Heavy_Effect_Usage_Fix //non spostarlo da qua o comunque tenerlo sempre sopra Area.h e sotto Timer.h #include "../UserInterface/StdAfx.h" #include "../UserInterface/PythonCharacterManager.h" #include "../UserInterface/PythonBackground.h" #endif #include "Area.h" #include "PropertyManager.h" Link to comment Share on other sites More sharing options...
Kafa 153 Posted December 17, 2020 Share Posted December 17, 2020 8 minutes ago, Hik said: Same error #include "../SpeedTreeLib/SpeedTreeForestDirectX8.h" #include "../eterBase/Timer.h" #ifdef Map_Area_Heavy_Effect_Usage_Fix //non spostarlo da qua o comunque tenerlo sempre sopra Area.h e sotto Timer.h #include "../UserInterface/StdAfx.h" #include "../UserInterface/PythonCharacterManager.h" #include "../UserInterface/PythonBackground.h" #endif #include "Area.h" #include "PropertyManager.h" I changed bitset to bool, but i dont know if this is correct. Link to comment Share on other sites More sharing options...
Premium Syreldar 1873 Posted December 17, 2020 Premium Share Posted December 17, 2020 (edited) 1 hour ago, Kafa said: I changed bitset to bool, but i dont know if this is correct. ??????? Just place the includes in between Area.h and Timer.h, like @Gurgarath said. Edited August 25, 2022 by Metin2 Dev Core X - External 2 Internal 1 "Nothing's free in this life. Ignorant people have an obligation to make up for their ignorance by paying those who help them. Either you got the brains or cash, if you lack both you're useless." Syreldar Link to comment Share on other sites More sharing options...
Hik 108 Posted December 17, 2020 Share Posted December 17, 2020 (edited) Like this, no? https://metin2.download/picture/G66TkY4Jh23B38QLXxGx2w0Fc8Ru3Py0/.png Edited September 4, 2022 by Metin2 Dev Core X - External 2 Internal 4 1 Link to comment Share on other sites More sharing options...
Honorable Member Distraught 5895 Posted December 17, 2020 Author Honorable Member Share Posted December 17, 2020 (edited) For me they are after other includes but as @Gurgarath and @Syreldar said it should work the way they said. What platform toolset are you using? I'm not sure about this but maybe that could possible cause this. Edited August 25, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Hik 108 Posted December 17, 2020 Share Posted December 17, 2020 Toolset V142. I made this change and it compiled. Do you think this is okay? byte *pInstanceData ----> to ----> BYTE *pInstanceData byte *pPropData ----> to ----> BYTE *pPropData Link to comment Share on other sites More sharing options...
Honorable Member Distraught 5895 Posted December 17, 2020 Author Honorable Member Share Posted December 17, 2020 (edited) 1 minute ago, Hik said: Toolset V142. I made this change and it compiled. Do you think this is okay? byte *pInstanceData ----> to ----> BYTE *pInstanceData byte *pPropData ----> to ----> BYTE *pPropData I don't know where you did that but I'm quite sure they are both defined as unsigned char so yes. Edited December 17, 2020 by Distraught Link to comment Share on other sites More sharing options...
Hik 108 Posted December 17, 2020 Share Posted December 17, 2020 The "byte" error is reported to me in the Strmif.h file. That's where I made the changes. If I find any errors I will report them, thanks everyone for the help Link to comment Share on other sites More sharing options...
Matteo 46 Posted December 17, 2020 Share Posted December 17, 2020 (edited) Spoiler v142 toolset, 10.0 sdk, c++17 works well. Edited August 25, 2022 by Metin2 Dev Core X - External 2 Internal 1 System Administrator @ Hungarian Government System Administrator @ Vibestro Freelancer Developer @ Various projects Link to comment Share on other sites More sharing options...
Honorable Member Distraught 5895 Posted December 17, 2020 Author Honorable Member Share Posted December 17, 2020 (edited) 19 minutes ago, Minton said: Hide contents v142 toolset, 10.0 sdk, c++17 works well. I suggest putting the includes in Area.cpp because those classes are only used there. If you can I suggest avoiding includes in headers because that makes the compilation much slower. You only have to include a header if you want to instantiate a class there or use any of its member variables or functions (or you want to know the size of it); otherwise you can predeclare the class (eg. if you just wanna have pointers to it or references) like class ClassName;. Edited August 25, 2022 by Metin2 Dev Core X - External 2 Internal 1 1 Link to comment Share on other sites More sharing options...
Forum Moderator Gurgarath 2511 Posted December 17, 2020 Forum Moderator Share Posted December 17, 2020 53 minutes ago, Hik said: The "byte" error is reported to me in the Strmif.h file. That's where I made the changes. If I find any errors I will report them, thanks everyone for the help I would warn you however not to do ANY change into the platform related includes, it can backslash at any moment, even though the change is minimal, you don't know what it can break. For me it only happened when I misplaced the includes. 2 Gurgarath coming soon Link to comment Share on other sites More sharing options...
Hik 108 Posted December 17, 2020 Share Posted December 17, 2020 1 hour ago, Gurgarath said: I would warn you however not to do ANY change into the platform related includes, it can backslash at any moment, even though the change is minimal, you don't know what it can break. For me it only happened when I misplaced the includes. Maybe it is better to restore the code, I would not like to have problems in the future that I am not able to solve. Link to comment Share on other sites More sharing options...
szotyizz 61 Posted February 2, 2021 Share Posted February 2, 2021 (edited) Hello. Someone? Edited August 25, 2022 by Metin2 Dev Core X - External 2 Internal 1 Link to comment Share on other sites More sharing options...
Recommended Posts