ScummVM API documentation
room_file.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 //=============================================================================
23 //
24 // This unit provides functions for reading compiled room file (CRM)
25 // into the RoomStruct structure, as well as extracting separate components,
26 // such as room scripts.
27 //
28 //=============================================================================
29 
30 #ifndef AGS_SHARED_GAME_ROOM_FILE_H
31 #define AGS_SHARED_GAME_ROOM_FILE_H
32 
33 #include "common/std/memory.h"
34 #include "common/std/vector.h"
35 #include "ags/shared/core/platform.h"
36 #include "ags/shared/game/room_version.h"
37 #include "ags/shared/util/error.h"
38 #include "ags/shared/util/stream.h"
39 #include "ags/shared/util/string.h"
40 
41 namespace AGS3 {
42 
43 struct SpriteInfo;
44 namespace AGS {
45 namespace Shared {
46 
47 class RoomStruct;
48 
49 enum RoomFileErrorType {
50  kRoomFileErr_NoError,
51  kRoomFileErr_FileOpenFailed,
52  kRoomFileErr_FormatNotSupported,
53  kRoomFileErr_BlockListFailed,
54  kRoomFileErr_UnknownBlockType,
55  kRoomFileErr_OldBlockNotSupported,
56  kRoomFileErr_BlockDataOverlapping,
57  kRoomFileErr_IncompatibleEngine,
58  kRoomFileErr_ScriptLoadFailed,
59  kRoomFileErr_InconsistentData,
60  kRoomFileErr_PropertiesBlockFormat,
61  kRoomFileErr_InvalidPropertyValues,
62  kRoomFileErr_BlockNotFound
63 };
64 
65 enum RoomFileBlock {
66  kRoomFblk_None = 0,
67  // Main room data
68  kRoomFblk_Main = 1,
69  // Room script text source (was present in older room formats)
70  kRoomFblk_Script = 2,
71  // Old versions of compiled script (no longer supported)
72  kRoomFblk_CompScript = 3,
73  kRoomFblk_CompScript2 = 4,
74  // Names of the room objects
75  kRoomFblk_ObjectNames = 5,
76  // Secondary room backgrounds
77  kRoomFblk_AnimBg = 6,
78  // Contemporary compiled script
79  kRoomFblk_CompScript3 = 7,
80  // Custom properties
81  kRoomFblk_Properties = 8,
82  // Script names of the room objects
83  kRoomFblk_ObjectScNames = 9,
84  // End of room data tag
85  kRoomFile_EOF = 0xFF
86 };
87 
88 String GetRoomFileErrorText(RoomFileErrorType err);
89 String GetRoomBlockName(RoomFileBlock id);
90 
91 typedef TypedCodeError<RoomFileErrorType, GetRoomFileErrorText> RoomFileError;
92 typedef ErrorHandle<RoomFileError> HRoomFileError;
93 #ifdef AGS_PLATFORM_SCUMMVM
94 typedef std::shared_ptr<Stream> UStream;
95 #else
96 typedef std::unique_ptr<Stream> UStream;
97 #endif
98 
99 
100 // RoomDataSource defines a successfully opened room file
102  // Name of the asset file
103  String Filename;
104  // Room file format version
105  RoomFileVersion DataVersion;
106  // A ponter to the opened stream
107  UStream InputStream;
108 
109  RoomDataSource();
110 };
111 
112 // Opens room data for reading from an arbitrary file
113 HRoomFileError OpenRoomFile(const String &filename, RoomDataSource &src);
114 // Opens room data for reading from asset of a given name
115 HRoomFileError OpenRoomFileFromAsset(const String &filename, RoomDataSource &src);
116 // Reads room data
117 HRoomFileError ReadRoomData(RoomStruct *room, Stream *in, RoomFileVersion data_ver);
118 // Applies necessary updates, conversions and fixups to the loaded data
119 // making it compatible with current engine
120 HRoomFileError UpdateRoomData(RoomStruct *room, RoomFileVersion data_ver, bool game_is_hires, const std::vector<SpriteInfo> &sprinfos);
121 // Extracts text script from the room file, if it's available.
122 // Historically, text sources were kept inside packed room files before AGS 3.*.
123 HRoomFileError ExtractScriptText(String &script, Stream *in, RoomFileVersion data_ver);
124 // Writes all room data to the stream
125 HRoomFileError WriteRoomData(const RoomStruct *room, Stream *out, RoomFileVersion data_ver);
126 
127 // Reads room data header using stream assigned to RoomDataSource;
128 // tests and saves its format index if successful
129 HRoomFileError ReadRoomHeader(RoomDataSource &src);
130 
131 typedef void(*PfnWriteRoomBlock)(const RoomStruct *room, Stream *out);
132 // Writes room block with a new-style string id
133 void WriteRoomBlock(const RoomStruct *room, const String &ext_id, PfnWriteRoomBlock writer, Stream *out);
134 // Writes room block with a old-style numeric id
135 void WriteRoomBlock(const RoomStruct *room, RoomFileBlock block, PfnWriteRoomBlock writer, Stream *out);
136 
137 } // namespace Shared
138 } // namespace AGS
139 } // namespace AGS3
140 
141 #endif
Definition: achievements_tables.h:27
Definition: vector.h:39
Definition: room_file.h:101
Definition: ptr.h:572
Definition: string.h:62
Definition: room_struct.h:270
Definition: ptr.h:159
Definition: stream.h:52
Definition: ags.h:40