188 lines
7.9 KiB
C++
188 lines
7.9 KiB
C++
#include "MetaCoreFoundation/MetaCoreGeneratedReflection.h"
|
|
#include "MetaCoreRuntimeData/MetaCoreRuntimeDataProject.h"
|
|
#include "MetaCoreScene/MetaCoreScene.h"
|
|
#include "MetaCoreScene/MetaCoreScenePackage.h"
|
|
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
namespace {
|
|
|
|
[[nodiscard]] MetaCore::MetaCoreSceneDocument MetaCoreBuildPilotSceneDocument() {
|
|
MetaCore::MetaCoreSceneDocument document;
|
|
document.Name = "Main";
|
|
const MetaCore::MetaCoreScene scene = MetaCore::MetaCoreCreateDefaultScene();
|
|
document.GameObjects = scene.GetGameObjects();
|
|
return document;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if (argc < 2) {
|
|
std::cerr << "Usage: MetaCoreRuntimeConfigTool <runtime-directory> [--tcp]\n";
|
|
return 1;
|
|
}
|
|
|
|
const bool generateTcpConfig = argc >= 3 && std::string_view(argv[2]) == "--tcp";
|
|
|
|
MetaCore::MetaCoreTypeRegistry registry;
|
|
MetaCore::MetaCoreRegisterRuntimeDataGeneratedTypes(registry);
|
|
|
|
MetaCore::MetaCoreRuntimeDataSourcesDocument sources;
|
|
sources.Sources.push_back(MetaCore::MetaCoreDataSourceDefinition{
|
|
generateTcpConfig ? "tcp-source" : "replay-source",
|
|
generateTcpConfig ? "tcp" : "file_replay",
|
|
generateTcpConfig ? "Tcp Source" : "Replay Source",
|
|
generateTcpConfig
|
|
? std::vector<MetaCore::MetaCoreDataSourceSetting>{
|
|
MetaCore::MetaCoreDataSourceSetting{"host", "127.0.0.1"},
|
|
MetaCore::MetaCoreDataSourceSetting{"port", "7001"}
|
|
}
|
|
: std::vector<MetaCore::MetaCoreDataSourceSetting>{
|
|
MetaCore::MetaCoreDataSourceSetting{"file_path", "TestProject/Runtime/RuntimeReplay.mcstream"}
|
|
},
|
|
true,
|
|
1000
|
|
});
|
|
sources.DataPoints.push_back(MetaCore::MetaCoreDataPointDefinition{
|
|
"cube.position",
|
|
generateTcpConfig ? "tcp-source" : "replay-source",
|
|
"cube.position",
|
|
MetaCore::MetaCoreRuntimeValueType::Vec3
|
|
});
|
|
sources.DataPoints.push_back(MetaCore::MetaCoreDataPointDefinition{
|
|
"cube.visible",
|
|
generateTcpConfig ? "tcp-source" : "replay-source",
|
|
"cube.visible",
|
|
MetaCore::MetaCoreRuntimeValueType::Bool
|
|
});
|
|
sources.DataPoints.push_back(MetaCore::MetaCoreDataPointDefinition{
|
|
"cube.base_color",
|
|
generateTcpConfig ? "tcp-source" : "replay-source",
|
|
"cube.base_color",
|
|
MetaCore::MetaCoreRuntimeValueType::Vec3
|
|
});
|
|
sources.DataPoints.push_back(MetaCore::MetaCoreDataPointDefinition{
|
|
"valve.visible",
|
|
generateTcpConfig ? "tcp-source" : "replay-source",
|
|
"valve.visible",
|
|
MetaCore::MetaCoreRuntimeValueType::Bool
|
|
});
|
|
sources.DataPoints.push_back(MetaCore::MetaCoreDataPointDefinition{
|
|
"tank.base_color",
|
|
generateTcpConfig ? "tcp-source" : "replay-source",
|
|
"tank.base_color",
|
|
MetaCore::MetaCoreRuntimeValueType::Vec3
|
|
});
|
|
sources.DataPoints.push_back(MetaCore::MetaCoreDataPointDefinition{
|
|
"alarm.intensity",
|
|
generateTcpConfig ? "tcp-source" : "replay-source",
|
|
"alarm.intensity",
|
|
MetaCore::MetaCoreRuntimeValueType::Double
|
|
});
|
|
|
|
MetaCore::MetaCoreRuntimeBindingsDocument bindings;
|
|
bindings.Bindings.push_back(MetaCore::MetaCoreSceneBindingDefinition{
|
|
"binding.cube.position",
|
|
"cube.position",
|
|
3,
|
|
MetaCore::MetaCoreRuntimeBindingTarget::TransformPosition,
|
|
MetaCore::MetaCoreRuntimeMissingDataPolicy::KeepLastValue
|
|
});
|
|
bindings.Bindings.push_back(MetaCore::MetaCoreSceneBindingDefinition{
|
|
"binding.cube.visible",
|
|
"cube.visible",
|
|
3,
|
|
MetaCore::MetaCoreRuntimeBindingTarget::MeshRendererVisible,
|
|
MetaCore::MetaCoreRuntimeMissingDataPolicy::KeepLastValue
|
|
});
|
|
bindings.Bindings.push_back(MetaCore::MetaCoreSceneBindingDefinition{
|
|
"binding.cube.base_color",
|
|
"cube.base_color",
|
|
3,
|
|
MetaCore::MetaCoreRuntimeBindingTarget::MeshRendererBaseColor,
|
|
MetaCore::MetaCoreRuntimeMissingDataPolicy::KeepLastValue
|
|
});
|
|
bindings.Bindings.push_back(MetaCore::MetaCoreSceneBindingDefinition{
|
|
"binding.valve.visible",
|
|
"valve.visible",
|
|
4,
|
|
MetaCore::MetaCoreRuntimeBindingTarget::MeshRendererVisible,
|
|
MetaCore::MetaCoreRuntimeMissingDataPolicy::KeepLastValue
|
|
});
|
|
bindings.Bindings.push_back(MetaCore::MetaCoreSceneBindingDefinition{
|
|
"binding.tank.base_color",
|
|
"tank.base_color",
|
|
5,
|
|
MetaCore::MetaCoreRuntimeBindingTarget::MeshRendererBaseColor,
|
|
MetaCore::MetaCoreRuntimeMissingDataPolicy::KeepLastValue
|
|
});
|
|
bindings.Bindings.push_back(MetaCore::MetaCoreSceneBindingDefinition{
|
|
"binding.alarm.intensity",
|
|
"alarm.intensity",
|
|
6,
|
|
MetaCore::MetaCoreRuntimeBindingTarget::LightIntensity,
|
|
MetaCore::MetaCoreRuntimeMissingDataPolicy::KeepLastValue
|
|
});
|
|
|
|
const std::filesystem::path runtimeDirectory = argv[1];
|
|
const std::filesystem::path projectRoot = runtimeDirectory.parent_path();
|
|
const std::filesystem::path scenePath = projectRoot / "Scenes" / "Main.mcscene";
|
|
std::filesystem::create_directories(runtimeDirectory);
|
|
if (!MetaCore::MetaCoreWriteRuntimeDataSourcesDocument(runtimeDirectory / "DataSources.mcruntime", sources, registry)) {
|
|
std::cerr << "Failed to write DataSources.mcruntime\n";
|
|
return 1;
|
|
}
|
|
if (!MetaCore::MetaCoreWriteRuntimeBindingsDocument(runtimeDirectory / "Bindings.mcruntime", bindings, registry)) {
|
|
std::cerr << "Failed to write Bindings.mcruntime\n";
|
|
return 1;
|
|
}
|
|
MetaCore::MetaCoreRuntimeProjectDocument runtimeProjectDocument;
|
|
runtimeProjectDocument.StartupScenePath = std::filesystem::path("Scenes") / "Main.mcscene";
|
|
runtimeProjectDocument.DataSourcesPath = std::filesystem::path("Runtime") / "DataSources.mcruntime";
|
|
runtimeProjectDocument.BindingsPath = std::filesystem::path("Runtime") / "Bindings.mcruntime";
|
|
runtimeProjectDocument.DiagnosticsPath = std::filesystem::path("Runtime") / "Diagnostics.mcruntimestate";
|
|
if (!MetaCore::MetaCoreWriteRuntimeProjectDocument(runtimeDirectory / "ProjectRuntime.mcruntimecfg", runtimeProjectDocument, registry)) {
|
|
std::cerr << "Failed to write ProjectRuntime.mcruntimecfg\n";
|
|
return 1;
|
|
}
|
|
std::filesystem::create_directories(scenePath.parent_path());
|
|
if (!MetaCore::MetaCoreWriteScenePackage(scenePath, MetaCoreBuildPilotSceneDocument())) {
|
|
std::cerr << "Failed to write Main.mcscene\n";
|
|
return 1;
|
|
}
|
|
|
|
if (!generateTcpConfig) {
|
|
std::ofstream replayFile(runtimeDirectory / "RuntimeReplay.mcstream", std::ios::trunc);
|
|
if (!replayFile) {
|
|
std::cerr << "Failed to write RuntimeReplay.mcstream\n";
|
|
return 1;
|
|
}
|
|
replayFile
|
|
<< "# emit_after_seconds data_point_id value_type payload\n"
|
|
<< "0.00 cube.position vec3 0.0 0.5 0.0\n"
|
|
<< "0.00 cube.visible bool true\n"
|
|
<< "0.00 cube.base_color vec3 0.4 0.6 0.9\n"
|
|
<< "0.00 valve.visible bool true\n"
|
|
<< "0.00 tank.base_color vec3 0.35 0.65 0.90\n"
|
|
<< "0.00 alarm.intensity double 0.0\n"
|
|
<< "0.50 cube.position vec3 1.5 0.5 0.0\n"
|
|
<< "0.50 cube.base_color vec3 0.8 0.6 0.5\n"
|
|
<< "0.50 tank.base_color vec3 0.20 0.80 0.25\n"
|
|
<< "0.50 alarm.intensity double 2.0\n"
|
|
<< "1.00 cube.visible bool false\n"
|
|
<< "1.00 valve.visible bool false\n"
|
|
<< "1.50 cube.position vec3 -1.5 0.5 0.0\n"
|
|
<< "1.50 cube.visible bool true\n"
|
|
<< "1.50 valve.visible bool true\n"
|
|
<< "1.50 alarm.intensity double 0.0\n";
|
|
}
|
|
|
|
std::cout << "Runtime config generated at " << runtimeDirectory.string()
|
|
<< " scene=" << scenePath.string()
|
|
<< " mode=" << (generateTcpConfig ? "tcp" : "file_replay") << '\n';
|
|
return 0;
|
|
}
|