Jump to content

Map Area Heavy Effect Usage Fix


Distraught

Recommended Posts

  • Honorable Member

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 by Distraught
  • Good 1
  • Love 1
  • Love 42

WRnRW3H.gif

Link to comment
Share on other sites

  • Honorable Member
1 hour ago, hachiwari said:

hm what will happen if pInst is null? :P

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 by Distraught
  • Good 1

WRnRW3H.gif

Link to comment
Share on other sites

  • Forum Moderator
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"

  • Love 1

Gurgarath
coming soon

Link to comment
Share on other sites

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

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

  • Premium
1 hour ago, Kafa said:

 

I changed bitset to bool, but i dont know if this is correct.

 

???????

 

a02RTHD.png

 

Just place the includes in between Area.h and Timer.h, like @Gurgarath said.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 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

  • Honorable Member

gziY6fu.png

 

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 by Metin2 Dev
Core X - External 2 Internal

WRnRW3H.gif

Link to comment
Share on other sites

  • Honorable Member
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 by Distraught

WRnRW3H.gif

Link to comment
Share on other sites

  • Honorable Member
19 minutes ago, Minton said:
  Hide contents

4c8816dce71607e87c756e0eddf384e2.png1316f42a2b142f8e84cbb2ceebbd962a.png

7b2f5f9cf0c1f42fc7919118856e830c.png

 

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 by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 1
  • Love 1

WRnRW3H.gif

Link to comment
Share on other sites

  • Forum Moderator
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.

 

  • Love 2

Gurgarath
coming soon

Link to comment
Share on other sites

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

  • 1 month later...

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.