ScummVM API documentation
movie.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 #ifndef SCUMM_INSANE_MORTIMER_MOVIE_H
22 #define SCUMM_INSANE_MORTIMER_MOVIE_H
23 
24 #include "common/array.h"
25 #include "common/rect.h"
26 #include "common/str.h"
27 
28 namespace Common {
29 class SeekableReadStream;
30 }
31 
32 namespace Graphics {
33 struct Surface;
34 }
35 
36 namespace Scumm {
37 
38 class SmushDeltaBlocksDecoder;
39 
41  int x, y, width, height;
42  Common::Array<byte> pixels;
43  // Codec 44 uses skipped pixels for transparency and relative palette colors.
45 
46  void draw(Graphics::Surface &screen, int dstX, int dstY, bool centered = false, const Common::Rect *bounds = nullptr, int scale = 1) const;
47 };
48 
49 struct MortimerSound {
50  uint frame = 0;
51  uint rate = 11025;
52  byte volume = 127;
53  int8 balance = 0;
54  bool music = false;
55  bool speech = true;
56  Common::Array<byte> samples;
57  Common::Array<byte> script;
58 };
59 
61  enum Condition { kAtGate, kHasStones, kHostilesRemain, kAnimalsRemain, kDamaged, kOutOfGuesses, kConditionCount };
62  bool girl = false;
63  int riddle = -1;
64  bool conditions[kConditionCount] = {};
65  bool matches(uint code) const;
66 };
67 
68 bool loadMortimerSprites(Common::SeekableReadStream &stream, Common::Array<MortimerSprite> &sprites, byte *palette = nullptr);
69 bool loadMortimerSound(Common::SeekableReadStream &stream, MortimerSound &sound);
70 
71 // Mortimer's SMUSH movie reader. Gameplay supplies the IACT and SKIP rules.
73 public:
74  enum { kScreenWidth = 640, kScreenHeight = 480 };
75  struct Caption {
76  int16 x, y;
77  uint16 id;
78  };
79 
80  MortimerMovie();
81  virtual ~MortimerMovie();
82  bool load(Common::SeekableReadStream &stream, bool doubled = true, bool continuation = false);
83  virtual void reset();
84  // Suppress compositing while seeking to a frame that replaces the image.
85  virtual bool advance(bool renderFrame = true);
86  void setBackground(const byte *pixels);
87 
88  const byte *pixels() const { return _pixels.begin(); }
89  const byte *palette() const { return _palette; }
90  uint frame() const { return _nextFrame ? _nextFrame - 1 : 0; }
91  uint frameCount() const { return _frames.size(); }
92  bool started() const { return _nextFrame != 0; }
93  uint frameRate() const { return _frameRate; }
94  const Common::Array<MortimerSound> &sounds() const { return _sounds; }
95  const Common::Array<Caption> &captions() const { return _captions; }
96  bool soundEnabled(uint index) const { return _soundEnabled[index]; }
97  const Common::Array<byte> &cachedMovie() const { return _cachedMovie; }
98  const Common::String &errorMessage() const { return _error; }
99 
100 protected:
101  virtual void handleAction(const byte *data, uint32 size);
102  virtual bool skipObject(uint16 a, uint16 b) const { return false; }
103  virtual int objectScale(byte codec) const;
104  void render();
105 
106 private:
107  struct Frame {
108  uint32 offset, size;
109  };
110  struct Object {
111  uint32 offset = 0, size = 0;
112  uint16 skipA = 0xffff, skipB = 0;
113  int x = 0, y = 0, width = 0, height = 0, scale = 1;
114  byte codec = 0;
115  bool transparent = false;
116  byte remap[256] = {};
117  Common::Array<byte> pixels;
118  };
119 
120  bool fail(const char *message);
121  void handlePalette(const byte *data, uint32 size);
122  bool decodeObject(Object &object);
123 
124  Common::Array<byte> _data, _pixels, _previous, _scratch, _background;
125  Common::Array<Frame> _frames;
126  Common::Array<Object> _objects;
128  Common::Array<uint32> _soundOffsets;
129  Common::Array<bool> _soundEnabled;
130  Common::Array<byte> _cachedMovie;
131  uint _cacheBlock;
132  Common::Array<Caption> _captions;
133  Object _storedObject;
134  SmushDeltaBlocksDecoder *_decoder;
135  Common::String _error;
136  byte _palette[768], _initialPalette[768], _remap[256];
137  int16 _paletteDelta[768];
138  int32 _shiftedPalette[768];
139  int _decoderWidth, _decoderHeight;
140  bool _doubled, _initialDoubled, _storeNext;
141  uint _nextFrame, _frameRate;
142 };
143 
145 public:
146  explicit MortimerCutscene(bool girl = false);
147  void reset() override;
148  MortimerMovieContext &context() { return _context; }
149  const MortimerMovieContext &context() const { return _context; }
150 
151 protected:
152  void handleAction(const byte *data, uint32 size) override;
153  bool skipObject(uint16 a, uint16 b) const override;
154  bool toggle(uint16 id) const { return id > 0 && id <= 1024 && _toggles[id - 1]; }
155  void setToggle(uint16 id, bool value) { if (id > 0 && id <= 1024) _toggles[id - 1] = value; }
156 
157 private:
158  MortimerMovieContext _context;
159  bool _toggles[1024];
160 };
161 
162 } // End of namespace Scumm
163 
164 #endif
Definition: str.h:59
Definition: surface.h:67
Definition: codec37.h:29
Definition: movie.h:49
Definition: movie.h:144
Definition: movie.h:75
Definition: rect.h:536
Definition: stream.h:745
Definition: movie.h:60
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: movie.h:72
Definition: movie.h:40
Definition: actor.h:30