change window draw function to IDrawable

This commit is contained in:
Clément Le Bihan
2021-05-26 16:38:27 +02:00
parent c12ecf6d8b
commit b2659c3272
7 changed files with 14 additions and 21 deletions

View File

@@ -10,6 +10,7 @@
#include <raylib.h> #include <raylib.h>
#include "Vector/Vector2.hpp" #include "Vector/Vector2.hpp"
#include "Image.hpp"
#include "Drawables/IDrawable.hpp" #include "Drawables/IDrawable.hpp"
#include "Color.hpp" #include "Color.hpp"

View File

@@ -8,20 +8,18 @@
#ifndef IDRAWABLE_HPP_ #ifndef IDRAWABLE_HPP_
#define IDRAWABLE_HPP_ #define IDRAWABLE_HPP_
#include "Drawables/Image.hpp"
#include "Window.hpp" #include "Window.hpp"
namespace RAY namespace RAY
{ {
class Window; class Window;
class Image;
namespace Drawables { namespace Drawables {
//! @brief Interface for any drawable //! @brief Interface for any drawable
class IDrawable { class IDrawable {
public: public:
virtual ~IDrawable() = default; virtual ~IDrawable() = default;
virtual void drawOn(RAY::Window &) = 0; virtual void drawOn(Window &) = 0;
protected: protected:
private: private:
}; };

View File

@@ -146,12 +146,7 @@ void RAY::Window::setTitle(const std::string &title)
this->_title = title; this->_title = title;
} }
void RAY::Window::draw(RAY::Drawables::ADrawable2D &drawable) void RAY::Window::draw(RAY::Drawables::IDrawable &drawable)
{
drawable.drawOn(*this);
}
void RAY::Window::draw(RAY::Drawables::ADrawable3D &drawable)
{ {
drawable.drawOn(*this); drawable.drawOn(*this);
} }

View File

@@ -10,6 +10,7 @@
#include <raylib.h> #include <raylib.h>
#include <string> #include <string>
#include "Drawables/Image.hpp"
#include "Vector/Vector2.hpp" #include "Vector/Vector2.hpp"
#include "Vector/Vector3.hpp" #include "Vector/Vector3.hpp"
#include "Controllers/Keyboard.hpp" #include "Controllers/Keyboard.hpp"
@@ -18,11 +19,13 @@
#include "Color.hpp" #include "Color.hpp"
#include "Drawables/Texture.hpp" #include "Drawables/Texture.hpp"
#include "Model/Model.hpp" #include "Model/Model.hpp"
#include "Drawables/IDrawable.hpp"
namespace RAY { namespace RAY {
class Model; class Model;
//! @brief Window manager //! @brief Window manager
namespace Drawables { namespace Drawables {
class IDrawable;
class ADrawable3D; class ADrawable3D;
} }
class Window { class Window {
@@ -66,7 +69,7 @@ namespace RAY {
bool cursorIsVisible(void) const; bool cursorIsVisible(void) const;
//! @brief set the window icon //! @brief set the window icon
void setIcon(Image &img); void setIcon(RAY::Image &img);
//! @brief Get the cursor position //! @brief Get the cursor position
Vector2 getCursorPosition() const; Vector2 getCursorPosition() const;
@@ -114,11 +117,7 @@ namespace RAY {
//! @brief draw drawable //! @brief draw drawable
//! @param drawable The drawable to render on screen //! @param drawable The drawable to render on screen
void draw(RAY::Drawables::ADrawable2D &drawable); void draw(RAY::Drawables::IDrawable &drawable);
//! @brief draw drawable
//! @param drawable The drawable to render on screen
void draw(RAY::Drawables::ADrawable3D &drawable);
//! @brief draw texture at position //! @brief draw texture at position
//! @param texture The object to render //! @param texture The object to render

View File

@@ -12,7 +12,7 @@ namespace WAL
void Wal::_update(std::chrono::nanoseconds dtime) void Wal::_update(std::chrono::nanoseconds dtime)
{ {
auto &entities = this->_scene.getEntities(); auto &entities = this->scene.getEntities();
for (auto &system : this->_systems) { for (auto &system : this->_systems) {
for (auto &entity : entities) { for (auto &entity : entities) {
@@ -26,7 +26,7 @@ namespace WAL
void Wal::_fixedUpdate() void Wal::_fixedUpdate()
{ {
auto &entities = this->_scene.getEntities(); auto &entities = this->scene.getEntities();
for (auto &system : this->_systems) { for (auto &system : this->_systems) {
for (auto &entity : entities) { for (auto &entity : entities) {

View File

@@ -20,9 +20,7 @@ namespace WAL
//! @brief The main WAL class, it is used to setup and run the ECS. //! @brief The main WAL class, it is used to setup and run the ECS.
class Wal class Wal
{ {
public: private:
//! @brief The scene manager that allow multiple scene to work together.
Scene _scene;
//! @brief The list of registered systems //! @brief The list of registered systems
std::vector<std::unique_ptr<System>> _systems = {}; std::vector<std::unique_ptr<System>> _systems = {};
//! @brief True if the engine should close after the end of the current tick. //! @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. //! @return True if all dependencies are met, false otherwise.
static bool _hasDependencies(const Entity &entity, const System &system); static bool _hasDependencies(const Entity &entity, const System &system);
public: public:
//! @brief The scene manager that allow multiple scene to work together.
Scene scene;
//! @brief The time between each fixed update. //! @brief The time between each fixed update.
static std::chrono::nanoseconds timestep; static std::chrono::nanoseconds timestep;

View File

@@ -75,7 +75,7 @@ int demo()
entityPlayer.addComponent(circleComponent); entityPlayer.addComponent(circleComponent);
entityPlayer.addComponent(cubeComponent); entityPlayer.addComponent(cubeComponent);
entityPlayer.addComponent(posComponent); entityPlayer.addComponent(posComponent);
wal._scene.addEntity(entityPlayer); wal.scene.addEntity(entityPlayer);
camera.setMode(CAMERA_FREE); // Set free camera mode camera.setMode(CAMERA_FREE); // Set free camera mode