From 54fe8005492a912bedb483d33d418e5b140a8a62 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 24 May 2021 14:59:28 +0200 Subject: [PATCH 01/24] Adding a state and scene utils --- CMakeLists.txt | 4 +++ lib/wal/sources/Models/Callback.hpp | 6 +++++ lib/wal/sources/Wal.cpp | 19 --------------- lib/wal/sources/Wal.hpp | 38 +++++++++++++++++++++++++++-- sources/Models/GameState.hpp | 31 +++++++++++++++++++++++ sources/Runner/Runner.cpp | 32 ++++++++++++++++++++++++ sources/Runner/Runner.hpp | 12 +++++++++ sources/main.cpp | 26 +++++++++++--------- 8 files changed, 136 insertions(+), 32 deletions(-) create mode 100644 sources/Models/GameState.hpp create mode 100644 sources/Runner/Runner.cpp create mode 100644 sources/Runner/Runner.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cd7e892..302671f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,11 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/lib/wal) add_executable(bomberman sources/main.cpp + sources/Models/GameState.hpp + sources/Runner/Runner.cpp + sources/Runner/Runner.hpp ) +target_include_directories(bomberman PUBLIC sources) find_package(raylib QUIET) if (NOT raylib_FOUND) diff --git a/lib/wal/sources/Models/Callback.hpp b/lib/wal/sources/Models/Callback.hpp index 9cce38cd..334d39a7 100644 --- a/lib/wal/sources/Models/Callback.hpp +++ b/lib/wal/sources/Models/Callback.hpp @@ -50,5 +50,11 @@ namespace WAL ~Callback() = default; //! @brief A default assignment operator Callback &operator=(const Callback &) = default; + + //! @brief Implicitly transform a function into a callback. + Callback(std::function callback) // NOLINT(google-explicit-constructor) + { + this->addCallback(callback); + } }; } \ No newline at end of file diff --git a/lib/wal/sources/Wal.cpp b/lib/wal/sources/Wal.cpp index 45d2caff..126f78dd 100644 --- a/lib/wal/sources/Wal.cpp +++ b/lib/wal/sources/Wal.cpp @@ -12,25 +12,6 @@ namespace WAL { std::chrono::nanoseconds Wal::timestep = 8ms; - void Wal::run() - { - auto lastTick = std::chrono::steady_clock::now(); - std::chrono::nanoseconds fBehind(0); - - while (!this->_shouldClose) { - auto now = std::chrono::steady_clock::now(); - std::chrono::nanoseconds dtime = now - lastTick; - fBehind += dtime; - lastTick = now; - - while (fBehind > Wal::timestep) { - fBehind -= Wal::timestep; - this->_fixedUpdate(); - } - this->_update(dtime); - } - } - void Wal::_update(std::chrono::nanoseconds dtime) { auto &entities = this->_scene.getEntities(); diff --git a/lib/wal/sources/Wal.hpp b/lib/wal/sources/Wal.hpp index f1b61f6f..9f560ac2 100644 --- a/lib/wal/sources/Wal.hpp +++ b/lib/wal/sources/Wal.hpp @@ -8,10 +8,11 @@ #include #include #include -#include +#include "Exception/WalError.hpp" #include "Scene/Scene.hpp" #include "Entity/Entity.hpp" #include "System/System.hpp" +#include "Models/Callback.hpp" namespace WAL { @@ -101,7 +102,40 @@ namespace WAL } //! @brief Start the game loop - void run(); + //! @param callback A callback called after each update of the game. It allow you to update the engine based on a specific game state. (you can also update the game state here) + //! @param state An initial game state. If not specified, it will be defaulted. + //! @tparam T A type used to track your game state. It must be default constructable. + template + void run(const std::function &callback, T state = T()) + { + Callback update(callback); + return this->run(update, state); + } + + //! @brief Start the game loop + //! @param callback A callback called after each update of the game. It allow you to update the engine based on a specific game state. (you can also update the game state here) + //! @param state An initial game state. If not specified, it will be defaulted. + //! @tparam T A type used to track your game state. It must be default constructable. + template + void run(const Callback &callback, T state = T()) + { + auto lastTick = std::chrono::steady_clock::now(); + std::chrono::nanoseconds fBehind(0); + + while (!this->_shouldClose) { + auto now = std::chrono::steady_clock::now(); + std::chrono::nanoseconds dtime = now - lastTick; + fBehind += dtime; + lastTick = now; + + while (fBehind > Wal::timestep) { + fBehind -= Wal::timestep; + this->_fixedUpdate(); + } + this->_update(dtime); + callback(*this, state); + } + } //! @brief A default constructor Wal() = default; diff --git a/sources/Models/GameState.hpp b/sources/Models/GameState.hpp new file mode 100644 index 00000000..7be6b723 --- /dev/null +++ b/sources/Models/GameState.hpp @@ -0,0 +1,31 @@ +// +// Created by Zoe Roux on 5/24/21. +// + + +#pragma once + +#include +#include + + +namespace Bomberman +{ + //! @brief A class representing the current game state. This allow one to retain information between update calls. + class GameState + { + //! @brief The list of scenes available. + enum SceneID + { + MainMenu, + GameScene + }; + + + //! @brief The currently loaded scene + SceneID currentScene = MainMenu; + + //! @brief The list of loaded scenes. + std::unordered_map _loadedScenes = {}; + }; +} \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp new file mode 100644 index 00000000..837831cc --- /dev/null +++ b/sources/Runner/Runner.cpp @@ -0,0 +1,32 @@ +// +// Created by Zoe Roux on 5/24/21. +// + +#include +#include +#include "Runner.hpp" +#include "Models/GameState.hpp" + +namespace Bomberman +{ + void updateState(WAL::Wal &engine, GameState &state) + { + // You can change the scene here or update the game state based on entities values. + + // If you want to keep a scene loaded but not running, store it in the state.loadedScenes. + // If you don't need the scene anymore, remember to remove it from the loadedScene array. + } + + int run() + { + WAL::Wal wal; + + try { + wal.run(updateState); + return 0; + } catch (const std::exception &ex) { + std::cerr << ex.what() << std::endl; + return 1; + } + } +} \ No newline at end of file diff --git a/sources/Runner/Runner.hpp b/sources/Runner/Runner.hpp new file mode 100644 index 00000000..4531039a --- /dev/null +++ b/sources/Runner/Runner.hpp @@ -0,0 +1,12 @@ +// +// Created by Zoe Roux on 5/24/21. +// + +#pragma once + +namespace Bomberman +{ + //! @brief Start the game and run a Bomberman. + //! @return 0 on success, another value on error. + int run(); +} \ No newline at end of file diff --git a/sources/main.cpp b/sources/main.cpp index 3096203d..8f963fb4 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -7,17 +7,21 @@ #include -#include +#include "Runner/Runner.hpp" -int main() +void usage(const std::string &bin) { - WAL::Wal wal; - - try { - wal.run(); - return 0; - } catch (const std::exception &ex) { - std::cerr << ex.what() << std::endl; - return 84; - } + std::cout << "Bomberman." << std::endl + << "\tUsage: " << bin << " [options]" << std::endl + << "Options:" << std::endl + << "\t-h:\tPrint this help message" << std::endl; +} + +int main(int argc, char **argv) +{ + if (argc == 2 && std::string(argv[1]) == "-h") { + usage(argv[0]); + return 1; + } + return Bomberman::run(); } From 851e4e50e042ed050c21afc0519dcdcabd5465ba Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 24 May 2021 15:29:54 +0200 Subject: [PATCH 02/24] Fixing catch path --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22171362..3c6cf9dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ target_link_libraries(unit_tests PUBLIC wal ray) find_package(Catch2 QUIET) if (NOT Catch2_FOUND) - set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../catch2) + set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/lib/catch2) find_package(Catch2 REQUIRED) endif() target_link_libraries(unit_tests PRIVATE Catch2::Catch2) From 22f61db1b3f3f3a94ca946e586b6b9a3eb58ed24 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 24 May 2021 15:34:03 +0200 Subject: [PATCH 03/24] Fixing tests ci --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 28aca385..f24a0564 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,4 +22,4 @@ jobs: cmake --build . -t unit_tests - name: Run tests run: | - ./unit_tests + ./build/unit_tests From 6deade8ddc6211be4ad1275601cd2a24a8d8bd90 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 24 May 2021 17:15:24 +0200 Subject: [PATCH 04/24] Fixing namespace --- sources/Component/Movable/MovableComponent.cpp | 2 +- sources/Component/Movable/MovableComponent.hpp | 2 +- sources/Component/Position/PositionComponent.cpp | 2 +- sources/Component/Position/PositionComponent.hpp | 2 +- sources/Models/GameState.hpp | 2 +- sources/Models/Vector3.hpp | 4 ++-- sources/Runner/Runner.cpp | 2 +- sources/Runner/Runner.hpp | 2 +- sources/System/Movable/MovableSystem.cpp | 2 +- sources/System/Movable/MovableSystem.hpp | 2 +- sources/main.cpp | 2 +- tests/EngineTests.cpp | 2 +- tests/EntityTests.cpp | 2 +- 13 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sources/Component/Movable/MovableComponent.cpp b/sources/Component/Movable/MovableComponent.cpp index c0e9e52d..2bbbde92 100644 --- a/sources/Component/Movable/MovableComponent.cpp +++ b/sources/Component/Movable/MovableComponent.cpp @@ -4,7 +4,7 @@ #include "MovableComponent.hpp" -namespace Bomberman +namespace BBM { MovableComponent::MovableComponent(WAL::Entity &entity) : Component(entity) diff --git a/sources/Component/Movable/MovableComponent.hpp b/sources/Component/Movable/MovableComponent.hpp index 2f194378..5266232a 100644 --- a/sources/Component/Movable/MovableComponent.hpp +++ b/sources/Component/Movable/MovableComponent.hpp @@ -7,7 +7,7 @@ #include "Models/Vector3.hpp" #include "Entity/Entity.hpp" -namespace Bomberman +namespace BBM { //! @brief A component to place on entities that can move or be moved. class MovableComponent : public WAL::Component diff --git a/sources/Component/Position/PositionComponent.cpp b/sources/Component/Position/PositionComponent.cpp index d992a4a5..c237f845 100644 --- a/sources/Component/Position/PositionComponent.cpp +++ b/sources/Component/Position/PositionComponent.cpp @@ -4,7 +4,7 @@ #include "PositionComponent.hpp" -namespace Bomberman +namespace BBM { PositionComponent::PositionComponent(WAL::Entity &entity) : Component(entity), diff --git a/sources/Component/Position/PositionComponent.hpp b/sources/Component/Position/PositionComponent.hpp index 18c5faee..368934eb 100644 --- a/sources/Component/Position/PositionComponent.hpp +++ b/sources/Component/Position/PositionComponent.hpp @@ -7,7 +7,7 @@ #include "Models/Vector3.hpp" #include "Component/Component.hpp" -namespace Bomberman +namespace BBM { //! @brief A basic position component class PositionComponent : public WAL::Component diff --git a/sources/Models/GameState.hpp b/sources/Models/GameState.hpp index 7be6b723..883578bf 100644 --- a/sources/Models/GameState.hpp +++ b/sources/Models/GameState.hpp @@ -9,7 +9,7 @@ #include -namespace Bomberman +namespace BBM { //! @brief A class representing the current game state. This allow one to retain information between update calls. class GameState diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index ab642e94..094f6da9 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -8,7 +8,7 @@ #include #include -namespace Bomberman +namespace BBM { //! @brief A Vector3 data type. (templated to allow any kind of vector3) template @@ -160,7 +160,7 @@ namespace Bomberman } template -std::ostream &operator<<(std::ostream &s, const Bomberman::Vector3 &v) +std::ostream &operator<<(std::ostream &s, const BBM::Vector3 &v) { s << "Vector3<" << typeid(T).name() << ">("<< v.x << ", " << v.y << ", " << v.z << ")"; return s; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 837831cc..ff2dc933 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -7,7 +7,7 @@ #include "Runner.hpp" #include "Models/GameState.hpp" -namespace Bomberman +namespace BBM { void updateState(WAL::Wal &engine, GameState &state) { diff --git a/sources/Runner/Runner.hpp b/sources/Runner/Runner.hpp index 4531039a..0f622f11 100644 --- a/sources/Runner/Runner.hpp +++ b/sources/Runner/Runner.hpp @@ -4,7 +4,7 @@ #pragma once -namespace Bomberman +namespace BBM { //! @brief Start the game and run a Bomberman. //! @return 0 on success, another value on error. diff --git a/sources/System/Movable/MovableSystem.cpp b/sources/System/Movable/MovableSystem.cpp index d8b88a48..2f699ece 100644 --- a/sources/System/Movable/MovableSystem.cpp +++ b/sources/System/Movable/MovableSystem.cpp @@ -7,7 +7,7 @@ #include "Component/Movable/MovableComponent.hpp" #include "Wal.hpp" -namespace Bomberman +namespace BBM { MovableSystem::MovableSystem() : System({ diff --git a/sources/System/Movable/MovableSystem.hpp b/sources/System/Movable/MovableSystem.hpp index 0bb89652..08555d26 100644 --- a/sources/System/Movable/MovableSystem.hpp +++ b/sources/System/Movable/MovableSystem.hpp @@ -7,7 +7,7 @@ #include "System/System.hpp" -namespace Bomberman +namespace BBM { //! @brief A system to handle movable entities. This system update velocity based on accelerations and positions based on velocity. class MovableSystem : public WAL::System diff --git a/sources/main.cpp b/sources/main.cpp index d29f7374..cd4efc41 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -107,5 +107,5 @@ int main(int argc, char **argv) return 1; } return demo(); - return Bomberman::run(); + return BBM::run(); } diff --git a/tests/EngineTests.cpp b/tests/EngineTests.cpp index 8c908dac..804b6050 100644 --- a/tests/EngineTests.cpp +++ b/tests/EngineTests.cpp @@ -8,7 +8,7 @@ #include using namespace WAL; -using namespace Bomberman; +using namespace BBM; TEST_CASE("Create system", "[Engine][System]") { diff --git a/tests/EntityTests.cpp b/tests/EntityTests.cpp index 3b009cad..f58fd0c1 100644 --- a/tests/EntityTests.cpp +++ b/tests/EntityTests.cpp @@ -7,7 +7,7 @@ #include using namespace WAL; -using namespace Bomberman; +using namespace BBM; TEST_CASE("Component", "[Entity]") { From 682b4388bbc877e437114b83f551f883fb0c8d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 10:46:12 +0200 Subject: [PATCH 05/24] fixing issues qith 3D/2D Renderer systems --- .../Drawable/Drawable3DComponent.hpp | 2 +- sources/System/Renderer/Renderer2DSystem.hpp | 4 +- sources/System/Renderer/Renderer3DSystem.hpp | 2 +- sources/main.cpp | 47 +++++++------------ 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/sources/Component/Drawable/Drawable3DComponent.hpp b/sources/Component/Drawable/Drawable3DComponent.hpp index 8807d76a..23fd2cd1 100644 --- a/sources/Component/Drawable/Drawable3DComponent.hpp +++ b/sources/Component/Drawable/Drawable3DComponent.hpp @@ -23,7 +23,7 @@ namespace BBM WAL::Component *clone(WAL::Entity &entity) const override { - return new Drawable3DComponent(entity); + return new Drawable3DComponent(entity, this->member); } }; } \ No newline at end of file diff --git a/sources/System/Renderer/Renderer2DSystem.hpp b/sources/System/Renderer/Renderer2DSystem.hpp index 69e94e96..a708d300 100644 --- a/sources/System/Renderer/Renderer2DSystem.hpp +++ b/sources/System/Renderer/Renderer2DSystem.hpp @@ -31,8 +31,8 @@ namespace BBM auto &comp = entity.getComponent>(); auto &pos = entity.getComponent(); - comp.setPosition({pos.getX(), pos.getY()}); - comp.drawOn(this->_window); + comp.member.setPosition({pos.getX(), pos.getY()}); + comp.member.drawOn(this->_window); } Renderer2DSystem(const Renderer2DSystem &) = default; diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index 83e91ff3..0a7423ff 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -31,7 +31,7 @@ namespace BBM auto &comp = entity.getComponent>(); auto &pos = entity.getComponent(); - comp.member.setPosition(pos); + comp.member.setPosition({pos.getX(), pos.getY(), pos.getZ()}); comp.member.drawOn(this->_window); } diff --git a/sources/main.cpp b/sources/main.cpp index d49bef62..55095958 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -13,11 +13,11 @@ #include "Drawables/Image.hpp" #include "Drawables/3D/Grid.hpp" #include "Drawables/Texture.hpp" -#include "Drawables/2D/Circle.hpp" +#include "Drawables/3D/Circle.hpp" #include "Model/Model.hpp" #include "Model/ModelAnimations.hpp" -#include "System/Renderer/Renderer2DSystem.hpp" -#include "Component/Drawable/Drawable2DComponent.hpp" +#include "System/Renderer/Renderer3DSystem.hpp" +#include "Component/Drawable/Drawable3DComponent.hpp" #include "Vector/Vector3.hpp" #include "Window.hpp" #include "TraceLog.hpp" @@ -37,11 +37,10 @@ std::string get_full_path(const std::string &color) int main() { - // Initialization - //-------------------------------------------------------------------------------------- + WAL::Wal wal; const int screenWidth = 800; const int screenHeight = 450; - std::vector::const_iterator iterator = textures.begin(); + auto iterator = textures.begin(); const std::string modelPath = "assets/player/player.obj"; const std::string texturePath = "assets/player/blue.png"; //const std::string animationPath = "assets/guy.iqm"; @@ -55,6 +54,15 @@ int main() RAY::Vector3(0.0f, 1.0f, 0.0f), 45.0f, CAMERA_PERSPECTIVE ); + WAL::Entity entityPlayer("roger"); + RAY::Drawables::Drawables3D::Circle circle({300, 300, 300}, 50, 0XFFFFFFF, {0, 0, 0}, 0); + BBM::Drawable3DComponent circleComponent(entityPlayer, circle); + + BBM::Renderer3DSystem circleSystem(window); + + wal.addSystem(circleSystem); + entityPlayer.addComponent(circleComponent); + RAY::Texture texture(get_full_path(*iterator)); //RAY::ModelAnimations animations(modelPath); RAY::Drawables::Drawables3D::Grid grid(10, 1.0f); @@ -66,17 +74,12 @@ int main() camera.setMode(CAMERA_FREE); // Set free camera mode float y_rotation = 0; - window.setFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- + window.setFPS(60); - // Main game loop - while (!window.shouldClose()) // Detect window close button or ESC key + while (!window.shouldClose()) { - // Update - //---------------------------------------------------------------------------------- camera.update(); - // Play animation when spacebar is held down if (RAY::Controller::Keyboard::isReleased(KEY_SPACE)) { ++iterator; @@ -88,33 +91,17 @@ int main() //animations[0].incrementFrameCounter(); //model.setAnimation(animations[0]); } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- window.setDrawingState(RAY::Window::DRAWING); - window.clear(); - window.useCamera(camera); - window.draw(model, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 5.0f, 5.0f, 5.0f )); - window.draw(grid); - window.unuseCamera(); - window.draw(instructionText); - window.setDrawingState(RAY::Window::IDLE); - //---------------------------------------------------------------------------------- } - // De-Initialization - //-------------------------------------------------------------------------------------- - - window.close(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- + window.close(); return 0; } From 9b763896986a803b1c7d46759c8d4d9618d95893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 10:56:06 +0200 Subject: [PATCH 06/24] dding missing doc and cooplean form --- sources/Component/Drawable/Drawable2DComponent.hpp | 12 +++++++++++- sources/Component/Drawable/Drawable3DComponent.hpp | 11 +++++++++++ sources/System/Renderer/Renderer2DSystem.hpp | 6 ++++++ sources/System/Renderer/Renderer3DSystem.hpp | 7 +++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/sources/Component/Drawable/Drawable2DComponent.hpp b/sources/Component/Drawable/Drawable2DComponent.hpp index c59e3c0c..0e383701 100644 --- a/sources/Component/Drawable/Drawable2DComponent.hpp +++ b/sources/Component/Drawable/Drawable2DComponent.hpp @@ -13,20 +13,30 @@ namespace BBM class Drawable2DComponent : public WAL::Component { public: - + //! @brief The type of the component T member; + //! ctor explicit Drawable2DComponent(WAL::Entity &entity, T member) : WAL::Component(entity), member(std::move(member)) { } + //! @brief Clone a component for another or the same entity. + //! @param entity The entity that owns the ne component. WAL::Component *clone(WAL::Entity &entity) const override { return new Drawable2DComponent(entity, this->member); } + //! @brief Default copy ctor + Drawable2DComponent(const Drawable2DComponent &) = default; + //! @brief Default dtor + ~Drawable2DComponent() override = default; + //! @brief Default assignment operator + Drawable2DComponent &operator=(const Drawable2DComponent &) = delete; + }; } \ No newline at end of file diff --git a/sources/Component/Drawable/Drawable3DComponent.hpp b/sources/Component/Drawable/Drawable3DComponent.hpp index 23fd2cd1..f221e7de 100644 --- a/sources/Component/Drawable/Drawable3DComponent.hpp +++ b/sources/Component/Drawable/Drawable3DComponent.hpp @@ -13,17 +13,28 @@ namespace BBM class Drawable3DComponent : public WAL::Component { public: + //! @brief The type of the component T member; + //! @brief ctor explicit Drawable3DComponent(WAL::Entity &entity, T member) : WAL::Component(entity), member(std::move(member)) { } + //! @brief Clone a component for another or the same entity. + //! @param entity The entity that owns the ne component. WAL::Component *clone(WAL::Entity &entity) const override { return new Drawable3DComponent(entity, this->member); } + + //! @brief Default copy ctor + Drawable3DComponent(const Drawable3DComponent &) = default; + //! @brief Default dtor + ~Drawable3DComponent() override = default; + //! @brief Default assignment operator + Drawable3DComponent &operator=(const Drawable3DComponent &) = delete; }; } \ No newline at end of file diff --git a/sources/System/Renderer/Renderer2DSystem.hpp b/sources/System/Renderer/Renderer2DSystem.hpp index a708d300..0008c1a0 100644 --- a/sources/System/Renderer/Renderer2DSystem.hpp +++ b/sources/System/Renderer/Renderer2DSystem.hpp @@ -26,6 +26,9 @@ namespace BBM { } + //! @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 dtime) override { auto &comp = entity.getComponent>(); @@ -35,8 +38,11 @@ namespace BBM comp.member.drawOn(this->_window); } + //! @brief default copy ctor Renderer2DSystem(const Renderer2DSystem &) = default; + //! @brief default dtor ~Renderer2DSystem() override = default; + //! @brief Default assignment operator Renderer2DSystem &operator=(const Renderer2DSystem &) = delete; }; } \ No newline at end of file diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index 0a7423ff..8478d320 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -20,12 +20,16 @@ namespace BBM //! @brief The class to render RAY::Window &_window; public: + //! @brief ctor explicit Renderer3DSystem(RAY::Window &window) : WAL::System({typeid(PositionComponent), typeid(Drawable3DComponent)}), _window(window) { } + //! @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 dtime) override { auto &comp = entity.getComponent>(); @@ -35,8 +39,11 @@ namespace BBM comp.member.drawOn(this->_window); } + //! @brief Default copy ctor Renderer3DSystem(const Renderer3DSystem &) = default; + //! @brief Default dtor ~Renderer3DSystem() override = default; + //! @brief Default assignment operator Renderer3DSystem &operator=(const Renderer3DSystem &) = delete; }; } \ No newline at end of file From 408e955b5218c09582202d421288bd4dc191a98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 11:38:21 +0200 Subject: [PATCH 07/24] big merge and fixing unit test compil --- .../Component/Movable/MovableComponent.cpp | 22 ++++++++++ .../Component/Movable/MovableComponent.hpp | 6 +-- .../Component/Position/PositionComponent.cpp | 43 +++++++++++++++++++ .../Component/Position/PositionComponent.hpp | 4 +- sources/System/Movable/MovableSystem.cpp | 2 +- sources/main.cpp | 1 + 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/sources/Component/Movable/MovableComponent.cpp b/sources/Component/Movable/MovableComponent.cpp index e69de29b..4fc9bc0c 100644 --- a/sources/Component/Movable/MovableComponent.cpp +++ b/sources/Component/Movable/MovableComponent.cpp @@ -0,0 +1,22 @@ +// +// Created by Zoe Roux on 5/17/21. +// + +#include "MovableComponent.hpp" + +namespace BBM +{ + MovableComponent::MovableComponent(WAL::Entity &entity) + : Component(entity) + {} + + WAL::Component *MovableComponent::clone(WAL::Entity &entity) const + { + return new MovableComponent(entity); + } + + void MovableComponent::addForce(Vector3f force) + { + this->_acceleration += force; + } +} // namespace WAL \ No newline at end of file diff --git a/sources/Component/Movable/MovableComponent.hpp b/sources/Component/Movable/MovableComponent.hpp index aee21495..7656a960 100644 --- a/sources/Component/Movable/MovableComponent.hpp +++ b/sources/Component/Movable/MovableComponent.hpp @@ -14,13 +14,13 @@ namespace BBM { private: //! @brief The acceleration of this entity. - WAL::Vector3f _acceleration; + Vector3f _acceleration; //! @brief The velocity of the entity. - WAL::Vector3f _velocity; + Vector3f _velocity; public: //! @brief Add an instant force to this entity. //! @param force The force to add to this entity's acceleration. The force is added instantly and in one go. - void addForce(WAL::Vector3f force); + void addForce(Vector3f force); //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Component/Position/PositionComponent.cpp b/sources/Component/Position/PositionComponent.cpp index e69de29b..b1b88f43 100644 --- a/sources/Component/Position/PositionComponent.cpp +++ b/sources/Component/Position/PositionComponent.cpp @@ -0,0 +1,43 @@ +// +// Created by Zoe Roux on 5/17/21. +// + +#include "PositionComponent.hpp" + +namespace BBM +{ + PositionComponent::PositionComponent(WAL::Entity &entity) + : Component(entity), + position() + {} + + PositionComponent::PositionComponent(WAL::Entity &entity, Vector3f pos) + : Component(entity), + position(pos) + {} + + PositionComponent::PositionComponent(WAL::Entity &entity, float x, float y, float z) + : Component(entity), + position(x, y, z) + {} + + WAL::Component *PositionComponent::clone(WAL::Entity &entity) const + { + return new PositionComponent(entity, this->position); + } + + float PositionComponent::getX() const + { + return this->position.x; + } + + float PositionComponent::getY() const + { + return this->position.y; + } + + float PositionComponent::getZ() const + { + return this->position.z; + } +} // namespace WAL \ No newline at end of file diff --git a/sources/Component/Position/PositionComponent.hpp b/sources/Component/Position/PositionComponent.hpp index 647314fd..0a34a8ca 100644 --- a/sources/Component/Position/PositionComponent.hpp +++ b/sources/Component/Position/PositionComponent.hpp @@ -14,7 +14,7 @@ namespace BBM { public: //! @brief Get the editable position of this entity - WAL::Vector3f position; + Vector3f position; //! @brief Get the X position of this entity. float getX() const; @@ -29,7 +29,7 @@ namespace BBM //! @brief Create a new PositionComponent linked to a specific entity explicit PositionComponent(WAL::Entity &entity); //! @brief Create a new PositionComponent at a certain position - PositionComponent(WAL::Entity &entity, WAL::Vector3f pos); + PositionComponent(WAL::Entity &entity, Vector3f pos); //! @brief Create a new PositionComponent at a certain position PositionComponent(WAL::Entity &entity, float x, float y, float z); //! @brief A position component is copy constructable diff --git a/sources/System/Movable/MovableSystem.cpp b/sources/System/Movable/MovableSystem.cpp index 34d5b300..5b57ebba 100644 --- a/sources/System/Movable/MovableSystem.cpp +++ b/sources/System/Movable/MovableSystem.cpp @@ -23,6 +23,6 @@ namespace BBM position.position += movable._velocity * WAL::Wal::timestep.count(); movable._velocity = movable._acceleration * WAL::Wal::timestep.count(); - movable._acceleration = WAL::Vector3f(); + movable._acceleration = Vector3f(); } } // namespace WAL \ No newline at end of file diff --git a/sources/main.cpp b/sources/main.cpp index aa9c8d8f..26274f6c 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -24,6 +24,7 @@ #include "Vector/Vector3.hpp" #include "Window.hpp" #include "TraceLog.hpp" +#include "Wal.hpp" const std::vectortextures = { "black", "blue", "pink", "red", "white", "yellow" From 8a9a5bb32c1314b77a5a8c45637f8e572f8b572c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 15:18:44 +0200 Subject: [PATCH 08/24] adding a screen renderer system --- CMakeLists.txt | 6 +-- .../System/Renderer/RenderScreenSystem.hpp | 50 +++++++++++++++++++ sources/main.cpp | 28 ++--------- tests/EntityTests.cpp | 1 - 4 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 sources/System/Renderer/RenderScreenSystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f93d13f..80ec4ef1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,9 @@ set(SOURCES ) add_executable(bomberman - sources/main.cpp - ${SOURCES} -) + sources/main.cpp + ${SOURCES} + sources/System/Renderer/RenderScreenSystem.hpp) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/sources/System/Renderer/RenderScreenSystem.hpp b/sources/System/Renderer/RenderScreenSystem.hpp new file mode 100644 index 00000000..b2e30e1b --- /dev/null +++ b/sources/System/Renderer/RenderScreenSystem.hpp @@ -0,0 +1,50 @@ +// +// Created by cbihan on 26/05/2021. +// + +#pragma once + +#include "System/System.hpp" +#include "Camera/Camera2D.hpp" +#include "Window.hpp" + +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({typeid(RenderScreenSystem)}), + _window(window), + _camera(camera) + { + } + + //! @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->_camera.update(); + this->_window.setDrawingState(RAY::Window::DRAWING); + this->_window.clear(); + this->_window.useCamera(_camera); + } + + //! @brief Default copy ctor + RenderScreenSystem(const RenderScreenSystem &) = delete; + //! @brief Default dtor + ~RenderScreenSystem() override = default; + //! @brief Default assignment operator + RenderScreenSystem &operator=(const RenderScreenSystem &) = delete; + + }; + +} diff --git a/sources/main.cpp b/sources/main.cpp index 26274f6c..340e6942 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -21,6 +21,7 @@ #include "Model/ModelAnimations.hpp" #include "System/Renderer/Renderer3DSystem.hpp" #include "Component/Drawable/Drawable3DComponent.hpp" +#include "System/Renderer/RenderScreenSystem.hpp" #include "Vector/Vector3.hpp" #include "Window.hpp" #include "TraceLog.hpp" @@ -64,6 +65,8 @@ int demo() BBM::Renderer3DSystem circleSystem(window); + BBM::RenderScreenSystem renderSystem(window, camera); + wal.addSystem(circleSystem); entityPlayer.addComponent(circleComponent); @@ -80,30 +83,7 @@ int demo() float y_rotation = 0; window.setFPS(60); - while (!window.shouldClose()) - { - camera.update(); - - if (RAY::Controller::Keyboard::isReleased(KEY_SPACE)) - { - ++iterator; - if (iterator == textures.end()) - iterator = textures.begin(); - texture.unload(); - texture.load(get_full_path(*iterator)); - model.setTextureToMaterial(MAP_DIFFUSE, texture); - //animations[0].incrementFrameCounter(); - //model.setAnimation(animations[0]); - } - window.setDrawingState(RAY::Window::DRAWING); - window.clear(); - window.useCamera(camera); - window.draw(model, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 5.0f, 5.0f, 5.0f )); - window.draw(grid); - window.unuseCamera(); - window.draw(instructionText); - window.setDrawingState(RAY::Window::IDLE); - } + //wal.run(); window.close(); diff --git a/tests/EntityTests.cpp b/tests/EntityTests.cpp index 5e1edb86..f58fd0c1 100644 --- a/tests/EntityTests.cpp +++ b/tests/EntityTests.cpp @@ -6,7 +6,6 @@ #include "Component/Position/PositionComponent.hpp" #include -using namespace BBM; using namespace WAL; using namespace BBM; From 2841ba5d6bccf530c6e49997e2f4d4e947f78e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 15:22:51 +0200 Subject: [PATCH 09/24] compiling but renderer doesn't render --- sources/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/main.cpp b/sources/main.cpp index 340e6942..7e8879c8 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -60,7 +60,7 @@ int demo() 45.0f, CAMERA_PERSPECTIVE ); WAL::Entity entityPlayer("roger"); - RAY::Drawables::Drawables3D::Circle circle({300, 300, 300}, 50, 0XFFFFFFF, {0, 0, 0}, 0); + RAY::Drawables::Drawables3D::Circle circle({30, 30, 30}, 50, 0XFFFFFFF, {0, 0, 0}, 0); BBM::Drawable3DComponent circleComponent(entityPlayer, circle); BBM::Renderer3DSystem circleSystem(window); @@ -83,7 +83,7 @@ int demo() float y_rotation = 0; window.setFPS(60); - //wal.run(); + wal.run([](WAL::Wal &wal, int) {}); window.close(); From 16f18c406d9f1984bfa75525105879e8b05b2f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 15:36:08 +0200 Subject: [PATCH 10/24] still some issues with drawable3D component --- sources/System/Renderer/RenderScreenSystem.hpp | 6 +++--- sources/System/Renderer/Renderer3DSystem.hpp | 3 ++- sources/main.cpp | 17 ++++------------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/sources/System/Renderer/RenderScreenSystem.hpp b/sources/System/Renderer/RenderScreenSystem.hpp index b2e30e1b..9549133d 100644 --- a/sources/System/Renderer/RenderScreenSystem.hpp +++ b/sources/System/Renderer/RenderScreenSystem.hpp @@ -19,7 +19,7 @@ namespace BBM T &_camera; public: //! @brief ctor - explicit RenderScreenSystem(RAY::Window &window, T camera) + explicit RenderScreenSystem(RAY::Window &window, T &camera) : WAL::System({typeid(RenderScreenSystem)}), _window(window), _camera(camera) @@ -39,11 +39,11 @@ namespace BBM } //! @brief Default copy ctor - RenderScreenSystem(const RenderScreenSystem &) = delete; + RenderScreenSystem(const RenderScreenSystem &) = default; //! @brief Default dtor ~RenderScreenSystem() override = default; //! @brief Default assignment operator - RenderScreenSystem &operator=(const RenderScreenSystem &) = delete; + RenderScreenSystem &operator=(const RenderScreenSystem &) = default; }; diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index 8478d320..099a7c57 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -30,8 +30,9 @@ namespace BBM //! @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 dtime) override + void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override { + std::cout << "Drawing: " << typeid(T).name() << std::endl; auto &comp = entity.getComponent>(); auto &pos = entity.getComponent(); diff --git a/sources/main.cpp b/sources/main.cpp index 7e8879c8..f1725a1a 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -45,15 +45,11 @@ int demo() WAL::Wal wal; const int screenWidth = 800; const int screenHeight = 450; - auto iterator = textures.begin(); - const std::string modelPath = "assets/player/player.obj"; - const std::string texturePath = "assets/player/blue.png"; - //const std::string animationPath = "assets/guy.iqm"; + 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::Model model(modelPath); 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), @@ -62,21 +58,16 @@ int demo() WAL::Entity entityPlayer("roger"); RAY::Drawables::Drawables3D::Circle circle({30, 30, 30}, 50, 0XFFFFFFF, {0, 0, 0}, 0); BBM::Drawable3DComponent circleComponent(entityPlayer, circle); + BBM::PositionComponent posComponent(entityPlayer, {20, 20, 20}); BBM::Renderer3DSystem circleSystem(window); BBM::RenderScreenSystem renderSystem(window, camera); wal.addSystem(circleSystem); + wal.addSystem(renderSystem); entityPlayer.addComponent(circleComponent); - - RAY::Texture texture(get_full_path(*iterator)); - //RAY::ModelAnimations animations(modelPath); - RAY::Drawables::Drawables3D::Grid grid(10, 1.0f); - RAY::Drawables::Drawables2D::Text instructionText("PRESS SPACE to PLAY MODEL ANIMATION", 10, {10, 20} , MAROON); - model.setTextureToMaterial(MAP_DIFFUSE, texture); - - RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position + entityPlayer.addComponent(posComponent); camera.setMode(CAMERA_FREE); // Set free camera mode From 214b9a467446b4aa13d8ebacbcda7e39d62f06ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 15:43:42 +0200 Subject: [PATCH 11/24] systems whould work but i don't know how to put my entity in a scene --- .../System/Renderer/RenderScreenSystem.hpp | 1 + sources/main.cpp | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/sources/System/Renderer/RenderScreenSystem.hpp b/sources/System/Renderer/RenderScreenSystem.hpp index 9549133d..bcb83a13 100644 --- a/sources/System/Renderer/RenderScreenSystem.hpp +++ b/sources/System/Renderer/RenderScreenSystem.hpp @@ -30,6 +30,7 @@ namespace BBM //! @note render on screen here void onSelfUpdate() override { + std::cout << "render" << std::endl; this->_window.unuseCamera(); this->_window.setDrawingState(RAY::Window::IDLE); this->_camera.update(); diff --git a/sources/main.cpp b/sources/main.cpp index f1725a1a..f6041ccd 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -78,6 +78,73 @@ int demo() window.close(); + /* + * const int screenWidth = 800; + const int screenHeight = 450; + auto iterator = textures.begin(); + const std::string modelPath = "assets/player/player.obj"; + const std::string texturePath = "assets/player/blue.png"; + //const std::string animationPath = "assets/guy.iqm"; + 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::Model model(modelPath); + 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 + ); + WAL::Entity entityPlayer("roger"); + RAY::Drawables::Drawables3D::Circle circle({300, 300, 300}, 50, 0XFFFFFFF, {0, 0, 0}, 0); + BBM::Drawable3DComponent circleComponent(entityPlayer, circle); + + BBM::Renderer3DSystem circleSystem(window); + + wal.addSystem(circleSystem); + entityPlayer.addComponent(circleComponent); + + RAY::Texture texture(get_full_path(*iterator)); + //RAY::ModelAnimations animations(modelPath); + RAY::Drawables::Drawables3D::Grid grid(10, 1.0f); + RAY::Drawables::Drawables2D::Text instructionText("PRESS SPACE to PLAY MODEL ANIMATION", 10, {10, 20} , MAROON); + model.setTextureToMaterial(MAP_DIFFUSE, texture); + + RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position + + camera.setMode(CAMERA_FREE); // Set free camera mode + + float y_rotation = 0; + window.setFPS(60); + + while (!window.shouldClose()) + { + camera.update(); + + if (RAY::Controller::Keyboard::isReleased(KEY_SPACE)) + { + ++iterator; + if (iterator == textures.end()) + iterator = textures.begin(); + texture.unload(); + texture.load(get_full_path(*iterator)); + model.setTextureToMaterial(MAP_DIFFUSE, texture); + //animations[0].incrementFrameCounter(); + //model.setAnimation(animations[0]); + } + window.setDrawingState(RAY::Window::DRAWING); + window.clear(); + window.useCamera(camera); + window.draw(model, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 5.0f, 5.0f, 5.0f )); + window.draw(grid); + window.unuseCamera(); + window.draw(instructionText); + window.setDrawingState(RAY::Window::IDLE); + } + + window.close(); + */ + return 0; } From c12ecf6d8bf41b6c5f16ce7bc55ba8409689dee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 16:24:43 +0200 Subject: [PATCH 12/24] renderers seems to work --- lib/wal/sources/Wal.hpp | 2 +- .../System/Renderer/RenderScreenSystem.hpp | 1 - sources/System/Renderer/Renderer3DSystem.hpp | 1 - sources/main.cpp | 24 +++++++++++++------ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/wal/sources/Wal.hpp b/lib/wal/sources/Wal.hpp index c7c02e9d..036c1787 100644 --- a/lib/wal/sources/Wal.hpp +++ b/lib/wal/sources/Wal.hpp @@ -20,7 +20,7 @@ namespace WAL //! @brief The main WAL class, it is used to setup and run the ECS. class Wal { - private: + public: //! @brief The scene manager that allow multiple scene to work together. Scene _scene; //! @brief The list of registered systems diff --git a/sources/System/Renderer/RenderScreenSystem.hpp b/sources/System/Renderer/RenderScreenSystem.hpp index bcb83a13..9549133d 100644 --- a/sources/System/Renderer/RenderScreenSystem.hpp +++ b/sources/System/Renderer/RenderScreenSystem.hpp @@ -30,7 +30,6 @@ namespace BBM //! @note render on screen here void onSelfUpdate() override { - std::cout << "render" << std::endl; this->_window.unuseCamera(); this->_window.setDrawingState(RAY::Window::IDLE); this->_camera.update(); diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index 099a7c57..bb345b42 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -32,7 +32,6 @@ namespace BBM //! @param dtime The delta time. void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override { - std::cout << "Drawing: " << typeid(T).name() << std::endl; auto &comp = entity.getComponent>(); auto &pos = entity.getComponent(); diff --git a/sources/main.cpp b/sources/main.cpp index f6041ccd..59318fc1 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -17,6 +17,8 @@ #include "Drawables/3D/Grid.hpp" #include "Drawables/Texture.hpp" #include "Drawables/3D/Circle.hpp" +#include "Drawables/3D/Cube.hpp" +#include "Drawables/3D/Sphere.hpp" #include "Model/Model.hpp" #include "Model/ModelAnimations.hpp" #include "System/Renderer/Renderer3DSystem.hpp" @@ -56,18 +58,24 @@ int demo() 45.0f, CAMERA_PERSPECTIVE ); WAL::Entity entityPlayer("roger"); - RAY::Drawables::Drawables3D::Circle circle({30, 30, 30}, 50, 0XFFFFFFF, {0, 0, 0}, 0); + RAY::Drawables::Drawables3D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0); + RAY::Drawables::Drawables3D::Cube cube({0, 0, 0}, {2, 2, 2}, BLUE); BBM::Drawable3DComponent circleComponent(entityPlayer, circle); - BBM::PositionComponent posComponent(entityPlayer, {20, 20, 20}); + BBM::Drawable3DComponent cubeComponent(entityPlayer, cube); + BBM::PositionComponent posComponent(entityPlayer, {0, 0, 0}); BBM::Renderer3DSystem circleSystem(window); + BBM::Renderer3DSystem cubeSystem(window); BBM::RenderScreenSystem renderSystem(window, camera); 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 @@ -78,8 +86,9 @@ int demo() window.close(); - /* - * const int screenWidth = 800; + +/* + const int screenWidth = 800; const int screenHeight = 450; auto iterator = textures.begin(); const std::string modelPath = "assets/player/player.obj"; @@ -96,7 +105,7 @@ int demo() 45.0f, CAMERA_PERSPECTIVE ); WAL::Entity entityPlayer("roger"); - RAY::Drawables::Drawables3D::Circle circle({300, 300, 300}, 50, 0XFFFFFFF, {0, 0, 0}, 0); + RAY::Drawables::Drawables3D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0); BBM::Drawable3DComponent circleComponent(entityPlayer, circle); BBM::Renderer3DSystem circleSystem(window); @@ -137,13 +146,14 @@ int demo() window.useCamera(camera); window.draw(model, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 5.0f, 5.0f, 5.0f )); window.draw(grid); + window.draw(circle); window.unuseCamera(); window.draw(instructionText); window.setDrawingState(RAY::Window::IDLE); } - +*/ window.close(); - */ + return 0; } 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 13/24] 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 From 7da7e50f6814b423587e2ddbd3955b145349e4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 16:50:52 +0200 Subject: [PATCH 14/24] using the utils function (BBM vector3 -> RAY vector3) --- CMakeLists.txt | 3 ++- sources/System/Renderer/Renderer3DSystem.hpp | 3 ++- sources/Util/{vector.cpp => Utils.cpp} | 8 +++++-- sources/Util/Utils.hpp | 25 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) rename sources/Util/{vector.cpp => Utils.cpp} (50%) create mode 100644 sources/Util/Utils.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 80ec4ef1..241eb737 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,12 +25,13 @@ set(SOURCES sources/Component/Drawable/Drawable2DComponent.hpp sources/System/Renderer/Renderer3DSystem.hpp sources/System/Renderer/Renderer2DSystem.hpp + sources/Util/Utils.cpp ) add_executable(bomberman sources/main.cpp ${SOURCES} - sources/System/Renderer/RenderScreenSystem.hpp) + sources/System/Renderer/RenderScreenSystem.hpp sources/Util/Utils.hpp) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index bb345b42..fe813318 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -9,6 +9,7 @@ #include "Entity/Entity.hpp" #include "Component/Position/PositionComponent.hpp" #include "Component/Drawable/Drawable3DComponent.hpp" +#include "Util/Utils.hpp" #include "Window.hpp" namespace BBM @@ -35,7 +36,7 @@ namespace BBM auto &comp = entity.getComponent>(); auto &pos = entity.getComponent(); - comp.member.setPosition({pos.getX(), pos.getY(), pos.getZ()}); + comp.member.setPosition(Utils::toRAY(pos.position)); comp.member.drawOn(this->_window); } diff --git a/sources/Util/vector.cpp b/sources/Util/Utils.cpp similarity index 50% rename from sources/Util/vector.cpp rename to sources/Util/Utils.cpp index ff4c15e9..eba97447 100644 --- a/sources/Util/vector.cpp +++ b/sources/Util/Utils.cpp @@ -7,8 +7,12 @@ #include "Vector/Vector3.hpp" #include "Models/Vector3.hpp" +#include "Utils.hpp" -RAY::Vector3 toRAY(const WAL::Vector3f &wal) +namespace BBM { - return RAY::Vector3(wal.x, wal.y, wal.y); + RAY::Vector3 Utils::toRAY(const BBM::Vector3f &wal) + { + return RAY::Vector3(wal.x, wal.y, wal.y); + } } \ No newline at end of file diff --git a/sources/Util/Utils.hpp b/sources/Util/Utils.hpp new file mode 100644 index 00000000..d2678a7c --- /dev/null +++ b/sources/Util/Utils.hpp @@ -0,0 +1,25 @@ +// +// Created by cbihan on 26/05/2021. +// + +#pragma once + +#include "Vector/Vector3.hpp" +#include "Models/Vector3.hpp" + +namespace BBM +{ + struct Utils + { + static RAY::Vector3 toRAY(const BBM::Vector3f &wal); + + //! @brief default ctor + Utils() = default; + //! @brief Default copy ctor + Utils(const Utils &) = default; + //! @brief Default dtor + ~Utils() = default; + //! @brief Default assignment operator + Utils &operator=(const Utils &) = default; + }; +} \ No newline at end of file From 0000136381a213c7f19bbe35c42c6a5fdc2bde39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 16:54:58 +0200 Subject: [PATCH 15/24] quick cleanup --- CMakeLists.txt | 4 +++- lib/Ray/sources/Drawables/IDrawable.hpp | 4 ++-- sources/Util/Utils.hpp | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 241eb737..75052c49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,12 +26,14 @@ set(SOURCES sources/System/Renderer/Renderer3DSystem.hpp sources/System/Renderer/Renderer2DSystem.hpp sources/Util/Utils.cpp + sources/System/Renderer/RenderScreenSystem.hpp + sources/Util/Utils.hpp ) add_executable(bomberman sources/main.cpp ${SOURCES} - sources/System/Renderer/RenderScreenSystem.hpp sources/Util/Utils.hpp) + ) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/lib/Ray/sources/Drawables/IDrawable.hpp b/lib/Ray/sources/Drawables/IDrawable.hpp index 377adee6..7063dd06 100644 --- a/lib/Ray/sources/Drawables/IDrawable.hpp +++ b/lib/Ray/sources/Drawables/IDrawable.hpp @@ -19,10 +19,10 @@ namespace RAY public: virtual ~IDrawable() = default; - virtual void drawOn(Window &) = 0; + virtual void drawOn(RAY::Window &) = 0; protected: private: - }; + };p } } diff --git a/sources/Util/Utils.hpp b/sources/Util/Utils.hpp index d2678a7c..8dd71fe0 100644 --- a/sources/Util/Utils.hpp +++ b/sources/Util/Utils.hpp @@ -11,8 +11,9 @@ namespace BBM { struct Utils { + //! @brief Convert BBM Vector3f to RAY Vector3 static RAY::Vector3 toRAY(const BBM::Vector3f &wal); - +p //! @brief default ctor Utils() = default; //! @brief Default copy ctor From 1ca134176ac28f1a82701cf77afe89ab88cf686a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 16:59:21 +0200 Subject: [PATCH 16/24] oups --- lib/Ray/sources/Drawables/IDrawable.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Ray/sources/Drawables/IDrawable.hpp b/lib/Ray/sources/Drawables/IDrawable.hpp index 7063dd06..9e3b403b 100644 --- a/lib/Ray/sources/Drawables/IDrawable.hpp +++ b/lib/Ray/sources/Drawables/IDrawable.hpp @@ -22,7 +22,7 @@ namespace RAY virtual void drawOn(RAY::Window &) = 0; protected: private: - };p + }; } } From 8cdae3a3fc77717001f174a92faa7aa19b229054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 17:00:54 +0200 Subject: [PATCH 17/24] oups x2 --- sources/Util/Utils.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/Util/Utils.hpp b/sources/Util/Utils.hpp index 8dd71fe0..51c6b1cb 100644 --- a/sources/Util/Utils.hpp +++ b/sources/Util/Utils.hpp @@ -13,7 +13,7 @@ namespace BBM { //! @brief Convert BBM Vector3f to RAY Vector3 static RAY::Vector3 toRAY(const BBM::Vector3f &wal); -p + //! @brief default ctor Utils() = default; //! @brief Default copy ctor From 864e75c5550d53b48d79def44785c23f621b7169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 17:07:43 +0200 Subject: [PATCH 18/24] first pr reviews fixes --- sources/System/Movable/MovableSystem.hpp | 2 +- sources/System/Renderer/RenderScreenSystem.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/System/Movable/MovableSystem.hpp b/sources/System/Movable/MovableSystem.hpp index 62c69ddb..51a56ea9 100644 --- a/sources/System/Movable/MovableSystem.hpp +++ b/sources/System/Movable/MovableSystem.hpp @@ -11,7 +11,7 @@ namespace BBM { //! @brief A system to handle movable entities. This system update velocity based on accelerations and positions based on velocity. -class MovableSystem : public WAL::System + class MovableSystem : public WAL::System { public: //! @inherit diff --git a/sources/System/Renderer/RenderScreenSystem.hpp b/sources/System/Renderer/RenderScreenSystem.hpp index 9549133d..d5074d1d 100644 --- a/sources/System/Renderer/RenderScreenSystem.hpp +++ b/sources/System/Renderer/RenderScreenSystem.hpp @@ -20,7 +20,7 @@ namespace BBM public: //! @brief ctor explicit RenderScreenSystem(RAY::Window &window, T &camera) - : WAL::System({typeid(RenderScreenSystem)}), + : WAL::System({}), _window(window), _camera(camera) { From e70dbd5b3b428d516d2e190c2e117f6eed62b01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 17:21:01 +0200 Subject: [PATCH 19/24] adding operator* for vector3f to please ZOE the tyrant --- CMakeLists.txt | 2 +- sources/Models/Vector3.cpp | 13 +++++++++++++ sources/Models/Vector3.hpp | 8 +++++++- sources/System/Renderer/Renderer3DSystem.hpp | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 sources/Models/Vector3.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 75052c49..dc167f05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ set(SOURCES add_executable(bomberman sources/main.cpp ${SOURCES} - ) + sources/Models/Vector3.cpp) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/sources/Models/Vector3.cpp b/sources/Models/Vector3.cpp new file mode 100644 index 00000000..d46f5ca9 --- /dev/null +++ b/sources/Models/Vector3.cpp @@ -0,0 +1,13 @@ +// +// Created by cbihan on 26/05/2021. +// + +#include "Vector3.hpp" + +namespace BBM +{ + RAY::Vector3 operator*(const Vector3f &v) + { + return {v.x, v.y, v.z}; + } +} \ No newline at end of file diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index 81a61cf3..0edd7a64 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -7,6 +7,7 @@ #include #include +#include "Vector/Vector3.hpp" namespace BBM { @@ -157,7 +158,12 @@ namespace BBM typedef Vector3 Vector3f; typedef Vector3 Vector3u; typedef Vector3 Vector3i; -} // namespace WAL + + RAY::Vector3 operator*(const Vector3f &v); +} + + + template std::ostream &operator<<(std::ostream &s, const BBM::Vector3 &v) diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index fe813318..cc376e61 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -36,7 +36,7 @@ namespace BBM auto &comp = entity.getComponent>(); auto &pos = entity.getComponent(); - comp.member.setPosition(Utils::toRAY(pos.position)); + comp.member.setPosition(*pos.position); comp.member.drawOn(this->_window); } From c3c6f1503cee5b62ee5994e774a71320021067b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 18:01:51 +0200 Subject: [PATCH 20/24] rm unwanted actions (update cam) --- lib/Ray/sources/Camera/Camera3D.cpp | 2 +- sources/System/Renderer/RenderScreenSystem.hpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Ray/sources/Camera/Camera3D.cpp b/lib/Ray/sources/Camera/Camera3D.cpp index 2482df6e..aa2b2a9b 100644 --- a/lib/Ray/sources/Camera/Camera3D.cpp +++ b/lib/Ray/sources/Camera/Camera3D.cpp @@ -80,4 +80,4 @@ void RAY::Camera::Camera3D::update(void) RAY::Camera::Camera3D::operator ::Camera3D() const { return this->_camera; -} +} \ No newline at end of file diff --git a/sources/System/Renderer/RenderScreenSystem.hpp b/sources/System/Renderer/RenderScreenSystem.hpp index d5074d1d..04f8e5e2 100644 --- a/sources/System/Renderer/RenderScreenSystem.hpp +++ b/sources/System/Renderer/RenderScreenSystem.hpp @@ -32,7 +32,6 @@ namespace BBM { this->_window.unuseCamera(); this->_window.setDrawingState(RAY::Window::IDLE); - this->_camera.update(); this->_window.setDrawingState(RAY::Window::DRAWING); this->_window.clear(); this->_window.useCamera(_camera); @@ -44,7 +43,6 @@ namespace BBM ~RenderScreenSystem() override = default; //! @brief Default assignment operator RenderScreenSystem &operator=(const RenderScreenSystem &) = default; - }; } From 6bd7a46ea978636174595209c16c3a0b4e942f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 18:36:26 +0200 Subject: [PATCH 21/24] rm Utils class --- CMakeLists.txt | 2 -- sources/System/Renderer/Renderer3DSystem.hpp | 1 - sources/Util/Utils.cpp | 18 -------------- sources/Util/Utils.hpp | 26 -------------------- 4 files changed, 47 deletions(-) delete mode 100644 sources/Util/Utils.cpp delete mode 100644 sources/Util/Utils.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index dc167f05..42a2ad8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,7 @@ set(SOURCES sources/Component/Drawable/Drawable2DComponent.hpp sources/System/Renderer/Renderer3DSystem.hpp sources/System/Renderer/Renderer2DSystem.hpp - sources/Util/Utils.cpp sources/System/Renderer/RenderScreenSystem.hpp - sources/Util/Utils.hpp ) add_executable(bomberman diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index cc376e61..7e221edc 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -9,7 +9,6 @@ #include "Entity/Entity.hpp" #include "Component/Position/PositionComponent.hpp" #include "Component/Drawable/Drawable3DComponent.hpp" -#include "Util/Utils.hpp" #include "Window.hpp" namespace BBM diff --git a/sources/Util/Utils.cpp b/sources/Util/Utils.cpp deleted file mode 100644 index eba97447..00000000 --- a/sources/Util/Utils.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* -** EPITECH PROJECT, 2021 -** Bomberman -** File description: -** Vector -*/ - -#include "Vector/Vector3.hpp" -#include "Models/Vector3.hpp" -#include "Utils.hpp" - -namespace BBM -{ - RAY::Vector3 Utils::toRAY(const BBM::Vector3f &wal) - { - return RAY::Vector3(wal.x, wal.y, wal.y); - } -} \ No newline at end of file diff --git a/sources/Util/Utils.hpp b/sources/Util/Utils.hpp deleted file mode 100644 index 51c6b1cb..00000000 --- a/sources/Util/Utils.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// -// Created by cbihan on 26/05/2021. -// - -#pragma once - -#include "Vector/Vector3.hpp" -#include "Models/Vector3.hpp" - -namespace BBM -{ - struct Utils - { - //! @brief Convert BBM Vector3f to RAY Vector3 - static RAY::Vector3 toRAY(const BBM::Vector3f &wal); - - //! @brief default ctor - Utils() = default; - //! @brief Default copy ctor - Utils(const Utils &) = default; - //! @brief Default dtor - ~Utils() = default; - //! @brief Default assignment operator - Utils &operator=(const Utils &) = default; - }; -} \ No newline at end of file From 07e2d5bc35aadd0db4cf31ef5a71ac19f06a42c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 18:40:18 +0200 Subject: [PATCH 22/24] adding a true user-defined conversion operator --- CMakeLists.txt | 3 +-- sources/Models/Vector3.hpp | 4 +++- sources/System/Renderer/Renderer3DSystem.hpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42a2ad8b..4efd04dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,7 @@ set(SOURCES add_executable(bomberman sources/main.cpp - ${SOURCES} - sources/Models/Vector3.cpp) + ${SOURCES}) target_include_directories(bomberman PUBLIC sources) target_link_libraries(bomberman PUBLIC wal ray) diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index 0edd7a64..c35891f8 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -153,13 +153,15 @@ namespace BBM { return (point * this) / std::pow(this->magnitude(), 2) * this; } + + explicit operator RAY::Vector3() const { return {this->x, this->y, this->z };} }; typedef Vector3 Vector3f; typedef Vector3 Vector3u; typedef Vector3 Vector3i; - RAY::Vector3 operator*(const Vector3f &v); + } diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index 7e221edc..dd55e584 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -35,7 +35,7 @@ namespace BBM auto &comp = entity.getComponent>(); auto &pos = entity.getComponent(); - comp.member.setPosition(*pos.position); + comp.member.setPosition(static_cast(pos.position)); comp.member.drawOn(this->_window); } From dee8c554c3aa05d486c0b85008fdc816e5564cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 26 May 2021 18:42:18 +0200 Subject: [PATCH 23/24] delete Vector3.cpp and rm trailing space --- sources/Models/Vector3.cpp | 13 ------------- sources/Models/Vector3.hpp | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 sources/Models/Vector3.cpp diff --git a/sources/Models/Vector3.cpp b/sources/Models/Vector3.cpp deleted file mode 100644 index d46f5ca9..00000000 --- a/sources/Models/Vector3.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// Created by cbihan on 26/05/2021. -// - -#include "Vector3.hpp" - -namespace BBM -{ - RAY::Vector3 operator*(const Vector3f &v) - { - return {v.x, v.y, v.z}; - } -} \ No newline at end of file diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index c35891f8..93327c70 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -154,7 +154,7 @@ namespace BBM return (point * this) / std::pow(this->magnitude(), 2) * this; } - explicit operator RAY::Vector3() const { return {this->x, this->y, this->z };} + explicit operator RAY::Vector3() const { return {this->x, this->y, this->z};} }; typedef Vector3 Vector3f; From d69a4f8ee246a8d4dd93f859eed050b7fb4ec0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Thu, 27 May 2021 12:01:43 +0200 Subject: [PATCH 24/24] delete Vector3.cpp and rm trailing space --- sources/System/Renderer/Renderer2DSystem.hpp | 2 +- sources/main.cpp | 26 +++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/sources/System/Renderer/Renderer2DSystem.hpp b/sources/System/Renderer/Renderer2DSystem.hpp index 0008c1a0..59518e68 100644 --- a/sources/System/Renderer/Renderer2DSystem.hpp +++ b/sources/System/Renderer/Renderer2DSystem.hpp @@ -29,7 +29,7 @@ namespace BBM //! @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 dtime) override + void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override { auto &comp = entity.getComponent>(); auto &pos = entity.getComponent(); diff --git a/sources/main.cpp b/sources/main.cpp index 7e3c6416..8bdf948f 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -17,12 +17,15 @@ #include "Drawables/3D/Grid.hpp" #include "Drawables/Texture.hpp" #include "Drawables/3D/Circle.hpp" +#include "Drawables/2D/Circle.hpp" #include "Drawables/3D/Cube.hpp" #include "Drawables/3D/Sphere.hpp" #include "Model/Model.hpp" #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 "System/Renderer/RenderScreenSystem.hpp" #include "Vector/Vector3.hpp" #include "Window.hpp" @@ -57,23 +60,28 @@ int demo() 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::Drawables3D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0); - RAY::Drawables::Drawables3D::Cube cube({0, 0, 0}, {2, 2, 2}, BLUE); - BBM::Drawable3DComponent circleComponent(entityPlayer, circle); - BBM::Drawable3DComponent cubeComponent(entityPlayer, cube); + //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::Renderer3DSystem circleSystem(window); - BBM::Renderer3DSystem cubeSystem(window); + BBM::Renderer2DSystem circleSystem(window); + //BBM::Renderer3DSystem cubeSystem(window); - BBM::RenderScreenSystem renderSystem(window, camera); + BBM::RenderScreenSystem renderSystem(window, camera2D); wal.addSystem(circleSystem); wal.addSystem(renderSystem); - wal.addSystem(cubeSystem); + //wal.addSystem(cubeSystem); entityPlayer.addComponent(circleComponent); - entityPlayer.addComponent(cubeComponent); + //entityPlayer.addComponent(cubeComponent); entityPlayer.addComponent(posComponent); wal.scene.addEntity(entityPlayer);