00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTFAMILYGRAPH_H
00030 #define NVBLASTFAMILYGRAPH_H
00031
00032
00033 #include "NvBlastSupportGraph.h"
00034 #include "NvBlastFixedArray.h"
00035 #include "NvBlastFixedBitmap.h"
00036 #include "NvBlastFixedBoolArray.h"
00037 #include "NvBlastMath.h"
00038 #include "NvBlastFixedPriorityQueue.h"
00039 #include "NvBlastMemory.h"
00040
00041
00042 namespace Nv
00043 {
00044 namespace Blast
00045 {
00046
00047
00048 typedef uint32_t NodeIndex;
00049 typedef NodeIndex IslandId;
00050 typedef uint32_t ActorIndex;
00051
00058 class FamilyGraph
00059 {
00060 public:
00061
00063
00069 FamilyGraph(const SupportGraph* graph);
00070
00071
00080 static size_t requiredMemorySize(uint32_t nodeCount, uint32_t bondCount)
00081 {
00082 return fillMemory(nullptr, nodeCount, bondCount);
00083 }
00084
00085
00087
00094 void initialize(ActorIndex actorIndex, const SupportGraph* graph);
00095
00104 bool notifyEdgeRemoved(ActorIndex actorIndex, NodeIndex node0, NodeIndex node1, const SupportGraph* graph);
00105 bool notifyEdgeRemoved(ActorIndex actorIndex, NodeIndex node0, NodeIndex node1, uint32_t bondIndex, const SupportGraph* graph);
00106
00107 bool notifyNodeRemoved(ActorIndex actorIndex, NodeIndex nodeIndex, const SupportGraph* graph);
00108
00119 uint32_t findIslands(ActorIndex actorIndex, void* scratch, const SupportGraph* graph);
00120
00128 static size_t findIslandsRequiredScratch(uint32_t graphNodeCount);
00129
00130
00132
00139 NvBlastBlockData(IslandId, m_islandIdsOffset, getIslandIds);
00140
00144 NvBlastBlockData(NodeIndex, m_dirtyNodeLinksOffset, getDirtyNodeLinks);
00145
00149 NvBlastBlockData(uint32_t, m_firstDirtyNodeIndicesOffset, getFirstDirtyNodeIndices);
00150
00154 NvBlastBlockData(NodeIndex, m_fastRouteOffset, getFastRoute);
00155
00159 NvBlastBlockData(uint32_t, m_hopCountsOffset, getHopCounts);
00160
00164 NvBlastBlockData(FixedBoolArray, m_isEdgeRemovedOffset, getIsEdgeRemoved);
00165
00169 NvBlastBlockData(FixedBoolArray, m_isNodeInDirtyListOffset, getIsNodeInDirtyList);
00170
00171
00173
00174 uint32_t getEdgesCount(const SupportGraph* graph) const;
00175 bool hasEdge(NodeIndex node0, NodeIndex node1, const SupportGraph* graph) const;
00176 bool canFindRoot(NodeIndex startNode, NodeIndex targetNode, FixedArray<NodeIndex>* visitedNodes, const SupportGraph* graph);
00177
00178
00179 private:
00180
00181 FamilyGraph& operator = (const FamilyGraph&);
00182
00184
00188 struct TraversalState
00189 {
00190 NodeIndex mNodeIndex;
00191 uint32_t mCurrentIndex;
00192 uint32_t mPrevIndex;
00193 uint32_t mDepth;
00194
00195 TraversalState()
00196 {
00197 }
00198
00199 TraversalState(NodeIndex nodeIndex, uint32_t currentIndex, uint32_t prevIndex, uint32_t depth) :
00200 mNodeIndex(nodeIndex), mCurrentIndex(currentIndex), mPrevIndex(prevIndex), mDepth(depth)
00201 {
00202 }
00203 };
00204
00208 struct QueueElement
00209 {
00210 TraversalState* mState;
00211 uint32_t mHopCount;
00212
00213 QueueElement()
00214 {
00215 }
00216
00217 QueueElement(TraversalState* state, uint32_t hopCount) : mState(state), mHopCount(hopCount)
00218 {
00219 }
00220 };
00221
00225 struct NodeComparator
00226 {
00227 NodeComparator()
00228 {
00229 }
00230
00231 bool operator() (const QueueElement& node0, const QueueElement& node1) const
00232 {
00233 return node0.mHopCount < node1.mHopCount;
00234 }
00235 private:
00236 NodeComparator& operator = (const NodeComparator&);
00237 };
00238
00242 typedef FixedPriorityQueue<QueueElement, NodeComparator> NodePriorityQueue;
00243
00244
00246
00257 static size_t fillMemory(FamilyGraph* familyGraph, uint32_t nodeCount, uint32_t bondCount);
00258
00262 bool findRoute(NodeIndex startNode, NodeIndex targetNode, IslandId islandId, FixedArray<TraversalState>* visitedNodes, FixedBitmap* isNodeWitness, NodePriorityQueue* priorityQueue, const SupportGraph* graph);
00263
00267 bool tryFastPath(NodeIndex startNode, NodeIndex targetNode, IslandId islandId, FixedArray<TraversalState>* visitedNodes, FixedBitmap* isNodeWitness, const SupportGraph* graph);
00268
00274 void unwindRoute(uint32_t traversalIndex, NodeIndex lastNode, uint32_t hopCount, IslandId id, FixedArray<TraversalState>* visitedNodes);
00275
00279 void addToDirtyNodeList(ActorIndex actorIndex, NodeIndex node);
00280
00284 NodeIndex getAdjacentNode(uint32_t adjacencyIndex, const SupportGraph* graph) const
00285 {
00286 const uint32_t bondIndex = graph->getAdjacentBondIndices()[adjacencyIndex];
00287 return getIsEdgeRemoved()->test(bondIndex) ? invalidIndex<uint32_t>() : graph->getAdjacentNodeIndices()[adjacencyIndex];
00288 }
00289
00290 };
00291
00292
00293 }
00294 }
00295
00296
00297 #endif // ifndef NVBLASTFAMILYGRAPH_H