File: savegame.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (179 lines) | stat: -rw-r--r-- 5,988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef AGS_ENGINE_GAME_SAVEGAME_H
#define AGS_ENGINE_GAME_SAVEGAME_H

#include "common/std/memory.h"
#include "ags/shared/core/platform.h"
#include "ags/shared/ac/game_version.h"
#include "ags/shared/util/error.h"
#include "ags/shared/util/version.h"

namespace AGS3 {
namespace AGS {

namespace Shared {
class Bitmap;
class Stream;
} // namespace Shared

namespace Engine {

using Shared::Bitmap;
using Shared::ErrorHandle;
using Shared::TypedCodeError;
using Shared::Stream;
using Shared::String;
using Shared::Version;

typedef std::shared_ptr<Stream> PStream;

//-----------------------------------------------------------------------------
// Savegame version history
//
// 8      last old style saved game format (of AGS 3.2.1)
// 9      first new style (self-descriptive block-based) format version
// Since 3.6.0: value is defined as AGS version represented as NN,NN,NN,NN.
//-----------------------------------------------------------------------------
enum SavegameVersion {
	kSvgVersion_Undefined = 0,
	kSvgVersion_321 = 8,
	kSvgVersion_Components = 9,
	kSvgVersion_Cmp_64bit = 10,
	kSvgVersion_350_final = 11,
	kSvgVersion_350_final2 = 12,
	kSvgVersion_351 = 13,
	kSvgVersion_360_beta = 3060023,
	kSvgVersion_360_final = 3060041,
	kSvgVersion_361 = 3060115,
	kSvgVersion_Current = kSvgVersion_361,
	kSvgVersion_LowestSupported = kSvgVersion_321 // change if support dropped
};

// Error codes for save restoration routine
enum SavegameErrorType {
	kSvgErr_NoError,
	kSvgErr_FileOpenFailed,
	kSvgErr_SignatureFailed,
	kSvgErr_FormatVersionNotSupported,
	kSvgErr_IncompatibleEngine,
	kSvgErr_GameGuidMismatch,
	kSvgErr_ComponentListOpeningTagFormat,
	kSvgErr_ComponentListClosingTagMissing,
	kSvgErr_ComponentOpeningTagFormat,
	kSvgErr_ComponentClosingTagFormat,
	kSvgErr_ComponentSizeMismatch,
	kSvgErr_UnsupportedComponent,
	kSvgErr_ComponentSerialization,
	kSvgErr_ComponentUnserialization,
	kSvgErr_InconsistentFormat,
	kSvgErr_UnsupportedComponentVersion,
	kSvgErr_GameContentAssertion,
	kSvgErr_InconsistentData,
	kSvgErr_InconsistentPlugin,
	kSvgErr_DifferentColorDepth,
	kSvgErr_GameObjectInitFailed,
	kNumSavegameError
};

String GetSavegameErrorText(SavegameErrorType err);

typedef TypedCodeError<SavegameErrorType, GetSavegameErrorText> SavegameError;
typedef ErrorHandle<SavegameError> HSaveError;

// SavegameSource defines a successfully opened savegame stream
struct SavegameSource {
	// Signature of the current savegame format
	static const char *Signature;
	// Signature of the legacy savegame format
	static const char *LegacySignature;

	// Name of the savefile
	String              Filename;
	// Savegame format version
	SavegameVersion     Version;
	// A ponter to the opened stream
	std::unique_ptr<Stream> InputStream;

	SavegameSource();
};

// Supported elements of savegame description;
// these may be used as flags to define valid fields
enum SavegameDescElem {
	kSvgDesc_None = 0,
	kSvgDesc_EnvInfo = 0x0001,
	kSvgDesc_UserText = 0x0002,
	kSvgDesc_UserImage = 0x0004,
	kSvgDesc_All = kSvgDesc_EnvInfo | kSvgDesc_UserText | kSvgDesc_UserImage
};

// SavegameDescription describes savegame with information about the environment
// it was created in, and custom data provided by user
struct SavegameDescription {
	// Name of the engine that saved the game
	String              EngineName;
	// Version of the engine that saved the game
	Version             EngineVersion;
	// Guid of the game which made this save
	String              GameGuid;
	// Legacy uniqueid of the game, for use in older games with no GUID
	int                 LegacyID;
	// Title of the game which made this save
	String              GameTitle;
	// Name of the main data file used; this is needed to properly
	// load saves made by "minigames"
	String              MainDataFilename;
	// Game's main data version; should be checked early to know
	// if the save was made for the supported game format
	GameDataVersion     MainDataVersion;
	// Native color depth of the game; this is required to
	// properly restore dynamic graphics from the save
	int                 ColorDepth;

	String              UserText;
	std::unique_ptr<Bitmap> UserImage;

	SavegameDescription();
};


// Opens savegame for reading; optionally reads description, if any is provided
HSaveError     OpenSavegame(const String &filename, SavegameSource &src,
                            SavegameDescription &desc, SavegameDescElem elems = kSvgDesc_All);
// Opens savegame and reads the savegame description
HSaveError     OpenSavegame(const String &filename, SavegameDescription &desc, SavegameDescElem elems = kSvgDesc_All);

// Reads the game data from the save stream and reinitializes game state
HSaveError     RestoreGameState(Stream *in, SavegameVersion svg_version);

// Opens savegame for writing and puts in savegame description
Stream *StartSavegame(const String &filename, const String &user_text, const Bitmap *user_image);

// Prepares game for saving state and writes game data into the save stream
void           SaveGameState(Stream *out);

} // namespace Engine
} // namespace AGS
} // namespace AGS3

#endif