content_cao.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 <map>
  18. #include "irrlichttypes_extrabloated.h"
  19. #include "clientobject.h"
  20. #include "object_properties.h"
  21. #include "itemgroup.h"
  22. #include "constants.h"
  23. class Camera;
  24. class Client;
  25. struct Nametag;
  26. /*
  27. SmoothTranslator
  28. */
  29. struct SmoothTranslator
  30. {
  31. v3f vect_old;
  32. v3f vect_show;
  33. v3f vect_aim;
  34. f32 anim_counter = 0;
  35. f32 anim_time = 0;
  36. f32 anim_time_counter = 0;
  37. bool aim_is_end = true;
  38. SmoothTranslator() = default;
  39. void init(v3f vect);
  40. void update(v3f vect_new, bool is_end_position=false, float update_interval=-1);
  41. void translate(f32 dtime);
  42. };
  43. class GenericCAO : public ClientActiveObject
  44. {
  45. private:
  46. // Only set at initialization
  47. std::string m_name = "";
  48. bool m_is_player = false;
  49. bool m_is_local_player = false;
  50. // Property-ish things
  51. ObjectProperties m_prop;
  52. //
  53. scene::ISceneManager *m_smgr = nullptr;
  54. Client *m_client = nullptr;
  55. aabb3f m_selection_box = aabb3f(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.);
  56. scene::IMeshSceneNode *m_meshnode = nullptr;
  57. scene::IAnimatedMeshSceneNode *m_animated_meshnode = nullptr;
  58. WieldMeshSceneNode *m_wield_meshnode = nullptr;
  59. scene::IBillboardSceneNode *m_spritenode = nullptr;
  60. Nametag *m_nametag = nullptr;
  61. v3f m_position = v3f(0.0f, 10.0f * BS, 0);
  62. v3f m_velocity;
  63. v3f m_acceleration;
  64. float m_yaw = 0.0f;
  65. s16 m_hp = 1;
  66. SmoothTranslator pos_translator;
  67. // Spritesheet/animation stuff
  68. v2f m_tx_size = v2f(1,1);
  69. v2s16 m_tx_basepos;
  70. bool m_initial_tx_basepos_set = false;
  71. bool m_tx_select_horiz_by_yawpitch = false;
  72. v2s32 m_animation_range;
  73. float m_animation_speed = 15.0f;
  74. float m_animation_blend = 0.0f;
  75. bool m_animation_loop = true;
  76. // stores position and rotation for each bone name
  77. std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
  78. std::string m_attachment_bone = "";
  79. v3f m_attachment_position;
  80. v3f m_attachment_rotation;
  81. bool m_attached_to_local = false;
  82. int m_anim_frame = 0;
  83. int m_anim_num_frames = 1;
  84. float m_anim_framelength = 0.2f;
  85. float m_anim_timer = 0.0f;
  86. ItemGroupList m_armor_groups;
  87. float m_reset_textures_timer = -1.0f;
  88. // stores texture modifier before punch update
  89. std::string m_previous_texture_modifier = "";
  90. // last applied texture modifier
  91. std::string m_current_texture_modifier = "";
  92. bool m_visuals_expired = false;
  93. float m_step_distance_counter = 0.0f;
  94. u8 m_last_light = 255;
  95. bool m_is_visible = false;
  96. s8 m_glow = 0;
  97. std::vector<u16> m_children;
  98. public:
  99. GenericCAO(Client *client, ClientEnvironment *env);
  100. ~GenericCAO();
  101. static ClientActiveObject* create(Client *client, ClientEnvironment *env)
  102. {
  103. return new GenericCAO(client, env);
  104. }
  105. inline ActiveObjectType getType() const
  106. {
  107. return ACTIVEOBJECT_TYPE_GENERIC;
  108. }
  109. void initialize(const std::string &data);
  110. void processInitData(const std::string &data);
  111. ClientActiveObject *getParent() const;
  112. bool getCollisionBox(aabb3f *toset) const;
  113. bool collideWithObjects() const;
  114. virtual bool getSelectionBox(aabb3f *toset) const;
  115. v3f getPosition();
  116. inline float getYaw() const
  117. {
  118. return m_yaw;
  119. }
  120. scene::ISceneNode *getSceneNode();
  121. scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode();
  122. inline f32 getStepHeight() const
  123. {
  124. return m_prop.stepheight;
  125. }
  126. inline bool isLocalPlayer() const
  127. {
  128. return m_is_local_player;
  129. }
  130. inline bool isVisible() const
  131. {
  132. return m_is_visible;
  133. }
  134. inline void setVisible(bool toset)
  135. {
  136. m_is_visible = toset;
  137. }
  138. void setChildrenVisible(bool toset);
  139. void setAttachments();
  140. void removeFromScene(bool permanent);
  141. void addToScene(ITextureSource *tsrc);
  142. inline void expireVisuals()
  143. {
  144. m_visuals_expired = true;
  145. }
  146. void updateLight(u8 light_at_pos);
  147. void updateLightNoCheck(u8 light_at_pos);
  148. v3s16 getLightPosition();
  149. void updateNodePos();
  150. void step(float dtime, ClientEnvironment *env);
  151. void updateTexturePos();
  152. // std::string copy is mandatory as mod can be a class member and there is a swap
  153. // on those class members
  154. void updateTextures(std::string mod);
  155. void updateAnimation();
  156. void updateAnimationSpeed();
  157. void updateBonePosition();
  158. void updateAttachments();
  159. void processMessage(const std::string &data);
  160. bool directReportPunch(v3f dir, const ItemStack *punchitem=NULL,
  161. float time_from_last_punch=1000000);
  162. std::string debugInfoText();
  163. std::string infoText()
  164. {
  165. return m_prop.infotext;
  166. }
  167. };