Components.h 837 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "utils/HashMap.h"
  2. #include "utils/List.h"
  3. #include "utils/Types.h"
  4. typedef uint32 Entity;
  5. template<typename T>
  6. class Components final {
  7. HashMap<Entity, T> components;
  8. public:
  9. Components() {
  10. }
  11. template<typename... Args>
  12. void add(Entity e, Args&&... args) {
  13. components.tryEmplace(e, std::forward<Args>(args)...);
  14. }
  15. void remove(Entity e) {
  16. components.remove(e);
  17. }
  18. T* search(Entity e) {
  19. return components.search(e);
  20. }
  21. const T* search(Entity e) const {
  22. return components.search(e);
  23. }
  24. auto begin() {
  25. return components.begin();
  26. }
  27. const auto begin() const {
  28. return components.begin();
  29. }
  30. auto end() {
  31. return components.end();
  32. }
  33. const auto end() const {
  34. return components.end();
  35. }
  36. };