Commit prog
This commit is contained in:
		| @@ -18,6 +18,7 @@ void Camera::onInit() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void Camera::onDispose() { | void Camera::onDispose() { | ||||||
|  |   std::cout << "Camera Disposing" << std::endl; | ||||||
|   renderTarget = nullptr; |   renderTarget = nullptr; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -48,4 +48,9 @@ std::shared_ptr<Scene> Game::getCurrentScene() { | |||||||
| } | } | ||||||
|  |  | ||||||
| Game::~Game() { | Game::~Game() { | ||||||
|  |   currentScene = nullptr; | ||||||
|  |   nextFrameScene = nullptr; | ||||||
|  |    | ||||||
|  |   assertTrue(SCENE_ITEMS_ACTIVE == 0, "Some scene items are still active?"); | ||||||
|  |   assertTrue(SCENE_COMPONENTS_ACTIVE == 0, "Some scene components are still active?"); | ||||||
| } | } | ||||||
| @@ -67,4 +67,6 @@ void Scene::removeItem(const std::shared_ptr<SceneItem> item) { | |||||||
| } | } | ||||||
|  |  | ||||||
| Scene::~Scene() { | Scene::~Scene() { | ||||||
|  |   sceneItemsToRemove.clear(); | ||||||
|  |   sceneItems.clear(); | ||||||
| } | } | ||||||
| @@ -10,7 +10,11 @@ | |||||||
|  |  | ||||||
| using namespace Dawn; | using namespace Dawn; | ||||||
|  |  | ||||||
|  | uint64_t SCENE_COMPONENTS_ACTIVE = 0; | ||||||
|  |  | ||||||
| void SceneComponent::init(const std::shared_ptr<SceneItem> item) { | void SceneComponent::init(const std::shared_ptr<SceneItem> item) { | ||||||
|  |   SCENE_COMPONENTS_ACTIVE++; | ||||||
|  |  | ||||||
|   assertFlagOff( |   assertFlagOff( | ||||||
|     sceneComponentState, |     sceneComponentState, | ||||||
|     SCENE_COMPONENT_STATE_INIT, |     SCENE_COMPONENT_STATE_INIT, | ||||||
| @@ -45,10 +49,11 @@ void SceneComponent::dispose() { | |||||||
|   this->listeners.clear(); |   this->listeners.clear(); | ||||||
|  |  | ||||||
|   this->onDispose(); |   this->onDispose(); | ||||||
|   this->item = nullptr; |   this->item.reset(); | ||||||
| } | } | ||||||
|  |  | ||||||
| std::shared_ptr<SceneItem> SceneComponent::getItem() { | std::shared_ptr<SceneItem> SceneComponent::getItem() { | ||||||
|  |   auto item = this->item.lock(); | ||||||
|   assertNotNull(item, "Item cannot be null?"); |   assertNotNull(item, "Item cannot be null?"); | ||||||
|   return item; |   return item; | ||||||
| } | } | ||||||
| @@ -78,4 +83,7 @@ SceneComponent::~SceneComponent() { | |||||||
|       "SceneComponent is initialized but was not properly disposed!" |       "SceneComponent is initialized but was not properly disposed!" | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   this->item.reset(); | ||||||
|  |   SCENE_COMPONENTS_ACTIVE--; | ||||||
| } | } | ||||||
| @@ -9,6 +9,8 @@ | |||||||
| #define SCENE_COMPONENT_STATE_INIT 0x01 | #define SCENE_COMPONENT_STATE_INIT 0x01 | ||||||
| #define SCENE_COMPONENT_STATE_DISPOSED 0x02 | #define SCENE_COMPONENT_STATE_DISPOSED 0x02 | ||||||
|  |  | ||||||
|  | extern uint64_t SCENE_COMPONENTS_ACTIVE; | ||||||
|  |  | ||||||
| namespace Dawn { | namespace Dawn { | ||||||
|   class Game; |   class Game; | ||||||
|   class Scene; |   class Scene; | ||||||
| @@ -17,7 +19,7 @@ namespace Dawn { | |||||||
|  |  | ||||||
|   class SceneComponent : std::enable_shared_from_this<SceneComponent> { |   class SceneComponent : std::enable_shared_from_this<SceneComponent> { | ||||||
|     private: |     private: | ||||||
|       std::shared_ptr<SceneItem> item; |       std::weak_ptr<SceneItem> item; | ||||||
|       uint_fast8_t sceneComponentState = 0; |       uint_fast8_t sceneComponentState = 0; | ||||||
|  |  | ||||||
|     protected: |     protected: | ||||||
|   | |||||||
| @@ -8,11 +8,15 @@ | |||||||
|  |  | ||||||
| using namespace Dawn; | using namespace Dawn; | ||||||
|  |  | ||||||
|  | uint64_t SCENE_ITEMS_ACTIVE = 0; | ||||||
|  |  | ||||||
| SceneItem::SceneItem(const std::weak_ptr<Scene> scene) : | SceneItem::SceneItem(const std::weak_ptr<Scene> scene) : | ||||||
|   scene(scene), |   scene(scene), | ||||||
|   SceneItemTransform(), |   SceneItemTransform(), | ||||||
|   SceneItemComponents() |   SceneItemComponents() | ||||||
| { | { | ||||||
|  |   std::cout << "Scene Item Initializing" << std::endl; | ||||||
|  |   SCENE_ITEMS_ACTIVE++; | ||||||
| } | } | ||||||
|  |  | ||||||
| std::shared_ptr<SceneItem> SceneItem::sceneItemComponentsSelf() { | std::shared_ptr<SceneItem> SceneItem::sceneItemComponentsSelf() { | ||||||
| @@ -37,12 +41,6 @@ void SceneItem::remove() { | |||||||
| } | } | ||||||
|  |  | ||||||
| SceneItem::~SceneItem() { | SceneItem::~SceneItem() { | ||||||
|   std::for_each( |   std::cout << "Scene Item Disposing" << std::endl; | ||||||
|     components.begin(), |   SCENE_ITEMS_ACTIVE--; | ||||||
|     components.end(), |  | ||||||
|     [](auto &component) { |  | ||||||
|       component->dispose(); |  | ||||||
|     } |  | ||||||
|   ); |  | ||||||
|   this->components.clear(); |  | ||||||
| } | } | ||||||
| @@ -7,6 +7,8 @@ | |||||||
| #include "scene/item/SceneItemTransform.hpp" | #include "scene/item/SceneItemTransform.hpp" | ||||||
| #include "scene/item/SceneItemComponents.hpp" | #include "scene/item/SceneItemComponents.hpp" | ||||||
|  |  | ||||||
|  | extern uint64_t SCENE_ITEMS_ACTIVE; | ||||||
|  |  | ||||||
| namespace Dawn { | namespace Dawn { | ||||||
|   class Scene; |   class Scene; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -21,5 +21,11 @@ void SceneItemComponents::removeComponent( | |||||||
| } | } | ||||||
|  |  | ||||||
| SceneItemComponents::~SceneItemComponents() { | SceneItemComponents::~SceneItemComponents() { | ||||||
|  |   auto it = components.begin(); | ||||||
|  |   while(it != components.end()) { | ||||||
|  |     auto component = *it; | ||||||
|  |     component->dispose(); | ||||||
|  |     ++it; | ||||||
|  |   } | ||||||
|  |   components.clear(); | ||||||
| } | } | ||||||
| @@ -205,4 +205,6 @@ SceneItemTransform::~SceneItemTransform() { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   ); |   ); | ||||||
|  |   this->children.clear(); | ||||||
|  |   this->parent.reset(); | ||||||
| } | } | ||||||
| @@ -48,6 +48,6 @@ void Dawn::worldScene(Scene &s) { | |||||||
|   auto player = createPlayerPrefab(map.map); |   auto player = createPlayerPrefab(map.map); | ||||||
|   player.player->camera = camera; |   player.player->camera = camera; | ||||||
|  |  | ||||||
|   auto test = createTestEntityPrefab(map.map); |   // auto test = createTestEntityPrefab(map.map); | ||||||
|   test.entity->setPosition({ 5, 0, 0 }); |   // test.entity->setPosition({ 5, 0, 0 }); | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user