#ifndef CONTENT_CONTENT_H_ #define CONTENT_CONTENT_H_ #include #include #include #include "../typedefs.h" class Block; class Content; class ContentBuilder { std::unordered_map blockDefs; std::vector blockIds; public: void add(Block* def); Content* build(); }; /* Runtime defs cache: indices */ class ContentIndices { // blockDefs must be a plain vector with block id used as index std::vector blockDefs; public: ContentIndices(std::vector blockDefs); inline Block* getBlockDef(blockid_t id) const { if (id >= blockDefs.size()) return nullptr; return blockDefs[id]; } inline size_t countBlockDefs() const { return blockDefs.size(); } // use this for critical spots to prevent range check overhead const Block* const* getBlockDefs() const { return blockDefs.data(); } }; /* Content is a definitions repository */ class Content { std::unordered_map blockDefs; public: ContentIndices* const indices; Content(ContentIndices* indices, std::unordered_map blockDefs); ~Content(); Block* require(std::string id) const; }; #endif // CONTENT_CONTENT_H_