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

Function AllocLoadRoom

editor/Erooms.cpp:923–1072  ·  view source on GitHub ↗

Allocates a room and then tries to load it Returns index into Rooms[] array on success -1 on fail

Source from the content-addressed store, hash-verified

921// Returns index into Rooms[] array on success
922// -1 on fail
923int AllocLoadRoom(char *filename, bool bCenter, bool palette_room) {
924 CFILE *infile;
925 int done = 0, initted = 0;
926 int command, len, room_num = -1, i;
927 room *rp;
928 char texture_names[MAX_TEXTURES][PAGENAME_LEN];
929 int highest_index;
930 int16_t tex_index;
931 int room_version = 0;
932
933 infile = (CFILE *)cfopen(filename, "rb");
934 if (!infile) {
935 Int3(); // hey, couldn't load this room!
936 return -1;
937 }
938
939 while (!done) {
940 command = cf_ReadInt(infile);
941 len = cf_ReadInt(infile);
942
943 switch (command) {
944 // Read room header stuff
945 case ROOM_HEADER_CHUNK:
946 case ROOM_NEW_HEADER_CHUNK:
947 int num_verts, num_faces;
948
949 if (command == ROOM_NEW_HEADER_CHUNK)
950 room_version = cf_ReadInt(infile);
951 num_verts = cf_ReadInt(infile);
952 num_faces = cf_ReadInt(infile);
953
954 // room_num=AllocRoom (num_verts,num_faces);
955 rp = CreateNewRoom(num_verts, num_faces, palette_room);
956
957 if (rp == NULL) {
958 done = 1;
959 continue;
960 }
961
962 initted = 1;
963 break;
964
965 case ROOM_VERTEX_CHUNK:
966 if (!initted) {
967 Int3(); // bad format info, get jason
968 done = 1;
969 break;
970 }
971 for (i = 0; i < rp->num_verts; i++) {
972 rp->verts[i].x = cf_ReadFloat(infile);
973 rp->verts[i].y = cf_ReadFloat(infile);
974 rp->verts[i].z = cf_ReadFloat(infile);
975 }
976 break;
977 case ROOM_TEXTURE_CHUNK:
978 if (!initted) {
979 Int3(); // bad format info, get jason
980 done = 1;

Callers 1

OnLoadRoomMethod · 0.85

Calls 15

cfopenFunction · 0.85
cf_ReadIntFunction · 0.85
CreateNewRoomFunction · 0.85
cf_ReadFloatFunction · 0.85
cf_ReadStringFunction · 0.85
cf_ReadByteFunction · 0.85
InitRoomFaceFunction · 0.85
cf_ReadShortFunction · 0.85
FindTextureNameFunction · 0.85
Float_to_ubyteFunction · 0.85
cfcloseFunction · 0.85
ResetRoomFaceNormalsFunction · 0.85

Tested by

no test coverage detected