implement entity-bound emitters
This commit is contained in:
parent
6d63c71221
commit
83ddbda90b
@ -6,15 +6,19 @@
|
|||||||
|
|
||||||
#include "window/Camera.hpp"
|
#include "window/Camera.hpp"
|
||||||
#include "graphics/core/Texture.hpp"
|
#include "graphics/core/Texture.hpp"
|
||||||
|
#include "objects/Entities.hpp"
|
||||||
|
#include "world/Level.hpp"
|
||||||
|
|
||||||
Emitter::Emitter(
|
Emitter::Emitter(
|
||||||
|
const Level& level,
|
||||||
std::variant<glm::vec3, entityid_t> origin,
|
std::variant<glm::vec3, entityid_t> origin,
|
||||||
Particle prototype,
|
Particle prototype,
|
||||||
const Texture* texture,
|
const Texture* texture,
|
||||||
float spawnInterval,
|
float spawnInterval,
|
||||||
int count
|
int count
|
||||||
)
|
)
|
||||||
: origin(std::move(origin)),
|
: level(level),
|
||||||
|
origin(std::move(origin)),
|
||||||
prototype(std::move(prototype)),
|
prototype(std::move(prototype)),
|
||||||
texture(texture),
|
texture(texture),
|
||||||
spawnInterval(spawnInterval),
|
spawnInterval(spawnInterval),
|
||||||
@ -38,8 +42,10 @@ void Emitter::update(
|
|||||||
glm::vec3 position {};
|
glm::vec3 position {};
|
||||||
if (auto staticPos = std::get_if<glm::vec3>(&origin)) {
|
if (auto staticPos = std::get_if<glm::vec3>(&origin)) {
|
||||||
position = *staticPos;
|
position = *staticPos;
|
||||||
} else {
|
} else if (auto entityId = std::get_if<entityid_t>(&origin)) {
|
||||||
// TODO: implement for entity origin
|
if (auto entity = level.entities->get(*entityId)) {
|
||||||
|
position = entity->getTransform().pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (glm::distance2(position, cameraPosition) > maxDistance * maxDistance) {
|
if (glm::distance2(position, cameraPosition) > maxDistance * maxDistance) {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include "maths/UVRegion.hpp"
|
#include "maths/UVRegion.hpp"
|
||||||
#include "maths/util.hpp"
|
#include "maths/util.hpp"
|
||||||
|
|
||||||
|
class Level;
|
||||||
class Emitter;
|
class Emitter;
|
||||||
|
|
||||||
struct Particle {
|
struct Particle {
|
||||||
@ -36,6 +37,7 @@ struct ParticleBehaviour {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Emitter {
|
class Emitter {
|
||||||
|
const Level& level;
|
||||||
/// @brief Static position or entity
|
/// @brief Static position or entity
|
||||||
std::variant<glm::vec3, entityid_t> origin;
|
std::variant<glm::vec3, entityid_t> origin;
|
||||||
/// @brief Particle prototype
|
/// @brief Particle prototype
|
||||||
@ -60,6 +62,7 @@ public:
|
|||||||
ParticleBehaviour behaviour;
|
ParticleBehaviour behaviour;
|
||||||
|
|
||||||
Emitter(
|
Emitter(
|
||||||
|
const Level& level,
|
||||||
std::variant<glm::vec3, entityid_t> origin,
|
std::variant<glm::vec3, entityid_t> origin,
|
||||||
Particle prototype,
|
Particle prototype,
|
||||||
const Texture* texture,
|
const Texture* texture,
|
||||||
|
|||||||
@ -19,10 +19,15 @@ ParticlesRenderer::ParticlesRenderer(
|
|||||||
: batch(std::make_unique<MainBatch>(1024)),
|
: batch(std::make_unique<MainBatch>(1024)),
|
||||||
level(level),
|
level(level),
|
||||||
settings(settings) {
|
settings(settings) {
|
||||||
auto region = util::get_texture_region(assets, "blocks:grass_top", "");
|
auto region = util::get_texture_region(assets, "blocks:grass_side", "");
|
||||||
emitters.push_back(std::make_unique<Emitter>(glm::vec3(0, 80, 0), Particle {
|
emitters.push_back(std::make_unique<Emitter>(
|
||||||
nullptr, 0, glm::vec3(), glm::vec3(), 5.0f, region.region
|
level,
|
||||||
}, region.texture, 0.002f, -1));
|
glm::vec3(0, 80, 0),
|
||||||
|
Particle {nullptr, 0, glm::vec3(), glm::vec3(), 5.0f, region.region},
|
||||||
|
region.texture,
|
||||||
|
0.002f,
|
||||||
|
-1
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
ParticlesRenderer::~ParticlesRenderer() = default;
|
ParticlesRenderer::~ParticlesRenderer() = default;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user