dl
dl_particle.h
浏览该文件的文档.
1
12#pragma once
13
14#include "io/dl_log.h"
17#include "render/dl_sprite.h"
18
19namespace dl
20{
23 {
24 bool _active; // 是否活动中
27 float _tEnd;
28 float _tLife;
29
31
33 _active{ false }
34 {}
35 };
36
39 {
41 std::array<float, 2> _radin;
43
44 void Calc()
45 {
46 _radin[0] = Math::Angle2Radian(_config.node.angle[0]);
47 _radin[1] = Math::Angle2Radian(_config.node.angle[1]);
48
50
51 _gravity = toArray(_config.system.gravity);
52 }
53 };
54
56 enum class ParticleState
57 {
58 NORMAL, // 运行中
59 WAIT, // 等待播放完成
60 STOP // 已停止
61 };
62
64 class Particle
65 {
66 friend class ParticleSystem;
67 friend class Memory::Reuse<Particle>;
68 public:
72 void Render();
80 void SetPosition(const Position& pos)
81 {
82 _pos = pos;
83 }
84
88 {
89 _posEmitter = pos;
90 }
91
94 void Replay();
99 {
100 return _state;
101 }
102
106 {
107 return _config;
108 }
109 private:
110 Particle(ParticleConfigX* config);
111 ~Particle() {}
112
113 ParticleConfigX* _config;
114 ParticleState _state; // 状态 0.激活 1.等待删除 2.休眠
115 float _tCreate; // 创建时间
116 float _tEmitter; // 上次发射时间
117 gcSprite _spr; // 模板精灵
118 Quad _sprQuad;
119 Position _pos;
120 Position _posEmitter;
121 // 等于最大数量
122 std::vector<ParicleNode> _allNode;
123
124 void _reset();
125 };
126
129 {
130 public:
137 Particle* Create(std::string_view name);
144 void Delete(Particle* par, bool wait = true);
151 void Load(std::string_view path_name, std::string_view res_name);
156 void LoadPath(std::string_view path);
157
162 void SetReadOverwirte(bool overwrite)
163 {
164 _bReadOverwrite = overwrite;
165 }
166
170 void Clear();
171
173 _bReadOverwrite{ false }
174 {}
176 private:
177 bool _bReadOverwrite;
178
179 std::unordered_map<std::string, ParticleConfigX> _allConfig;
180
181 dl::Memory::Reuse<Particle> _memoryReuse;
182 std::list<Particle*> _listDelete;
183
184 void _update();
185 };
186
188}
2d粒子实体
friend class ParticleSystem
void SetSprite(gcSprite spr)
设置基础精灵
void Render()
执行逻辑并渲染
ParticleState GetState()
返回状态
void Replay()
再次播放
const ParticleConfigX * GetConfig()
返回配置
void SetPositionEmitter(const Position &pos)
设置发射位置
void SetPosition(const Position &pos)
设置整体位置偏移
void LoadPath(std::string_view path)
加载粒子配置 @parma[in] path 文件夹
void Delete(Particle *par, bool wait=true)
删除粒子实体 @parma[in] par 实例 @parma[in] wait 是否等待播放完成后,再删除(如果是无限循环的粒子,则立即删除)
void Clear()
立即清除当前播放的粒子
void SetReadOverwirte(bool overwrite)
设置是否读取后覆盖原配置
Particle * Create(std::string_view name)
创建粒子实体 @parma[in] name 资源名
void Load(std::string_view path_name, std::string_view res_name)
加载粒子配置 @parma[in] path_name 路径 @parma[in] res_name 资源名
日志系统
复用内存
粒子系统配置
2d绘图元素
constexpr void RangeRadian(std::array< float, 2 > &arr)
constexpr float Angle2Radian(float angle)
角度转弧度
Position2 Position
ParticleSystem * g_particle
ParticleState
2d粒子状态
GC< Sprite > gcSprite
constexpr Array< T1, N > toArray(const Array< T, N > &a)
Array< Position, 4 > Quad
2d粒子配置 -> 2d粒子配置
std::array< float, 2 > _radin