From 155288ee981c70f505526347cb2bcda4df1c8e6b Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 6 Oct 2016 19:20:12 +0200 Subject: use unordered containers where possible (patch 4 on X) Also remove some unused parameters/functions --- src/content_sao.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index 44d40d332..ccae90b77 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -112,7 +112,7 @@ private: bool m_animation_loop; bool m_animation_sent; - std::map > m_bone_position; + UNORDERED_MAP > m_bone_position; bool m_bone_position_sent; int m_attachment_parent_id; @@ -321,7 +321,8 @@ private: bool m_animation_loop; bool m_animation_sent; - std::map > m_bone_position; // Stores position and rotation for each bone name + // Stores position and rotation for each bone name + UNORDERED_MAP > m_bone_position; bool m_bone_position_sent; int m_attachment_parent_id; -- cgit v1.2.3 From 8bcd10b872bc88c6f474913d6efb8d53c50c5ae1 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 8 Oct 2016 10:38:04 +0200 Subject: Player/LocalPlayer/RemotePlayer inheritance cleanup (part 1 on X) * LocalPlayer take ownership of maxHudId as it's the only caller * RemotePlayer take ownership of day night ratio as it's the only user * Pass getPlayerControl as const reference to prevent object copy on each call (perf improvement in ObjectRef::l_get_player_control call) * getPlayerSAO is now only RemotePlayer call * get/setHotbarItemCount is now RemotePlayer owned * Server: Use RemotePlayer instead of Player object on concerned call to properly fix the object type * PlayerSAO now uses RemotePlayer instead of Player because it's only server side * ObjectRef::getplayer also returns RemotePlayer as it's linked with PlayerSAO --- src/content_sao.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index ccae90b77..c97db4922 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -160,7 +160,7 @@ public: class PlayerSAO : public ServerActiveObject { public: - PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_, + PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_, const std::set &privs, bool is_singleplayer); ~PlayerSAO(); ActiveObjectType getType() const @@ -231,14 +231,8 @@ public: void disconnected(); - Player* getPlayer() - { - return m_player; - } - u16 getPeerID() const - { - return m_peer_id; - } + RemotePlayer* getPlayer() { return m_player; } + u16 getPeerID() const { return m_peer_id; } // Cheat prevention @@ -291,7 +285,7 @@ public: private: std::string getPropertyPacket(); - Player *m_player; + RemotePlayer *m_player; u16 m_peer_id; Inventory *m_inventory; s16 m_damage; -- cgit v1.2.3 From ad163ee5c3f7d6ca31e0add052fb76466a9bfcc8 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sat, 8 Oct 2016 16:51:25 +0400 Subject: Prevent attached models from disappearing during parent reload (#4128) --- src/content_sao.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index c97db4922..341ebb5da 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -67,7 +67,7 @@ public: void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation); void addAttachmentChild(int child_id); void removeAttachmentChild(int child_id); - std::set getAttachmentChildIds(); + UNORDERED_SET getAttachmentChildIds(); ObjectProperties* accessObjectProperties(); void notifyObjectPropertiesModified(); /* LuaEntitySAO-specific */ @@ -116,7 +116,7 @@ private: bool m_bone_position_sent; int m_attachment_parent_id; - std::set m_attachment_child_ids; + UNORDERED_SET m_attachment_child_ids; std::string m_attachment_bone; v3f m_attachment_position; v3f m_attachment_rotation; @@ -210,7 +210,7 @@ public: void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation); void addAttachmentChild(int child_id); void removeAttachmentChild(int child_id); - std::set getAttachmentChildIds(); + UNORDERED_SET getAttachmentChildIds(); ObjectProperties* accessObjectProperties(); void notifyObjectPropertiesModified(); @@ -320,7 +320,7 @@ private: bool m_bone_position_sent; int m_attachment_parent_id; - std::set m_attachment_child_ids; + UNORDERED_SET m_attachment_child_ids; std::string m_attachment_bone; v3f m_attachment_position; v3f m_attachment_rotation; -- cgit v1.2.3 From 569b89b36fff058390cb90458da4285552a9c97e Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 8 Oct 2016 19:08:23 +0200 Subject: Move RemotePlayer code to its own cpp/header --- src/content_sao.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index 341ebb5da..76a3a37da 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serverobject.h" #include "itemgroup.h" -#include "player.h" #include "object_properties.h" /* @@ -157,6 +156,8 @@ public: } }; +class RemotePlayer; + class PlayerSAO : public ServerActiveObject { public: @@ -231,7 +232,7 @@ public: void disconnected(); - RemotePlayer* getPlayer() { return m_player; } + RemotePlayer *getPlayer() { return m_player; } u16 getPeerID() const { return m_peer_id; } // Cheat prevention -- cgit v1.2.3 From 9d25242c5c1411d692254cf910345d51c9a24fa3 Mon Sep 17 00:00:00 2001 From: Ner'zhul Date: Sun, 30 Oct 2016 14:53:26 +0100 Subject: PlayerSAO/LocalPlayer refactor: (#4612) * Create UnitSAO, a common part between PlayerSAO & LuaEntitySAO * Move breath to PlayerSAO & LocalPlayer * Migrate m_yaw from (Remote)Player & LuaEntitySAO to UnitSAO * Migrate m_yaw from Player to LocalPlayer for client * Move some functions outside of player class to PlayerSAO/RemotePlayer or LocalPlayer depending on which class needs it * Move pitch to LocalPlayer & PlayerSAO * Move m_position from Player to LocalPlayer * Move camera_barely_in_ceiling to LocalPlayer as it's used only there * use PlayerSAO::m_base_position for Server side positions * remove a unused variable * ServerActiveObject::setPos now uses const ref * use ServerEnv::loadPlayer unconditionnaly as it creates RemotePlayer only if it's not already loaded * Move hp from Player to LocalPlayer * Move m_hp from LuaEntitySAO to UnitSAO * Use m_hp from PlayerSAO/UnitSAO instead of RemotePlayer --- src/content_sao.h | 62 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 17 deletions(-) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index 76a3a37da..4ea6277ff 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -23,12 +23,35 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serverobject.h" #include "itemgroup.h" #include "object_properties.h" +#include "constants.h" + +class UnitSAO: public ServerActiveObject +{ +public: + UnitSAO(ServerEnvironment *env, v3f pos): + ServerActiveObject(env, pos), + m_hp(-1), m_yaw(0) {} + virtual ~UnitSAO() {} + + virtual void setYaw(const float yaw) { m_yaw = yaw; } + float getYaw() const { return m_yaw; }; + f32 getRadYaw() const { return m_yaw * core::DEGTORAD; } + // Deprecated + f32 getRadYawDep() const { return (m_yaw + 90.) * core::DEGTORAD; } + + s16 getHP() const { return m_hp; } + // Use a function, if isDead can be defined by other conditions + bool isDead() const { return m_hp == 0; } +protected: + s16 m_hp; + float m_yaw; +}; /* LuaEntitySAO needs some internals exposed. */ -class LuaEntitySAO : public ServerActiveObject +class LuaEntitySAO : public UnitSAO { public: LuaEntitySAO(ServerEnvironment *env, v3f pos, @@ -74,8 +97,7 @@ public: v3f getVelocity(); void setAcceleration(v3f acceleration); v3f getAcceleration(); - void setYaw(float yaw); - float getYaw(); + void setTextureMod(const std::string &mod); void setSprite(v2s16 p, int num_frames, float framelength, bool select_horiz_by_yawpitch); @@ -91,10 +113,9 @@ private: bool m_registered; struct ObjectProperties m_prop; - s16 m_hp; v3f m_velocity; v3f m_acceleration; - float m_yaw; + ItemGroupList m_armor_groups; bool m_properties_sent; @@ -158,11 +179,10 @@ public: class RemotePlayer; -class PlayerSAO : public ServerActiveObject +class PlayerSAO : public UnitSAO { public: - PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_, - const std::set &privs, bool is_singleplayer); + PlayerSAO(ServerEnvironment *env_, u16 peer_id_, bool is_singleplayer); ~PlayerSAO(); ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_PLAYER; } @@ -182,10 +202,14 @@ public: bool isAttached(); void step(float dtime, bool send_recommended); void setBasePosition(const v3f &position); - void setPos(v3f pos); + void setPos(const v3f &pos); void moveTo(v3f pos, bool continuous); - void setYaw(float); - void setPitch(float); + void setYaw(const float yaw, bool send_data = true); + void setPitch(const float pitch, bool send_data = true); + f32 getPitch() const { return m_pitch; } + f32 getRadPitch() const { return m_pitch * core::DEGTORAD; } + // Deprecated + f32 getRadPitchDep() const { return -1.0 * m_pitch * core::DEGTORAD; } /* Interaction interface @@ -196,11 +220,10 @@ public: ServerActiveObject *puncher, float time_from_last_punch); void rightClick(ServerActiveObject *clicker); - s16 getHP() const; - void setHP(s16 hp); + void setHP(s16 hp, bool direct = false); s16 readDamage(); - u16 getBreath() const; - void setBreath(u16 breath); + u16 getBreath() const { return m_breath; } + void setBreath(const u16 breath); void setArmorGroups(const ItemGroupList &armor_groups); ItemGroupList getArmorGroups(); void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop); @@ -283,6 +306,11 @@ public: bool getCollisionBox(aabb3f *toset); bool collideWithObjects(); + void initialize(RemotePlayer *player, const std::set &privs); + + v3f getEyePosition() const { return m_base_position + getEyeOffset(); } + v3f getEyeOffset() const { return v3f(0, BS * 1.625f, 0); } + private: std::string getPropertyPacket(); @@ -326,8 +354,8 @@ private: v3f m_attachment_position; v3f m_attachment_rotation; bool m_attachment_sent; - - + u16 m_breath; + f32 m_pitch; public: float m_physics_override_speed; float m_physics_override_jump; -- cgit v1.2.3 From 595932a8602292f28333ce14e20cee4b6d8820c1 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sun, 30 Oct 2016 16:12:09 +0100 Subject: Fix overloading problems mentioned by clang --- src/content_sao.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index 4ea6277ff..5d837a466 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -73,7 +73,7 @@ public: ServerActiveObject *puncher=NULL, float time_from_last_punch=1000000); void rightClick(ServerActiveObject *clicker); - void setPos(v3f pos); + void setPos(const v3f &pos); void moveTo(v3f pos, bool continuous); float getMinimumSavedMovement(); std::string getDescription(); @@ -204,8 +204,12 @@ public: void setBasePosition(const v3f &position); void setPos(const v3f &pos); void moveTo(v3f pos, bool continuous); - void setYaw(const float yaw, bool send_data = true); - void setPitch(const float pitch, bool send_data = true); + void setYaw(const float yaw); + // Data should not be sent at player initialization + void setYawAndSend(const float yaw); + void setPitch(const float pitch); + // Data should not be sent at player initialization + void setPitchAndSend(const float pitch); f32 getPitch() const { return m_pitch; } f32 getRadPitch() const { return m_pitch * core::DEGTORAD; } // Deprecated @@ -220,7 +224,8 @@ public: ServerActiveObject *puncher, float time_from_last_punch); void rightClick(ServerActiveObject *clicker); - void setHP(s16 hp, bool direct = false); + void setHP(s16 hp); + void setHPRaw(s16 hp) { m_hp = hp; } s16 readDamage(); u16 getBreath() const { return m_breath; } void setBreath(const u16 breath); -- cgit v1.2.3 From 66bb2954362748c4722d366d0df490ad51a591a2 Mon Sep 17 00:00:00 2001 From: Ner'zhul Date: Sat, 5 Nov 2016 10:25:30 +0100 Subject: PlayerSAO saving fix (#4734) PlayerSAO::disconnected() function was historical and remove the link between SAO and RemotePlayer session. With previous attributes linked to RemotePlayer saving was working. But now attributes are read from SAO not RemotePlayer and the current serialize function verify SAO exists to save the player attributes. Because PlayerSAO::disconnected marks playersao for removal, only mark playerSAO for removal and let PlayerSAO::removingFromEnvironment do the correct saving behaviour and all the disconnection process instead of doing a partial removal and let the server loop doing the RemotePlayer cleanup and remove some saved attributes... --- src/content_sao.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index 5d837a466..f58c7dadb 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -318,6 +318,7 @@ public: private: std::string getPropertyPacket(); + void unlinkPlayerSessionAndSave(); RemotePlayer *m_player; u16 m_peer_id; -- cgit v1.2.3 From 785a9a6c1af424b0a46f334de7176c9e67341cfb Mon Sep 17 00:00:00 2001 From: TeTpaAka Date: Thu, 25 Jun 2015 13:06:49 +0200 Subject: Wieldhand: Allow overriding the hand --- src/content_sao.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index f58c7dadb..c5b066f50 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -251,6 +251,8 @@ public: const Inventory* getInventory() const; InventoryLocation getInventoryLocation() const; std::string getWieldList() const; + ItemStack getWieldedItem() const; + bool setWieldedItem(const ItemStack &item); int getWieldIndex() const; void setWieldIndex(int i); -- cgit v1.2.3 From 5dc61988788e44bc87e8c57c0beded97d4efdf05 Mon Sep 17 00:00:00 2001 From: lhofhansl Date: Wed, 30 Nov 2016 00:13:14 -0800 Subject: Optimize/adjust blocks/ActiveObjects sent at the server based on client settings. (#4811) Optimize/adjust blocks and active blocks sent at the server based on client settings. --- src/content_sao.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/content_sao.h') diff --git a/src/content_sao.h b/src/content_sao.h index c5b066f50..86255183d 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -214,6 +214,10 @@ public: f32 getRadPitch() const { return m_pitch * core::DEGTORAD; } // Deprecated f32 getRadPitchDep() const { return -1.0 * m_pitch * core::DEGTORAD; } + void setFov(const float pitch); + f32 getFov() const { return m_fov; } + void setWantedRange(const s16 range); + s16 getWantedRange() const { return m_wanted_range; } /* Interaction interface @@ -364,6 +368,8 @@ private: bool m_attachment_sent; u16 m_breath; f32 m_pitch; + f32 m_fov; + s16 m_wanted_range; public: float m_physics_override_speed; float m_physics_override_jump; -- cgit v1.2.3