Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Naur -x '*.o' -x .git -x CMakeFiles -x lua -x sqlite -x '*.s' -x cmake_install.cmake -x jthread -x Makefile ../git/minetest.modif/src/content_cao_lua.cpp src/content_cao_lua.cpp
- --- ../git/minetest.modif/src/content_cao_lua.cpp 2012-01-09 01:35:04.000000000 +0100
- +++ src/content_cao_lua.cpp 2012-01-09 02:25:56.000000000 +0100
- @@ -43,6 +43,8 @@
- {
- if(gamedef == NULL)
- ClientActiveObject::registerType(LuaEntityCAO::getType(), LuaEntityCAO::create);
- +
- + this->m_Parent = NULL;
- }
- void LuaEntityCAO::initialize(const std::string &data)
- @@ -177,33 +179,45 @@
- void LuaEntityCAO::step(float dtime, ClientEnvironment *env)
- {
- - if(m_prop->physical){
- - core::aabbox3d<f32> box = m_prop->collisionbox;
- - box.MinEdge *= BS;
- - box.MaxEdge *= BS;
- - collisionMoveResult moveresult;
- - f32 pos_max_d = BS*0.25; // Distance per iteration
- - v3f p_pos = m_position;
- - v3f p_velocity = m_velocity;
- - IGameDef *gamedef = env->getGameDef();
- - moveresult = collisionMovePrecise(&env->getMap(), gamedef,
- - pos_max_d, box, dtime, p_pos, p_velocity);
- - // Apply results
- - m_position = p_pos;
- - m_velocity = p_velocity;
- -
- - bool is_end_position = moveresult.collides;
- - pos_translator.update(m_position, is_end_position, dtime);
- - pos_translator.translate(dtime);
- - updateNodePos();
- + //if liked movement is handled by parent entity
- + if(this->m_Parent == NULL) {
- + if(m_prop->physical){
- + core::aabbox3d<f32> box = m_prop->collisionbox;
- + box.MinEdge *= BS;
- + box.MaxEdge *= BS;
- + collisionMoveResult moveresult;
- + f32 pos_max_d = BS*0.25; // Distance per iteration
- + v3f p_pos = m_position;
- + v3f p_velocity = m_velocity;
- + IGameDef *gamedef = env->getGameDef();
- + moveresult = collisionMovePrecise(&env->getMap(), gamedef,
- + pos_max_d, box, dtime, p_pos, p_velocity);
- + // Apply results
- + m_position = p_pos;
- + m_velocity = p_velocity;
- +
- + bool is_end_position = moveresult.collides;
- + pos_translator.update(m_position, is_end_position, dtime);
- + pos_translator.translate(dtime);
- + updateNodePos();
- - m_velocity += dtime * m_acceleration;
- - } else {
- - m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
- - m_velocity += dtime * m_acceleration;
- - pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
- - pos_translator.translate(dtime);
- - updateNodePos();
- + m_velocity += dtime * m_acceleration;
- + } else {
- + m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
- + m_velocity += dtime * m_acceleration;
- + pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
- + pos_translator.translate(dtime);
- + updateNodePos();
- + }
- + }
- +
- + for(std::list<ClientActiveObject*>::iterator i = this->m_LinkedObjects.begin();
- + i != this->m_LinkedObjects.end(); i++) {
- + LuaEntityCAO* toupdate = dynamic_cast<LuaEntityCAO*>(*i);
- +
- + if (toupdate != NULL) {
- + toupdate->setPosition(this->m_position,dtime);
- + }
- }
- m_anim_timer += dtime;
- @@ -352,4 +366,92 @@
- updateTexturePos();
- }
- + else if(cmd == AO_Message_type::Link) // Link entity
- + {
- + //Object to link entity to
- + u16 object_id = readU16(is);
- + //offset against linked object
- + v3f offset = readV3F1000(is);
- +
- + ClientActiveObject* parent = m_env->getActiveObject(object_id);
- +
- + if (parent != NULL) {
- + this->linkEntity(offset,parent);
- + }
- + else {
- + errorstream << "Invalid object to link to!" << std::endl;
- + }
- +
- + }
- + else if(cmd == AO_Message_type::UnLink) // UnLink entity
- + {
- + if (this->m_Parent == NULL) {
- + errorstream << "Unlinking object not linked!" << std::endl;
- + }
- +
- + this->unlinkEntity();
- + }
- + }
- +
- +bool LuaEntityCAO::linkEntity(v3f offset, ClientActiveObject* parent) {
- +
- +
- + //already linked unlink first
- + if (this->m_Parent != NULL) {
- + return false;
- + }
- +
- + //TODO add linkchain support
- + if (this->m_LinkedObjects.size() > 0) {
- + return false;
- + }
- +
- + LuaEntityCAO * parent_lua = dynamic_cast<LuaEntityCAO*>(parent);
- +
- + if (parent_lua == NULL) {
- + return false;
- + }
- +
- + parent_lua->link(this);
- + this->m_linkOffset = offset;
- + this->m_Parent = parent;
- + return true;
- +}
- +
- +bool LuaEntityCAO::unlinkEntity() {
- + if (this->m_Parent != NULL) {
- +
- + //tell parent we do unlink
- + LuaEntityCAO * parent = dynamic_cast<LuaEntityCAO*>(this->m_Parent);
- +
- + if (parent != NULL) {
- + parent->unlink(this);
- + this->m_Parent = NULL;
- + return true;
- + }
- }
- +
- + return false;
- +}
- +
- +void LuaEntityCAO::link(ClientActiveObject* entity) {
- +
- + //TODO check if entity is already linkt (shouldn't be the case but just to be sure)
- + this->m_LinkedObjects.push_back(entity);
- +}
- +
- +void LuaEntityCAO::unlink(ClientActiveObject* entity) {
- + this->m_LinkedObjects.remove(entity);
- +}
- +
- +void LuaEntityCAO::setPosition(v3f toset, float dtime){
- +
- + if (this->m_Parent != NULL) {
- + 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();
- + }
- +
- +}
- diff -Naur -x '*.o' -x .git -x CMakeFiles -x lua -x sqlite -x '*.s' -x cmake_install.cmake -x jthread -x Makefile ../git/minetest.modif/src/content_cao_lua.h src/content_cao_lua.h
- --- ../git/minetest.modif/src/content_cao_lua.h 2012-01-09 01:34:56.000000000 +0100
- +++ src/content_cao_lua.h 2012-01-08 22:41:06.000000000 +0100
- @@ -20,6 +20,7 @@
- #ifndef CONTENT_COA_LUA_H_
- #define CONTENT_COA_LUA_H_
- +#include <list>
- #include "content_cao.h"
- #include "luaentity_common.h"
- @@ -44,6 +45,11 @@
- float m_anim_framelength;
- float m_anim_timer;
- + ClientActiveObject* m_Parent;
- + v3f m_linkOffset;
- +
- + std::list<ClientActiveObject*> m_LinkedObjects;
- +
- public:
- LuaEntityCAO(IGameDef *gamedef, ClientEnvironment *env);
- @@ -61,6 +67,8 @@
- inline v3f getPosition()
- { return pos_translator.vect_show; }
- + void setPosition(v3f toset, float dtime);
- +
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
- IrrlichtDevice *irr);
- @@ -79,6 +87,14 @@
- void updateTextures(const std::string &mod);
- void processMessage(const std::string &data);
- +
- + //user driven functions (exported by lua)
- + bool linkEntity(v3f offset, ClientActiveObject* parent);
- + bool unlinkEntity();
- +
- + //internal communication between entitys NOT to be used by user
- + void link(ClientActiveObject* entity);
- + void unlink(ClientActiveObject* entity);
- };
- diff -Naur -x '*.o' -x .git -x CMakeFiles -x lua -x sqlite -x '*.s' -x cmake_install.cmake -x jthread -x Makefile ../git/minetest.modif/src/content_sao_lua.cpp src/content_sao_lua.cpp
- --- ../git/minetest.modif/src/content_sao_lua.cpp 2012-01-09 01:35:04.000000000 +0100
- +++ src/content_sao_lua.cpp 2012-01-09 02:26:31.000000000 +0100
- @@ -37,7 +37,8 @@
- 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_last_sent_move_precision(0),
- + m_Linked(false)
- {
- // Only register type if no environment supplied
- if(env == NULL){
- @@ -277,6 +278,10 @@
- void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
- {
- + //don't send position updates if linked
- + if (this->m_Linked) {
- + return;
- + }
- m_last_sent_move_precision = m_base_position.getDistanceFrom(
- m_last_sent_position);
- m_last_sent_position_timer = 0;
- @@ -311,3 +316,36 @@
- m_messages_out.push_back(aom);
- }
- +bool LuaEntitySAO::linkEntity(ServerActiveObject* parent,v3f offset) {
- + //check if entity is in correct state
- + if (this->m_Linked == true) {
- + return false;
- + }
- +
- + this->m_Linked = true;
- + 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::unlinkEntity() {
- + //check if entity is in correct state
- + if (this->m_Linked == false) {
- + return false;
- + }
- +
- + this->m_Linked = false;
- + 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;
- +}
- +
- diff -Naur -x '*.o' -x .git -x CMakeFiles -x lua -x sqlite -x '*.s' -x cmake_install.cmake -x jthread -x Makefile ../git/minetest.modif/src/content_sao_lua.h src/content_sao_lua.h
- --- ../git/minetest.modif/src/content_sao_lua.h 2012-01-09 01:34:56.000000000 +0100
- +++ src/content_sao_lua.h 2012-01-08 22:12:16.000000000 +0100
- @@ -54,6 +54,9 @@
- void setSprite(v2s16 p, int num_frames, float framelength,
- bool select_horiz_by_yawpitch);
- std::string getName();
- +
- + bool linkEntity(ServerActiveObject* parent,v3f offset);
- + bool unlinkEntity();
- private:
- void sendPosition(bool do_interpolate, bool is_movement_end);
- @@ -70,6 +73,8 @@
- v3f m_last_sent_velocity;
- float m_last_sent_position_timer;
- float m_last_sent_move_precision;
- +
- + bool m_Linked;
- };
- diff -Naur -x '*.o' -x .git -x CMakeFiles -x lua -x sqlite -x '*.s' -x cmake_install.cmake -x jthread -x Makefile ../git/minetest.modif/src/scriptapi.cpp src/scriptapi.cpp
- --- ../git/minetest.modif/src/scriptapi.cpp 2012-01-09 01:34:56.000000000 +0100
- +++ src/scriptapi.cpp 2012-01-09 02:15:46.000000000 +0100
- @@ -2176,6 +2176,58 @@
- return 1;
- }
- + // link(parent, offset)
- + static int l_link(lua_State *L)
- + {
- + ObjectRef *ref_child = checkobject(L, 1);
- + ObjectRef *ref_parent = checkobject(L, 2);
- + v3f offset = checkFloatPos(L, 3);
- + std::cout << "parameters read" << std::endl;
- +
- + ServerActiveObject *child = getobject(ref_child);
- + ServerActiveObject *parent = getobject(ref_parent);
- +
- + if (child == NULL) return 0;
- + if (parent == NULL) return 0;
- +
- +
- + LuaEntitySAO* child_lua = dynamic_cast<LuaEntitySAO*>(child);
- + LuaEntitySAO* parent_lua = dynamic_cast<LuaEntitySAO*>(parent);
- +
- + if (child_lua == NULL) return 0;
- + if (parent_lua == NULL) return 0;
- +
- + if (child_lua->linkEntity(parent_lua,offset)) {
- + lua_pushboolean(L, true);
- + return 1;
- + }
- + else {
- + return 0;
- + }
- + }
- +
- + // unlink()
- + static int l_unlink(lua_State *L)
- + {
- + ObjectRef *ref = checkobject(L, 1);
- +
- + ServerActiveObject *obj = getobject(ref);
- +
- + if (obj == NULL) return 0;
- +
- + LuaEntitySAO* tolink = dynamic_cast<LuaEntitySAO*>(obj);
- +
- + if (tolink == NULL) return 0;
- +
- + if (tolink->unlinkEntity()) {
- + lua_pushboolean(L, true);
- + return 1;
- + }
- + else {
- + return 0;
- + }
- + }
- +
- public:
- ObjectRef(ServerActiveObject *object):
- m_object(object)
- @@ -2273,6 +2325,8 @@
- method(ObjectRef, get_look_dir),
- method(ObjectRef, get_look_pitch),
- method(ObjectRef, get_look_yaw),
- + method(ObjectRef, link),
- + method(ObjectRef, unlink),
- {0,0}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement