Is it possible to get the rendering rectangle by some position? Something like
Code: Select all
local id = surface.get_rendering (position, mod_name)
Code: Select all
local id = surface.get_rendering (position, mod_name)
Those would all be O(N) operations. Just store the IDs you make when you tell the game to draw them.eradicator wrote: Sat Aug 17, 2019 1:59 am I have to admit that it would be quite nice to not have to remember all ids ever used in global but instead be able to retrieve them from the world somehow. Though i think for me it would me most useful to get a) renderings attached to a specific LuaEntity and b) only retrieve ids of renderings that the calling mod created itself.
So are LuaSurface.find_entities_filtered operations i presume. And i *do* store my entity references and render IDs i create (obviously, as that's currently the only possible way to do it). But sometimes in non-performance-critical applications it would reduce mod-side code complexity if i didn't *have* to. It's imho a typical "if it was in base game mods wouldn't have to reinvent the wheel" situation.Rseding91 wrote: Sun Aug 18, 2019 4:39 amThose would all be O(N) operations. Just store the IDs you make when you tell the game to draw them.eradicator wrote: Sat Aug 17, 2019 1:59 am I have to admit that it would be quite nice to not have to remember all ids ever used in global but instead be able to retrieve them from the world somehow. Though i think for me it would me most useful to get a) renderings attached to a specific LuaEntity and b) only retrieve ids of renderings that the calling mod created itself.
Yes, that is what the C++ would be doing. Which is why it's not a thing: It's not only O(n), the operation that that to be done for every n is also pretty expensive.darkfrei wrote: Sun Aug 18, 2019 8:42 am So if i have the rendering.rectangle somewhere on the map, but I know the position (or connected entity), then the best way is to scan all rendering objects, check them if they are rectangles, get the corners for this rectangles and check if the input position is inside of this rectangle?
Yes, I need to check that they are on the same surface.
Nope, the "best" way to do this, for the most common values of best, is using a tree structure to index the space for efficiently locating the device -- typically a variant of an R-tree, a BSP-derived tree like a k-d tree or quadtree, or maybe if you are feeling really exotic, some other structure using exotic space filling hibbert curves, or something. Since you have very limited search requirements a k-d tree should sort you right out, though, and is the easiest of those to implement. (Index surface as a Z dimension if you really can't limit your range to even same-surface indexes.)darkfrei wrote: Sun Aug 18, 2019 8:42 am So if i have the rendering.rectangle somewhere on the map, but I know the position (or connected entity), then the best way is to scan all rendering objects, check them if they are rectangles, get the corners for this rectangles and check if the input position is inside of this rectangle?
Yes, I need to check that they are on the same surface.