Jump to content

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 (see edit history)
  • Love 32

AxgtRfG.png
C++ programmer at Gameloft

Link to post
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 (see edit history)
  • Good 1

AxgtRfG.png
C++ programmer at Gameloft

Link to post

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 post
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 post
  • Developer
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 (see edit history)
  • Love 1

👑 Premium International Lua Developer 👑

 My service topic: https://bit.ly/2UPly54

 

Ignorant people have the obligation to compensate their ignorance by paying whoever helps them.

Syreldar

Link to post
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 (see edit history)

AxgtRfG.png
C++ programmer at Gameloft

Link to post
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 (see edit history)

AxgtRfG.png
C++ programmer at Gameloft

Link to post
  • Engineer
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
Link to post
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 post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



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