clientobject.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef CLIENTOBJECT_HEADER
  17. #define CLIENTOBJECT_HEADER
  18. #include "irrlichttypes_extrabloated.h"
  19. #include "activeobject.h"
  20. #include <map>
  21. /*
  22. Some planning
  23. -------------
  24. * Client receives a network packet with information of added objects
  25. in it
  26. * Client supplies the information to its ClientEnvironment
  27. * The environment adds the specified objects to itself
  28. */
  29. class ClientEnvironment;
  30. class ITextureSource;
  31. class IGameDef;
  32. class LocalPlayer;
  33. struct ItemStack;
  34. class ClientActiveObject : public ActiveObject
  35. {
  36. public:
  37. ClientActiveObject(u16 id, IGameDef *gamedef, ClientEnvironment *env);
  38. virtual ~ClientActiveObject();
  39. virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
  40. IrrlichtDevice *irr){}
  41. virtual void removeFromScene(bool permanent){}
  42. // 0 <= light_at_pos <= LIGHT_SUN
  43. virtual void updateLight(u8 light_at_pos){}
  44. virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
  45. virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
  46. virtual bool getCollisionBox(aabb3f *toset){return false;}
  47. virtual bool collideWithObjects(){return false;}
  48. virtual v3f getPosition(){return v3f(0,0,0);}
  49. virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
  50. virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}
  51. virtual scene::IBillboardSceneNode *getSpriteSceneNode(){return NULL;}
  52. virtual bool isPlayer() const {return false;}
  53. virtual bool isLocalPlayer() const {return false;}
  54. virtual void setAttachments(){}
  55. virtual bool doShowSelectionBox(){return true;}
  56. virtual void updateCameraOffset(v3s16 camera_offset){};
  57. // Step object in time
  58. virtual void step(float dtime, ClientEnvironment *env){}
  59. // Process a message sent by the server side object
  60. virtual void processMessage(const std::string &data){}
  61. virtual std::string infoText() {return "";}
  62. virtual std::string debugInfoText() {return "";}
  63. /*
  64. This takes the return value of
  65. ServerActiveObject::getClientInitializationData
  66. */
  67. virtual void initialize(const std::string &data){}
  68. // Create a certain type of ClientActiveObject
  69. static ClientActiveObject* create(u8 type, IGameDef *gamedef,
  70. ClientEnvironment *env);
  71. // If returns true, punch will not be sent to the server
  72. virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
  73. float time_from_last_punch=1000000)
  74. { return false; }
  75. protected:
  76. // Used for creating objects based on type
  77. typedef ClientActiveObject* (*Factory)(IGameDef *gamedef, ClientEnvironment *env);
  78. static void registerType(u16 type, Factory f);
  79. IGameDef *m_gamedef;
  80. ClientEnvironment *m_env;
  81. private:
  82. // Used for creating objects based on type
  83. static std::map<u16, Factory> m_types;
  84. };
  85. struct DistanceSortedActiveObject
  86. {
  87. ClientActiveObject *obj;
  88. f32 d;
  89. DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
  90. {
  91. obj = a_obj;
  92. d = a_d;
  93. }
  94. bool operator < (const DistanceSortedActiveObject &other) const
  95. {
  96. return d < other.d;
  97. }
  98. };
  99. #endif