diff --git a/CMakeLists.txt b/CMakeLists.txt index 4efd04dc..45d0247d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,11 +21,17 @@ set(SOURCES sources/System/Movable/MovableSystem.hpp sources/System/Movable/MovableSystem.cpp sources/Models/Vector3.hpp - sources/Component/Drawable/Drawable3DComponent.hpp - sources/Component/Drawable/Drawable2DComponent.hpp + sources/Models/Vector2.hpp + sources/Component/Renderer/Drawable3DComponent.hpp + sources/Component/Renderer/Drawable2DComponent.hpp sources/System/Renderer/Renderer3DSystem.hpp sources/System/Renderer/Renderer2DSystem.hpp sources/System/Renderer/RenderScreenSystem.hpp + sources/System/Renderer/RenderScreenSystem.cpp + sources/Component/Renderer/CameraComponent.cpp + sources/Component/Renderer/CameraComponent.hpp + sources/System/Renderer/Render2DScreenSystem.cpp + sources/System/Renderer/Render2DScreenSystem.hpp ) add_executable(bomberman diff --git a/lib/Ray/sources/Camera/Camera2D.hpp b/lib/Ray/sources/Camera/Camera2D.hpp index 6248ecae..aa4a20de 100644 --- a/lib/Ray/sources/Camera/Camera2D.hpp +++ b/lib/Ray/sources/Camera/Camera2D.hpp @@ -19,7 +19,7 @@ namespace RAY::Camera { public: //! @brief 2D Camera constructor //! @param offset Camera offset (displacement from target) - //! @param target Camera target (rotation and zoom origin + //! @param target Camera target (rotation and zoom origin) //! @param rotation Camera rotation in degrees //! @param zoom Camera zoom (scaling), should be 1.0f by default Camera2D(const Vector2 &offset, const Vector2 &target, float rotation, float zoom = 1); diff --git a/lib/Ray/sources/Drawables/2D/Rectangle.hpp b/lib/Ray/sources/Drawables/2D/Rectangle.hpp index 5371e77c..18f25d4f 100644 --- a/lib/Ray/sources/Drawables/2D/Rectangle.hpp +++ b/lib/Ray/sources/Drawables/2D/Rectangle.hpp @@ -12,7 +12,7 @@ #include "Drawables/ADrawable2D.hpp" namespace RAY::Drawables::Drawables2D { - //! @brief Rectangle in a two-dimensionnal space + //! @brief Rectangle in a two-dimensional space class Rectangle: public ADrawable2D { public: diff --git a/lib/Ray/sources/Window.cpp b/lib/Ray/sources/Window.cpp index 755bfb61..d64caa2d 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -11,11 +11,22 @@ #include "Drawables/ADrawable2D.hpp" #include "Drawables/ADrawable3D.hpp" -RAY::Window &RAY::Window::getInstance(int width, int height, const std::string &title, unsigned flags, bool openNow) -{ - static RAY::Window window(width, height, title, flags, openNow); +std::optional RAY::Window::_instance = std::nullopt; - return window; +RAY::Window &RAY::Window::getInstance() +{ + if (!RAY::Window::_instance.has_value()) + throw std::runtime_error("No window has been constructed."); + return RAY::Window::_instance.value(); +} + +RAY::Window &RAY::Window::getInstance(int width, int height, const std::string &title, unsigned flags, bool openNow) noexcept +{ + if (!RAY::Window::_instance.has_value()){ + RAY::Window window(width, height, title, flags, openNow); + RAY::Window::_instance.emplace(std::move(window)); + } + return RAY::Window::_instance.value(); } RAY::Window::Window(int width, int height, std::string title, unsigned flags, bool openNow): @@ -23,7 +34,7 @@ RAY::Window::Window(int width, int height, std::string title, unsigned flags, bo _title(std::move(title)), _isOpen(openNow), _flags(flags), - _drawingState(IDLE), _displayState(NONE) + _displayState(NONE) { if (openNow) this->open(); @@ -95,20 +106,10 @@ void RAY::Window::clear(const RAY::Color &color) ClearBackground(color); } -void RAY::Window::setDrawingState(enum RAY::Window::drawingState state) +void RAY::Window::draw() { - if (state == this->_drawingState) - return; - switch (state) - { - case DRAWING: - BeginDrawing(); - break; - case IDLE: - EndDrawing(); - break; - } - this->_drawingState = state; + EndDrawing(); + BeginDrawing(); } void RAY::Window::useCamera(RAY::Camera::Camera2D &camera) @@ -169,4 +170,4 @@ void RAY::Window::draw(const RAY::Model &model, const RAY::Vector3 &position, co void RAY::Window::setIcon(RAY::Image &img) { SetWindowIcon(img); -} \ No newline at end of file +} diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index bc763354..6e9f2279 100644 --- a/lib/Ray/sources/Window.hpp +++ b/lib/Ray/sources/Window.hpp @@ -10,6 +10,7 @@ #include #include +#include #include "Drawables/Image.hpp" #include "Vector/Vector2.hpp" #include "Vector/Vector3.hpp" @@ -29,10 +30,19 @@ namespace RAY { class ADrawable3D; } class Window { + private: + //! @brief The window's instance as an optional. + static std::optional _instance; public: + //! @brief Get The window's instance, if the window has not been already constructed a runtime exception is thrown. + static Window &getInstance(); + //! @return A widow insta,ce. Only one window can be open at a time - static Window &getInstance(int width, int height, const std::string &title, unsigned flags = 0, bool openNow = true); + static Window &getInstance(int width, int height, const std::string &title, unsigned flags = 0, bool openNow = true) noexcept; + //! @brief A window is movable. + Window(Window &&) = default; + //! @brief A default copy constructor Window(const Window &window) = delete; @@ -81,14 +91,6 @@ namespace RAY { //! @param color The color to clear the screen (default: black) void clear(const Color &color = BLACK); - //! @brief Different states of the draw-ability of the window - enum drawingState { - //! @brief Must be called after last draw of iteration - IDLE, - //! @brief Must be called before first draw of iteration - DRAWING, - }; - //! @brief Different states of the view of the window enum displayState { //! @brief When a custom 2D camera is used @@ -99,8 +101,8 @@ namespace RAY { NONE, }; - //! @brief Set drawing state of the window - void setDrawingState(enum drawingState); + //! @brief Draw the content of the buffer on the screen. + void draw(); //! @brief Initialize 2D mode with custom camera (2D) void useCamera(Camera::Camera2D &camera); @@ -136,7 +138,7 @@ namespace RAY { private: //! @brief Creates window, and opens it if openNow is set to true Window(int width, int height, std::string title, unsigned flags = 0, bool openNow = true); - + //! @brief Dimension of window RAY::Vector2 _dimensions; @@ -149,9 +151,6 @@ namespace RAY { //! @brief flags for the window (ex: FLAG_WINDOW_RESIZABLE) unsigned int _flags; - //! @brief Current window draw-state - enum drawingState _drawingState; - //! @brief Current window draw-state enum displayState _displayState; }; diff --git a/lib/wal/sources/Entity/Entity.hpp b/lib/wal/sources/Entity/Entity.hpp index f0c3d641..061b42e4 100644 --- a/lib/wal/sources/Entity/Entity.hpp +++ b/lib/wal/sources/Entity/Entity.hpp @@ -75,11 +75,11 @@ namespace WAL //! @throw DuplicateError is thrown if a component with the same type already exist. //! @return This entity is returned template - Entity &addComponent(Types ...params) + Entity &addComponent(Types &&...params) { if (this->hasComponent()) throw DuplicateError("A component of the type \"" + std::string(typeid(T).name()) + "\" already exists."); - this->_components.push_back(std::make_unique(*this, params...)); + this->_components.push_back(std::make_unique(*this, std::forward(params)...)); return *this; } diff --git a/lib/wal/sources/Scene/Scene.hpp b/lib/wal/sources/Scene/Scene.hpp index 3491170e..c36a6a0c 100644 --- a/lib/wal/sources/Scene/Scene.hpp +++ b/lib/wal/sources/Scene/Scene.hpp @@ -24,10 +24,9 @@ namespace WAL //! @brief Add a new entity to the scene, you can use this method with the same arguments as the entity's constructor. //! @return The current scene is returned to allow you to chain call. template - Scene &addEntity(Params ...params) + Entity &addEntity(Params &&...params) { - this->_entities.emplace_back(params...); - return *this; + return this->_entities.emplace_back(std::forward(params)...); } //! @brief A default constructor @@ -38,5 +37,6 @@ namespace WAL ~Scene() = default; //! @brief A scene is assignable Scene &operator=(const Scene &) = default; + Scene(Scene &&) = default; }; } // namespace WAL \ No newline at end of file diff --git a/lib/wal/sources/Wal.hpp b/lib/wal/sources/Wal.hpp index 47c5027f..ec2d1786 100644 --- a/lib/wal/sources/Wal.hpp +++ b/lib/wal/sources/Wal.hpp @@ -38,7 +38,7 @@ 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. + //! @brief The scene that contains entities. Scene scene; //! @brief The time between each fixed update. static std::chrono::nanoseconds timestep; @@ -46,7 +46,7 @@ namespace WAL //! @brief Create a new system in place. //! @return The wal instance used to call this function is returned. This allow method chaining. template - Wal &addSystem(Types ...params) + Wal &addSystem(Types &&...params) { const std::type_info &type = typeid(T); auto existing = std::find_if(this->_systems.begin(), this->_systems.end(), [&type] (auto &sys) { @@ -54,7 +54,7 @@ namespace WAL }); if (existing != this->_systems.end()) throw DuplicateError("A system of the type \"" + std::string(type.name()) + "\" already exists."); - this->_systems.push_back(std::make_unique(params...)); + this->_systems.push_back(std::make_unique(std::forward(params)...)); return *this; } diff --git a/sources/Component/Renderer/CameraComponent.cpp b/sources/Component/Renderer/CameraComponent.cpp new file mode 100644 index 00000000..3f6c1239 --- /dev/null +++ b/sources/Component/Renderer/CameraComponent.cpp @@ -0,0 +1,17 @@ +// +// Created by Zoe Roux on 5/27/21. +// + +#include "CameraComponent.hpp" + +namespace BBM +{ + CameraComponent::CameraComponent(WAL::Entity &entity) + : Component(entity) + {} + + WAL::Component *BBM::CameraComponent::clone(WAL::Entity &entity) const + { + return new CameraComponent(entity); + } +} \ No newline at end of file diff --git a/sources/Component/Renderer/CameraComponent.hpp b/sources/Component/Renderer/CameraComponent.hpp new file mode 100644 index 00000000..1aa5cc38 --- /dev/null +++ b/sources/Component/Renderer/CameraComponent.hpp @@ -0,0 +1,28 @@ +// +// Created by Zoe Roux on 5/27/21. +// + +#pragma once + +#include + +namespace BBM +{ + //! @brief A class allowing one to place the camera in the scene. + //! @warning Only one CameraComponent is allowed on the scene. Using more than one result in undefined behaviors. + class CameraComponent : public WAL::Component + { + public: + //! @inherit + Component *clone(WAL::Entity &entity) const override; + + //! @brief Ctor + explicit CameraComponent(WAL::Entity &); + //! @brief A camera component is copy constructable. + CameraComponent(const CameraComponent &) = default; + //! @brief Default destructor. + ~CameraComponent() override = default; + //! @brief A camera component can't be assigned. + CameraComponent &operator=(const CameraComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Component/Drawable/Drawable2DComponent.hpp b/sources/Component/Renderer/Drawable2DComponent.hpp similarity index 77% rename from sources/Component/Drawable/Drawable2DComponent.hpp rename to sources/Component/Renderer/Drawable2DComponent.hpp index 0e383701..63aaaf2b 100644 --- a/sources/Component/Drawable/Drawable2DComponent.hpp +++ b/sources/Component/Renderer/Drawable2DComponent.hpp @@ -17,11 +17,17 @@ namespace BBM T member; //! ctor - explicit Drawable2DComponent(WAL::Entity &entity, T member) + Drawable2DComponent(WAL::Entity &entity, T member) : WAL::Component(entity), member(std::move(member)) - { - } + {} + + //! ctor + template + explicit Drawable2DComponent(WAL::Entity &entity, Params &&...params) + : WAL::Component(entity), + member(std::forward(params)...) + {} //! @brief Clone a component for another or the same entity. //! @param entity The entity that owns the ne component. diff --git a/sources/Component/Drawable/Drawable3DComponent.hpp b/sources/Component/Renderer/Drawable3DComponent.hpp similarity index 78% rename from sources/Component/Drawable/Drawable3DComponent.hpp rename to sources/Component/Renderer/Drawable3DComponent.hpp index f221e7de..0f8de20e 100644 --- a/sources/Component/Drawable/Drawable3DComponent.hpp +++ b/sources/Component/Renderer/Drawable3DComponent.hpp @@ -17,11 +17,17 @@ namespace BBM T member; //! @brief ctor - explicit Drawable3DComponent(WAL::Entity &entity, T member) + Drawable3DComponent(WAL::Entity &entity, T member) : WAL::Component(entity), member(std::move(member)) - { - } + {} + + //! ctor + template + explicit Drawable3DComponent(WAL::Entity &entity, Params &&...params) + : WAL::Component(entity), + member(std::forward(params)...) + {} //! @brief Clone a component for another or the same entity. //! @param entity The entity that owns the ne component. diff --git a/sources/Models/Vector2.hpp b/sources/Models/Vector2.hpp new file mode 100644 index 00000000..07904949 --- /dev/null +++ b/sources/Models/Vector2.hpp @@ -0,0 +1,166 @@ +// +// Created by Zoe Roux on 5/17/21. +// + + +#pragma once + +#include +#include +#include "Vector/Vector2.hpp" + +namespace BBM +{ + //! @brief A Vector2 data type. (templated to allow any kind of vector2) + template + class Vector2 + { + public: + //! @brief The x value of the vector + T x; + //! @brief The y value of the vector + T y; + + //! @brief Create a new nil vector2. + Vector2() + : x(0), y(0) + {} + + //! @brief Create a new vector2 representing a specific coordinate. + Vector2(T x, T y) + : x(x), y(y) + {} + + //! @brief A default destructor + ~Vector2() = default; + + bool operator==(const Vector2 &other) const + { + return this->x == other.x && this->y == other.y; + } + + bool operator!=(const Vector2 &other) const + { + return !this->operator==(other); + } + + template + Vector2 &operator+=(const Vector2 &vec) + { + this->x += vec.x; + this->y += vec.y; + return *this; + } + + template + Vector2 operator+(const Vector2 &vec) const + { + return Vector2(this->x + vec.x, this->y + vec.y); + } + + template + Vector2 &operator-=(const Vector2 &vec) + { + this->x -= vec.x; + this->y -= vec.y; + return *this; + } + + template + Vector2 &operator*=(T2 d) + { + this->x *= d; + this->y *= d; + return *this; + } + + template + Vector2 operator*(T2 d) const + { + return Vector2(this->x * d, this->y * d); + } + + template + Vector2 operator*(const Vector2 &b) const + { + return Vector2(this->x * b.x, this->y * b.y); + } + + template + Vector2 operator/=(const Vector2 &b) + { + this->x /= b.x; + this->y /= b.y; + return this; + } + + template + Vector2 operator/(const Vector2 &b) const + { + return Vector2(this->x / b.x, this->y / b.y); + } + + template + Vector2 operator/=(T2 b) + { + this->x /= b; + this->y /= b; + return this; + } + + template + Vector2 operator/(T2 b) const + { + return Vector2(this->x / b, this->y / b); + } + + template + double distance(const Vector2 &o) const + { + return std::sqrt(std::pow(this->x - o.x, 2) + std::pow(this->y - o.y, 2)); + } + + double magnitude() const + { + return std::sqrt(std::pow(this->x, 2) + std::pow(this->y, 2)); + } + + Vector2 normalize() + { + double mag = this->magnitude(); + + this->x /= mag; + this->y /= mag; + return *this; + } + + Vector2 normalized() const + { + T mag = this->magnitude(); + + return Vector2(this->x / mag, this->y / mag); + } + + Vector2 projection(const Vector2 &point) const + { + return (point * this) / std::pow(this->magnitude(), 2) * this; + } + + operator RAY::Vector2() const requires(std::is_same_v) + { + return RAY::Vector2(this->x, this->y); + } + }; + + typedef Vector2 Vector2f; + typedef Vector2 Vector2u; + typedef Vector2 Vector2i; +} + + +template +std::ostream &operator<<(std::ostream &s, const BBM::Vector2 &v) +{ + s << "Vector2<" << typeid(T).name() << ">("<< v.x << ", " << v.y << ")"; + return s; +} \ No newline at end of file diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index 93327c70..5579b382 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -154,19 +154,18 @@ namespace BBM return (point * this) / std::pow(this->magnitude(), 2) * this; } - explicit operator RAY::Vector3() const { return {this->x, this->y, this->z};} + operator RAY::Vector3() const requires(std::is_same_v) + { + return RAY::Vector3(this->x, this->y, this->z); + } }; typedef Vector3 Vector3f; typedef Vector3 Vector3u; typedef Vector3 Vector3i; - - } - - template std::ostream &operator<<(std::ostream &s, const BBM::Vector3 &v) { diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index ff2dc933..06c2cd6b 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -4,6 +4,12 @@ #include #include +#include +#include +#include +#include +#include +#include #include "Runner.hpp" #include "Models/GameState.hpp" @@ -17,9 +23,36 @@ namespace BBM // If you don't need the scene anymore, remember to remove it from the loadedScene array. } + void enableRaylib(WAL::Wal &wal) + { + RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE); + +// wal.addSystem<>(); 3D elements here + + wal.addSystem(window) + .addSystem>(); + wal.addSystem(window); + } + + WAL::Scene loadGameScene() + { + WAL::Scene scene; + scene.addEntity("cube") + .addComponent() + .addComponent>(Vector2f(), Vector2f(1, 1), RED); + return scene; + } + int run() { WAL::Wal wal; + wal.addSystem(); + enableRaylib(wal); + WAL::Scene scene = loadGameScene(); + wal.scene = scene; + + + // wal.scene = loadGameScene(); try { wal.run(updateState); diff --git a/sources/System/Renderer/Render2DScreenSystem.cpp b/sources/System/Renderer/Render2DScreenSystem.cpp new file mode 100644 index 00000000..d82747f5 --- /dev/null +++ b/sources/System/Renderer/Render2DScreenSystem.cpp @@ -0,0 +1,19 @@ +// +// Created by Zoe Roux on 5/27/21. +// + +#include "Render2DScreenSystem.hpp" + +namespace BBM +{ + Render2DScreenSystem::Render2DScreenSystem(RAY::Window &window) + : WAL::System({}), + _window(window), + _camera(RAY::Vector2(), RAY::Vector2(), 0) + {} + + void Render2DScreenSystem::onSelfUpdate() + { + this->_window.useCamera(this->_camera); + } +} \ No newline at end of file diff --git a/sources/System/Renderer/Render2DScreenSystem.hpp b/sources/System/Renderer/Render2DScreenSystem.hpp new file mode 100644 index 00000000..12adaf34 --- /dev/null +++ b/sources/System/Renderer/Render2DScreenSystem.hpp @@ -0,0 +1,33 @@ +// +// Created by Zoe Roux on 5/27/21. +// + +#pragma once + +#include +#include + +namespace BBM +{ + class Render2DScreenSystem : public WAL::System + { + //! @brief The window to render on + RAY::Window &_window; + + //! @brief The camera used to render. + RAY::Camera::Camera2D _camera; + public: + //! @brief A method called after all entities that this system manage has been updated. + //! @note render on screen here + void onSelfUpdate() override; + + //! @brief ctor + explicit Render2DScreenSystem(RAY::Window &window); + //! @brief Default copy ctor + Render2DScreenSystem(const Render2DScreenSystem &) = default; + //! @brief Default dtor + ~Render2DScreenSystem() override = default; + //! @brief A render screen system can't be assigned. + Render2DScreenSystem &operator=(const Render2DScreenSystem &) = delete; + }; +} \ No newline at end of file diff --git a/sources/System/Renderer/RenderScreenSystem.cpp b/sources/System/Renderer/RenderScreenSystem.cpp new file mode 100644 index 00000000..5523ee48 --- /dev/null +++ b/sources/System/Renderer/RenderScreenSystem.cpp @@ -0,0 +1,32 @@ +// +// Created by Zoe Roux on 5/27/21. +// + +#include "RenderScreenSystem.hpp" +#include "Component/Renderer/CameraComponent.hpp" +#include "Component/Position/PositionComponent.hpp" + +namespace BBM +{ + RenderScreenSystem::RenderScreenSystem(RAY::Window &window) + : WAL::System({ + typeid(CameraComponent), + typeid(PositionComponent) + }), + _window(window), + _camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE) + {} + + void RenderScreenSystem::onSelfUpdate() + { + this->_window.draw(); + this->_window.clear(); + this->_window.useCamera(this->_camera); + } + + void RenderScreenSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) + { + const auto &pos = entity.getComponent(); + _camera.setPosition(pos.position); + } +} \ No newline at end of file diff --git a/sources/System/Renderer/RenderScreenSystem.hpp b/sources/System/Renderer/RenderScreenSystem.hpp index 04f8e5e2..e9b2ea85 100644 --- a/sources/System/Renderer/RenderScreenSystem.hpp +++ b/sources/System/Renderer/RenderScreenSystem.hpp @@ -10,39 +10,28 @@ namespace BBM { - template class RenderScreenSystem : public WAL::System { //! @brief The window to render on RAY::Window &_window; - //! @brief The camera - T &_camera; - public: - //! @brief ctor - explicit RenderScreenSystem(RAY::Window &window, T &camera) - : WAL::System({}), - _window(window), - _camera(camera) - { - } + //! @brief The camera used to render. + RAY::Camera::Camera3D _camera; + public: //! @brief A method called after all entities that this system manage has been updated. //! @note render on screen here - void onSelfUpdate() override - { - this->_window.unuseCamera(); - this->_window.setDrawingState(RAY::Window::IDLE); - this->_window.setDrawingState(RAY::Window::DRAWING); - this->_window.clear(); - this->_window.useCamera(_camera); - } + void onSelfUpdate() override; + //! @inherit + void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override; + + //! @brief ctor + explicit RenderScreenSystem(RAY::Window &window); //! @brief Default copy ctor RenderScreenSystem(const RenderScreenSystem &) = default; //! @brief Default dtor ~RenderScreenSystem() override = default; - //! @brief Default assignment operator - RenderScreenSystem &operator=(const RenderScreenSystem &) = default; + //! @brief A render screen system can't be assigned. + RenderScreenSystem &operator=(const RenderScreenSystem &) = delete; }; - } diff --git a/sources/System/Renderer/Renderer2DSystem.hpp b/sources/System/Renderer/Renderer2DSystem.hpp index 59518e68..a1622c0d 100644 --- a/sources/System/Renderer/Renderer2DSystem.hpp +++ b/sources/System/Renderer/Renderer2DSystem.hpp @@ -8,7 +8,7 @@ #include "System/System.hpp" #include "Entity/Entity.hpp" #include "Component/Position/PositionComponent.hpp" -#include "Component/Drawable/Drawable2DComponent.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" #include "Window.hpp" namespace BBM @@ -20,9 +20,9 @@ namespace BBM //! @brief The class to render RAY::Window &_window; public: - explicit Renderer2DSystem(RAY::Window &window) + explicit Renderer2DSystem() : WAL::System({typeid(PositionComponent), typeid(Drawable2DComponent)}), - _window(window) + _window(RAY::Window::getInstance()) { } diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index dd55e584..b8435aed 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -8,7 +8,7 @@ #include "System/System.hpp" #include "Entity/Entity.hpp" #include "Component/Position/PositionComponent.hpp" -#include "Component/Drawable/Drawable3DComponent.hpp" +#include "Component/Renderer/Drawable3DComponent.hpp" #include "Window.hpp" namespace BBM diff --git a/sources/main.cpp b/sources/main.cpp index 8bdf948f..46846934 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -24,8 +24,8 @@ #include "Model/ModelAnimations.hpp" #include "System/Renderer/Renderer3DSystem.hpp" #include "System/Renderer/Renderer2DSystem.hpp" -#include "Component/Drawable/Drawable3DComponent.hpp" -#include "Component/Drawable/Drawable2DComponent.hpp" +#include "Component/Renderer/Drawable3DComponent.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" #include "System/Renderer/RenderScreenSystem.hpp" #include "Vector/Vector3.hpp" #include "Window.hpp" @@ -47,52 +47,52 @@ std::string get_full_path(const std::string &color) int demo() { - WAL::Wal wal; - const int screenWidth = 800; - const int screenHeight = 450; - - RAY::TraceLog::setLevel(LOG_WARNING); - RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE); - RAY::Image icon("assets/icon.png"); - window.setIcon(icon); - RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f), - RAY::Vector3(0.0f, 0.0f, 0.0f), - RAY::Vector3(0.0f, 1.0f, 0.0f), - 45.0f, CAMERA_PERSPECTIVE - ); - - RAY::Camera::Camera2D camera2D(RAY::Vector2(screenWidth / 2.0f, screenHeight / 2.0f), - RAY::Vector2(20.0f, 20.0f), - 0., 1); - WAL::Entity entityPlayer("roger"); - //RAY::Drawables::Drawables2D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0); - RAY::Drawables::Drawables2D::Circle circle({0, 0}, 50, MAROON); - //RAY::Drawables::Drawables3D::Cube cube({0, 0, 0}, {2, 2, 2}, BLUE); - BBM::Drawable2DComponent circleComponent(entityPlayer, circle); -// BBM::Drawable3DComponent cubeComponent(entityPlayer, cube); - BBM::PositionComponent posComponent(entityPlayer, {0, 0, 0}); - - BBM::Renderer2DSystem circleSystem(window); - //BBM::Renderer3DSystem cubeSystem(window); - - BBM::RenderScreenSystem renderSystem(window, camera2D); - - wal.addSystem(circleSystem); - wal.addSystem(renderSystem); - //wal.addSystem(cubeSystem); - entityPlayer.addComponent(circleComponent); - //entityPlayer.addComponent(cubeComponent); - entityPlayer.addComponent(posComponent); - wal.scene.addEntity(entityPlayer); - - camera.setMode(CAMERA_FREE); // Set free camera mode - - float y_rotation = 0; - window.setFPS(60); - - wal.run([](WAL::Wal &wal, int) {}); - - window.close(); +// WAL::Wal wal; +// const int screenWidth = 800; +// const int screenHeight = 450; +// +// RAY::TraceLog::setLevel(LOG_WARNING); +// RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE); +// RAY::Image icon("assets/icon.png"); +// window.setIcon(icon); +// RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f), +// RAY::Vector3(0.0f, 0.0f, 0.0f), +// RAY::Vector3(0.0f, 1.0f, 0.0f), +// 45.0f, CAMERA_PERSPECTIVE +// ); +// +// RAY::Camera::Camera2D camera2D(RAY::Vector2(screenWidth / 2.0f, screenHeight / 2.0f), +// RAY::Vector2(20.0f, 20.0f), +// 0., 1); +// WAL::Entity entityPlayer("roger"); +// //RAY::Drawables::Drawables2D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0); +// RAY::Drawables::Drawables2D::Circle circle({0, 0}, 50, MAROON); +// //RAY::Drawables::Drawables3D::Cube cube({0, 0, 0}, {2, 2, 2}, BLUE); +// BBM::Drawable2DComponent circleComponent(entityPlayer, circle); +//// BBM::Drawable3DComponent cubeComponent(entityPlayer, cube); +// BBM::PositionComponent posComponent(entityPlayer, {0, 0, 0}); +// +// BBM::Renderer2DSystem circleSystem(window); +// //BBM::Renderer3DSystem cubeSystem(window); +// +//// BBM::RenderScreenSystem renderSystem(window, camera2D); +// +// wal.addSystem(circleSystem); +//// wal.addSystem(renderSystem); +// //wal.addSystem(cubeSystem); +// entityPlayer.addComponent(circleComponent); +// //entityPlayer.addComponent(cubeComponent); +// entityPlayer.addComponent(posComponent); +// wal.scene.addEntity(entityPlayer); +// +// camera.setMode(CAMERA_FREE); // Set free camera mode +// +// float y_rotation = 0; +// window.setFPS(60); +// +// wal.run([](WAL::Wal &wal, int) {}); +// +// window.close(); /* @@ -160,7 +160,7 @@ int demo() window.setDrawingState(RAY::Window::IDLE); } */ - window.close(); +// window.close(); return 0; @@ -181,6 +181,6 @@ int main(int argc, char **argv) usage(argv[0]); return 1; } - return demo(); +// return demo(); return BBM::run(); }