MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ReadRoom

Function ReadRoom

Descent3/LoadLevel.cpp:2437–2631  ·  view source on GitHub ↗

Reads a room from a disk file Parameters: ifile - file to read from rp - room to read version - version number of file Returns: 1 if read ok, else 0

Source from the content-addressed store, hash-verified

2435// version - version number of file
2436// Returns: 1 if read ok, else 0
2437int ReadRoom(CFILE *ifile, room *rp, int version) {
2438 int i, nverts, nfaces, nportals;
2439
2440 ASSERT(rp->used == 0); // should be free
2441
2442 // Get counts for room elements
2443 nverts = cf_ReadInt(ifile);
2444 nfaces = cf_ReadInt(ifile);
2445 nportals = cf_ReadInt(ifile);
2446
2447 // Initialize the room
2448 InitRoom(rp, nverts, nfaces, nportals);
2449
2450 // Get room name
2451 rp->name = NULL;
2452 if (version >= 96) {
2453 char tempname[ROOM_NAME_LEN + 1];
2454 cf_ReadString(tempname, sizeof(tempname), ifile);
2455 if (strlen(tempname)) {
2456 rp->name = (char *)mem_malloc(strlen(tempname) + 1);
2457 strcpy(rp->name, tempname);
2458 }
2459 }
2460
2461 // Read path point
2462 if (version >= 63) {
2463 cf_ReadVector(ifile, &rp->path_pnt);
2464 }
2465
2466 // Read in verts
2467 for (i = 0; i < rp->num_verts; i++) {
2468 cf_ReadVector(ifile, &rp->verts[i]);
2469 if (version >= 52 && version <= 67) {
2470 cf_ReadByte(ifile);
2471 cf_ReadByte(ifile);
2472 } else if (version >= 68 && version < 71) {
2473 vector tempv;
2474 cf_ReadVector(ifile, &tempv);
2475 cf_ReadShort(ifile);
2476 }
2477
2478 // Update checksum
2479 AppendToLevelChecksum(rp->verts[i]);
2480 }
2481
2482 // Read in faces
2483 for (i = 0; i < rp->num_faces; i++) {
2484 bool t;
2485
2486 // Load the face
2487 ReadFace(ifile, &rp->faces[i], version);
2488
2489 for (int k = 0; k < rp->faces[i].num_verts; k++) {
2490 AppendToLevelChecksum(rp->faces[i].face_verts[k]);
2491 }
2492 AppendToLevelChecksum(rp->faces[i].tmap);
2493
2494 // Get the surface normal for this face

Callers 2

LoadGroupFunction · 0.85
LoadLevelFunction · 0.85

Calls 14

cf_ReadIntFunction · 0.85
InitRoomFunction · 0.85
cf_ReadStringFunction · 0.85
cf_ReadByteFunction · 0.85
cf_ReadShortFunction · 0.85
AppendToLevelChecksumFunction · 0.85
ReadFaceFunction · 0.85
ComputeFaceNormalFunction · 0.85
ReadPortalFunction · 0.85
cf_ReadFloatFunction · 0.85
FindValidIDFunction · 0.85
DoorwayAddFunction · 0.85

Tested by

no test coverage detected