ScummVM API documentation
sprite.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TWINE_PARSER_SPRITE_H
23 #define TWINE_PARSER_SPRITE_H
24 
25 #include "common/array.h"
26 #include "common/memstream.h"
27 #include "common/stream.h"
28 #include "graphics/managed_surface.h"
29 #include "twine/parser/parser.h"
30 #include "twine/shared.h"
31 
32 namespace TwinE {
33 
34 struct SpriteDim {
35  int16 x = 0;
36  int16 y = 0;
37  int16 w = 0;
38  int16 h = 0;
39 };
40 
41 // PtrZvExtra
42 class SpriteBoundingBoxData : public Parser {
43 private:
44  Common::Array<BoundingBox> _boundingBoxes;
45  Common::Array<SpriteDim> _dimensions;
46 
47 public:
48  bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
49 
50  const BoundingBox *bbox(int index) const; // PtrZvAnim3DS, PtrZvExtra, PtrZvExtraRaw
51  const SpriteDim *dim(int index) const;
52 };
53 
54 inline const BoundingBox *SpriteBoundingBoxData::bbox(int index) const {
55  if (index < 0) {
56  return nullptr;
57  }
58  return &_boundingBoxes[index];
59 }
60 
61 inline const SpriteDim *SpriteBoundingBoxData::dim(int index) const {
62  if (index < 0) {
63  return nullptr;
64  }
65  return &_dimensions[index];
66 }
67 
68 class SpriteData : public Parser {
69 protected:
70  Graphics::ManagedSurface _surfaces[2];
71  int _offsetX[2] {0};
72  int _offsetY[2] {0};
73  int _sprites = 0;
74  bool _bricks = false;
75 
76  bool loadSprite(Common::SeekableReadStream &stream, uint32 offset);
77  void reset() override;
78 public:
79  bool loadFromStream(Common::SeekableReadStream &stream, bool lba1) override;
80 
81  inline const Graphics::ManagedSurface &surface(int index = 0) const {
82  if (index < 0 || index >= _sprites) {
83  error("Sprite surface index out of range: %i (max: %i)", index, _sprites);
84  }
85  return _surfaces[index];
86  }
87 
88  inline int sprites() const {
89  return _sprites;
90  }
91 
92  inline int offsetX(int index = 0) const {
93  if (index < 0 || index >= _sprites) {
94  error("Sprite offset index out of range: %i (max: %i)", index, _sprites);
95  }
96  return _offsetX[index];
97  }
98 
99  inline int offsetY(int index = 0) const {
100  if (index < 0 || index >= _sprites) {
101  error("Sprite offset index out of range: %i (max: %i)", index, _sprites);
102  }
103  return _offsetY[index];
104  }
105 };
106 
107 class BrickData : public SpriteData {
108 public:
109  BrickData() {
110  _bricks = true;
111  }
112 };
113 
114 } // End of namespace TwinE
115 
116 #endif
Definition: managed_surface.h:51
Definition: sprite.h:42
Definition: array.h:52
Definition: stream.h:745
Definition: sprite.h:34
Definition: sprite.h:68
Definition: achievements_tables.h:27
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: parser.h:32
Axis aligned bounding box.
Definition: shared.h:188
Definition: sprite.h:107