Skip to content

Commit

Permalink
feat: new gameplay framework
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyAndNotDown committed Dec 9, 2024
1 parent 23e0f27 commit 2184198
Show file tree
Hide file tree
Showing 7 changed files with 385 additions and 30 deletions.
63 changes: 45 additions & 18 deletions Engine/Source/Runtime/Include/Runtime/ECS.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace Runtime {

explicit System(ECRegistry& inRegistry);
virtual ~System();
virtual void Setup();
virtual void Execute(float inDeltaTimeMs);

protected:
Expand Down Expand Up @@ -138,6 +137,7 @@ namespace Runtime::Internal {
public:
explicit SystemFactory(SystemClass inClass);
Common::UniqueRef<System> Build(ECRegistry& inRegistry) const;
std::unordered_map<std::string, Mirror::Any> GetArguments();
const std::unordered_map<std::string, Mirror::Any>& GetArguments() const;

private:
Expand Down Expand Up @@ -319,7 +319,7 @@ namespace Runtime {
std::vector<Entity> entities;
};

class ECRegistry {
class MIRROR_API ECRegistry {
public:
using EntityTraverseFunc = Internal::EntityPool::EntityTraverseFunc;
using DynUpdateFunc = std::function<void(const Mirror::Any&)>;
Expand Down Expand Up @@ -347,13 +347,14 @@ namespace Runtime {
ECRegistry& operator=(const ECRegistry& inOther);
ECRegistry& operator=(ECRegistry&& inOther) noexcept;

void ResetTransients();

// entity
Entity Create();
void Destroy(Entity inEntity);
bool Valid(Entity inEntity) const;
size_t Size() const;
void Clear();
void ResetTransients();
void Each(const EntityTraverseFunc& inFunc) const;
ConstIter Begin() const;
ConstIter End() const;
Expand Down Expand Up @@ -440,41 +441,67 @@ namespace Runtime {
public:
explicit SystemGroup(std::string inName);

void AddSystem(SystemClass inClass);
Internal::SystemFactory& EmplaceSystem(SystemClass inClass);
void RemoveSystem(SystemClass inClass);
const std::string& GetName() const;
bool HasSystem(SystemClass inClass) const;
Internal::SystemFactory& GetSystem(SystemClass inClass);
const Internal::SystemFactory& GetSystem(SystemClass inClass) const;
auto GetSystems();
auto GetSystems() const;
const std::string& GetName() const;

private:
std::string name;
std::unordered_map<SystemClass, Internal::SystemFactory> systems;
};

class Feature {
class SystemGraph {
public:
Feature();
SystemGraph();

SystemGroup& AddSystemGroup(const std::string& inName);
SystemGroup& GetSystemGroup(const std::string& inName);
SystemGroup& AddGroup(const std::string& inName);
void RemoveGroup(const std::string& inName);
bool HasGroup(const std::string& inName) const;
SystemGroup& GetGroup(const std::string& inName);
const SystemGroup& GetGroup(const std::string& inName) const;
const std::vector<SystemGroup>& GetGroups() const;

private:
std::vector<SystemGroup> systemGroups;
};

class SystemRegistry {
class SystemPipeline {
public:
explicit SystemPipeline(const SystemGraph& inGraph);

private:
struct SystemContext {
const Internal::SystemFactory& factory;
Common::UniqueRef<System> instance;
};
using ActionFunc = std::function<void(SystemContext&)>;

void ParallelPerformAction(const ActionFunc& inActionFunc);

friend class SystemGraphExecutor;

std::vector<std::vector<SystemContext>> systemGraph;
};

class SystemGraphExecutor {
public:
SystemRegistry();
explicit SystemGraphExecutor(ECRegistry& inEcRegistry, const SystemGraph& inSystemGraph);
~SystemGraphExecutor();

SystemGroup& AddSystemGroup(const std::string& inName);
SystemGroup& GetSystemGroup(const std::string& inName);
void UseFeature(const Feature& inFeature);
NonCopyable(SystemGraphExecutor)
NonMovable(SystemGraphExecutor)

// TODO runtime
void Tick(float inDeltaTimeMs);

private:
std::vector<SystemGroup> systemGroups;
// transients
// TODO
ECRegistry& ecRegistry;
SystemGraph systemGraph;
SystemPipeline pipeline;
};
}

Expand Down
27 changes: 26 additions & 1 deletion Engine/Source/Runtime/Include/Runtime/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,48 @@

#pragma once

#include <cstdint>
#include <string>

#include <Common/Utility.h>
#include <Runtime/ECS.h>

namespace Runtime {
enum class PlayStatus : uint8_t {
stopped,
playing,
paused,
max
};

class World {
public:
NonCopyable(World)
NonMovable(World)
~World();

private:
friend class Engine;

explicit World(const std::string& inName = "");
// TODO play/stop/pause/status

void SetSystemGraph(const SystemGraph& inSystemGraph);
void Reset();
PlayStatus PlayStatus() const;
bool Stopped() const;
bool Playing() const;
bool Paused() const;
void Play();
void Resume();
void Pause();
void Stop();
void Tick(float inTimeMs);

std::string name;
Runtime::PlayStatus playStatus;
ECRegistry ecRegistry;
SystemGraph systemGraph;
std::optional<SystemGraphExecutor> executor;
};
}

Loading

0 comments on commit 2184198

Please sign in to comment.