MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / level_loadObjects

Function level_loadObjects

TheForceEngine/TFE_Jedi/Level/level.cpp:725–1035  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

723 }
724
725 JBool level_loadObjects(const char* levelName, u8 difficulty)
726 {
727 char levelPath[TFE_MAX_PATH];
728 strcpy(levelPath, levelName);
729 strcat(levelPath, ".O");
730
731 s32 curDiff = s32(difficulty) + 1;
732
733 FilePath filePath;
734 if (!TFE_Paths::getFilePath(levelPath, &filePath))
735 {
736 TFE_System::logWrite(LOG_ERROR, "Level Load", "Cannot find level objects '%s'.", levelName);
737 return false;
738 }
739 FileStream file;
740 if (!file.open(&filePath, Stream::MODE_READ))
741 {
742 TFE_System::logWrite(LOG_ERROR, "Level Load", "Cannot open level objects '%s'.", levelName);
743 return false;
744 }
745
746 size_t len = file.getSize();
747 s_buffer.resize(len);
748 file.readBuffer(s_buffer.data(), u32(len));
749 file.close();
750
751 TFE_Parser parser;
752 size_t bufferPos = 0;
753 parser.init(s_buffer.data(), s_buffer.size());
754 parser.enableBlockComments();
755 parser.addCommentString("//");
756 parser.addCommentString("#");
757 parser.convertToUpperCase(true);
758
759 // Only use the parser "read line" functionality and otherwise read in the same was as the DOS code.
760 const char* line;
761 line = parser.readLine(bufferPos);
762 s32 versionMajor, versionMinor;
763 if (sscanf(line, "O %d.%d", &versionMajor, &versionMinor) != 2)
764 {
765 TFE_System::logWrite(LOG_ERROR, "Level Load", "Cannot parse version for Object file '%s'.", levelName);
766 return false;
767 }
768
769 while (nullptr != (line = parser.readLine(bufferPos)))
770 {
771 if (sscanf(line, "PODS %d", &s_levelIntState.podCount) == 1)
772 {
773 s_levelIntState.pods = (JediModel**)level_alloc(sizeof(JediModel*)*s_levelIntState.podCount);
774 for (s32 p = 0; p < s_levelIntState.podCount; p++)
775 {
776 line = parser.readLine(bufferPos);
777 s_levelIntState.pods[p] = nullptr;
778
779 if (line)
780 {
781 char podName[32];
782 if (sscanf(line, " POD: %s", podName) == 1)

Callers 1

level_loadFunction · 0.85

Calls 15

logWriteFunction · 0.85
getWaxFunction · 0.85
sound_loadFunction · 0.85
absFunction · 0.85
floatToFixed16Function · 0.85
sector_which3DFunction · 0.85
allocateObjectFunction · 0.85
floatDegreesToFixedFunction · 0.85
getKeywordIndexFunction · 0.85
sector_addObjectFunction · 0.85
obj3d_setDataFunction · 0.85
obj3d_computeTransformFunction · 0.85

Tested by

no test coverage detected