Skip to content

fix(points): grid inconsistencies#37

Merged
antond15 merged 2 commits intoCommunityOx:mainfrom
D4isDAVID:points-fixes
Aug 10, 2025
Merged

fix(points): grid inconsistencies#37
antond15 merged 2 commits intoCommunityOx:mainfrom
D4isDAVID:points-fixes

Conversation

@D4isDAVID
Copy link

@D4isDAVID D4isDAVID commented Aug 8, 2025

  • Fix memory constantly going up when having any points.
    Currently, the points thread creates a new filter function every loop iteration and passes it to lib.grid.getNearbyEntries, which would break caching, as the filter function would be different every iteration.
    This PR fixes this by creating a local function, and passing it instead, meaning it wouldn't be created over and over, and it would be properly cached.

  • Fix onExit not firing when both exiting a point and moving grid cells in the same loop iteration, when onEnter isn't set.
    When moving grid cells, the points thread uses point.inside to check whether to run onExit. However, point.inside is only set when onEnter is defined.
    This PR fixes this by setting point.inside even when onEnter isn't defined.

Fixes #20.

@thelindat
Copy link

thelindat commented Aug 8, 2025

A single point can only be on a single cell, yet a min/max X/Y is calculated.

If the radius of the point is larger than the cell size then the point can span multiple cells.

@D4isDAVID
Copy link
Author

@thelindat From my understanding, points are already inserted into all the appropriate cells in lib.grid.addEntry, are they not? That means when using lib.grid.getNearbyEntries you only need the current cell, as the point would already be included.

@D4isDAVID
Copy link
Author

Ah, I guess what I wrote is actually confusing. The parameter for getNearbyEntries is called point, but it's just a vector position. I meant a single position can only have one single grid cell.

@thelindat
Copy link

thelindat commented Aug 8, 2025

The purpose of getNearbyEntries is to get entries in the current and surrounding cells, not strictly the current cell. Whether that's necessary depends on the exact use-case, and it's not very sensible to outright change the behaviour.

It's redundant in the case of points due to their own distance checks, but that's not strictly what the grid is for.

@D4isDAVID
Copy link
Author

That makes sense. I'll revert it.

Copy link
Member

@antond15 antond15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR

@antond15 antond15 merged commit a9648fb into CommunityOx:main Aug 10, 2025
@D4isDAVID D4isDAVID deleted the points-fixes branch August 10, 2025 00:22
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.

[Bug] onExit not works when player teleporting

4 participants