Merge branch 'develop' of github.com:AnonymusRaccoon/Bomberman into opti

This commit is contained in:
Clément Le Bihan
2021-06-17 17:01:26 +02:00
11 changed files with 138 additions and 13 deletions
+2
View File
@@ -138,6 +138,8 @@ set(SOURCES
sources/Component/IntroAnimation/IntroAnimationComponent.cpp
sources/System/IntroAnimation/IntroAnimationSystem.hpp
sources/System/IntroAnimation/IntroAnimationSystem.cpp
sources/System/Renderer/CameraSystem.cpp
sources/System/Renderer/CameraSystem.cpp
sources/Runner/SplashScreenScene.cpp
sources/Runner/TitleScreenScene.cpp
sources/Runner/MainMenuScene.cpp
+2 -1
View File
@@ -52,11 +52,12 @@ namespace BBM
// interact with bombs & stop the explosion
constexpr const char Blowable[] = "Blowable";
// interact with visual features like camera
constexpr const char Player[] = "Player";
constexpr const char Unbreakable[] = "Unbreakable";
constexpr const char Breakable[] = "Breakable";
constexpr const char Hole[] = "Hole";
constexpr const char Bumper[] = "Bumper";
constexpr const char Player[] = "Player";
// interact with bombs (getting damage etc) but doesn't stop explosion
constexpr const char BlowablePass[] = "BlowablePass";
}
+6 -1
View File
@@ -135,7 +135,7 @@ namespace BBM
double magnitude() const
{
return (std::sqrt(std::pow(this->x, 2) + std::pow(this->y, 2), std::pow(this->z, 2)));
return (std::sqrt(std::pow(this->x, 2) + std::pow(this->y, 2) + std::pow(this->z, 2)));
}
Vector3<T> normalize()
@@ -168,6 +168,11 @@ namespace BBM
return (point * this) / std::pow(this->magnitude(), 2) * this;
}
Vector3<T> abs() const
{
return Vector3<T>(std::abs(this->x), std::abs(this->y), std::abs(this->z));
}
Vector3<T> trunc() const requires(std::is_floating_point_v<T>)
{
return Vector3<T>(std::trunc(this->x), std::trunc(this->y), std::trunc(this->z));
+3 -6
View File
@@ -19,8 +19,6 @@
#include "Component/Renderer/Drawable2DComponent.hpp"
#include <Drawables/Image.hpp>
#include "Drawables/2D/Text.hpp"
#include "Component/Renderer/Drawable2DComponent.hpp"
#include "Component/Button/ButtonComponent.hpp"
#include "Drawables/Texture.hpp"
#include "Component/Gravity/GravityComponent.hpp"
#include "Component/BumperTimer/BumperTimerComponent.hpp"
@@ -28,7 +26,6 @@
#include "Model/Model.hpp"
#include "Map/Map.hpp"
#include "Component/Score/ScoreComponent.hpp"
#include "Drawables/2D/Text.hpp"
namespace RAY3D = RAY::Drawables::Drawables3D;
namespace RAY2D = RAY::Drawables::Drawables2D;
@@ -39,7 +36,7 @@ namespace BBM
{
auto scene = std::make_shared<WAL::Scene>();
scene->addEntity("camera")
.addComponent<PositionComponent>(8, 20, 7)
.addComponent<PositionComponent>(8, 0, -5)
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
scene->addEntity("Timer")
.addComponent<TimerComponent>(std::chrono::minutes (3), [](WAL::Entity &, WAL::Wal &) {
@@ -62,16 +59,16 @@ namespace BBM
{SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"},
//{SoundComponent::DEATH, "assets/sounds/death.ogg"}
};
return scene.addEntity("player")
.addComponent<PositionComponent>()
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", true)
.addComponent<ControllableComponent>()
.addComponent<ScoreComponent>()
.addComponent<AnimatorComponent>()
.addComponent<GravityComponent>()
.addComponent<BumperTimerComponent>()
.addComponent<TagComponent<BlowablePass>>()
.addComponent<TagComponent<Player>>()
.addComponent<AnimationsComponent>("assets/player/player.iqm", 3)
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
.addComponent<MovableComponent>()
+1 -1
View File
@@ -200,7 +200,7 @@ namespace BBM
player.addComponent<LobbyComponent>(i, ready, playerTile);
}
scene->addEntity("camera")
.addComponent<PositionComponent>(8, 20, 7)
.addComponent<PositionComponent>(-5, 0, -5)
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
play.getComponent<OnClickComponent>().setButtonLinks(&lavaOption, &back, &back, &howToPlay);
howToPlay.getComponent<OnClickComponent>().setButtonLinks(&play, nullptr, &play);
+2
View File
@@ -46,6 +46,7 @@
#include "System/Gravity/GravitySystem.hpp"
#include "System/BumperTimer/BumperTimerSystem.hpp"
#include "System/Music/MusicSystem.hpp"
#include "System/Renderer/CameraSystem.hpp"
#include "System/Lobby/LobbySystem.hpp"
#include "System/Score/ScoreSystem.hpp"
#include "System/EndCondition/EndConditionSystem.hpp"
@@ -108,6 +109,7 @@ namespace BBM
.addSystem<ShaderDrawable2DSystem>()
// .addSystem<EndConditionSystem>()
.addSystem<ScoreSystem>()
.addSystem<CameraSystem>()
.addSystem<MusicSystem>();
}
+1 -1
View File
@@ -30,7 +30,7 @@ namespace BBM
auto anim = dynamic_cast<RAY3D::Model *>(drawable);
auto health = entity->tryGetComponent<HealthComponent>();
if (health && health->getHealthPoint() <= 0)
if (health && health->getHealthPoint() <= 0 || entity->shouldDelete())
return;
if (anim && controllable.move != Vector2f(0, 0)) {
anim->setRotationAngle(controllable.move.angle(Vector2f(-1, 0)));
+79
View File
@@ -0,0 +1,79 @@
//
// Created by Tom Augier on 05/06/2021
//
#include "CameraSystem.hpp"
#include "Entity/Entity.hpp"
#include "Component/Tag/TagComponent.hpp"
namespace BBM
{
CameraSystem::CameraSystem(WAL::Wal &wal)
: System(wal)
{}
bool CameraSystem::introAnimation(WAL::ViewEntity<CameraComponent, PositionComponent> &entity, bool restart)
{
auto &pos = entity.get<PositionComponent>();
static Vector3f posTarget(8, 25, 7);
static bool hasEnded = false;
if (restart) {
hasEnded = false;
return (false);
}
if (pos.position.distance(posTarget) < 4 || hasEnded) {
hasEnded = true;
return (true);
}
auto &cam = entity.get<CameraComponent>();
pos.position += (posTarget - pos.position) / 100;
return (false);
}
void CameraSystem::onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity,
std::chrono::nanoseconds dtime)
{
if (!introAnimation(entity))
return;
auto &pos = entity.get<PositionComponent>();
auto &cam = entity.get<CameraComponent>();
Vector3f newCameraPos = Vector3f(-1, -1, -1);
std::vector<Vector3f> playerPos;
float maxDist = 0;
float lowerXDist = 0;
float lowerZDist = 0;
for (auto &[entity, pos, _] : this->_wal.getScene()->view<PositionComponent, TagComponent<Player>>()) {
if (!entity.hasComponent<ControllableComponent>())
entity.addComponent<ControllableComponent>();
playerPos.emplace_back(pos.position);
}
if (playerPos.size() == 0)
introAnimation(entity, true);
if (playerPos.size() == 1)
newCameraPos = playerPos[0];
for (int i = 0; i < playerPos.size(); i++)
for (int j = 0; j < playerPos.size(); j++) {
if (maxDist < playerPos[i].distance(playerPos[j])) {
maxDist = playerPos[i].distance(playerPos[j]);
newCameraPos = (playerPos[i] + playerPos[j]) / 2;
}
if (lowerXDist < std::abs((playerPos[i].x - playerPos[j].x)))
lowerXDist = std::abs((playerPos[i].x - playerPos[j].x));
if (lowerZDist < std::abs((playerPos[i].z - playerPos[j].z)))
lowerZDist = std::abs((playerPos[i].z - playerPos[j].z));
}
maxDist += (lowerXDist + lowerZDist) / 2;
if (maxDist < 14)
maxDist = 14;
if (maxDist > 25)
maxDist = 25;
cam.target += (newCameraPos.abs() - pos.position.abs()) / 10;
newCameraPos.y = maxDist;
newCameraPos.z -= 1;
pos.position += (newCameraPos.abs() - pos.position.abs()) / 10;
}
}
+36
View File
@@ -0,0 +1,36 @@
//
// Created by Tom Augier on 05/06/2021
//
#pragma once
#include "System/System.hpp"
#include "Window.hpp"
#include "Component/Renderer/CameraComponent.hpp"
#include "Component/Position/PositionComponent.hpp"
#include <Component/Controllable/ControllableComponent.hpp>
#include "Wal.hpp"
namespace BBM
{
class CameraSystem : public WAL::System<CameraComponent, PositionComponent>
{
public:
//! @inherit
void onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity, std::chrono::nanoseconds) override;
//! @brief introduciton animation when entering gameScene
bool introAnimation(WAL::ViewEntity<CameraComponent, PositionComponent> &entity, bool restart = false);
//! @brief ctor
CameraSystem(WAL::Wal &wal);
//! @brief Default copy ctor
CameraSystem(const CameraSystem &) = default;
//! @brief Default dtor
~CameraSystem() override = default;
//! @brief A CameraManager screen system can't be assigned.
CameraSystem &operator=(const CameraSystem &) = delete;
};
}
+5 -3
View File
@@ -12,6 +12,7 @@
#include "Drawables/ADrawable3D.hpp"
#include "Drawables/ADrawable2D.hpp"
#include "Component/Shaders/ShaderComponent.hpp"
#include "Component/Tag/TagComponent.hpp"
#include <Drawables/3D/Cube.hpp>
#include "Models/Vector3.hpp"
#include "Component/Collision/CollisionComponent.hpp"
@@ -164,10 +165,11 @@ namespace BBM
void RenderSystem::onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity,
std::chrono::nanoseconds dtime)
{
const auto &pos = entity.get<PositionComponent>();
const auto &cam = entity.get<CameraComponent>();
_camera.setPosition(pos.position);
auto &pos = entity.get<PositionComponent>();
auto &cam = entity.get<CameraComponent>();
_camera.setTarget(cam.target);
_camera.setPosition(pos.position);
}
void RenderSystem::setDebug(bool debug)
+1
View File
@@ -6,6 +6,7 @@
#include "Component/Renderer/CameraComponent.hpp"
#include "Component/Position/PositionComponent.hpp"
#include "Component/Movable/MovableComponent.hpp"
#include "Component/Renderer/Drawable3DComponent.hpp"
#include "System/System.hpp"
#include "Camera/Camera2D.hpp"