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/clientlinkableobject.cpp src/clientlinkableobject.cpp
- --- ../git/minetest.modif/src/clientlinkableobject.cpp 1970-01-01 01:00:00.000000000 +0100
- +++ src/clientlinkableobject.cpp 2012-01-09 20:18:12.000000000 +0100
- @@ -0,0 +1,121 @@
- +/*
- +Minetest-c55
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
- +Copyright (C) 2012 sapier sapier at gmx dot net
- +
- +This program is free software; you can redistribute it and/or modify
- +it under the terms of the GNU General Public License as published by
- +the Free Software Foundation; either version 2 of the License, or
- +(at your option) any later version.
- +
- +This program is distributed in the hope that it will be useful,
- +but WITHOUT ANY WARRANTY; without even the implied warranty of
- +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +GNU General Public License for more details.
- +
- +You should have received a copy of the GNU General Public License along
- +with this program; if not, write to the Free Software Foundation, Inc.,
- +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- +*/
- +
- +#include "clientlinkableobject.h"
- +
- +ClientLinkableObject::ClientLinkableObject() {
- +
- + this->m_Parent = NULL;
- +}
- +
- +ClientLinkableObject::~ClientLinkableObject() {
- + if (this->isLinked())
- + this->unlink(this);
- +}
- +
- +
- +void ClientLinkableObject::link(ClientLinkableObject* 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 ClientLinkableObject::unlink(ClientLinkableObject* entity) {
- + this->m_LinkedObjects.remove(entity);
- +}
- +
- +
- +void ClientLinkableObject::stepLinkedObjects(v3f pos,float dtime) {
- + for(std::list<ClientLinkableObject*>::iterator i = this->m_LinkedObjects.begin();
- + i != this->m_LinkedObjects.end(); i++) {
- + (*i)->setPosition(pos,dtime);
- + }
- +}
- +
- +bool ClientLinkableObject::handleLinkUnlinkMessages(u8 cmd,std::istringstream* is,ClientEnvironment *m_env) {
- + 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_cao = m_env->getActiveObject(object_id);
- +
- + ClientLinkableObject* parent = dynamic_cast<ClientLinkableObject*>(parent_cao);
- +
- + if (parent != NULL) {
- + this->linkEntity(offset,parent);
- + }
- + else {
- + errorstream << "Invalid object to link to!" << std::endl;
- + }
- + return true;
- +
- + }
- + else if(cmd == AO_Message_type::UnLink) // UnLink entity
- + {
- + if (this->m_Parent == NULL) {
- + errorstream << "Unlinking object not linked!" << std::endl;
- + }
- +
- + this->unlinkEntity();
- + return true;
- + }
- +
- + return false;
- +}
- +
- +
- +bool ClientLinkableObject::linkEntity(v3f offset, ClientLinkableObject* parent) {
- + //already linked unlink first
- + if (this->m_Parent != NULL) {
- + return false;
- + }
- +
- + //TODO add linkchain support
- + if (this->m_LinkedObjects.size() > 0) {
- + return false;
- + }
- +
- + parent->link(this);
- + this->m_linkOffset = offset;
- + this->m_Parent = parent;
- + return true;
- +}
- +
- +
- +bool ClientLinkableObject::unlinkEntity() {
- + if (this->m_Parent != NULL) {
- +
- + this->m_Parent->unlink(this);
- + this->m_Parent = NULL;
- + return true;
- +
- + }
- +
- + return false;
- +}
- +
- +bool ClientLinkableObject::isLinked() {
- + if (this->m_Parent != NULL)
- + return true;
- + else
- + return false;
- +}
- 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/clientlinkableobject.h src/clientlinkableobject.h
- --- ../git/minetest.modif/src/clientlinkableobject.h 1970-01-01 01:00:00.000000000 +0100
- +++ src/clientlinkableobject.h 2012-01-09 20:19:48.000000000 +0100
- @@ -0,0 +1,66 @@
- +/*
- +Minetest-c55
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
- +Copyright (C) 2012 sapier sapier at gmx dot net
- +
- +This program is free software; you can redistribute it and/or modify
- +it under the terms of the GNU General Public License as published by
- +the Free Software Foundation; either version 2 of the License, or
- +(at your option) any later version.
- +
- +This program is distributed in the hope that it will be useful,
- +but WITHOUT ANY WARRANTY; without even the implied warranty of
- +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +GNU General Public License for more details.
- +
- +You should have received a copy of the GNU General Public License along
- +with this program; if not, write to the Free Software Foundation, Inc.,
- +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- +*/
- +
- +#ifndef CLIENTLINKABLEOBJECT_H_
- +#define CLIENTLINKABLEOBJECT_H_
- +
- +#include <list>
- +#include <sstream>
- +#include <irrlichttypes.h>
- +#include "clientobject.h"
- +#include "environment.h"
- +#include "content_object.h"
- +#include "utility.h"
- +#include "log.h"
- +
- +
- +
- +class ClientLinkableObject {
- + public:
- + ClientLinkableObject();
- + ~ClientLinkableObject();
- + //internal communication between entitys NOT to be used by user
- + void link(ClientLinkableObject* entity);
- + void unlink(ClientLinkableObject* entity);
- +
- + virtual void setPosition(v3f toset, float dtime) = 0;
- +
- + protected:
- + void stepLinkedObjects(v3f pos,float dtime);
- +
- + bool handleLinkUnlinkMessages(u8 cmd,std::istringstream* is,ClientEnvironment *m_env);
- +
- +
- + //user driven functions (exported by lua)
- + bool linkEntity(v3f offset, ClientLinkableObject* parent);
- + bool unlinkEntity();
- +
- + bool isLinked();
- + v3f m_linkOffset;
- +
- +
- + private:
- + ClientLinkableObject* m_Parent;
- +
- + std::list<ClientLinkableObject*> m_LinkedObjects;
- +};
- +
- +
- +#endif /* CLIENTLINKABLEOBJECT_H_ */
- 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/clientobject.h src/clientobject.h
- --- ../git/minetest.modif/src/clientobject.h 2012-01-09 20:40:04.000000000 +0100
- +++ src/clientobject.h 2012-01-09 19:46:06.000000000 +0100
- @@ -1,6 +1,6 @@
- /*
- Minetest-c55
- -Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- 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/CMakeLists.txt src/CMakeLists.txt
- --- ../git/minetest.modif/src/CMakeLists.txt 2012-01-09 20:40:04.000000000 +0100
- +++ src/CMakeLists.txt 2012-01-09 19:43:21.000000000 +0100
- @@ -115,6 +115,7 @@
- content_sao_firefly.cpp
- content_sao_mobv2.cpp
- content_sao_test.cpp
- + serverlinkableobject.cpp
- mapgen.cpp
- content_nodemeta.cpp
- content_mapnode.cpp
- @@ -177,6 +178,7 @@
- content_cao_firefly.cpp
- content_cao_mobv2.cpp
- content_cao_test.cpp
- + clientlinkableobject.cpp
- mesh.cpp
- mapblock_mesh.cpp
- farmesh.cpp
- 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 20:40:04.000000000 +0100
- +++ src/content_cao_lua.cpp 2012-01-09 19:42:09.000000000 +0100
- @@ -43,6 +43,7 @@
- {
- if(gamedef == NULL)
- ClientActiveObject::registerType(LuaEntityCAO::getType(), LuaEntityCAO::create);
- +
- }
- void LuaEntityCAO::initialize(const std::string &data)
- @@ -177,35 +178,40 @@
- 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->isLinked()) {
- + 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();
- + }
- }
- + stepLinkedObjects(this->m_position,dtime);
- +
- m_anim_timer += dtime;
- if(m_anim_timer >= m_anim_framelength){
- m_anim_timer -= m_anim_framelength;
- @@ -352,4 +358,20 @@
- updateTexturePos();
- }
- + else if (handleLinkUnlinkMessages(cmd,&is,this->m_env))
- + {
- + //Link unlink already done in handleLinkUnlinkMessages!
- + }
- }
- +
- +void LuaEntityCAO::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();
- + }
- +
- +}
- 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 20:40:04.000000000 +0100
- +++ src/content_cao_lua.h 2012-01-09 19:39:48.000000000 +0100
- @@ -20,10 +20,12 @@
- #ifndef CONTENT_COA_LUA_H_
- #define CONTENT_COA_LUA_H_
- +#include <list>
- #include "content_cao.h"
- +#include "clientlinkableobject.h"
- #include "luaentity_common.h"
- -class LuaEntityCAO : public ClientActiveObject
- +class LuaEntityCAO : public ClientActiveObject, public ClientLinkableObject
- {
- private:
- core::aabbox3d<f32> m_selection_box;
- @@ -61,6 +63,8 @@
- inline v3f getPosition()
- { return pos_translator.vect_show; }
- + void setPosition(v3f toset, float dtime);
- +
- void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
- IrrlichtDevice *irr);
- 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 20:40:04.000000000 +0100
- +++ src/content_sao_lua.cpp 2012-01-09 20:08:37.000000000 +0100
- @@ -277,6 +277,10 @@
- void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
- {
- + //don't send position updates if linked
- + if (isLinked()) {
- + return;
- + }
- m_last_sent_move_precision = m_base_position.getDistanceFrom(
- m_last_sent_position);
- m_last_sent_position_timer = 0;
- @@ -311,3 +315,11 @@
- m_messages_out.push_back(aom);
- }
- +bool LuaEntitySAO::linkEntity(ServerActiveObject* parent,v3f offset) {
- + return ServerLinkableObject::linkEntity(parent,offset,getId(), &m_messages_out);
- +}
- +
- +bool LuaEntitySAO::unlinkEntity() {
- + return ServerLinkableObject::unlinkEntity(getId(), &m_messages_out);
- +}
- +
- 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 20:40:04.000000000 +0100
- +++ src/content_sao_lua.h 2012-01-09 20:06:19.000000000 +0100
- @@ -21,10 +21,11 @@
- #define CONTENT_SAO_LUA_H_
- #include "content_sao.h"
- +#include "serverlinkableobject.h"
- #include "scriptapi.h"
- #include "luaentity_common.h"
- -class LuaEntitySAO : public ServerActiveObject
- +class LuaEntitySAO : public ServerActiveObject, public ServerLinkableObject
- {
- public:
- LuaEntitySAO(ServerEnvironment *env, v3f pos,
- @@ -54,6 +55,10 @@
- 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);
- 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 20:40:04.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}
- };
- 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/serverlinkableobject.cpp src/serverlinkableobject.cpp
- --- ../git/minetest.modif/src/serverlinkableobject.cpp 1970-01-01 01:00:00.000000000 +0100
- +++ src/serverlinkableobject.cpp 2012-01-09 20:09:55.000000000 +0100
- @@ -0,0 +1,61 @@
- +/*
- +Minetest-c55
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
- +Copyright (C) 2012 sapier sapier at gmx dot net
- +
- +This program is free software; you can redistribute it and/or modify
- +it under the terms of the GNU General Public License as published by
- +the Free Software Foundation; either version 2 of the License, or
- +(at your option) any later version.
- +
- +This program is distributed in the hope that it will be useful,
- +but WITHOUT ANY WARRANTY; without even the implied warranty of
- +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +GNU General Public License for more details.
- +
- +You should have received a copy of the GNU General Public License along
- +with this program; if not, write to the Free Software Foundation, Inc.,
- +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- +*/
- +
- +#include "serverlinkableobject.h"
- +
- +
- +ServerLinkableObject::ServerLinkableObject() {
- + this->m_Linked = false;
- +}
- +
- +ServerLinkableObject::~ServerLinkableObject() {}
- +
- +bool ServerLinkableObject::linkEntity(ServerActiveObject* parent,v3f offset,u16 id, Queue<ActiveObjectMessage>* message_queue) {
- + //check if entity is in correct state
- + if (this->m_Linked == true) {
- + return false;
- + }
- + std::ostringstream os(std::ios::binary);
- + writeU8(os, AO_Message_type::Link);
- + // parameters
- + writeU16(os, parent->getId());
- + writeV3F1000(os, offset);
- +
- + this->m_Linked = true;
- + // create message and add to list
- + ActiveObjectMessage aom(id, false, os.str());
- + message_queue->push_back(aom);
- + return true;
- +}
- +
- +bool ServerLinkableObject::unlinkEntity(u16 id, Queue<ActiveObjectMessage>* message_queue) {
- + //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(id, false, os.str());
- + message_queue->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/serverlinkableobject.h src/serverlinkableobject.h
- --- ../git/minetest.modif/src/serverlinkableobject.h 1970-01-01 01:00:00.000000000 +0100
- +++ src/serverlinkableobject.h 2012-01-09 20:19:59.000000000 +0100
- @@ -0,0 +1,46 @@
- +/*
- +Minetest-c55
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
- +Copyright (C) 2012 sapier sapier at gmx dot net
- +
- +This program is free software; you can redistribute it and/or modify
- +it under the terms of the GNU General Public License as published by
- +the Free Software Foundation; either version 2 of the License, or
- +(at your option) any later version.
- +
- +This program is distributed in the hope that it will be useful,
- +but WITHOUT ANY WARRANTY; without even the implied warranty of
- +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +GNU General Public License for more details.
- +
- +You should have received a copy of the GNU General Public License along
- +with this program; if not, write to the Free Software Foundation, Inc.,
- +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- +*/
- +
- +#ifndef SERVERLINKABLEOBJECT_H_
- +#define SERVERLINKABLEOBJECT_H_
- +
- +#include <sstream>
- +#include <irrlichttypes.h>
- +#include "serverobject.h"
- +#include "content_object.h"
- +
- +class ServerLinkableObject {
- + public:
- + ServerLinkableObject();
- + ~ServerLinkableObject();
- +
- + virtual bool linkEntity(ServerActiveObject* parent,v3f offset) = 0;
- + virtual bool unlinkEntity() = 0;
- +
- + protected:
- + inline bool isLinked() { return m_Linked; }
- + bool linkEntity(ServerActiveObject* parent,v3f offset,u16 id, Queue<ActiveObjectMessage>* message_queue);
- + bool unlinkEntity(u16 id, Queue<ActiveObjectMessage>* message_queue);
- + private:
- + bool m_Linked;
- +
- +};
- +
- +#endif /* SERVERLINKABLEOBJECT_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement