AnimThing.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // AnimThing.H
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 02/18/97 JMI Started.
  23. //
  24. // 02/19/97 JMI Added ability to send any message to any CThing when done
  25. // with animation.
  26. //
  27. // 02/19/97 JMI Unprotected more members.
  28. //
  29. // 02/24/97 JMI Changed declaration of m_sprite from CAlphaSprite2 to
  30. // CSprite2.
  31. //
  32. // 02/24/97 JMI Changed m_pthingSendMsg to m_u16IdSendMsg.
  33. //
  34. // 02/26/97 JMI Now sets m_sprite.m_pthing = this on construction.
  35. //
  36. // 03/13/97 JMI Load now takes a version number.
  37. //
  38. // 06/24/97 JMI Now intializes m_msg's priority to 0 on construction for
  39. // safety.
  40. //
  41. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  42. //
  43. //////////////////////////////////////////////////////////////////////////////
  44. //
  45. // This CThing-derived class will play an animation to its finish and then
  46. // destroy itself. It's a mini Postal movie player.
  47. //
  48. //////////////////////////////////////////////////////////////////////////////
  49. #ifndef ANIMTHING_H
  50. #define ANIMTHING_H
  51. #include "RSPiX.h"
  52. #include "realm.h"
  53. #include "AlphaAnimType.h"
  54. class CAnimThing : public CThing
  55. {
  56. //---------------------------------------------------------------------------
  57. // Types, enums, etc.
  58. //---------------------------------------------------------------------------
  59. public:
  60. typedef RChannel<CAlphaAnim> ChannelAA;
  61. //---------------------------------------------------------------------------
  62. // Variables
  63. //---------------------------------------------------------------------------
  64. public:
  65. double m_dX;
  66. double m_dY;
  67. double m_dZ;
  68. short m_sSuspend; // Suspend flag
  69. short m_sLoop; // Loops, if true.
  70. char m_szResName[RSP_MAX_PATH]; // Resource name.
  71. long m_lAnimTime; // Cummulative animation time.
  72. long m_lAnimPrevTime; // Last animation time.
  73. U16 m_u16IdSendMsg; // ID of CThing to send msg to when done.
  74. GameMessage m_msg; // Message to send to m_pthingSendMsg.
  75. protected:
  76. CSprite2 m_sprite; // Sprite.
  77. ChannelAA* m_paachannel; // Animation (with or without alpha).
  78. //---------------------------------------------------------------------------
  79. // Constructor(s) / destructor
  80. //---------------------------------------------------------------------------
  81. public:
  82. // Constructor
  83. CAnimThing(CRealm* pRealm)
  84. : CThing(pRealm, CAnimThingID)
  85. {
  86. m_paachannel = NULL;
  87. m_sSuspend = 0;
  88. m_sLoop = TRUE;
  89. m_szResName[0] = '\0';
  90. m_msg.msg_Generic.sPriority = 0;
  91. m_u16IdSendMsg = CIdBank::IdNil;
  92. m_sprite.m_pthing = this;
  93. }
  94. public:
  95. // Destructor
  96. ~CAnimThing()
  97. {
  98. // Remove sprite from scene (this is safe even if it was already removed!)
  99. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  100. // Free resources
  101. FreeResources();
  102. }
  103. //---------------------------------------------------------------------------
  104. // Required static functions
  105. //---------------------------------------------------------------------------
  106. public:
  107. // Construct object
  108. static short Construct( // Returns 0 if successfull, non-zero otherwise
  109. CRealm* pRealm, // In: Pointer to realm this object belongs to
  110. CThing** ppNew) // Out: Pointer to new object
  111. {
  112. short sResult = 0;
  113. *ppNew = new CAnimThing(pRealm);
  114. if (*ppNew == 0)
  115. {
  116. sResult = -1;
  117. TRACE("CExplode::Construct(): Couldn't construct CAnimThing (that's a bad thing)\n");
  118. }
  119. return sResult;
  120. }
  121. //---------------------------------------------------------------------------
  122. // Required virtual functions (implimenting them as inlines doesn't pay!)
  123. //---------------------------------------------------------------------------
  124. public:
  125. // Load object (should call base class version!)
  126. short Load( // Returns 0 if successfull, non-zero otherwise
  127. RFile* pFile, // In: File to load from
  128. bool bEditMode, // In: True for edit mode, false otherwise
  129. short sFileCount, // In: File count (unique per file, never 0)
  130. ULONG ulFileVersion); // In: Version of file format to load.
  131. // Save object (should call base class version!)
  132. short Save( // Returns 0 if successfull, non-zero otherwise
  133. RFile* pFile, // In: File to save to
  134. short sFileCount); // In: File count (unique per file, never 0)
  135. // Startup object
  136. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  137. // Shutdown object
  138. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  139. // Suspend object
  140. void Suspend(void);
  141. // Resume object
  142. void Resume(void);
  143. // Update object
  144. void Update(void);
  145. // Render object
  146. void Render(void);
  147. short Setup( // Returns 0 on success.
  148. short sX, // In: New x coord
  149. short sY, // In: New y coord
  150. short sZ); // In: New z coord
  151. // Called by editor to init new object at specified position
  152. short EditNew( // Returns 0 if successfull, non-zero otherwise
  153. short sX, // In: New x coord
  154. short sY, // In: New y coord
  155. short sZ); // In: New z coord
  156. // Called by editor to modify object
  157. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  158. // Called by editor to move object to specified position
  159. short EditMove( // Returns 0 if successfull, non-zero otherwise
  160. short sX, // In: New x coord
  161. short sY, // In: New y coord
  162. short sZ); // In: New z coord
  163. // Called by editor to get the clickable pos/area of an object in 2D.
  164. virtual // Overridden here.
  165. void EditRect( // Returns nothiing.
  166. RRect* prc); // Out: Clickable pos/area of object.
  167. // Called by editor to get the hotspot of an object in 2D.
  168. virtual // Overridden here.
  169. void EditHotSpot( // Returns nothiing.
  170. short* psX, // Out: X coord of 2D hotspot relative to
  171. // EditRect() pos.
  172. short* psY); // Out: Y coord of 2D hotspot relative to
  173. // EditRect() pos.
  174. // Called by editor to update object
  175. void EditUpdate(void);
  176. // Called by editor to render object
  177. void EditRender(void);
  178. // Get the coordinates of this thing.
  179. virtual // Overriden here.
  180. double GetX(void) { return m_dX; }
  181. virtual // Overriden here.
  182. double GetY(void) { return m_dY; }
  183. virtual // Overriden here.
  184. double GetZ(void) { return m_dZ; }
  185. //---------------------------------------------------------------------------
  186. // Internal functions
  187. //---------------------------------------------------------------------------
  188. protected:
  189. // Get all required resources
  190. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  191. // Free all resources
  192. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  193. };
  194. #endif // ANIMTHING_H
  195. ////////////////////////////////////////////////////////////////////////////////
  196. // EOF
  197. ////////////////////////////////////////////////////////////////////////////////