Opened 11 years ago

Closed 10 years ago

#2016 closed enhancement (wontfix)

[PATCH] Adaptive quadtree

Reported by: Don Owned by:
Priority: Should Have Milestone:
Component: Core engine Keywords: patch
Cc: Patch:

Description

This is a templated adaptive quadtree class. It comes with its own memory pool, and has minimal entanglement with the game object it contains.

Once the quadtree is reviewed, it would be trivial work to submit a patch for an octree class as well. Then developers will be free to try either one, or both.

Attachments (1)

quadtree.diff (34.8 KB ) - added by Don 11 years ago.
Contains updated quadtree code, plus an octree with almost identical interface.

Download all attachments as: .zip

Change History (9)

comment:1 by Don, 11 years ago

Type: defectenhancement

comment:2 by Jorma Rebane, 11 years ago

  • Memory pool implementation. We have been working on a general solution for 0 A.D. already that doesn't require fixing pointers if the pool is out of memory. To make transition easier you should replace the allocation routines with new/delete.
  • I know that having a 2D array m_Child[2][2] seems like a good idea, but for a Quadtree the preferred solution is to have 4 variables: NW, NE, SW, SE. Why? This lets us unroll the loops and actually speeds up the code a lot.

by Don, 11 years ago

Attachment: quadtree.diff added

Contains updated quadtree code, plus an octree with almost identical interface.

comment:3 by Don, 11 years ago

Updated patch is now attached. (Wow. Where did my summer go?)

The CQuadtree class now uses new/delete, which can be replaced by calls to our memory pool any time.

The power-of-two bug is fixed.

Unrolling the loops didn't improve performance in my tests (which involved creating a large-ish quadtree, filling it with game objects and removing them, times 10,000), perhaps because the compiler is doing so already. So I went with the more concise original code.

The patch includes a COctree class that works in three dimensions. Other developers can enjoy the argument over which is better.

There was a suggestion in the forum that I hook one of these new classes into CCmpRangeManager. I did look over CCmpRangeManager, but it would take a lot of study before I could modify it. Better to submit the patch now, so it's in the hands of someone else who understands the game better.

comment:4 by sanderd17, 11 years ago

A remark: you seem to use an other commenting style than the one described in  http://trac.wildfiregames.com/wiki/Coding_Conventions#Documentation. This probably won't work with doxygen (http://svn.wildfiregames.com/docs/annotated.html).

Apart from that, it looks quite good, although I'm no c(pp) specialist. I'd like to have it in quite soon, so it's easier to use in other work like optimizing the RangeManager.

comment:5 by Jorma Rebane, 11 years ago

Don's commenting style follows Doxygen guidelines. See http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html

It is true however that 0AD codebase mainly uses Javadoc style commenting, so /* * @note ... */ instead of /*! \note ...*/. I wouldn't really worry about it though. The comments can stay as they are, since they're perfectly valid Doxygen.

As for the octree - I don't see any reason why we would ever need it.

Last edited 11 years ago by Jorma Rebane (previous) (diff)

comment:6 by Jorma Rebane, 11 years ago

Keywords: reviewed added; review removed

Hi Don, I've gotten back to patch reviewing.

Since A14 is going to be released, we can start working on A15 changeset and I really want to see your Quadtree implementation in A15.

I'll incorporate it into the build as soon as the feature lock on A14 is lifted and we move on to A15.

comment:7 by historic_bruno, 11 years ago

Milestone: Alpha 15Alpha 16

Judging by discussions in IRC, a generic quadtree doesn't really help us and each class of problem will need a different design (quadtree may not even be the best design for said problem). So I'm bumping to A16 and we can think about it again later.

comment:8 by historic_bruno, 10 years ago

Keywords: reviewed removed
Milestone: Alpha 16
Resolution: wontfix
Status: newclosed

As this isn't really in a committable form by itself, I'm going to close the ticket, but link to the forum discussion: http://www.wildfiregames.com/forum/index.php?showtopic=17384

That topic also cross-references this ticket, so if anyone wants to analyze a particular problem were quadtrees might help, they will hopefully be able to find both as a useful starting point :)

Note: See TracTickets for help on using tickets.