-
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.
Rework HierarchySystem -> NodeSystem + Add RenderingSystem
- Loading branch information
1 parent
badaaa4
commit 8cc56d8
Showing
23 changed files
with
425 additions
and
337 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
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
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
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
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 @@ | ||
// | ||
// Created by Tristan Klempka on 25/07/2024. | ||
// | ||
|
||
#ifndef ENTITYFACTORY_H | ||
#define ENTITYFACTORY_H | ||
|
||
#include <SFML/Graphics/CircleShape.hpp> // for CircleShape | ||
#include <SFML/Graphics/Color.hpp> // for Color | ||
#include <SFML/Graphics/RectangleShape.hpp> // for RectangleShape | ||
#include <SFML/System/Vector2.hpp> // for Vector2f | ||
#include <memory> // for unique_ptr | ||
#include "Entity.h" // for Entity | ||
class World; | ||
|
||
class EntityFactory { | ||
public: | ||
explicit EntityFactory(World& world); | ||
|
||
[[nodiscard]] Entity::Id createCircleEntity(float radius, sf::Color fillColor, sf::Color outlineColor = sf::Color::Transparent, float outlineThickness = 0.0f) const; | ||
[[nodiscard]] Entity::Id createRectangleEntity(const sf::Vector2f& size, const sf::Color& fillColor, const sf::Color& outlineColor = sf::Color::Transparent, float outlineThickness = 0.0f) const; | ||
|
||
private: | ||
World& world; | ||
|
||
static std::unique_ptr<sf::CircleShape> createCircle(float radius, sf::Color fillColor, sf::Color outlineColor = sf::Color::Transparent, float outlineThickness = 0.0f); | ||
static std::unique_ptr<sf::RectangleShape> createRectangle(const sf::Vector2f& size, const sf::Color& fillColor, const sf::Color& outlineColor = sf::Color::Transparent, float outlineThickness = 0.0f); | ||
}; | ||
|
||
#endif // ENTITYFACTORY_H |
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
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
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
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 @@ | ||
// | ||
// Created by Tristan Klempka on 25/07/2024. | ||
// | ||
|
||
#ifndef PHYSICSYSTEM_H | ||
#define PHYSICSYSTEM_H | ||
|
||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include <vector> | ||
#include <iostream> | ||
|
||
#include "System.h" | ||
#include "Entity.h" | ||
#include "EventDispatcher.h" | ||
#include "World.h" | ||
#include "components/Node.h" | ||
#include "components/Velocity.h" | ||
|
||
class PhysicsSystem : public System { | ||
public: | ||
using QueryFunction = std::function<void(std::function<void(Entity::Id, Node&, const Velocity&)>, | ||
std::optional<std::unordered_set<Entity::Id>>)>; | ||
|
||
explicit PhysicsSystem(World& world, EventDispatcher& dispatcher) | ||
: m_query(world.getComponentQuery<Node, Velocity>()), m_dispatcher(dispatcher) {} | ||
|
||
void update() override { | ||
m_query([this](const Entity::Id id, Node& node, const Velocity& velocity) { | ||
node.transform = node.transform.rotate(velocity.dtheta).translate(velocity.dx, velocity.dy); | ||
m_dispatcher.dispatch(EventBuilder(EventType::TransformChanged, id).build()); | ||
}, std::nullopt); | ||
} | ||
|
||
private: | ||
QueryFunction m_query; | ||
EventDispatcher& m_dispatcher; | ||
}; | ||
|
||
#endif //PHYSICSYSTEM_H |
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,38 @@ | ||
// | ||
// Created by Tristan Klempka on 25/07/2024. | ||
// | ||
|
||
#ifndef RENDERINGSYSTEM_H | ||
#define RENDERINGSYSTEM_H | ||
|
||
#include <functional> // for function | ||
#include <optional> // for optional | ||
#include <unordered_map> // for unordered_map | ||
#include <unordered_set> // for unordered_set | ||
#include "Entity.h" // for Entity | ||
#include "System.h" // for System | ||
#include "components/Node.h" // for Node | ||
#include "components/Shape.h" // for Shape | ||
class World; | ||
namespace sf { class Drawable; } | ||
namespace sf { class RenderWindow; } | ||
namespace sf { class Transform; } | ||
|
||
class RenderingSystem : public System { | ||
public: | ||
using QueryFunction = std::function<void(std::function<void(Entity::Id, Node&, Shape&)>, | ||
std::optional<std::unordered_set<Entity::Id>>)>; | ||
|
||
explicit RenderingSystem(World& world, sf::RenderWindow& window); | ||
|
||
void update() override; | ||
|
||
private: | ||
QueryFunction m_query; | ||
sf::RenderWindow& m_window; | ||
std::unordered_map<Entity::Id, sf::Drawable*> m_renderables; | ||
|
||
void doDraw(Entity::Id id, const sf::Transform& parentTransform); | ||
}; | ||
|
||
#endif // RENDERINGSYSTEM_H |
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
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,27 @@ | ||
// | ||
// Created by Tristan Klempka on 26/07/2024. | ||
// | ||
|
||
#ifndef TRANSFORMMANAGER_H | ||
#define TRANSFORMMANAGER_H | ||
|
||
#include <functional> // for function | ||
#include <optional> // for optional | ||
#include <unordered_set> // for unordered_set | ||
#include "Entity.h" // for Entity | ||
class World; | ||
struct Node; | ||
|
||
class TransformManager { | ||
public: | ||
explicit TransformManager(World& world); | ||
|
||
void applyRotation(Entity::Id entityId, float angle) const; | ||
void applyTranslation(Entity::Id entityId, float x, float y) const; | ||
void applyTransformation(Entity::Id entityId, float angle, float x, float y) const; | ||
|
||
private: | ||
std::function<void(std::function<void(Entity::Id, Node&)>, std::optional<std::unordered_set<Entity::Id>>)> m_query; | ||
}; | ||
|
||
#endif // TRANSFORMMANAGER_H |
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
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
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.