Jump to content

Sectree memory


Recommended Posts

  • Premium

the sectree in metin2 is scary and not even the old korean wizards know what the fuck is happening over there so I took a deep breath and started to change some stuff around. While doing so I found something strange, after around 2.5-5k mobs the ram is exploding and its getting extremely laggy. I noticed that every `server-source/game/src/entiy.h` -> `CEntity` has its own

`ENTITY_MAP m_map_view;`

But what is a ENTITY_MAP? In short, it's a container of every currently-visible entity. This is useful to see things but has a small issue: every entity sees every entity in proximity. In other words: the amount of currently tracked entities is growing exponentially.

1 mob -> 0 entries
2 mobs -> 1 entry per mob / 2 entries
3 mobs -> 2 entries per mob / 6 entries
4 mobs -> 3 entries per mob / 12 entries
2500 mobs -> 2499 entries per mob / 6247500 entries

This is not good, but we have to see things, we can't just remove it completely. Introducing, my pseudo fix:

search for `CFuncViewInsert` in `server-source/game/src/entity_view.cpp`
my change would be to avoid calling `m_me->ViewInsert(ent);` every time, so it would look something like that


This is the hidden content, please


We check if both entities are of the "character" type and if so we cast them to `LPCHARACTERS`.
If the current view is of a player, he has to see everything
if the current view is of a NPC, he has to see only players

This fix has some issues, with newer versions of the game there are a few mobs that heal each other - I haven't tested those neither have I tested this change throughout, but I'm fairly certain that it will work. If there is a problem you could add a type/subtype check or even hardcode the vnums since I think that there are only a handful of NPCs that have to see other NPCs (i.e. jotun)

good luck




Thanks to everyone from sura-head.


esp. @CYN3 and  @HelloBrightness ( Amas ).

Edited by LTGT
added correct link to users
  • Metin2 Dev 99
  • kekw 2
  • Eyes 2
  • Dislove 2
  • Sad 1
  • Cry 1
  • Think 2
  • Good 20
  • Love 6
  • Love 24

🍆 Sura-Head 💯

Link to comment
Share on other sites

  • 1 month later...

Did this a while ago after noticing freak memory usage, I recommend you add these checks as well for more optimization:


			else if (m_me->IsType(ENTITY_ITEM) && ent->IsType(ENTITY_ITEM))
				//NOTE: no item to item insert
			else if (m_me->IsType(ENTITY_ITEM) && ent->IsType(ENTITY_CHARACTER) && !ent->GetDesc())
				//NOTE: no item to NPC insert
			else if (m_me->IsType(ENTITY_CHARACTER) && !m_me->GetDesc() && ent->IsType(ENTITY_ITEM))
				//NOTE: no NPC to item insert


  • Metin2 Dev 1
  • Love 1
  • Love 1
Link to comment
Share on other sites

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