1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Particle cleanup (#13394)

This commit is contained in:
DS 2023-10-11 17:07:30 +02:00 committed by GitHub
parent 352a403bd0
commit 12e98678f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 262 additions and 261 deletions

View file

@ -31,33 +31,34 @@ class ClientEnvironment;
struct MapNode;
struct ContentFeatures;
struct ClientTexture
struct ClientParticleTexture
{
/* per-spawner structure used to store the ParticleTexture structs
* that spawned particles will refer to through ClientTexRef */
* that spawned particles will refer to through ClientParticleTexRef */
ParticleTexture tex;
video::ITexture *ref = nullptr;
ClientTexture() = default;
ClientTexture(const ServerParticleTexture& p, ITextureSource *t):
ClientParticleTexture() = default;
ClientParticleTexture(const ServerParticleTexture& p, ITextureSource *t):
tex(p),
ref(t->getTextureForMesh(p.string)) {};
};
struct ClientTexRef
struct ClientParticleTexRef
{
/* per-particle structure used to avoid massively duplicating the
* fairly large ParticleTexture struct */
ParticleTexture* tex = nullptr;
video::ITexture* ref = nullptr;
ClientTexRef() = default;
ParticleTexture *tex = nullptr;
video::ITexture *ref = nullptr;
ClientParticleTexRef() = default;
/* constructor used by particles spawned from a spawner */
ClientTexRef(ClientTexture& t):
explicit ClientParticleTexRef(ClientParticleTexture &t):
tex(&t.tex), ref(t.ref) {};
/* constructor used for node particles */
ClientTexRef(decltype(ref) tp): ref(tp) {};
explicit ClientParticleTexRef(video::ITexture *tp): ref(tp) {};
};
class ParticleSpawner;
@ -70,12 +71,13 @@ public:
LocalPlayer *player,
ClientEnvironment *env,
const ParticleParameters &p,
const ClientTexRef &texture,
const ClientParticleTexRef &texture,
v2f texpos,
v2f texsize,
video::SColor color
video::SColor color,
ParticleSpawner *parent = nullptr,
std::unique_ptr<ClientParticleTexture> owned_texture = nullptr
);
~Particle();
virtual const aabb3f &getBoundingBox() const
{
@ -97,10 +99,10 @@ public:
void step(float dtime);
bool get_expired ()
bool isExpired ()
{ return m_expiration < m_time; }
ParticleSpawner *m_parent;
ParticleSpawner *getParent() { return m_parent; }
private:
void updateLight();
@ -115,33 +117,27 @@ private:
IGameDef *m_gamedef;
aabb3f m_box;
aabb3f m_collisionbox;
ClientTexRef m_texture;
ClientParticleTexRef m_texture;
video::SMaterial m_material;
v2f m_texpos;
v2f m_texsize;
v3f m_pos;
v3f m_velocity;
v3f m_acceleration;
v3f m_drag;
ParticleParamTypes::v3fRange m_jitter;
ParticleParamTypes::f32Range m_bounce;
const ParticleParameters m_p;
LocalPlayer *m_player;
float m_size;
//! Color without lighting
video::SColor m_base_color;
//! Final rendered color
video::SColor m_color;
bool m_collisiondetection;
bool m_collision_removal;
bool m_object_collision;
bool m_vertical;
v3s16 m_camera_offset;
struct TileAnimationParams m_animation;
float m_animation_time = 0.0f;
int m_animation_frame = 0;
u8 m_glow;
float m_alpha = 0.0f;
ParticleSpawner *m_parent = nullptr;
// Used if not spawned from a particlespawner
std::unique_ptr<ClientParticleTexture> m_owned_texture;
};
class ParticleSpawner
@ -149,31 +145,30 @@ class ParticleSpawner
public:
ParticleSpawner(IGameDef *gamedef,
LocalPlayer *player,
const ParticleSpawnerParameters &p,
const ParticleSpawnerParameters &params,
u16 attached_id,
std::unique_ptr<ClientTexture[]> &texpool,
size_t texcount,
ParticleManager* p_manager);
std::vector<ClientParticleTexture> &&texpool,
ParticleManager *p_manager);
void step(float dtime, ClientEnvironment *env);
size_t m_active;
bool getExpired() const
{ return m_dying || (p.amount <= 0 && p.time != 0); }
void setDying() { m_dying = true; }
{ return p.amount <= 0 && p.time != 0; }
bool hasActive() const { return m_active != 0; }
void decrActive() { m_active -= 1; }
private:
void spawnParticle(ClientEnvironment *env, float radius,
const core::matrix4 *attached_absolute_pos_rot_matrix);
size_t m_active;
ParticleManager *m_particlemanager;
float m_time;
bool m_dying;
IGameDef *m_gamedef;
LocalPlayer *m_player;
ParticleSpawnerParameters p;
std::unique_ptr<ClientTexture[]> m_texpool;
std::vector<ClientParticleTexture> m_texpool;
size_t m_texcount;
std::vector<float> m_spawntimes;
u16 m_attached_id;
@ -187,6 +182,7 @@ class ParticleManager
friend class ParticleSpawner;
public:
ParticleManager(ClientEnvironment* env);
DISABLE_CLASS_COPY(ParticleManager)
~ParticleManager();
void step (float dtime);
@ -219,10 +215,10 @@ protected:
ParticleParameters &p, video::ITexture **texture, v2f &texpos,
v2f &texsize, video::SColor *color, u8 tilenum = 0);
void addParticle(Particle* toadd);
void addParticle(std::unique_ptr<Particle> toadd);
private:
void addParticleSpawner(u64 id, ParticleSpawner *toadd);
void addParticleSpawner(u64 id, std::unique_ptr<ParticleSpawner> toadd);
void deleteParticleSpawner(u64 id);
void stepParticles(float dtime);
@ -230,13 +226,14 @@ private:
void clearAll();
std::vector<Particle*> m_particles;
std::unordered_map<u64, ParticleSpawner*> m_particle_spawners;
std::vector<std::unique_ptr<Particle>> m_particles;
std::unordered_map<u64, std::unique_ptr<ParticleSpawner>> m_particle_spawners;
std::vector<std::unique_ptr<ParticleSpawner>> m_dying_particle_spawners;
// Start the particle spawner ids generated from here after u32_max. lower values are
// for server sent spawners.
u64 m_next_particle_spawner_id = U32_MAX + 1;
ClientEnvironment* m_env;
ClientEnvironment *m_env;
std::mutex m_particle_list_lock;
std::mutex m_spawner_list_lock;
};