mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-25 07:34:01 +00:00
remove unwanted defines + upade encapsulation for window drawing function
This commit is contained in:
@@ -107,10 +107,14 @@ void RAY::Window::clear(const RAY::Color &color)
|
||||
ClearBackground(color);
|
||||
}
|
||||
|
||||
void RAY::Window::draw()
|
||||
void RAY::Window::beginDrawing()
|
||||
{
|
||||
BeginDrawing();
|
||||
}
|
||||
|
||||
void RAY::Window::endDrawing()
|
||||
{
|
||||
EndDrawing();
|
||||
BeginDrawing();
|
||||
}
|
||||
|
||||
void RAY::Window::useCamera(RAY::Camera::Camera2D &camera)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#ifndef WINDOW_HPP_
|
||||
#define WINDOW_HPP_
|
||||
#define INTERNAL public
|
||||
|
||||
#include <raylib.h>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
@@ -102,8 +102,10 @@ namespace RAY {
|
||||
NONE,
|
||||
};
|
||||
|
||||
//! @brief Draw the content of the buffer on the screen.
|
||||
void draw();
|
||||
//! @brief Setup canvas (framebuffer) to start drawing
|
||||
void beginDrawing();
|
||||
//! @brief End canvas drawing and swap buffers (double buffering)
|
||||
void endDrawing();
|
||||
|
||||
//! @brief Initialize 2D mode with custom camera (2D)
|
||||
void useCamera(Camera::Camera2D &camera);
|
||||
@@ -131,6 +133,7 @@ namespace RAY {
|
||||
//! @brief Draw a 3d mesh with material and transform
|
||||
void draw(const Mesh &mesh, const Material &material, const Matrix &transform);
|
||||
|
||||
//! @return true if the window's context has been correctly initialized
|
||||
bool isReady() const;
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/27/21.
|
||||
//
|
||||
|
||||
#include "Render2DScreenSystem.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
Render2DScreenSystem::Render2DScreenSystem(RAY::Window &window)
|
||||
: WAL::System({}),
|
||||
_window(window)
|
||||
{}
|
||||
|
||||
void Render2DScreenSystem::onSelfUpdate()
|
||||
{
|
||||
EndMode3D();
|
||||
printf("EndMode3D\n");
|
||||
DrawText("Try selecting the box with mouse!", 10, 10, 20, WHITE);
|
||||
//this->_window.unuseCamera();
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/27/21.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <System/System.hpp>
|
||||
#include <Window.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class Render2DScreenSystem : public WAL::System
|
||||
{
|
||||
//! @brief The window to render on
|
||||
RAY::Window &_window;
|
||||
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;
|
||||
};
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// 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)
|
||||
{
|
||||
this->_camera.setMode(CAMERA_FREE);
|
||||
}
|
||||
|
||||
void RenderScreenSystem::onSelfUpdate()
|
||||
{
|
||||
//this->_window.draw();
|
||||
//EndMode2D();
|
||||
EndDrawing();
|
||||
this->_camera.update();
|
||||
BeginDrawing();
|
||||
this->_window.clear();
|
||||
BeginMode3D(this->_camera);
|
||||
printf("BeginMode3D\n");
|
||||
}
|
||||
|
||||
void RenderScreenSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
const auto &pos = entity.getComponent<PositionComponent>();
|
||||
_camera.setPosition(pos.position);
|
||||
//this->_camera.update();
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
// Created by Zoe Roux on 5/27/21.
|
||||
//
|
||||
|
||||
#undef INTERNAL
|
||||
#define INTERNAL public
|
||||
#include <Component/Renderer/Drawable3DComponent.hpp>
|
||||
#include "Models/Vector2.hpp"
|
||||
#include "RenderSystem.hpp"
|
||||
@@ -28,10 +26,10 @@ namespace BBM
|
||||
void RenderSystem::onSelfUpdate()
|
||||
{
|
||||
this->_camera.update();
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
this->_window.beginDrawing();
|
||||
this->_window.clear();
|
||||
|
||||
BeginMode3D(this->_camera);
|
||||
this->_window.useCamera(this->_camera);
|
||||
for (auto &entity : this->_wal.scene->getEntities()) {
|
||||
if (!entity.hasComponent<Drawable3DComponent>()
|
||||
|| !entity.hasComponent<PositionComponent>())
|
||||
@@ -42,7 +40,7 @@ namespace BBM
|
||||
drawable.drawable->setPosition(pos.position);
|
||||
drawable.drawable->drawOn(this->_window);
|
||||
}
|
||||
EndMode3D();
|
||||
this->_window.unuseCamera();
|
||||
|
||||
// TODO sort entities based on the Z axis
|
||||
for (auto &entity : this->_wal.scene->getEntities()) {
|
||||
@@ -55,7 +53,7 @@ namespace BBM
|
||||
drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y));
|
||||
drawable.drawable->drawOn(this->_window);
|
||||
}
|
||||
EndDrawing();
|
||||
this->_window.endDrawing();
|
||||
}
|
||||
|
||||
void RenderSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// Created by cbihan on 24/05/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include "System/System.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||
#include "Window.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
template <class T>
|
||||
class Renderer2DSystem : public WAL::System
|
||||
{
|
||||
private:
|
||||
//! @brief The class to render
|
||||
RAY::Window &_window;
|
||||
public:
|
||||
explicit Renderer2DSystem()
|
||||
: WAL::System({typeid(PositionComponent), typeid(Drawable2DComponent<T>)}),
|
||||
_window(RAY::Window::getInstance())
|
||||
{
|
||||
}
|
||||
|
||||
//! @brief Update the corresponding component of the given entity
|
||||
//! @param entity The entity to update.
|
||||
//! @param dtime The delta time.
|
||||
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override
|
||||
{
|
||||
auto &comp = entity.getComponent<Drawable2DComponent<T>>();
|
||||
auto &pos = entity.getComponent<PositionComponent>();
|
||||
|
||||
comp.member.setPosition({pos.getX(), pos.getY()});
|
||||
this->_window.draw(comp.member);
|
||||
printf("Drawing smth\n");
|
||||
}
|
||||
|
||||
//! @brief default copy ctor
|
||||
Renderer2DSystem(const Renderer2DSystem &) = default;
|
||||
//! @brief default dtor
|
||||
~Renderer2DSystem() override = default;
|
||||
//! @brief Default assignment operator
|
||||
Renderer2DSystem &operator=(const Renderer2DSystem &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
//
|
||||
// Created by cbihan on 24/05/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include "System/System.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
#include "Window.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
template <class T>
|
||||
class Renderer3DSystem : public WAL::System
|
||||
{
|
||||
private:
|
||||
//! @brief The class to render
|
||||
RAY::Window &_window;
|
||||
public:
|
||||
//! @brief ctor
|
||||
explicit Renderer3DSystem()
|
||||
: WAL::System({typeid(PositionComponent), typeid(Drawable3DComponent<T>)}),
|
||||
_window(RAY::Window::getInstance())
|
||||
{}
|
||||
|
||||
//! @brief Update the corresponding component of the given entity
|
||||
//! @param entity The entity to update.
|
||||
//! @param dtime The delta time.
|
||||
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override
|
||||
{
|
||||
auto &comp = entity.getComponent<Drawable3DComponent<T>>();
|
||||
auto &pos = entity.getComponent<PositionComponent>();
|
||||
|
||||
comp.member.setPosition(static_cast<RAY::Vector3>(pos.position));
|
||||
this->_window.draw(comp.member);
|
||||
}
|
||||
|
||||
//! @brief Default copy ctor
|
||||
Renderer3DSystem(const Renderer3DSystem &) = default;
|
||||
//! @brief Default dtor
|
||||
~Renderer3DSystem() override = default;
|
||||
//! @brief Default assignment operator
|
||||
Renderer3DSystem &operator=(const Renderer3DSystem &) = delete;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user