Spatial Display and asynchronous updates for desktop Gui app
Okay, so we need to display a set of possibly moving objects in 2D on a top-down map.
As well as do hit-detection of the cursor against those entities.
Naturally, we need to draw them.
So we have a need to be able to quickly obtain a slice of them that intersect the viewbox of the 2D map, as well as detect which ones we are clicking on.
So, spatial-indexing is desired, hence the thought to have a QuadTree to organize them.
This would not be a thread-safe collection, and we would need to synchronize access to it.
Updates to this would come in from threads other than the main thread.
The main thread needs to read from the tree very often.
Which of the folowing approaches would be preferred:
1) Assert that the tree is a threaded object local to the main thread, thus any updates to the tree will be dispatched and executed on the main thread.
2) Have access to the QuadTree guarded through the use of reader writer locks, with threads contesting and taking these locks when needed.
I am very open to discussion and ideas about this - perhaps some of my assumptions here are wrong. :catfine:
As well as do hit-detection of the cursor against those entities.
Naturally, we need to draw them.
So we have a need to be able to quickly obtain a slice of them that intersect the viewbox of the 2D map, as well as detect which ones we are clicking on.
So, spatial-indexing is desired, hence the thought to have a QuadTree to organize them.
This would not be a thread-safe collection, and we would need to synchronize access to it.
Updates to this would come in from threads other than the main thread.
The main thread needs to read from the tree very often.
Which of the folowing approaches would be preferred:
1) Assert that the tree is a threaded object local to the main thread, thus any updates to the tree will be dispatched and executed on the main thread.
2) Have access to the QuadTree guarded through the use of reader writer locks, with threads contesting and taking these locks when needed.
I am very open to discussion and ideas about this - perhaps some of my assumptions here are wrong. :catfine:
