CompositeSprite.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 _COMPOSITE_SPRITE_H_
  23. #define _COMPOSITE_SPRITE_H_
  24. #ifndef _SPRITE_BATCH_H_
  25. #include "2d/core/SpriteBatch.h"
  26. #endif
  27. #ifndef _SCENE_OBJECT_H_
  28. #include "2d/sceneobject/SceneObject.h"
  29. #endif
  30. //------------------------------------------------------------------------------
  31. class CompositeSprite : public SceneObject, public SpriteBatch
  32. {
  33. protected:
  34. typedef SceneObject Parent;
  35. public:
  36. // Batch layout type.
  37. enum BatchLayoutType
  38. {
  39. INVALID_LAYOUT,
  40. NO_LAYOUT,
  41. RECTILINEAR_LAYOUT,
  42. ISOMETRIC_LAYOUT,
  43. CUSTOM_LAYOUT
  44. };
  45. private:
  46. BatchLayoutType mBatchLayoutType;
  47. public:
  48. CompositeSprite();
  49. virtual ~CompositeSprite();
  50. static void initPersistFields();
  51. virtual bool onAdd();
  52. virtual void onRemove();
  53. virtual void preIntegrate( const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats );
  54. virtual void integrateObject( const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats );
  55. virtual void interpolateObject( const F32 timeDelta );
  56. virtual inline void setSpatialDirty(void) { mSpatialDirty = true; }
  57. virtual bool canPrepareRender( void ) const { return true; }
  58. virtual bool shouldRender( void ) const { return true; }
  59. virtual void scenePrepareRender( const SceneRenderState* pSceneRenderState, SceneRenderQueue* pSceneRenderQueue );
  60. virtual void sceneRender( const SceneRenderState* pSceneRenderState, const SceneRenderRequest* pSceneRenderRequest, BatchRender* pBatchRenderer );
  61. virtual void copyTo( SimObject* object );
  62. void setBatchLayout( const BatchLayoutType& batchLayoutType );
  63. BatchLayoutType getBatchLayout( void ) const { return mBatchLayoutType; }
  64. static BatchLayoutType getBatchLayoutTypeEnum( const char* label );
  65. static const char* getBatchLayoutTypeDescription( const BatchLayoutType batchLayoutType );
  66. /// Declare Console Object.
  67. DECLARE_CONOBJECT( CompositeSprite );
  68. protected:
  69. virtual SpriteBatchItem* createSprite( const SpriteBatchItem::LogicalPosition& logicalPosition );
  70. virtual SpriteBatchItem* createSpriteRectilinearLayout( const SpriteBatchItem::LogicalPosition& logicalPosition );
  71. virtual SpriteBatchItem* createSpriteIsometricLayout( const SpriteBatchItem::LogicalPosition& logicalPosition );
  72. virtual SpriteBatchItem* createCustomLayout( const SpriteBatchItem::LogicalPosition& logicalPosition );
  73. virtual void onTamlCustomWrite( TamlCustomNodes& customNodes );
  74. virtual void onTamlCustomRead( const TamlCustomNodes& customNodes );
  75. protected:
  76. static bool writeDefaultSpriteStride( void* obj, StringTableEntry pFieldName ) { return !STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, obj)->getDefaultSpriteStride().isEqual( Vector2::getOne() ); }
  77. static bool writeDefaultSpriteSize( void* obj, StringTableEntry pFieldName ) { return !STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, obj)->getDefaultSpriteSize().isEqual( Vector2::getOne() ); }
  78. static bool setDefaultSpriteAngle(void* obj, const char* data) { STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, obj)->setDefaultSpriteAngle(mDegToRad(dAtof(data))); return false; }
  79. static const char* getDefaultSpriteAngle(void* obj, const char* data) { return Con::getFloatArg( mRadToDeg(STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, obj)->getDefaultSpriteAngle()) ); }
  80. static bool writeDefaultSpriteAngle( void* obj, StringTableEntry pFieldName ) { return mNotZero( STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, obj)->getDefaultSpriteAngle() ); }
  81. static bool writeBatchIsolated( void* obj, StringTableEntry pFieldName ) { return static_cast<CompositeSprite*>(obj)->getBatchIsolated(); }
  82. static bool writeBatchSortMode( void* obj, StringTableEntry pFieldName ) { return static_cast<CompositeSprite*>(obj)->getBatchSortMode() != SceneRenderQueue::RENDER_SORT_OFF; }
  83. static bool setBatchLayout(void* obj, const char* data) { static_cast<CompositeSprite*>(obj)->setBatchLayout( getBatchLayoutTypeEnum(data) ); return false; }
  84. static bool writeBatchLayout( void* obj, StringTableEntry pFieldName ) { return static_cast<CompositeSprite*>(obj)->getBatchLayout() != CompositeSprite::NO_LAYOUT; }
  85. static bool setBatchCulling(void* obj, const char* data) { STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, obj)->setBatchCulling(dAtob(data)); return false; }
  86. static bool writeBatchCulling( void* obj, StringTableEntry pFieldName ) { return !static_cast<CompositeSprite*>(obj)->getBatchCulling(); }
  87. };
  88. #endif // _COMPOSITE_SPRITE_H_