mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-01 17:55:48 +00:00
modif shaders callback (adding dtime)
This commit is contained in:
@@ -99,7 +99,7 @@ varying vec3 fragPosition;
|
||||
|
||||
void main() {
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(0, frame, 0) + vertexPosition + vertexPosition * vec3(cnoise(vertexNormal) * 0.5);
|
||||
fragPosition = vertexPosition + vertexPosition * vec3(cnoise(vec3(vertexNormal + vec3(frame))) * 0.5);
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp * vec4(fragPosition , 1.0);
|
||||
//gl_Position = vec4(vertexNormal, 1.0);
|
||||
|
||||
@@ -22,12 +22,12 @@ namespace BBM
|
||||
ShaderComponent::ShaderComponent(WAL::Entity &entity,
|
||||
const std::string &fragmentFilePath,
|
||||
const std::string &vertexFilePath,
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &> &onFixedUpdate)
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds> &onFixedUpdate)
|
||||
: WAL::Component(entity),
|
||||
shader(vertexFilePath, fragmentFilePath),
|
||||
fragmentFilePath(fragmentFilePath),
|
||||
vertexFilePath(vertexFilePath),
|
||||
onFixedUpdate(onFixedUpdate)
|
||||
update(onFixedUpdate)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace BBM
|
||||
ShaderComponentModel::ShaderComponentModel(WAL::Entity &entity,
|
||||
const std::string &fragmentFilePath,
|
||||
const std::string &vertexFilePath,
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &> &onFixedUpdate)
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds> &onFixedUpdate)
|
||||
: ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate)
|
||||
{
|
||||
}
|
||||
@@ -60,7 +60,7 @@ namespace BBM
|
||||
ShaderComponentDrawable2D::ShaderComponentDrawable2D(WAL::Entity &entity,
|
||||
const std::string &fragmentFilePath,
|
||||
const std::string &vertexFilePath,
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &> &onFixedUpdate)
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds> &onFixedUpdate)
|
||||
: ShaderComponent(entity, fragmentFilePath, vertexFilePath, onFixedUpdate)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <Entity/Entity.hpp>
|
||||
#include <Shaders/Shaders.hpp>
|
||||
#include <Model/Model.hpp>
|
||||
#include <chrono>
|
||||
#include <Wal.hpp>
|
||||
|
||||
namespace BBM
|
||||
@@ -25,7 +26,7 @@ namespace BBM
|
||||
std::string vertexFilePath;
|
||||
|
||||
//! @brief the function called to update shaders vars
|
||||
WAL::Callback<WAL::Entity &, WAL::Wal &> onFixedUpdate;
|
||||
WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds> update;
|
||||
|
||||
//! @brief getter for _shader
|
||||
RAY::Shader &getShader();
|
||||
@@ -45,7 +46,7 @@ namespace BBM
|
||||
ShaderComponent(WAL::Entity &entity,
|
||||
const std::string &fragmentFilePath,
|
||||
const std::string &vertexFilePath = "",
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &>());
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds>());
|
||||
|
||||
//! @brief Default copy ctor
|
||||
ShaderComponent(const ShaderComponent &) = default;
|
||||
@@ -69,7 +70,7 @@ namespace BBM
|
||||
ShaderComponentModel(WAL::Entity &entity,
|
||||
const std::string &fragmentFilePath,
|
||||
const std::string &vertexFilePath = "",
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &>());
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds>());
|
||||
|
||||
//! @brief Default copy ctor
|
||||
ShaderComponentModel(const ShaderComponentModel &) = default;
|
||||
@@ -89,7 +90,7 @@ namespace BBM
|
||||
ShaderComponentDrawable2D(WAL::Entity &entity,
|
||||
const std::string &fragmentFilePath,
|
||||
const std::string &vertexFilePath = "",
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &>());
|
||||
const WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds> &onFixedUpdate = WAL::Callback<WAL::Entity &, WAL::Wal &, std::chrono::nanoseconds>());
|
||||
|
||||
//! @brief Default copy ctor
|
||||
ShaderComponentDrawable2D(const ShaderComponentDrawable2D &) = default;
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include "Map/Map.hpp"
|
||||
#include "Component/Score/ScoreComponent.hpp"
|
||||
|
||||
int glob = 0;
|
||||
|
||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
|
||||
namespace BBM
|
||||
@@ -63,22 +61,16 @@ namespace BBM
|
||||
|
||||
return scene.addEntity("player")
|
||||
.addComponent<PositionComponent>()
|
||||
//.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", true)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(GenMeshSphere(1, 16, 16))
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", true)
|
||||
//.addComponent<Drawable3DComponent, RAY3D::Model>(GenMeshSphere(1, 16, 16))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<ScoreComponent>()
|
||||
.addComponent<AnimatorComponent>()
|
||||
.addComponent<GravityComponent>()
|
||||
.addComponent<ShaderComponentModel>("assets/shaders/mask.fs", "assets/shaders/mask.vs", [](WAL::Entity &entity, WAL::Wal &wal) {
|
||||
/*auto &shader = entity.getComponent<ShaderComponentModel>();
|
||||
shader.shader.setShaderUniformVar("frame", glob);
|
||||
glob++;
|
||||
glob %= 10;*/
|
||||
})
|
||||
.addComponent<BumperTimerComponent>()
|
||||
// .addComponent<ShaderComponentModel>("assets/shaders/glsl330/predator.fs")
|
||||
.addComponent<TagComponent<BlowablePass>>()
|
||||
//.addComponent<AnimationsComponent>("assets/player/player.iqm", 3)
|
||||
.addComponent<AnimationsComponent>("assets/player/player.iqm", 3)
|
||||
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
|
||||
.addComponent<MovableComponent>()
|
||||
.addComponent<SoundComponent>(soundPath)
|
||||
@@ -86,8 +78,8 @@ namespace BBM
|
||||
.addComponent<BombHolderComponent>()
|
||||
.addComponent<PlayerBonusComponent>()
|
||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &) {
|
||||
//auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
//animation.setAnimIndex(5);
|
||||
auto &animation = entity.getComponent<AnimationsComponent>();
|
||||
animation.setAnimIndex(5);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,13 @@
|
||||
#include "Component/Health/HealthComponent.hpp"
|
||||
#include <functional>
|
||||
#include <Map/Map.hpp>
|
||||
#include <chrono>
|
||||
#include "Component/Shaders/ShaderComponent.hpp"
|
||||
#include "Component/Collision/CollisionComponent.hpp"
|
||||
#include "Component/Tag/TagComponent.hpp"
|
||||
|
||||
int glob = 0;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
|
||||
@@ -44,14 +48,27 @@ namespace BBM
|
||||
return;
|
||||
wal.getScene()->scheduleNewEntity("explosion")
|
||||
.addComponent<PositionComponent>(position)
|
||||
.addComponent<ShaderComponentModel>("assets/shaders/mask.fs", "assets/shaders/mask.vs", [](WAL::Entity &entity, WAL::Wal &wal, std::chrono::nanoseconds dtime) {
|
||||
static std::chrono::nanoseconds nanoseconds {};
|
||||
auto &shader = entity.getComponent<ShaderComponentModel>();
|
||||
|
||||
nanoseconds += dtime;
|
||||
if (duration_cast<std::chrono::milliseconds>(nanoseconds).count() <= 400)
|
||||
return;
|
||||
std::cout << "test" << std::endl;
|
||||
shader.shader.setShaderUniformVar("frame", glob);
|
||||
glob++;
|
||||
glob %= 40;
|
||||
})
|
||||
.addComponent<TimerComponent>(500ms, [](WAL::Entity &explosion, WAL::Wal &wal) {
|
||||
explosion.scheduleDeletion();
|
||||
})
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/explosion/explosion.glb", false,
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(GenMeshSphere(0.5, 16, 16));
|
||||
/*.addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/explosion/explosion.glb", false,
|
||||
std::make_pair(
|
||||
MAP_DIFFUSE,
|
||||
"assets/bombs/explosion/blast.png"
|
||||
));
|
||||
));*/
|
||||
wal.getSystem<EventSystem>().dispatchEvent([position, size, expansionDirections](WAL::Wal &wal) {
|
||||
for (auto &[entity, pos, _] : wal.getScene()->view<PositionComponent, TagComponent<Blowable>>()) {
|
||||
if (pos.position.round() == position) {
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace BBM
|
||||
{
|
||||
}
|
||||
|
||||
void ShaderDrawable2DSystem::onFixedUpdate(WAL::ViewEntity<ShaderComponentDrawable2D> &entity)
|
||||
void ShaderDrawable2DSystem::onUpdate(WAL::ViewEntity<ShaderComponentDrawable2D> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &shader = entity->getComponent<ShaderComponentDrawable2D>();
|
||||
|
||||
shader.onFixedUpdate(entity, this->_wal);
|
||||
shader.update(entity, this->_wal, dtime);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace BBM
|
||||
public:
|
||||
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::ViewEntity<ShaderComponentDrawable2D> &entity) override;
|
||||
void onUpdate(WAL::ViewEntity<ShaderComponentDrawable2D> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief ctor
|
||||
explicit ShaderDrawable2DSystem(WAL::Wal &wal);
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace BBM
|
||||
{
|
||||
}
|
||||
|
||||
void ShaderModelSystem::onFixedUpdate(WAL::ViewEntity<ShaderComponentModel> &entity)
|
||||
void ShaderModelSystem::onUpdate(WAL::ViewEntity<ShaderComponentModel> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &shader = entity->getComponent<ShaderComponentModel>();
|
||||
|
||||
shader.onFixedUpdate(entity, this->_wal);
|
||||
shader.update(entity, this->_wal, dtime);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace BBM
|
||||
public:
|
||||
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::ViewEntity<ShaderComponentModel> &entity) override;
|
||||
void onUpdate(WAL::ViewEntity<ShaderComponentModel> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief ctor
|
||||
explicit ShaderModelSystem(WAL::Wal &wal);
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace BBM
|
||||
{
|
||||
}
|
||||
|
||||
void ShaderSystem::onFixedUpdate(WAL::ViewEntity<ShaderComponent> &entity)
|
||||
void ShaderSystem::onUpdate(WAL::ViewEntity<ShaderComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &shader = entity->getComponent<ShaderComponent>();
|
||||
|
||||
shader.onFixedUpdate(entity, this->_wal);
|
||||
shader.update(entity, this->_wal, dtime);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace BBM
|
||||
public:
|
||||
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::ViewEntity<ShaderComponent> &entity) override;
|
||||
void onUpdate(WAL::ViewEntity<ShaderComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief ctor
|
||||
explicit ShaderSystem(WAL::Wal &wal);
|
||||
|
||||
Reference in New Issue
Block a user