2#include "components/GameComponents/UtilityComponents.hpp"
16 trans.recalculateMatrix();
20 if (frame++ % 60 == 0)
vex::log(LogLevel::INFO,
"ProcessParticles running... CPU count: %d, spawnTimer: %f", (
int)emit.
cpuParticles.size(), emit.
spawnTimer);
28 float rx = ((rand() % 200) / 100.0f) - 1.0f;
29 float ry = ((rand() % 200) / 100.0f) - 1.0f;
30 float rz = ((rand() % 200) / 100.0f) - 1.0f;
34 float rLife = ((rand() % 200) / 100.0f) - 1.0f;
47 it->life -= deltaTime;
48 if (it->life <= 0.0f) {
51 it->velocity += emit.
gravity * deltaTime;
52 it->position += it->velocity * deltaTime;
54 float t = 1.0f - (it->life / it->startingLife);
55 float currentSize = glm::mix(it->startSize, it->endSize, t);
57 glm::vec4 sColor(it->startColor.r, it->startColor.g, it->startColor.b, it->startColor.a);
58 glm::vec4 eColor(it->endColor.r, it->endColor.g, it->endColor.b, it->endColor.a);
59 glm::vec4 currentColor = glm::mix(sColor, eColor, t);
62 gpuData.
position = glm::vec4(it->position, 1.0f);
63 gpuData.
scaleX = currentSize;
64 gpuData.
scaleY = currentSize;
65 gpuData.
color = currentColor;
76void ProcessUtilityComponents(
vex::Registry& registry,
float deltaTime, Engine& engine) {
78 oscView.each([&](
vex::Entity entity, OscillatorComponent& osc, TransformComponent& transform) {
79 if (!osc.initialized) {
80 osc.startPosition = transform.getLocalPosition();
81 osc.initialized =
true;
84 osc.currentTime += deltaTime;
85 float wave = std::sin((osc.currentTime + osc.timeOffset) * osc.frequency) * osc.amplitude;
87 transform.setLocalPosition(osc.startPosition + (osc.axis * wave));
90 vex::View<TweenComponent, TransformComponent> tweenView(registry);
92 if (!tween.initialized) {
93 tween.startPosition = transform.getLocalPosition();
94 tween.initialized =
true;
97 tween.timeElapsed += deltaTime;
98 float t = std::clamp(tween.timeElapsed / tween.duration, 0.0f, 1.0f);
100 float ease = t * t * (3.0f - 2.0f * t);
102 glm::vec3 currentTarget = tween.returning ? tween.startPosition : (tween.startPosition + tween.targetLocalOffset);
103 glm::vec3 currentStart = tween.returning ? (tween.startPosition + tween.targetLocalOffset) : tween.startPosition;
105 transform.setLocalPosition(glm::mix(currentStart, currentTarget, ease));
108 if (tween.pingPong) {
109 tween.returning = !tween.returning;
110 tween.timeElapsed = 0.0f;
115 vex::View<LifetimeComponent> lifetimeView(registry);
117 lifetime.timeElapsed += deltaTime;
119 if (lifetime.timeElapsed >= lifetime.lifespan) {
120 for (
const auto& sceneName : engine.getSceneManager()->GetAllSceneNames()) {
121 Scene* scene = engine.getSceneManager()->GetScene(sceneName);
123 GameObject* obj = scene->GetGameObjectByEntity(entity);
125 scene->DestroyGameObject(obj);
Particle emitter component.
Its base class for all game objects, eg. Player, Enemy, Weapon. Your Class needs to inherit from it.
Central registry for managing entities and their components in the ECS system.
Scene class implements scene functionality like loading and holding game objects.
Provides iteration over entities that have all specified component types.
void each(Func func)
Iterates over all entities with the specified component types.
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
void ProcessParticles(vex::Registry ®istry, float deltaTime)
Processes CPU-side particle simulation and prepares GPU data.
Destroys the entity after a set amount of time. Useful for temporary effects.
Component that emits and manages a system of particles.
bool active
Indicates if the emitter is active and emitting particles.
vex::rgba startColor
Color of particles at spawn.
float particleLifeVariation
Random variation range applied to lifetime.
float particleLife
Base lifetime for new particles.
glm::vec3 velocityVariation
Random variation range applied to initial velocity.
std::vector< ParticleGPUData > activeParticles
GPU data buffer built every frame for rendering.
float spawnTimer
Internal timer to track time since last spawn.
float startSize
Base size for new particles.
std::vector< Particle > cpuParticles
Internal list of active CPU particles.
vex::rgba endColor
Color of particles at the end of their life.
bool isUnlit
Indicates if the particles should ignore lighting.
float endSize
Size of particles at the end of their life.
glm::vec3 initialVelocity
Base starting velocity for new particles.
glm::vec3 gravity
Gravity applied to particles.
float spawnRate
Time in seconds between particle spawns.
Structure passed to the GPU containing per-particle rendering data.
uint32_t isUnlit
Flag determining if the particle is unlit (1) or affected by lighting (0).
float scaleY
Particle vertical scale.
float scaleX
Particle horizontal scale.
glm::vec4 color
Particle color (rgba).
glm::vec4 position
Particle position (xyz) and unused (w).
CPU-side representation of a single particle during its lifetime.
vex::rgba startColor
Color at spawn.
float startingLife
Total lifetime in seconds.
vex::rgba endColor
Color at end of life.
glm::vec3 velocity
Current velocity.
float startSize
Size at spawn.
float endSize
Size at end of life.
float life
Remaining lifetime in seconds.
glm::vec3 position
Current world position.
Smoothly interpolates an entity's local position over time.