-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from MasterLaplace/54-imlement-a-game-class-in…
…-flakkari-server 54 implement a game class in flakkari server
- Loading branch information
Showing
19 changed files
with
729 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Flakkari/Engine/EntityComponentSystem/Components/2D/Movable.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Title: Flakkari | ||
** Author: MasterLaplace | ||
** Created: 2023-01-06 | ||
** File description: | ||
** Movable | ||
*/ | ||
|
||
#ifndef MOVABLE_HPP_ | ||
#define MOVABLE_HPP_ | ||
|
||
#include "../../../Math/Vector.hpp" | ||
|
||
namespace Flakkari::Engine::ECS::Components::_2D { | ||
|
||
struct Movable { | ||
Math::Vector2d velocity; // pixels / second | ||
double angularVelocity; // degrees / second | ||
Math::Vector2d acceleration; // pixels / second^2 | ||
double angularAcceleration; // degrees / second^2 | ||
|
||
Movable() : velocity(0, 0), acceleration(0, 0) {}; | ||
Movable(const Math::Vector2d &velocity, const Math::Vector2d &acceleration) : velocity(velocity), acceleration(acceleration) {}; | ||
Movable(const Movable &other) : velocity(other.velocity), acceleration(other.acceleration) {}; | ||
}; | ||
|
||
} // namespace Game::ECS::Components::_2D | ||
|
||
#endif /* !MOVABLE_HPP_ */ |
29 changes: 29 additions & 0 deletions
29
Flakkari/Engine/EntityComponentSystem/Components/2D/Transform.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Title: Flakkari | ||
** Author: MasterLaplace | ||
** Created: 2023-01-06 | ||
** File description: | ||
** Transform | ||
*/ | ||
|
||
#ifndef TRANSFORM_HPP_ | ||
#define TRANSFORM_HPP_ | ||
|
||
#include "../../../Math/Vector.hpp" | ||
|
||
namespace Flakkari::Engine::ECS::Components::_2D { | ||
|
||
struct Transform { | ||
Math::Vector2d position; | ||
Math::Vector2d scale; | ||
double rotation; | ||
|
||
Transform() : position(0, 0), scale(1, 1), rotation(0) {}; | ||
Transform(const Math::Vector2d &position, const Math::Vector2d &scale, double rotation) : position(position), scale(scale), rotation(rotation) {}; | ||
Transform(const Transform &other) : position(other.position), scale(other.scale), rotation(other.rotation) {}; | ||
}; | ||
|
||
} // namespace Game::ECS::Components::_2D | ||
|
||
#endif /* !TRANSFORM_HPP_ */ |
33 changes: 33 additions & 0 deletions
33
Flakkari/Engine/EntityComponentSystem/Components/Common/Child.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Title: Flakkari | ||
** Author: MasterLaplace | ||
** Created: 2023-01-06 | ||
** File description: | ||
** Child | ||
*/ | ||
|
||
#ifndef CHILD_HPP_ | ||
#define CHILD_HPP_ | ||
|
||
#include <string> | ||
|
||
namespace Flakkari::Engine::ECS::Components::Common { | ||
|
||
/** | ||
* @brief Child component for ECS entities that have a child entity attached to them | ||
* | ||
* @details This component is used to create a child entity based on a prefab | ||
* and attach it to the entity that has this component | ||
*/ | ||
struct Child { | ||
std::string name; | ||
|
||
Child() : name("") {} | ||
Child(const std::string &name) : name(name) {} | ||
Child(const Child &other) : name(other.name) {} | ||
}; | ||
|
||
} // namespace Flakkari::Engine::ECS::Components::Common | ||
|
||
#endif /* !CHILD_HPP_ */ |
32 changes: 32 additions & 0 deletions
32
Flakkari/Engine/EntityComponentSystem/Components/Common/Parent.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Title: Flakkari | ||
** Author: MasterLaplace | ||
** Created: 2023-01-06 | ||
** File description: | ||
** Parent | ||
*/ | ||
|
||
#ifndef PARENT_HPP_ | ||
#define PARENT_HPP_ | ||
|
||
#include <string> | ||
|
||
namespace Flakkari::Engine::ECS::Components::Common { | ||
|
||
/** | ||
* @brief Parent component for ECS entities that have a parent entity attached to them | ||
* | ||
* @details This component is used to store the parent entity of an entity in the ECS | ||
*/ | ||
struct Parent { | ||
std::size_t entity; | ||
|
||
Parent() : entity(0) {} | ||
Parent(const std::size_t &entity) : entity(entity) {} | ||
Parent(const Parent &other) : entity(other.entity) {} | ||
}; | ||
|
||
} // namespace Flakkari::Engine::ECS::Components::Common | ||
|
||
#endif /* !PARENT_HPP_ */ |
32 changes: 32 additions & 0 deletions
32
Flakkari/Engine/EntityComponentSystem/Components/Common/Tag.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Title: Flakkari | ||
** Author: MasterLaplace | ||
** Created: 2023-01-06 | ||
** File description: | ||
** Tag | ||
*/ | ||
|
||
#ifndef TAG_HPP_ | ||
#define TAG_HPP_ | ||
|
||
#include <string> | ||
|
||
namespace Flakkari::Engine::ECS::Components::Common { | ||
|
||
/** | ||
* @brief Tag component for ECS entities that have a script attached to them | ||
* | ||
* @details This component is used to store the path to the script that will be executed | ||
*/ | ||
struct Tag { | ||
std::string tag; | ||
|
||
Tag() : tag("") {} | ||
Tag(const std::string &tag) : tag(tag) {} | ||
Tag(const Tag &other) : tag(other.tag) {} | ||
}; | ||
|
||
} // namespace Game::ECS::Components::Common | ||
|
||
#endif /* !TAG_HPP_ */ |
22 changes: 22 additions & 0 deletions
22
Flakkari/Engine/EntityComponentSystem/Components/Components2D.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/************************************************************************** | ||
* Flakkari Engine Library v0.1.0 | ||
* | ||
* Flakkari Library is a C++ Library for Network. | ||
* @file Components2D.hpp | ||
* @brief Components2D header. Contains all 2D components. | ||
* (Collider, Movable, RigidBody, Transform) | ||
* | ||
* Flakkari Library is under MIT License. | ||
* https://opensource.org/licenses/MIT | ||
* © 2023 @MasterLaplace | ||
* @version 0.1.0 | ||
* @date 2023-01-06 | ||
**************************************************************************/ | ||
|
||
#ifndef COMPONENTS2D_HPP_ | ||
#define COMPONENTS2D_HPP_ | ||
|
||
#include "2D/Movable.hpp" // Movable component (velocity, angularVelocity, acceleration, angularAcceleration) | ||
#include "2D/Transform.hpp" // Transform component (position, rotation, scale) | ||
|
||
#endif /* !COMPONENTS2D_HPP_ */ |
22 changes: 22 additions & 0 deletions
22
Flakkari/Engine/EntityComponentSystem/Components/ComponentsCommon.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/************************************************************************** | ||
* Flakkari Engine Library v0.1.0 | ||
* | ||
* Flakkari Library is a C++ Library for Network. | ||
* @file ComponentsCommon.hpp | ||
* @brief ComponentsCommon header. Contains all common components. | ||
* (Parent, Tag) | ||
* | ||
* Flakkari Library is under MIT License. | ||
* https://opensource.org/licenses/MIT | ||
* © 2023 @MasterLaplace | ||
* @version 0.1.0 | ||
* @date 2023-01-06 | ||
**************************************************************************/ | ||
|
||
#ifndef COMPONENTSCOMMON_HPP_ | ||
#define COMPONENTSCOMMON_HPP_ | ||
|
||
#include "Common/Parent.hpp" // Parent component (entity) | ||
#include "Common/Tag.hpp" // Tag component (tag) | ||
|
||
#endif /* !COMPONENTSCOMMON_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Title: Flakkari | ||
** Author: MasterLaplace | ||
** Created: 2023-01-06 | ||
** File description: | ||
** Systems | ||
*/ | ||
|
||
#include "Systems.hpp" | ||
|
||
namespace Flakkari::Engine::ECS::Systems { | ||
|
||
void position(Registry &r, float deltaTime) | ||
{ | ||
if (!r.isRegistered<ECS::Components::_2D::Transform>() || !r.isRegistered<ECS::Components::_2D::Movable>()) | ||
return; | ||
auto& positions = r.getComponents<ECS::Components::_2D::Transform>(); | ||
auto& velocities = r.getComponents<ECS::Components::_2D::Movable>(); | ||
|
||
for (Entity i(0); i < positions.size() && i < velocities.size(); ++i) { | ||
auto& pos = positions[i]; | ||
auto& vel = velocities[i]; | ||
|
||
if (pos.has_value() && vel.has_value()) { | ||
pos->position.x += vel->velocity.dx * deltaTime * 0.5f * vel->acceleration.x * deltaTime * deltaTime; | ||
pos->position.y += vel->velocity.dy * deltaTime * 0.5f * vel->acceleration.y * deltaTime * deltaTime; | ||
vel->velocity.dx += vel->acceleration.x * deltaTime; | ||
vel->velocity.dy += vel->acceleration.y * deltaTime; | ||
} | ||
} | ||
} | ||
|
||
} // namespace Flakkari::Engine::ECS::Systems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/************************************************************************** | ||
* Flakkari Engine Library v0.1.0 | ||
* | ||
* Flakkari Library is a C++ Library for Network. | ||
* @file Systems.hpp | ||
* @brief Systems header. Contains all systems. | ||
* (position, rigid_body) | ||
* | ||
* Flakkari Library is under MIT License. | ||
* https://opensource.org/licenses/MIT | ||
* © 2023 @MasterLaplace | ||
* @version 0.1.0 | ||
* @date 2023-01-06 | ||
**************************************************************************/ | ||
|
||
#ifndef SYSTEMS_HPP_ | ||
#define SYSTEMS_HPP_ | ||
|
||
#include "../Registry.hpp" | ||
#include "../Components/Components2D.hpp" | ||
#include "../Components/ComponentsCommon.hpp" | ||
|
||
#include <cmath> | ||
#include <chrono> | ||
|
||
namespace Flakkari::Engine::ECS::Systems { | ||
|
||
/** | ||
* @brief Updates the position of all entities with a Position and a Movable component based on their velocity. | ||
* | ||
* @note The velocity vector is normalized following this advice: https://youtube.com/shorts/0cYjreg7dpg | ||
* | ||
* @param r The registry containing the entities to update. | ||
* @param deltaTime The time elapsed since the last update. | ||
*/ | ||
void position(Registry &r, float deltaTime); | ||
|
||
} // namespace Flakkari::Engine::ECS::Systems | ||
|
||
#endif /* !SYSTEMS_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.