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

Function SaveRoom

editor/Erooms.cpp:790–918  ·  view source on GitHub ↗

saves a room in our ORF (Outrage room file) format

Source from the content-addressed store, hash-verified

788
789// saves a room in our ORF (Outrage room file) format
790void SaveRoom(int n, char *filename) {
791 CFILE *outfile;
792 int headsize, savepos, vertsize, facesize, texsize;
793 int highest_index = 0;
794 int16_t Room_to_texture[MAX_TEXTURES];
795 int t, found_it = 0;
796
797 // Make sure its in use!
798 ASSERT(Rooms[n].used);
799
800 outfile = (CFILE *)cfopen(filename, "wb");
801 if (!outfile) {
802 mprintf(0, "Couldn't save room %s!\n", filename);
803 Int3();
804 return;
805 }
806
807 // write out header info
808 cf_WriteInt(outfile, ROOM_NEW_HEADER_CHUNK);
809 headsize = cftell(outfile);
810 cf_WriteInt(outfile, -1);
811
812 cf_WriteInt(outfile, ROOMFILE_VERSION);
813 cf_WriteInt(outfile, Rooms[n].num_verts);
814 cf_WriteInt(outfile, Rooms[n].num_faces);
815
816 savepos = cftell(outfile);
817 cfseek(outfile, headsize, SEEK_SET);
818 cf_WriteInt(outfile, (savepos - headsize) - 4);
819 cfseek(outfile, savepos, SEEK_SET);
820
821 // write out vertex info
822 cf_WriteInt(outfile, ROOM_VERTEX_CHUNK);
823 vertsize = cftell(outfile);
824 cf_WriteInt(outfile, -1);
825
826 for (int i = 0; i < Rooms[n].num_verts; i++) {
827 cf_WriteFloat(outfile, Rooms[n].verts[i].x);
828 cf_WriteFloat(outfile, Rooms[n].verts[i].y);
829 cf_WriteFloat(outfile, Rooms[n].verts[i].z);
830 }
831
832 savepos = cftell(outfile);
833 cfseek(outfile, vertsize, SEEK_SET);
834 cf_WriteInt(outfile, (savepos - vertsize) - 4);
835 cfseek(outfile, savepos, SEEK_SET);
836
837 // figure out correct texture ordering
838 for (i = 0; i < Rooms[n].num_faces; i++) {
839 int16_t index = Rooms[n].faces[i].tmap;
840
841 for (found_it = 0, t = 0; t < highest_index; t++) {
842 if (Room_to_texture[t] == index) {
843 // This texture is already there
844 found_it = 1;
845 break;
846 }
847 }

Callers 2

OnSaveRoomLocallyMethod · 0.85
Read3DSMaxFileFunction · 0.85

Calls 9

cfopenFunction · 0.85
cf_WriteIntFunction · 0.85
cftellFunction · 0.85
cfseekFunction · 0.85
cf_WriteFloatFunction · 0.85
cf_WriteStringFunction · 0.85
cf_WriteByteFunction · 0.85
cf_WriteShortFunction · 0.85
cfcloseFunction · 0.85

Tested by

no test coverage detected