ScummVM API documentation
score.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 DIRECTOR_SCORE_H
23 #define DIRECTOR_SCORE_H
24 
25 #include "director/cursor.h"
26 
27 namespace Graphics {
28  struct Surface;
29  class ManagedSurface;
30  class Font;
31  class MacWindow;
32  struct ZoomBox;
33 }
34 
35 namespace Common {
36  class ReadStreamEndian;
37  class MemoryReadStreamEndian;
38  class SeekableReadStreamEndian;
39  class SeekableWriteStream;
40 }
41 
42 namespace Director {
43 
44 class Window;
45 class Archive;
46 class DirectorEngine;
47 class DirectorSound;
48 class Frame;
49 class Movie;
50 struct Resource;
51 class Cursor;
52 class Channel;
53 class Sprite;
54 class CastMember;
55 class AudioDecoder;
56 struct BehaviorElement;
57 struct SpriteInfo;
58 
59 struct Label {
60  Common::String comment;
61  Common::String name;
62  uint16 number;
63  Label(Common::String name1, uint16 number1, Common::String comment1) { name = name1; number = number1; comment = comment1;}
64 };
65 
66 class Score {
67 public:
68  Score(Movie *movie);
69  ~Score();
70 
71  Movie *getMovie() const { return _movie; }
72 
73  void loadFrames(Common::SeekableReadStreamEndian &stream, uint16 version);
74  bool loadFrame(int frame, bool loadCast);
75  bool readOneFrame();
76  void updateFrame(Frame *frame);
77  Frame *getFrameData(int frameNum);
78 
79  void writeVWSCResource(Common::SeekableWriteStream *writeStream, uint32 offset);
80  uint32 getVWSCResourceSize();
81 
82  void loadLabels(Common::SeekableReadStreamEndian &stream);
83  void loadActions(Common::SeekableReadStreamEndian &stream);
84  void loadSampleSounds(uint type);
85 
86  static int compareLabels(const void *a, const void *b);
87  uint16 getLabel(Common::String &label);
88  Common::String *getLabelList();
89  Common::String *getFrameLabel(uint id);
90  void setStartToLabel(Common::String &label);
91  void gotoLoop();
92  void gotoNext();
93  void gotoPrevious();
94  void startPlay();
95  void step();
96  void stopPlay();
97  void setDelay(uint32 ticks);
98 
99  void setCurrentFrame(uint16 frameId);
100  uint16 getCurrentFrameNum() { return _curFrameNumber; }
101  int getNextFrame() { return _nextFrame; }
102  uint16 getFramesNum() { return _numFrames; }
103 
104  void setPuppetTempo(int16 puppetTempo);
105 
106  CastMemberID getCurrentPalette();
107 
108  Channel *getChannelById(uint16 id);
109  Sprite *getSpriteById(uint16 id);
110  Sprite *getOriginalSpriteById(uint16 id);
111 
112  void setSpriteCasts();
113 
114  int getPreviousLabelNumber(int referenceFrame);
115  int getCurrentLabelNumber();
116  int getNextLabelNumber(int referenceFrame);
117 
118  uint16 getSpriteIDOfActiveWidget();
119  uint16 getSpriteIDFromPos(Common::Point pos);
120  uint16 getMouseSpriteIDFromPos(Common::Point pos);
121  uint16 getActiveSpriteIDFromPos(Common::Point pos);
122  bool checkSpriteRollOver(uint16 spriteId, Common::Point pos);
123  uint16 getRollOverSpriteIDFromPos(Common::Point pos);
124  Common::List<Channel *> getSpriteIntersections(const Common::Rect &r);
125  uint16 getSpriteIdByMemberId(CastMemberID id);
126  bool refreshPointersForCastMemberID(CastMemberID id);
127  bool refreshPointersForCastLib(uint16 castLib);
128 
129  bool renderTransition(uint16 frameId, RenderMode mode);
130  void renderFrame(uint16 frameId, RenderMode mode = kRenderModeNormal, bool sound1Changed = true, bool sound2Changed = true);
131  void incrementFilmLoops();
132  void updateSprites(RenderMode mode = kRenderModeNormal, bool withClean = false);
133  bool renderPrePaletteCycle(RenderMode mode = kRenderModeNormal);
134  void setLastPalette();
135  bool isPaletteColorCycling();
136  void renderPaletteCycle(RenderMode mode = kRenderModeNormal);
137  void renderCursor(Common::Point pos, bool forceUpdate = false);
138  void updateWidgets(bool hasVideoPlayback);
139 
140  void invalidateRectsForMember(CastMember *member);
141 
142  void playSoundChannel(bool puppetOnly, bool sound1Changed = true, bool sound2Changed = true);
143 
144  Common::String formatChannelInfo();
145  bool processFrozenPlayScript();
146 
147  Common::MemoryReadStreamEndian *getSpriteDetailsStream(int spriteIdx);
148 
149  // They live in lingo/lingo-events.cpp
150  void killScriptInstances(int frameNum);
151  void createScriptInstances(int frameNum);
152  Datum createScriptInstance(BehaviorElement *behavior);
153 
154 private:
155  bool isWaitingForNextFrame();
156  void updateCurrentFrame();
157  void updateNextFrameTime();
158  void update();
159  void playQueuedSound();
160 
161  void screenShot();
162  bool checkShotSimilarity(const Graphics::Surface *surface1, const Graphics::Surface *surface2);
163 
164  bool processImmediateFrameScript(Common::String s, int id);
165  bool processFrozenScripts(bool recursion = false, int count = 0);
166 
167  void writeFrame(Common::SeekableWriteStream *writeStream, Frame frame, uint32 channelSize, uint32 mainChannelSize);
168 
169  void seekToMemberInList(int frame);
170 
171  void loadFrameSpriteDetails(bool skipLog);
172 
173  BehaviorElement loadSpriteBehavior(Common::MemoryReadStreamEndian *stream, bool skipLog);
174  SpriteInfo loadSpriteInfo(int spriteId, bool skipLog);
175 
176 public:
177  Common::Array<Channel *> _channels;
180  Common::HashMap<uint16, bool> _immediateActions;
181  Datum _scriptChannelScriptInstance;
182 
183  Common::Array<Frame *> _scoreCache;
184 
185  // On demand frames loading
186  uint32 _version;
187  Frame *_currentFrame;
188  uint32 _curFrameNumber;
189  uint32 _numFrames;
190  uint8 _currentTempo;
191  CastMemberID _currentPaletteId;
192 
193  // header D4+
194  uint32 _framesStreamSize;
195  int32 _frame1Offset;
196  int32 _numOfFrames;
197  uint16 _framesVersion;
198  uint16 _spriteRecordSize;
199  uint16 _numChannels;
200  int16 _numChannelsDisplayed; // D7+, no-op in earlier versions
201  // 20 bytes in total
202 
203  int16 _maxChannelsUsed; // max channel number used in the score, used to optimize rendering
204 
205  uint _firstFramePosition;
206  uint _indexStart = 0;
207  uint _frameDataOffset = 0;
208  Common::MemoryReadStreamEndian *_framesStream;
209 
210  byte _currentFrameRate;
211  byte _puppetTempo;
212 
213  bool _puppetPalette;
214  int _paletteTransitionIndex;
215  byte _paletteSnapshotBuffer[768];
216 
217  PlayState _playState;
218  uint32 _nextFrameTime;
219  uint32 _nextFrameDelay;
220  int _lastTempo;
221  int _waitForChannel;
222  int _waitForChannelCue;
223  int _waitForVideoChannel;
224  bool _waitForClick;
225  bool _waitForClickCursor;
226  bool _cursorDirty;
227  bool _activeFade;
228  bool _exitFrameCalled;
229  bool _stopPlayCalled;
230  Cursor _defaultCursor;
231  CursorRef _currentCursor;
232  bool _skipTransition;
233 
234  Common::Array<uint32> _spriteDetailOffsets;
235  Common::Array<bool> _spriteDetailAccessed;
236 
237  bool _disableGoPlayUpdateStage;
238 
239 private:
240  DirectorEngine *_vm;
241  Lingo *_lingo;
242  Movie *_movie;
243  Window *_window;
244 
245  uint16 _nextFrame;
246  int _currentLabel;
247  DirectorSound *_soundManager;
248 
249  int _previousBuildBotBuild = -1;
250  bool _firstRun = true;
251 };
252 
253 } // End of namespace Director
254 
255 #endif
Definition: cursor.h:73
Definition: str.h:59
Definition: surface.h:67
Definition: channel.h:40
Definition: array.h:52
Definition: list.h:44
Definition: rect.h:524
Definition: spriteinfo.h:87
Definition: window.h:106
Definition: movie.h:88
Definition: archive.h:36
Definition: memstream.h:103
Definition: cursor.h:41
Definition: sound.h:164
Definition: atari-cursor.h:35
Definition: algorithm.h:29
Definition: sprite.h:68
Definition: formatinfo.h:28
Definition: score.h:66
Definition: rect.h:144
Definition: array.h:559
Definition: lingo.h:130
Definition: stream.h:351
Definition: stream.h:944
Definition: director.h:157
Definition: spriteinfo.h:43
Definition: frame.h:180
Definition: score.h:59
Definition: castmember.h:48
Definition: lingo.h:356
Definition: types.h:419