From fd7a0735c9aeaa7978190049319e3cdfe48920a4 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 10 Apr 2011 04:15:10 +0300 Subject: new object system --- src/serverobject.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'src/serverobject.cpp') diff --git a/src/serverobject.cpp b/src/serverobject.cpp index 3645f7666..f0ef7d8d6 100644 --- a/src/serverobject.cpp +++ b/src/serverobject.cpp @@ -20,11 +20,16 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serverobject.h" #include #include "environment.h" +#include "inventory.h" + +core::map ServerActiveObject::m_types; ServerActiveObject::ServerActiveObject(ServerEnvironment *env, u16 id, v3f pos): ActiveObject(id), m_known_by_count(0), m_removed(false), + m_static_exists(false), + m_static_block(1337,1337,1337), m_env(env), m_base_position(pos) { @@ -34,15 +39,55 @@ ServerActiveObject::~ServerActiveObject() { } +ServerActiveObject* ServerActiveObject::create(u8 type, + ServerEnvironment *env, u16 id, v3f pos, + const std::string &data) +{ + // Find factory function + core::map::Node *n; + n = m_types.find(type); + if(n == NULL) + { + // If factory is not found, just return. + dstream<<"WARNING: ServerActiveObject: No factory for type=" + <getValue(); + ServerActiveObject *object = (*f)(env, id, pos, data); + return object; +} + +void ServerActiveObject::registerType(u16 type, Factory f) +{ + core::map::Node *n; + n = m_types.find(type); + if(n) + return; + m_types.insert(type, f); +} + + /* TestSAO */ +// Prototype +TestSAO proto_TestSAO(NULL, 0, v3f(0,0,0)); + TestSAO::TestSAO(ServerEnvironment *env, u16 id, v3f pos): ServerActiveObject(env, id, pos), m_timer1(0), m_age(0) { + ServerActiveObject::registerType(getType(), create); +} + +ServerActiveObject* TestSAO::create(ServerEnvironment *env, u16 id, v3f pos, + const std::string &data) +{ + return new TestSAO(env, id, pos); } void TestSAO::step(float dtime, Queue &messages) @@ -84,6 +129,9 @@ void TestSAO::step(float dtime, Queue &messages) ItemSAO */ +// Prototype +ItemSAO proto_ItemSAO(NULL, 0, v3f(0,0,0), ""); + ItemSAO::ItemSAO(ServerEnvironment *env, u16 id, v3f pos, const std::string inventorystring): ServerActiveObject(env, id, pos), @@ -91,6 +139,19 @@ ItemSAO::ItemSAO(ServerEnvironment *env, u16 id, v3f pos, { dstream<<"Server: ItemSAO created with inventorystring=\"" < &messages) @@ -111,4 +172,34 @@ std::string ItemSAO::getClientInitializationData() return data; } +std::string ItemSAO::getStaticData() +{ + dstream<<__FUNCTION_NAME< item="<