From 9c1f7b20394808f7ec7a6cadd9e0dd665c6f6bd5 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 10 Mar 2015 18:39:05 +0100 Subject: [PATCH] decrease block id size --- src/block.cpp | 2 +- src/block.hpp | 37 +++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/block.cpp b/src/block.cpp index 50c4a4f..b0de21a 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -28,7 +28,7 @@ BlockTypeRegistry::BlockTypeRegistry() { Add(BlockType()); } -int BlockTypeRegistry::Add(const BlockType &t) { +Block::Type BlockTypeRegistry::Add(const BlockType &t) { int id = types.size(); types.push_back(t); types.back().id = id; diff --git a/src/block.hpp b/src/block.hpp index 1c1dddb..5d8e7e7 100644 --- a/src/block.hpp +++ b/src/block.hpp @@ -11,10 +11,24 @@ namespace blank { +/// single 1x1x1 cube +struct Block { + + using Type = unsigned short; + using Pos = glm::vec3; + + Type type; + + constexpr explicit Block(Type type = 0) + : type(type) { } + +}; + + /// attributes of a type of block struct BlockType { - int id; + Block::Type id; bool visible; @@ -27,7 +41,7 @@ struct BlockType { const glm::vec3 &color = { 1, 1, 1 }, const Shape *shape = &DEFAULT_SHAPE, const glm::vec3 &outline_color = { -1, -1, -1 }) - : id(-1), visible(v), shape(shape), color(color), outline_color(outline_color) { } + : id(0), visible(v), shape(shape), color(color), outline_color(outline_color) { } static const NullShape DEFAULT_SHAPE; @@ -52,31 +66,18 @@ public: BlockTypeRegistry(); public: - int Add(const BlockType &); + Block::Type Add(const BlockType &); size_t Size() const { return types.size(); } - BlockType *operator [](int id) { return &types[id]; } - const BlockType *Get(int id) const { return &types[id]; } + BlockType *operator [](Block::Type id) { return &types[id]; } + const BlockType *Get(Block::Type id) const { return &types[id]; } private: std::vector types; }; - -/// single 1x1x1 cube -struct Block { - - using Pos = glm::vec3; - - int type; - - constexpr explicit Block(int type = 0) - : type(type) { } - -}; - } #endif -- 2.39.2