BlockRegistry.h 586 B

1234567891011121314151617181920212223242526
  1. #ifndef BLOCKREGISTRY_H
  2. #define BLOCKREGISTRY_H
  3. #include <vector>
  4. #include <unordered_map>
  5. #include "common/utils/HashedString.h"
  6. #include "common/block/Block.h"
  7. class BlockRegistry {
  8. public:
  9. BlockRegistry();
  10. const Block& getBlock(const HashedString& registry) const;
  11. const Block& getBlock(u16 id) const;
  12. private:
  13. void add(const char* registry, const BlockBuilder& builder);
  14. std::vector<Block> blocks;
  15. struct Hasher {
  16. size_t operator()(const HashedString& key) const;
  17. };
  18. std::unordered_map<HashedString, u16, Hasher> registryToId;
  19. };
  20. #endif