SpriteBatchQuery.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. #ifndef _SPRITE_BATCH_QUERY_H_
  23. #define _SPRITE_BATCH_QUERY_H_
  24. #ifndef _SPRITE_BATCH_QUERY_RESULT_H_
  25. #include "2d/core/SpriteBatchQueryResult.h"
  26. #endif
  27. ///-----------------------------------------------------------------------------
  28. class SpriteBatch;
  29. class SpriteBatchItem;
  30. ///-----------------------------------------------------------------------------
  31. class SpriteBatchQuery :
  32. protected b2DynamicTree,
  33. public b2QueryCallback,
  34. public b2RayCastCallback
  35. {
  36. public:
  37. SpriteBatchQuery( SpriteBatch* pSpriteBatch );
  38. virtual ~SpriteBatchQuery() {}
  39. /// Standard scope.
  40. S32 add( SpriteBatchItem* pSpriteBatchItem );
  41. void remove( SpriteBatchItem* pSpriteBatchItem );
  42. bool update( SpriteBatchItem* pSpriteBatchItem, const b2AABB& aabb, const b2Vec2& displacement );
  43. //// Render queries.
  44. U32 renderQueryArea( const b2AABB& aabb );
  45. U32 renderQueryRay( const Vector2& point1, const Vector2& point2 );
  46. U32 renderQueryPoint( const Vector2& point );
  47. /// Results.
  48. void clearQuery( void );
  49. typeSpriteBatchQueryResultVector& getQueryResults( void ) { return mQueryResults; }
  50. inline U32 getQueryResultsCount( void ) const { return mQueryResults.size(); }
  51. inline bool getIsRaycastQueryResult( void ) const { return mIsRaycastQueryResult; }
  52. void sortRaycastQueryResult( void );
  53. /// Unused result callbacks.
  54. virtual bool ReportFixture( b2Fixture* fixture ) { return true; }
  55. virtual F32 ReportFixture( b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, F32 fraction ) { return 1.0; }
  56. /// Callbacks.
  57. bool QueryCallback( S32 proxyId );
  58. F32 RayCastCallback( const b2RayCastInput& input, S32 proxyId );
  59. private:
  60. static S32 QSORT_CALLBACK rayCastFractionSort(const void* a, const void* b);
  61. private:
  62. SpriteBatch* mpSpriteBatch;
  63. bool mCheckFixturePoint;
  64. b2Vec2 mFixturePoint;
  65. typeSpriteBatchQueryResultVector mQueryResults;
  66. bool mIsRaycastQueryResult;
  67. typeSceneObjectVector mAlwaysInScopeSet;
  68. U32 mMasterQueryKey;
  69. };
  70. #endif // _SPRITE_BATCH_QUERY_H_