hkKdTreeBuilder.h
上传用户:yisoukefu
上传日期:2020-08-09
资源大小:39506k
文件大小:5k
源码类别:

其他游戏

开发平台:

Visual C++

  1. /* 
  2.  * 
  3.  * Confidential Information of Telekinesys Research Limited (t/a Havok). Not for disclosure or distribution without Havok's
  4.  * prior written consent. This software contains code, techniques and know-how which is confidential and proprietary to Havok.
  5.  * Level 2 and Level 3 source code contains trade secrets of Havok. Havok Software (C) Copyright 1999-2009 Telekinesys Research Limited t/a Havok. All Rights Reserved. Use of this software is subject to the terms of an end user license agreement.
  6.  * 
  7.  */
  8. #ifndef HK_KDTREE_BUILDER_H
  9. #define HK_KDTREE_BUILDER_H
  10. #include <Common/Base/hkBase.h>
  11. #include <Common/Internal/KdTree/hkKdTree.h>
  12. #include <Common/Internal/KdTree/Build/hkKdTreeBuildInput.h>
  13. #include <Common/Base/Thread/Semaphore/hkSemaphoreBusyWait.h>
  14. enum hkSplitPrimitivesStatus
  15. {
  16. SPLIT_PRIMITIVES_OK,
  17. SPLIT_PRIMITIVES_INDISTINGUISHABLE
  18. };
  19. template <typename ReadIter, typename WriteIter, const bool streaming>
  20. class hkKdTreeBuilder
  21. {
  22. public:
  23. struct SplitPrimitivesResults
  24. {
  25. HK_PAD_ON_SPU(int) m_splitAxis;
  26. HK_PAD_ON_SPU(int) m_splitIndex;
  27. HK_PAD_ON_SPU(hkSplitType) m_splitMin;
  28. HK_PAD_ON_SPU(hkSplitType) m_splitMax;
  29. };
  30. // Bucketed (fast) build
  31. static hkSplitPrimitivesStatus HK_CALL splitPrimitives( const hkKdTreeBuildInput::WorkingSet& buffersIn, int startPrimIdx, int endPrimIdx, SplitPrimitivesResults& results, 
  32. HK_PAD_ON_SPU(int)& numAvailableEmptyNodes, hkKdTreeBuildInput::WorkingSet& buffersOut, const hkKdTreeBuildInput::ProjectedEntry& bounds, hkVector4ComparisonParameter allowedEmptySplits);
  33. static int HK_CALL buildTreeRecursive( const hkKdTreeBuildInput::BuildRecursiveInput& input, hkKdTreeBuildInput::TreeStream* streamOut, hkKdTreeBuildInput::ProjectedEntry* peOut, HK_PAD_ON_SPU(int)& numAllocatedNodes, HK_PAD_ON_SPU(int)& numEmptyNodesRemaining);
  34. static void HK_CALL checkBuildRecursiveInput( const hkKdTreeBuildInput::BuildRecursiveInput& subJob );
  35. static hkSplitPrimitivesStatus HK_CALL splitPrimitivesExactly( const hkKdTreeBuildInput::WorkingSet& buffersIn, int startPrimIdx, int endPrimIdx, 
  36. SplitPrimitivesResults& results, hkKdTreeBuildInput::WorkingSet& buffersOut, const hkKdTreeBuildInput::ProjectedEntry& bounds );
  37. static void HK_CALL splitTreeBuilding( const hkKdTreeBuildInput::WorkingSet& buffersIn, hkKdTreeNode* treeOut, int treeSize, int numPrimitives,  hkKdTreeBuildInput::BuildRecursiveInput* subJobs, int subTreeSizes[4], const hkKdTreeBuildInput::ProjectedEntry& bounds );
  38. static void HK_CALL writeEmptyLeaf(hkKdTreeNode* treeRoot, int nodeIdx, class hkKdTreeBuilderSparseWriter* writer);
  39. static void HK_CALL writeSinglePrimitiveToLeaf(hkKdTreeNode* treeRoot, hkKdTreeBuildInput::ProjectedEntry* entriesIn, hkKdTreeBuildInput::ProjectedEntry* projEntOut, int nodeIdx, int primIdx, hkKdTreeBuilderSparseWriter* writer);
  40. // returns the number of tree nodes that are "saved" by writing out the multiple leaves. These can be added to the number of available free nodes.
  41. static int HK_CALL writeMultiplePrimitivesToLeaf(hkKdTreeNode* HK_RESTRICT treeRoot, const hkKdTreeBuildInput::ProjectedEntry* entriesIn, hkKdTreeBuildInput::ProjectedEntry* HK_RESTRICT projEntOut, int nodeIdx, int primIdx, int numPrims, hkKdTreeBuilderSparseWriter* writer);
  42. };
  43. // It's safe to add __restrict on the write iterators, since they're write-only.
  44. typedef const hkKdTreeBuildInput::ProjectedEntry* ProjectedEntryDirectReadIterator;
  45. typedef hkKdTreeBuildInput::ProjectedEntry* HK_RESTRICT ProjectedEntryDirectWriteIterator;
  46. typedef hkKdTreeBuilder< ProjectedEntryDirectReadIterator,    ProjectedEntryDirectWriteIterator, false> hkKdTreeBuilderDirect;
  47. // We never use this on non-SPU platforms, but putting it here helps keep the recursion code a bit cleaner
  48. typedef hkKdTreeBuilder< ProjectedEntryDirectReadIterator,    ProjectedEntryDirectWriteIterator, false> hkKdTreeBuilderStreaming;
  49. class hkKdTreeBuilderSparseWriter
  50. {
  51. public:
  52. hkKdTreeBuilderSparseWriter();
  53. // This ensures that the writes finish when the writer goes out of scope.
  54. ~hkKdTreeBuilderSparseWriter() { flush(); }
  55. void putNodeToMainMemory(hkKdTreeNode* root, int currentNodeIdx, hkKdTreeNode& node);
  56. void putProjEntToMainMemory(hkKdTreeBuildInput::ProjectedEntry* base, int peIdx, const hkKdTreeBuildInput::ProjectedEntry& peToWrite);
  57. enum { BUFFER_SIZE = 16 };
  58. protected:
  59. void flush();
  60. hkVector4 m_writeBuffer[ BUFFER_SIZE ];
  61. HK_PAD_ON_SPU(int) m_index;
  62. };
  63. #endif //HK_KDTREE_BUILDER_H
  64. /*
  65. * Havok SDK - NO SOURCE PC DOWNLOAD, BUILD(#20090216)
  66. * Confidential Information of Havok.  (C) Copyright 1999-2009
  67. * Telekinesys Research Limited t/a Havok. All Rights Reserved. The Havok
  68. * Logo, and the Havok buzzsaw logo are trademarks of Havok.  Title, ownership
  69. * rights, and intellectual property rights in the Havok software remain in
  70. * Havok and/or its suppliers.
  71. * Use of this software for evaluation purposes is subject to and indicates
  72. * acceptance of the End User licence Agreement for this product. A copy of
  73. * the license is included with this software and is also available at www.havok.com/tryhavok.
  74. */