1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

add support for entity linking

This commit is contained in:
sapier 2012-01-15 22:22:07 +01:00
parent e3122ae727
commit 14a64000ea
3 changed files with 72 additions and 27 deletions

View file

@ -19,8 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <list> #include <list>
#include "content_cao.h" #include "content_cao.h"
#include "luaentity_common.h" #include "luaentity_common.h"
#include "clientlinkableobject.h"
class LuaEntityCAO : public ClientActiveObject class LuaEntityCAO : public ClientActiveObject, public ClientLinkableObject
{ {
private: private:
core::aabbox3d<f32> m_selection_box; core::aabbox3d<f32> m_selection_box;
@ -223,6 +224,8 @@ public:
void step(float dtime, ClientEnvironment *env) void step(float dtime, ClientEnvironment *env)
{ {
//if liked movement is handled by parent entity
if(!this->isLinked()) {
if(m_prop->physical){ if(m_prop->physical){
core::aabbox3d<f32> box = m_prop->collisionbox; core::aabbox3d<f32> box = m_prop->collisionbox;
box.MinEdge *= BS; box.MinEdge *= BS;
@ -251,6 +254,9 @@ public:
pos_translator.translate(dtime); pos_translator.translate(dtime);
updateNodePos(); updateNodePos();
} }
}
stepLinkedObjects(this->m_position,dtime);
m_anim_timer += dtime; m_anim_timer += dtime;
if(m_anim_timer >= m_anim_framelength){ if(m_anim_timer >= m_anim_framelength){
@ -397,7 +403,23 @@ public:
updateTexturePos(); updateTexturePos();
} }
else if (handleLinkUnlinkMessages(cmd,&is,this->m_env))
{
//Link unlink already done in handleLinkUnlinkMessages!
} }
}
void setPosition(v3f toset, float dtime){
if (this->isLinked()) {
this->m_position = toset + this->m_linkOffset;
pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
pos_translator.translate(dtime);
updateNodePos();
}
}
void updateLinkState(bool value) {}
}; };
// Prototype // Prototype

View file

@ -319,5 +319,26 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
m_messages_out.push_back(aom); m_messages_out.push_back(aom);
} }
bool LuaEntitySAO::sendLinkMsg(ServerActiveObject* parent,v3f offset) {
std::ostringstream os(std::ios::binary);
writeU8(os, AO_Message_type::Link);
// parameters
writeU16(os, parent->getId());
writeV3F1000(os, offset);
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());
m_messages_out.push_back(aom);
return true;
}
bool LuaEntitySAO::sendUnlinkMsg() {
std::ostringstream os(std::ios::binary);
writeU8(os, AO_Message_type::UnLink);
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());
m_messages_out.push_back(aom);
return true;
}
// Prototype // Prototype
LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", ""); LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", "");

View file

@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "scriptapi.h" #include "scriptapi.h"
#include "luaentity_common.h" #include "luaentity_common.h"
class LuaEntitySAO : public ServerActiveObject class LuaEntitySAO : public ServerActiveObject, public ServerLinkableObject
{ {
public: public:
LuaEntitySAO(ServerEnvironment *env, v3f pos, LuaEntitySAO(ServerEnvironment *env, v3f pos,
@ -55,6 +55,8 @@ public:
void setSprite(v2s16 p, int num_frames, float framelength, void setSprite(v2s16 p, int num_frames, float framelength,
bool select_horiz_by_yawpitch); bool select_horiz_by_yawpitch);
std::string getName(); std::string getName();
bool sendLinkMsg(ServerActiveObject* parent,v3f offset);
bool sendUnlinkMsg();
private: private:
void sendPosition(bool do_interpolate, bool is_movement_end); void sendPosition(bool do_interpolate, bool is_movement_end);