MCPcopy Create free account
hub / github.com/Meridian59/Meridian59 / LoadRoom

Function LoadRoom

roomedit/source/load.cpp:272–508  ·  view source on GitHub ↗

/ * LoadRoom: Load the room editor part of the room file, and set Vertices, * Linedefs, etc. * Return True on success. */

Source from the content-addressed store, hash-verified

270 * Return True on success.
271 */
272BOOL LoadRoom(int infile)
273{
274 int i, j, temp;
275 BYTE byte;
276 long node_pos, cwall_pos, rwall_pos, sector_pos, thing_pos, sidedef_pos;
277
278 // Check magic number and version
279 for (i = 0; i < 4; i++)
280 if (read(infile, &byte, 1) != 1 || byte != room_magic[i])
281 return FALSE;
282
283 if (read(infile, &room_version, 4) != 4 || room_version > ROO_VERSION)
284 return FALSE;
285
286 // Skip room security check
287 if (read(infile, &temp, 4) != 4) return FALSE;
288
289 // Seek to main section of the file
290 if (read(infile, &temp, 4) != 4) return FALSE;
291 lseek(infile, temp, SEEK_SET);
292
293 // Skip width and height
294 if (read(infile, &temp, 4) != 4) return FALSE;
295 if (read(infile, &temp, 4) != 4) return FALSE;
296
297 // Read subsection locations
298 if (read(infile, &node_pos, 4) != 4) return FALSE;
299 if (read(infile, &cwall_pos, 4) != 4) return FALSE;
300 if (read(infile, &rwall_pos, 4) != 4) return FALSE;
301 if (read(infile, &sidedef_pos, 4) != 4) return FALSE;
302 if (read(infile, &sector_pos, 4) != 4) return FALSE;
303 if (read(infile, &thing_pos, 4) != 4) return FALSE;
304
305 NumThings = 0;
306 NumVertexes = 0;
307 NumLineDefs = 0;
308 NumSideDefs = 0;
309 NumSectors = 0;
310 NumFileSideDefs = 0;
311
312 MapMaxX = MAP_MIN_X;
313 MapMaxY = MAP_MIN_Y;
314 MapMinX = MAP_MAX_X;
315 MapMinY = MAP_MAX_Y;
316
317 // *** Read linedefs
318 lseek(infile, rwall_pos, SEEK_SET);
319 if (read(infile, &NumLineDefs, 2) != 2) return FALSE;
320 if (NumLineDefs < 1)
321 {
322 ProgError("While loading roo file it specified %d Line Defs",(int)NumLineDefs);
323 }
324 LineDefs = (LDPtr)GetMemory (NumLineDefs * sizeof (LineDef));
325 SideDefs = (SDPtr)GetMemory (2 * NumLineDefs * sizeof (SideDef));
326 Vertexes = (VPtr)GetMemory (2 * NumLineDefs * sizeof (Vertex));
327
328 NumSideDefs = 2 * NumLineDefs;
329

Callers 1

ReadLevelDataFunction · 0.85

Calls 8

ProgErrorFunction · 0.85
AddVertexFunction · 0.85
SetSideDefsFunction · 0.85
ReadSlopeInfoFunction · 0.85
FindTextureByNumberFunction · 0.85
FindRoomBoundaryFunction · 0.85
LogMessageFunction · 0.85
SafeFreeFunction · 0.50

Tested by

no test coverage detected