From de166e75a1d9835e2670da9314e206014551fa20 Mon Sep 17 00:00:00 2001 From: sapier Date: Sun, 15 Jan 2012 19:43:31 +0100 Subject: [PATCH] sao prototype global variables no longer depend on link order to be correctly added to factory --- src/serverobject.cpp | 12 ++++++------ src/serverobject.h | 9 ++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/serverobject.cpp b/src/serverobject.cpp index ca3d2c3b9..b5fd6fc3a 100644 --- a/src/serverobject.cpp +++ b/src/serverobject.cpp @@ -43,8 +43,8 @@ ServerActiveObject* ServerActiveObject::create(u8 type, const std::string &data) { // Find factory function - core::map::Node *n; - n = m_types.find(type); + core::map::Node *n; + n = ServerActiveObject::getTypes().find(type); if(n == NULL) { // If factory is not found, just return. @@ -58,13 +58,13 @@ ServerActiveObject* ServerActiveObject::create(u8 type, return object; } -void ServerActiveObject::registerType(u16 type, Factory f) +void ServerActiveObject::registerType(u8 type, Factory f) { - core::map::Node *n; - n = m_types.find(type); + core::map::Node *n; + n = ServerActiveObject::getTypes().find(type); if(n) return; - m_types.insert(type, f); + ServerActiveObject::getTypes().insert(type, f); } void ServerActiveObject::getWieldDiggingProperties(ToolDiggingProperties *dst) diff --git a/src/serverobject.h b/src/serverobject.h index fd8a51a9e..d2627c87e 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -200,14 +200,17 @@ protected: typedef ServerActiveObject* (*Factory) (ServerEnvironment *env, v3f pos, const std::string &data); - static void registerType(u16 type, Factory f); + static void registerType(u8 type, Factory f); ServerEnvironment *m_env; v3f m_base_position; private: - // Used for creating objects based on type - static core::map m_types; + static core::map& getTypes() + { + static core::map types; + return types; + } }; #endif -- 2.25.1