BlockRegistry.h 622 B

12345678910111213141516171819202122232425
  1. #ifndef BLOCKREGISTRY_H
  2. #define BLOCKREGISTRY_H
  3. #include "common/utils/List.h"
  4. #include "common/utils/HashedString.h"
  5. #include "common/utils/HashMap.h"
  6. #include "common/block/Block.h"
  7. class BlockRegistry final {
  8. public:
  9. BlockRegistry();
  10. void forEach(void (*f) (const Block&)) const;
  11. const Block& getBlock(const HashedString& registry) const;
  12. const Block& getBlock(u16 id) const;
  13. private:
  14. void add(const char* registry, const BlockBuilder& builder);
  15. static constexpr uint MAX_BLOCKS = 4096;
  16. List<Block, MAX_BLOCKS> blocks;
  17. HashMap<HashedString, u16, MAX_BLOCKS> registryToId;
  18. };
  19. #endif