ScummVM API documentation
scenestream.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 NANCY_STATE_SCENESTREAM_H
23 #define NANCY_STATE_SCENESTREAM_H
24 
25 #include "common/array.h"
26 #include "common/str.h"
27 
28 #include "engines/nancy/commontypes.h"
29 #include "engines/nancy/puzzledata.h"
30 
31 #include "engines/nancy/action/actionmanager.h"
32 
33 namespace Common {
34 class SeekableReadStream;
35 }
36 
37 namespace Nancy {
38 
39 struct NancyInput;
40 
41 namespace UI {
42 class Viewport;
43 }
44 
45 namespace Script {
46 class SceneContext;
47 struct Message;
48 }
49 
50 namespace State {
51 
52 // What a stream gets started with
53 struct StreamFlags {
54  enum Lifetime {
55  kIndependent = 0,
56  kEndsWithParentScene = 1, // ...and with the parent itself
57  kEndsWithParent = 2
58  };
59 
60  void read(Common::SeekableReadStream &stream);
61 
62  byte lifetime = kIndependent;
63  bool capturesInput = false; // the streams after this one get no input
64  bool runsFirst = false; // put in front of the running streams
65  int32 zOffset = 0; // added to the z order of everything the stream draws
66 };
67 
68 // Nancy17 runs several scenes side by side, each in a stream of its own. The scene
69 // the player walks around in is the main stream, and is still handled by the Scene
70 // state itself; this is one of the others. Those play the ambient sounds of an
71 // environment, fill the journal, show a close-up or a phone call on top of the main
72 // scene, and so on. A scene change made by a stream's records only changes the scene
73 // of that stream.
74 class SceneStream {
75 public:
76  typedef StreamData::Child Child;
77 
78  // The z offset is the stream's own on top of the one of the stream that started it
79  SceneStream(const Common::String &name, const StreamFlags &flags, int32 zOffset);
80  ~SceneStream();
81 
82  // Runs the records of the stream's scene, and loads the next scene when one got
83  // requested. Returns false once the stream is over.
84  bool update();
85  void handleInput(NancyInput &input);
86 
87  // Nancy19: the scripts of the scene store what they keep in a saved game
88  void onSave();
89 
90  // Nancy19: hands a message to the scene. Returns false when it isn't for it.
91  bool receiveMessage(const Script::Message &message, bool &wasTaken);
92 
93  void changeScene(const Common::String &sceneName, uint16 frameID);
94  void end() { _isEnded = true; }
95  bool isEnded() const { return _isEnded; }
96 
97  // Nancy20: lets the records of the scene know that it is being left
98  void endScene();
99 
100  // Loads the scene the stream was asked to go to, without running it.
101  // Returns whether there was one, and it could be loaded.
102  bool loadNextScene();
103 
104  void setEventFlag(int16 index, byte flag);
105  byte getEventFlag(int16 index) const;
106 
107  const Common::String &getName() const { return _name; }
108  const StreamFlags &getFlags() const { return _flags; }
109  int32 getZOffset() const { return _zOffset; }
110  const Common::String &getSceneName() const { return _sceneName; }
111  SceneChangeDescription &getSceneInfo() { return _sceneInfo; }
112  Action::ActionManager &getActionManager() { return _actionManager; }
113 
114  Common::Array<Child> _children;
115 
116 private:
117  bool loadScene();
118 #ifdef ENABLE_NANCY_V4
119  bool loadScriptedScene(); // Nancy19+
120 #endif
121  void beginScene();
122  void loadBackground(const Common::Path &videoFile);
123  void clearScene();
124  void processRecords();
125 
126  Common::String _name;
127  StreamFlags _flags;
128  int32 _zOffset;
129 
130  Common::String _sceneName;
131  SceneChangeDescription _sceneInfo;
132  Action::ActionManager _actionManager;
133  UI::Viewport *_background = nullptr;
134 
135 #ifdef ENABLE_NANCY_V4
136  // Nancy19: the script of the scene, which takes the place of the action records
137  Script::SceneContext *_scriptScene = nullptr;
138 #endif
139 
140  // Every stream has generic event flags of its own
141  Common::Array<byte> _genericFlags;
142 
143  bool _hasNextScene = false;
144  Common::String _nextSceneName;
145  uint16 _nextFrameID = 0;
146 
147  bool _isEnded = false;
148 };
149 
150 // The streams running next to the main one. Where a stream gets named, no name
151 // stands for the stream whose records are running.
153 public:
154  void begin(const Common::String &name, const Common::String &sceneName, uint16 frameID, const StreamFlags &flags);
155  void end(const Common::String &name);
156 
157  // Loads the scene a stream that was just begun starts with right away,
158  // instead of with the next frame
159  void loadNow(const Common::String &name);
160 
161  void changeScene(const Common::String &name, const SceneChangeDescription &sceneDescription);
162  void changeScene(const Common::String &name, const Common::String &sceneName, uint16 frameID);
163  Common::String getSceneName(const Common::String &name) const;
164  bool isRunning(const Common::String &name) const { return find(name) != nullptr; }
165 
166  // The stream whose records are running or getting input; null for the main one
167  SceneStream *getRunning() const { return _running; }
168 
169  void process();
170  bool handleInput(NancyInput &input, bool beforeMainStream);
171 
172  void clear();
173  bool isEmpty() const { return _streams.empty(); }
174 
175  void onMainSceneChange();
176  void changeEnvironment(const Common::String &newEnvironment);
177 
178  // Nancy19: hands a message to the scenes of the streams it is for. Returns
179  // false when there is none.
180  bool receiveMessage(const Script::Message &message, bool &wasTaken);
181 
182  // Keeps the streams in the saved game, and starts them again after loading
183  void store();
184  void restore();
185 
186 private:
187  SceneStream *find(const Common::String &name) const;
188  void endChildren(const Common::Array<SceneStream::Child> &children);
189 
190  // Every stream in the order they run and get input in. The main stream is
191  // the scene itself, and takes part as a null entry.
193  Common::Array<SceneStream::Child> _mainStreamChildren;
194  SceneStream *_running = nullptr;
195  Common::String _environment;
196 };
197 
198 } // End of namespace State
199 } // End of namespace Nancy
200 
201 #endif // NANCY_STATE_SCENESTREAM_H
Definition: types.h:91
Definition: str.h:59
Definition: viewport.h:42
Definition: commontypes.h:186
Definition: scenestream.h:74
Definition: array.h:52
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Definition: path.h:52
Definition: stream.h:745
Definition: input.h:41
Definition: puzzledata.h:631
Definition: scenecontext.h:52
Definition: scenestream.h:53
Definition: actionmanager.h:48
Definition: soundequalizerpuzzle.h:27
Definition: algorithm.h:29
Definition: scenestream.h:152
Definition: actionmanager.h:32