gcsx_animgroup.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* GCSx
  2. ** ANIMGROUP.H
  3. **
  4. ** Animation group support, objects and drawing
  5. ** Doesn't include any editor-only functionality
  6. */
  7. /*****************************************************************************
  8. ** Copyright (C) 2003-2006 Janson
  9. **
  10. ** This program is free software; you can redistribute it and/or modify
  11. ** it under the terms of the GNU General Public License as published by
  12. ** the Free Software Foundation; either version 2 of the License, or
  13. ** (at your option) any later version.
  14. **
  15. ** This program is distributed in the hope that it will be useful,
  16. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ** GNU General Public License for more details.
  19. **
  20. ** You should have received a copy of the GNU General Public License
  21. ** along with this program; if not, write to the Free Software
  22. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  23. *****************************************************************************/
  24. #ifndef __GCSx_ANIMGROUP_H_
  25. #define __GCSx_ANIMGROUP_H_
  26. // One tile within a animation image
  27. class AnimComponent {
  28. public:
  29. class TileSet* tileset;
  30. Uint16 index; // specifically allowed to go past # of tiles without error- just blank
  31. Uint16 x; // ranges from 0 to size of image - 1
  32. Uint16 y; // (editor tries to enforce "size of image minus size of tile", but
  33. // this could be exceeded in some situations)
  34. Uint8 r;
  35. Uint8 g;
  36. Uint8 b;
  37. Uint8 alpha;
  38. Uint8 effects; // See enum
  39. enum {
  40. EFFECTS_FLIP = 0x01,
  41. EFFECTS_MIRROR = 0x02,
  42. EFFECTS_ROTATE = 0x04,
  43. EFFECTS_ALL = 0x07,
  44. };
  45. AnimComponent();
  46. };
  47. // An entire single animation image or frame
  48. class AnimFrame {
  49. public:
  50. AnimComponent* comps;
  51. int count; // zero is ok
  52. Sint16 xOrigin; // point of origin for display- 0,0 for standard upperleft corner
  53. Sint16 yOrigin;
  54. Sint16 xOffs; // no limit- this is the amount the sprite itself moves by
  55. Sint16 yOffs;
  56. Uint8 delay; // cycles to delay- 1 or more
  57. AnimFrame();
  58. ~AnimFrame();
  59. void setCount(int newCount);
  60. const AnimFrame& operator=(const AnimFrame& from);
  61. };
  62. // An entire animation sequence (one or more frames)
  63. class AnimSequence {
  64. public:
  65. std::string name; // @TODO: lowercase?
  66. AnimFrame* frames;
  67. int width;
  68. int height;
  69. int count; // minimum one frame once created/loaded, although constructed with zero
  70. enum AnimLoop {
  71. LOOP_NONE = 0,
  72. LOOP_FORWARD,
  73. LOOP_PINGPONG,
  74. };
  75. AnimLoop loopType;
  76. AnimSequence();
  77. ~AnimSequence();
  78. void setCount(int newCount);
  79. const AnimSequence& operator=(const AnimSequence& from);
  80. };
  81. class AnimGroup : virtual public LoadOnly {
  82. protected:
  83. // Is the library cached to our file and not in memory?
  84. int cached;
  85. FileRead* cacheFile;
  86. int lockCount;
  87. // Name of animation group, where it's located
  88. std::string name;
  89. std::string nameL;
  90. class World* world;
  91. // Numeric ID- computer-generated- unique to world- nonzero
  92. int id;
  93. // Default size for a new animation
  94. int defWidth;
  95. int defHeight;
  96. // Number of animations
  97. int numAnim;
  98. AnimSequence* anims; // CACHEABLE
  99. enum {
  100. // Default image size, when creating a blank set
  101. IMAGE_DEFAULT_SIZE = 32,
  102. };
  103. public:
  104. // Id must be unique; use ID of 0 if we're going to load anyways
  105. AnimGroup(class World* myWorld, int myId = 0); // Starts with default settings
  106. virtual ~AnimGroup();
  107. // Do any of our animation frames use a given tileset?
  108. int usesTileSet(const class TileSet* tileset) const;
  109. // Accessors
  110. int getCount() const { return numAnim; }
  111. const std::string& getName() const { return name; }
  112. const std::string& getNameL() const { return nameL; }
  113. const class World* getWorld() const { return world; }
  114. class World* getWorld() { return world; }
  115. int getId() const { return id; }
  116. int getBlockType() const { return WorldFileLoad::BLOCKTYPE_ANIMGROUP; }
  117. // File access
  118. void loadHeader(FileRead* file) throw_File;
  119. void loadContent(FileRead* file);
  120. int isContentCached() const;
  121. void cacheLoad() throw_File;
  122. int markLock() throw_File;
  123. int markUnlock();
  124. int isLocked() const;
  125. // Any content-accessor functions- remember to call markLock first!
  126. };
  127. #endif