-
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.
- Loading branch information
Showing
6 changed files
with
92 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,13 @@ build/ | |
.vs/ | ||
*.ini | ||
!dllTest/* | ||
|
||
#CMake | ||
*.vcxproj* | ||
CmakeCache* | ||
CmakeFiles/ | ||
Debug/ | ||
cmake_* | ||
*.dir/ | ||
*.sln | ||
x64/ |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,38 @@ | ||
#include <any> | ||
#include <typeinfo> | ||
#include <typeindex> | ||
#include <unordered_map> | ||
#include "SparseArray.hpp" | ||
#include <memory> | ||
|
||
class Registry { | ||
public: | ||
Registry(); | ||
~Registry(); | ||
template <class Component> | ||
using array = std::shared_ptr<SparseArray<Component>>; | ||
|
||
template <class Component> | ||
array<Component> registerComponent() | ||
{ | ||
if (_data.find(typeid(Component)) == _data.end()) { | ||
_data[typeid(Component)] = std::make_shared<SparseArray<Component>>(); | ||
} | ||
return castReturn<Component>(); | ||
}; | ||
template <class Component> | ||
array<Component> getComponents() | ||
{ | ||
return castReturn<Component>(); | ||
}; | ||
template <class Component> | ||
array<Component> const &getComponents() const | ||
{ | ||
return castReturn<Component>(); | ||
}; | ||
private: | ||
template<class Component> | ||
array<Component> castReturn() | ||
{ | ||
return std::any_cast<array<Component>>(_data[typeid(Component)]); | ||
} | ||
std::unordered_map<std::type_index, std::any> _data; | ||
}; |
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 @@ | ||
#include <iterator> | ||
#include <list> | ||
|
||
template <typename Component> | ||
class SparseArray { | ||
public: | ||
void add(Component component) | ||
{ | ||
_components.push_back(component); | ||
}; | ||
void erase(int id) | ||
{ | ||
auto it = _components.begin(); | ||
std::advance(it, id); | ||
_components.erase(it); | ||
}; | ||
Component &operator[](size_t idx) | ||
{ | ||
return _components[idx]; | ||
} | ||
|
||
std::list<Component>::iterator begin() | ||
{ | ||
return _components.begin(); | ||
} | ||
|
||
std::list<Component>::iterator end() | ||
{ | ||
return _components.end(); | ||
} | ||
private: | ||
std::list<Component> _components; | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,20 @@ | ||
#include <iostream> | ||
#include "Registry.hpp" | ||
|
||
int main() | ||
{ | ||
std::cout << "RTYPE POC" << std::endl; | ||
Registry registry; | ||
Registry::array<int> arrInt = registry.registerComponent<int>(); | ||
arrInt->add(4); | ||
arrInt->add(69); | ||
Registry::array<float> arrFloat = registry.registerComponent<float>(); | ||
arrFloat->add(69.69); | ||
Registry::array<float> scdContainer = registry.getComponents<float>(); | ||
for (auto begin = arrInt->begin(); begin != arrInt->end(); begin++) { | ||
std::cout << *begin << std::endl; | ||
} | ||
for (auto begin = scdContainer->begin(); begin != scdContainer->end(); begin++) { | ||
std::cout << *begin << std::endl; | ||
} | ||
return 0; | ||
} |