Kajetan Johannes Hammerle před 3 roky
rodič
revize
edc52f9db4

+ 6 - 2
common/block/BlockRegistry.cpp

@@ -7,7 +7,7 @@ BlockRegistry::BlockRegistry() {
     add("grass");
 }
 
-void BlockRegistry::forEach(void(*f)(const Block&)) const {
+void BlockRegistry::forEach(void (*f)(const Block&)) const {
     for(const Block& b : blocks) {
         f(b);
     }
@@ -20,7 +20,11 @@ void BlockRegistry::add(const char* registry) {
 }
 
 const Block& BlockRegistry::getBlock(const BlockName& registry) const {
-    return blocks[registryToId.search(registry, 0)];
+    const BlockId* id = registryToId.search(registry);
+    if(id == nullptr) {
+        return blocks[0];
+    }
+    return blocks[*id];
 }
 
 const Block& BlockRegistry::getBlock(BlockId id) const {

+ 1 - 3
common/block/BlockRegistry.h

@@ -16,10 +16,8 @@ public:
 private:
     void add(const char* registry);
 
-    static constexpr int MAX_BLOCKS = 4096;
-
     List<Block> blocks;
-    HashMap<BlockName, BlockId, MAX_BLOCKS> registryToId;
+    HashMap<BlockName, BlockId> registryToId;
 };
 
 #endif

+ 1 - 1
gaming-core

@@ -1 +1 @@
-Subproject commit 3f19a9343926b7ee3dc8c8fca6c503062adc6a0b
+Subproject commit c836197dbc6de9b4e68aacd06b1a6d95d9d14c87

+ 3 - 6
server/commands/CommandManager.cpp

@@ -13,9 +13,6 @@ static void commandStop(ServerState& sc, const CommandArguments&) {
     sc.running = false;
 }
 
-static void commandEmpty(ServerState&, const CommandArguments&) {
-}
-
 CommandManager::CommandManager() {
     commands.add("test", commandTest);
     commands.add("stop", commandStop);
@@ -29,10 +26,10 @@ void CommandManager::execute(ServerState& sc, const RawCommand& rawCommand) {
     }
 
     CommandName command(args[0]);
-    Command c = commands.search(command, commandEmpty);
-    if(c == commandEmpty) {
+    Command* c = commands.search(command);
+    if(c == nullptr) {
         std::cout << "Unknown command: '" << command << "'" << std::endl;
         return;
     }
-    c(sc, args);
+    (*c)(sc, args);
 }

+ 5 - 5
server/commands/CommandManager.h

@@ -1,20 +1,20 @@
 #ifndef COMMANDMANAGER_H
 #define COMMANDMANAGER_H
 
-#include "server/commands/ServerState.h"
-#include "server/commands/CommandTypes.h"
 #include "gaming-core/utils/HashMap.h"
+#include "server/commands/CommandTypes.h"
+#include "server/commands/ServerState.h"
 
 class CommandManager {
 public:
     CommandManager();
 
     void execute(ServerState& sc, const RawCommand& rawCommand);
-    
+
 private:
-    typedef void (*Command) (ServerState&, const CommandArguments&);
+    typedef void (*Command)(ServerState&, const CommandArguments&);
 
-    HashMap<CommandName, Command, 16> commands;
+    HashMap<CommandName, Command> commands;
 };
 
 #endif