ScummVM API documentation
gamesys.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 GNAP_GAMESYS_H
23 #define GNAP_GAMESYS_H
24 
25 #include "gnap/gnap.h"
26 #include "gnap/resource.h"
27 #include "common/array.h"
28 #include "common/rect.h"
29 #include "graphics/surface.h"
30 
31 namespace Gnap {
32 
33 const int kMaxSequenceItems = 40;
34 const int kMaxSpriteDrawItems = 30;
35 const int kMaxSoundIds = 50;
36 const int kMaxSeqItems = 50;
37 const int kMaxUpdRects = 20;
38 const int kMaxGfxItems = 50;
39 const int kMaxAnimations = 12;
40 
41 enum {
42  kSeqNone = 0x00,
43  kSeqScale = 0x01, // Enable scaling
44  kSeqLoop = 0x02, // Loop
45  kSeqUnk = 0x04, // Unknown
46  kSeqSyncWait = 0x08, // Start if other sequence is done
47  kSeqSyncExists = 0x20 // Start if other sequence exists
48 };
49 
50 struct Sequence {
51  int32 _sequenceId;
52  int32 _id;
53  int32 _sequenceId2;
54  int32 _id2;
55  uint32 _flags;
56  int32 _totalDuration;
57  int16 _x, _y;
58 };
59 
61  int _id;
62  Common::Rect _rect;
63  Graphics::Surface *_surface;
64 };
65 
67  int _sequenceId;
68  int _id;
69  bool _forceFrameReset;
70 };
71 
73  int _id;
74  Graphics::Surface *_surface;
75 };
76 
77 struct GfxItem {
78  int _sequenceId;
79  int _id;
80  int _flags;
81  SequenceAnimation *_animation;
82  int _currFrameNum;
83  int _delayTicks;
84  bool _updFlag;
85  int _updRectsCount;
86  Graphics::Surface *_surface;
87  Common::Rect _updRects[kMaxUpdRects];
88  SequenceFrame _prevFrame;
89  SequenceFrame _currFrame;
90  void testUpdRect(const Common::Rect &updRect);
91 };
92 
93 struct Animation {
94  int _sequenceId;
95  int _id;
96  int _status;
97 };
98 
99 class GameSys {
100 public:
101  GameSys(GnapEngine *vm);
102  ~GameSys();
103  void insertSequence(int sequenceId, int id, int sequenceId2, int id2, int flags, int totalDuration, int16 x, int16 y);
104  void insertDirtyRect(const Common::Rect &rect);
105  void removeSequence(int sequenceId, int id, bool resetFl);
106  void invalidateGrabCursorSprite(int id, Common::Rect &rect, Graphics::Surface *surface1, Graphics::Surface *surface2);
107  void requestClear2(bool resetFl);
108  void requestClear1();
109  void requestRemoveSequence(int sequenceId, int id);
110  void waitForUpdate();
111  int isSequenceActive(int sequenceId, int id);
112  void setBackgroundSurface(Graphics::Surface *surface, int a4, int a5, int a6, int a7);
113  void setScaleValues(int a1, int a2, int a3, int a4);
114  void insertSpriteDrawItem(Graphics::Surface *surface, int x, int y, int id);
115  void removeSpriteDrawItem(Graphics::Surface *surface, int id);
116  void drawSpriteToBackground(int x, int y, int resourceId);
117  Graphics::Surface *allocSurface(int width, int height);
118  Graphics::Surface *createSurface(int resourceId);
119  void drawSpriteToSurface(Graphics::Surface *surface, int x, int y, int resourceId);
120  void drawTextToSurface(Graphics::Surface *surface, int x, int y, byte r, byte g, byte b, const char *text);
121  int getTextHeight(const char *text);
122  int getTextWidth(const char *text);
123  void fillSurface(Graphics::Surface *surface, int x, int y, int width, int height, byte r, byte g, byte b);
124  void setAnimation(int sequenceId, int id, int animationIndex);
125  int getAnimationStatus(int animationIndex);
126  int getSpriteWidthById(int resourceId);
127  int getSpriteHeightById(int resourceId);
128  Graphics::Surface *loadBitmap(int resourceId);
129  void drawBitmap(int resourceId);
130 public:
131  GnapEngine *_vm;
132 
133  Common::Array<Common::Rect> _dirtyRects;
134 
135  SpriteDrawItem _newSpriteDrawItems[kMaxSpriteDrawItems];
136  int _newSpriteDrawItemsCount;
137 
138  RemoveSequenceItem _removeSequenceItems[kMaxSequenceItems];
139  int _removeSequenceItemsCount;
140 
141  RemoveSpriteDrawItem _removeSpriteDrawItems[kMaxSpriteDrawItems];
142  int _removeSpriteDrawItemsCount;
143 
144  int _grabSpriteId;
145  Common::Rect _grabSpriteRect;
146  bool _grabSpriteChanged;
147  Graphics::Surface *_grabSpriteSurface1, *_grabSpriteSurface2;
148 
149  bool _reqRemoveSequenceItem;
150  int _removeSequenceItemSequenceId, _removeSequenceItemValue;
151 
152  Common::Array<int> _soundIds;
153 
155 
156  Common::Array<Sequence> _seqItems;
157  Common::Array<Sequence> _fatSequenceItems;
158 
159  GfxItem _gfxItems[kMaxGfxItems];
160  int _gfxItemsCount;
161 
162  Animation _animations[kMaxAnimations];
163  int _animationsCount;
164 
165  int _backgroundImageValue3, _backgroundImageValue1;
166  int _backgroundImageValue4, _backgroundImageValue2;
167 
168  int32 _gameSysClock, _lastUpdateClock;
169  bool _animationsDone;
170 
171 
172  Graphics::Surface *_backgroundSurface;
173  Graphics::Surface *_frontSurface;
174  Common::Rect _screenRect;
175 
176  Sequence *seqFind(int sequenceId, int id, int *outIndex);
177  int seqLocateGfx(int sequenceId, int id, int *outGfxIndex);
178  void seqInsertGfx(int index, int duration);
179  void seqRemoveGfx(int sequenceId, int id);
180  bool updateSequenceDuration(int sequenceId, int id, int *outDuration);
181  void updateAnimationsStatus(int sequenceId, int id);
182 
183  void restoreBackgroundRect(const Common::Rect &rect);
184 
185  void blitSurface32(Graphics::Surface *destSurface, int x, int y, Graphics::Surface *sourceSurface,
186  Common::Rect &sourceRect, bool transparent);
187  void blitSprite32(Graphics::Surface *destSurface, int x, int y, byte *sourcePixels,
188  int sourceWidth, Common::Rect &sourceRect, uint32 *sourcePalette, bool transparent);
189  void blitSpriteScaled32(Graphics::Surface *destSurface, Common::Rect &frameRect,
190  Common::Rect &destRect, byte *sourcePixels, int sourceWidth, Common::Rect &sourceRect, uint32 *sourcePalette);
191 
192  void seqDrawStaticFrame(Graphics::Surface *surface, SequenceFrame &frame, Common::Rect *subRect);
193  void seqDrawSpriteFrame(SpriteResource *spriteResource, SequenceFrame &frame, Common::Rect *subRect);
194 
195  void drawSprites();
196  void updateRect(const Common::Rect &r);
197  void updateScreen();
198 
199  void handleReqRemoveSequenceItem();
200  void handleReqRemoveSequenceItems();
201  void handleReqRemoveSpriteDrawItems();
202  void fatUpdateFrame();
203  void fatUpdate();
204  void updatePlaySounds();
205 
206 };
207 
208 bool intersectRect(Common::Rect &intersectingRect, const Common::Rect &r1, const Common::Rect &r2);
209 
210 } // End of namespace Gnap
211 
212 #endif // GNAP_GAMESYS_H
Definition: gamesys.h:93
Definition: surface.h:67
Definition: gamesys.h:77
Definition: gamesys.h:66
Definition: rect.h:144
Definition: resource.h:56
Definition: resource.h:47
Definition: resource.h:84
Definition: character.h:25
Definition: gamesys.h:50
Definition: gnap.h:222
Definition: gamesys.h:60
Definition: gamesys.h:99
Definition: gamesys.h:72