Guest User

Untitled

a guest
Jan 11th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.69 KB | None | 0 0
  1. 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
  2. --- minetest/src/clientlinkableobject.cpp 1970-01-01 01:00:00.000000000 +0100
  3. +++ minetest_modif3/src/clientlinkableobject.cpp 2012-01-11 21:25:49.000000000 +0100
  4. @@ -0,0 +1,123 @@
  5. +/*
  6. +Minetest-c55
  7. +Copyright (C) 2010-2012 celeron55, Perttu Ahola <[email protected]>
  8. +Copyright (C) 2012 sapier sapier at gmx dot net
  9. +
  10. +This program is free software; you can redistribute it and/or modify
  11. +it under the terms of the GNU General Public License as published by
  12. +the Free Software Foundation; either version 2 of the License, or
  13. +(at your option) any later version.
  14. +
  15. +This program is distributed in the hope that it will be useful,
  16. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. +GNU General Public License for more details.
  19. +
  20. +You should have received a copy of the GNU General Public License along
  21. +with this program; if not, write to the Free Software Foundation, Inc.,
  22. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. +*/
  24. +
  25. +#include "clientlinkableobject.h"
  26. +
  27. +ClientLinkableObject::ClientLinkableObject() {
  28. +
  29. + this->m_Parent = NULL;
  30. +}
  31. +
  32. +ClientLinkableObject::~ClientLinkableObject() {
  33. + if (this->isLinked())
  34. + this->unlink(this);
  35. +}
  36. +
  37. +
  38. +void ClientLinkableObject::link(ClientLinkableObject* entity) {
  39. + //TODO check if entity is already linkt (shouldn't be the case but just to be sure)
  40. + this->m_LinkedObjects.push_back(entity);
  41. +}
  42. +
  43. +void ClientLinkableObject::unlink(ClientLinkableObject* entity) {
  44. + this->m_LinkedObjects.remove(entity);
  45. +}
  46. +
  47. +
  48. +void ClientLinkableObject::stepLinkedObjects(v3f pos,float dtime) {
  49. + for(std::list<ClientLinkableObject*>::iterator i = this->m_LinkedObjects.begin();
  50. + i != this->m_LinkedObjects.end(); i++) {
  51. + (*i)->setPosition(pos,dtime);
  52. + }
  53. +}
  54. +
  55. +bool ClientLinkableObject::handleLinkUnlinkMessages(u8 cmd,std::istringstream* is,ClientEnvironment *m_env) {
  56. + if(cmd == AO_Message_type::Link) // Link entity
  57. + {
  58. + //Object to link entity to
  59. + u16 object_id = readU16(*is);
  60. + //offset against linked object
  61. + v3f offset = readV3F1000(*is);
  62. +
  63. + ClientActiveObject* parent_cao = m_env->getActiveObject(object_id);
  64. +
  65. + ClientLinkableObject* parent = dynamic_cast<ClientLinkableObject*>(parent_cao);
  66. +
  67. + if (parent != NULL) {
  68. + this->linkEntity(offset,parent);
  69. + }
  70. + else {
  71. + errorstream << "Invalid object to link to!" << std::endl;
  72. + }
  73. + return true;
  74. +
  75. + }
  76. + else if(cmd == AO_Message_type::UnLink) // UnLink entity
  77. + {
  78. + if (this->m_Parent == NULL) {
  79. + errorstream << "Unlinking object not linked!" << std::endl;
  80. + }
  81. +
  82. + this->unlinkEntity();
  83. + return true;
  84. + }
  85. +
  86. + return false;
  87. +}
  88. +
  89. +
  90. +bool ClientLinkableObject::linkEntity(v3f offset, ClientLinkableObject* parent) {
  91. + //already linked unlink first
  92. + if (this->m_Parent != NULL) {
  93. + return false;
  94. + }
  95. +
  96. + //TODO add linkchain support
  97. + if (this->m_LinkedObjects.size() > 0) {
  98. + return false;
  99. + }
  100. +
  101. + parent->link(this);
  102. + updateLinkState(true);
  103. + this->m_linkOffset = offset;
  104. + this->m_Parent = parent;
  105. + return true;
  106. +}
  107. +
  108. +
  109. +bool ClientLinkableObject::unlinkEntity() {
  110. + if (this->m_Parent != NULL) {
  111. +
  112. + updateLinkState(false);
  113. + this->m_Parent->unlink(this);
  114. + this->m_Parent = NULL;
  115. + return true;
  116. +
  117. + }
  118. +
  119. + return false;
  120. +}
  121. +
  122. +bool ClientLinkableObject::isLinked() {
  123. + if (this->m_Parent != NULL)
  124. + return true;
  125. + else
  126. + return false;
  127. +}
  128. 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
  129. --- minetest/src/clientlinkableobject.h 1970-01-01 01:00:00.000000000 +0100
  130. +++ minetest_modif3/src/clientlinkableobject.h 2012-01-11 21:42:02.000000000 +0100
  131. @@ -0,0 +1,80 @@
  132. +/*
  133. +Minetest-c55
  134. +Copyright (C) 2010-2012 celeron55, Perttu Ahola <[email protected]>
  135. +Copyright (C) 2012 sapier sapier at gmx dot net
  136. +
  137. +This program is free software; you can redistribute it and/or modify
  138. +it under the terms of the GNU General Public License as published by
  139. +the Free Software Foundation; either version 2 of the License, or
  140. +(at your option) any later version.
  141. +
  142. +This program is distributed in the hope that it will be useful,
  143. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  144. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  145. +GNU General Public License for more details.
  146. +
  147. +You should have received a copy of the GNU General Public License along
  148. +with this program; if not, write to the Free Software Foundation, Inc.,
  149. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  150. +*/
  151. +
  152. +#ifndef CLIENTLINKABLEOBJECT_H_
  153. +#define CLIENTLINKABLEOBJECT_H_
  154. +
  155. +#include <list>
  156. +#include <sstream>
  157. +#include <irrlichttypes.h>
  158. +#include "clientobject.h"
  159. +#include "environment.h"
  160. +#include "content_object.h"
  161. +#include "utility.h"
  162. +#include "log.h"
  163. +
  164. +
  165. +//this ain't the right place to define this but until cao/sao split
  166. +//is decided it'll have to stay here
  167. +struct AO_Message_type {
  168. + static const u8 SetPosition = 0x00;
  169. + static const u8 SetTextureMod = 0x01;
  170. + static const u8 SetSprite = 0x02;
  171. + static const u8 Punched = 0x03;
  172. + static const u8 TakeDamage = 0x04;
  173. + static const u8 Shoot = 0x05;
  174. + static const u8 Link = 0x06;
  175. + static const u8 UnLink = 0x07;
  176. +};
  177. +
  178. +
  179. +class ClientLinkableObject {
  180. + public:
  181. + ClientLinkableObject();
  182. + ~ClientLinkableObject();
  183. + //internal communication between entitys NOT to be used by user
  184. + void link(ClientLinkableObject* entity);
  185. + void unlink(ClientLinkableObject* entity);
  186. +
  187. + virtual void setPosition(v3f toset, float dtime) = 0;
  188. + virtual void updateLinkState(bool value) = 0;
  189. +
  190. + protected:
  191. + void stepLinkedObjects(v3f pos,float dtime);
  192. +
  193. + bool handleLinkUnlinkMessages(u8 cmd,std::istringstream* is,ClientEnvironment *m_env);
  194. +
  195. +
  196. + //user driven functions (exported by lua)
  197. + bool linkEntity(v3f offset, ClientLinkableObject* parent);
  198. + bool unlinkEntity();
  199. +
  200. + bool isLinked();
  201. + v3f m_linkOffset;
  202. +
  203. +
  204. + private:
  205. + ClientLinkableObject* m_Parent;
  206. +
  207. + std::list<ClientLinkableObject*> m_LinkedObjects;
  208. +};
  209. +
  210. +
  211. +#endif /* CLIENTLINKABLEOBJECT_H_ */
  212. 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
  213. --- minetest/src/cmake_config.h 1970-01-01 01:00:00.000000000 +0100
  214. +++ minetest_modif3/src/cmake_config.h 2012-01-11 21:26:29.000000000 +0100
  215. @@ -0,0 +1,18 @@
  216. +// Filled in by the build system
  217. +
  218. +#ifndef CMAKE_CONFIG_H
  219. +#define CMAKE_CONFIG_H
  220. +
  221. +#define PROJECT_NAME "minetest"
  222. +#define INSTALL_PREFIX "/usr/local"
  223. +#define VERSION_STRING "0.4.dev-20120106-1"
  224. +#define USE_GETTEXT 1
  225. +#ifdef NDEBUG
  226. + #define BUILD_TYPE "Release"
  227. +#else
  228. + #define BUILD_TYPE "Debug"
  229. +#endif
  230. +#define BUILD_INFO "VER="VERSION_STRING" RUN_IN_PLACE=1 USE_GETTEXT=1 INSTALL_PREFIX=/usr/local BUILD_TYPE="BUILD_TYPE
  231. +
  232. +#endif
  233. +
  234. 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
  235. --- minetest/src/CMakeLists.txt 2012-01-09 20:35:52.000000000 +0100
  236. +++ minetest_modif3/src/CMakeLists.txt 2012-01-11 21:27:29.000000000 +0100
  237. @@ -115,6 +115,7 @@
  238. collision.cpp
  239. nodemetadata.cpp
  240. serverobject.cpp
  241. + serverlinkableobject.cpp
  242. noise.cpp
  243. mineral.cpp
  244. porting.cpp
  245. @@ -168,6 +169,7 @@
  246. camera.cpp
  247. clouds.cpp
  248. clientobject.cpp
  249. + clientlinkableobject.cpp
  250. guiMainMenu.cpp
  251. guiKeyChangeMenu.cpp
  252. guiMessageMenu.cpp
  253. 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
  254. --- minetest/src/scriptapi.cpp 2012-01-09 20:35:52.000000000 +0100
  255. +++ minetest_modif3/src/scriptapi.cpp 2012-01-11 21:26:16.000000000 +0100
  256. @@ -46,6 +46,7 @@
  257. #include "mapblock.h" // For getNodeBlockPos
  258. #include "content_nodemeta.h"
  259. #include "utility.h"
  260. +#include "serverlinkableobject.h"
  261.  
  262. static void stackDump(lua_State *L, std::ostream &o)
  263. {
  264. @@ -1753,7 +1754,7 @@
  265. get_server(L)->SendMovePlayer(player);
  266. return 0;
  267. }
  268. -
  269. +
  270. // moveto(self, pos, continuous=false)
  271. static int l_moveto(lua_State *L)
  272. {
  273. @@ -2173,6 +2174,62 @@
  274. return 1;
  275. }
  276.  
  277. + // link(parent, offset)
  278. + static int l_link(lua_State *L)
  279. + {
  280. + ObjectRef *ref_child = checkobject(L, 1);
  281. + ObjectRef *ref_parent = checkobject(L, 2);
  282. + v3f offset = checkFloatPos(L, 3);
  283. +
  284. + ServerActiveObject *child = getobject(ref_child);
  285. + ServerActiveObject *parent = getobject(ref_parent);
  286. +
  287. + if ((child == NULL) || (parent == NULL)) {
  288. + errorstream << "LUA: link(): invalid parameters" << std::endl;
  289. + return 0;
  290. + }
  291. +
  292. +
  293. + ServerLinkableObject* child_lua = dynamic_cast<ServerLinkableObject*>(child);
  294. + ServerLinkableObject* parent_lua = dynamic_cast<ServerLinkableObject*>(parent);
  295. +
  296. + if (child_lua == NULL) return 0;
  297. + if (parent_lua == NULL) return 0;
  298. +
  299. + if (child_lua->linkEntity(parent,offset)) {
  300. + lua_pushboolean(L, true);
  301. + return 1;
  302. + }
  303. + else {
  304. + return 0;
  305. + }
  306. + }
  307. +
  308. + // unlink()
  309. + static int l_unlink(lua_State *L)
  310. + {
  311. + ObjectRef *ref = checkobject(L, 1);
  312. +
  313. + ServerActiveObject *obj = getobject(ref);
  314. +
  315. + if (obj == NULL) {
  316. + errorstream << "LUA: unlink(): invalid parameters" << std::endl;
  317. + return 0;
  318. + }
  319. +
  320. + ServerLinkableObject* tolink = dynamic_cast<ServerLinkableObject*>(obj);
  321. +
  322. + if (tolink == NULL) return 0;
  323. +
  324. + if (tolink->unlinkEntity()) {
  325. + lua_pushboolean(L, true);
  326. + return 1;
  327. + }
  328. + else {
  329. + return 0;
  330. + }
  331. + }
  332. +
  333. public:
  334. ObjectRef(ServerActiveObject *object):
  335. m_object(object)
  336. @@ -2270,6 +2327,8 @@
  337. method(ObjectRef, get_look_dir),
  338. method(ObjectRef, get_look_pitch),
  339. method(ObjectRef, get_look_yaw),
  340. + method(ObjectRef, link),
  341. + method(ObjectRef, unlink),
  342. {0,0}
  343. };
  344.  
  345. 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
  346. --- minetest/src/serverlinkableobject.cpp 1970-01-01 01:00:00.000000000 +0100
  347. +++ minetest_modif3/src/serverlinkableobject.cpp 2012-01-11 21:25:49.000000000 +0100
  348. @@ -0,0 +1,53 @@
  349. +/*
  350. +Minetest-c55
  351. +Copyright (C) 2010-2012 celeron55, Perttu Ahola <[email protected]>
  352. +Copyright (C) 2012 sapier sapier at gmx dot net
  353. +
  354. +This program is free software; you can redistribute it and/or modify
  355. +it under the terms of the GNU General Public License as published by
  356. +the Free Software Foundation; either version 2 of the License, or
  357. +(at your option) any later version.
  358. +
  359. +This program is distributed in the hope that it will be useful,
  360. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  361. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  362. +GNU General Public License for more details.
  363. +
  364. +You should have received a copy of the GNU General Public License along
  365. +with this program; if not, write to the Free Software Foundation, Inc.,
  366. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  367. +*/
  368. +
  369. +#include "serverlinkableobject.h"
  370. +
  371. +
  372. +ServerLinkableObject::ServerLinkableObject() {
  373. + this->m_Linked = false;
  374. +}
  375. +
  376. +ServerLinkableObject::~ServerLinkableObject() {}
  377. +
  378. +bool ServerLinkableObject::linkEntity(ServerActiveObject* parent,v3f offset) {
  379. + //check if entity is in correct state
  380. + if (this->m_Linked == true) {
  381. + errorstream<<"ServerLinkableObject: link but object already linked!"<<std::endl;
  382. + return false;
  383. + }
  384. + this->m_Linked = true;
  385. +
  386. + errorstream<<"ServerLinkableObject: try to send link message!"<<std::endl;
  387. + return sendLinkMsg(parent,offset);
  388. +}
  389. +
  390. +bool ServerLinkableObject::unlinkEntity() {
  391. + //check if entity is in correct state
  392. + if (this->m_Linked == false) {
  393. + errorstream<<"ServerLinkableObject: unlink but object not linked!"<<std::endl;
  394. + return false;
  395. + }
  396. +
  397. + this->m_Linked = false;
  398. +
  399. + errorstream<<"ServerLinkableObject: try to send unlink message!"<<std::endl;
  400. + return sendUnlinkMsg();
  401. +}
  402. 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
  403. --- minetest/src/serverlinkableobject.h 1970-01-01 01:00:00.000000000 +0100
  404. +++ minetest_modif3/src/serverlinkableobject.h 2012-01-11 21:41:58.000000000 +0100
  405. @@ -0,0 +1,62 @@
  406. +/*
  407. +Minetest-c55
  408. +Copyright (C) 2010-2012 celeron55, Perttu Ahola <[email protected]>
  409. +Copyright (C) 2012 sapier sapier at gmx dot net
  410. +
  411. +This program is free software; you can redistribute it and/or modify
  412. +it under the terms of the GNU General Public License as published by
  413. +the Free Software Foundation; either version 2 of the License, or
  414. +(at your option) any later version.
  415. +
  416. +This program is distributed in the hope that it will be useful,
  417. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  418. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  419. +GNU General Public License for more details.
  420. +
  421. +You should have received a copy of the GNU General Public License along
  422. +with this program; if not, write to the Free Software Foundation, Inc.,
  423. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  424. +*/
  425. +
  426. +#ifndef SERVERLINKABLEOBJECT_H_
  427. +#define SERVERLINKABLEOBJECT_H_
  428. +
  429. +#include <sstream>
  430. +#include <irrlichttypes.h>
  431. +#include "serverobject.h"
  432. +#include "content_object.h"
  433. +#include "log.h"
  434. +
  435. +//this ain't the right place to define this but until cao/sao split
  436. +//is decided it'll have to stay here
  437. +struct AO_Message_type {
  438. + static const u8 SetPosition = 0x00;
  439. + static const u8 SetTextureMod = 0x01;
  440. + static const u8 SetSprite = 0x02;
  441. + static const u8 Punched = 0x03;
  442. + static const u8 TakeDamage = 0x04;
  443. + static const u8 Shoot = 0x05;
  444. + static const u8 Link = 0x06;
  445. + static const u8 UnLink = 0x07;
  446. +};
  447. +
  448. +class ServerLinkableObject {
  449. + public:
  450. + ServerLinkableObject();
  451. + ~ServerLinkableObject();
  452. +
  453. + bool linkEntity(ServerActiveObject* parent,v3f offset);
  454. + bool unlinkEntity();
  455. +
  456. + virtual bool sendLinkMsg(ServerActiveObject* parent,v3f offset) = 0;
  457. + virtual bool sendUnlinkMsg() = 0;
  458. +
  459. + protected:
  460. + inline bool isLinked() { return m_Linked; }
  461. +
  462. + private:
  463. + bool m_Linked;
  464. +
  465. +};
  466. +
  467. +#endif /* SERVERLINKABLEOBJECT_H_ */
Advertisement
Add Comment
Please, Sign In to add comment