summaryrefslogtreecommitdiff
path: root/src/serverobject.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-04-10 04:15:10 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-04-10 04:15:10 +0300
commitfd7a0735c9aeaa7978190049319e3cdfe48920a4 (patch)
tree655709280d2940de54bd489a24821a158cea787d /src/serverobject.h
parentc0f0c6568bb45350e65f31476578feff879831bf (diff)
downloadminetest-fd7a0735c9aeaa7978190049319e3cdfe48920a4.tar.gz
minetest-fd7a0735c9aeaa7978190049319e3cdfe48920a4.tar.bz2
minetest-fd7a0735c9aeaa7978190049319e3cdfe48920a4.zip
new object system
Diffstat (limited to 'src/serverobject.h')
-rw-r--r--src/serverobject.h70
1 files changed, 45 insertions, 25 deletions
diff --git a/src/serverobject.h b/src/serverobject.h
index 241458193..a307c421f 100644
--- a/src/serverobject.h
+++ b/src/serverobject.h
@@ -39,27 +39,28 @@ Some planning
*/
class ServerEnvironment;
+class InventoryItem;
class ServerActiveObject : public ActiveObject
{
public:
- ServerActiveObject(ServerEnvironment *env, u16 id, v3f pos=v3f(0,0,0));
+ ServerActiveObject(ServerEnvironment *env, u16 id, v3f pos);
virtual ~ServerActiveObject();
- v3f getBasePosition()
- {
- return m_base_position;
- }
+ // Create a certain type of ServerActiveObject
+ static ServerActiveObject* create(u8 type,
+ ServerEnvironment *env, u16 id, v3f pos,
+ const std::string &data);
+ /*
+ Some simple getters/setters
+ */
+ v3f getBasePosition()
+ {return m_base_position;}
void setBasePosition(v3f pos)
- {
- m_base_position = pos;
- }
-
+ {m_base_position = pos;}
ServerEnvironment* getEnv()
- {
- return m_env;
- }
+ {return m_env;}
/*
Step object in time.
@@ -75,14 +76,10 @@ public:
/*
The return value of this is passed to the server-side object
- when it is loaded from disk or from a static object
- */
- virtual std::string getServerInitializationData(){return "";}
-
- /*
- This takes the return value of getServerInitializationData
+ when it is created (converted from static to active - actually
+ the data is the static form)
*/
- virtual void initialize(const std::string &data){}
+ virtual std::string getStaticData(){return "";}
// Number of players which know about this object
u16 m_known_by_count;
@@ -93,12 +90,33 @@ public:
it could be confused to some other object by some client.
- This is set to true by the step() method when the object wants
to be deleted.
+ - This can be set to true by anything else too.
*/
bool m_removed;
+ /*
+ Whether the object's static data has been stored to a block
+ */
+ bool m_static_exists;
+ /*
+ The block from which the object was loaded from, and in which
+ a copy of the static data resides.
+ */
+ v3s16 m_static_block;
+
protected:
+ // Used for creating objects based on type
+ typedef ServerActiveObject* (*Factory)
+ (ServerEnvironment *env, u16 id, v3f pos,
+ const std::string &data);
+ static void registerType(u16 type, Factory f);
+
ServerEnvironment *m_env;
v3f m_base_position;
+
+private:
+ // Used for creating objects based on type
+ static core::map<u16, Factory> m_types;
};
class TestSAO : public ServerActiveObject
@@ -106,9 +124,9 @@ class TestSAO : public ServerActiveObject
public:
TestSAO(ServerEnvironment *env, u16 id, v3f pos);
u8 getType() const
- {
- return ACTIVEOBJECT_TYPE_TEST;
- }
+ {return ACTIVEOBJECT_TYPE_TEST;}
+ static ServerActiveObject* create(ServerEnvironment *env, u16 id, v3f pos,
+ const std::string &data);
void step(float dtime, Queue<ActiveObjectMessage> &messages);
private:
float m_timer1;
@@ -121,11 +139,13 @@ public:
ItemSAO(ServerEnvironment *env, u16 id, v3f pos,
const std::string inventorystring);
u8 getType() const
- {
- return ACTIVEOBJECT_TYPE_ITEM;
- }
+ {return ACTIVEOBJECT_TYPE_ITEM;}
+ static ServerActiveObject* create(ServerEnvironment *env, u16 id, v3f pos,
+ const std::string &data);
void step(float dtime, Queue<ActiveObjectMessage> &messages);
std::string getClientInitializationData();
+ std::string getStaticData();
+ InventoryItem* createInventoryItem();
private:
std::string m_inventorystring;
};