clientobject.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #pragma once
  17. #include "irrlichttypes_extrabloated.h"
  18. #include "activeobject.h"
  19. #include <unordered_map>
  20. class ClientEnvironment;
  21. class ITextureSource;
  22. class Client;
  23. class IGameDef;
  24. class LocalPlayer;
  25. struct ItemStack;
  26. class WieldMeshSceneNode;
  27. class ClientActiveObject : public ActiveObject
  28. {
  29. public:
  30. ClientActiveObject(u16 id, Client *client, ClientEnvironment *env);
  31. virtual ~ClientActiveObject();
  32. virtual void addToScene(ITextureSource *tsrc) {};
  33. virtual void removeFromScene(bool permanent) {}
  34. // 0 <= light_at_pos <= LIGHT_SUN
  35. virtual void updateLight(u8 light_at_pos){}
  36. virtual void updateLightNoCheck(u8 light_at_pos){}
  37. virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
  38. virtual bool getCollisionBox(aabb3f *toset) const { return false; }
  39. virtual bool getSelectionBox(aabb3f *toset) const { return false; }
  40. virtual bool collideWithObjects() const { return false; }
  41. virtual v3f getPosition(){ return v3f(0,0,0); }
  42. virtual float getYaw() const { return 0; }
  43. virtual scene::ISceneNode *getSceneNode() { return NULL; }
  44. virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode() { return NULL; }
  45. virtual bool isLocalPlayer() const {return false;}
  46. virtual void setAttachments() {}
  47. virtual bool doShowSelectionBox(){return true;}
  48. // Step object in time
  49. virtual void step(float dtime, ClientEnvironment *env){}
  50. // Process a message sent by the server side object
  51. virtual void processMessage(const std::string &data){}
  52. virtual std::string infoText() {return "";}
  53. virtual std::string debugInfoText() {return "";}
  54. /*
  55. This takes the return value of
  56. ServerActiveObject::getClientInitializationData
  57. */
  58. virtual void initialize(const std::string &data){}
  59. // Create a certain type of ClientActiveObject
  60. static ClientActiveObject* create(ActiveObjectType type, Client *client,
  61. ClientEnvironment *env);
  62. // If returns true, punch will not be sent to the server
  63. virtual bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
  64. float time_from_last_punch=1000000)
  65. { return false; }
  66. protected:
  67. // Used for creating objects based on type
  68. typedef ClientActiveObject* (*Factory)(Client *client, ClientEnvironment *env);
  69. static void registerType(u16 type, Factory f);
  70. Client *m_client;
  71. ClientEnvironment *m_env;
  72. private:
  73. // Used for creating objects based on type
  74. static std::unordered_map<u16, Factory> m_types;
  75. };
  76. struct DistanceSortedActiveObject
  77. {
  78. ClientActiveObject *obj;
  79. f32 d;
  80. DistanceSortedActiveObject(ClientActiveObject *a_obj, f32 a_d)
  81. {
  82. obj = a_obj;
  83. d = a_d;
  84. }
  85. bool operator < (const DistanceSortedActiveObject &other) const
  86. {
  87. return d < other.d;
  88. }
  89. };