diff --git a/ext/ghoul b/ext/ghoul index cec683e244..f8e1ba97c3 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit cec683e244ab02a4454d07f7406a5c837a4a6f97 +Subproject commit f8e1ba97c3d70ac456a3db3843d4160a6733d6b3 diff --git a/include/openspace/scenegraph/spiceephemeris.h b/include/openspace/scenegraph/spiceephemeris.h index d52a990d87..663460fcf3 100644 --- a/include/openspace/scenegraph/spiceephemeris.h +++ b/include/openspace/scenegraph/spiceephemeris.h @@ -34,8 +34,6 @@ namespace openspace { class SpiceEphemeris : public Ephemeris { public: SpiceEphemeris(const ghoul::Dictionary& dictionary); - ~SpiceEphemeris(); - bool initialize(); const psc& position() const; void update(const UpdateData& data) override; @@ -43,6 +41,7 @@ private: std::string _targetName; std::string _originName; psc _position; + bool _kernelsLoadedSuccessfully; }; } // namespace openspace diff --git a/include/openspace/util/constants.h b/include/openspace/util/constants.h index a523c2b423..49e8787045 100644 --- a/include/openspace/util/constants.h +++ b/include/openspace/util/constants.h @@ -42,6 +42,7 @@ namespace configurationmanager { namespace scenegraph { const std::string keyPathScene = "ScenePath"; + const std::string keyCommonFolder = "CommonFolder"; const std::string keyModules = "Modules"; const std::string keyCamera = "Camera"; const std::string keyFocusObject = "Focus"; diff --git a/include/openspace/util/spicemanager.h b/include/openspace/util/spicemanager.h index ca946903e2..7eb56e5c05 100644 --- a/include/openspace/util/spicemanager.h +++ b/include/openspace/util/spicemanager.h @@ -73,8 +73,7 @@ public: * \param filePath The path to the kernel that should be loaded * \return The loaded kernel's unique identifier that can be used to unload the kernel */ - KernelIdentifier loadKernel(std::string filePath); - KernelIdentifier loadKernelExplicit(std::string filePath); + KernelIdentifier loadKernel(const std::string& filePath); /** diff --git a/openspace-data b/openspace-data index 078b74de34..5100d9e5b8 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 078b74de3490cf1358b53257b0b29bb91455610b +Subproject commit 5100d9e5b8366034809ff57890f0aafb63cc5677 diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index ac91556db3..84024e2267 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -5,4 +5,4 @@ openspace.time.setTime("2007-02-26T12:00:00") --openspace.time.setDeltaTime(200000.0) openspace.time.setDeltaTime(2000.0) --openspace.time.setDeltaTime(30000.0) -print(openspace.time.currentTimeUTC()) +-- print(openspace.time.currentTimeUTC()) diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 2cc9c3b878..141ff3115e 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -242,13 +242,16 @@ bool OpenSpaceEngine::initialize() std::string timeKernel; bool success = OsEng.configurationManager().getValue(keySpiceTimeKernel, timeKernel); - std::cout << "timeKernel = " << timeKernel << std::endl; - if (!success) { LERROR("Configuration file does not contain a '" << keySpiceTimeKernel << "'"); return false; } - SpiceManager::ref().loadKernel(std::move(timeKernel)); + SpiceManager::KernelIdentifier id = + SpiceManager::ref().loadKernel(timeKernel); + if (id == SpiceManager::KernelFailed) { + LERROR("Error loading time kernel '" << timeKernel << "'"); + return false; + } using constants::configurationmanager::keySpiceLeapsecondKernel; std::string leapSecondKernel; @@ -257,8 +260,11 @@ bool OpenSpaceEngine::initialize() LERROR("Configuration file does not contain a '" << keySpiceLeapsecondKernel << "'"); return false; } - std::cout << "leapSecondKernel : " << leapSecondKernel << std::endl; - SpiceManager::ref().loadKernel(std::move(leapSecondKernel)); + id = SpiceManager::ref().loadKernel(std::move(leapSecondKernel)); + if (id == SpiceManager::KernelFailed) { + LERROR("Error loading leap second kernel '" << leapSecondKernel << "'"); + return false; + } //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/de413.bsp"); //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/jup260.bsp") diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index c184ea58f3..433e03b297 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -156,7 +156,7 @@ void InteractionHandler::orbit(const glm::quat &rotation) { // should be changed to something more dynamic =) psc origin; - if(node_) { + if (node_) { origin = node_->worldPosition(); } @@ -170,7 +170,7 @@ void InteractionHandler::orbit(const glm::quat &rotation) { //camera_->rotate(rotation); //camera_->setRotation(glm::mat4_cast(rotation)); - glm::mat4 la = glm::lookAt(camera_->position().vec3(), node_->worldPosition().vec3(), glm::rotate(rotation, camera_->lookUpVector())); + glm::mat4 la = glm::lookAt(camera_->position().vec3(), origin.vec3(), glm::rotate(rotation, camera_->lookUpVector())); camera_->setRotation(la); //camera_->setLookUpVector(); diff --git a/src/main.cpp b/src/main.cpp index 333b9d4d5f..0fcf03cb55 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -113,18 +113,26 @@ int main(int argc, char** argv) void mainInitFunc() { - OsEng.initialize(); - OsEng.initializeGL(); + bool success = OsEng.initialize(); + if (success) + success = OsEng.initializeGL(); + + if (!success) { + LFATAL("Initializing OpenSpaceEngine failed"); + std::cout << "Press any key to continue..."; + std::cin.ignore(100); + exit(EXIT_FAILURE); + } } void mainPreSyncFunc() { - OsEng.preSynchronization(); + OsEng.preSynchronization(); } void mainPostSyncPreDrawFunc() { - OsEng.postSynchronizationPreDraw(); + OsEng.postSynchronizationPreDraw(); } void mainRenderFunc() diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index 1d68d30a26..781afab522 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -55,6 +55,8 @@ namespace { const std::string _loggerCat = "SceneGraph"; const std::string _moduleExtension = ".mod"; + const std::string _defaultCommonDirectory = "common"; + const std::string _commonModuleToken = "${COMMON_MODULE}"; } namespace openspace { @@ -345,6 +347,10 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath) std::string moduleDirectory("."); dictionary.getValue(constants::scenegraph::keyPathScene, moduleDirectory); + std::string commonDirectory(_defaultCommonDirectory); + dictionary.getValue(constants::scenegraph::keyCommonFolder, commonDirectory); + FileSys.registerPathToken(_commonModuleToken, commonDirectory); + // The scene path could either be an absolute or relative path to the description // paths directory std::string&& relativeCandidate = sceneDescriptionDirectory + diff --git a/src/scenegraph/spiceephemeris.cpp b/src/scenegraph/spiceephemeris.cpp index 10a1e58fc0..45aa2d18ed 100644 --- a/src/scenegraph/spiceephemeris.cpp +++ b/src/scenegraph/spiceephemeris.cpp @@ -40,6 +40,7 @@ SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary) : _targetName("") , _originName("") , _position() + , _kernelsLoadedSuccessfully(true) { const bool hasBody = dictionary.getValue(keyBody, _targetName); if (!hasBody) @@ -51,49 +52,32 @@ SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary) ghoul::Dictionary kernels; dictionary.getValue(keyKernels, kernels); + if (kernels.size() == 0) + _kernelsLoadedSuccessfully = false; for (size_t i = 1; i <= kernels.size(); ++i) { std::string kernel; bool success = kernels.getValue(std::to_string(i), kernel); if (!success) LERROR("'" << keyKernels << "' has to be an array-style table"); - SpiceManager::ref().loadKernel(kernel); + SpiceManager::KernelIdentifier id = SpiceManager::ref().loadKernel(kernel); + _kernelsLoadedSuccessfully &= (id != SpiceManager::KernelFailed); } } -SpiceEphemeris::~SpiceEphemeris() {} - -bool SpiceEphemeris::initialize() -{ - //if (!_targetName.empty() && !_originName.empty()) { - // int bsuccess = 0; - // int osuccess = 0; - // Spice::ref().bod_NameToInt(_targetName, &_target, &bsuccess); - // Spice::ref().bod_NameToInt(_originName, &_origin, &osuccess); - // - // if (bsuccess && osuccess) - // return true; - //} - // - return true; -} - const psc& SpiceEphemeris::position() const { return _position; } void SpiceEphemeris::update(const UpdateData& data) { - double state[3]; - - glm::dvec3 position(0,0,0); + if (!_kernelsLoadedSuccessfully) + return; + glm::dvec3 position(0,0,0); double lightTime = 0.0; - glm::dmat3 _stateMatrix; SpiceManager::ref().getTargetPosition(_targetName, _originName, "GALACTIC", "NONE", data.time, position, lightTime); _position = psc::CreatePowerScaledCoordinate(position.x, position.y, position.z); _position[3] += 3; - //_position[3] += 3; - } } // namespace openspace \ No newline at end of file diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index 32fc8714da..35aac55809 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -68,43 +68,15 @@ SpiceManager& SpiceManager::ref() { return *_manager; } -SpiceManager::KernelIdentifier SpiceManager::loadKernelExplicit(std::string filePath) { +SpiceManager::KernelIdentifier SpiceManager::loadKernel(const std::string& filePath) { if (filePath.empty()) { LERROR("No filename provided"); return KernelFailed; } - // I tried the *.cfg loading, didnt work. Im sorry but I just need this present right now. - KernelIdentifier kernelId = ++_lastAssignedKernel; - - // Load the kernel - furnsh_c(filePath.c_str()); - - // Reset the current directory to the previous one - std::cout << filePath.c_str() << std::endl; - int failed = failed_c(); - if (failed) { - char msg[1024]; - getmsg_c("LONG", 1024, msg); - LERROR("Error loading kernel '" + filePath + "'"); - LERROR("Spice reported: " + std::string(msg)); - reset_c(); - return false; - } - - bool hasError = checkForError("Error loading kernel '" + filePath + "'"); - if (hasError) - return KernelFailed; - else { - KernelInformation&& info = { filePath, std::move(kernelId) }; - _loadedKernels.push_back(info); - return kernelId; - } -} - -SpiceManager::KernelIdentifier SpiceManager::loadKernel(std::string filePath) { - if (filePath.empty()) { - LERROR("No filename provided"); + std::string&& path = absPath(filePath); + if (!FileSys.fileExists(path)) { + LERROR("Kernel file '" << path << "' does not exist"); return KernelFailed; } @@ -113,10 +85,14 @@ SpiceManager::KernelIdentifier SpiceManager::loadKernel(std::string filePath) { // We need to set the current directory as meta-kernels are usually defined relative // to the directory they reside in. The directory change is not necessary for regular // kernels - std::string&& path = absPath(std::move(filePath)); ghoul::filesystem::Directory currentDirectory = FileSys.currentDirectory(); std::string&& fileDirectory = ghoul::filesystem::File(path).directoryName(); + + if (!FileSys.directoryExists(fileDirectory)) { + LERROR("Could not find directory for kernel '" << path << "'"); + return KernelFailed; + } FileSys.setCurrentDirectory(fileDirectory); // Load the kernel @@ -124,15 +100,14 @@ SpiceManager::KernelIdentifier SpiceManager::loadKernel(std::string filePath) { // Reset the current directory to the previous one FileSys.setCurrentDirectory(currentDirectory); - std::cout << filePath.c_str() << std::endl; int failed = failed_c(); if (failed) { char msg[1024]; getmsg_c ( "LONG", 1024, msg ); - LERROR("Error loading kernel '" + filePath + "'"); + LERROR("Error loading kernel '" + path + "'"); LERROR("Spice reported: " + std::string(msg)); reset_c(); - return false; + return KernelFailed; } bool hasError = checkForError("Error loading kernel '" + path + "'"); @@ -421,7 +396,7 @@ bool SpiceManager::getPositionTransformMatrix(const std::string& fromFrame, bool hasError = checkForError("Error retrieving position transform matrix from " "frame '" + fromFrame + "' to frame '" + toFrame + - "at time '" + std::to_string(ephemerisTime) + "'"); + "' at time '" + std::to_string(ephemerisTime) + "'"); positionMatrix = glm::transpose(positionMatrix); return !hasError;