if I have a dictionary, and it uses
dictionary = { [x,y]:object, [x,y]:object, [x,y]:object}
how do I return only objects whose x,y are less than 20 in distance from
[int(own.worldPosition.x),int(own.worldPosition.y)]
?
as efficiently as possible (there are a lot of tiles) as a list?
(I guess it does not have to be that efficient if I store a ‘Close List’ in each tile, over time)
starting near the player and working away…
1000h
(1000h)
February 8, 2016, 9:22pm
2
when i try that i get unhashable type having a list as a key, how did you get around that?
Mobious
(Mobious)
February 8, 2016, 9:29pm
3
You should use a KD Tree. There’s already a simple implementation provided in the mathutils module. There’s even a find_range method that does exactly what you want. Note that it’s a 3-dimentional tree, so you’ll have to provide an arbitrary Z value if you’re only worried about objects in a 2D plane.
I got it working using list.sorted() but it uses way too much resources
I think the way to go is ->
Generate maze ->
Store maze as KD tree
Remove maze except closest X units
Add units in and remove units as I move using KD tree and manage a list
(lamp hooks) while doing so.
I will attempt to make the KD tree tonight.
Edit: KDTree is what I needed for another problem as well!
editing a mesh vertex data in a object without using polyProxy !
Attachments
controllingWallPhysicsObjectsPlacementAndLamps.blend (872 KB)