sceneContainer.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  23. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  24. // Copyright (C) 2015 Faust Logic, Inc.
  25. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  26. #ifndef _SCENECONTAINER_H_
  27. #define _SCENECONTAINER_H_
  28. #ifndef _MBOX_H_
  29. #include "math/mBox.h"
  30. #endif
  31. #ifndef _MSPHERE_H_
  32. #include "math/mSphere.h"
  33. #endif
  34. #ifndef _TVECTOR_H_
  35. #include "core/util/tVector.h"
  36. #endif
  37. #ifndef _MPOLYHEDRON_H_
  38. #include "math/mPolyhedron.h"
  39. #endif
  40. #ifndef _SIMOBJECT_H_
  41. #include "console/simObject.h"
  42. #endif
  43. #ifndef _SCENEOBJECT_H_
  44. #include "scene/sceneObject.h"
  45. #endif
  46. /// @file
  47. /// SceneObject database.
  48. class SceneObject;
  49. class AbstractPolyList;
  50. class OptimizedPolyList;
  51. class Frustum;
  52. class Point3F;
  53. struct RayInfo;
  54. inline U32 dCalcBlocks(U32 value, U32 blockSize)
  55. {
  56. U32 curBlock = value / blockSize;
  57. U32 nextBlock = curBlock + 1;
  58. return nextBlock * blockSize;
  59. }
  60. /// Allocates a list of T in blocks of mBlockSize, doesn't shrink unless forced
  61. template<typename T> class LazyItemAllocator
  62. {
  63. protected:
  64. T* mItems;
  65. U32 mSize;
  66. U32 mBlockSize;
  67. public:
  68. LazyItemAllocator(U32 blockSize) : mItems(NULL), mSize(0), mBlockSize(blockSize)
  69. {
  70. }
  71. ~LazyItemAllocator()
  72. {
  73. if (mItems)
  74. dFree(mItems);
  75. }
  76. inline bool isNull() const
  77. {
  78. return mItems == NULL;
  79. }
  80. inline T* getPtr() const
  81. {
  82. return mItems;
  83. }
  84. inline bool canFit(U32 count) const
  85. {
  86. return count <= mSize;
  87. }
  88. inline U32 getCapacity() const
  89. {
  90. return mSize;
  91. }
  92. void realloc(U32 requiredItems, bool force)
  93. {
  94. U32 requiredSize = dCalcBlocks(requiredItems, mBlockSize);
  95. if (mSize < requiredSize || (force && (mSize != requiredSize)))
  96. {
  97. if (mItems == NULL)
  98. mItems = (T*)dMalloc(sizeof(T) * requiredSize);
  99. else
  100. mItems = (T*)dRealloc(mItems, sizeof(T) * requiredSize);
  101. mSize = requiredSize;
  102. }
  103. }
  104. };
  105. /// Maintains a set of bin lists for SceneObjects
  106. /// Use allocList to allocate a list. freeList frees the list,
  107. /// and reallocList handles reallocating an existing list handle.
  108. template<typename T> class SceneContainerBinRefList
  109. {
  110. public:
  111. /// Index type for a bin reference
  112. typedef T BinValue;
  113. /// Type for number of bins used by a reference list
  114. typedef T BinCount;
  115. /// Handle used for bin lists
  116. typedef U32 ListHandle;
  117. // Defaults
  118. enum
  119. {
  120. /// Chunk size of reference lists
  121. ReserveSize = 20000,
  122. /// Chunk count of reference list entries
  123. DataReserveSize = 20000*4,
  124. /// Number of unused references when compaction should occur
  125. CompactionThreshold = 4096
  126. };
  127. struct ValueIterator
  128. {
  129. T* binList;
  130. BinCount numElements;
  131. BinCount currentElement;
  132. ValueIterator() : binList(NULL), numElements(0), currentElement(0) { ; }
  133. ValueIterator(T* list, U32 count, U32 idx=0) : binList(list), numElements(count), currentElement(idx)
  134. {
  135. }
  136. T& operator* () const
  137. {
  138. return binList[currentElement];
  139. }
  140. inline bool isValid() const
  141. {
  142. return currentElement < numElements && binList != NULL;
  143. }
  144. inline T* getPtr() const
  145. {
  146. return &binList[currentElement];
  147. }
  148. inline BinCount getIndex() const
  149. {
  150. return currentElement;
  151. }
  152. inline BinCount getCount() const
  153. {
  154. return numElements;
  155. }
  156. ValueIterator& operator++()
  157. {
  158. if (currentElement < numElements)
  159. currentElement++;
  160. return *this;
  161. }
  162. ValueIterator& operator++(int other)
  163. {
  164. currentElement++;
  165. currentElement = mMin(currentElement, numElements);
  166. return *this;
  167. }
  168. inline ValueIterator& operator+(const U32 other)
  169. {
  170. currentElement += other;
  171. currentElement = mMin(currentElement, numElements);
  172. return *this;
  173. }
  174. inline ValueIterator& operator=(const ValueIterator& other)
  175. {
  176. binList = other.binList;
  177. numElements = other.numElements;
  178. currentElement = other.currentElement;
  179. return *this;
  180. }
  181. inline bool operator==(const ValueIterator& other) const
  182. {
  183. return binList == other.binList && currentElement == other.currentElement;
  184. }
  185. inline bool operator!=(const ValueIterator& other) const
  186. {
  187. return !(binList == other.binList && currentElement == other.currentElement);
  188. }
  189. };
  190. public:
  191. #pragma pack(2)
  192. struct BinList
  193. {
  194. // Start reference
  195. U32 startValue;
  196. /// References allocated
  197. BinCount numValues;
  198. };
  199. #pragma pack()
  200. protected:
  201. /// List of bin lists
  202. Vector<BinList> mBinLists;
  203. /// Current bin values
  204. LazyItemAllocator<BinValue> mBinValues;
  205. /// Temporary compaction list
  206. LazyItemAllocator<BinValue> mCompactData;
  207. /// Offset (+1) of first free mBinLists
  208. U32 mFreeListStart;
  209. /// Chunks of mRefList to allocate
  210. U32 mListChunkSize;
  211. /// Current used ref count (in mBinValues)
  212. U32 mUsedValues;
  213. /// Current reference index we are writing
  214. U32 mLastValueIdx;
  215. public:
  216. SceneContainerBinRefList() :
  217. mBinValues(DataReserveSize),
  218. mCompactData(DataReserveSize),
  219. mFreeListStart(0),
  220. mListChunkSize(ReserveSize),
  221. mUsedValues(0),
  222. mLastValueIdx(0)
  223. {
  224. }
  225. ~SceneContainerBinRefList()
  226. {
  227. }
  228. /// Resets the SceneContainerBinRefList
  229. void clear()
  230. {
  231. mBinLists.clear();
  232. mBinValues.realloc(0, true);
  233. mCompactData.realloc(0, true);
  234. mFreeListStart = 0;
  235. mUsedValues = 0;
  236. mLastValueIdx = 0;
  237. }
  238. /// Gets a BinValue list based on a ListHandle.
  239. BinValue* getValues(ListHandle handle, U32& numValues)
  240. {
  241. if (handle == 0 ||
  242. handle > mBinLists.size())
  243. {
  244. numValues = 0;
  245. return NULL;
  246. }
  247. U32 realIDX = handle - 1;
  248. BinList& list = mBinLists[realIDX];
  249. numValues = list.numValues;
  250. return mBinValues.getPtr() + list.startValue;
  251. }
  252. void getValueIterators(ListHandle handle, ValueIterator& start, ValueIterator& end)
  253. {
  254. if (handle == 0 ||
  255. handle > mBinLists.size())
  256. {
  257. start = ValueIterator(NULL, 0);
  258. end = ValueIterator(NULL, 0);
  259. return;
  260. }
  261. U32 realIDX = handle - 1;
  262. BinList& list = mBinLists[realIDX];
  263. start = ValueIterator(mBinValues.getPtr() + list.startValue, list.numValues, 0);
  264. end = ValueIterator(mBinValues.getPtr() + list.startValue, list.numValues, list.numValues);
  265. }
  266. ValueIterator getValueIterator(ListHandle handle)
  267. {
  268. if (handle == 0 ||
  269. handle > mBinLists.size())
  270. {
  271. return ValueIterator(NULL, 0);
  272. }
  273. U32 realIDX = handle - 1;
  274. BinList& list = mBinLists[realIDX];
  275. return ValueIterator(mBinValues.getPtr() + list.startValue, list.numValues);
  276. }
  277. inline U32 getNextFreeListIndex() const
  278. {
  279. return mFreeListStart;
  280. }
  281. inline const Vector<BinList>& getBinLists() const
  282. {
  283. return mBinLists;
  284. }
  285. inline const BinValue* getBin() const
  286. {
  287. return mBinValues.getPtr();
  288. }
  289. inline const U32 getBinCapacity() const
  290. {
  291. return mBinValues.getCapacity();
  292. }
  293. protected:
  294. /// Gets a free entry from the free entry list.
  295. bool getFreeEntry(ListHandle& outIDX)
  296. {
  297. if (mFreeListStart > 0)
  298. {
  299. outIDX = mFreeListStart - 1;
  300. mFreeListStart = mBinLists[outIDX].startValue;
  301. return true;
  302. }
  303. return false;
  304. }
  305. public:
  306. /// Allocates a new ListHandle with numValue values copied from values.
  307. ListHandle allocList(BinCount numValues, BinValue* values)
  308. {
  309. BinList list;
  310. ListHandle retHandle = 0;
  311. list.numValues = numValues;
  312. list.startValue = mLastValueIdx;
  313. mLastValueIdx += numValues;
  314. mUsedValues += numValues;
  315. // Use free list or push new entry
  316. if (!getFreeEntry(retHandle))
  317. {
  318. mBinLists.push_back(list);
  319. retHandle = mBinLists.size();
  320. }
  321. else
  322. {
  323. mBinLists[retHandle++] = list;
  324. }
  325. // Manage lists
  326. mBinLists.reserve(dCalcBlocks(mBinLists.size(), mListChunkSize));
  327. mBinValues.realloc(mLastValueIdx, false);
  328. // Copy data
  329. dCopyArray(mBinValues.getPtr() + list.startValue, values, numValues);
  330. return retHandle;
  331. }
  332. /// Reallocates an existing ListHandle.
  333. /// Existing memory will be used if numValues is the same,
  334. /// otherwise new list memory will be allocated.
  335. void reallocList(ListHandle handle, BinCount numValues, BinValue* values)
  336. {
  337. if (handle == 0 ||
  338. handle > mBinLists.size())
  339. return;
  340. U32 realIDX = handle - 1;
  341. BinList& list = mBinLists[realIDX];
  342. if (list.numValues != numValues)
  343. {
  344. // Allocate new entry
  345. mUsedValues -= list.numValues;
  346. mUsedValues += numValues;
  347. list.numValues = numValues;
  348. list.startValue = mLastValueIdx;
  349. mLastValueIdx += numValues;
  350. mBinValues.realloc(mLastValueIdx, false);
  351. }
  352. dCopyArray(mBinValues.getPtr() + list.startValue, values, numValues);
  353. }
  354. /// Frees an existing ListHandle
  355. void freeList(ListHandle handle)
  356. {
  357. if (handle == 0 ||
  358. handle > mBinLists.size())
  359. return;
  360. U32 realIDX = handle - 1;
  361. BinList& list = mBinLists[realIDX];
  362. mUsedValues -= list.numValues;
  363. list.numValues = 0;
  364. // Add to free list
  365. list.startValue = mFreeListStart;
  366. // Next
  367. mFreeListStart = handle;
  368. AssertFatal(mLastValueIdx >= mUsedValues, "ref overflow");
  369. // Automatically compact if we have enough free items
  370. if ((mLastValueIdx - mUsedValues) > CompactionThreshold)
  371. {
  372. compact();
  373. }
  374. }
  375. void replaceListBin(ListHandle handle, BinValue oldValue, BinValue newValue)
  376. {
  377. if (handle == 0 ||
  378. handle > mBinLists.size())
  379. return;
  380. U32 realIDX = handle - 1;
  381. BinList& list = mBinLists[realIDX];
  382. BinValue* values = mBinValues.getPtr() + list.startValue;
  383. for (U32 i = 0; i < list.numValues; i++)
  384. {
  385. if (values[i] == oldValue)
  386. {
  387. values[i] = newValue;
  388. break;
  389. }
  390. }
  391. }
  392. bool containsBinItem(ListHandle handle, BinValue value) const
  393. {
  394. if (handle == 0 ||
  395. handle > mBinLists.size())
  396. return false;
  397. U32 realIDX = handle - 1;
  398. const BinList& list = mBinLists[realIDX];
  399. const BinValue* values = mBinValues.getPtr() + list.startValue;
  400. for (U32 i = 0; i < list.numValues; i++)
  401. {
  402. if (values[i] == value)
  403. return true;
  404. }
  405. return false;
  406. }
  407. /// Compacts the BinValue lists.
  408. /// This will automatically be called by freeList usually
  409. /// once CompactionThreshold list values have been freed.
  410. void compact()
  411. {
  412. if (mBinValues.isNull())
  413. return;
  414. mCompactData.realloc(mUsedValues, false);
  415. BinValue* outPtr = mCompactData.getPtr();
  416. U32 newOutStart = 0;
  417. // Copy list values to scratch list
  418. for (BinList& list : mBinLists)
  419. {
  420. if (list.numValues == 0)
  421. continue;
  422. const BinValue* inPtr = mBinValues.getPtr() + list.startValue;
  423. dCopyArray(outPtr, inPtr, list.numValues);
  424. // Update counters
  425. list.startValue = newOutStart;
  426. outPtr += list.numValues;
  427. newOutStart += list.numValues;
  428. }
  429. AssertFatal(newOutStart == mUsedValues, "value count mismatch");
  430. mLastValueIdx = mUsedValues;
  431. mBinValues.realloc(mLastValueIdx, true);
  432. const U32 copySize = newOutStart * sizeof(BinValue);
  433. memcpy(mBinValues.getPtr(), mCompactData.getPtr(), copySize);
  434. }
  435. };
  436. //----------------------------------------------------------------------------
  437. /// Database for SceneObjects.
  438. ///
  439. /// ScenceContainer implements a grid-based spatial subdivision for the contents of a scene.
  440. class SceneContainer
  441. {
  442. public:
  443. enum CastRayType
  444. {
  445. CollisionGeometry,
  446. RenderedGeometry,
  447. };
  448. public:
  449. typedef SceneContainerBinRefList<U16> BinValueList;
  450. /// Base object list type, should conform to Vector
  451. typedef Vector<SceneObject*> ObjectList;
  452. /// Type to reference a bin list
  453. typedef U32 BinListIndex;
  454. /// Type to reference a bin. This should be changed if there are more than 65536 bins.
  455. typedef U16 BinRef;
  456. struct CallbackInfo
  457. {
  458. PolyListContext context;
  459. AbstractPolyList* polyList;
  460. Box3F boundingBox;
  461. SphereF boundingSphere;
  462. void *key;
  463. };
  464. private:
  465. /// Container queries based on #mCurrSeqKey are are not re-entrant;
  466. /// this is used to detect when it happens.
  467. bool mSearchInProgress;
  468. /// Current sequence key.
  469. U32 mCurrSeqKey;
  470. /// Binned object lists
  471. ObjectList* mBinArray;
  472. /// Large objects
  473. ObjectList mOverflowBin;
  474. /// Every single object not categorized by bin
  475. ObjectList mGlobalList;
  476. /// A vector that contains just the water and physical zone
  477. /// object types which is used to optimize searches.
  478. ObjectList mWaterAndZones;
  479. /// Vector that contains just the terrain objects in the container.
  480. ObjectList mTerrains;
  481. /// Temporary list for value insert
  482. Vector<BinValueList::BinValue> mBinValueList;
  483. /// Maintains a list of bin references
  484. BinValueList mBinRefLists;
  485. public:
  486. /// World units of side of bin
  487. static const F32 csmBinSize;
  488. /// World units of entire side of bin grid
  489. static const F32 csmTotalAxisBinSize;
  490. /// Size of grid on any axis
  491. static const U32 csmNumAxisBins;
  492. /// Index used to store overflow entries
  493. static const U32 csmOverflowBinIdx;
  494. /// Total number of bin lists to allocate
  495. static const U32 csmTotalNumBins;
  496. public:
  497. SceneContainer();
  498. ~SceneContainer();
  499. /// Return a vector containing all the water and physical zone objects in this container.
  500. const Vector< SceneObject* >& getWaterAndPhysicalZones() const { return mWaterAndZones; }
  501. /// Return a vector containing all terrain objects in this container.
  502. const Vector< SceneObject* >& getTerrains() const { return mTerrains; }
  503. /// @name Basic database operations
  504. /// @{
  505. ///
  506. typedef void ( *FindCallback )( SceneObject* object, void* key );
  507. /// Find all objects of the given type(s) and invoke the given callback for each
  508. /// of them.
  509. /// @param mask Object type mask (@see SimObjectTypes).
  510. /// @param callback Pointer to function to invoke for each object.
  511. /// @param key User data to pass to the "key" argument of @a callback.
  512. void findObjects( U32 mask, FindCallback callback, void* key = NULL );
  513. void findObjects( const Box3F& box, U32 mask, FindCallback, void *key = NULL );
  514. void findObjects( const Frustum& frustum, U32 mask, FindCallback, void *key = NULL );
  515. void polyhedronFindObjects( const Polyhedron& polyhedron, U32 mask, FindCallback, void *key = NULL );
  516. /// Find all objects of the given type(s) and add them to the given vector.
  517. /// @param mask Object type mask (@see SimObjectTypes).
  518. /// @param outFound Vector to add found objects to.
  519. void findObjectList( U32 mask, Vector< SceneObject* >* outFound );
  520. ///
  521. void findObjectList( const Box3F& box, U32 mask, Vector< SceneObject* >* outFound );
  522. ///
  523. void findObjectList( const Frustum& frustum, U32 mask, Vector< SceneObject* >* outFound );
  524. /// @}
  525. /// @name Line intersection
  526. /// @{
  527. typedef bool ( *CastRayCallback )( SceneObject* object );
  528. /// Test against collision geometry -- fast.
  529. bool castRay( const Point3F &start, const Point3F &end, U32 mask, RayInfo* info, CastRayCallback callback = NULL );
  530. /// Test against rendered geometry -- slow.
  531. bool castRayRendered( const Point3F &start, const Point3F &end, U32 mask, RayInfo* info, CastRayCallback callback = NULL );
  532. bool collideBox(const Point3F &start, const Point3F &end, U32 mask, RayInfo* info);
  533. /// @}
  534. /// @name Poly list
  535. /// @{
  536. ///
  537. bool buildPolyList( PolyListContext context,
  538. const Box3F &box,
  539. U32 typeMask,
  540. AbstractPolyList *polylist );
  541. /// @}
  542. /// Add an object to the database.
  543. /// @param object A SceneObject.
  544. bool addObject( SceneObject* object );
  545. /// Remove an object from the database.
  546. /// @param object A SceneObject.
  547. bool removeObject( SceneObject* object );
  548. void insertIntoBins( SceneObject* object );
  549. void removeFromBins( SceneObject* object );
  550. /// Make sure that we're not just sticking the object right back
  551. /// where it came from. The overloaded insertInto is so we don't calculate
  552. /// the ranges twice.
  553. void checkBins( SceneObject* object );
  554. void insertIntoBins(SceneObject*, const SceneBinRange& range);
  555. void initRadiusSearch(const Point3F& searchPoint,
  556. const F32 searchRadius,
  557. const U32 searchMask);
  558. void initTypeSearch(const U32 searchMask);
  559. SceneObject* containerSearchNextObject();
  560. U32 containerSearchNext();
  561. F32 containerSearchCurrDist();
  562. F32 containerSearchCurrRadiusDist();
  563. private:
  564. Vector<SimObjectPtr<SceneObject>*> mSearchList;///< Object searches to support console querying of the database. ONLY WORKS ON SERVER
  565. S32 mCurrSearchPos;
  566. Point3F mSearchReferencePoint;
  567. void cleanupSearchVectors();
  568. /// Base cast ray code
  569. bool _castRay( U32 type, const Point3F &start, const Point3F &end, U32 mask, RayInfo* info, CastRayCallback callback );
  570. void _findSpecialObjects( const Vector< SceneObject* >& vector, U32 mask, FindCallback, void *key = NULL );
  571. void _findSpecialObjects( const Vector< SceneObject* >& vector, const Box3F &box, U32 mask, FindCallback callback, void *key = NULL );
  572. public:
  573. static inline void getBinRange( const Point2F minExtents, const Point2F maxExtents, SceneBinRange& outRange )
  574. {
  575. U32 outMin, outMax;
  576. getBinRange(minExtents.x, maxExtents.x, outMin, outMax);
  577. outRange.minCoord[0] = outMin;
  578. outRange.maxCoord[0] = outMax;
  579. getBinRange(minExtents.y, maxExtents.y, outMin, outMax);
  580. outRange.minCoord[1] = outMin;
  581. outRange.maxCoord[1] = outMax;
  582. }
  583. inline void dumpBin(U32 x, U32 y, Vector<SceneObject*> &list)
  584. {
  585. U32 insertX = x % csmNumAxisBins;
  586. U32 insertY = y * csmNumAxisBins;
  587. U32 binIDX = insertY + insertX;
  588. list.clear();
  589. if (binIDX < csmTotalNumBins)
  590. {
  591. for (SceneObject* obj : mBinArray[binIDX])
  592. {
  593. list.push_back(obj);
  594. }
  595. }
  596. }
  597. static void getBinRange( const F32 min, const F32 max, U32& minBin, U32& maxBin );
  598. public:
  599. Vector<SimObjectPtr<SceneObject>*>& getRadiusSearchList() { return mSearchList; }
  600. };
  601. //-----------------------------------------------------------------------------
  602. inline bool SceneBinRange::shouldOverflow() const
  603. {
  604. return
  605. ((getWidth() + 1) >= SceneContainer::csmNumAxisBins ||
  606. ((getHeight() + 1) >= SceneContainer::csmNumAxisBins));
  607. }
  608. //-----------------------------------------------------------------------------
  609. extern SceneContainer gServerContainer;
  610. extern SceneContainer gClientContainer;
  611. #endif // !_SCENECONTAINER_H_