Allocates a room and then tries to load it Returns index into Rooms[] array on success -1 on fail
| 921 | // Returns index into Rooms[] array on success |
| 922 | // -1 on fail |
| 923 | int 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; |
no test coverage detected