lightBase.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #ifndef _LIGHTBASE_H_
  23. #define _LIGHTBASE_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _LIGHTINFO_H_
  28. #include "lighting/lightInfo.h"
  29. #endif
  30. #ifndef _ITICKABLE_H_
  31. #include "core/iTickable.h"
  32. #endif
  33. #ifndef _LIGHTFLAREDATA_H_
  34. #include "T3D/lightFlareData.h"
  35. #endif
  36. #ifndef _LIGHTANIMDATA_H_
  37. #include "T3D/lightAnimData.h"
  38. #endif
  39. class LightAnimData;
  40. class LightBase : public SceneObject, public ISceneLight, public virtual ITickable
  41. {
  42. typedef SceneObject Parent;
  43. friend class LightAnimData;
  44. friend class LightFlareData;
  45. protected:
  46. bool mIsEnabled;
  47. LinearColorF mColor;
  48. F32 mBrightness;
  49. bool mCastShadows;
  50. S32 mStaticRefreshFreq;
  51. S32 mDynamicRefreshFreq;
  52. F32 mPriority;
  53. LightInfo *mLight;
  54. LightAnimData *mAnimationData;
  55. LightAnimState mAnimState;
  56. LightFlareData *mFlareData;
  57. LightFlareState mFlareState;
  58. F32 mFlareScale;
  59. static bool smRenderViz;
  60. virtual void _conformLights() {}
  61. void _onRenderViz( ObjectRenderInst *ri,
  62. SceneRenderState *state,
  63. BaseMatInstance *overrideMat );
  64. virtual void _renderViz( SceneRenderState *state ) {}
  65. enum LightMasks
  66. {
  67. InitialUpdateMask = Parent::NextFreeMask,
  68. EnabledMask = Parent::NextFreeMask << 1,
  69. TransformMask = Parent::NextFreeMask << 2,
  70. UpdateMask = Parent::NextFreeMask << 3,
  71. DatablockMask = Parent::NextFreeMask << 4,
  72. NextFreeMask = Parent::NextFreeMask << 5
  73. };
  74. // SimObject.
  75. virtual void _onSelected();
  76. virtual void _onUnselected();
  77. public:
  78. LightBase();
  79. virtual ~LightBase();
  80. // SimObject
  81. virtual bool onAdd();
  82. virtual void onRemove();
  83. // ConsoleObject
  84. void inspectPostApply();
  85. static void initPersistFields();
  86. DECLARE_CONOBJECT(LightBase);
  87. // NetObject
  88. U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  89. void unpackUpdate( NetConnection *conn, BitStream *stream );
  90. // ISceneLight
  91. virtual void submitLights( LightManager *lm, bool staticLighting );
  92. virtual LightInfo* getLight() { return mLight; }
  93. // SceneObject
  94. virtual void setTransform( const MatrixF &mat );
  95. virtual void prepRenderImage( SceneRenderState *state );
  96. // ITickable
  97. virtual void interpolateTick( F32 delta );
  98. virtual void processTick();
  99. virtual void advanceTime( F32 timeDelta );
  100. /// Toggles the light on and off.
  101. void setLightEnabled( bool enabled );
  102. bool getLightEnabled() { return mIsEnabled; };
  103. /// Animate the light.
  104. virtual void pauseAnimation( void );
  105. virtual void playAnimation( void );
  106. virtual void playAnimation( LightAnimData *animData );
  107. };
  108. #endif // _LIGHTBASE_H_