add 'frames' particles setting
This commit is contained in:
@@ -58,6 +58,9 @@ void Emitter::update(
|
||||
} else if (auto entityId = std::get_if<entityid_t>(&origin)) {
|
||||
if (auto entity = level.entities->get(*entityId)) {
|
||||
position = entity->getTransform().pos;
|
||||
} else {
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
const float maxDistance = preset.maxDistance;
|
||||
@@ -102,6 +105,10 @@ void Emitter::update(
|
||||
}
|
||||
}
|
||||
|
||||
void Emitter::stop() {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
bool Emitter::isDead() const {
|
||||
return count == 0;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,10 @@ public:
|
||||
const glm::vec3& cameraPosition,
|
||||
std::vector<Particle>& particles
|
||||
);
|
||||
|
||||
|
||||
/// @brief Set remaining particles count to 0
|
||||
void stop();
|
||||
|
||||
/// @return true if the emitter has spawned all particles
|
||||
bool isDead() const;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ParticlesRenderer.hpp"
|
||||
|
||||
#include "assets/Assets.hpp"
|
||||
#include "assets/assets_util.hpp"
|
||||
#include "graphics/core/Shader.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "graphics/render/MainBatch.hpp"
|
||||
@@ -17,6 +18,7 @@ ParticlesRenderer::ParticlesRenderer(
|
||||
)
|
||||
: batch(std::make_unique<MainBatch>(1024)),
|
||||
level(level),
|
||||
assets(assets),
|
||||
settings(settings) {}
|
||||
|
||||
ParticlesRenderer::~ParticlesRenderer() = default;
|
||||
@@ -59,6 +61,23 @@ void ParticlesRenderer::renderParticles(const Camera& camera, float delta) {
|
||||
auto& particle = *iter;
|
||||
auto& preset = particle.emitter->preset;
|
||||
|
||||
if (!preset.frames.empty()) {
|
||||
float time = preset.lifetime - particle.lifetime;
|
||||
int framesCount = preset.frames.size();
|
||||
int frameid = time / preset.lifetime * framesCount;
|
||||
int frameid2 = glm::min(
|
||||
(time + delta) / preset.lifetime * framesCount,
|
||||
framesCount - 1.0f
|
||||
);
|
||||
if (frameid2 != frameid) {
|
||||
auto tregion = util::get_texture_region(
|
||||
assets, preset.frames.at(frameid2), ""
|
||||
);
|
||||
if (tregion.texture == texture) {
|
||||
particle.region = tregion.region;
|
||||
}
|
||||
}
|
||||
}
|
||||
update_particle(particle, delta, chunks);
|
||||
|
||||
glm::vec4 light(1, 1, 1, 0);
|
||||
|
||||
@@ -15,6 +15,7 @@ struct GraphicsSettings;
|
||||
|
||||
class ParticlesRenderer {
|
||||
const Level& level;
|
||||
const Assets& assets;
|
||||
const GraphicsSettings* settings;
|
||||
std::unordered_map<const Texture*, std::vector<Particle>> particles;
|
||||
std::vector<std::unique_ptr<Emitter>> emitters;
|
||||
|
||||
Reference in New Issue
Block a user