Repository navigation
Particle Break Callback - #3721
Crepestrom wants to merge 17 commits into
Conversation
Co-authored-by: Wunka <56411012+Wunka@users.noreply.github.com>
Co-authored-by: Wunka <56411012+Wunka@users.noreply.github.com>
Co-authored-by: Wunka <56411012+Wunka@users.noreply.github.com>
|
thanks for making this easier to read wunka |
IntegratedQuantum
left a comment
There was a problem hiding this comment.
Also I do want to note one more time:
What's the point of particle changes, when we still don't have particles anywhere???
| } | ||
|
|
||
| pub fn run(_: *@This(), params: main.callbacks.ParticleCollideCallback.Params) main.callbacks.Result { | ||
| params.source.currentFrame = 0; |
There was a problem hiding this comment.
This is a bad solution. This makes the particle stick around for another frame, likely long enough to make it show up as a black particle for one frame (due to lighting being black inside of blocks)
There was a problem hiding this comment.
ok i fixed that by changing a different line
There was a problem hiding this comment.
This should not be fixed by changing a different line.
The interface is lacking a way to remove the currently viewed particle. You hacked around it by setting a different property. This is not good design. The API accessible to mods should be self-documenting.
Also consider a particle death callback, maybe we want one particle type (e.g. fire) decay into a different one (e.g. smoke) when reaching the timer. Now instead of removing the particle from the list you'd also still spawn the smoke particle.
There was a problem hiding this comment.
ok created a proper funciton for deleting partcles that this calls
| zon.getChildOrNull("onTouch") orelse break :blk .noop, | ||
| .{ | ||
| .particle = .{ | ||
| .typ = @intCast(types.items.len), |
There was a problem hiding this comment.
This information is completely useless to the callback, in fact if they were to use it, it would cause a crash due to the data not being initialized.
There was a problem hiding this comment.
this was mostly for letting the callback know what type of particle it was messing with
i have changed the .position = undefined
There was a problem hiding this comment.
That was not the issue. typ points at uninitialized memory.
There was a problem hiding this comment.
ok i have mirrored how blocks do it where it inits the callback after registering all of the particles
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
| } | ||
| } | ||
| pos = @as(Vec3f, @floatCast(v3Pos - playerPos)); | ||
| _ = if (hasCollided) particle_manager.typesLocal.items[particle.typ].onCollide.run(.{.source = particle, .pos = pos}); |
There was a problem hiding this comment.
The callback should be evaluated with data about the collision, otherwise you cannot e.g. make water drops split into smaller particles that jump away from the collision when hitting the ground.
Maybe the default collision response could even be part of the callback.
There was a problem hiding this comment.
hmm that is a interesting idea of the colision response being a callback
for now i have just given what direction it colided from as a parameter
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
|
updated test command to be more visible |
I need this specifically for implementing weather as even the particle tests we do in the playtest sessions looks cool |
| var colisionDelta: Vec3f = .{0, 0, 0}; | ||
| hasCollided = hasCollided or collideOnAxis(&v3Pos, posDelta, hitBox, 0, &colisionDelta); | ||
| hasCollided = hasCollided or collideOnAxis(&v3Pos, posDelta, hitBox, 1, &colisionDelta); | ||
| hasCollided = hasCollided or collideOnAxis(&v3Pos, posDelta, hitBox, 2, &colisionDelta); |
There was a problem hiding this comment.
Now it will clip into the ground if it collides on multiple axis at once, since or does not execute the right hand side when the left hand side is already true.
Also I think the callback would need to run inside the function to make it handle angled surfaces correctly (see other comment)
| } | ||
|
|
||
| pub fn run(_: *@This(), params: main.callbacks.ParticleCollideCallback.Params) main.callbacks.Result { | ||
| main.particles.particle_system.removeParticle(params.particleIndex); |
There was a problem hiding this comment.
You can't call it like that, the parent loop is not properly handling removal during iteration, and the particle that gets swapped into this index will be skipped for this update step, causing it to freeze mid-air for one frame.
| while (iterator.next()) |entry| { | ||
| particles.particle_manager.register(assetFolder, entry.key_ptr.*, entry.value_ptr.*); | ||
| } | ||
| iterator.index = 0; |
There was a problem hiding this comment.
Don't mess with the internal state of the iterator. Get a fresh one instead.
| v3Pos.*[dir] += posDelta[dir]; | ||
| if (physics.collision.collides(.client, @fromBackingInt(dir), -posDelta[dir], v3Pos.*, hitBox)) |box| { | ||
| if (posDelta[dir] < 0) { | ||
| colisionDelta[dir] = 1; |
There was a problem hiding this comment.
This is not a delta value. Please use a more fitting name, maybe collisionDirection?
Though ideally we'd use the raw normal, to make particles bounce correctly on angled surfaces.
Implements a Callback when a particle touches a block that destroys the particle
currently implmented on cubyz:flame
test commnd:
/particles cubyz:flame ~ ~ ~ 1000 .{.lifeTime=100}