-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
253 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include <string_view> | ||
|
||
namespace Ubpa { | ||
class World; | ||
class SystemMngr; | ||
class EntityMngr; | ||
class Entity; | ||
class CmptPtr; | ||
|
||
class IListener { | ||
public: | ||
virtual void EnterWorld(const World* w) = 0; | ||
virtual void ExistWorld(const World* w) = 0; | ||
|
||
virtual void EnterSystemMngr(const SystemMngr* sm) = 0; | ||
virtual void ExistSystemMngr(const SystemMngr* sm) = 0; | ||
|
||
virtual void EnterSystem(std::string_view s) = 0; | ||
virtual void ExistSystem(std::string_view s) = 0; | ||
|
||
virtual void EnterEntityMngr(const EntityMngr* em) = 0; | ||
virtual void ExistEntityMngr(const EntityMngr* em) = 0; | ||
|
||
virtual void EnterEntity(const Entity* e) = 0; | ||
virtual void ExistEntity(const Entity* e) = 0; | ||
|
||
virtual void EnterCmptPtr(const CmptPtr* cmpt) = 0; | ||
virtual void ExistCmptPtr(const CmptPtr* cmpt) = 0; | ||
}; | ||
} |
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,14 @@ | ||
#include <UECS/SystemMngr.h> | ||
|
||
#include <UECS/IListener.h> | ||
|
||
using namespace Ubpa; | ||
|
||
void SystemMngr::Accept(IListener* listener) const { | ||
listener->EnterSystemMngr(this); | ||
for (const auto& [n, f] : onUpdateMap) { | ||
listener->EnterSystem(n); | ||
listener->ExistSystem(n); | ||
} | ||
listener->ExistSystemMngr(this); | ||
} |
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,6 @@ | ||
Ubpa_GetTargetName(core "${PROJECT_SOURCE_DIR}/src/core") | ||
Ubpa_AddTarget( | ||
TEST | ||
MODE EXE | ||
LIB ${core} | ||
) |
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,162 @@ | ||
#include <UECS/World.h> | ||
#include <UECS/IListener.h> | ||
|
||
#include <iostream> | ||
|
||
using namespace Ubpa; | ||
using namespace std; | ||
|
||
struct Position { float val; }; | ||
struct Velocity { float val; }; | ||
|
||
class Dumper : public IListener { | ||
size_t indent{ 0 }; | ||
bool firstSystem{ true }; | ||
bool firstEntity{ true }; | ||
bool firstCmpt{ true }; | ||
|
||
void PrintIndent() { | ||
for (size_t i = 0; i < indent; i++) | ||
cout << " "; | ||
} | ||
|
||
// new line | ||
virtual void EnterWorld(const World* w) override { | ||
cout << "{" << endl; | ||
indent++; | ||
PrintIndent(); | ||
cout << "\"type\" : \"World\"," << endl; | ||
} | ||
|
||
virtual void ExistWorld(const World* w) override { | ||
indent--; | ||
cout << "}"; | ||
} | ||
|
||
virtual void EnterSystemMngr(const SystemMngr* sm) override { | ||
PrintIndent(); | ||
cout << "\"systemMngr\" : {" << endl; | ||
indent++; | ||
PrintIndent(); | ||
cout << "\"type\" : \"SystemMngr\"," << endl; | ||
PrintIndent(); | ||
cout << "\"systems\" : ["; | ||
indent++; | ||
firstSystem = true; | ||
} | ||
|
||
virtual void ExistSystemMngr(const SystemMngr* sm) override { | ||
cout << endl; | ||
indent--; | ||
PrintIndent(); | ||
cout << "]" << endl; | ||
indent--; | ||
PrintIndent(); | ||
cout << "}," << endl; | ||
} | ||
|
||
virtual void EnterSystem(std::string_view s) override { | ||
if (!firstSystem) | ||
cout << ","; | ||
else | ||
firstSystem = false; | ||
cout << endl; | ||
PrintIndent(); | ||
cout << "\"" << s << "\""; | ||
} | ||
|
||
virtual void ExistSystem(std::string_view s) override { | ||
|
||
} | ||
|
||
virtual void EnterEntityMngr(const EntityMngr* em) override { | ||
PrintIndent(); | ||
cout << "\"entityMngr\" : {" << endl; | ||
indent++; | ||
PrintIndent(); | ||
cout << "\"type\" : \"EntityMngr\"," << endl; | ||
PrintIndent(); | ||
cout << "\"entities\" : ["; | ||
indent++; | ||
firstEntity = true; | ||
} | ||
|
||
virtual void ExistEntityMngr(const EntityMngr* em) override { | ||
cout << endl; | ||
indent--; | ||
PrintIndent(); | ||
cout << "]" << endl; | ||
indent--; | ||
PrintIndent(); | ||
cout << "}" << endl; | ||
} | ||
|
||
virtual void EnterEntity(const Entity* e) override { | ||
if (!firstEntity) | ||
cout << ","; | ||
else | ||
firstEntity = false; | ||
cout << endl; | ||
PrintIndent(); | ||
cout << "{" << endl; | ||
indent++; | ||
PrintIndent(); | ||
cout << "\"type\" : \"Entity\"," << endl; | ||
PrintIndent(); | ||
cout << "\"components\" : [" << endl; | ||
indent++; | ||
firstCmpt = true; | ||
} | ||
|
||
virtual void ExistEntity(const Entity* e) override { | ||
cout << endl; | ||
indent--; | ||
PrintIndent(); | ||
cout << "]" << endl; | ||
indent--; | ||
PrintIndent(); | ||
cout << "}"; | ||
} | ||
|
||
virtual void EnterCmptPtr(const CmptPtr* cmpt) override { | ||
if (!firstCmpt) | ||
cout << ","; | ||
else | ||
firstCmpt = false; | ||
cout << endl; | ||
PrintIndent(); | ||
cout << "{" << endl; | ||
indent++; | ||
PrintIndent(); | ||
cout << "\"type\" : \"" << RTDCmptTraits::Instance().Nameof(cmpt->Type()) << "\""; | ||
} | ||
|
||
virtual void ExistCmptPtr(const CmptPtr* cmpt) override { | ||
cout << endl; | ||
indent--; | ||
PrintIndent(); | ||
cout << "}"; | ||
} | ||
}; | ||
|
||
struct MoverSystem { | ||
static void OnUpdate(Schedule& schedule) { | ||
schedule.Register( | ||
[](const Velocity* v, Position* p) { | ||
p->val += v->val; | ||
}, "Mover"); | ||
} | ||
}; | ||
|
||
int main() { | ||
World w; | ||
RTDCmptTraits::Instance().Register<Position, Velocity>(); | ||
w.systemMngr.Register<MoverSystem>(); | ||
w.entityMngr.Create<Position, Velocity>(); | ||
w.entityMngr.Create<Position>(); | ||
w.entityMngr.Create<Velocity>(); | ||
w.entityMngr.Create<>(); | ||
w.Update(); | ||
Dumper dumper; | ||
w.Accept(&dumper); | ||
} |