Jump to content
×
×
  • Create New...

Map Area Heavy Effect Usage Fix


Recommended Posts

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
  • Love 37
  • Good 1

WRnRW3H.gif

Link to comment
Share on other sites

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

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 Syreldar
  • 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

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

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

WRnRW3H.gif

Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


  • Activity

    1. 36

      Destroy Item System

    2. 1

      Brillances

    3. 0

      Fusion.org is Looking for Staff Members

    4. 1

      Brillances

    5. 3

      ELONIA2 | PVM-MEDIUM | 11 LANGUAGES | INTERNATIONAL | A NEW STORY

    6. 4

      Spider Queen not spawining in spider dungeon v1

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.