| 203 | ParticleNode::~ParticleNode() { } |
| 204 | |
| 205 | bool ParticleNode::init() { |
| 206 | if (!Node::init()) return false; |
| 207 | if (!_particleDef) { |
| 208 | setAsManaged(); |
| 209 | return false; |
| 210 | } |
| 211 | _particles.reserve(_particleDef->maxParticles); |
| 212 | _quads.reserve(_particleDef->maxParticles); |
| 213 | Rect textureRect = _particleDef->textureRect; |
| 214 | if (!_particleDef->textureName.empty()) { |
| 215 | if (SharedClipCache.isClip(_particleDef->textureName) && SharedClipCache.isFileExist(_particleDef->textureName)) { |
| 216 | Texture2D* tex = nullptr; |
| 217 | Rect rect; |
| 218 | std::tie(tex, rect) = SharedClipCache.loadTexture(_particleDef->textureName); |
| 219 | if (tex) { |
| 220 | _texture = tex; |
| 221 | textureRect = rect; |
| 222 | } |
| 223 | } else if (SharedContent.exist(_particleDef->textureName) && !SharedContent.isFolder(_particleDef->textureName)) { |
| 224 | _texture = SharedTextureCache.load(_particleDef->textureName); |
| 225 | } |
| 226 | } |
| 227 | if (!_texture) { |
| 228 | textureRect = Rect::zero; |
| 229 | _texture = SharedTextureCache.get("__defaultParticleTexture.png"); |
| 230 | if (!_texture) { |
| 231 | _texture = SharedTextureCache.update( |
| 232 | "__defaultParticleTexture.png", |
| 233 | __defaultParticleTexturePng, |
| 234 | sizeof(__defaultParticleTexturePng)); |
| 235 | } |
| 236 | } |
| 237 | if (textureRect != Rect::zero) { |
| 238 | const bgfx::TextureInfo& info = _texture->getInfo(); |
| 239 | _texLeft = textureRect.getX() / info.width; |
| 240 | _texTop = textureRect.getY() / info.height; |
| 241 | _texRight = (textureRect.getX() + textureRect.getWidth()) / info.width; |
| 242 | _texBottom = (textureRect.getY() + textureRect.getHeight()) / info.height; |
| 243 | } else { |
| 244 | _texRight = 1.0f; |
| 245 | _texBottom = 1.0f; |
| 246 | } |
| 247 | return true; |
| 248 | } |
| 249 | |
| 250 | bool ParticleNode::isActive() const noexcept { |
| 251 | return _flags.isOn(ParticleNode::Active); |
nothing calls this directly
no test coverage detected