Modernize client code (#6250)
[oweals/minetest.git] / src / serverobject.h
index cfe2b6bcc20a366c9dc72f8774d3bfac0cb7fc95..8acbd6a19c5cad36b70d777bec1263f5c89b2bfe 100644 (file)
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef SERVEROBJECT_HEADER
 #define SERVEROBJECT_HEADER
 
+#include <unordered_set>
 #include "irrlichttypes_bloated.h"
 #include "activeobject.h"
 #include "inventorymanager.h"
@@ -77,7 +78,7 @@ public:
        /*
                Some simple getters/setters
        */
-       v3f getBasePosition(){ return m_base_position; }
+       v3f getBasePosition() const { return m_base_position; }
        void setBasePosition(v3f pos){ m_base_position = pos; }
        ServerEnvironment* getEnv(){ return m_env; }
 
@@ -85,7 +86,7 @@ public:
                Some more dynamic interface
        */
 
-       virtual void setPos(v3f pos)
+       virtual void setPos(const v3f &pos)
                { setBasePosition(pos); }
        // continuous: if true, object does not stop immediately at pos
        virtual void moveTo(v3f pos, bool continuous)
@@ -119,10 +120,10 @@ public:
                when it is created (converted from static to active - actually
                the data is the static form)
        */
-       virtual std::string getStaticData()
+       virtual void getStaticData(std::string *result) const
        {
                assert(isStaticAllowed());
-               return "";
+               *result = "";
        }
        /*
                Return false in here to never save and instead remove object
@@ -146,8 +147,8 @@ public:
 
        virtual void setArmorGroups(const ItemGroupList &armor_groups)
        {}
-       virtual ItemGroupList getArmorGroups()
-       { return ItemGroupList(); }
+       virtual const ItemGroupList &getArmorGroups()
+       { static const ItemGroupList rv; return rv; }
        virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity)
        {}
        virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop)
@@ -166,8 +167,8 @@ public:
        {}
        virtual void removeAttachmentChild(int child_id)
        {}
-       virtual UNORDERED_SET<int> getAttachmentChildIds()
-       { return UNORDERED_SET<int>(); }
+       virtual const std::unordered_set<int> &getAttachmentChildIds()
+       { static const std::unordered_set<int> rv; return rv; }
        virtual ObjectProperties* accessObjectProperties()
        { return NULL; }
        virtual void notifyObjectPropertiesModified()
@@ -188,13 +189,22 @@ public:
        { return 0; }
        virtual ItemStack getWieldedItem() const;
        virtual bool setWieldedItem(const ItemStack &item);
+       inline void attachParticleSpawner(u32 id)
+       {
+               m_attached_particle_spawners.insert(id);
+       }
+       inline void detachParticleSpawner(u32 id)
+       {
+               m_attached_particle_spawners.erase(id);
+       }
+
 
        /*
                Number of players which know about this object. Object won't be
                deleted until this is 0 to keep the id preserved for the right
                object.
        */
-       u16 m_known_by_count;
+       u16 m_known_by_count = 0;
 
        /*
                - Whether this object is to be removed when nobody knows about
@@ -205,7 +215,7 @@ public:
                  to be deleted.
                - This can be set to true by anything else too.
        */
-       bool m_removed;
+       bool m_removed = false;
 
        /*
                This is set to true when an object should be removed from the active
@@ -216,17 +226,17 @@ public:
                m_known_by_count is true, object is deleted from the active object
                list.
        */
-       bool m_pending_deactivation;
+       bool m_pending_deactivation = false;
 
        /*
                Whether the object's static data has been stored to a block
        */
-       bool m_static_exists;
+       bool m_static_exists = false;
        /*
                The block from which the object was loaded from, and in which
                a copy of the static data resides.
        */
-       v3s16 m_static_block;
+       v3s16 m_static_block = v3s16(1337,1337,1337);
 
        /*
                Queue of messages to be sent to the client
@@ -242,6 +252,7 @@ protected:
 
        ServerEnvironment *m_env;
        v3f m_base_position;
+       std::unordered_set<u32> m_attached_particle_spawners;
 
 private:
        // Used for creating objects based on type