GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — UZDoom/src/p_openmap.cpp at trunk · UZDoom/UZDoom

Expand file tree

/

p_openmap.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
404 lines (367 loc) · 9.91 KB
/

p_openmap.cpp

Copy path

File metadata and controls

404 lines (367 loc) · 9.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
** p_openmap.cpp
**
** creates the data structures needed to load a map from the resource files.
**
**---------------------------------------------------------------------------
**
** Copyright 2005-2016 Marisa Heit
** Copyright 2005-2018 Christoph Oelckers
** Copyright 2017-2025 GZDoom Maintainers and Contributors
** Copyright 2025-2026 UZDoom Maintainers and Contributors
**
** SPDX-License-Identifier: GPL-3.0-or-later
**
**---------------------------------------------------------------------------
**
** Code written prior to 2026 is also licensed under:
**
** SPDX-License-Identifier: BSD-3-Clause
**
**---------------------------------------------------------------------------
**
*/
#include "p_setup.h"
#include "cmdlib.h"
#include "filesystem.h"
#include "md5.h"
#include "g_levellocals.h"
#include "cmdlib.h"
#define IWAD_ID MAKE_ID('I','W','A','D')
#define PWAD_ID MAKE_ID('P','W','A','D')
inline bool P_IsBuildMap(MapData *map)
{
return false;
}
//===========================================================================
//
// GetMapIndex
//
// Gets the type of map lump or -1 if invalid or -2 if required and not found.
//
//===========================================================================
struct checkstruct
{
const char lumpname[9];
bool required;
};
static int GetMapIndex(const char *mapname, int lastindex, const char *lumpname, bool needrequired)
{
static const checkstruct check[] =
{
{"", true},
{"THINGS", true},
{"LINEDEFS", true},
{"SIDEDEFS", true},
{"VERTEXES", true},
{"SEGS", false},
{"SSECTORS", false},
{"NODES", false},
{"SECTORS", true},
{"REJECT", false},
{"BLOCKMAP", false},
{"BEHAVIOR", false},
{"LIGHTMAP", false },
//{"SCRIPTS", false},
};
if (lumpname==NULL) lumpname="";
for(size_t i=lastindex+1;i<countof(check);i++)
{
if (!strnicmp(lumpname, check[i].lumpname, 8))
return (int)i;
if (check[i].required)
{
if (needrequired)
{
I_Error("'%s' not found in %s\n", check[i].lumpname, mapname);
}
return -2;
}
}
return -1; // End of map reached
}
//===========================================================================
//
// Opens a map for reading
//
//===========================================================================
MapData *P_OpenMapData(const char * mapname, bool justcheck)
{
MapData * map = new MapData;
FileReader * wadReader = nullptr;
bool externalfile = !strnicmp(mapname, "file:", 5);
if (externalfile)
{
mapname += 5;
if (!FileExists(mapname))
{
delete map;
return NULL;
}
map->resource = FResourceFile::OpenResourceFile(mapname);
wadReader = map->resource->GetContainerReader();
}
else
{
FString fmt;
int lump_wad;
int lump_map;
int lump_name = -1;
// Check for both *.wad and *.map in order to load Build maps
// as well. The higher one will take precedence.
// Names with more than 8 characters will only be checked as .wad and .map.
if (strlen(mapname) <= 8) lump_name = fileSystem.CheckNumForName(mapname);
fmt.Format("maps/%s.wad", mapname);
lump_wad = fileSystem.CheckNumForFullName(fmt.GetChars());
fmt.Format("maps/%s.map", mapname);
lump_map = fileSystem.CheckNumForFullName(fmt.GetChars());
if (lump_name > lump_wad && lump_name > lump_map && lump_name != -1)
{
int lumpfile = fileSystem.GetFileContainer(lump_name);
int nextfile = fileSystem.GetFileContainer(lump_name+1);
map->lumpnum = lump_name;
if (lumpfile != nextfile)
{
// The following lump is from a different file so whatever this is,
// it is not a multi-lump Doom level so let's assume it is a Build map.
map->MapLumps[0].Reader = fileSystem.ReopenFileReader(lump_name);
if (!P_IsBuildMap(map))
{
delete map;
return NULL;
}
return map;
}
// This case can only happen if the lump is inside a real WAD file.
// As such any special handling for other types of lumps is skipped.
map->MapLumps[0].Reader = fileSystem.ReopenFileReader(lump_name);
strncpy(map->MapLumps[0].Name, fileSystem.GetFileFullName(lump_name), 8);
map->InWad = true;
int index = 0;
if (stricmp(fileSystem.GetFileFullName(lump_name + 1), "TEXTMAP") != 0)
{
for(int i = 1;; i++)
{
// Since levels must be stored in WADs they can't really have full
// names and for any valid level lump this always returns the short name.
const char * lumpname = fileSystem.GetFileFullName(lump_name + i);
try
{
index = GetMapIndex(mapname, index, lumpname, !justcheck);
}
catch(...)
{
delete map;
throw;
}
if (index == -2)
{
delete map;
return NULL;
}
if (index == ML_BEHAVIOR) map->HasBehavior = true;
// The next lump is not part of this map anymore
if (index < 0) break;
map->MapLumps[index].Reader = fileSystem.ReopenFileReader(lump_name + i);
strncpy(map->MapLumps[index].Name, lumpname, 8);
}
}
else
{
map->isText = true;
map->MapLumps[1].Reader = fileSystem.ReopenFileReader(lump_name + 1);
for(int i = 2;; i++)
{
const char * lumpname = fileSystem.GetFileFullName(lump_name + i);
if (lumpname == NULL)
{
I_Error("Invalid map definition for %s", mapname);
}
else if (!stricmp(lumpname, "ZNODES"))
{
index = ML_GLZNODES;
}
else if (!stricmp(lumpname, "BLOCKMAP"))
{
// there is no real point in creating a blockmap but let's use it anyway
index = ML_BLOCKMAP;
}
else if (!stricmp(lumpname, "REJECT"))
{
index = ML_REJECT;
}
else if (!stricmp(lumpname, "DIALOGUE"))
{
index = ML_CONVERSATION;
}
else if (!stricmp(lumpname, "BEHAVIOR"))
{
index = ML_BEHAVIOR;
map->HasBehavior = true;
}
else if (!stricmp(lumpname, "LIGHTMAP"))
{
index = ML_LIGHTMAP;
}
else if (!stricmp(lumpname, "ENDMAP"))
{
break;
}
else continue;
map->MapLumps[index].Reader = fileSystem.ReopenFileReader(lump_name + i);
strncpy(map->MapLumps[index].Name, lumpname, 8);
}
}
return map;
}
else
{
if (lump_map > lump_wad)
{
lump_wad = lump_map;
}
if (lump_wad == -1)
{
delete map;
return NULL;
}
map->lumpnum = lump_wad;
auto reader = fileSystem.ReopenFileReader(lump_wad);
map->resource = FResourceFile::OpenResourceFile(fileSystem.GetFileFullName(lump_wad), reader, true);
wadReader = map->resource->GetContainerReader();
}
}
uint32_t id;
// Although we're using the resource system, we still want to be sure we're
// reading from a wad file.
wadReader->Seek(0, FileReader::SeekSet);
wadReader->Read(&id, sizeof(id));
if (id == IWAD_ID || id == PWAD_ID)
{
char maplabel[9]="";
int index=0;
map->MapLumps[0].Reader = map->resource->GetEntryReader(0, FileSys::READER_SHARED);
uppercopy(map->MapLumps[0].Name, map->resource->getName(0));
for(uint32_t i = 1; i < map->resource->EntryCountU(); i++)
{
const char* lumpname = map->resource->getName(i);
if (i == 1 && !strnicmp(lumpname, "TEXTMAP", 8))
{
map->isText = true;
map->MapLumps[ML_TEXTMAP].Reader = map->resource->GetEntryReader(i, FileSys::READER_SHARED);
strncpy(map->MapLumps[ML_TEXTMAP].Name, lumpname, 8);
for(int i = 2;; i++)
{
lumpname = map->resource->getName(i);
if (!strnicmp(lumpname, "ZNODES",8))
{
index = ML_GLZNODES;
}
else if (!strnicmp(lumpname, "BLOCKMAP",8))
{
// there is no real point in creating a blockmap but let's use it anyway
index = ML_BLOCKMAP;
}
else if (!strnicmp(lumpname, "REJECT",8))
{
index = ML_REJECT;
}
else if (!strnicmp(lumpname, "DIALOGUE",8))
{
index = ML_CONVERSATION;
}
else if (!strnicmp(lumpname, "BEHAVIOR",8))
{
index = ML_BEHAVIOR;
map->HasBehavior = true;
}
else if (!strnicmp(lumpname, "LIGHTMAP", 8))
{
index = ML_LIGHTMAP;
}
else if (!strnicmp(lumpname, "ENDMAP",8))
{
return map;
}
else continue;
map->MapLumps[index].Reader = map->resource->GetEntryReader(i, FileSys::READER_SHARED);
strncpy(map->MapLumps[index].Name, lumpname, 8);
}
}
if (i>0)
{
try
{
index = GetMapIndex(maplabel, index, lumpname, !justcheck);
}
catch(...)
{
delete map;
throw;
}
if (index == -2)
{
delete map;
return NULL;
}
if (index == ML_BEHAVIOR) map->HasBehavior = true;
// The next lump is not part of this map anymore
if (index < 0) break;
}
else
{
strncpy(maplabel, lumpname, 8);
maplabel[8]=0;
}
map->MapLumps[index].Reader = map->resource->GetEntryReader(i, FileSys::READER_SHARED);
strncpy(map->MapLumps[index].Name, lumpname, 8);
}
}
else
{
// This is a Build map and not subject to WAD consistency checks.
//map->MapLumps[0].Size = wadReader->GetLength();
if (!P_IsBuildMap(map))
{
delete map;
return NULL;
}
}
return map;
}
bool P_CheckMapData(const char *mapname)
{
MapData *mapd = P_OpenMapData(mapname, true);
if (mapd == NULL) return false;
delete mapd;
return true;
}
//===========================================================================
//
// MapData :: GetChecksum
//
// Hashes a map based on its header, THINGS, LINEDEFS, SIDEDEFS, SECTORS,
// and BEHAVIOR lumps. Node-builder generated lumps are not included.
//
//===========================================================================
void MapData::GetChecksum(uint8_t cksum[16])
{
MD5Context md5;
if (isText)
{
md5Update(Reader(ML_TEXTMAP), md5, Size(ML_TEXTMAP));
}
else
{
md5Update(Reader(ML_LABEL), md5, Size(ML_LABEL));
md5Update(Reader(ML_THINGS), md5, Size(ML_THINGS));
md5Update(Reader(ML_LINEDEFS), md5, Size(ML_LINEDEFS));
md5Update(Reader(ML_SIDEDEFS), md5, Size(ML_SIDEDEFS));
md5Update(Reader(ML_SECTORS), md5, Size(ML_SECTORS));
}
if (HasBehavior)
{
md5Update(Reader(ML_BEHAVIOR), md5, Size(ML_BEHAVIOR));
}
md5.Final(cksum);
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.