You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Currently, I have an unfinished BulkUpdate function due to a code block that I don’t know how to solve to be performance. -
What is the issue? Include screenshots / videos if possible!
Current the functions has 3 parameters, one for the self, 2 for the Objects and Positions. In the tree root, there is a table called ObjectsCache to holds all objects in the tree itself that has the value of the tree holding it.
The Objects are not order, so I would iterate backward for every Object I would get the Tree that the object in through ObjectsCache so ObjectsCache[Object], now the tree that holding the Object also has another folder called Objects. I would then use a hash table to compare the Objects parameter and the Objects Tree to see if any Objects in parameter is present in the Objects Tree. Then remove it from the Object’s parameter, hence why I iterated backward.
I did this so that I can: stop getting the same tree for other object that has the same tree, deal with a batch of Objects presented in the Object’s parameter that in the same Objects Tree. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I still don’t know how to do it efficiently, so I am reconsidering re structuring the tree, but that might break another thing, so I’ll put this as the last thing to do.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
export type self = {
Level: number,
MaxCapacity: number,
Min: Vector3,
Max: Vector3,
CurrentCapacity: number,
ObjectsCache: { [any]: self }?,
Objects: { [any]: Vector3 },
Parent: self,
NW: self,
NE: self,
SW: self,
SE: self,
}
local Quadtree = {}
function Quadtree.BulkUpdate(self: self, Objects: { any }, Positions: { Vector3 })
local ObjectsCache = self.ObjectsCache :: { [any]: self }
for Index = #Objects, 1, -1 do
local Value = Objects[Index]
local SubTree = ObjectsCache[Value]
local SubTreeObjects = SubTree.Objects
-- somehow do a hashtable on a dict with an array to remove the overhead of calling SubTree everytime and also do it in a batch if there any other object that has the same SubTree
end
end
I hope my explanation is at least understandable, I would gladly appreciate any helps.