Jump to content

Recommended Posts

  • Honorable Member

Hi everyone,

During some profiling today, I noticed that a significant amount of time in the Update process is being used to determine the z position of characters.

This is primarily because we currently have to iterate through all the collisions to verify their height.

getheight-before.png

 

By default, there’s another method available that utilizes caching, so we don’t have to repeatedly perform these calculations. Unfortunately, this method wasn’t used.

We’ll be updating our code to take advantage of the cached version.

 

First, go to MapManager.h in GameLib.

Find

float					GetHeight(float fx, float fy);

and add after:

float					GetCacheHeight(float fx, float fy);

 

Now, go to MapManager.cpp and add the following code somewhere:

float CMapManager::GetCacheHeight(float fx, float fy)
{
	if (!m_pkMap)
		return 0.0f;
  
	CMapOutdoor& rkMap = GetMapOutdoorRef();
	return rkMap.GetCacheHeight(fx, fy);
}

 

Now go to InstanceBase.cpp in UserInterface and find the CInstanceBase::__GetBackgroundHeight function.

Modify it:

float CInstanceBase::__GetBackgroundHeight(float x, float y)
{
	CPythonBackground& rkBG=CPythonBackground::Instance();
	return rkBG.GetCacheHeight(x, y);
}

That's all, we're done.

 

Here is how our flame graph looks like now:

getheight-after.png

 

I hope, it helped!

Edited by Metin2 Dev International
Core X - External 2 Internal
  • Metin2 Dev 6
  • Good 1
  • Love 1
  • Love 13

992404397646696589.png
Former C++ Developer at Gameloft on DML
Join my Discord: Distraught Labs

Link to comment
https://metin2.dev/topic/33123-small-optimization-for-getting-the-height/
Share on other sites

  • Honorable Member
42 minutes ago, Denizeri24 said:

thats will create 'stutter' problem for higher fps.

What do you mean by that?

We're using this for days, and nobody noticed any problem. Literally it's just caching the values that has already been calculated.

  • Love 1

992404397646696589.png
Former C++ Developer at Gameloft on DML
Join my Discord: Distraught Labs

6 minutes ago, Distraught said:

What do you mean by that?

We're using this for days, and nobody noticed any problem. Literally it's just caching the values that has already been calculated.

no. cache vector is small so its caching precision is not good.

 

if you play like 240 fps, height updates will stutter. its look like warping..

  • Lmao 1
  • 1 month later...

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • 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.