SWF_SpriteInstance.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __SWF_SPRITEINSTANCE_H__
  21. #define __SWF_SPRITEINSTANCE_H__
  22. /*
  23. ================================================
  24. There can be multiple instances of a single sprite running
  25. ================================================
  26. */
  27. class idSWFSpriteInstance {
  28. public:
  29. idSWFSpriteInstance();
  30. ~idSWFSpriteInstance();
  31. void Init( idSWFSprite * sprite, idSWFSpriteInstance * parent, int depth );
  32. bool Run();
  33. bool RunActions();
  34. const char * GetName() const { return name.c_str(); }
  35. idSWFScriptObject * GetScriptObject() { return scriptObject; }
  36. void SetAlignment( float x, float y ) { xOffset = x; yOffset = y; }
  37. void SetMaterial( const idMaterial * material, int width = -1, int height = -1 );
  38. void SetVisible( bool visible );
  39. bool IsVisible() { return isVisible; }
  40. void PlayFrame( const idSWFParmList & parms );
  41. void PlayFrame( const char * frameName ) {
  42. idSWFParmList parms;
  43. parms.Append( frameName );
  44. PlayFrame( parms );
  45. }
  46. void PlayFrame( const int frameNum ) {
  47. idSWFParmList parms;
  48. parms.Append( frameNum );
  49. PlayFrame( parms );
  50. }
  51. void StopFrame( const idSWFParmList & parms );
  52. void StopFrame( const char * frameName ) {
  53. idSWFParmList parms;
  54. parms.Append( frameName );
  55. StopFrame( parms );
  56. }
  57. void StopFrame( const int frameNum ) {
  58. idSWFParmList parms;
  59. parms.Append( frameNum );
  60. StopFrame( parms );
  61. }
  62. // FIXME: Why do all the Set functions have defaults of -1.0f? This seems arbitrar.
  63. // Probably better to not have a default at all, so any non-parametized calls throw a
  64. // compilation error.
  65. float GetXPos() const;
  66. float GetYPos( bool overallPos = false ) const;
  67. void SetXPos( float xPos = -1.0f );
  68. void SetYPos( float yPos = -1.0f );
  69. void SetPos( float xPos = -1.0f, float yPos = -1.0f );
  70. void SetAlpha( float val );
  71. void SetScale( float x = -1.0f, float y = -1.0f );
  72. void SetMoveToScale( float x = -1.0f, float y = -1.0f );
  73. bool UpdateMoveToScale( float speed ); // returns true if the update was successful
  74. void SetRotation( float rot );
  75. uint16 GetCurrentFrame() { return currentFrame; }
  76. bool IsPlaying() const { return isPlaying; }
  77. int GetStereoDepth() { return stereoDepth; }
  78. // Removing the private access control statement due to cl 214702
  79. // Apparently MS's C++ compiler supports the newer C++ standard, and GCC supports C++03
  80. // In the new C++ standard, nested members of a friend class have access to private/protected members of the class granting friendship
  81. // In C++03, nested members defined in a friend class do NOT have access to private/protected members of the class granting friendship friend class idSWF;
  82. bool isPlaying;
  83. bool isVisible;
  84. bool childrenRunning;
  85. bool firstRun;
  86. // currentFrame is the frame number currently in the displayList
  87. // we use 1 based frame numbers because currentFrame = 0 means nothing is in the display list
  88. // it's also convenient because Flash also uses 1 based frame numbers
  89. uint16 currentFrame;
  90. uint16 frameCount;
  91. // the sprite this is an instance of
  92. idSWFSprite * sprite;
  93. // sprite instances can be nested
  94. idSWFSpriteInstance * parent;
  95. // depth of this sprite instance in the parent's display list
  96. int depth;
  97. // if this is set, apply this material when rendering any child shapes
  98. int itemIndex;
  99. const idMaterial * materialOverride;
  100. uint16 materialWidth;
  101. uint16 materialHeight;
  102. float xOffset;
  103. float yOffset;
  104. float moveToXScale;
  105. float moveToYScale;
  106. float moveToSpeed;
  107. int stereoDepth;
  108. idSWFScriptObject * scriptObject;
  109. // children display entries
  110. idList< swfDisplayEntry_t, TAG_SWF > displayList;
  111. swfDisplayEntry_t * FindDisplayEntry( int depth );
  112. // name of this sprite instance
  113. idStr name;
  114. struct swfAction_t {
  115. const byte * data;
  116. uint32 dataLength;
  117. };
  118. idList< swfAction_t, TAG_SWF > actions;
  119. idSWFScriptFunction_Script * actionScript;
  120. idSWFScriptVar onEnterFrame;
  121. //idSWFScriptVar onLoad;
  122. // Removing the private access control statement due to cl 214702
  123. // Apparently MS's C++ compiler supports the newer C++ standard, and GCC supports C++03
  124. // In the new C++ standard, nested members of a friend class have access to private/protected members of the class granting friendship
  125. // In C++03, nested members defined in a friend class do NOT have access to private/protected members of the class granting friendship
  126. //----------------------------------
  127. // SWF_PlaceObject.cpp
  128. //----------------------------------
  129. void PlaceObject2( idSWFBitStream & bitstream );
  130. void PlaceObject3( idSWFBitStream & bitstream );
  131. void RemoveObject2( idSWFBitStream & bitstream );
  132. //----------------------------------
  133. // SWF_Sounds.cpp
  134. //----------------------------------
  135. void StartSound( idSWFBitStream & bitstream );
  136. //----------------------------------
  137. // SWF_SpriteInstance.cpp
  138. //----------------------------------
  139. void NextFrame();
  140. void PrevFrame();
  141. void RunTo( int frameNum );
  142. void Play();
  143. void Stop();
  144. void FreeDisplayList();
  145. swfDisplayEntry_t * AddDisplayEntry( int depth, int characterID );
  146. void RemoveDisplayEntry( int depth );
  147. void SwapDepths( int depth1, int depth2 );
  148. void DoAction( idSWFBitStream & bitstream );
  149. idSWFSpriteInstance * FindChildSprite( const char * childName );
  150. idSWFSpriteInstance * ResolveTarget( const char * targetName );
  151. uint32 FindFrame( const char * frameLabel ) const;
  152. bool FrameExists( const char * frameLabel ) const;
  153. bool IsBetweenFrames( const char * frameLabel1, const char * frameLabel2 ) const;
  154. };
  155. /*
  156. ================================================
  157. This is the prototype object that all the sprite instance script objects reference
  158. ================================================
  159. */
  160. class idSWFScriptObject_SpriteInstancePrototype : public idSWFScriptObject {
  161. public:
  162. idSWFScriptObject_SpriteInstancePrototype();
  163. #define SWF_SPRITE_FUNCTION_DECLARE( x ) \
  164. class idSWFScriptFunction_##x : public idSWFScriptFunction { \
  165. public: \
  166. void AddRef() {} \
  167. void Release() {} \
  168. idSWFScriptVar Call( idSWFScriptObject * thisObject, const idSWFParmList & parms ); \
  169. } scriptFunction_##x
  170. SWF_SPRITE_FUNCTION_DECLARE( duplicateMovieClip );
  171. SWF_SPRITE_FUNCTION_DECLARE( gotoAndPlay );
  172. SWF_SPRITE_FUNCTION_DECLARE( gotoAndStop );
  173. SWF_SPRITE_FUNCTION_DECLARE( swapDepths );
  174. SWF_SPRITE_FUNCTION_DECLARE( nextFrame );
  175. SWF_SPRITE_FUNCTION_DECLARE( prevFrame );
  176. SWF_SPRITE_FUNCTION_DECLARE( play );
  177. SWF_SPRITE_FUNCTION_DECLARE( stop );
  178. SWF_NATIVE_VAR_DECLARE( _x );
  179. SWF_NATIVE_VAR_DECLARE( _y );
  180. SWF_NATIVE_VAR_DECLARE( _xscale );
  181. SWF_NATIVE_VAR_DECLARE( _yscale );
  182. SWF_NATIVE_VAR_DECLARE( _alpha );
  183. SWF_NATIVE_VAR_DECLARE( _brightness );
  184. SWF_NATIVE_VAR_DECLARE( _visible );
  185. SWF_NATIVE_VAR_DECLARE( _width );
  186. SWF_NATIVE_VAR_DECLARE( _height );
  187. SWF_NATIVE_VAR_DECLARE( _rotation );
  188. SWF_NATIVE_VAR_DECLARE_READONLY( _name );
  189. SWF_NATIVE_VAR_DECLARE_READONLY( _currentframe );
  190. SWF_NATIVE_VAR_DECLARE_READONLY( _totalframes );
  191. SWF_NATIVE_VAR_DECLARE_READONLY( _target );
  192. SWF_NATIVE_VAR_DECLARE_READONLY( _framesloaded );
  193. SWF_NATIVE_VAR_DECLARE_READONLY( _droptarget );
  194. SWF_NATIVE_VAR_DECLARE_READONLY( _url );
  195. SWF_NATIVE_VAR_DECLARE_READONLY( _highquality );
  196. SWF_NATIVE_VAR_DECLARE_READONLY( _focusrect );
  197. SWF_NATIVE_VAR_DECLARE_READONLY( _soundbuftime );
  198. SWF_NATIVE_VAR_DECLARE_READONLY( _quality );
  199. SWF_NATIVE_VAR_DECLARE_READONLY( _mousex );
  200. SWF_NATIVE_VAR_DECLARE_READONLY( _mousey );
  201. SWF_NATIVE_VAR_DECLARE( _stereoDepth );
  202. SWF_NATIVE_VAR_DECLARE( _itemindex );
  203. SWF_NATIVE_VAR_DECLARE( material );
  204. SWF_NATIVE_VAR_DECLARE( materialWidth );
  205. SWF_NATIVE_VAR_DECLARE( materialHeight );
  206. SWF_NATIVE_VAR_DECLARE( xOffset );
  207. SWF_NATIVE_VAR_DECLARE( onEnterFrame );
  208. //SWF_NATIVE_VAR_DECLARE( onLoad );
  209. };
  210. #endif