Replaced engine init single asset call with separate profile conversions

This commit is contained in:
GPayne
2021-08-22 22:48:44 -06:00
parent 52e4f75b32
commit 4016180b8c
4 changed files with 130 additions and 104 deletions

View File

@@ -115,6 +115,7 @@ private:
void configureLogging();
std::string generateFilePath(std::string openspaceRelativePath);
void resetPropertyChangeFlagsOfSubowners(openspace::properties::PropertyOwner* po);
void loadInitAssetSection(const std::string profileSectionName);
std::unique_ptr<Scene> _scene;
std::unique_ptr<AssetManager> _assetManager;
@@ -124,6 +125,7 @@ private:
bool _hasScheduledAssetLoading = false;
std::string _scheduledAssetPathToLoad;
bool _hasInitializedProfile = false;
glm::vec2 _mousePosition = glm::vec2(0.f);

View File

@@ -76,10 +76,9 @@ public:
SetPropertyValueSingle
};
SetType setType;
SetType setType = SetType::SetPropertyValue;
std::string name;
std::string value;
};
struct Action {
std::string identifier;
@@ -165,10 +164,35 @@ public:
*/
static scripting::LuaLibrary luaLibrary();
const std::string file_subName_assets = "";
const std::string assetFileExtension = ".asset";
std::string file_subName_assets = "";
std::string assetFileExtension = ".asset";
};
/**
* Function to convert a profile into separate files with converted asset contents
* from each section
*
* \param filePre The prefix name for the asset section to be applied to the output
* filename. The pattern is "<filePre>_<profilePrefix>.asset"
* \param p The profile that should be processed
*/
void convertToSeparatedAssets(const std::string filePre, const Profile& p);
/**
* Function to convert a specific section of a profile into an asset file, which allows
* that section to be individually loaded.
*
* \param profilePrefix The name for the asset section to be applied to the output
* filename. The pattern is "<profileName>_<profilePrefix>.asset"
* \param p The profile that should be processed
* \param profileSectionName The name of the profile subsection used for output filename
* \param func a std::function that takes a reference to a const Profile as arg, and
* returns the asset-ified contents as a std::string object
*/
void convertSectionToAssetFile(const std::string profilePrefix, const Profile& p,
const std::string profileSectionName,
std::function<std::string(const Profile&)> func);
/**
* convertToAsset_* functions extract a section (* as section name) and returns its
* asset-ified version as a string. This allows the profile section to be processed
@@ -179,8 +203,8 @@ public:
/**
* Function to process the meta information included in the profile
*
* \param profile The profile that should be processed
*
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's meta section, ready
* to be loaded as an asset
*/
@@ -189,18 +213,18 @@ std::string convertToAsset_meta(const Profile& p);
/**
* Function to process the assets that are included in the profile
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's asset section, ready
* to be loaded as an asset
*/
std::string convertToAsset_includedAssets(const Profile& p);
std::string convertToAsset_addedAssets(const Profile& p);
/**
* Function to process the modules that may be included in the profile, and the commands
* to execute if they are/aren't loaded
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's modules section, ready
* to be loaded as an asset
@@ -208,20 +232,31 @@ std::string convertToAsset_includedAssets(const Profile& p);
std::string convertToAsset_modules(const Profile& p);
/**
* Function to process the actions and keybindings that are included in the profile.
* The actions and keybindings are separate but closely-related sections of a profile
* Function to process the actions that are included in the profile.
* This is separate from, but closely-related to, the keybindings section
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's actions and keybindings
* sections, ready to be loaded as an asset
* \return The string representation of the provided profile's actions section,
* ready to be loaded as an asset
*/
std::string convertToAsset_actionsKeybinds(const Profile& p);
std::string convertToAsset_actions(const Profile& p);
/**
* Function to process the keybindings that are included in the profile.
* This is separate from, but closely-related to, the actions section
*
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's keybindings
* section, ready to be loaded as an asset
*/
std::string convertToAsset_keybinds(const Profile& p);
/**
* Function to process the time setting that is included in the profile
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's time section, ready
* to be loaded as an asset
@@ -231,7 +266,7 @@ std::string convertToAsset_time(const Profile& p);
/**
* Function to process the delta time settings that are included in the profile
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's delta times section, ready
* to be loaded as an asset
@@ -241,7 +276,7 @@ std::string convertToAsset_deltaTimes(const Profile& p);
/**
* Function to process the mark-interesting-nodes that are included in the profile
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's mark-interesting-nodes
* section, ready to be loaded as an asset
@@ -251,7 +286,7 @@ std::string convertToAsset_markNodes(const Profile& p);
/**
* Function to process the properties that are included in the profile
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's properties section, ready
* to be loaded as an asset
@@ -261,7 +296,7 @@ std::string convertToAsset_properties(const Profile& p);
/**
* Function to process the initial camera orientation that is included in the profile
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's camera section, ready
* to be loaded as an asset
@@ -272,12 +307,12 @@ std::string convertToAsset_camera(const Profile& p);
* Function to process the additional scripts command section that is included in the
* profile
*
* \param profile The profile that should be processed
* \param p The profile that should be processed
*
* \return The string representation of the provided profile's additional scripts
* section, ready to be loaded as an asset
*/
std::string convertToAsset_additionalScripts(const Profile& p);
std::string convertToAsset_addedScripts(const Profile& p);
} // namespace openspace

View File

@@ -302,8 +302,6 @@ void OpenSpaceEngine::initialize() {
global::configuration->profile + ".profile";
std::string outputProfilePrefix = outputScenePath + "/"
+ global::configuration->profile;
std::string outputAsset = outputScenePath + "/" + global::configuration->profile
+ ".asset";
if (std::filesystem::is_regular_file(inputUserProfile)) {
inputProfile = inputUserProfile;
@@ -335,14 +333,9 @@ void OpenSpaceEngine::initialize() {
// Then save the profile to a scene so that we can load it with the
// existing infrastructure
std::ofstream scene(outputAsset);
std::string sceneContent = convertToScene(*global::profile);
scene << sceneContent;
convertToSeparatedAssets(outputProfilePrefix, *global::profile);
// Set asset name to that of the profile because a new scene file will be
// created with that name, and also because the profile name will override
// an asset name if both are provided.
global::configuration->asset = outputAsset;
global::configuration->profileOutPrefixName = outputProfilePrefix;
global::configuration->usingProfile = true;
}
}
@@ -386,7 +379,6 @@ void OpenSpaceEngine::initialize() {
}
global::openSpaceEngine->_assetManager->initialize();
scheduleLoadSingleAsset(global::configuration->asset);
LTRACE("OpenSpaceEngine::initialize(end)");
}
@@ -1112,6 +1104,19 @@ void OpenSpaceEngine::preSynchronization() {
_hasScheduledAssetLoading = false;
_scheduledAssetPathToLoad.clear();
}
else if (!_hasInitializedProfile) {
loadInitAssetSection("_meta");
loadInitAssetSection("_addedAssets");
loadInitAssetSection("_modules");
loadInitAssetSection("_actions");
loadInitAssetSection("_keybinds");
loadInitAssetSection("_time");
loadInitAssetSection("_deltaTimes");
loadInitAssetSection("_markNodes");
loadInitAssetSection("_properties");
loadInitAssetSection("_camera");
_hasInitializedProfile = true;
}
if (_isFirstRenderingFirstFrame) {
global::windowDelegate->setSynchronization(false);
@@ -1140,7 +1145,9 @@ void OpenSpaceEngine::preSynchronization() {
);
}
global::renderEngine->updateScene();
if (!_hasInitializedProfile) {
loadInitAssetSection("_addedScripts");
}
if (_scene) {
Camera* camera = _scene->camera();
@@ -1159,9 +1166,27 @@ void OpenSpaceEngine::preSynchronization() {
func();
}
if (!_hasInitializedProfile) {
_hasInitializedProfile = true;
}
LTRACE("OpenSpaceEngine::preSynchronization(end)");
}
void OpenSpaceEngine::loadInitAssetSection(const std::string profileSectionName) {
std::string assetFilename = fmt::format(
"{}_{}{}",
global::configuration->profileOutPrefixName,
profileSectionName,
global::profile->assetFileExtension
);
LINFO(fmt::format("Loading profile subsection {}", profileSectionName));
global::profile->ignoreUpdates = true;
loadSingleAsset(assetFilename);
global::profile->ignoreUpdates = false;
resetPropertyChangeFlagsOfSubowners(global::rootPropertyOwner);
}
void OpenSpaceEngine::postSynchronizationPreDraw() {
ZoneScoped
TracyGpuZone("postSynchronizationPreDraw")

View File

@@ -465,7 +465,7 @@ struct Keybinding {
std::string documentation;
std::string name;
std::string guiPath;
bool isLocal;
bool isLocal = true;
std::string script;
};
@@ -741,57 +741,27 @@ scripting::LuaLibrary Profile::luaLibrary() {
};
}
void convertProfileToSeparatedAssets(const std::string profilePrefix, const Profile& p) {
{
std::ofstream converted(fmt::format("{}_meta{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_meta(p);
}
{
std::ofstream converted(fmt::format("{}_includedAssets{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_includedAssets(p);
}
{
std::ofstream converted(fmt::format("{}_modules{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_modules(p);
}
{
std::ofstream converted(fmt::format("{}_actionsKeybinds{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_actionsKeybinds(p);
}
{
std::ofstream converted(fmt::format("{}_time{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_time(p);
}
{
std::ofstream converted(fmt::format("{}_deltaTimes{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_deltaTimes(p);
}
{
std::ofstream converted(fmt::format("{}_markNodes{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_markNodes(p);
}
{
std::ofstream converted(fmt::format("{}_properties{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_properties(p);
}
{
std::ofstream converted(fmt::format("{}_camera{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_camera(p);
}
{
std::ofstream converted(fmt::format("{}_additionalScripts{}", profilePrefix,
p.assetFileExtension));
converted << convertToAsset_additionalScripts(p);
}
void convertToSeparatedAssets(const std::string filePre, const Profile& p) {
convertSectionToAssetFile(filePre, p, "_meta", convertToAsset_meta);
convertSectionToAssetFile(filePre, p, "_addedAssets", convertToAsset_addedAssets);
convertSectionToAssetFile(filePre, p, "_modules", convertToAsset_modules);
convertSectionToAssetFile(filePre, p, "_actions", convertToAsset_actions);
convertSectionToAssetFile(filePre, p, "_keybinds", convertToAsset_keybinds);
convertSectionToAssetFile(filePre, p, "_time", convertToAsset_time);
convertSectionToAssetFile(filePre, p, "_deltaTimes", convertToAsset_deltaTimes);
convertSectionToAssetFile(filePre, p, "_markNodes", convertToAsset_markNodes);
convertSectionToAssetFile(filePre, p, "_properties", convertToAsset_properties);
convertSectionToAssetFile(filePre, p, "_camera", convertToAsset_camera);
convertSectionToAssetFile(filePre, p, "_addedScripts", convertToAsset_addedScripts);
}
void convertSectionToAssetFile(const std::string profilePrefix, const Profile& p,
const std::string profileSectionName,
std::function<std::string(const Profile&)> func)
{
std::ofstream converted(fmt::format("{}_{}{}", profilePrefix,
profileSectionName, p.assetFileExtension));
converted << func(p);
}
std::string convertToAsset_meta(const Profile& p) {
@@ -827,7 +797,7 @@ std::string convertToAsset_meta(const Profile& p) {
return output;
}
std::string convertToAsset_includedAssets(const Profile& p) {
std::string convertToAsset_addedAssets(const Profile& p) {
ZoneScoped
std::string output;
@@ -844,7 +814,6 @@ std::string convertToAsset_modules(const Profile& p) {
ZoneScoped
std::string output;
for (const Profile::Module& m : p.modules) {
output += fmt::format(
"if openspace.modules.isLoaded(\"{}\") then {} else {} end\n",
@@ -855,12 +824,10 @@ std::string convertToAsset_modules(const Profile& p) {
return output;
}
std::string convertToAsset_actionsKeybinds(const Profile& p) {
std::string convertToAsset_actions(const Profile& p) {
ZoneScoped
std::string output = "asset.onInitialize(function()\n";
// Actions
output += " -- Actions\n";
for (const Profile::Action& action : p.actions) {
const std::string name = action.name.empty() ? action.identifier : action.name;
output += fmt::format(
@@ -872,9 +839,15 @@ std::string convertToAsset_actionsKeybinds(const Profile& p) {
action.isLocal ? "true" : "false"
);
}
output += "end)\n";
// Keybindings
output += "\n -- Keybindings\n";
return output;
}
std::string convertToAsset_keybinds(const Profile& p) {
ZoneScoped
std::string output = "asset.onInitialize(function()\n";
for (size_t i = 0; i < p.keybindings.size(); ++i) {
const Profile::Keybinding& k = p.keybindings[i];
const std::string key = keyToString(k.key);
@@ -889,7 +862,6 @@ std::string convertToAsset_time(const Profile& p) {
ZoneScoped
std::string output = "asset.onInitialize(function()\n";
output += "\n -- Time\n";
switch (p.time->type) {
case Profile::Time::Type::Absolute:
output += fmt::format(" openspace.time.setTime(\"{}\")\n", p.time->value);
@@ -914,7 +886,6 @@ std::string convertToAsset_deltaTimes(const Profile& p) {
std::string output = "asset.onInitialize(function()\n";
{
output += "\n -- Delta Times\n";
std::string times;
for (double d : p.deltaTimes) {
times += fmt::format("{}, ", d);
@@ -931,7 +902,6 @@ std::string convertToAsset_markNodes(const Profile& p) {
std::string output = "asset.onInitialize(function()\n";
{
output += "\n -- Mark Nodes\n";
std::string nodes;
for (const std::string& n : p.markNodes) {
nodes += fmt::format("[[{}]],", n);
@@ -947,7 +917,6 @@ std::string convertToAsset_properties(const Profile& p) {
ZoneScoped
std::string output = "asset.onInitialize(function()\n";
output += "\n -- Properties\n";
for (const Profile::Property& prop : p.properties) {
switch (prop.setType) {
case Profile::Property::SetType::SetPropertyValue:
@@ -973,13 +942,10 @@ std::string convertToAsset_properties(const Profile& p) {
std::string convertToAsset_camera(const Profile& p) {
ZoneScoped
std::string output;
// Camera
output += "\n -- Camera\n";
std::string output = "asset.onInitialize(function()\n";
if (p.camera.has_value()) {
output += std::visit(
overloaded{
overloaded {
[](const Profile::CameraNavState& c) {
std::string result;
result += " openspace.navigation.setNavigationState({";
@@ -1033,12 +999,10 @@ std::string convertToAsset_camera(const Profile& p) {
return output;
}
std::string convertToAsset_additionalScripts(const Profile& p) {
std::string convertToAsset_addedScripts(const Profile& p) {
ZoneScoped
std::string output = "asset.onInitialize(function()\n";
output += "\n -- Additional Scripts\n";
for (const std::string& a : p.additionalScripts) {
output += fmt::format(" {}\n", a);
}