| 1 |
#ifndef _ISPACE_PARTITION_H_ |
| 2 |
#define _ISPACE_PARTITION_H_ |
| 3 |
|
| 4 |
#include <list> |
| 5 |
#include <vector> |
| 6 |
#include "imodule.h" |
| 7 |
|
| 8 |
// Forward declaration |
| 9 |
class AABB; |
| 10 |
|
| 11 |
namespace scene |
| 12 |
{ |
| 13 |
|
| 14 |
// Some forward declarations to avoid including all the headers |
| 15 |
class INode; |
| 16 |
typedef std::shared_ptr<INode> INodePtr; |
| 17 |
|
| 18 |
class ISPNode; |
| 19 |
typedef std::shared_ptr<ISPNode> ISPNodePtr; |
| 20 |
typedef std::weak_ptr<ISPNode> ISPNodeWeakPtr; |
| 21 |
|
| 22 |
/** |
| 23 |
* greebo: This is the abstract definition of a SpacePartition node. |
| 24 |
* |
| 25 |
* A SpacePartition node has the following properties: |
| 26 |
* |
| 27 |
* - It always has valid bounds (in the form of an AABB). |
| 28 |
* - Each node can have any amount of children [0..infinity) |
| 29 |
* - A node with 0 children is called a Leaf. |
| 30 |
* - Each node can have exactly one parent (which is NULL for the root node). |
| 31 |
* - The collectivity of nodes form a tree whereas the topmost one is the largest. |
| 32 |
* - Each node can host any amount of "members" (member == scene::INode). |
| 33 |
* |
| 34 |
* It is the task of the ISpacePartitionSystem to allocate and manage these nodes. |
| 35 |
* scene::INodes are "linked" to the correct ISPNodes through the ISPacePartition's |
| 36 |
* link() methods - and are unlinked through the unlink() method of the latter. |
| 37 |
*/ |
| 38 |
class ISPNode |
| 39 |
{ |
| 40 |
public: |
| 41 |
virtual ~ISPNode() {} |
| 42 |
|
| 43 |
// The child nodes |
| 44 |
typedef std::vector<ISPNodePtr> NodeList; |
| 45 |
|
| 46 |
// The members |
| 47 |
typedef std::list<INodePtr> MemberList; |
| 48 |
|
| 49 |
// Get the parent node (can be NULL for the root node) |
| 50 |
virtual ISPNodePtr getParent() const = 0; |
| 51 |
|
| 52 |
// The maximum bounds of this node |
| 53 |
virtual const AABB& getBounds() const = 0; |
| 54 |
|
| 55 |
// The child nodes of this node (either 8 or 0) |
| 56 |
virtual const NodeList& getChildNodes() const = 0; |
| 57 |
|
| 58 |
// Returns true if no more child nodes are below this one |
| 59 |
virtual bool isLeaf() const = 0; |
| 60 |
|
| 61 |
// Get a list of members |
| 62 |
virtual const MemberList& getMembers() const = 0; |
| 63 |
}; |
| 64 |
typedef std::shared_ptr<ISPNode> ISPNodePtr; |
| 65 |
|
| 66 |
/** |
| 67 |
* greebo: The SpacePartitionSystem interface is a simple one. All it needs |
| 68 |
* to do is to provide link/unlink methods for linking scene::INodes |
| 69 |
* into the space partition system and to deliver the "entry point" for traversal, |
| 70 |
* which is the root ISPNode. |
| 71 |
* |
| 72 |
* The link() method makes sure the given node is added as member to the ISPNode it fits best. |
| 73 |
* The unlink() method can be used to remove a node from the tree again. |
| 74 |
* |
| 75 |
* Note: It's not allowed to call link() for nodes which are already linked into the tree. |
| 76 |
* It's safe to call unlink() for any node at any time, even multiple times in a row. |
| 77 |
* The unlink() method will return true if the node had been linked before. |
| 78 |
*/ |
| 79 |
class ISpacePartitionSystem |
| 80 |
{ |
| 81 |
public: |
| 82 |
virtual ~ISpacePartitionSystem() {} |
| 83 |
|
| 84 |
// Links this node into the SP tree. Returns the node it ends up being associated with |
| 85 |
virtual void link(const scene::INodePtr& sceneNode) = 0; |
| 86 |
|
| 87 |
// Unlink this node from the SP tree, returns true if this was successful |
| 88 |
// (node had been linked before) |
| 89 |
virtual bool unlink(const scene::INodePtr& sceneNode) = 0; |
| 90 |
|
| 91 |
// Returns the root node of this SP tree (the largest one, encompassing everything) |
| 92 |
virtual ISPNodePtr getRoot() const = 0; |
| 93 |
}; |
| 94 |
typedef std::shared_ptr<ISpacePartitionSystem> ISpacePartitionSystemPtr; |
| 95 |
|
| 96 |
} // namespace scene |
| 97 |
|
| 98 |
#endif /* _ISPACE_PARTITION_H_ */ |