Add deferred async scene asset loading
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "Scene/Scene.h"
|
||||
#include "Components/ComponentFactoryRegistry.h"
|
||||
#include "Debug/Logger.h"
|
||||
#include "Components/GameObject.h"
|
||||
#include "Components/TransformComponent.h"
|
||||
#include <sstream>
|
||||
@@ -11,6 +12,16 @@ namespace Components {
|
||||
|
||||
namespace {
|
||||
|
||||
bool ShouldTraceSceneComponentPayload(const std::string& payload) {
|
||||
return payload.find("builtin://") != std::string::npos ||
|
||||
payload.find("backpack") != std::string::npos ||
|
||||
payload.find("New Material.mat") != std::string::npos;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
|
||||
struct PendingComponentData {
|
||||
std::string type;
|
||||
std::string payload;
|
||||
@@ -338,6 +349,19 @@ void Scene::DeserializeFromString(const std::string& data) {
|
||||
}
|
||||
|
||||
for (const PendingComponentData& componentData : pending.components) {
|
||||
if (ShouldTraceSceneComponentPayload(componentData.payload)) {
|
||||
Debug::Logger::Get().Info(
|
||||
Debug::LogCategory::FileSystem,
|
||||
Containers::String("[Scene] Deserialize component objectId=") +
|
||||
Containers::String(std::to_string(pending.id).c_str()) +
|
||||
" name=" +
|
||||
Containers::String(pending.name.c_str()) +
|
||||
" type=" +
|
||||
Containers::String(componentData.type.c_str()) +
|
||||
" payload=" +
|
||||
Containers::String(componentData.payload.c_str()));
|
||||
}
|
||||
|
||||
if (Component* component = ComponentFactoryRegistry::Get().CreateComponent(go.get(), componentData.type)) {
|
||||
if (!componentData.payload.empty()) {
|
||||
std::istringstream componentStream(componentData.payload);
|
||||
@@ -396,11 +420,24 @@ std::string Scene::SerializeToString() const {
|
||||
void Scene::Load(const std::string& filePath) {
|
||||
std::ifstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
Debug::Logger::Get().Warning(
|
||||
Debug::LogCategory::FileSystem,
|
||||
Containers::String("[Scene] Load failed to open file=") + Containers::String(filePath.c_str()));
|
||||
return;
|
||||
}
|
||||
|
||||
Debug::Logger::Get().Info(
|
||||
Debug::LogCategory::FileSystem,
|
||||
Containers::String("[Scene] Load file=") + Containers::String(filePath.c_str()));
|
||||
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
Debug::Logger::Get().Info(
|
||||
Debug::LogCategory::FileSystem,
|
||||
Containers::String("[Scene] Load bytes=") +
|
||||
Containers::String(std::to_string(buffer.str().size()).c_str()) +
|
||||
" file=" +
|
||||
Containers::String(filePath.c_str()));
|
||||
DeserializeFromString(buffer.str());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user