Lehona / LeGo

A daedalus library for the game Gothic. It contains various packages to support modders.
19 stars 7 forks source link

Improve `Talents.Npc_FindByID` to stop on first occurence of ID #31

Closed kirides closed 3 years ago

kirides commented 3 years ago

Currently Npc_FindByID looks at every single NPC to find a specific talent id, even if the found id (which should be unique) is found after just a few iterations.

I propose we alter the code for Npc_FindByID to stop iterating as soon as we found the first matching NPC with said ID.

grafik

Before the change, every single buff that would use Buff_GetNpc would look at > 700 NPCs, even though just 10-15 iterations (optimally) were enough.

That, combined with having skills that target multiple NPCs (e.g. Firerain proccing many buffs, each summoned creature having a buff) could previously lead to significant stutter.

In a test on my machine, this code improved the performance for 24 summons (3x army of darkness, all summoned creatures having a buff that uses Buff_GetNpc) from 40-45 FPS and stuttering every 1000ms, to 55-60 fps and no stuttering.

Lehona commented 3 years ago

That's an embarrassing oversight by me, would you be so kind and create a PR? :)

kirides commented 3 years ago

Sure, would you want the proposed change, or remove the function calls alltogether and combine it all into one?