ANIMSPRT.H 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. // ANIMSPRT.H
  19. //
  20. // Created on 3/15/95 BRH
  21. // Implemented on 3/21/95 BRH
  22. //
  23. // The RAnimSprite class is derived from the Sprite class. It adds
  24. // animation capabilities to the basic sprite.
  25. //
  26. // History:
  27. //
  28. // 10/31/96 BRH Changed names from CAnimSprite to RAnimSprite for
  29. // the new RSPiX naming convention.
  30. //
  31. // 11/01/96 JMI Changed:
  32. // Old label: New label:
  33. // ========= =========
  34. // CImage RImage
  35. //
  36. //////////////////////////////////////////////////////////////////////
  37. #ifndef animsprt_h
  38. #define animsprt_h
  39. #include "System.h"
  40. // If PATHS_IN_INCLUDES macro is defined, we can utilized relative
  41. // paths to a header file. In this case we generally go off of our
  42. // RSPiX root directory. System.h MUST be included before this macro
  43. // is evaluated. System.h is the header that, based on the current
  44. // platform (or more so in this case on the compiler), defines
  45. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  46. // instead.
  47. #ifdef PATHS_IN_INCLUDES
  48. // Orange includes
  49. #include "ORANGE/GameLib/SPRITE.H"
  50. #include "ORANGE/File/file.h"
  51. #else
  52. // Orange includes
  53. #include "sprite.h"
  54. #include "file.h"
  55. #endif // PATHS_IN_INCLUDES
  56. #ifdef _MSC_VER
  57. #pragma warning (disable:4200) // disable warning about zero-length arrays
  58. #endif
  59. // These masks are used with the animation flags
  60. #define ANIMSPRITE_FLAG_LOOP 0x0001 // 1=loop anim, 0=stop at end
  61. #define ANIMSPRITE_FLAG_NOSKIP 0x0002 // 1=can't skip frames, 0=can
  62. #define ANIMSPRITE_FLAG_OFFSET 0x0004 // 1=add anim offsets to sprite
  63. #define ANIMSPRITE_FLAG_ROTATION 0x0008 // 1=modify rotation of sprite
  64. #define ANIMSPRITE_FLAG_SCALE 0x0010 // 1=modify sprite's scale
  65. #define ANIMSPRITE_FLAG_END 0x0100 // 1=ending frame, 0=other
  66. #define ANIMSPRITE_FLAG_KEY 0x0200 // 1=key frame, 0=other
  67. #define ANIMSPRITE_LAST_FRAME -1
  68. #define ANIMSPRITE_FIRST_FRAME -2
  69. #define ANIMSPRITE_WAITING -3
  70. #define ANIMSPRITE_CURRENT_VERSION 0
  71. #define ANIMSPRITE_COOKIE 0x4d494e41 //"ANIM" in the file
  72. // Error codes
  73. #define ANIM_INVALID_FRAME 1 // Current anim does not contain
  74. // A FRAME contains offsets that describe how the hotspot should be moved
  75. // in order to get to the position at which the specified IMAGE should be
  76. // displayed. The "hold" value tells how many milliseconds this FRAME should
  77. // be held for before moving on to the next frame. The sPicIndex is stored
  78. // in the animation file to associate this frame with one of the animation's
  79. // pictures. Once the pictures are loaded, the pImage pointer is set to the
  80. // image for this frame. This way multiple frames can use the same picture.
  81. typedef struct tag_FRAME
  82. {
  83. short sOffsetX; // amount to add to sprite's X position for this frame
  84. short sOffsetY; // amount to add to sprite's Y position for this frame
  85. short sOffsetZ; // amount to add to sprite's Z position for this frame
  86. short sRotDeg; // Rotation in Degrees
  87. long lScaleWidth;// Scaled width for this frame
  88. long lScaleHeight;//Scaled height for this frame
  89. ULONG ulFlags; // Flags for this frame
  90. short sHold; // number of milliseconds to hold this frame
  91. short sPicIndex; // Animation's picture index for this frame (used to load)
  92. RImage* pImage; // pointer to the image for this frame
  93. } FRAME;
  94. class RAnimSprite : public RSprite
  95. {
  96. private:
  97. short m_sVersion; // Animation version number (to mark .ani files)
  98. short m_sAllocatedPics; // Keep track of number allocated (user can't change)
  99. public: // so Load can check the header format
  100. short m_sNumFrames; // Number of frames in this animation
  101. short m_sNumPictures; // Number of RImages in this animation
  102. short m_sLoopToFrame; // -1 if no loop, or frame number to start loop
  103. ULONG m_ulAnimFlags; // Animation flags and status
  104. long m_lTimer; // timer used for animating
  105. short m_sCurrFrame; // current frame in the animation
  106. FRAME* m_aFrames; // Array of frame structures
  107. RImage** m_apPictures; // Array of RImage*
  108. public:
  109. RAnimSprite();
  110. ~RAnimSprite();
  111. // Load an animation from a .ani file with this filename
  112. short Load(char* pszFilename);
  113. // Load an animation from an open RFile
  114. short Load(RFile* pcf);
  115. // Save this animation to a .ani file and give it this filename
  116. short Save(char* pszFilename);
  117. // Save this animation to an open RFile
  118. short Save(RFile* pcf);
  119. // Go to the next frame of animation if it is time
  120. short Animate(void);
  121. // Set to specified frame in current animation.
  122. // Updates m_sAnimFrameNum, m_sAnimFrameNum and m_usAnimFlags.
  123. // NOTE: If frame is too high then ending frame is used.
  124. // NOTE: A sequential search for specified frame is required!
  125. // NOTE: If ANIMSPRITE_FLAGS_NOSKIP flag is set, nearest key-frame
  126. // is used (nearest before, nearest after, or just nearest?)
  127. short SetFrame(short sFrameNum);
  128. // Go on to next frame of current anim. If anim was on ending frame
  129. // then this will wrap back around to frame 1 (not frame 0!)
  130. // Updates m_sAnimFrameNum, m_sAnimFrameNum and m_usAnimFlags.
  131. short NextFrame(void);
  132. // Go on to next key frame of current anim. If anim was on ending frame
  133. // then this will wrap back around to frame 1 (not frame 0!)
  134. // Updates m_sAnimFrameNum, m_sAnimFrameNum and m_usAnimFlags.
  135. short NextKeyFrame(void);
  136. // Go on to previous frame of current anim. If anim was on first frame
  137. // then this will wrap around to the end frame
  138. short PrevFrame(void);
  139. // Function to allocate space for given number of frames
  140. short AllocateFrames(short sNumFrames);
  141. // Function to allocate space for given number of RImage pointers
  142. short AllocatePictures(short sNumPictures);
  143. // Function to free frames if you allocated them
  144. short FreeFrames(void);
  145. // Function to free pictues if you allocated them
  146. short FreePictures(void);
  147. // Return a pointer to the current frame's RImage
  148. RImage* GetFrameImage(void)
  149. {
  150. if (m_sCurrFrame >= 0 && m_sCurrFrame < m_sNumFrames)
  151. return m_aFrames[m_sCurrFrame].pImage;
  152. else
  153. return NULL;
  154. };
  155. // Return a pointer to a specified frame's RImage
  156. RImage* GetFrameImage(short sFrameNumber)
  157. {
  158. if (sFrameNumber >= 0 && sFrameNumber < m_sNumFrames)
  159. return m_aFrames[sFrameNumber].pImage;
  160. else
  161. return NULL;
  162. }
  163. // Return a pointer to the current frame
  164. FRAME* GetFrame(void)
  165. {
  166. return &(m_aFrames[m_sCurrFrame]);
  167. };
  168. // Get the current frame's hold time
  169. short GetFrameTime(void)
  170. {
  171. return m_aFrames[m_sCurrFrame].sHold;
  172. };
  173. private:
  174. // Function used by Save to loop through and save all of the images
  175. short WritePictures(RFile* pcf);
  176. // Function used by Save to loop through and save all of the frames
  177. short WriteFrames(RFile* pcf);
  178. // Function used by Load to loop through and load all of the images
  179. short ReadPictures(RFile* pcf);
  180. // Function used by Load to loop through and load all of the frames
  181. short ReadFrames(RFile* pcf);
  182. };
  183. #endif //animsprt_h
  184. //*****************************************************************************
  185. // EOF
  186. //*****************************************************************************