Minetest  5.4.0
particles.h
Go to the documentation of this file.
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #pragma once
21 
22 #include <iostream>
24 #include "client/tile.h"
25 #include "localplayer.h"
26 #include "../particles.h"
27 
28 struct ClientEvent;
29 class ParticleManager;
30 class ClientEnvironment;
31 struct MapNode;
32 struct ContentFeatures;
33 
34 class Particle : public scene::ISceneNode
35 {
36  public:
37  Particle(
38  IGameDef* gamedef,
39  LocalPlayer *player,
40  ClientEnvironment *env,
41  const ParticleParameters &p,
42  video::ITexture *texture,
43  v2f texpos,
44  v2f texsize,
45  video::SColor color
46  );
47  ~Particle() = default;
48 
49  virtual const aabb3f &getBoundingBox() const
50  {
51  return m_box;
52  }
53 
54  virtual u32 getMaterialCount() const
55  {
56  return 1;
57  }
58 
59  virtual video::SMaterial& getMaterial(u32 i)
60  {
61  return m_material;
62  }
63 
64  virtual void OnRegisterSceneNode();
65  virtual void render();
66 
67  void step(float dtime);
68 
69  bool get_expired ()
70  { return m_expiration < m_time; }
71 
72 private:
73  void updateLight();
74  void updateVertices();
75 
76  video::S3DVertex m_vertices[4];
77  float m_time = 0.0f;
78  float m_expiration;
79 
84  video::SMaterial m_material;
91  float m_size;
93  video::SColor m_base_color;
95  video::SColor m_color;
99  bool m_vertical;
102  float m_animation_time = 0.0f;
104  u8 m_glow;
105 };
106 
108 {
109 public:
110  ParticleSpawner(IGameDef* gamedef,
111  LocalPlayer *player,
113  u16 attached_id,
114  video::ITexture *texture,
115  ParticleManager* p_manager);
116 
117  ~ParticleSpawner() = default;
118 
119  void step(float dtime, ClientEnvironment *env);
120 
121  bool get_expired ()
122  { return p.amount <= 0 && p.time != 0; }
123 
124 private:
125  void spawnParticle(ClientEnvironment *env, float radius,
126  const core::matrix4 *attached_absolute_pos_rot_matrix);
127 
129  float m_time;
133  video::ITexture *m_texture;
134  std::vector<float> m_spawntimes;
136 };
137 
142 {
143 friend class ParticleSpawner;
144 public:
147 
148  void step (float dtime);
149 
151  LocalPlayer *player);
152 
153  void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
154  const MapNode &n, const ContentFeatures &f);
155 
156  void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos,
157  const MapNode &n, const ContentFeatures &f);
158 
167  {
169  }
170 
171 protected:
172  static bool getNodeParticleParams(const MapNode &n, const ContentFeatures &f,
173  ParticleParameters &p, video::ITexture **texture, v2f &texpos,
174  v2f &texsize, video::SColor *color, u8 tilenum = 0);
175 
176  void addParticle(Particle* toadd);
177 
178 private:
179  void addParticleSpawner(u64 id, ParticleSpawner *toadd);
180  void deleteParticleSpawner(u64 id);
181 
182  void stepParticles(float dtime);
183  void stepSpawners(float dtime);
184 
185  void clearAll();
186 
187  std::vector<Particle*> m_particles;
188  std::unordered_map<u64, ParticleSpawner*> m_particle_spawners;
189  // Start the particle spawner ids generated from here after u32_max. lower values are
190  // for server sent spawners.
192 
196 };
Definition: clientenvironment.h:64
Definition: client.h:109
Definition: gamedef.h:49
Definition: localplayer.h:45
Class doing particle as well as their spawners handling.
Definition: particles.h:142
u64 m_next_particle_spawner_id
Definition: particles.h:191
std::mutex m_particle_list_lock
Definition: particles.h:194
void stepSpawners(float dtime)
Definition: particles.cpp:407
static bool getNodeParticleParams(const MapNode &n, const ContentFeatures &f, ParticleParameters &p, video::ITexture **texture, v2f &texpos, v2f &texsize, video::SColor *color, u8 tilenum=0)
Definition: particles.cpp:519
void clearAll()
Definition: particles.cpp:436
~ParticleManager()
Definition: particles.cpp:396
void addParticle(Particle *toadd)
Definition: particles.cpp:619
void stepParticles(float dtime)
Definition: particles.cpp:421
void addNodeParticle(IGameDef *gamedef, LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
Definition: particles.cpp:576
void step(float dtime)
Definition: particles.cpp:401
void addParticleSpawner(u64 id, ParticleSpawner *toadd)
Definition: particles.cpp:626
std::vector< Particle * > m_particles
Definition: particles.h:187
u64 generateSpawnerId()
This function is only used by client particle spawners.
Definition: particles.h:166
void deleteParticleSpawner(u64 id)
Definition: particles.cpp:632
void addDiggingParticles(IGameDef *gamedef, LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
Definition: particles.cpp:561
void handleParticleEvent(ClientEvent *event, Client *client, LocalPlayer *player)
Definition: particles.cpp:453
ParticleManager(ClientEnvironment *env)
Definition: particles.cpp:392
ClientEnvironment * m_env
Definition: particles.h:193
std::unordered_map< u64, ParticleSpawner * > m_particle_spawners
Definition: particles.h:188
std::mutex m_spawner_list_lock
Definition: particles.h:195
Definition: particles.h:108
ParticleSpawnerParameters p
Definition: particles.h:132
float m_time
Definition: particles.h:129
~ParticleSpawner()=default
bool get_expired()
Definition: particles.h:121
std::vector< float > m_spawntimes
Definition: particles.h:134
IGameDef * m_gamedef
Definition: particles.h:130
video::ITexture * m_texture
Definition: particles.h:133
void step(float dtime, ClientEnvironment *env)
Definition: particles.cpp:341
u16 m_attached_id
Definition: particles.h:135
void spawnParticle(ClientEnvironment *env, float radius, const core::matrix4 *attached_absolute_pos_rot_matrix)
Definition: particles.cpp:272
LocalPlayer * m_player
Definition: particles.h:131
ParticleManager * m_particlemanager
Definition: particles.h:128
ParticleSpawner(IGameDef *gamedef, LocalPlayer *player, const ParticleSpawnerParameters &p, u16 attached_id, video::ITexture *texture, ParticleManager *p_manager)
Definition: particles.cpp:249
Definition: particles.h:35
v3f m_velocity
Definition: particles.h:88
virtual void render()
Definition: particles.cpp:122
bool m_collisiondetection
Definition: particles.h:96
video::S3DVertex m_vertices[4]
Definition: particles.h:76
bool get_expired()
Definition: particles.h:69
bool m_object_collision
Definition: particles.h:98
struct TileAnimationParams m_animation
Definition: particles.h:101
v3f m_pos
Definition: particles.h:87
bool m_vertical
Definition: particles.h:99
float m_animation_time
Definition: particles.h:102
aabb3f m_box
Definition: particles.h:82
LocalPlayer * m_player
Definition: particles.h:90
IGameDef * m_gamedef
Definition: particles.h:81
v2f m_texpos
Definition: particles.h:85
virtual void OnRegisterSceneNode()
Definition: particles.cpp:114
~Particle()=default
void step(float dtime)
Definition: particles.cpp:134
Particle(IGameDef *gamedef, LocalPlayer *player, ClientEnvironment *env, const ParticleParameters &p, video::ITexture *texture, v2f texpos, v2f texsize, video::SColor color)
Definition: particles.cpp:57
virtual video::SMaterial & getMaterial(u32 i)
Definition: particles.h:59
float m_time
Definition: particles.h:77
v3s16 m_camera_offset
Definition: particles.h:100
u8 m_glow
Definition: particles.h:104
bool m_collision_removal
Definition: particles.h:97
v3f m_acceleration
Definition: particles.h:89
video::SMaterial m_material
Definition: particles.h:84
virtual u32 getMaterialCount() const
Definition: particles.h:54
float m_expiration
Definition: particles.h:78
virtual const aabb3f & getBoundingBox() const
Definition: particles.h:49
v2f m_texsize
Definition: particles.h:86
video::SColor m_base_color
Color without lighting.
Definition: particles.h:93
video::SColor m_color
Final rendered color.
Definition: particles.h:95
void updateVertices()
Definition: particles.cpp:198
ClientEnvironment * m_env
Definition: particles.h:80
void updateLight()
Definition: particles.cpp:175
float m_size
Definition: particles.h:91
aabb3f m_collisionbox
Definition: particles.h:83
int m_animation_frame
Definition: particles.h:103
core::aabbox3d< f32 > aabb3f
Definition: irr_aabb3d.h:26
core::vector2d< f32 > v2f
Definition: irr_v2d.h:26
core::vector3d< s16 > v3s16
Definition: irr_v3d.h:28
core::vector3df v3f
Definition: irr_v3d.h:26
#define U32_MAX
Definition: irrlichttypes.h:79
Definition: activeobjectmgr.cpp:25
Definition: clientevent.h:56
Definition: nodedef.h:279
Definition: mapnode.h:118
Definition: particles.h:61
Definition: particles.h:72
u16 amount
Definition: particles.h:73
f32 time
Definition: particles.h:75
Definition: tileanimation.h:33
std::string p(std::string path)
Definition: test_filepath.cpp:59