content_cao.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 CONTENT_CAO_HEADER
  17. #define CONTENT_CAO_HEADER
  18. #include <map>
  19. #include "irrlichttypes_extrabloated.h"
  20. #include "content_object.h"
  21. #include "clientobject.h"
  22. #include "object_properties.h"
  23. #include "itemgroup.h"
  24. /*
  25. SmoothTranslator
  26. */
  27. struct SmoothTranslator
  28. {
  29. v3f vect_old;
  30. v3f vect_show;
  31. v3f vect_aim;
  32. f32 anim_counter;
  33. f32 anim_time;
  34. f32 anim_time_counter;
  35. bool aim_is_end;
  36. SmoothTranslator();
  37. void init(v3f vect);
  38. void sharpen();
  39. void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
  40. void translate(f32 dtime);
  41. bool is_moving();
  42. };
  43. class GenericCAO : public ClientActiveObject
  44. {
  45. private:
  46. // Only set at initialization
  47. std::string m_name;
  48. bool m_is_player;
  49. bool m_is_local_player;
  50. int m_id;
  51. // Property-ish things
  52. ObjectProperties m_prop;
  53. //
  54. scene::ISceneManager *m_smgr;
  55. IrrlichtDevice *m_irr;
  56. core::aabbox3d<f32> m_selection_box;
  57. scene::IMeshSceneNode *m_meshnode;
  58. scene::IAnimatedMeshSceneNode *m_animated_meshnode;
  59. scene::IBillboardSceneNode *m_spritenode;
  60. scene::ITextSceneNode* m_textnode;
  61. v3f m_position;
  62. v3f m_velocity;
  63. v3f m_acceleration;
  64. float m_yaw;
  65. s16 m_hp;
  66. SmoothTranslator pos_translator;
  67. // Spritesheet/animation stuff
  68. v2f m_tx_size;
  69. v2s16 m_tx_basepos;
  70. bool m_initial_tx_basepos_set;
  71. bool m_tx_select_horiz_by_yawpitch;
  72. v2s32 m_animation_range;
  73. int m_animation_speed;
  74. int m_animation_blend;
  75. std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
  76. std::string m_attachment_bone;
  77. v3f m_attachment_position;
  78. v3f m_attachment_rotation;
  79. bool m_attached_to_local;
  80. int m_anim_frame;
  81. int m_anim_num_frames;
  82. float m_anim_framelength;
  83. float m_anim_timer;
  84. ItemGroupList m_armor_groups;
  85. float m_reset_textures_timer;
  86. bool m_visuals_expired;
  87. float m_step_distance_counter;
  88. u8 m_last_light;
  89. bool m_is_visible;
  90. std::vector<u16> m_children;
  91. public:
  92. GenericCAO(IGameDef *gamedef, ClientEnvironment *env);
  93. ~GenericCAO();
  94. static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
  95. {
  96. return new GenericCAO(gamedef, env);
  97. }
  98. inline u8 getType() const
  99. {
  100. return ACTIVEOBJECT_TYPE_GENERIC;
  101. }
  102. void initialize(const std::string &data);
  103. ClientActiveObject *getParent();
  104. bool getCollisionBox(aabb3f *toset);
  105. bool collideWithObjects();
  106. core::aabbox3d<f32>* getSelectionBox();
  107. v3f getPosition();
  108. scene::IMeshSceneNode *getMeshSceneNode();
  109. scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
  110. scene::IBillboardSceneNode *getSpriteSceneNode();
  111. inline bool isPlayer() const
  112. {
  113. return m_is_player;
  114. }
  115. inline bool isLocalPlayer() const
  116. {
  117. return m_is_local_player;
  118. }
  119. inline bool isVisible() const
  120. {
  121. return m_is_visible;
  122. }
  123. inline void setVisible(bool toset)
  124. {
  125. m_is_visible = toset;
  126. }
  127. void setAttachments();
  128. void removeFromScene(bool permanent);
  129. void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
  130. IrrlichtDevice *irr);
  131. inline void expireVisuals()
  132. {
  133. m_visuals_expired = true;
  134. }
  135. void updateLight(u8 light_at_pos);
  136. v3s16 getLightPosition();
  137. void updateNodePos();
  138. void step(float dtime, ClientEnvironment *env);
  139. void updateTexturePos();
  140. void updateTextures(const std::string &mod);
  141. void updateAnimation();
  142. void updateBonePosition();
  143. void updateAttachments();
  144. void processMessage(const std::string &data);
  145. bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
  146. float time_from_last_punch=1000000);
  147. std::string debugInfoText();
  148. };
  149. #endif