From e9e389374bb39a03474013e0e6190713322cec2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 16 Jun 2021 10:30:10 +0200 Subject: [PATCH] adding lonely option for shaders and adding a BombExplosionShaderComponent.cpp to save data --- CMakeLists.txt | 262 +++++++++--------- assets/shaders/mask.vs | 6 +- lib/Ray/sources/Shaders/Shaders.cpp | 4 +- lib/Ray/sources/Shaders/Shaders.hpp | 2 +- lib/Ray/sources/Utils/Cache.hpp | 25 +- .../Items/BombExplosionShaderComponent.cpp | 19 ++ .../Items/BombExplosionShaderComponent.hpp | 44 +++ sources/Component/Shaders/ShaderComponent.cpp | 15 +- sources/Component/Shaders/ShaderComponent.hpp | 9 +- .../System/BombHolder/BombHolderSystem.cpp | 22 +- 10 files changed, 248 insertions(+), 160 deletions(-) create mode 100644 sources/Component/Shaders/Items/BombExplosionShaderComponent.cpp create mode 100644 sources/Component/Shaders/Items/BombExplosionShaderComponent.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e422e18..a180e9b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,137 +18,137 @@ if (EMSCRIPTEN) endif () set(SOURCES - sources/Models/GameState.hpp - sources/Runner/Runner.cpp - sources/Runner/Runner.hpp - sources/Map/Map.cpp - sources/Map/Map.hpp - sources/Items/Bonus.cpp - sources/Items/Bonus.hpp - sources/Component/Position/PositionComponent.cpp - sources/Component/Position/PositionComponent.hpp - sources/Component/Movable/MovableComponent.cpp - sources/Component/Movable/MovableComponent.hpp - sources/Component/Controllable/ControllableComponent.hpp - sources/Component/Controllable/ControllableComponent.cpp - sources/Component/BombHolder/BombHolderComponent.cpp - sources/Component/BombHolder/BombHolderComponent.hpp - sources/Component/Gamepad/GamepadComponent.cpp - sources/Component/Gamepad/GamepadComponent.hpp - sources/Component/Keyboard/KeyboardComponent.cpp - sources/Component/Keyboard/KeyboardComponent.hpp - sources/Component/Health/HealthComponent.cpp - sources/Component/Health/HealthComponent.hpp - sources/System/Movable/MovableSystem.hpp - sources/System/Movable/MovableSystem.cpp - sources/System/Controllable/ControllableSystem.cpp - sources/System/Controllable/ControllableSystem.hpp - sources/System/Gamepad/GamepadSystem.cpp - sources/System/Gamepad/GamepadSystem.hpp - sources/System/Health/HealthSystem.cpp - sources/System/Health/HealthSystem.hpp - sources/System/Keyboard/KeyboardSystem.cpp - sources/System/Keyboard/KeyboardSystem.hpp - sources/System/Movable/MovableSystem.cpp - sources/System/Movable/MovableSystem.hpp - sources/Models/Vector3.hpp - sources/Component/GridCentered/GridCenteredComponent.cpp - sources/Component/GridCentered/GridCenteredComponent.hpp - sources/System/GridCentered/GridCenteredSystem.cpp - sources/System/GridCentered/GridCenteredSystem.hpp - sources/Models/Vector2.hpp - sources/Component/Renderer/Drawable2DComponent.hpp - sources/Component/Renderer/Drawable3DComponent.hpp - sources/System/Renderer/RenderSystem.hpp - sources/System/Renderer/RenderSystem.cpp - sources/Component/Renderer/CameraComponent.cpp - sources/Component/Renderer/CameraComponent.hpp - sources/System/BombHolder/BombHolderSystem.cpp - sources/System/BombHolder/BombHolderSystem.hpp - sources/Component/Timer/TimerComponent.cpp - sources/Component/Timer/TimerComponent.hpp - sources/System/Timer/TimerSystem.cpp - sources/System/Timer/TimerSystem.hpp - sources/System/Event/EventSystem.cpp - sources/System/Event/EventSystem.hpp - sources/Component/Animation/AnimationsComponent.cpp - sources/Component/Animation/AnimationsComponent.hpp - sources/System/Animation/AnimationsSystem.cpp - sources/System/Animation/AnimationsSystem.hpp - sources/Component/Collision/CollisionComponent.cpp - sources/Component/Collision/CollisionComponent.hpp - sources/System/Collision/CollisionSystem.hpp - sources/System/Collision/CollisionSystem.cpp - sources/Component/Button/ButtonComponent.hpp - sources/System/MenuControllable/MenuControllableSystem.cpp - sources/System/MenuControllable/MenuControllableSystem.hpp - sources/System/Levitate/LevitateSystem.hpp - sources/System/Levitate/LevitateSystem.cpp - sources/Component/Levitate/LevitateComponent.cpp - sources/Component/Levitate/LevitateComponent.cpp - sources/Component/Animator/AnimatorComponent.cpp - sources/Component/Animator/AnimatorComponent.hpp - sources/System/Animator/AnimatorSystem.cpp - sources/System/Animator/AnimatorSystem.hpp - sources/Component/Shaders/ShaderComponent.cpp - sources/Component/Shaders/ShaderComponent.hpp - sources/Component/Bomb/BasicBombComponent.cpp - sources/Component/Bomb/BasicBombComponent.hpp - sources/Component/Bonus/PlayerBonusComponent.hpp - sources/Component/Bonus/PlayerBonusComponent.cpp - sources/System/Bonus/PlayerBonusSystem.hpp - sources/System/Bonus/PlayerBonusSystem.cpp - sources/Component/Tag/TagComponent.hpp - sources/Component/Music/MusicComponent.cpp - sources/Component/Music/MusicComponent.hpp - sources/Component/Sound/SoundComponent.hpp - sources/Component/Sound/SoundComponent.cpp - sources/System/Sound/MenuSoundManagerSystem.cpp - sources/System/Sound/MenuSoundManagerSystem.hpp - sources/System/Sound/PlayerSoundManagerSystem.cpp - sources/System/Sound/PlayerSoundManagerSystem.hpp - sources/System/Music/MusicSystem.hpp - sources/System/Music/MusicSystem.cpp - sources/System/Lobby/LobbySystem.cpp - sources/System/Lobby/LobbySystem.hpp - sources/Component/Lobby/LobbyComponent.cpp - sources/Component/Lobby/LobbyComponent.hpp - sources/Component/Gravity/GravityComponent.hpp - sources/Component/Gravity/GravityComponent.cpp - sources/System/Gravity/GravitySystem.hpp - sources/System/Gravity/GravitySystem.cpp - sources/Component/BumperTimer/BumperTimerComponent.hpp - sources/Component/BumperTimer/BumperTimerComponent.cpp - sources/System/BumperTimer/BumperTimerSystem.hpp - sources/System/BumperTimer/BumperTimerSystem.cpp - sources/System/Bomb/BombSystem.cpp - sources/System/Bomb/BombSystem.hpp - sources/Component/IntroAnimation/IntroAnimationComponent.hpp - sources/Component/IntroAnimation/IntroAnimationComponent.cpp - sources/System/IntroAnimation/IntroAnimationSystem.hpp - sources/System/IntroAnimation/IntroAnimationSystem.cpp - sources/Runner/SplashScreenScene.cpp - sources/Runner/TitleScreenScene.cpp - sources/Runner/MainMenuScene.cpp - sources/Runner/GameScene.cpp - sources/Runner/PauseMenuScene.cpp - sources/Runner/SettingsMenuScene.cpp - sources/Runner/CreditScene.cpp - sources/Component/Score/ScoreComponent.cpp - sources/Component/Score/ScoreComponent.hpp - sources/System/Score/ScoreSystem.cpp - sources/System/Score/ScoreSystem.hpp - sources/System/EndCondition/EndConditionSystem.hpp - sources/System/EndCondition/EndConditionSystem.cpp - sources/Runner/LobbyScene.cpp - sources/Runner/ScoreScene.cpp - sources/System/Shaders/ShaderSystem.cpp - sources/System/Shaders/ShaderSystem.hpp - sources/System/Shaders/ShaderModelSystem.cpp - sources/System/Shaders/ShaderModelSystem.hpp - sources/System/Shaders/ShaderDrawable2DSystem.cpp - sources/System/Shaders/ShaderDrawable2DSystem.hpp -) + sources/Models/GameState.hpp + sources/Runner/Runner.cpp + sources/Runner/Runner.hpp + sources/Map/Map.cpp + sources/Map/Map.hpp + sources/Items/Bonus.cpp + sources/Items/Bonus.hpp + sources/Component/Position/PositionComponent.cpp + sources/Component/Position/PositionComponent.hpp + sources/Component/Movable/MovableComponent.cpp + sources/Component/Movable/MovableComponent.hpp + sources/Component/Controllable/ControllableComponent.hpp + sources/Component/Controllable/ControllableComponent.cpp + sources/Component/BombHolder/BombHolderComponent.cpp + sources/Component/BombHolder/BombHolderComponent.hpp + sources/Component/Gamepad/GamepadComponent.cpp + sources/Component/Gamepad/GamepadComponent.hpp + sources/Component/Keyboard/KeyboardComponent.cpp + sources/Component/Keyboard/KeyboardComponent.hpp + sources/Component/Health/HealthComponent.cpp + sources/Component/Health/HealthComponent.hpp + sources/System/Movable/MovableSystem.hpp + sources/System/Movable/MovableSystem.cpp + sources/System/Controllable/ControllableSystem.cpp + sources/System/Controllable/ControllableSystem.hpp + sources/System/Gamepad/GamepadSystem.cpp + sources/System/Gamepad/GamepadSystem.hpp + sources/System/Health/HealthSystem.cpp + sources/System/Health/HealthSystem.hpp + sources/System/Keyboard/KeyboardSystem.cpp + sources/System/Keyboard/KeyboardSystem.hpp + sources/System/Movable/MovableSystem.cpp + sources/System/Movable/MovableSystem.hpp + sources/Models/Vector3.hpp + sources/Component/GridCentered/GridCenteredComponent.cpp + sources/Component/GridCentered/GridCenteredComponent.hpp + sources/System/GridCentered/GridCenteredSystem.cpp + sources/System/GridCentered/GridCenteredSystem.hpp + sources/Models/Vector2.hpp + sources/Component/Renderer/Drawable2DComponent.hpp + sources/Component/Renderer/Drawable3DComponent.hpp + sources/System/Renderer/RenderSystem.hpp + sources/System/Renderer/RenderSystem.cpp + sources/Component/Renderer/CameraComponent.cpp + sources/Component/Renderer/CameraComponent.hpp + sources/System/BombHolder/BombHolderSystem.cpp + sources/System/BombHolder/BombHolderSystem.hpp + sources/Component/Timer/TimerComponent.cpp + sources/Component/Timer/TimerComponent.hpp + sources/System/Timer/TimerSystem.cpp + sources/System/Timer/TimerSystem.hpp + sources/System/Event/EventSystem.cpp + sources/System/Event/EventSystem.hpp + sources/Component/Animation/AnimationsComponent.cpp + sources/Component/Animation/AnimationsComponent.hpp + sources/System/Animation/AnimationsSystem.cpp + sources/System/Animation/AnimationsSystem.hpp + sources/Component/Collision/CollisionComponent.cpp + sources/Component/Collision/CollisionComponent.hpp + sources/System/Collision/CollisionSystem.hpp + sources/System/Collision/CollisionSystem.cpp + sources/Component/Button/ButtonComponent.hpp + sources/System/MenuControllable/MenuControllableSystem.cpp + sources/System/MenuControllable/MenuControllableSystem.hpp + sources/System/Levitate/LevitateSystem.hpp + sources/System/Levitate/LevitateSystem.cpp + sources/Component/Levitate/LevitateComponent.cpp + sources/Component/Levitate/LevitateComponent.cpp + sources/Component/Animator/AnimatorComponent.cpp + sources/Component/Animator/AnimatorComponent.hpp + sources/System/Animator/AnimatorSystem.cpp + sources/System/Animator/AnimatorSystem.hpp + sources/Component/Shaders/ShaderComponent.cpp + sources/Component/Shaders/ShaderComponent.hpp + sources/Component/Bomb/BasicBombComponent.cpp + sources/Component/Bomb/BasicBombComponent.hpp + sources/Component/Bonus/PlayerBonusComponent.hpp + sources/Component/Bonus/PlayerBonusComponent.cpp + sources/System/Bonus/PlayerBonusSystem.hpp + sources/System/Bonus/PlayerBonusSystem.cpp + sources/Component/Tag/TagComponent.hpp + sources/Component/Music/MusicComponent.cpp + sources/Component/Music/MusicComponent.hpp + sources/Component/Sound/SoundComponent.hpp + sources/Component/Sound/SoundComponent.cpp + sources/System/Sound/MenuSoundManagerSystem.cpp + sources/System/Sound/MenuSoundManagerSystem.hpp + sources/System/Sound/PlayerSoundManagerSystem.cpp + sources/System/Sound/PlayerSoundManagerSystem.hpp + sources/System/Music/MusicSystem.hpp + sources/System/Music/MusicSystem.cpp + sources/System/Lobby/LobbySystem.cpp + sources/System/Lobby/LobbySystem.hpp + sources/Component/Lobby/LobbyComponent.cpp + sources/Component/Lobby/LobbyComponent.hpp + sources/Component/Gravity/GravityComponent.hpp + sources/Component/Gravity/GravityComponent.cpp + sources/System/Gravity/GravitySystem.hpp + sources/System/Gravity/GravitySystem.cpp + sources/Component/BumperTimer/BumperTimerComponent.hpp + sources/Component/BumperTimer/BumperTimerComponent.cpp + sources/System/BumperTimer/BumperTimerSystem.hpp + sources/System/BumperTimer/BumperTimerSystem.cpp + sources/System/Bomb/BombSystem.cpp + sources/System/Bomb/BombSystem.hpp + sources/Component/IntroAnimation/IntroAnimationComponent.hpp + sources/Component/IntroAnimation/IntroAnimationComponent.cpp + sources/System/IntroAnimation/IntroAnimationSystem.hpp + sources/System/IntroAnimation/IntroAnimationSystem.cpp + sources/Runner/SplashScreenScene.cpp + sources/Runner/TitleScreenScene.cpp + sources/Runner/MainMenuScene.cpp + sources/Runner/GameScene.cpp + sources/Runner/PauseMenuScene.cpp + sources/Runner/SettingsMenuScene.cpp + sources/Runner/CreditScene.cpp + sources/Component/Score/ScoreComponent.cpp + sources/Component/Score/ScoreComponent.hpp + sources/System/Score/ScoreSystem.cpp + sources/System/Score/ScoreSystem.hpp + sources/System/EndCondition/EndConditionSystem.hpp + sources/System/EndCondition/EndConditionSystem.cpp + sources/Runner/LobbyScene.cpp + sources/Runner/ScoreScene.cpp + sources/System/Shaders/ShaderSystem.cpp + sources/System/Shaders/ShaderSystem.hpp + sources/System/Shaders/ShaderModelSystem.cpp + sources/System/Shaders/ShaderModelSystem.hpp + sources/System/Shaders/ShaderDrawable2DSystem.cpp + sources/System/Shaders/ShaderDrawable2DSystem.hpp + sources/Component/Shaders/Items/BombExplosionShaderComponent.cpp sources/Component/Shaders/Items/BombExplosionShaderComponent.hpp) add_executable(bomberman sources/main.cpp ${SOURCES} diff --git a/assets/shaders/mask.vs b/assets/shaders/mask.vs index 58cb597e..f7a7bd38 100644 --- a/assets/shaders/mask.vs +++ b/assets/shaders/mask.vs @@ -89,9 +89,11 @@ attribute vec4 vertexColor; // Input uniform values uniform mat4 mvp; -uniform int frame; +uniform float frame; uniform vec3 center; +uniform float radius; + // Output vertex attributes (to fragment shader) varying vec3 fragPosition; @@ -101,6 +103,6 @@ void main() { // Send vertex attributes to fragment shader fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + vec3(frame))) * 0.5); // Calculate final vertex position - gl_Position = mvp * vec4(fragPosition , 1.0); + gl_Position = mvp * vec4(fragPosition , radius); //gl_Position = vec4(vertexNormal, 1.0); } \ No newline at end of file diff --git a/lib/Ray/sources/Shaders/Shaders.cpp b/lib/Ray/sources/Shaders/Shaders.cpp index 3e08f719..0def3c96 100644 --- a/lib/Ray/sources/Shaders/Shaders.cpp +++ b/lib/Ray/sources/Shaders/Shaders.cpp @@ -12,10 +12,10 @@ namespace RAY Cache<::Shader> Shader::_shadersCache(LoadShader, UnloadShader); - Shader::Shader(const std::string &vertexFile, const std::string &fragmentFile) + Shader::Shader(const std::string &vertexFile, const std::string &fragmentFile, bool lonely) : _vertexFile(vertexFile), _fragmentFile(fragmentFile), - _rayLibShader(_shadersCache.fetch(vertexFile, fragmentFile)) + _rayLibShader(_shadersCache.fetch(vertexFile, fragmentFile, lonely)) { this->_rayLibShader->locs[SHADER_LOC_MAP_EMISSION] = GetShaderLocation(*this->_rayLibShader, "mask"); } diff --git a/lib/Ray/sources/Shaders/Shaders.hpp b/lib/Ray/sources/Shaders/Shaders.hpp index fb93d326..20231ea7 100644 --- a/lib/Ray/sources/Shaders/Shaders.hpp +++ b/lib/Ray/sources/Shaders/Shaders.hpp @@ -49,7 +49,7 @@ namespace RAY void setLocation(::ShaderLocationIndex, const std::string &name); //! @brief ctor if no vertexfile in needed set it to nullptr - Shader(const std::string &vertexFile, const std::string &fragmentFile); + Shader(const std::string &vertexFile, const std::string &fragmentFile, bool lonely = false); //! @brief Default copy ctor Shader(const Shader &) = default; //! @brief dtor diff --git a/lib/Ray/sources/Utils/Cache.hpp b/lib/Ray/sources/Utils/Cache.hpp index beb1ff89..f7433c17 100644 --- a/lib/Ray/sources/Utils/Cache.hpp +++ b/lib/Ray/sources/Utils/Cache.hpp @@ -45,7 +45,7 @@ namespace RAY { this->_cache.emplace(path, std::vector>()); std::vector> &matchingDataVector = this->_cache.at(path); - if (matchingDataVector.size()) { + if (!matchingDataVector.empty()) { for (std::shared_ptr &i: matchingDataVector) { if (!lonely) return i; @@ -117,23 +117,34 @@ namespace RAY { _dataLoader(std::move(dataLoader)), _dataUnloader(std::move(dataUnloader)) {}; - std::shared_ptr<::Shader> fetch(const std::string &vertexFile, const std::string &fragmentFile) + std::shared_ptr<::Shader> fetch(const std::string &vertexFile, const std::string &fragmentFile, bool lonely = false) { const std::string index = vertexFile + fragmentFile; if (vertexFile.empty() && fragmentFile.empty()) { throw RAY::Exception::WrongInputError(); } - if (this->_cache.find(index) != this->_cache.end()) - return this->_cache[index]; + if (!this->_cache.contains(index)) { + this->_cache.emplace(index, std::vector>()); + } + std::vector> &matchingDataVector = this->_cache.at(index); - this->_cache.emplace(index, std::shared_ptr<::Shader>( + if (!matchingDataVector.empty()) { + for (std::shared_ptr<::Shader> &i: matchingDataVector) { + if (!lonely) + return i; + if (lonely && i.use_count() == 1) + return i; + } + } + + matchingDataVector.emplace_back(std::shared_ptr<::Shader>( new ::Shader( this->_dataLoader(vertexFile.empty() ? nullptr : vertexFile.c_str(), fragmentFile.c_str())), [this](::Shader *p) { this->_dataUnloader(*p); })); - return this->_cache[index]; + return matchingDataVector.back(); }; private: //! @brief function to call to load data @@ -143,6 +154,6 @@ namespace RAY { std::function _dataUnloader; //! @brief map storing shared ptr of caches - std::unordered_map> _cache; + std::unordered_map>> _cache; }; } diff --git a/sources/Component/Shaders/Items/BombExplosionShaderComponent.cpp b/sources/Component/Shaders/Items/BombExplosionShaderComponent.cpp new file mode 100644 index 00000000..c1ee13b6 --- /dev/null +++ b/sources/Component/Shaders/Items/BombExplosionShaderComponent.cpp @@ -0,0 +1,19 @@ +// +// Created by cbihan on 16/06/2021. +// + +#include "BombExplosionShaderComponent.hpp" + +namespace BBM +{ + + BombExplosionShaderComponent::BombExplosionShaderComponent(WAL::Entity &entity) : + Component(entity) + { + } + + WAL::Component *BombExplosionShaderComponent::clone(WAL::Entity &entity) const + { + return new BombExplosionShaderComponent(this->_entity); + } +} \ No newline at end of file diff --git a/sources/Component/Shaders/Items/BombExplosionShaderComponent.hpp b/sources/Component/Shaders/Items/BombExplosionShaderComponent.hpp new file mode 100644 index 00000000..548ebef4 --- /dev/null +++ b/sources/Component/Shaders/Items/BombExplosionShaderComponent.hpp @@ -0,0 +1,44 @@ +// +// Created by cbihan on 16/06/2021. +// + +#pragma once + +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" +#include + +using namespace std::chrono_literals; + +namespace BBM +{ + class BombExplosionShaderComponent : public WAL::Component + { + public: + //! @brief Explosion radius + float explosionRadius = 4; + //! @brief to have the shader move by the time + float frameCounter = 0; + + //! @brief The clock to use + std::chrono::nanoseconds clock = 0ns; + + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + + //! @brief ctor + explicit BombExplosionShaderComponent(WAL::Entity &entity); + + //! @brief Default copy ctor + BombExplosionShaderComponent(const BombExplosionShaderComponent &) = default; + + //! @brief Default dtor + ~BombExplosionShaderComponent() override = default; + + //! @brief Default assignment operator + BombExplosionShaderComponent &operator=(const BombExplosionShaderComponent &) = delete; + }; + +} diff --git a/sources/Component/Shaders/ShaderComponent.cpp b/sources/Component/Shaders/ShaderComponent.cpp index febb859a..e6f51917 100644 --- a/sources/Component/Shaders/ShaderComponent.cpp +++ b/sources/Component/Shaders/ShaderComponent.cpp @@ -22,9 +22,10 @@ namespace BBM ShaderComponent::ShaderComponent(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath, - const WAL::Callback &onFixedUpdate) + const WAL::Callback &onFixedUpdate, + bool lonely) : WAL::Component(entity), - shader(vertexFilePath, fragmentFilePath), + shader(vertexFilePath, fragmentFilePath, lonely), fragmentFilePath(fragmentFilePath), vertexFilePath(vertexFilePath), update(onFixedUpdate) @@ -44,8 +45,9 @@ namespace BBM ShaderComponentModel::ShaderComponentModel(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath, - const WAL::Callback &onFixedUpdate) - : ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate) + const WAL::Callback &onFixedUpdate, + bool lonely) + : ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate, lonely) { } @@ -60,8 +62,9 @@ namespace BBM ShaderComponentDrawable2D::ShaderComponentDrawable2D(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath, - const WAL::Callback &onFixedUpdate) - : ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate) + const WAL::Callback &onFixedUpdate, + bool lonely) + : ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate, lonely) { } } \ No newline at end of file diff --git a/sources/Component/Shaders/ShaderComponent.hpp b/sources/Component/Shaders/ShaderComponent.hpp index 747ba37d..fe44a506 100644 --- a/sources/Component/Shaders/ShaderComponent.hpp +++ b/sources/Component/Shaders/ShaderComponent.hpp @@ -46,7 +46,8 @@ namespace BBM ShaderComponent(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath = "", - const WAL::Callback &onFixedUpdate = WAL::Callback()); + const WAL::Callback &onFixedUpdate = WAL::Callback(), + bool lonely = false); //! @brief Default copy ctor ShaderComponent(const ShaderComponent &) = default; @@ -70,7 +71,8 @@ namespace BBM ShaderComponentModel(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath = "", - const WAL::Callback &onFixedUpdate = WAL::Callback()); + const WAL::Callback &onFixedUpdate = WAL::Callback(), + bool lonely = false); //! @brief Default copy ctor ShaderComponentModel(const ShaderComponentModel &) = default; @@ -90,7 +92,8 @@ namespace BBM ShaderComponentDrawable2D(WAL::Entity &entity, const std::string &fragmentFilePath, const std::string &vertexFilePath = "", - const WAL::Callback &onFixedUpdate = WAL::Callback()); + const WAL::Callback &onFixedUpdate = WAL::Callback(), + bool lonely = false); //! @brief Default copy ctor ShaderComponentDrawable2D(const ShaderComponentDrawable2D &) = default; diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index 6857bbb9..3ebb71c6 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -11,12 +11,13 @@ #include "Component/Health/HealthComponent.hpp" #include #include +#include "Component/Shaders/Items/BombExplosionShaderComponent.hpp" #include #include "Component/Shaders/ShaderComponent.hpp" #include "Component/Collision/CollisionComponent.hpp" #include "Component/Tag/TagComponent.hpp" -int glob = 0; +float glob = 0; using namespace std::chrono_literals; namespace RAY3D = RAY::Drawables::Drawables3D; @@ -48,17 +49,22 @@ namespace BBM return; wal.getScene()->scheduleNewEntity("explosion") .addComponent(position) + .addComponent() .addComponent("assets/shaders/mask.fs", "assets/shaders/mask.vs", [](WAL::Entity &entity, WAL::Wal &wal, std::chrono::nanoseconds dtime) { - static std::chrono::nanoseconds nanoseconds {}; + auto &ctx = entity.getComponent(); auto &shader = entity.getComponent(); - nanoseconds += dtime; - if (duration_cast(nanoseconds).count() <= 400) + ctx.clock += dtime; + if (duration_cast(ctx.clock).count() <= 10) return; - std::cout << "test" << std::endl; - shader.shader.setShaderUniformVar("frame", glob); - glob++; - glob %= 40; + ctx.clock = 0ns; + ctx.explosionRadius -= 0.3; + if (ctx.explosionRadius < 1.2) { + ctx.explosionRadius = 1.2; + } + shader.shader.setShaderUniformVar("frame", ctx.frameCounter); + shader.shader.setShaderUniformVar("radius", ctx.explosionRadius); + ctx.frameCounter += 0.1; }) .addComponent(500ms, [](WAL::Entity &explosion, WAL::Wal &wal) { explosion.scheduleDeletion();