Skip to content

Commit

Permalink
Project Loader: resolve relative project file paths via CLI to absolu…
Browse files Browse the repository at this point in the history
…te paths
  • Loading branch information
geringsj committed Apr 27, 2023
1 parent eaaf51f commit f191efd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions frontend/main/src/CLIConfigParsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ std::pair<RuntimeConfig, GlobalValueStore> megamol::frontend::handle_cli_and_con
RuntimeConfig config;

config.megamol_executable_directory = getExecutableDirectory().u8string();
config.megamol_current_working_directory = std::filesystem::current_path().u8string();

// config files are already checked to exist in file system
config.configuration_files = extract_config_file_paths(argc, argv);
Expand Down
2 changes: 2 additions & 0 deletions frontend/resources/include/MegaMolProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <cassert>
#include <filesystem>
#include <optional>
#include <string>
Expand All @@ -27,6 +28,7 @@ struct MegaMolProject {
std::optional<ProjectAttributes> attributes = std::nullopt;

void setProjectFile(path const& file) {
assert(file.is_absolute());
ProjectAttributes a;
a.project_file = file;
a.project_directory = path{file}.remove_filename(); // leaves trailing '/'
Expand Down
3 changes: 2 additions & 1 deletion frontend/resources/include/RuntimeConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ struct RuntimeConfig {
std::vector<std::string> configuration_file_contents = {};
std::vector<StringPair> cli_options_from_configs = {}; // mmSetCliOption - set config/option values accepted in CLI
std::vector<std::string> configuration_file_contents_as_cli = {};
Path megamol_executable_directory = ""; // mmGetMegaMolExecutableDirectory
Path megamol_executable_directory = ""; // mmGetMegaMolExecutableDirectory
Path megamol_current_working_directory = "";
Path application_directory = ""; // mmSetAppDir
std::vector<Path> resource_directories = {}; // mmAddResourceDir
std::vector<Path> shader_directories = {}; // mmAddShaderDir
Expand Down
14 changes: 12 additions & 2 deletions frontend/services/project_loader/ProjectLoader_Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <fstream>
#include <sstream>

#include "RuntimeConfig.h"
#include "Window_Events.h"
#include "mmcore/utility/String.h"
#include "mmcore/utility/graphics/ScreenShotComments.h"
Expand Down Expand Up @@ -54,7 +55,12 @@ bool ProjectLoader_Service::init(const Config& config) {
{"MegaMolProject", m_current_project},
};

this->m_requestedResourcesNames = {"ExecuteLuaScript", "SetScriptPath", "optional<WindowEvents>"};
this->m_requestedResourcesNames = {
"ExecuteLuaScript",
"SetScriptPath",
"optional<WindowEvents>",
"RuntimeConfig",
};

log("initialized successfully");
return true;
Expand Down Expand Up @@ -115,14 +121,18 @@ bool ProjectLoader_Service::load_file(std::filesystem::path const& filename) con
using SetScriptPath = std::function<void(std::string const&)>;
const SetScriptPath& set_script_path = m_requestedResourceReferences[1].getResource<SetScriptPath>();

const frontend_resources::RuntimeConfig& rt_config =
m_requestedResourceReferences[3].getResource<frontend_resources::RuntimeConfig>();

set_script_path(filename.generic_u8string());
// TODO: we have a timing issue with the script path / project path here
// the lua script path resource gets updated by the lua service at the beginning of each frame
// but here the project service needs to set the project file/directory right before the lua code gets executed,
// such that the project path is known to the megamol graph when constructing modules with file path parameters
// thus we sed the current project path resource, which the megamol graph can look into
// somewhat of a very thight coupling here to pass information into the lua interpreter but currently no other solution...
const_cast<ProjectLoader_Service*>(this)->m_current_project.setProjectFile(filename);
const_cast<ProjectLoader_Service*>(this)->m_current_project.setProjectFile(
filename.is_absolute() ? filename : (rt_config.megamol_current_working_directory / filename));

auto result = execute_lua(script);
bool script_ok = std::get<0>(result);
Expand Down

0 comments on commit f191efd

Please sign in to comment.