From c065ab08b3068a90860de9fb32494227d0d10995 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 21 Feb 2023 20:59:42 -0800 Subject: [PATCH] Moved Scene implementation around --- src/dawn/display/RenderPipeline.cpp | 1 - src/dawn/display/RenderPipeline.hpp | 2 - src/dawn/game/_DawnGame.hpp | 1 - src/dawn/physics/2d/Box.cpp | 15 ++ src/dawn/physics/2d/Box.hpp | 20 +++ src/dawn/physics/2d/CMakeLists.txt | 11 ++ .../{PhysicsManager.hpp => 2d/Circle.hpp} | 11 +- src/dawn/physics/2d/PhysicsGrid.hpp | 0 .../components => }/physics/2d/Ray2D.cpp | 52 +++--- .../components => }/physics/2d/Ray2D.hpp | 60 +++---- src/dawn/physics/CMakeLists.txt | 3 +- src/dawn/physics/ScenePhysicsManager.cpp | 17 ++ src/dawn/physics/ScenePhysicsManager.hpp | 29 ++++ src/dawn/poker/PokerPlayer.hpp | 1 - src/dawn/prefab/Prefab.hpp | 70 ++++---- src/dawn/prefab/SceneItemPrefab.hpp | 93 +++++----- src/dawn/scene/Scene.cpp | 2 + src/dawn/scene/Scene.hpp | 16 +- src/dawn/scene/SceneItem.cpp | 2 +- src/dawn/scene/SceneItem.hpp | 6 +- src/dawn/scene/SceneItemComponent.hpp | 10 +- .../display/AnimationController.cpp | 73 ++++---- src/dawn/scene/components/display/Camera.cpp | 1 - .../scene/components/display/Material.cpp | 1 - .../display/SimpleRenderTargetQuad.cpp | 159 +++++++++--------- .../scene/components/example/ExampleSpin.cpp | 87 +++++----- .../components/physics/2d/BoxCollider.cpp} | 7 +- .../components/physics/2d/BoxCollider.hpp | 18 ++ .../components/physics/2d/CMakeLists.txt | 20 +-- .../components/physics/3d/CMakeLists.txt | 8 +- .../components/physics/3d/RayTester3D.cpp | 44 ----- .../components/physics/3d/RayTester3D.hpp | 27 --- .../components/scene/SubSceneController.hpp | 54 +++--- src/dawn/scene/components/ui/UICanvas.cpp | 1 - src/dawn/ui/UIComponent.hpp | 1 - src/dawntictactoe/components/CMakeLists.txt | 1 + .../components/TicTacToeGame.cpp | 27 +++ .../components/TicTacToeGame.hpp | 21 +++ src/dawntictactoe/game/DawnGame.cpp | 1 - src/dawntictactoe/game/DawnGame.hpp | 1 - .../prefabs/TicTacToeTilePrefab.hpp | 8 +- src/dawntictactoe/scenes/TicTacToeScene.hpp | 17 +- 42 files changed, 540 insertions(+), 459 deletions(-) create mode 100644 src/dawn/physics/2d/Box.cpp create mode 100644 src/dawn/physics/2d/Box.hpp create mode 100644 src/dawn/physics/2d/CMakeLists.txt rename src/dawn/physics/{PhysicsManager.hpp => 2d/Circle.hpp} (56%) create mode 100644 src/dawn/physics/2d/PhysicsGrid.hpp rename src/dawn/{scene/components => }/physics/2d/Ray2D.cpp (96%) rename src/dawn/{scene/components => }/physics/2d/Ray2D.hpp (96%) create mode 100644 src/dawn/physics/ScenePhysicsManager.cpp create mode 100644 src/dawn/physics/ScenePhysicsManager.hpp rename src/dawn/{physics/PhysicsManager.cpp => scene/components/physics/2d/BoxCollider.cpp} (55%) create mode 100644 src/dawn/scene/components/physics/2d/BoxCollider.hpp delete mode 100644 src/dawn/scene/components/physics/3d/RayTester3D.cpp delete mode 100644 src/dawn/scene/components/physics/3d/RayTester3D.hpp create mode 100644 src/dawntictactoe/components/TicTacToeGame.cpp create mode 100644 src/dawntictactoe/components/TicTacToeGame.hpp diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 7b1e0584..56d902f7 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -5,7 +5,6 @@ #include "RenderPipeline.hpp" #include "game/DawnGame.hpp" -#include "display/RenderManager.hpp" using namespace Dawn; diff --git a/src/dawn/display/RenderPipeline.hpp b/src/dawn/display/RenderPipeline.hpp index cb45a2cf..bd601f7d 100644 --- a/src/dawn/display/RenderPipeline.hpp +++ b/src/dawn/display/RenderPipeline.hpp @@ -5,8 +5,6 @@ #pragma once #include "dawnlibs.hpp" -#include "scene/SceneItem.hpp" -#include "scene/Scene.hpp" #include "scene/components/display/Material.hpp" #include "scene/components/display/MeshRenderer.hpp" #include "scene/components/display/Camera.hpp" diff --git a/src/dawn/game/_DawnGame.hpp b/src/dawn/game/_DawnGame.hpp index 9c3564bb..47451b75 100644 --- a/src/dawn/game/_DawnGame.hpp +++ b/src/dawn/game/_DawnGame.hpp @@ -12,7 +12,6 @@ #include "time/TimeManager.hpp" #include "input/InputBinds.hpp" #include "locale/LocaleManager.hpp" -#include "physics/PhysicsManager.hpp" #include "save/SaveManager.hpp" #include "audio/AudioManager.hpp" diff --git a/src/dawn/physics/2d/Box.cpp b/src/dawn/physics/2d/Box.cpp new file mode 100644 index 00000000..486a6c5f --- /dev/null +++ b/src/dawn/physics/2d/Box.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "Box.hpp" + +using namespace Dawn; + +bool_t boxIsPointInside(glm::vec2 point, glm::vec2 min, glm::vec2 max) { + return ( + point.x >= min.x && point.x <= max.x && + point.y >= min.y && point.y <= max.y + ); +} \ No newline at end of file diff --git a/src/dawn/physics/2d/Box.hpp b/src/dawn/physics/2d/Box.hpp new file mode 100644 index 00000000..aedff741 --- /dev/null +++ b/src/dawn/physics/2d/Box.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawnlibs.hpp" +#include "assert/assert.hpp" + +namespace Dawn { + /** + * Checks if a given point is within the 2D Boundaries of an object. + * + * @param point Point to test. + * @param min Minimum point on the box. + * @param max Maximum point on the box. + * @return True if the point is within the box. + */ + static bool_t boxIsPointInside(glm::vec2 point, glm::vec2 min, glm::vec2 max); +} \ No newline at end of file diff --git a/src/dawn/physics/2d/CMakeLists.txt b/src/dawn/physics/2d/CMakeLists.txt new file mode 100644 index 00000000..18f96e0a --- /dev/null +++ b/src/dawn/physics/2d/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2023 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + Box.cpp + Ray2D.cpp +) \ No newline at end of file diff --git a/src/dawn/physics/PhysicsManager.hpp b/src/dawn/physics/2d/Circle.hpp similarity index 56% rename from src/dawn/physics/PhysicsManager.hpp rename to src/dawn/physics/2d/Circle.hpp index 343ce2ea..3f534377 100644 --- a/src/dawn/physics/PhysicsManager.hpp +++ b/src/dawn/physics/2d/Circle.hpp @@ -4,14 +4,9 @@ // https://opensource.org/licenses/MIT #pragma once +#include "dawnlibs.hpp" +#include "assert/assert.hpp namespace Dawn { - class DawnGame; - - class PhysicsManager { - public: - DawnGame *game; - - PhysicsManager(DawnGame *game); - }; + } \ No newline at end of file diff --git a/src/dawn/physics/2d/PhysicsGrid.hpp b/src/dawn/physics/2d/PhysicsGrid.hpp new file mode 100644 index 00000000..e69de29b diff --git a/src/dawn/scene/components/physics/2d/Ray2D.cpp b/src/dawn/physics/2d/Ray2D.cpp similarity index 96% rename from src/dawn/scene/components/physics/2d/Ray2D.cpp rename to src/dawn/physics/2d/Ray2D.cpp index 2b64a6a7..b8a990a0 100644 --- a/src/dawn/scene/components/physics/2d/Ray2D.cpp +++ b/src/dawn/physics/2d/Ray2D.cpp @@ -1,27 +1,27 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "Ray2D.hpp" - -using namespace Dawn; - -Ray2D::Ray2D(glm::vec2 pos, glm::vec2 dir) : - position(pos), - direction(dir) -{ -} - -bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) { - glm::vec2 j = this->position - ray.position; - float_t f = -ray.direction.x * direction.y + direction.x * ray.direction.y; - float_t s = (-direction.y * j.x + direction.x * j.y) / f; - float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f; - if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { - *out = position + (t * direction); - return true; - } - - return false; +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "Ray2D.hpp" + +using namespace Dawn; + +Ray2D::Ray2D(glm::vec2 pos, glm::vec2 dir) : + position(pos), + direction(dir) +{ +} + +bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) { + glm::vec2 j = this->position - ray.position; + float_t f = -ray.direction.x * direction.y + direction.x * ray.direction.y; + float_t s = (-direction.y * j.x + direction.x * j.y) / f; + float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f; + if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { + *out = position + (t * direction); + return true; + } + + return false; } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/Ray2D.hpp b/src/dawn/physics/2d/Ray2D.hpp similarity index 96% rename from src/dawn/scene/components/physics/2d/Ray2D.hpp rename to src/dawn/physics/2d/Ray2D.hpp index 063ab13c..fc792e33 100644 --- a/src/dawn/scene/components/physics/2d/Ray2D.hpp +++ b/src/dawn/physics/2d/Ray2D.hpp @@ -1,31 +1,31 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "dawnlibs.hpp" - -namespace Dawn { - struct Ray2D { - const glm::vec2 position; - const glm::vec2 direction; - - /** - * Constructs a new Ray 2D. - * - * @param position Position of this ray in 2D space. - * @param direction Direction from the origin in 2D space of this ray. - */ - Ray2D(glm::vec2 position, glm::vec2 direction); - - /** - * Checks whether one ray is intersecting with another ray. - * - * @param ray The ray to check if this ray is intersecting. - * @param out The point in space where the two rays intersect. - * @return True if they intersect, otherwise false. - */ - bool_t intersects(struct Ray2D ray, glm::vec2 *out); - }; +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawnlibs.hpp" + +namespace Dawn { + struct Ray2D { + const glm::vec2 position; + const glm::vec2 direction; + + /** + * Constructs a new Ray 2D. + * + * @param position Position of this ray in 2D space. + * @param direction Direction from the origin in 2D space of this ray. + */ + Ray2D(glm::vec2 position, glm::vec2 direction); + + /** + * Checks whether one ray is intersecting with another ray. + * + * @param ray The ray to check if this ray is intersecting. + * @param out The point in space where the two rays intersect. + * @return True if they intersect, otherwise false. + */ + bool_t intersects(struct Ray2D ray, glm::vec2 *out); + }; } \ No newline at end of file diff --git a/src/dawn/physics/CMakeLists.txt b/src/dawn/physics/CMakeLists.txt index a4a8d532..be9c0cc3 100644 --- a/src/dawn/physics/CMakeLists.txt +++ b/src/dawn/physics/CMakeLists.txt @@ -6,8 +6,9 @@ # Sources target_sources(${DAWN_TARGET_NAME} PRIVATE - PhysicsManager.cpp + ScenePhysicsManager.cpp ) # Subdirs +add_subdirectory(2d) add_subdirectory(3d) \ No newline at end of file diff --git a/src/dawn/physics/ScenePhysicsManager.cpp b/src/dawn/physics/ScenePhysicsManager.cpp new file mode 100644 index 00000000..26fb15a0 --- /dev/null +++ b/src/dawn/physics/ScenePhysicsManager.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "ScenePhysicsManager.hpp" +#include "scene/Scene.hpp" + +using namespace Dawn; + +ScenePhysicsManager::ScenePhysicsManager() { + +} + +void ScenePhysicsManager::update() { + +} \ No newline at end of file diff --git a/src/dawn/physics/ScenePhysicsManager.hpp b/src/dawn/physics/ScenePhysicsManager.hpp new file mode 100644 index 00000000..e1e0d222 --- /dev/null +++ b/src/dawn/physics/ScenePhysicsManager.hpp @@ -0,0 +1,29 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawnlibs.hpp" +#include "scene/SceneItem.hpp" + +typedef int64_t scenechunk_t; + +#define SCENE_CHUNK_SIZE_2D 512 + +namespace Dawn { + class Scene; + + class ScenePhysicsManager { + protected: + std::map> chunkItems; + std::map> itemChunks; + + public: + ScenePhysicsManager(); + + void update(); + + friend class Scene; + }; +} \ No newline at end of file diff --git a/src/dawn/poker/PokerPlayer.hpp b/src/dawn/poker/PokerPlayer.hpp index b7cb2a75..b29e7c4e 100644 --- a/src/dawn/poker/PokerPlayer.hpp +++ b/src/dawn/poker/PokerPlayer.hpp @@ -6,7 +6,6 @@ #pragma once #include "scene/SceneItemComponent.hpp" #include "Card.hpp" -#include "scene/Scene.hpp" #include "PokerPot.hpp" #include "util/mathutils.hpp" #include "display/animation/Easing.hpp" diff --git a/src/dawn/prefab/Prefab.hpp b/src/dawn/prefab/Prefab.hpp index accd13b8..a2e48377 100644 --- a/src/dawn/prefab/Prefab.hpp +++ b/src/dawn/prefab/Prefab.hpp @@ -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 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 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 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 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); + } + }; } \ No newline at end of file diff --git a/src/dawn/prefab/SceneItemPrefab.hpp b/src/dawn/prefab/SceneItemPrefab.hpp index 80c111ab..3b3b6c04 100644 --- a/src/dawn/prefab/SceneItemPrefab.hpp +++ b/src/dawn/prefab/SceneItemPrefab.hpp @@ -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 SceneItemPrefab : - public SceneItem, - public Prefab - { - 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(); - 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 SceneItemPrefab : + public SceneItem, + public Prefab + { + 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(); + 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; + }; } \ No newline at end of file diff --git a/src/dawn/scene/Scene.cpp b/src/dawn/scene/Scene.cpp index 6c895423..2f680928 100644 --- a/src/dawn/scene/Scene.cpp +++ b/src/dawn/scene/Scene.cpp @@ -4,6 +4,8 @@ // https://opensource.org/licenses/MIT #include "Scene.hpp" +#include "SceneItem.hpp" +#include "SceneItemComponent.hpp" #include "game/DawnGame.hpp" using namespace Dawn; diff --git a/src/dawn/scene/Scene.hpp b/src/dawn/scene/Scene.hpp index a44e5f77..1af075b1 100644 --- a/src/dawn/scene/Scene.hpp +++ b/src/dawn/scene/Scene.hpp @@ -4,13 +4,19 @@ // https://opensource.org/licenses/MIT #pragma once -#include "SceneItem.hpp" #include "event/Event.hpp" #include "asset/Asset.hpp" namespace Dawn { class DawnGame; class RenderPipeline; + class SceneItem; + class SceneItemComponent; + + typedef int32_t sceneitemid_t; + + template + T * _sceneForwardGetComponent(SceneItem *item); class Scene { private: @@ -84,13 +90,13 @@ namespace Dawn { T * findComponent() { auto it = this->itemsNotInitialized.begin(); while(it != this->itemsNotInitialized.end()) { - auto component = it->second->getComponent(); + auto component = _sceneForwardGetComponent(it->second); if(component != nullptr) return component; ++it; } auto it2 = this->items.begin(); while(it2 != this->items.end()) { - auto component = it2->second->getComponent(); + auto component = _sceneForwardGetComponent(it2->second); if(component != nullptr) return component; ++it2; } @@ -110,14 +116,14 @@ namespace Dawn { auto it = this->itemsNotInitialized.begin(); while(it != this->itemsNotInitialized.end()) { - auto component = it->second->getComponent(); + auto component = _sceneForwardGetComponent(it->second); if(component != nullptr) components.push_back(component); ++it; } auto it2 = this->items.begin(); while(it2 != this->items.end()) { - auto component = it2->second->getComponent(); + auto component = _sceneForwardGetComponent(it2->second); if(component != nullptr) components.push_back(component); ++it2; } diff --git a/src/dawn/scene/SceneItem.cpp b/src/dawn/scene/SceneItem.cpp index dfdba3c7..005c7d12 100644 --- a/src/dawn/scene/SceneItem.cpp +++ b/src/dawn/scene/SceneItem.cpp @@ -4,7 +4,7 @@ // https://opensource.org/licenses/MIT #include "SceneItem.hpp" -#include "Scene.hpp" +#include "SceneItemComponent.hpp" using namespace Dawn; diff --git a/src/dawn/scene/SceneItem.hpp b/src/dawn/scene/SceneItem.hpp index 9d911484..91fcb8cc 100644 --- a/src/dawn/scene/SceneItem.hpp +++ b/src/dawn/scene/SceneItem.hpp @@ -4,14 +4,12 @@ // https://opensource.org/licenses/MIT #pragma once -#include "SceneItemComponent.hpp" #include "display/Transform.hpp" #include "event/Event.hpp" +#include "scene/Scene.hpp" namespace Dawn { - typedef int32_t sceneitemid_t; - - class Scene; + class SceneItemComponent; class SceneItem { private: diff --git a/src/dawn/scene/SceneItemComponent.hpp b/src/dawn/scene/SceneItemComponent.hpp index 12f54c96..265b2ce9 100644 --- a/src/dawn/scene/SceneItemComponent.hpp +++ b/src/dawn/scene/SceneItemComponent.hpp @@ -6,10 +6,9 @@ #pragma once #include "dawnlibs.hpp" #include "display/Transform.hpp" +#include "scene/SceneItem.hpp" namespace Dawn { - class SceneItem; - class Scene; class DawnGame; class SceneItemComponent { @@ -70,4 +69,11 @@ namespace Dawn { */ ~SceneItemComponent(); }; + + + + template + T * _sceneForwardGetComponent(SceneItem *item) { + return item->getComponent(); + } } \ No newline at end of file diff --git a/src/dawn/scene/components/display/AnimationController.cpp b/src/dawn/scene/components/display/AnimationController.cpp index 76948266..8b3bbdfc 100644 --- a/src/dawn/scene/components/display/AnimationController.cpp +++ b/src/dawn/scene/components/display/AnimationController.cpp @@ -1,38 +1,37 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "AnimationController.hpp" -#include "scene/Scene.hpp" -#include "game/DawnGame.hpp" - -using namespace Dawn; - -AnimationController::AnimationController(SceneItem *item) : - SceneItemComponent(item) -{ - -} - -void AnimationController::addAnimation(Animation *animation) { - assertNotNull(animation); - this->animations.push_back(animation); -} - -void AnimationController::onSceneUpdate() { - auto it = this->animations.begin(); - while(it != this->animations.end()) { - (*it)->tick(this->getGame()->timeManager.delta); - ++it; - } -} - -void AnimationController::onStart() { - SceneItemComponent::onStart(); - getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate); -} - -void AnimationController::onDispose() { - getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate); +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "AnimationController.hpp" +#include "game/DawnGame.hpp" + +using namespace Dawn; + +AnimationController::AnimationController(SceneItem *item) : + SceneItemComponent(item) +{ + +} + +void AnimationController::addAnimation(Animation *animation) { + assertNotNull(animation); + this->animations.push_back(animation); +} + +void AnimationController::onSceneUpdate() { + auto it = this->animations.begin(); + while(it != this->animations.end()) { + (*it)->tick(this->getGame()->timeManager.delta); + ++it; + } +} + +void AnimationController::onStart() { + SceneItemComponent::onStart(); + getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate); +} + +void AnimationController::onDispose() { + getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate); } \ No newline at end of file diff --git a/src/dawn/scene/components/display/Camera.cpp b/src/dawn/scene/components/display/Camera.cpp index aa8fdf77..84b44e92 100644 --- a/src/dawn/scene/components/display/Camera.cpp +++ b/src/dawn/scene/components/display/Camera.cpp @@ -4,7 +4,6 @@ // https://opensource.org/licenses/MIT #include "Camera.hpp" -#include "scene/Scene.hpp" #include "game/DawnGame.hpp" using namespace Dawn; diff --git a/src/dawn/scene/components/display/Material.cpp b/src/dawn/scene/components/display/Material.cpp index 1be1e70a..1c364aa8 100644 --- a/src/dawn/scene/components/display/Material.cpp +++ b/src/dawn/scene/components/display/Material.cpp @@ -4,7 +4,6 @@ // https://opensource.org/licenses/MIT #include "Material.hpp" -#include "scene/Scene.hpp" #include "game/DawnGame.hpp" using namespace Dawn; diff --git a/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp b/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp index ca0a2371..42c8ce8f 100644 --- a/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp +++ b/src/dawn/scene/components/display/SimpleRenderTargetQuad.cpp @@ -1,81 +1,80 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "SimpleRenderTargetQuad.hpp" -#include "scene/Scene.hpp" - -using namespace Dawn; - -SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) : - SceneItemComponent(i) -{ -} - -void SimpleRenderTargetQuad::onRenderTargetResized( - RenderTarget *target, float_t w, float_t h -) { - assertTrue(target == this->renderTarget); - // Update mesh - QuadMesh::bufferQuadMesh( - &this->meshHost->mesh, - glm::vec2(0, 0), glm::vec2(0, 0), - glm::vec2(w, h), glm::vec2(1, 1), - 0, 0 - ); -} - - -void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) { - assertTrue(rt != this->renderTarget); - - // Remove old event listener - if(this->renderTarget != nullptr) { - this->renderTarget->eventRenderTargetResized.removeListener( - this, &SimpleRenderTargetQuad::onRenderTargetResized - ); - } - - this->renderTarget = rt; - - // Add new event listener. - if(rt != nullptr) { - rt->eventRenderTargetResized.addListener( - this, &SimpleRenderTargetQuad::onRenderTargetResized - ); - } -} - -std::vector SimpleRenderTargetQuad::getDependencies() { - return std::vector{ - (this->meshHost = this->item->getComponent()) - }; -} - -void SimpleRenderTargetQuad::onStart() { - assertNotNull(this->meshHost); - - // Create quad mesh - this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT); - - // Perform first resize. - if(this->renderTarget != nullptr) { - QuadMesh::bufferQuadMesh( - &this->meshHost->mesh, - glm::vec2(0, 0), - glm::vec2(0, 0), - glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()), - glm::vec2(1,1), - 0, 0 - ); - } -} - -void SimpleRenderTargetQuad::onDispose() { - if(this->renderTarget != nullptr) { - this->renderTarget->eventRenderTargetResized.removeListener( - this, &SimpleRenderTargetQuad::onRenderTargetResized - ); - } +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "SimpleRenderTargetQuad.hpp" + +using namespace Dawn; + +SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) : + SceneItemComponent(i) +{ +} + +void SimpleRenderTargetQuad::onRenderTargetResized( + RenderTarget *target, float_t w, float_t h +) { + assertTrue(target == this->renderTarget); + // Update mesh + QuadMesh::bufferQuadMesh( + &this->meshHost->mesh, + glm::vec2(0, 0), glm::vec2(0, 0), + glm::vec2(w, h), glm::vec2(1, 1), + 0, 0 + ); +} + + +void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) { + assertTrue(rt != this->renderTarget); + + // Remove old event listener + if(this->renderTarget != nullptr) { + this->renderTarget->eventRenderTargetResized.removeListener( + this, &SimpleRenderTargetQuad::onRenderTargetResized + ); + } + + this->renderTarget = rt; + + // Add new event listener. + if(rt != nullptr) { + rt->eventRenderTargetResized.addListener( + this, &SimpleRenderTargetQuad::onRenderTargetResized + ); + } +} + +std::vector SimpleRenderTargetQuad::getDependencies() { + return std::vector{ + (this->meshHost = this->item->getComponent()) + }; +} + +void SimpleRenderTargetQuad::onStart() { + assertNotNull(this->meshHost); + + // Create quad mesh + this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT); + + // Perform first resize. + if(this->renderTarget != nullptr) { + QuadMesh::bufferQuadMesh( + &this->meshHost->mesh, + glm::vec2(0, 0), + glm::vec2(0, 0), + glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()), + glm::vec2(1,1), + 0, 0 + ); + } +} + +void SimpleRenderTargetQuad::onDispose() { + if(this->renderTarget != nullptr) { + this->renderTarget->eventRenderTargetResized.removeListener( + this, &SimpleRenderTargetQuad::onRenderTargetResized + ); + } } \ No newline at end of file diff --git a/src/dawn/scene/components/example/ExampleSpin.cpp b/src/dawn/scene/components/example/ExampleSpin.cpp index f287aab3..eeaff8a9 100644 --- a/src/dawn/scene/components/example/ExampleSpin.cpp +++ b/src/dawn/scene/components/example/ExampleSpin.cpp @@ -1,45 +1,44 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "ExampleSpin.hpp" -#include "scene/Scene.hpp" -#include "game/DawnGame.hpp" -#include "scene/components/display/MeshRenderer.hpp" -#include "display/mesh/CubeMesh.hpp" -#include "scene/components/display/material/SimpleTexturedMaterial.hpp" - -using namespace Dawn; - -SceneItem * ExampleSpin::create(Scene *scene) { - auto item = scene->createSceneItem(); - auto mr = item->addComponent(); - mr->mesh = new Mesh(); - mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT); - CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0); - auto mat = item->addComponent(); - item->addComponent(); - - return item; -} - -ExampleSpin::ExampleSpin(SceneItem *item) : - SceneItemComponent(item) -{ - getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate); -} - - -void ExampleSpin::onUnpausedUpdate() { - auto quat = this->transform->getLocalRotation(); - quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0)); - quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0)); - quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1)); - - this->transform->setLocalRotation(quat); -} - -void ExampleSpin::onDispose() { - getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate); +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "ExampleSpin.hpp" +#include "game/DawnGame.hpp" +#include "scene/components/display/MeshRenderer.hpp" +#include "display/mesh/CubeMesh.hpp" +#include "scene/components/display/material/SimpleTexturedMaterial.hpp" + +using namespace Dawn; + +SceneItem * ExampleSpin::create(Scene *scene) { + auto item = scene->createSceneItem(); + auto mr = item->addComponent(); + mr->mesh = new Mesh(); + mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT); + CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0); + auto mat = item->addComponent(); + item->addComponent(); + + return item; +} + +ExampleSpin::ExampleSpin(SceneItem *item) : + SceneItemComponent(item) +{ + getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate); +} + + +void ExampleSpin::onUnpausedUpdate() { + auto quat = this->transform->getLocalRotation(); + quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0)); + quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0)); + quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1)); + + this->transform->setLocalRotation(quat); +} + +void ExampleSpin::onDispose() { + getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate); } \ No newline at end of file diff --git a/src/dawn/physics/PhysicsManager.cpp b/src/dawn/scene/components/physics/2d/BoxCollider.cpp similarity index 55% rename from src/dawn/physics/PhysicsManager.cpp rename to src/dawn/scene/components/physics/2d/BoxCollider.cpp index 9d5f5cdb..43003021 100644 --- a/src/dawn/physics/PhysicsManager.cpp +++ b/src/dawn/scene/components/physics/2d/BoxCollider.cpp @@ -3,11 +3,10 @@ // This software is released under the MIT License. // https://opensource.org/licenses/MIT -#include "PhysicsManager.hpp" -#include "game/DawnGame.hpp" +#include "BoxCollider.hpp" using namespace Dawn; -PhysicsManager::PhysicsManager(DawnGame *game) { - this->game = game; +BoxCollider::BoxCollider(SceneItem *i) : Collider2D(i) { + } \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/BoxCollider.hpp b/src/dawn/scene/components/physics/2d/BoxCollider.hpp new file mode 100644 index 00000000..fbd004c3 --- /dev/null +++ b/src/dawn/scene/components/physics/2d/BoxCollider.hpp @@ -0,0 +1,18 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "Collider2D.hpp" +#include "physics/2d/Box.hpp" + +namespace Dawn { + class BoxCollider : public Collider2D { + public: + glm::vec2 min = glm::vec2(-0.5f, -0.5f); + glm::vec2 max = glm::vec2( 0.5f, 0.5f); + + BoxCollider(SceneItem *item); + }; +} \ No newline at end of file diff --git a/src/dawn/scene/components/physics/2d/CMakeLists.txt b/src/dawn/scene/components/physics/2d/CMakeLists.txt index 2159a106..2b9c5131 100644 --- a/src/dawn/scene/components/physics/2d/CMakeLists.txt +++ b/src/dawn/scene/components/physics/2d/CMakeLists.txt @@ -1,11 +1,11 @@ -# Copyright (c) 2023 Dominic Masters -# -# This software is released under the MIT License. -# https://opensource.org/licenses/MIT - -# Sources -target_sources(${DAWN_TARGET_NAME} - PRIVATE - Collider2D.cpp - Ray2D.cpp +# Copyright (c) 2023 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + BoxCollider.cpp + Collider2D.cpp ) \ No newline at end of file diff --git a/src/dawn/scene/components/physics/3d/CMakeLists.txt b/src/dawn/scene/components/physics/3d/CMakeLists.txt index b77295db..4fefb26c 100644 --- a/src/dawn/scene/components/physics/3d/CMakeLists.txt +++ b/src/dawn/scene/components/physics/3d/CMakeLists.txt @@ -4,10 +4,10 @@ # https://opensource.org/licenses/MIT # Sources -target_sources(${DAWN_TARGET_NAME} - PRIVATE - RayTester3D.cpp -) +# target_sources(${DAWN_TARGET_NAME} +# PRIVATE +# RayTester3D.cpp +# ) # Subdirs add_subdirectory(collider) \ No newline at end of file diff --git a/src/dawn/scene/components/physics/3d/RayTester3D.cpp b/src/dawn/scene/components/physics/3d/RayTester3D.cpp deleted file mode 100644 index 5dd08c09..00000000 --- a/src/dawn/scene/components/physics/3d/RayTester3D.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "RayTester3D.hpp" -#include "scene/Scene.hpp" - -using namespace Dawn; - -RayTester3D::RayTester3D(SceneItem *item) : SceneItemComponent(item) { - -} - -void RayTester3D::onStart() { - this->getScene()->eventSceneUpdate.addListener(this, &RayTester3D::onUpdate); -} - -void RayTester3D::onUpdate() { - prefab->transform.setLocalPosition(glm::vec3(0, 0, 0)); - - triangle.v0 = glm::vec3(-0.5f, -0.5f, 0); - triangle.v1 = glm::vec3(0.5f, -0.5f, 0); - triangle.v2 = glm::vec3(0, 0.5f, 0); - - auto mouse = this->getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y); - mouse *= 2.0f; - mouse -= glm::vec2(1, 1); - - glm::vec3 pos = glm::vec3(mouse.x * camera->orthoRight, mouse.y * camera->orthoBottom, 0.0f); - ray.direction = glm::vec3(0, 0, -15); - ray.origin = pos; - - // prefab->transform.setLocalPosition(pos); - // ray.origin = glm::vec3(0, 0, 5); - - bool_t x = raytestTriangle(ray, triangle, &hit, &normal, &distance); - - if(x) { - prefab->material->color = COLOR_RED; - } else { - prefab->material->color = COLOR_WHITE; - } -} \ No newline at end of file diff --git a/src/dawn/scene/components/physics/3d/RayTester3D.hpp b/src/dawn/scene/components/physics/3d/RayTester3D.hpp deleted file mode 100644 index 099043f1..00000000 --- a/src/dawn/scene/components/physics/3d/RayTester3D.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "scene/SceneItemComponent.hpp" -#include "prefabs/SimpleSpinningCubePrefab.hpp" -#include "physics/3d/Ray3D.hpp" -#include "scene/components/display/Camera.hpp" - -namespace Dawn { - class RayTester3D : public SceneItemComponent { - public: - SimpleSpinningCubePrefab *prefab; - Camera *camera; - struct PhysicsTriangle triangle; - struct Ray3D ray; - glm::vec3 hit; - glm::vec3 normal; - float_t distance; - - RayTester3D(SceneItem *item); - void onStart() override; - void onUpdate(); - }; -} \ No newline at end of file diff --git a/src/dawn/scene/components/scene/SubSceneController.hpp b/src/dawn/scene/components/scene/SubSceneController.hpp index 1b7d6801..30ae85ac 100644 --- a/src/dawn/scene/components/scene/SubSceneController.hpp +++ b/src/dawn/scene/components/scene/SubSceneController.hpp @@ -1,28 +1,28 @@ -// Copyright (c) 2023 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "scene/Scene.hpp" - -namespace Dawn { - class SubSceneController : public SceneItemComponent { - protected: - Scene *subScene = nullptr; - - void onSceneUpdate(); - void onSceneUnpausedUpdate(); - - public: - bool_t onlyUpdateUnpaused = false; - - SubSceneController(SceneItem *item); - - Scene * getSubScene(); - void setSubScene(Scene *scene); - - void onStart() override; - void onDispose() override; - }; +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "scene/SceneItemComponent.hpp" + +namespace Dawn { + class SubSceneController : public SceneItemComponent { + protected: + Scene *subScene = nullptr; + + void onSceneUpdate(); + void onSceneUnpausedUpdate(); + + public: + bool_t onlyUpdateUnpaused = false; + + SubSceneController(SceneItem *item); + + Scene * getSubScene(); + void setSubScene(Scene *scene); + + void onStart() override; + void onDispose() override; + }; } \ No newline at end of file diff --git a/src/dawn/scene/components/ui/UICanvas.cpp b/src/dawn/scene/components/ui/UICanvas.cpp index 59ba8c41..dd53671f 100644 --- a/src/dawn/scene/components/ui/UICanvas.cpp +++ b/src/dawn/scene/components/ui/UICanvas.cpp @@ -4,7 +4,6 @@ // https://opensource.org/licenses/MIT #include "UICanvas.hpp" -#include "scene/Scene.hpp" #include "ui/UIComponent.hpp" #include "game/DawnGame.hpp" #include "ui/UIMenu.hpp" diff --git a/src/dawn/ui/UIComponent.hpp b/src/dawn/ui/UIComponent.hpp index d87966c8..c582f7ff 100644 --- a/src/dawn/ui/UIComponent.hpp +++ b/src/dawn/ui/UIComponent.hpp @@ -5,7 +5,6 @@ #pragma once #include "scene/components/ui/UICanvas.hpp" -#include "scene/Scene.hpp" #include "display/Color.hpp" #include "util/array.hpp" #include "util/mathutils.hpp" diff --git a/src/dawntictactoe/components/CMakeLists.txt b/src/dawntictactoe/components/CMakeLists.txt index cc28f296..58264fcd 100644 --- a/src/dawntictactoe/components/CMakeLists.txt +++ b/src/dawntictactoe/components/CMakeLists.txt @@ -7,4 +7,5 @@ target_sources(${DAWN_TARGET_NAME} PRIVATE TicTacToeTile.cpp + TicTacToeGame.cpp ) \ No newline at end of file diff --git a/src/dawntictactoe/components/TicTacToeGame.cpp b/src/dawntictactoe/components/TicTacToeGame.cpp new file mode 100644 index 00000000..859734cd --- /dev/null +++ b/src/dawntictactoe/components/TicTacToeGame.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "TicTacToeGame.hpp" +#include "game/DawnGame.hpp" + +using namespace Dawn; + +TicTacToeGame::TicTacToeGame(SceneItem *item) : SceneItemComponent(item) {} + +void TicTacToeGame::onStart() { + std::cout << "Test" << std::endl; + this->tiles = getScene()->findComponents(); + + getScene()->eventSceneUpdate.addListener(this, &TicTacToeGame::onSceneUpdate); +} + +void TicTacToeGame::onSceneUpdate() { + // Get mouse in screen space. + auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y); + mouse *= 2.0f; + mouse -= glm::vec2(1, 1); + + +} \ No newline at end of file diff --git a/src/dawntictactoe/components/TicTacToeGame.hpp b/src/dawntictactoe/components/TicTacToeGame.hpp new file mode 100644 index 00000000..9d3daf5a --- /dev/null +++ b/src/dawntictactoe/components/TicTacToeGame.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "scene/SceneItemComponent.hpp" +#include "TicTacToeTile.hpp" + +namespace Dawn { + class TicTacToeGame : public SceneItemComponent { + public: + std::vector tiles; + + TicTacToeGame(SceneItem *item); + + void onStart() override; + + void onSceneUpdate(); + }; +} \ No newline at end of file diff --git a/src/dawntictactoe/game/DawnGame.cpp b/src/dawntictactoe/game/DawnGame.cpp index b76e816e..666434cb 100644 --- a/src/dawntictactoe/game/DawnGame.cpp +++ b/src/dawntictactoe/game/DawnGame.cpp @@ -13,7 +13,6 @@ DawnGame::DawnGame(DawnHost *host) : renderManager(this), inputManager(this), localeManager(this), - physicsManager(this), saveManager(this) { } diff --git a/src/dawntictactoe/game/DawnGame.hpp b/src/dawntictactoe/game/DawnGame.hpp index e83df40f..991f6d3e 100644 --- a/src/dawntictactoe/game/DawnGame.hpp +++ b/src/dawntictactoe/game/DawnGame.hpp @@ -20,7 +20,6 @@ namespace Dawn { TimeManager timeManager; LocaleManager localeManager; DawnGameSaveManager saveManager; - PhysicsManager physicsManager; DawnGame(DawnHost *host); int32_t init() override; diff --git a/src/dawntictactoe/prefabs/TicTacToeTilePrefab.hpp b/src/dawntictactoe/prefabs/TicTacToeTilePrefab.hpp index e73e3927..633f6f4b 100644 --- a/src/dawntictactoe/prefabs/TicTacToeTilePrefab.hpp +++ b/src/dawntictactoe/prefabs/TicTacToeTilePrefab.hpp @@ -9,6 +9,7 @@ #include "scene/components/display/MeshHost.hpp" #include "scene/components/display/MeshRenderer.hpp" #include "scene/components/display/material/SimpleTexturedMaterial.hpp" +#include "scene/components/physics/2d/BoxCollider.hpp" #include "components/TicTacToeTile.hpp" namespace Dawn { @@ -27,6 +28,7 @@ namespace Dawn { MeshRenderer *meshRenderer; SimpleTexturedMaterial *material; TicTacToeTile *ticTacToe; + BoxCollider *boxCollider; TicTacToeTilePrefab(Scene *s, sceneitemid_t i) : SceneItemPrefab(s,i) @@ -48,7 +50,11 @@ namespace Dawn { sprite = this->addComponent(); sprite->setTileset(&tileset->tileset); sprite->setSize(glm::vec2(1, 1)); - sprite->setTile(0x00); + sprite->setTile(0x01); + + boxCollider = this->addComponent(); + boxCollider->min = glm::vec2(); + boxCollider->max = glm::vec2(1, 1); ticTacToe = this->addComponent(); } diff --git a/src/dawntictactoe/scenes/TicTacToeScene.hpp b/src/dawntictactoe/scenes/TicTacToeScene.hpp index 4cae598f..09e6c7d9 100644 --- a/src/dawntictactoe/scenes/TicTacToeScene.hpp +++ b/src/dawntictactoe/scenes/TicTacToeScene.hpp @@ -8,14 +8,12 @@ #include "prefabs/SimpleSpinningCubePrefab.hpp" #include "prefabs/TicTacToeTilePrefab.hpp" #include "display/mesh/TriangleMesh.hpp" - -#include "scene/components/physics/3d/RayTester3D.hpp" +#include "components/TicTacToeGame.hpp" namespace Dawn { class TicTacToeScene : public Scene { protected: Camera *camera; - TicTacToeTilePrefab* tiles[9]; void stage() override { camera = Camera::create(this); @@ -30,22 +28,19 @@ namespace Dawn { camera->orthoLeft = -s * ratio; camera->orthoRight = s * ratio; - auto cube = SimpleSpinningCubePrefab::create(this); - TriangleMesh::createTriangleMesh(&cube->meshHost->mesh); + // auto cube = SimpleSpinningCubePrefab::create(this); + // TriangleMesh::createTriangleMesh(&cube->meshHost->mesh); // SphereMesh::createSphere(&cube->meshHost->mesh, 1.0f, 16, 16); - auto tester = cube->addComponent(); - tester->prefab = cube; - tester->camera = camera; + auto gameItem = this->createSceneItem(); + auto game = gameItem->addComponent(); int32_t i = 0; for(int32_t x = -1; x <= 1; x++) { for(int32_t y = -1; y <= 1; y++) { - continue; auto tile = TicTacToeTilePrefab::create(this); tile->transform.setLocalPosition(glm::vec3(x * 1.25f, y * 1.25f, 0)); - tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT); - tiles[i++] = tile; + // tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT); } } }