Changed scene item components to smart pointers

This commit is contained in:
2023-11-10 23:21:59 -06:00
parent 085facd079
commit 7b1933159b
33 changed files with 84 additions and 97 deletions

View File

@ -59,7 +59,7 @@ void RenderPipeline::renderScene(std::shared_ptr<Scene> scene) {
// Now render backbuffers. // Now render backbuffers.
auto backBuffer = rm->getBackBuffer(); auto backBuffer = rm->getBackBuffer();
auto cameras = scene->findComponents<Camera>(); auto cameras = scene->findComponents<Camera>();
Camera *backBufferCamera = nullptr; std::shared_ptr<Camera> backBufferCamera;
// First, render all non-backbuffer cameras. // First, render all non-backbuffer cameras.
auto it = cameras.begin(); auto it = cameras.begin();
@ -74,7 +74,7 @@ void RenderPipeline::renderScene(std::shared_ptr<Scene> scene) {
} else if(cameraTarget == backBuffer) { } else if(cameraTarget == backBuffer) {
backBufferCamera = *it; backBufferCamera = *it;
} else { } else {
renderSceneCamera(&(*scene), *it); renderSceneCamera(scene, *it);
} }
++it; ++it;
@ -82,10 +82,10 @@ void RenderPipeline::renderScene(std::shared_ptr<Scene> scene) {
// Now render the backbuffer camera. // Now render the backbuffer camera.
if(backBufferCamera == nullptr) return; if(backBufferCamera == nullptr) return;
renderSceneCamera(&(*scene), backBufferCamera); renderSceneCamera(scene, backBufferCamera);
} }
void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) { void RenderPipeline::renderSceneCamera(std::shared_ptr<Scene> scene, std::shared_ptr<Camera> camera) {
auto rm = renderManager.lock(); auto rm = renderManager.lock();
assertNotNull(rm, "RenderPipeline::renderSceneCamera: RenderManager cannot be null"); assertNotNull(rm, "RenderPipeline::renderSceneCamera: RenderManager cannot be null");
@ -114,7 +114,7 @@ void RenderPipeline::renderSceneCamera(Scene *scene, Camera *camera) {
struct IRenderableContext context = { struct IRenderableContext context = {
scene, scene,
camera, camera,
this shared_from_this()
}; };
// Get the list of things to render first. // Get the list of things to render first.

View File

@ -13,7 +13,7 @@
namespace Dawn { namespace Dawn {
class RenderManager; class RenderManager;
class RenderPipeline { class RenderPipeline : public std::enable_shared_from_this<RenderPipeline> {
private: private:
int_fast16_t renderId = -1; int_fast16_t renderId = -1;
@ -54,7 +54,7 @@ namespace Dawn {
* @param scene Scene to render. * @param scene Scene to render.
* @param camera Camera within the scene to render. * @param camera Camera within the scene to render.
*/ */
virtual void renderSceneCamera(Scene *scene, Camera *camera); virtual void renderSceneCamera(std::shared_ptr<Scene> scene, std::shared_ptr<Camera> camera);
/** /**
* Cleanup a render pipeline that has been initialized. * Cleanup a render pipeline that has been initialized.

View File

@ -17,7 +17,7 @@ namespace Dawn {
public SceneItemPrefab<SimpleSpinningCubePrefab> public SceneItemPrefab<SimpleSpinningCubePrefab>
{ {
public: public:
SimpleTexturedMaterial *material; std::shared_ptr<SimpleTexturedMaterial> material;
static std::vector<std::shared_ptr<Asset>> prefabAssets(AssetManager *man) { static std::vector<std::shared_ptr<Asset>> prefabAssets(AssetManager *man) {
return std::vector<std::shared_ptr<Asset>>(); return std::vector<std::shared_ptr<Asset>>();

View File

@ -20,10 +20,10 @@ namespace Dawn {
typedef int32_t sceneitemid_t; typedef int32_t sceneitemid_t;
template<class T> template<class T>
T * _sceneForwardGetComponent(SceneItem *item); std::shared_ptr<T> _sceneForwardGetComponent(SceneItem *item);
template<class T> template<class T>
std::vector<T*> _sceneForwardGetComponents(SceneItem *item); std::vector<std::shared_ptr<T>> _sceneForwardGetComponents(SceneItem *item);
class Scene : public StateOwner { class Scene : public StateOwner {
private: private:
@ -95,7 +95,7 @@ namespace Dawn {
* @return Pointer to the found component (and by extension the item). * @return Pointer to the found component (and by extension the item).
*/ */
template<class T> template<class T>
T * findComponent() { std::shared_ptr<T> findComponent() {
auto it = this->itemsNotInitialized.begin(); auto it = this->itemsNotInitialized.begin();
while(it != this->itemsNotInitialized.end()) { while(it != this->itemsNotInitialized.end()) {
auto component = _sceneForwardGetComponent<T>(it->second); auto component = _sceneForwardGetComponent<T>(it->second);
@ -119,8 +119,8 @@ namespace Dawn {
* @return List of matching compnoents. * @return List of matching compnoents.
*/ */
template<class T> template<class T>
std::vector<T*> findComponents() { std::vector<std::shared_ptr<T>> findComponents() {
std::vector<T*> components; std::vector<std::shared_ptr<T>> components;
auto it = this->itemsNotInitialized.begin(); auto it = this->itemsNotInitialized.begin();
while(it != this->itemsNotInitialized.end()) { while(it != this->itemsNotInitialized.end()) {

View File

@ -60,18 +60,8 @@ void SceneItem::init() {
} }
void SceneItem::destroy() { void SceneItem::destroy() {
auto it = this->components.begin(); this->components.clear();
while(it != this->components.end()) {
(*it)->onDispose();
++it;
}
} }
SceneItem::~SceneItem() { SceneItem::~SceneItem() {
auto it = this->components.begin();
it = this->components.begin();
while(it != this->components.end()) {
delete *it;
++it;
}
} }

View File

@ -13,7 +13,7 @@ namespace Dawn {
class SceneItem : public StateOwner { class SceneItem : public StateOwner {
private: private:
std::vector<SceneItemComponent*> components; std::vector<std::shared_ptr<SceneItemComponent>> components;
public: public:
Scene *scene; Scene *scene;
@ -52,9 +52,8 @@ namespace Dawn {
* @return A shared pointer to the newly added component. * @return A shared pointer to the newly added component.
*/ */
template<class T> template<class T>
T * addComponent() { std::shared_ptr<T> addComponent() {
auto component = new T(this); auto component = std::make_shared<T>(this);
assertNotNull(component, "SceneItem::addComponent: Component could not be created (Memory filled?)");
this->components.push_back(component); this->components.push_back(component);
return component; return component;
} }
@ -68,10 +67,10 @@ namespace Dawn {
* @return A shared pointer to the component, or nullptr if not found. * @return A shared pointer to the component, or nullptr if not found.
*/ */
template<class T> template<class T>
T * getComponent() { std::shared_ptr<T> getComponent() {
auto it = this->components.begin(); auto it = this->components.begin();
while(it != this->components.end()) { while(it != this->components.end()) {
T *castedAs = dynamic_cast<T*>(*it); std::shared_ptr<T> castedAs = std::dynamic_pointer_cast<T>(*it);
if(castedAs != nullptr) return castedAs; if(castedAs != nullptr) return castedAs;
++it; ++it;
} }
@ -88,11 +87,11 @@ namespace Dawn {
* @return An array of pointers to the components. * @return An array of pointers to the components.
*/ */
template<class T> template<class T>
std::vector<T*> getComponents() { std::vector<std::shared_ptr<T>> getComponents() {
std::vector<T*> components; std::vector<std::shared_ptr<T>> components;
auto it = this->components.begin(); auto it = this->components.begin();
while(it != this->components.end()) { while(it != this->components.end()) {
T *castedAs = dynamic_cast<T*>(*it); T *castedAs = std::dynamic_pointer_cast<T>(it);
if(castedAs != nullptr) components.push_back(castedAs); if(castedAs != nullptr) components.push_back(castedAs);
++it; ++it;
} }
@ -106,7 +105,7 @@ namespace Dawn {
* @return Pointer to the child, or nullptr if not found. * @return Pointer to the child, or nullptr if not found.
*/ */
template<class T> template<class T>
T * findChild() { std::shared_ptr<T> findChild() {
auto it = this->transform.children.begin(); auto it = this->transform.children.begin();
while(it != this->transform.children.end()) { while(it != this->transform.children.end()) {
auto child = (*it)->item->getComponent<T>(); auto child = (*it)->item->getComponent<T>();
@ -124,9 +123,9 @@ namespace Dawn {
* @return Array of pointers to matching children. * @return Array of pointers to matching children.
*/ */
template<class T> template<class T>
std::vector<T*> findChildren() { std::vector<std::shared_ptr<T>> findChildren() {
auto it = this->transform.children.begin(); auto it = this->transform.children.begin();
std::vector<T*> children; std::vector<std::shared_ptr<T>> children;
while(it != this->transform.children.end()) { while(it != this->transform.children.end()) {
auto child = (*it)->item->getComponent<T>(); auto child = (*it)->item->getComponent<T>();
if(child != nullptr) children.push_back(child); if(child != nullptr) children.push_back(child);
@ -143,9 +142,9 @@ namespace Dawn {
* @return Array of pointers to matching children components. * @return Array of pointers to matching children components.
*/ */
template<class T> template<class T>
std::vector<T*> findChildrenDeep() { std::vector<std::shared_ptr<T>> findChildrenDeep() {
std::vector<Transform*> transformsToCheck = this->transform.children; std::vector<Transform*> transformsToCheck = this->transform.children;
std::vector<T*> itemsFound; std::vector<std::shared_ptr<T>> itemsFound;
while(transformsToCheck.size() > 0) { while(transformsToCheck.size() > 0) {
Transform *tras = *transformsToCheck.begin(); Transform *tras = *transformsToCheck.begin();

View File

@ -21,8 +21,8 @@ void SceneItemComponent::init() {
this->hasInitialized = true; this->hasInitialized = true;
} }
std::vector<SceneItemComponent*> SceneItemComponent::getDependencies() { std::vector<std::shared_ptr<SceneItemComponent>> SceneItemComponent::getDependencies() {
return std::vector<SceneItemComponent*>(); return {};
} }
Scene * SceneItemComponent::getScene() { Scene * SceneItemComponent::getScene() {

View File

@ -39,7 +39,7 @@ namespace Dawn {
* *
* @return Array of dependencies. * @return Array of dependencies.
*/ */
virtual std::vector<SceneItemComponent*> getDependencies(); virtual std::vector<std::shared_ptr<SceneItemComponent>> getDependencies();
/** /**
* Shorthand to return the scene that this component's item belongs to. * Shorthand to return the scene that this component's item belongs to.
@ -80,12 +80,12 @@ namespace Dawn {
}; };
template<class T> template<class T>
T * _sceneForwardGetComponent(SceneItem *item) { std::shared_ptr<T> _sceneForwardGetComponent(SceneItem *item) {
return item->getComponent<T>(); return item->getComponent<T>();
} }
template<class T> template<class T>
T * _sceneForwardGetComponents(SceneItem *item) { std::shared_ptr<T> _sceneForwardGetComponents(SceneItem *item) {
return item->getComponents<T>(); return item->getComponents<T>();
} }
} }

View File

@ -22,7 +22,7 @@ namespace Dawn {
std::function<void()> evtResized; std::function<void()> evtResized;
public: public:
static Camera * create(Scene *scene) { static std::shared_ptr<Camera> create(Scene *scene) {
auto item = scene->createSceneItem(); auto item = scene->createSceneItem();
auto cam = item->addComponent<Camera>(); auto cam = item->addComponent<Camera>();
return cam; return cam;

View File

@ -11,7 +11,7 @@ namespace Dawn {
class CameraTexture : public SceneItemComponent { class CameraTexture : public SceneItemComponent {
public: public:
// @optional // @optional
StateProperty<Camera*> camera; StateProperty<std::shared_ptr<Camera>> camera;
std::shared_ptr<TextureRenderTarget> renderTarget; std::shared_ptr<TextureRenderTarget> renderTarget;
CameraTexture(SceneItem *item); CameraTexture(SceneItem *item);

View File

@ -12,9 +12,9 @@ namespace Dawn {
class RenderPipeline; class RenderPipeline;
struct IRenderableContext { struct IRenderableContext {
Scene *scene; std::shared_ptr<Scene> scene;
Camera *camera; std::shared_ptr<Camera> camera;
RenderPipeline *renderPipeline; std::shared_ptr<RenderPipeline> renderPipeline;
}; };
class IRenderable { class IRenderable {

View File

@ -55,7 +55,7 @@ void PixelPerfectCamera::onStart() {
}, scale); }, scale);
useEffectWithTeardown([&]{ useEffectWithTeardown([&]{
if(!camera) { if(!camera._realValue) {
return teardown = [&]{}; return teardown = [&]{};
} }

View File

@ -18,7 +18,7 @@ namespace Dawn {
public: public:
// @optional // @optional
StateProperty<Camera*> camera; StateProperty<std::shared_ptr<Camera>> camera;
// @optional // @optional
StateProperty<float_t> scale; StateProperty<float_t> scale;

View File

@ -13,8 +13,8 @@ SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
{ {
} }
std::vector<SceneItemComponent*> SimpleRenderTargetQuad::getDependencies() { std::vector<std::shared_ptr<SceneItemComponent>> SimpleRenderTargetQuad::getDependencies() {
return std::vector<SceneItemComponent*>{ return {
(this->meshHost = this->item->getComponent<MeshHost>()) (this->meshHost = this->item->getComponent<MeshHost>())
}; };
} }

View File

@ -11,7 +11,7 @@
namespace Dawn { namespace Dawn {
class SimpleRenderTargetQuad : public SceneItemComponent { class SimpleRenderTargetQuad : public SceneItemComponent {
protected: protected:
MeshHost *meshHost = nullptr; std::shared_ptr<MeshHost> meshHost;
std::function<void()> evtResized; std::function<void()> evtResized;
public: public:
@ -27,7 +27,7 @@ namespace Dawn {
*/ */
SimpleRenderTargetQuad(SceneItem *item); SimpleRenderTargetQuad(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies() override; std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
void onStart() override; void onStart() override;
}; };
} }

View File

@ -20,14 +20,12 @@ TiledSprite::TiledSprite(SceneItem *item) :
} }
std::vector<SceneItemComponent*> TiledSprite::getDependencies() { std::vector<std::shared_ptr<SceneItemComponent>> TiledSprite::getDependencies() {
if(this->meshHost == nullptr) { if(this->meshHost == nullptr) {
this->meshHost = this->item->getComponent<QuadMeshHost>(); this->meshHost = this->item->getComponent<QuadMeshHost>();
} }
return { return { this->meshHost._realValue };
this->meshHost
};
} }
void TiledSprite::onStart() { void TiledSprite::onStart() {

View File

@ -22,7 +22,7 @@ namespace Dawn {
// @optional // @optional
StateProperty<Tileset*> tileset; StateProperty<Tileset*> tileset;
// @optional // @optional
StateProperty<QuadMeshHost*> meshHost; StateProperty<std::shared_ptr<QuadMeshHost>> meshHost;
// @optional // @optional
StateProperty<int32_t> tile; StateProperty<int32_t> tile;
// @optional // @optional
@ -33,7 +33,7 @@ namespace Dawn {
StateProperty<float_t> size; StateProperty<float_t> size;
TiledSprite(SceneItem *item); TiledSprite(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies(); std::vector<std::shared_ptr<SceneItemComponent>> getDependencies();
void onStart() override; void onStart() override;
}; };
} }

View File

@ -12,8 +12,8 @@ using namespace Dawn;
MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) { MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) {
} }
std::vector<SceneItemComponent*> MeshRenderer::getDependencies() { std::vector<std::shared_ptr<SceneItemComponent>> MeshRenderer::getDependencies() {
return std::vector<SceneItemComponent*>{ return {
this->meshHost = this->item->getComponent<MeshHost>() this->meshHost = this->item->getComponent<MeshHost>()
}; };
} }

View File

@ -12,7 +12,7 @@ namespace Dawn {
class MeshRenderer : public SceneItemComponent { class MeshRenderer : public SceneItemComponent {
protected: protected:
MeshHost *meshHost = nullptr; std::shared_ptr<MeshHost> meshHost;
public: public:
// @optional // @optional
@ -25,7 +25,7 @@ namespace Dawn {
*/ */
MeshRenderer(SceneItem *item); MeshRenderer(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies() override; std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
void onStart() override; void onStart() override;
}; };
} }

View File

@ -9,7 +9,7 @@
namespace Dawn { namespace Dawn {
struct CharacterController2DCollisionEventInfo { struct CharacterController2DCollisionEventInfo {
SolidController2D *collider; std::shared_ptr<SolidController2D> collider;
glm::vec2 normal; glm::vec2 normal;
float_t entryTime; float_t entryTime;
float_t exitTime; float_t exitTime;

View File

@ -10,7 +10,7 @@ using namespace Dawn;
SolidController2D::SolidController2D(SceneItem *item) : SceneItemComponent(item) { SolidController2D::SolidController2D(SceneItem *item) : SceneItemComponent(item) {
} }
std::vector<SceneItemComponent*> SolidController2D::getDependencies() { std::vector<std::shared_ptr<SceneItemComponent>> SolidController2D::getDependencies() {
return { return {
(this->collider = item->getComponent<Collider2D>()) (this->collider = item->getComponent<Collider2D>())
}; };
@ -18,7 +18,7 @@ std::vector<SceneItemComponent*> SolidController2D::getDependencies() {
bool_t SolidController2D::getCollidingResult( bool_t SolidController2D::getCollidingResult(
glm::vec2 movement, glm::vec2 movement,
Collider2D *movingObject, std::shared_ptr<Collider2D> movingObject,
glm::vec2 &normal, glm::vec2 &normal,
float_t &entryTime, float_t &entryTime,
float_t &exitTime, float_t &exitTime,
@ -34,13 +34,13 @@ bool_t SolidController2D::getCollidingResult(
// Check what the moving object is // Check what the moving object is
switch(movingObject->getColliderType()) { switch(movingObject->getColliderType()) {
case COLLIDER2D_TYPE_BOX: { case COLLIDER2D_TYPE_BOX: {
auto box1 = dynamic_cast<BoxCollider*>(movingObject); auto box1 = std::static_pointer_cast<BoxCollider>(movingObject);
assertNotNull(box1, "SolidController2D::getCollidingResult: Moving object is not a BoxCollider"); assertNotNull(box1, "SolidController2D::getCollidingResult: Moving object is not a BoxCollider");
// Box VS (this)? // Box VS (this)?
switch(this->collider->getColliderType()) { switch(this->collider->getColliderType()) {
case COLLIDER2D_TYPE_BOX: { case COLLIDER2D_TYPE_BOX: {
auto box2 = dynamic_cast<BoxCollider*>(this->collider); auto box2 = std::static_pointer_cast<BoxCollider>(this->collider);
assertNotNull(box2, "SolidController2D::getCollidingResult: Collider is not a BoxCollider"); assertNotNull(box2, "SolidController2D::getCollidingResult: Collider is not a BoxCollider");
auto otherPos = physics3Dto2D(box2->transform->getWorldPosition()); auto otherPos = physics3Dto2D(box2->transform->getWorldPosition());

View File

@ -10,10 +10,10 @@
namespace Dawn { namespace Dawn {
class SolidController2D : public SceneItemComponent { class SolidController2D : public SceneItemComponent {
public: public:
Collider2D *collider = nullptr; std::shared_ptr<Collider2D> collider;
SolidController2D(SceneItem *item); SolidController2D(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies() override; std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
/** /**
* Gets the result of checking if two collider bodies are intersecting. * Gets the result of checking if two collider bodies are intersecting.
@ -31,7 +31,7 @@ namespace Dawn {
*/ */
bool_t getCollidingResult( bool_t getCollidingResult(
glm::vec2 movement, glm::vec2 movement,
Collider2D *movingObject, std::shared_ptr<Collider2D> movingObject,
glm::vec2 &normal, glm::vec2 &normal,
float_t &entryTime, float_t &entryTime,
float_t &exitTime, float_t &exitTime,

View File

@ -11,25 +11,25 @@ TriggerController2D::TriggerController2D(SceneItem *i) : SceneItemComponent(i) {
} }
std::vector<SceneItemComponent*> TriggerController2D::getDependencies() { std::vector<std::shared_ptr<SceneItemComponent>> TriggerController2D::getDependencies() {
return { return {
(this->collider = this->item->getComponent<Collider2D>()) (this->collider = this->item->getComponent<Collider2D>())
}; };
} }
bool_t TriggerController2D::getCollidingResult(Collider2D* movingObject) { bool_t TriggerController2D::getCollidingResult(std::shared_ptr<Collider2D> movingObject) {
assertNotNull(this->collider, "TriggerController2D::getCollidingResult: Collider cannot be null"); assertNotNull(this->collider, "TriggerController2D::getCollidingResult: Collider cannot be null");
assertNotNull(movingObject, "TriggerController2D::getCollidingResult: Moving object cannot be null"); assertNotNull(movingObject, "TriggerController2D::getCollidingResult: Moving object cannot be null");
switch(movingObject->getColliderType()) { switch(movingObject->getColliderType()) {
case COLLIDER2D_TYPE_BOX: { case COLLIDER2D_TYPE_BOX: {
auto box1 = dynamic_cast<BoxCollider*>(movingObject); auto box1 = std::static_pointer_cast<BoxCollider>(movingObject);
assertNotNull(box1, "TriggerController2D::getCollidingResult: Moving object is not a BoxCollider"); assertNotNull(box1, "TriggerController2D::getCollidingResult: Moving object is not a BoxCollider");
// Box VS ? // Box VS ?
switch(collider->getColliderType()) { switch(collider->getColliderType()) {
case COLLIDER2D_TYPE_BOX: { case COLLIDER2D_TYPE_BOX: {
auto box2 = dynamic_cast<BoxCollider*>(collider); auto box2 = std::static_pointer_cast<BoxCollider>(collider);
assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider"); assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider");
return boxIsBoxColliding( return boxIsBoxColliding(
physics3Dto2D(box1->transform->getWorldPosition()), box1->min, box1->max, physics3Dto2D(box1->transform->getWorldPosition()), box1->min, box1->max,

View File

@ -12,16 +12,16 @@ namespace Dawn {
class TriggerController2D : public SceneItemComponent { class TriggerController2D : public SceneItemComponent {
public: public:
Collider2D *collider = nullptr; std::shared_ptr<Collider2D> collider;
StateEvent<CharacterController2D*> eventTriggerEnter; StateEvent<CharacterController2D*> eventTriggerEnter;
TriggerController2D(SceneItem *i); TriggerController2D(SceneItem *i);
std::vector<SceneItemComponent*> getDependencies() override; std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
/** /**
* Returns whether or not the given moving object is colliding with this * Returns whether or not the given moving object is colliding with this
* trigger collider. * trigger collider.
*/ */
bool_t getCollidingResult(Collider2D* movingObject); bool_t getCollidingResult(std::shared_ptr<Collider2D> movingObject);
}; };
} }

View File

@ -9,7 +9,7 @@
using namespace Dawn; using namespace Dawn;
UICanvas * UICanvas::create(Scene *scene) { std::shared_ptr<UICanvas> UICanvas::create(Scene *scene) {
auto item = scene->createSceneItem(); auto item = scene->createSceneItem();
return item->addComponent<UICanvas>(); return item->addComponent<UICanvas>();
} }

View File

@ -83,10 +83,10 @@ namespace Dawn {
* @param scene Scene to create the UI Canvas for. * @param scene Scene to create the UI Canvas for.
* @return Created UI Canvas. * @return Created UI Canvas.
*/ */
static UICanvas * create(Scene *scene); static std::shared_ptr<UICanvas> create(Scene *scene);
//======================================================================// //======================================================================//
StateProperty<Camera*> camera; StateProperty<std::shared_ptr<Camera>> camera;
enum UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE; enum UIDrawType drawType = UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE;
/** /**

View File

@ -21,7 +21,7 @@ UIComponent::UIComponent(SceneItem *item) :
} }
UIComponentDimensional * UIComponent::getParentDimensional() { std::shared_ptr<UIComponentDimensional> UIComponent::getParentDimensional() {
auto parent = this->transform->getParent(); auto parent = this->transform->getParent();
if(parent == nullptr) return nullptr; if(parent == nullptr) return nullptr;
auto dimensional = parent->item->getComponent<UIComponentDimensional>(); auto dimensional = parent->item->getComponent<UIComponentDimensional>();
@ -238,7 +238,7 @@ void UIComponent::calculateDimensions(
} }
} }
UICanvas * UIComponent::getCanvas() { std::shared_ptr<UICanvas> UIComponent::getCanvas() {
// TODO: Cache this on first hit. // TODO: Cache this on first hit.
auto parent = this->transform->getParent(); auto parent = this->transform->getParent();
while(parent != nullptr) { while(parent != nullptr) {

View File

@ -38,7 +38,7 @@ namespace Dawn {
* *
* @return Pointer to the parent dimensional. * @return Pointer to the parent dimensional.
*/ */
UIComponentDimensional * getParentDimensional(); std::shared_ptr<UIComponentDimensional> getParentDimensional();
/** /**
* Internal method to update the alignment of this item. * Internal method to update the alignment of this item.
@ -130,7 +130,7 @@ namespace Dawn {
* *
* @return Pointer to the UI Canvas this component is a child of. * @return Pointer to the UI Canvas this component is a child of.
*/ */
virtual UICanvas * getCanvas(); virtual std::shared_ptr<UICanvas> getCanvas();
float_t getWidth() override; float_t getWidth() override;
float_t getHeight() override; float_t getHeight() override;

View File

@ -14,7 +14,7 @@ UISimpleMenu::UISimpleMenu(SceneItem *item) :
} }
std::vector<SceneItemComponent*> UISimpleMenu::getDependencies() { std::vector<std::shared_ptr<SceneItemComponent>> UISimpleMenu::getDependencies() {
return { return {
(this->menu = this->item->getComponent<UIMenuController>()), (this->menu = this->item->getComponent<UIMenuController>()),
(this->canvas == nullptr ? (this->canvas = this->item->getComponent<UICanvas>()) : nullptr) (this->canvas == nullptr ? (this->canvas = this->item->getComponent<UICanvas>()) : nullptr)

View File

@ -10,14 +10,14 @@
namespace Dawn { namespace Dawn {
class UISimpleMenu : public SceneItemComponent { class UISimpleMenu : public SceneItemComponent {
protected: protected:
UIMenuController *menu = nullptr; std::shared_ptr<UIMenuController> menu;
UICanvas *canvas = nullptr; std::shared_ptr<UICanvas> canvas;
UISimpleMenuItem *currentlySelected = nullptr; std::shared_ptr<UISimpleMenuItem> currentlySelected;
std::vector<UISimpleMenuItem*> menuItems; std::vector<std::shared_ptr<UISimpleMenuItem>> menuItems;
public: public:
UISimpleMenu(SceneItem *item); UISimpleMenu(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies() override; std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
void onStart() override; void onStart() override;
}; };
} }

View File

@ -11,7 +11,7 @@ UISimpleMenuItem::UISimpleMenuItem(SceneItem *item) : SceneItemComponent(item) {
} }
UIComponent * UISimpleMenuItem::getComponentForHighlighting() { std::shared_ptr<UIComponent> UISimpleMenuItem::getComponentForHighlighting() {
if(uiComponent == nullptr) uiComponent = item->getComponent<UIComponent>(); if(uiComponent == nullptr) uiComponent = item->getComponent<UIComponent>();
return uiComponent; return uiComponent;
} }

View File

@ -15,7 +15,7 @@ namespace Dawn {
// May make these into either state events or make a new event. // May make these into either state events or make a new event.
int32_t menuX = 0; int32_t menuX = 0;
int32_t menuY = 0; int32_t menuY = 0;
UIComponent *uiComponent = nullptr; std::shared_ptr<UIComponent> uiComponent = nullptr;
UISimpleMenuItem(SceneItem *item); UISimpleMenuItem(SceneItem *item);
@ -25,6 +25,6 @@ namespace Dawn {
* *
* @return UI Component to use for highlighting / hovering. * @return UI Component to use for highlighting / hovering.
*/ */
virtual UIComponent * getComponentForHighlighting(); virtual std::shared_ptr<UIComponent> getComponentForHighlighting();
}; };
} }

View File

@ -11,9 +11,9 @@
namespace Dawn { namespace Dawn {
class HelloWorldScene : public Scene { class HelloWorldScene : public Scene {
protected: protected:
Camera *camera; std::shared_ptr<Camera> camera;
SimpleSpinningCubePrefab *cube; SimpleSpinningCubePrefab *cube;
UICanvas *canvas; std::shared_ptr<UICanvas> canvas;
void stage() override { void stage() override {
camera = Camera::create(this); camera = Camera::create(this);