Add context sharing on prefabs.
This commit is contained in:
@@ -35,7 +35,9 @@ void LoaderForSceneItems::setupDependencies() {
|
||||
loader = getAssetManager()->get<JSONLoader>(path);
|
||||
|
||||
} else if(type == "prefab") {
|
||||
loader = getAssetManager()->get<PrefabLoader>(path);
|
||||
auto prefabLoader = getAssetManager()->get<PrefabLoader>(path);
|
||||
prefabLoader->parentLoader = weak_from_this();
|
||||
loader = prefabLoader;
|
||||
|
||||
} else {
|
||||
assertUnreachable("Unknown asset type: %s", type.c_str());
|
||||
|
||||
@@ -8,10 +8,14 @@
|
||||
#include "scene/Scene.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class LoaderForSceneItems : public AssetLoader {
|
||||
class LoaderForSceneitems;
|
||||
|
||||
class LoaderForSceneItems :
|
||||
public AssetLoader,
|
||||
public std::enable_shared_from_this<LoaderForSceneItems>
|
||||
{
|
||||
protected:
|
||||
std::shared_ptr<JSONLoader> jsonLoader;
|
||||
struct SceneComponentLoadContext ctx;
|
||||
|
||||
/**
|
||||
* Loads the dependencies into the context for the data available in
|
||||
@@ -20,6 +24,8 @@ namespace Dawn {
|
||||
void setupDependencies();
|
||||
|
||||
public:
|
||||
struct SceneComponentLoadContext ctx;
|
||||
|
||||
LoaderForSceneItems(
|
||||
const std::shared_ptr<AssetManager> assetManager,
|
||||
const std::string name
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "PrefabLoader.hpp"
|
||||
#include "SceneLoader.hpp"
|
||||
#include "game/Game.hpp"
|
||||
#include "assert/assert.hpp"
|
||||
#include "asset/loader/TextureLoader.hpp"
|
||||
@@ -64,6 +65,11 @@ std::string PrefabLoader::getAssetType() const {
|
||||
void PrefabLoader::stagePrefab(std::shared_ptr<SceneItem> item) {
|
||||
assertTrue(this->loaded, "Prefab not loaded");
|
||||
|
||||
// Can we merge with the parent context?
|
||||
auto parentLoaderLock = this->parentLoader.lock();
|
||||
if(parentLoaderLock) this->ctx.merge(parentLoaderLock->ctx);
|
||||
|
||||
// Force-set new context values
|
||||
ctx.scene = item->getScene();
|
||||
ctx.data = this->jsonLoader->data;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "scene/Scene.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
|
||||
enum class PrefabLoaderState {
|
||||
INITIAL,
|
||||
LOADING_JSON,
|
||||
@@ -23,6 +24,7 @@ namespace Dawn {
|
||||
|
||||
public:
|
||||
const static std::string ASSET_TYPE;
|
||||
std::weak_ptr<LoaderForSceneItems> parentLoader;
|
||||
|
||||
PrefabLoader(
|
||||
const std::shared_ptr<AssetManager> assetManager,
|
||||
|
||||
Reference in New Issue
Block a user