Skip to content

Conversation

@Gamemechanicwow
Copy link
Contributor

🍰 Pullrequest

Optimizes GetContinentInstanceId() by precalculating boundaries needed to do early returns.

Example of existing lines that are used to calculated ContinentInstanceId:
image
(Crude mock up. Boundary lines might be off)

Image of orc/troll starting zone, with its own continentinstanceid - show with lines that indicate boundaries and their early return values
image

Test show high potential for performance gains
image

Test explained:

  • loaded all positions from creature table in map 0/1
  • made a vector with all positions repeated 50 times
  • timed old function
  • timed new function
  • after timing; a 2nd iteration was done verifying that the new and old implementation returned the same value for all coords in the vector

Notes:
Could use better codeformatting.
Maybe better naming of structs, vars etc.

Alternative solution
Remove struct and makeboundary - and just add the boundary as constants to function call:
if (IsNorthTo(x, y, topNorthSouthBoundary, yyy, YYY, xxx, XXX))
return MAP0_TOP_NORTH;
Upside: less code needed.
Downside: if someone is to edit limits, they also manually need to update the numbers in the function call

Proof

  • None

Issues

  • None

How2Test

  • None

Todo / Checklist

  • Better code formatting
  • Better naming
  • Code comments

@ratkosrb
Copy link
Contributor

Why move those to the header file? They are not used outside the file. No need to expose them. Also now if anyone edits the boundaries it will recompile most of the core because it's in a header.

@Gamemechanicwow Gamemechanicwow marked this pull request as draft June 18, 2025 00:06
@Gamemechanicwow
Copy link
Contributor Author

Ye, from that perspective I guess it makes sense to keep them in the .cpp file.

I have moved the constants to the .cpp file. Also marked this PR as a draft, since there might be an edgecase with the orgrimmar boundary. It's a small area that doesn't contain any creatures, so my initial test didn't catch it.

@Gamemechanicwow
Copy link
Contributor Author

  • Added a better check for when a player is further north than the most northen point in the boundary line.
  • All poly lines now go from east to west. The first Y coordinate must be less than the last Y coordinate. Added comment and assert to document this new restriction

Diagram showing the 3 types of early outs:

image

1 - Player is more south than the most southern point in the boundary line, so the player can't be in this area
2 - Player is to the east or west of the boundary.
3 - Player is above the boundary. We know that boundaries are checked from south to north, so we don't have to worry about the player being in a different boundary. So if the player position is between the starting and end position of the boundary he is in this instance.

@Gamemechanicwow Gamemechanicwow marked this pull request as ready for review June 27, 2025 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants