WaveComposite.h 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 _WAVE_COMPOSITE_H_
  23. #define _WAVE_COMPOSITE_H_
  24. #ifndef _COMPOSITE_SPRITE_H_
  25. #include "2d/sceneobject/CompositeSprite.h"
  26. #endif
  27. //------------------------------------------------------------------------------
  28. class WaveComposite : public SceneObject, public SpriteBatch
  29. {
  30. protected:
  31. typedef SceneObject Parent;
  32. private:
  33. AssetPtr<ImageAsset> mImageAsset;
  34. U32 mImageFrame;
  35. U32 mSpriteCount;
  36. Vector2 mSpriteSize;
  37. F32 mAmplitude;
  38. F32 mFrequency;
  39. typedef Vector<SpriteBatchItem*> typeWaveSpritesVector;
  40. typeWaveSpritesVector mWaveSprites;
  41. F32 mPreTickTime;
  42. F32 mPostTickTime;
  43. public:
  44. WaveComposite();
  45. virtual ~WaveComposite();
  46. static void initPersistFields();
  47. virtual void preIntegrate( const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats );
  48. virtual void integrateObject( const F32 totalTime, const F32 elapsedTime, DebugStats* pDebugStats );
  49. virtual void interpolateObject( const F32 timeDelta );
  50. virtual void copyTo( SimObject* object );
  51. virtual bool canPrepareRender( void ) const { return true; }
  52. virtual bool validRender( void ) const { return mImageAsset.notNull(); }
  53. virtual bool shouldRender( void ) const { return true; }
  54. virtual void scenePrepareRender( const SceneRenderState* pSceneRenderState, SceneRenderQueue* pSceneRenderQueue );
  55. virtual void sceneRender( const SceneRenderState* pSceneRenderState, const SceneRenderRequest* pSceneRenderRequest, BatchRender* pBatchRenderer );
  56. bool setImage( const char* pImageAssetId );
  57. inline StringTableEntry getImage( void ) const { return mImageAsset.getAssetId(); }
  58. bool setImageFrame( const U32 frame );
  59. inline U32 getImageFrame( void ) const { return mImageFrame; }
  60. void setSpriteCount( const U32 spriteCount );
  61. inline U32 getSpriteCount( void ) const { return mSpriteCount; }
  62. void setSpriteSize( const Vector2& spriteSize );
  63. inline const Vector2& getSpriteSize( void ) const { return mSpriteSize; };
  64. inline void setAmplitude( const F32 amplitude ) { mAmplitude = amplitude; }
  65. inline F32 getAmplitude( void ) const { return mAmplitude; }
  66. inline void setFrequency( const F32 frequency ) { mFrequency = frequency; }
  67. inline F32 getFrequency( void ) const { return mFrequency; }
  68. /// Declare Console Object.
  69. DECLARE_CONOBJECT( WaveComposite );
  70. protected:
  71. void generateComposition( void );
  72. void updateComposition( const F32 time );
  73. protected:
  74. static bool setImage(void* obj, const char* data) { static_cast<WaveComposite*>(obj)->setImage( data ); return false; }
  75. static const char* getImage(void* obj, const char* data) { return DYNAMIC_VOID_CAST_TO(WaveComposite, ImageFrameProvider, obj)->getImage(); }
  76. static bool writeImage( void* obj, StringTableEntry pFieldName ) { return static_cast<WaveComposite*>(obj)->mImageAsset.notNull(); }
  77. static bool setImageFrame(void* obj, const char* data) { static_cast<WaveComposite*>(obj)->setImageFrame( dAtoi(data) ); return false; }
  78. static bool writeImageFrame( void* obj, StringTableEntry pFieldName ) { return static_cast<WaveComposite*>(obj)->getImageFrame() > 0; }
  79. static bool setSpriteCount(void* obj, const char* data) { static_cast<WaveComposite*>(obj)->setSpriteCount( dAtoi(data) ); return false; }
  80. static bool setSpriteSize(void* obj, const char* data) { static_cast<WaveComposite*>(obj)->setSpriteSize( Vector2(data) ); return false; }
  81. };
  82. #endif // _WAVE_COMPOSITE_H_