Merging with deevelop

This commit is contained in:
Zoe Roux
2021-06-09 16:26:39 +02:00
12 changed files with 132 additions and 22 deletions
+1
View File
@@ -83,6 +83,7 @@ set(SOURCES
sources/System/Animator/AnimatorSystem.hpp
sources/Component/Shaders/ShaderComponent.cpp
sources/Component/Shaders/ShaderComponent.hpp
sources/Component/Tag/TagComponent.hpp
sources/Component/Music/MusicComponent.cpp
sources/Component/Music/MusicComponent.hpp
sources/Component/Sound/SoundComponent.hpp
+5 -3
View File
@@ -11,10 +11,12 @@ namespace BBM
float SoundComponent::volume = 0.75;
SoundComponent::SoundComponent(WAL::Entity &entity,
const std::map<SoundComponent::SoundIndex, std::string> &soundPath)
const std::map<SoundComponent::SoundIndex, std::string> &soundPath,
bool isLonely)
: WAL::Component(entity),
_soundIndex(IDLE),
_soundPath(soundPath)
_soundPath(soundPath),
_isLonely(isLonely)
{
for (int i = 0; i <= DEATH; i++) {
this->_isSoundLoad[static_cast<SoundIndex>(i)] = false;
@@ -22,7 +24,7 @@ namespace BBM
for (auto &soundPath : soundPath)
{
this->_isSoundLoad[soundPath.first] = true;
this->_soundList[soundPath.first] = std::make_unique<RAY::Audio::Sound>(soundPath.second);
this->_soundList[soundPath.first] = std::make_unique<RAY::Audio::Sound>(soundPath.second, this->_isLonely);
}
}
+5 -1
View File
@@ -53,7 +53,9 @@ namespace BBM
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
//! @brief Create a new SoundComponent at a certain Sound
explicit SoundComponent(WAL::Entity &entity, const std::map<SoundIndex, std::string> &);
explicit SoundComponent(WAL::Entity &entity,
const std::map<SoundIndex, std::string> &,
bool isLonely = false);
//! @brief A Sound component is copy constructable
SoundComponent(const SoundComponent &) = default;
//! @brief A default destructor
@@ -68,6 +70,8 @@ namespace BBM
std::map<SoundIndex, std::shared_ptr<RAY::Audio::Sound>> _soundList;
//! @brief map to know if sound is loaded
std::map<SoundIndex, bool> _isSoundLoad;
//! @brief to know if cache is needed
bool _isLonely;
//! @brief All sounds path
const std::map<SoundIndex, std::string> _soundPath;
//! SoundIndex
+54
View File
@@ -0,0 +1,54 @@
//
// Created by Zoe Roux on 6/9/21.
//
#pragma once
#include <Component/Component.hpp>
#include <string_view>
namespace BBM
{
template<std::size_t I>
struct StringLiteral
{
public:
char value[I];
//! @brief Implicitly convert an array of char to a string literal.
constexpr StringLiteral(const char (&str)[I]) // NOLINT(google-explicit-constructor)
: value()
{
std::copy_n(str, I, value);
}
//! @brief A string literal is copy constructable.
constexpr StringLiteral(const StringLiteral &) = default;
//! @brief A default destructor
constexpr ~StringLiteral() = default;
//! @brief A string literal is assignable.
constexpr StringLiteral &operator=(const StringLiteral &) = default;
};
template <StringLiteral name>
class TagComponent : public WAL::Component
{
public:
Component *clone(WAL::Entity &entity) const override
{
return new TagComponent<name>(entity);
}
//! @brief Create a new empty tag component.
explicit TagComponent(WAL::Entity &entity)
: WAL::Component(entity)
{}
//! @brief A default copy constructor.
TagComponent(const TagComponent &) = default;
//! @brief A default destructor
~TagComponent() override = default;
//! @brief A tag component is not assignable.
TagComponent &operator=(const TagComponent &) = delete;
};
constexpr const char Blowable[] = "Blowable";
}
+8 -2
View File
@@ -6,7 +6,7 @@
#include "Component/Collision/CollisionComponent.hpp"
#include "System/Collision/CollisionSystem.hpp"
#include "Map.hpp"
#include <iostream>
#include <Component/Tag/TagComponent.hpp>
namespace RAY3D = RAY::Drawables::Drawables3D;
@@ -23,7 +23,7 @@ namespace BBM
if (collidedAxis & CollisionComponent::CollidedAxis::X)
mov->_velocity.x = 0;
if (collidedAxis & CollisionComponent::CollidedAxis::Y)
mov->_velocity.x = 0;
mov->_velocity.y = 0;
if (collidedAxis & CollisionComponent::CollidedAxis::Z)
mov->_velocity.z = 0;
}
@@ -56,6 +56,7 @@ namespace BBM
if (!(i % 2) && !(j % 2)) {
scene->addEntity("Unbreakable Wall")
.addComponent<PositionComponent>(i, 0, j)
.addComponent<TagComponent<Blowable>>()
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
@@ -73,6 +74,7 @@ namespace BBM
scene->addEntity("Bottom Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
.addComponent<TagComponent<Blowable>>()
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75))
@@ -81,6 +83,7 @@ namespace BBM
RAY::Vector3(width + 3, 1, 1));
scene->addEntity("Upper Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, height + 1))
.addComponent<TagComponent<Blowable>>()
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75))
@@ -89,6 +92,7 @@ namespace BBM
RAY::Vector3(width + 3, 1, 1));
scene->addEntity("Left Wall")
.addComponent<PositionComponent>(Vector3f(width + 1, 0, height / 2))
.addComponent<TagComponent<Blowable>>()
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1))
@@ -145,6 +149,7 @@ namespace BBM
scene->addEntity("Breakable Block")
.addComponent<PositionComponent>(coords)
.addComponent<TagComponent<Blowable>>()
.addComponent<HealthComponent>(1, &MapGenerator::wallDestroyed)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
@@ -181,6 +186,7 @@ namespace BBM
scene->addEntity("Unbreakable Block")
.addComponent<PositionComponent>(coords)
.addComponent<TagComponent<Blowable>>()
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
+5
View File
@@ -168,6 +168,11 @@ namespace BBM
return (point * this) / std::pow(this->magnitude(), 2) * this;
}
Vector3<T> round() const requires(std::is_floating_point_v<T>)
{
return Vector3<T>(std::round(this->x), std::round(this->y), std::round(this->z));
}
operator RAY::Vector3() const requires(std::is_same_v<T, float>)
{
return RAY::Vector3(this->x, this->y, this->z);
+3 -1
View File
@@ -30,6 +30,7 @@
#include <System/Animator/AnimatorSystem.hpp>
#include <Component/Renderer/Drawable2DComponent.hpp>
#include <Component/Animator/AnimatorComponent.hpp>
#include <Component/Tag/TagComponent.hpp>
#include "Component/Animation/AnimationsComponent.hpp"
#include "System/Animation/AnimationsSystem.hpp"
#include "Component/Shaders/ShaderComponent.hpp"
@@ -85,7 +86,7 @@ namespace BBM
{SoundComponent::JUMP, "assets/sounds/jump.wav"},
{SoundComponent::MOVE, "assets/sounds/move.ogg"},
{SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"},
{SoundComponent::DEATH, "assets/sounds/death.ogg"}
//{SoundComponent::DEATH, "assets/sounds/death.ogg"}
};
scene->addEntity("player")
.addComponent<PositionComponent>()
@@ -94,6 +95,7 @@ namespace BBM
.addComponent<AnimatorComponent>()
.addComponent<KeyboardComponent>()
.addComponent<ShaderComponentModel>("assets/shaders/glsl330/predator.fs")
.addComponent<TagComponent<Blowable>>()
//.addComponent<GamepadComponent>(0)
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
+28 -14
View File
@@ -7,6 +7,10 @@
#include "Component/Renderer/Drawable3DComponent.hpp"
#include "BombHolderSystem.hpp"
#include "Component/Health/HealthComponent.hpp"
#include <functional>
#include <Map/Map.hpp>
#include "Component/Collision/CollisionComponent.hpp"
#include "Component/Tag/TagComponent.hpp"
using namespace std::chrono_literals;
namespace RAY3D = RAY::Drawables::Drawables3D;
@@ -14,34 +18,44 @@ namespace RAY3D = RAY::Drawables::Drawables3D;
namespace BBM
{
std::chrono::nanoseconds BombHolderSystem::explosionTimer = 3s;
float BombHolderSystem::explosionRadius = 3;
BombHolderSystem::BombHolderSystem(WAL::Wal &wal)
: System(wal)
{}
void BombHolderSystem::_dispatchExplosion(Vector3f position, WAL::Wal &wal, int count)
{
if (count <= 0)
return;
wal.getSystem<EventSystem>().dispatchEvent([position, count](WAL::Wal &wal) {
for (auto &[entity, pos, _] : wal.getScene()->view<PositionComponent, TagComponent<Blowable>>()) {
if (pos.position.round() == position) {
if (auto *health = entity.tryGetComponent<HealthComponent>())
health->takeDmg(1);
return;
}
}
_dispatchExplosion(position + Vector3f(1, 0, 0), wal, count - 1);
_dispatchExplosion(position + Vector3f(-1, 0, 0), wal, count - 1);
_dispatchExplosion(position + Vector3f(0, 0, 1), wal, count - 1);
_dispatchExplosion(position + Vector3f(0, 0, -1), wal, count - 1);
});
}
void BombHolderSystem::_bombExplosion(WAL::Entity &bomb, WAL::Wal &wal)
{
bomb.scheduleDeletion();
auto &bombPosition = bomb.getComponent<PositionComponent>();
wal.getSystem<EventSystem>().dispatchEvent([&bombPosition](WAL::Entity &entity){
auto *health = entity.tryGetComponent<HealthComponent>();
auto *pos = entity.tryGetComponent<PositionComponent>();
if (!health || !pos)
return;
if (pos->position.distance(bombPosition.position) > BombHolderSystem::explosionRadius)
return;
// TODO do a raycast here to only remove health to entities that are not behind others.
health->takeDmg(1);
});
auto position = bomb.getComponent<PositionComponent>().position.round();
_dispatchExplosion(position, wal, 3);
}
void BombHolderSystem::_spawnBomb(Vector3f position)
{
this->_wal.getScene()->scheduleNewEntity("Bomb")
.addComponent<PositionComponent>(position)
.addComponent<PositionComponent>(position.round())
.addComponent<TimerComponent>(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion)
// .addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
// &MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/bomb.obj",
std::make_pair(MAP_DIFFUSE, "assets/bombs/bomb_normal.png"));
}
@@ -20,6 +20,9 @@ namespace BBM
//! @brief Spawn a bomb at the specified position.
void _spawnBomb(Vector3f position);
//! @brief Spawn a bomb at the specified position.
static void _dispatchExplosion(Vector3f position, WAL::Wal &, int count);
//! @brief The method triggered when the bomb explode.
static void _bombExplosion(WAL::Entity &bomb, WAL::Wal &);
public:
+8
View File
@@ -15,6 +15,11 @@ namespace BBM
this->_events.emplace_back(event);
}
void EventSystem::dispatchEvent(const std::function<void(WAL::Wal &)> &event)
{
this->_globalEvents.emplace_back(event);
}
void EventSystem::onUpdate(WAL::ViewEntity<> &entity, std::chrono::nanoseconds)
{
for (auto &event : this->_events)
@@ -23,6 +28,9 @@ namespace BBM
void EventSystem::onSelfUpdate()
{
for (auto &event : this->_globalEvents)
event(this->_wal);
this->_events.clear();
this->_globalEvents.clear();
}
}
+6 -1
View File
@@ -14,11 +14,16 @@ namespace BBM
{
private:
//! @brief The list of events that occurred in the last update.
std::vector<std::function<void (WAL::Entity &)>> _events;
std::list<std::function<void (WAL::Entity &)>> _events;
//! @brief The list of events that occurred in the last update.
std::list<std::function<void (WAL::Wal &)>> _globalEvents;
public:
//! @brief Inform the system that a new event has occurred and it should run the given method on every entities.
void dispatchEvent(const std::function<void (WAL::Entity &)>& event);
//! @brief Inform the system that a new event has occurred and it should run the given method on every entities.
void dispatchEvent(const std::function<void (WAL::Wal &)>& event);
//! @inherit
void onUpdate(WAL::ViewEntity<> &entity, std::chrono::nanoseconds dtime) override;
//! @inherit
+6
View File
@@ -97,4 +97,10 @@ TEST_CASE("Collsion test with movable", "[Component][System]")
REQUIRE(entity.getComponent<PositionComponent>().position.x == 0.0);
REQUIRE(entity.getComponent<PositionComponent>().position.y == 0.0);
REQUIRE(entity.getComponent<PositionComponent>().position.z == 0.0);
}
TEST_CASE("Vector round", "[Vector]")
{
Vector3f v(1.3, 1.5, 1.7);
REQUIRE(v.round() == Vector3f(1, 2, 2));
}