Moved Scene implementation around

This commit is contained in:
2023-02-21 20:59:42 -08:00
parent cd686c2bd6
commit c065ab08b3
42 changed files with 540 additions and 459 deletions

View File

@ -1,36 +1,36 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "asset/AssetManager.hpp"
#include "scene/Scene.hpp"
#include "util/array.hpp"
namespace Dawn {
template<class O, typename J, class P = O>
class Prefab {
public:
/**
* Returns the list of assets required for this prefab.
*
* @param man Asset Manasger for getting required assets from.
* @return List of required assets this prefab.
*/
static std::vector<Asset*> getRequiredAssets(AssetManager *man) {
return P::prefabAssets(man);
}
/**
* Creates a new instance of this prefabricated asset.
*
* @param context Custom context that this prefab needs to initialize.
* @return The instance of the created prefab.
*/
static O * create(J *context) {
assertNotNull(context);
return P::prefabCreate(context);
}
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "asset/AssetManager.hpp"
#include "scene/SceneItemComponent.hpp"
#include "util/array.hpp"
namespace Dawn {
template<class O, typename J, class P = O>
class Prefab {
public:
/**
* Returns the list of assets required for this prefab.
*
* @param man Asset Manasger for getting required assets from.
* @return List of required assets this prefab.
*/
static std::vector<Asset*> getRequiredAssets(AssetManager *man) {
return P::prefabAssets(man);
}
/**
* Creates a new instance of this prefabricated asset.
*
* @param context Custom context that this prefab needs to initialize.
* @return The instance of the created prefab.
*/
static O * create(J *context) {
assertNotNull(context);
return P::prefabCreate(context);
}
};
}

View File

@ -1,48 +1,47 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "Prefab.hpp"
#include "scene/SceneItem.hpp"
#include "game/DawnGame.hpp"
namespace Dawn {
template<class O>
class SceneItemPrefab :
public SceneItem,
public Prefab<O, Scene, O>
{
public:
/**
* Creates an instance of this prefab for the given scene.
*
* @param scene Scene that this prefab is going to be added to.
* @return The created prefab instance.
*/
static O * prefabCreate(Scene *scene) {
O *item = scene->createSceneItemOfType<O>();
item->prefabInit(&scene->game->assetManager);
return item;
}
/**
* Constructor for this SceneItemPrefab.
*
* @param scene Scene that this prefab belongs to.
* @param id ID of this scene item.
*/
SceneItemPrefab(Scene *scene, sceneitemid_t id) :
SceneItem(scene, id)
{
}
/**
* Virtual method called by the subclass for initialization after the
* prefab has been created.
*/
virtual void prefabInit(AssetManager *man) = 0;
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "Prefab.hpp"
#include "game/DawnGame.hpp"
namespace Dawn {
template<class O>
class SceneItemPrefab :
public SceneItem,
public Prefab<O, Scene, O>
{
public:
/**
* Creates an instance of this prefab for the given scene.
*
* @param scene Scene that this prefab is going to be added to.
* @return The created prefab instance.
*/
static O * prefabCreate(Scene *scene) {
O *item = scene->createSceneItemOfType<O>();
item->prefabInit(&scene->game->assetManager);
return item;
}
/**
* Constructor for this SceneItemPrefab.
*
* @param scene Scene that this prefab belongs to.
* @param id ID of this scene item.
*/
SceneItemPrefab(Scene *scene, sceneitemid_t id) :
SceneItem(scene, id)
{
}
/**
* Virtual method called by the subclass for initialization after the
* prefab has been created.
*/
virtual void prefabInit(AssetManager *man) = 0;
};
}