| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include "Blocks.h"
- const int BlockRegistry::BLOCK_AMOUNT = 2;
- const Block* BlockRegistry::BLOCKS[BLOCK_AMOUNT];
- const BlockAir Blocks::AIR;
- const Block Blocks::GRASS;
- BlockRegistry::BlockRegistry()
- {
- }
- void BlockRegistry::registerBlock(const Block& block)
- {
- BlockId id = block.getId();
- if(id >= 0 && id < BLOCK_AMOUNT && BLOCKS[id] == nullptr)
- {
- BLOCKS[id] = █
- }
- }
- const Block& BlockRegistry::getBlockFromId(BlockId id)
- {
- return *BLOCKS[(id >= 0 && id < BLOCK_AMOUNT && BLOCKS[id] != nullptr) * id];
- }
- void BlockRegistry::init()
- {
- for(int i = 0; i < BLOCK_AMOUNT; i++)
- {
- BLOCKS[i] = nullptr;
- }
- }
- void BlockRegistry::registerBlocks()
- {
- init();
-
- registerBlock(Blocks::AIR);
- registerBlock(Blocks::GRASS);
- }
|