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 minetest/src/clientlinkableobject.cpp minetest_modif3/src/clientlinkableobject.cpp
- --- minetest/src/clientlinkableobject.cpp 1970-01-01 01:00:00.000000000 +0100
- +++ minetest_modif3/src/clientlinkableobject.cpp 2012-01-11 21:25:49.000000000 +0100
- @@ -0,0 +1,123 @@
- +/*
- +Minetest-c55
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <[email protected]>
- +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);
- + updateLinkState(true);
- + this->m_linkOffset = offset;
- + this->m_Parent = parent;
- + return true;
- +}
- +
- +
- +bool ClientLinkableObject::unlinkEntity() {
- + if (this->m_Parent != NULL) {
- +
- + updateLinkState(false);
- + 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 minetest/src/clientlinkableobject.h minetest_modif3/src/clientlinkableobject.h
- --- minetest/src/clientlinkableobject.h 1970-01-01 01:00:00.000000000 +0100
- +++ minetest_modif3/src/clientlinkableobject.h 2012-01-11 21:42:02.000000000 +0100
- @@ -0,0 +1,80 @@
- +/*
- +Minetest-c55
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <[email protected]>
- +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"
- +
- +
- +//this ain't the right place to define this but until cao/sao split
- +//is decided it'll have to stay here
- +struct AO_Message_type {
- + static const u8 SetPosition = 0x00;
- + static const u8 SetTextureMod = 0x01;
- + static const u8 SetSprite = 0x02;
- + static const u8 Punched = 0x03;
- + static const u8 TakeDamage = 0x04;
- + static const u8 Shoot = 0x05;
- + static const u8 Link = 0x06;
- + static const u8 UnLink = 0x07;
- +};
- +
- +
- +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;
- + virtual void updateLinkState(bool value) = 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 minetest/src/cmake_config.h minetest_modif3/src/cmake_config.h
- --- minetest/src/cmake_config.h 1970-01-01 01:00:00.000000000 +0100
- +++ minetest_modif3/src/cmake_config.h 2012-01-11 21:26:29.000000000 +0100
- @@ -0,0 +1,18 @@
- +// Filled in by the build system
- +
- +#ifndef CMAKE_CONFIG_H
- +#define CMAKE_CONFIG_H
- +
- +#define PROJECT_NAME "minetest"
- +#define INSTALL_PREFIX "/usr/local"
- +#define VERSION_STRING "0.4.dev-20120106-1"
- +#define USE_GETTEXT 1
- +#ifdef NDEBUG
- + #define BUILD_TYPE "Release"
- +#else
- + #define BUILD_TYPE "Debug"
- +#endif
- +#define BUILD_INFO "VER="VERSION_STRING" RUN_IN_PLACE=1 USE_GETTEXT=1 INSTALL_PREFIX=/usr/local BUILD_TYPE="BUILD_TYPE
- +
- +#endif
- +
- diff -Naur -x '*.o' -x .git -x CMakeFiles -x lua -x sqlite -x '*.s' -x cmake_install.cmake -x jthread -x Makefile minetest/src/CMakeLists.txt minetest_modif3/src/CMakeLists.txt
- --- minetest/src/CMakeLists.txt 2012-01-09 20:35:52.000000000 +0100
- +++ minetest_modif3/src/CMakeLists.txt 2012-01-11 21:27:29.000000000 +0100
- @@ -115,6 +115,7 @@
- collision.cpp
- nodemetadata.cpp
- serverobject.cpp
- + serverlinkableobject.cpp
- noise.cpp
- mineral.cpp
- porting.cpp
- @@ -168,6 +169,7 @@
- camera.cpp
- clouds.cpp
- clientobject.cpp
- + clientlinkableobject.cpp
- guiMainMenu.cpp
- guiKeyChangeMenu.cpp
- guiMessageMenu.cpp
- diff -Naur -x '*.o' -x .git -x CMakeFiles -x lua -x sqlite -x '*.s' -x cmake_install.cmake -x jthread -x Makefile minetest/src/scriptapi.cpp minetest_modif3/src/scriptapi.cpp
- --- minetest/src/scriptapi.cpp 2012-01-09 20:35:52.000000000 +0100
- +++ minetest_modif3/src/scriptapi.cpp 2012-01-11 21:26:16.000000000 +0100
- @@ -46,6 +46,7 @@
- #include "mapblock.h" // For getNodeBlockPos
- #include "content_nodemeta.h"
- #include "utility.h"
- +#include "serverlinkableobject.h"
- static void stackDump(lua_State *L, std::ostream &o)
- {
- @@ -1753,7 +1754,7 @@
- get_server(L)->SendMovePlayer(player);
- return 0;
- }
- -
- +
- // moveto(self, pos, continuous=false)
- static int l_moveto(lua_State *L)
- {
- @@ -2173,6 +2174,62 @@
- 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);
- +
- + ServerActiveObject *child = getobject(ref_child);
- + ServerActiveObject *parent = getobject(ref_parent);
- +
- + if ((child == NULL) || (parent == NULL)) {
- + errorstream << "LUA: link(): invalid parameters" << std::endl;
- + return 0;
- + }
- +
- +
- + ServerLinkableObject* child_lua = dynamic_cast<ServerLinkableObject*>(child);
- + ServerLinkableObject* parent_lua = dynamic_cast<ServerLinkableObject*>(parent);
- +
- + if (child_lua == NULL) return 0;
- + if (parent_lua == NULL) return 0;
- +
- + if (child_lua->linkEntity(parent,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) {
- + errorstream << "LUA: unlink(): invalid parameters" << std::endl;
- + return 0;
- + }
- +
- + ServerLinkableObject* tolink = dynamic_cast<ServerLinkableObject*>(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)
- @@ -2270,6 +2327,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 minetest/src/serverlinkableobject.cpp minetest_modif3/src/serverlinkableobject.cpp
- --- minetest/src/serverlinkableobject.cpp 1970-01-01 01:00:00.000000000 +0100
- +++ minetest_modif3/src/serverlinkableobject.cpp 2012-01-11 21:25:49.000000000 +0100
- @@ -0,0 +1,53 @@
- +/*
- +Minetest-c55
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <[email protected]>
- +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) {
- + //check if entity is in correct state
- + if (this->m_Linked == true) {
- + errorstream<<"ServerLinkableObject: link but object already linked!"<<std::endl;
- + return false;
- + }
- + this->m_Linked = true;
- +
- + errorstream<<"ServerLinkableObject: try to send link message!"<<std::endl;
- + return sendLinkMsg(parent,offset);
- +}
- +
- +bool ServerLinkableObject::unlinkEntity() {
- + //check if entity is in correct state
- + if (this->m_Linked == false) {
- + errorstream<<"ServerLinkableObject: unlink but object not linked!"<<std::endl;
- + return false;
- + }
- +
- + this->m_Linked = false;
- +
- + errorstream<<"ServerLinkableObject: try to send unlink message!"<<std::endl;
- + return sendUnlinkMsg();
- +}
- diff -Naur -x '*.o' -x .git -x CMakeFiles -x lua -x sqlite -x '*.s' -x cmake_install.cmake -x jthread -x Makefile minetest/src/serverlinkableobject.h minetest_modif3/src/serverlinkableobject.h
- --- minetest/src/serverlinkableobject.h 1970-01-01 01:00:00.000000000 +0100
- +++ minetest_modif3/src/serverlinkableobject.h 2012-01-11 21:41:58.000000000 +0100
- @@ -0,0 +1,62 @@
- +/*
- +Minetest-c55
- +Copyright (C) 2010-2012 celeron55, Perttu Ahola <[email protected]>
- +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"
- +#include "log.h"
- +
- +//this ain't the right place to define this but until cao/sao split
- +//is decided it'll have to stay here
- +struct AO_Message_type {
- + static const u8 SetPosition = 0x00;
- + static const u8 SetTextureMod = 0x01;
- + static const u8 SetSprite = 0x02;
- + static const u8 Punched = 0x03;
- + static const u8 TakeDamage = 0x04;
- + static const u8 Shoot = 0x05;
- + static const u8 Link = 0x06;
- + static const u8 UnLink = 0x07;
- +};
- +
- +class ServerLinkableObject {
- + public:
- + ServerLinkableObject();
- + ~ServerLinkableObject();
- +
- + bool linkEntity(ServerActiveObject* parent,v3f offset);
- + bool unlinkEntity();
- +
- + virtual bool sendLinkMsg(ServerActiveObject* parent,v3f offset) = 0;
- + virtual bool sendUnlinkMsg() = 0;
- +
- + protected:
- + inline bool isLinked() { return m_Linked; }
- +
- + private:
- + bool m_Linked;
- +
- +};
- +
- +#endif /* SERVERLINKABLEOBJECT_H_ */
Advertisement
Add Comment
Please, Sign In to add comment