瀏覽代碼

simple block handling

Kajetan Johannes Hammerle 3 年之前
父節點
當前提交
8eff92beaf

+ 1 - 5
common/block/Block.cpp

@@ -1,10 +1,6 @@
 #include "common/block/Block.h"
 
-Block::Block() : id(0), registry("") {
-}
-
-Block::Block(BlockId id, const BlockName& registry, const BlockBuilder& builder) : id(id), registry(registry) {
-    (void) builder;
+Block::Block(BlockId id, const BlockName& registry) : id(id), registry(registry) {
 }
 
 BlockId Block::getId() const {

+ 5 - 7
common/block/Block.h

@@ -2,18 +2,16 @@
 #define BLOCK_H
 
 #include "common/block/BlockTypes.h"
-#include "common/block/BlockBuilder.h"
 
 class Block final {
+    BlockId id;
+    BlockName registry;
+    
 public:
-    Block();
-    Block(BlockId id, const BlockName& registry, const BlockBuilder& builder);
+    Block(BlockId id, const BlockName& registry);
+    
     BlockId getId() const;
     const BlockName& getRegistry() const;
-
-private:
-    BlockId id;
-    BlockName registry;
 };
 
 #endif

+ 0 - 8
common/block/BlockBuilder.cpp

@@ -1,8 +0,0 @@
-#include "common/block/BlockBuilder.h"
-
-BlockBuilder::BlockBuilder() {
-}
-
-BlockBuilder& BlockBuilder::test() {
-    return *this;
-}

+ 0 - 10
common/block/BlockBuilder.h

@@ -1,10 +0,0 @@
-#ifndef BLOCKBUILDER_H
-#define BLOCKBUILDER_H
-
-class BlockBuilder final {
-public:
-    BlockBuilder();
-    BlockBuilder& test();
-};
-
-#endif

+ 6 - 6
common/block/BlockRegistry.cpp

@@ -1,10 +1,10 @@
 #include "common/block/BlockRegistry.h"
 
 BlockRegistry::BlockRegistry() {
-    add("air", BlockBuilder());
-    add("stone", BlockBuilder());
-    add("dirt", BlockBuilder());
-    add("grass", BlockBuilder());
+    add("air");
+    add("stone");
+    add("dirt");
+    add("grass");
 }
 
 void BlockRegistry::forEach(void(*f)(const Block&)) const {
@@ -13,9 +13,9 @@ void BlockRegistry::forEach(void(*f)(const Block&)) const {
     }
 }
 
-void BlockRegistry::add(const char* registry, const BlockBuilder& builder) {
+void BlockRegistry::add(const char* registry) {
     BlockId id = blocks.getLength();
-    blocks.add(Block(id, registry, builder));
+    blocks.add(id, registry);
     registryToId.add(registry, id);
 }
 

+ 1 - 1
common/block/BlockRegistry.h

@@ -14,7 +14,7 @@ public:
     const Block& getBlock(BlockId id) const;
 
 private:
-    void add(const char* registry, const BlockBuilder& builder);
+    void add(const char* registry);
 
     static constexpr int MAX_BLOCKS = 4096;
 

+ 2 - 3
common/block/BlockTypes.h

@@ -2,10 +2,9 @@
 #define BLOCKTYPES_H
 
 #include "gaming-core/utils/StringBuffer.h"
+#include "gaming-core/utils/Types.h"
 
 typedef StringBuffer<32> BlockName;
-typedef unsigned short BlockId;
-
-static_assert(sizeof(BlockId) == 2, "size of block id must be 2 bytes");
+typedef uint16 BlockId;
 
 #endif

+ 0 - 1
meson.build

@@ -2,7 +2,6 @@ project('cubes plus plus', 'cpp')
 
 sourcesCommon = [
     'common/network/Packet.cpp', 
-    'common/block/BlockBuilder.cpp', 
     'common/block/Block.cpp', 
     'common/block/BlockRegistry.cpp', 
     'gaming-core/utils/Random.cpp',