ScummVM API documentation
savepoint.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 LASTEXPRESS_SAVEPOINT_H
23 #define LASTEXPRESS_SAVEPOINT_H
24 
25 #include "lastexpress/helpers.h"
26 #include "lastexpress/shared.h"
27 
28 #include "common/array.h"
29 #include "common/list.h"
30 #include "common/serializer.h"
31 
32 /*
33  Savepoint format
34  ----------------
35 
36  Save point: max: 127 - FIFO list (ie. goes back and overwrites first save point when full)
37  uint32 {4} - Entity 1
38  uint32 {4} - Action
39  uint32 {4} - Entity 2
40  uint32 {4} - Parameter
41 
42  Save point Data
43  uint32 {4} - Entity 1
44  uint32 {4} - Action
45  uint32 {4} - Entity 2
46  uint32 {4} - function pointer to ??
47 
48 */
49 
50 namespace LastExpress {
51 
52 class LastExpressEngine;
53 
54 struct SavePoint {
55  EntityIndex entity1;
56  ActionIndex action;
57  EntityIndex entity2;
58  union {
59  uint32 intValue;
60  char charValue[7]; // "MUS%03d" with terminating zero
61  } param;
62 
63  SavePoint() {
64  entity1 = kEntityPlayer;
65  action = kActionNone;
66  entity2 = kEntityPlayer;
67  param.intValue = 0;
68  param.charValue[6] = 0;
69  }
70 
71  Common::String toString() {
72  return Common::String::format("{ %s - %d - %s - %s }", ENTITY_NAME(entity1), action, ENTITY_NAME(entity2), param.charValue);
73  }
74 };
75 
77 
79 public:
80 
81  struct SavePointData {
82  EntityIndex entity1;
83  ActionIndex action;
84  EntityIndex entity2;
85  uint32 param;
86 
87  SavePointData() {
88  entity1 = kEntityPlayer;
89  action = kActionNone;
90  entity2 = kEntityPlayer;
91  param = 0;
92  }
93 
94  Common::String toString() {
95  return Common::String::format(" { %s - %d - %s - %d }", ENTITY_NAME(entity1), action, ENTITY_NAME(entity2), param);
96  }
97  };
98 
100  ~SavePoints() override;
101 
102  // Savepoints
103  void push(EntityIndex entity2, EntityIndex entity1, ActionIndex action, uint32 param = 0);
104  void push(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const Common::String param);
105  void pushAll(EntityIndex entity, ActionIndex action, uint32 param = 0);
106  void process();
107  void reset();
108 
109  // Data
110  void addData(EntityIndex entity, ActionIndex action, uint32 param);
111 
112  // Callbacks
113  void setCallback(EntityIndex index, Callback *callback);
114  Callback *getCallback(EntityIndex entity) const;
115  void call(EntityIndex entity2, EntityIndex entity1, ActionIndex action, uint32 param = 0) const;
116  void call(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const Common::String param) const;
117  void callAndProcess();
118 
119  // Serializable
120  void saveLoadWithSerializer(Common::Serializer &s) override;
121 
127  Common::String toString();
128 
129  uint32 count() { return _savepoints.size(); }
130 
131 private:
132  static const uint32 _savePointsMaxSize = 128;
133 
134  LastExpressEngine *_engine;
135 
136  Common::List<SavePoint> _savepoints;
138  Callback *_callbacks[40];
139 
140  SavePoint pop();
141  bool updateEntityFromData(const SavePoint &point);
142 };
143 
144 } // End of namespace LastExpress
145 
146 #endif // LASTEXPRESS_SAVEPOINT_H
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: savepoint.h:78
Definition: lastexpress.h:69
Definition: array.h:52
Definition: list.h:44
Definition: animation.h:45
Definition: serializer.h:79
Definition: savepoint.h:54
Definition: savepoint.h:81
Definition: serializer.h:308
Definition: func.h:437