aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/activeobject.h6
-rw-r--r--src/clientobject.h4
-rw-r--r--src/content_cao.cpp6
-rw-r--r--src/content_cao.h2
-rw-r--r--src/content_sao.cpp85
-rw-r--r--src/content_sao.h87
-rw-r--r--src/script/lua_api/l_object.cpp7
-rw-r--r--src/serverobject.h8
8 files changed, 88 insertions, 117 deletions
diff --git a/src/activeobject.h b/src/activeobject.h
index 48f078d3f..fe6c08514 100644
--- a/src/activeobject.h
+++ b/src/activeobject.h
@@ -64,7 +64,7 @@ public:
m_id(id)
{
}
-
+
u16 getId()
{
return m_id;
@@ -76,8 +76,8 @@ public:
}
virtual ActiveObjectType getType() const = 0;
- virtual bool getCollisionBox(aabb3f *toset) = 0;
- virtual bool collideWithObjects() = 0;
+ virtual bool getCollisionBox(aabb3f *toset) const = 0;
+ virtual bool collideWithObjects() const = 0;
protected:
u16 m_id; // 0 is invalid, "no id"
};
diff --git a/src/clientobject.h b/src/clientobject.h
index f0bde0adc..1db5bcf24 100644
--- a/src/clientobject.h
+++ b/src/clientobject.h
@@ -47,8 +47,8 @@ public:
virtual void updateLightNoCheck(u8 light_at_pos){}
virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
virtual aabb3f *getSelectionBox() { return NULL; }
- virtual bool getCollisionBox(aabb3f *toset){return false;}
- virtual bool collideWithObjects(){return false;}
+ virtual bool getCollisionBox(aabb3f *toset) const { return false; }
+ virtual bool collideWithObjects() const { return false; }
virtual v3f getPosition(){return v3f(0,0,0);}
virtual float getYaw() const {return 0;}
virtual scene::ISceneNode *getSceneNode(){return NULL;}
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index a4c0bf14d..5ddbd27c9 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -159,7 +159,7 @@ public:
void processMessage(const std::string &data);
- bool getCollisionBox(aabb3f *toset) { return false; }
+ bool getCollisionBox(aabb3f *toset) const { return false; }
private:
scene::IMeshSceneNode *m_node;
v3f m_position;
@@ -316,7 +316,7 @@ public:
std::string infoText()
{return m_infotext;}
- bool getCollisionBox(aabb3f *toset) { return false; }
+ bool getCollisionBox(aabb3f *toset) const { return false; }
private:
aabb3f m_selection_box;
scene::IMeshSceneNode *m_node;
@@ -587,7 +587,7 @@ GenericCAO::GenericCAO(Client *client, ClientEnvironment *env):
}
}
-bool GenericCAO::getCollisionBox(aabb3f *toset)
+bool GenericCAO::getCollisionBox(aabb3f *toset) const
{
if (m_prop.physical)
{
diff --git a/src/content_cao.h b/src/content_cao.h
index 96a160055..19fecdde5 100644
--- a/src/content_cao.h
+++ b/src/content_cao.h
@@ -130,7 +130,7 @@ public:
ClientActiveObject *getParent();
- bool getCollisionBox(aabb3f *toset);
+ bool getCollisionBox(aabb3f *toset) const;
bool collideWithObjects();
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index dd8bdc592..c403a3673 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -19,11 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_sao.h"
#include "util/serialize.h"
-#include "util/mathconstants.h"
#include "collision.h"
#include "environment.h"
-#include "settings.h"
-#include "serialization.h" // For compressZlib
#include "tool.h" // For ToolCapabilities
#include "gamedef.h"
#include "nodedef.h"
@@ -31,7 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "scripting_game.h"
#include "genericobject.h"
-#include "log.h"
std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
@@ -94,13 +90,8 @@ public:
}
}
- bool getCollisionBox(aabb3f *toset) {
- return false;
- }
-
- bool collideWithObjects() {
- return false;
- }
+ bool getCollisionBox(aabb3f *toset) const { return false; }
+ bool collideWithObjects() const { return false; }
private:
float m_timer1;
@@ -111,6 +102,28 @@ private:
TestSAO proto_TestSAO(NULL, v3f(0,0,0));
/*
+ UnitSAO
+ */
+
+UnitSAO::UnitSAO(ServerEnvironment *env, v3f pos):
+ ServerActiveObject(env, pos),
+ m_hp(-1),
+ m_yaw(0),
+ m_properties_sent(true),
+ m_armor_groups_sent(false),
+ m_animation_range(0,0),
+ m_animation_speed(0),
+ m_animation_blend(0),
+ m_animation_loop(true),
+ m_animation_sent(false),
+ m_bone_position_sent(false),
+ m_attachment_parent_id(0),
+ m_attachment_sent(false)
+{
+ // Initialize something to armor groups
+ m_armor_groups["fleshy"] = 100;
+}
+/*
LuaEntitySAO
*/
@@ -125,29 +138,17 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
m_registered(false),
m_velocity(0,0,0),
m_acceleration(0,0,0),
- m_properties_sent(true),
m_last_sent_yaw(0),
m_last_sent_position(0,0,0),
m_last_sent_velocity(0,0,0),
m_last_sent_position_timer(0),
- m_last_sent_move_precision(0),
- m_armor_groups_sent(false),
- m_animation_speed(0),
- m_animation_blend(0),
- m_animation_loop(true),
- m_animation_sent(false),
- m_bone_position_sent(false),
- m_attachment_parent_id(0),
- m_attachment_sent(false)
+ m_last_sent_move_precision(0)
{
// Only register type if no environment supplied
if(env == NULL){
ServerActiveObject::registerType(getType(), create);
return;
}
-
- // Initialize something to armor groups
- m_armor_groups["fleshy"] = 100;
}
LuaEntitySAO::~LuaEntitySAO()
@@ -565,7 +566,7 @@ void LuaEntitySAO::setArmorGroups(const ItemGroupList &armor_groups)
m_armor_groups_sent = false;
}
-ItemGroupList LuaEntitySAO::getArmorGroups()
+const ItemGroupList &LuaEntitySAO::getArmorGroups()
{
return m_armor_groups;
}
@@ -635,7 +636,7 @@ void LuaEntitySAO::removeAttachmentChild(int child_id)
m_attachment_child_ids.erase(child_id);
}
-UNORDERED_SET<int> LuaEntitySAO::getAttachmentChildIds()
+const UNORDERED_SET<int> &LuaEntitySAO::getAttachmentChildIds()
{
return m_attachment_child_ids;
}
@@ -732,7 +733,8 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
m_messages_out.push(aom);
}
-bool LuaEntitySAO::getCollisionBox(aabb3f *toset) {
+bool LuaEntitySAO::getCollisionBox(aabb3f *toset) const
+{
if (m_prop.physical)
{
//update collision box
@@ -748,7 +750,8 @@ bool LuaEntitySAO::getCollisionBox(aabb3f *toset) {
return false;
}
-bool LuaEntitySAO::collideWithObjects(){
+bool LuaEntitySAO::collideWithObjects() const
+{
return m_prop.collideWithObjects;
}
@@ -770,16 +773,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, u16 peer_id_, bool is_singleplayer
m_nocheat_dig_time(0),
m_wield_index(0),
m_position_not_sent(false),
- m_armor_groups_sent(false),
- m_properties_sent(true),
m_is_singleplayer(is_singleplayer),
- m_animation_speed(0),
- m_animation_blend(0),
- m_animation_loop(true),
- m_animation_sent(false),
- m_bone_position_sent(false),
- m_attachment_parent_id(0),
- m_attachment_sent(false),
m_breath(PLAYER_MAX_BREATH),
m_pitch(0),
m_fov(0),
@@ -793,7 +787,6 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, u16 peer_id_, bool is_singleplayer
m_physics_override_sent(false)
{
assert(m_peer_id != 0); // pre-condition
- m_armor_groups["fleshy"] = 100;
m_prop.hp_max = PLAYER_MAX_HP;
m_prop.physical = false;
@@ -828,6 +821,11 @@ void PlayerSAO::initialize(RemotePlayer *player, const std::set<std::string> &pr
m_inventory = &m_player->inventory;
}
+v3f PlayerSAO::getEyeOffset() const
+{
+ return v3f(0, BS * 1.625f, 0);
+}
+
std::string PlayerSAO::getDescription()
{
return std::string("player ") + m_player->getName();
@@ -1282,7 +1280,7 @@ void PlayerSAO::setArmorGroups(const ItemGroupList &armor_groups)
m_armor_groups_sent = false;
}
-ItemGroupList PlayerSAO::getArmorGroups()
+const ItemGroupList &PlayerSAO::getArmorGroups()
{
return m_armor_groups;
}
@@ -1354,7 +1352,7 @@ void PlayerSAO::removeAttachmentChild(int child_id)
m_attachment_child_ids.erase(child_id);
}
-UNORDERED_SET<int> PlayerSAO::getAttachmentChildIds()
+const UNORDERED_SET<int> &PlayerSAO::getAttachmentChildIds()
{
return m_attachment_child_ids;
}
@@ -1512,15 +1510,10 @@ bool PlayerSAO::checkMovementCheat()
return cheated;
}
-bool PlayerSAO::getCollisionBox(aabb3f *toset)
+bool PlayerSAO::getCollisionBox(aabb3f *toset) const
{
*toset = aabb3f(-BS * 0.30, 0.0, -BS * 0.30, BS * 0.30, BS * 1.75, BS * 0.30);
toset->MinEdge += m_base_position;
toset->MaxEdge += m_base_position;
return true;
}
-
-bool PlayerSAO::collideWithObjects()
-{
- return true;
-}
diff --git a/src/content_sao.h b/src/content_sao.h
index 9c66068b3..d5e9b2cbf 100644
--- a/src/content_sao.h
+++ b/src/content_sao.h
@@ -24,14 +24,11 @@ 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) {}
+ UnitSAO(ServerEnvironment *env, v3f pos);
virtual ~UnitSAO() {}
virtual void setYaw(const float yaw) { m_yaw = yaw; }
@@ -46,6 +43,29 @@ public:
protected:
s16 m_hp;
float m_yaw;
+
+ bool m_properties_sent;
+ struct ObjectProperties m_prop;
+
+ ItemGroupList m_armor_groups;
+ bool m_armor_groups_sent;
+
+ v2f m_animation_range;
+ float m_animation_speed;
+ float m_animation_blend;
+ bool m_animation_loop;
+ bool m_animation_sent;
+
+ // Stores position and rotation for each bone name
+ UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
+ bool m_bone_position_sent;
+
+ int m_attachment_parent_id;
+ UNORDERED_SET<int> m_attachment_child_ids;
+ std::string m_attachment_bone;
+ v3f m_attachment_position;
+ v3f m_attachment_rotation;
+ bool m_attachment_sent;
};
/*
@@ -81,7 +101,7 @@ public:
void setHP(s16 hp);
s16 getHP() const;
void setArmorGroups(const ItemGroupList &armor_groups);
- ItemGroupList getArmorGroups();
+ const ItemGroupList &getArmorGroups();
void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
@@ -90,7 +110,7 @@ public:
void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
void addAttachmentChild(int child_id);
void removeAttachmentChild(int child_id);
- UNORDERED_SET<int> getAttachmentChildIds();
+ const UNORDERED_SET<int> &getAttachmentChildIds();
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
/* LuaEntitySAO-specific */
@@ -103,8 +123,8 @@ public:
void setSprite(v2s16 p, int num_frames, float framelength,
bool select_horiz_by_yawpitch);
std::string getName();
- bool getCollisionBox(aabb3f *toset);
- bool collideWithObjects();
+ bool getCollisionBox(aabb3f *toset) const;
+ bool collideWithObjects() const;
private:
std::string getPropertyPacket();
void sendPosition(bool do_interpolate, bool is_movement_end);
@@ -112,36 +132,15 @@ private:
std::string m_init_name;
std::string m_init_state;
bool m_registered;
- struct ObjectProperties m_prop;
v3f m_velocity;
v3f m_acceleration;
- ItemGroupList m_armor_groups;
-
- bool m_properties_sent;
float m_last_sent_yaw;
v3f m_last_sent_position;
v3f m_last_sent_velocity;
float m_last_sent_position_timer;
float m_last_sent_move_precision;
- bool m_armor_groups_sent;
-
- v2f m_animation_range;
- float m_animation_speed;
- float m_animation_blend;
- bool m_animation_loop;
- bool m_animation_sent;
-
- UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
- bool m_bone_position_sent;
-
- int m_attachment_parent_id;
- UNORDERED_SET<int> m_attachment_child_ids;
- std::string m_attachment_bone;
- v3f m_attachment_position;
- v3f m_attachment_rotation;
- bool m_attachment_sent;
};
/*
@@ -235,7 +234,7 @@ public:
u16 getBreath() const { return m_breath; }
void setBreath(const u16 breath, bool send = true);
void setArmorGroups(const ItemGroupList &armor_groups);
- ItemGroupList getArmorGroups();
+ const ItemGroupList &getArmorGroups();
void setAnimation(v2f frame_range, float frame_speed, float frame_blend, bool frame_loop);
void getAnimation(v2f *frame_range, float *frame_speed, float *frame_blend, bool *frame_loop);
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
@@ -244,7 +243,7 @@ public:
void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
void addAttachmentChild(int child_id);
void removeAttachmentChild(int child_id);
- UNORDERED_SET<int> getAttachmentChildIds();
+ const UNORDERED_SET<int> &getAttachmentChildIds();
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
@@ -315,13 +314,13 @@ public:
m_is_singleplayer = is_singleplayer;
}
- bool getCollisionBox(aabb3f *toset);
- bool collideWithObjects();
+ bool getCollisionBox(aabb3f *toset) const;
+ bool collideWithObjects() const { return true; }
void initialize(RemotePlayer *player, const std::set<std::string> &privs);
v3f getEyePosition() const { return m_base_position + getEyeOffset(); }
- v3f getEyeOffset() const { return v3f(0, BS * 1.625f, 0); }
+ v3f getEyeOffset() const;
private:
std::string getPropertyPacket();
@@ -346,31 +345,11 @@ private:
int m_wield_index;
bool m_position_not_sent;
- ItemGroupList m_armor_groups;
- bool m_armor_groups_sent;
- bool m_properties_sent;
- struct ObjectProperties m_prop;
// Cached privileges for enforcement
std::set<std::string> m_privs;
bool m_is_singleplayer;
- v2f m_animation_range;
- float m_animation_speed;
- float m_animation_blend;
- bool m_animation_loop;
- bool m_animation_sent;
-
- // Stores position and rotation for each bone name
- UNORDERED_MAP<std::string, core::vector2d<v3f> > m_bone_position;
- bool m_bone_position_sent;
-
- int m_attachment_parent_id;
- UNORDERED_SET<int> m_attachment_child_ids;
- std::string m_attachment_bone;
- v3f m_attachment_position;
- v3f m_attachment_rotation;
- bool m_attachment_sent;
u16 m_breath;
f32 m_pitch;
f32 m_fov;
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index cfdceb28e..84d14d521 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -137,8 +137,8 @@ int ObjectRef::l_remove(lua_State *L)
if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
return 0;
- UNORDERED_SET<int> child_ids = co->getAttachmentChildIds();
- UNORDERED_SET<int>::iterator it;
+ const UNORDERED_SET<int> &child_ids = co->getAttachmentChildIds();
+ UNORDERED_SET<int>::const_iterator it;
for (it = child_ids.begin(); it != child_ids.end(); ++it) {
// Child can be NULL if it was deleted earlier
if (ServerActiveObject *child = env->getActiveObject(*it))
@@ -396,8 +396,7 @@ int ObjectRef::l_get_armor_groups(lua_State *L)
if (co == NULL)
return 0;
// Do it
- ItemGroupList groups = co->getArmorGroups();
- push_groups(L, groups);
+ push_groups(L, co->getArmorGroups());
return 1;
}
diff --git a/src/serverobject.h b/src/serverobject.h
index 9884eb0a1..9e8b5a779 100644
--- a/src/serverobject.h
+++ b/src/serverobject.h
@@ -146,8 +146,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 +166,8 @@ public:
{}
virtual void removeAttachmentChild(int child_id)
{}
- virtual UNORDERED_SET<int> getAttachmentChildIds()
- { return UNORDERED_SET<int>(); }
+ virtual const UNORDERED_SET<int> &getAttachmentChildIds()
+ { static const UNORDERED_SET<int> rv; return rv; }
virtual ObjectProperties* accessObjectProperties()
{ return NULL; }
virtual void notifyObjectPropertiesModified()