mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-30 01:05:24 +00:00
Merge branch 'develop' into bonus
This commit is contained in:
+8
-3
@@ -62,6 +62,10 @@ set(SOURCES
|
||||
sources/Component/Renderer/CameraComponent.hpp
|
||||
sources/System/Renderer/Render2DScreenSystem.cpp
|
||||
sources/System/Renderer/Render2DScreenSystem.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
|
||||
@@ -70,7 +74,8 @@ set(SOURCES
|
||||
|
||||
add_executable(bomberman
|
||||
sources/main.cpp
|
||||
${SOURCES})
|
||||
${SOURCES}
|
||||
)
|
||||
target_include_directories(bomberman PUBLIC sources)
|
||||
target_link_libraries(bomberman PUBLIC wal ray)
|
||||
|
||||
@@ -81,9 +86,9 @@ add_executable(unit_tests EXCLUDE_FROM_ALL
|
||||
tests/MainTest.cpp
|
||||
tests/EngineTests.cpp
|
||||
tests/CallbackTest.cpp
|
||||
tests/CollisionTest.cpp
|
||||
tests/MoveTests.cpp
|
||||
)
|
||||
tests/CollisionTest.cpp
|
||||
)
|
||||
target_include_directories(unit_tests PUBLIC sources)
|
||||
target_link_libraries(unit_tests PUBLIC wal ray)
|
||||
|
||||
|
||||
@@ -40,12 +40,13 @@ mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
cd -
|
||||
```
|
||||
|
||||
Enjoy !
|
||||
|
||||
```bash
|
||||
./bomberman
|
||||
./build/bomberman
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
RAY::Cache<::ModelAnimation> RAY::ModelAnimations::_animationsCache(LoadModelAnimations, UnloadModelAnimations);
|
||||
|
||||
RAY::ModelAnimations::ModelAnimations(const std::string &filePath):
|
||||
_animationsPtr(_animationsCache.fetch(filePath, &this->_animationCount))
|
||||
_animationsPtr(_animationsCache.fetch(filePath, &this->_animationCount)),
|
||||
_filePath(filePath)
|
||||
{
|
||||
::ModelAnimation *ptr = this->_animationsPtr.get();
|
||||
|
||||
for (int i = 0; i < this->_animationCount; i++)
|
||||
this->_animations.push_back(RAY::ModelAnimation(ptr[i]));
|
||||
this->_animations.emplace_back(ptr[i]);
|
||||
}
|
||||
|
||||
RAY::ModelAnimation &RAY::ModelAnimations::operator[](int index)
|
||||
@@ -28,3 +29,22 @@ size_t RAY::ModelAnimations::getAnimationsCount() const
|
||||
return this->_animationCount;
|
||||
}
|
||||
|
||||
std::string RAY::ModelAnimations::getFilePath() const
|
||||
{
|
||||
return this->_filePath;
|
||||
}
|
||||
|
||||
const RAY::ModelAnimation &RAY::ModelAnimations::at(int index) const
|
||||
{
|
||||
return this->_animations.at(index);
|
||||
}
|
||||
|
||||
const RAY::ModelAnimation &RAY::ModelAnimations::operator[](int index) const
|
||||
{
|
||||
return this->_animations[index];
|
||||
}
|
||||
|
||||
RAY::ModelAnimation &RAY::ModelAnimations::at(int index)
|
||||
{
|
||||
return this->_animations.at(index);
|
||||
}
|
||||
|
||||
@@ -21,21 +21,33 @@ namespace RAY {
|
||||
//! @param filePath Path to the file containing animations
|
||||
ModelAnimations(const std::string &filePath);
|
||||
|
||||
//! @brief Only single entity can hold these animations pointers
|
||||
ModelAnimations(const ModelAnimations &) = delete;
|
||||
//! @brief default copy ctor
|
||||
ModelAnimations(const ModelAnimations &) = default;
|
||||
|
||||
//! @brief Default constructor
|
||||
~ModelAnimations() = default;
|
||||
|
||||
//! @brief Only single entity can hold these animations pointers
|
||||
ModelAnimations &operator=(const ModelAnimations &) = delete;
|
||||
//! @brief Default assignment operator
|
||||
ModelAnimations &operator=(const ModelAnimations &) = default;
|
||||
|
||||
//! @brief Castin Object to raw model animation pointer
|
||||
ModelAnimation &operator[](int index);
|
||||
|
||||
//! @brief std [] const
|
||||
const ModelAnimation &operator[](int index) const;
|
||||
|
||||
//! @brief std at const
|
||||
const ModelAnimation &at(int index) const;
|
||||
|
||||
//! @brief std at
|
||||
ModelAnimation &at(int index);
|
||||
|
||||
//! @return the number of loaded animations
|
||||
size_t getAnimationsCount() const;
|
||||
|
||||
//! @brief Get the creation file
|
||||
std::string getFilePath() const;
|
||||
|
||||
private:
|
||||
//! @brief Holds the pointer returned by the loading function
|
||||
std::shared_ptr<::ModelAnimation> _animationsPtr;
|
||||
@@ -46,6 +58,9 @@ namespace RAY {
|
||||
//! @brief the number of loaded animations
|
||||
int _animationCount;
|
||||
|
||||
//! @brief The file where the animations were loaded (used to create a copy of this class)
|
||||
const std::string _filePath;
|
||||
|
||||
static Cache<::ModelAnimation> _animationsCache;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,13 +60,17 @@ namespace RAY {
|
||||
{};
|
||||
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
|
||||
{
|
||||
if (this->_cache.find(path) == this->_cache.end())
|
||||
this->_cache.emplace(path, std::shared_ptr<::ModelAnimation>(
|
||||
this->_dataLoader(path.c_str(), counter), [this, counter](::ModelAnimation *p) {
|
||||
this->_dataUnloader(p, *counter);
|
||||
delete p;
|
||||
}));
|
||||
return _cache[path];
|
||||
if (this->_cache.find(path) != this->_cache.end())
|
||||
return this->_cache[path];
|
||||
|
||||
::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter);
|
||||
unsigned int animCount = *counter;
|
||||
|
||||
this->_cache.emplace(path, std::shared_ptr<::ModelAnimation>(
|
||||
animations, [this, animCount](::ModelAnimation *p) {
|
||||
this->_dataUnloader(p, animCount);
|
||||
}));
|
||||
return this->_cache[path];
|
||||
};
|
||||
private:
|
||||
//! @brief function to call to load data
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// Created by cbihan on 01/06/2021.
|
||||
//
|
||||
|
||||
#include "AnimationsComponent.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include "Model/ModelAnimations.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play)
|
||||
: WAL::Component(entity),
|
||||
_modelAnimation(std::move(modelAnimation)),
|
||||
_currentAnimIndex(animIndex),
|
||||
_animDisabled(play)
|
||||
{
|
||||
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0);
|
||||
}
|
||||
|
||||
WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new AnimationsComponent(entity,
|
||||
RAY::ModelAnimations(this->_modelAnimation.getFilePath()),
|
||||
this->_currentAnimIndex);
|
||||
}
|
||||
|
||||
size_t AnimationsComponent::getCurrentAnimFrameCounter() const
|
||||
{
|
||||
return this->_modelAnimation.at(this->_currentAnimIndex).getFrameCounter();
|
||||
}
|
||||
|
||||
RAY::ModelAnimation AnimationsComponent::getCurrentModelAnim()
|
||||
{
|
||||
return this->_modelAnimation[this->_currentAnimIndex];
|
||||
}
|
||||
|
||||
void AnimationsComponent::setCurrentAnimFrameCounter(size_t animFrameCounter)
|
||||
{
|
||||
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(animFrameCounter);
|
||||
}
|
||||
|
||||
void AnimationsComponent::resetCurrentAnimFrameCounter()
|
||||
{
|
||||
this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0);
|
||||
}
|
||||
|
||||
size_t AnimationsComponent::getCurrentAnimIndex() const
|
||||
{
|
||||
return this->_currentAnimIndex;
|
||||
}
|
||||
|
||||
void AnimationsComponent::setAnimIndex(int animIndex)
|
||||
{
|
||||
this->_currentAnimIndex = animIndex % static_cast<int>(this->_modelAnimation.getAnimationsCount());
|
||||
}
|
||||
|
||||
void AnimationsComponent::incCurrentAnimFrameCounter()
|
||||
{
|
||||
this->_modelAnimation[this->_currentAnimIndex].incrementFrameCounter();
|
||||
}
|
||||
|
||||
void AnimationsComponent::setAnimDisabled(bool disable)
|
||||
{
|
||||
this->_animDisabled = disable;
|
||||
}
|
||||
|
||||
bool AnimationsComponent::isAnimDisabled() const
|
||||
{
|
||||
return this->_animDisabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// Created by cbihan on 01/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <Model/ModelAnimations.hpp>
|
||||
#include <Component/Component.hpp>
|
||||
#include <Entity/Entity.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class AnimationsComponent : public WAL::Component
|
||||
{
|
||||
private:
|
||||
//! @brief To get the animation data
|
||||
RAY::ModelAnimations _modelAnimation;
|
||||
//! @brief The index of the
|
||||
int _currentAnimIndex;
|
||||
//! @brief Bool allowing to play pause an animation
|
||||
bool _animDisabled;
|
||||
public:
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief get the current animation index
|
||||
size_t getCurrentAnimIndex() const;
|
||||
|
||||
//! @brief Set the animation index to use
|
||||
void setAnimIndex(int animIndex);
|
||||
|
||||
//! @brief get animation frame counter
|
||||
size_t getCurrentAnimFrameCounter() const;
|
||||
|
||||
//! @brief get the current
|
||||
RAY::ModelAnimation getCurrentModelAnim();
|
||||
|
||||
//! @brief set the anim frame counter
|
||||
void setCurrentAnimFrameCounter(size_t animFrameCounter);
|
||||
|
||||
//! @brief Set the internal anim counter to 0
|
||||
void resetCurrentAnimFrameCounter();
|
||||
|
||||
//! @brief Increment the internal anim counter
|
||||
void incCurrentAnimFrameCounter();
|
||||
|
||||
//! @brief Allow to play pause animations
|
||||
void setAnimDisabled(bool disable);
|
||||
|
||||
//! @brief To know if the animation will be updated or not
|
||||
bool isAnimDisabled() const;
|
||||
|
||||
//! @brief ctor entity and the path of the animation file
|
||||
explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play = true);
|
||||
//! @brief copy ctor
|
||||
AnimationsComponent(const AnimationsComponent &) = default;
|
||||
//! @brief dtor
|
||||
~AnimationsComponent() override = default;
|
||||
//! @brief assignment operator
|
||||
AnimationsComponent &operator=(const AnimationsComponent &) = delete;
|
||||
};
|
||||
}
|
||||
@@ -25,6 +25,9 @@
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Runner.hpp"
|
||||
#include "Models/GameState.hpp"
|
||||
#include <Model/ModelAnimations.hpp>
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "System/Animation/AnimationsSystem.hpp"
|
||||
#include "Map/Map.hpp"
|
||||
|
||||
namespace RAY2D = RAY::Drawables::Drawables2D;
|
||||
@@ -58,6 +61,7 @@ namespace BBM
|
||||
|
||||
wal.addSystem<Renderer3DSystem<RAY3D::Model>>();
|
||||
wal.addSystem<Renderer3DSystem<RAY3D::Cube>>();
|
||||
wal.addSystem<AnimationsSystem>();
|
||||
|
||||
wal.addSystem<Render2DScreenSystem>(window)
|
||||
.addSystem<Renderer2DSystem<RAY2D::Rectangle>>();
|
||||
@@ -72,6 +76,7 @@ namespace BBM
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 1)
|
||||
.addComponent<CollisionComponent>(2)
|
||||
.addComponent<MovableComponent>();
|
||||
scene->addEntity("cube")
|
||||
@@ -86,7 +91,7 @@ namespace BBM
|
||||
mov.resetVelocity();
|
||||
} catch (std::exception &e) { };
|
||||
}, 3);
|
||||
|
||||
|
||||
scene->addEntity("camera")
|
||||
.addComponent<PositionComponent>(8, 20, 7)
|
||||
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by cbihan on 01/06/2021.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "AnimationsSystem.hpp"
|
||||
#include "Component/Animation/AnimationsComponent.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
|
||||
AnimationsSystem::AnimationsSystem()
|
||||
: WAL::System({
|
||||
typeid(Drawable3DComponent<RAY::Drawables::Drawables3D::Model>),
|
||||
typeid(AnimationsComponent)
|
||||
})
|
||||
{
|
||||
}
|
||||
|
||||
void AnimationsSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds)
|
||||
{
|
||||
auto &model = entity.getComponent<Drawable3DComponent<RAY::Drawables::Drawables3D::Model>>();
|
||||
auto &anim = entity.getComponent<AnimationsComponent>();
|
||||
|
||||
if (anim.isDisabled())
|
||||
return;
|
||||
model.member.setAnimation(anim.getCurrentModelAnim());
|
||||
anim.incCurrentAnimFrameCounter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by cbihan on 01/06/2021.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <System/System.hpp>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class AnimationsSystem : public WAL::System
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds) override;
|
||||
|
||||
//! @brief A default constructor
|
||||
AnimationsSystem();
|
||||
//! @brief A Controllable system is copy constructable
|
||||
AnimationsSystem(const AnimationsSystem &) = default;
|
||||
//! @brief A default destructor
|
||||
~AnimationsSystem() override = default;
|
||||
//! @brief A Controllable system is assignable.
|
||||
AnimationsSystem &operator=(const AnimationsSystem &) = default;
|
||||
};
|
||||
}
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
float ControllableSystem::speed = .25f;
|
||||
|
||||
ControllableSystem::ControllableSystem()
|
||||
: WAL::System({
|
||||
typeid(ControllableComponent),
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace BBM
|
||||
{
|
||||
public:
|
||||
//! @brief The speed applied to every controllable entities.
|
||||
static float speed;
|
||||
static constexpr const float speed = .25f;
|
||||
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
Reference in New Issue
Block a user