From b2659c32721ef08b6ebc4e28c7670a19b59bf21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 16:38:27 +0200 Subject: [PATCH] change window draw function to IDrawable --- lib/Ray/sources/Drawables/ADrawable2D.hpp | 1 + lib/Ray/sources/Drawables/IDrawable.hpp | 4 +--- lib/Ray/sources/Window.cpp | 7 +------ lib/Ray/sources/Window.hpp | 11 +++++------ lib/wal/sources/Wal.cpp | 4 ++-- lib/wal/sources/Wal.hpp | 6 +++--- sources/main.cpp | 2 +- 7 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/Ray/sources/Drawables/ADrawable2D.hpp b/lib/Ray/sources/Drawables/ADrawable2D.hpp index bfdba5a3..46a9407b 100644 --- a/lib/Ray/sources/Drawables/ADrawable2D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable2D.hpp @@ -10,6 +10,7 @@ #include #include "Vector/Vector2.hpp" +#include "Image.hpp" #include "Drawables/IDrawable.hpp" #include "Color.hpp" diff --git a/lib/Ray/sources/Drawables/IDrawable.hpp b/lib/Ray/sources/Drawables/IDrawable.hpp index 97c0a110..377adee6 100644 --- a/lib/Ray/sources/Drawables/IDrawable.hpp +++ b/lib/Ray/sources/Drawables/IDrawable.hpp @@ -8,20 +8,18 @@ #ifndef IDRAWABLE_HPP_ #define IDRAWABLE_HPP_ -#include "Drawables/Image.hpp" #include "Window.hpp" namespace RAY { class Window; - class Image; namespace Drawables { //! @brief Interface for any drawable class IDrawable { public: virtual ~IDrawable() = default; - virtual void drawOn(RAY::Window &) = 0; + virtual void drawOn(Window &) = 0; protected: private: }; diff --git a/lib/Ray/sources/Window.cpp b/lib/Ray/sources/Window.cpp index 2f9d2dd6..755bfb61 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -146,12 +146,7 @@ void RAY::Window::setTitle(const std::string &title) this->_title = title; } -void RAY::Window::draw(RAY::Drawables::ADrawable2D &drawable) -{ - drawable.drawOn(*this); -} - -void RAY::Window::draw(RAY::Drawables::ADrawable3D &drawable) +void RAY::Window::draw(RAY::Drawables::IDrawable &drawable) { drawable.drawOn(*this); } diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index d9e86053..bc763354 100644 --- a/lib/Ray/sources/Window.hpp +++ b/lib/Ray/sources/Window.hpp @@ -10,6 +10,7 @@ #include #include +#include "Drawables/Image.hpp" #include "Vector/Vector2.hpp" #include "Vector/Vector3.hpp" #include "Controllers/Keyboard.hpp" @@ -18,11 +19,13 @@ #include "Color.hpp" #include "Drawables/Texture.hpp" #include "Model/Model.hpp" +#include "Drawables/IDrawable.hpp" namespace RAY { class Model; //! @brief Window manager namespace Drawables { + class IDrawable; class ADrawable3D; } class Window { @@ -66,7 +69,7 @@ namespace RAY { bool cursorIsVisible(void) const; //! @brief set the window icon - void setIcon(Image &img); + void setIcon(RAY::Image &img); //! @brief Get the cursor position Vector2 getCursorPosition() const; @@ -114,11 +117,7 @@ namespace RAY { //! @brief draw drawable //! @param drawable The drawable to render on screen - void draw(RAY::Drawables::ADrawable2D &drawable); - - //! @brief draw drawable - //! @param drawable The drawable to render on screen - void draw(RAY::Drawables::ADrawable3D &drawable); + void draw(RAY::Drawables::IDrawable &drawable); //! @brief draw texture at position //! @param texture The object to render diff --git a/lib/wal/sources/Wal.cpp b/lib/wal/sources/Wal.cpp index 2f90a19f..5bab4a43 100644 --- a/lib/wal/sources/Wal.cpp +++ b/lib/wal/sources/Wal.cpp @@ -12,7 +12,7 @@ namespace WAL void Wal::_update(std::chrono::nanoseconds dtime) { - auto &entities = this->_scene.getEntities(); + auto &entities = this->scene.getEntities(); for (auto &system : this->_systems) { for (auto &entity : entities) { @@ -26,7 +26,7 @@ namespace WAL void Wal::_fixedUpdate() { - auto &entities = this->_scene.getEntities(); + auto &entities = this->scene.getEntities(); for (auto &system : this->_systems) { for (auto &entity : entities) { diff --git a/lib/wal/sources/Wal.hpp b/lib/wal/sources/Wal.hpp index 036c1787..47c5027f 100644 --- a/lib/wal/sources/Wal.hpp +++ b/lib/wal/sources/Wal.hpp @@ -20,9 +20,7 @@ namespace WAL //! @brief The main WAL class, it is used to setup and run the ECS. class Wal { - public: - //! @brief The scene manager that allow multiple scene to work together. - Scene _scene; + private: //! @brief The list of registered systems std::vector> _systems = {}; //! @brief True if the engine should close after the end of the current tick. @@ -40,6 +38,8 @@ namespace WAL //! @return True if all dependencies are met, false otherwise. static bool _hasDependencies(const Entity &entity, const System &system); public: + //! @brief The scene manager that allow multiple scene to work together. + Scene scene; //! @brief The time between each fixed update. static std::chrono::nanoseconds timestep; diff --git a/sources/main.cpp b/sources/main.cpp index 59318fc1..7e3c6416 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -75,7 +75,7 @@ int demo() entityPlayer.addComponent(circleComponent); entityPlayer.addComponent(cubeComponent); entityPlayer.addComponent(posComponent); - wal._scene.addEntity(entityPlayer); + wal.scene.addEntity(entityPlayer); camera.setMode(CAMERA_FREE); // Set free camera mode