Skip to content

Commit 766fb7b

Browse files
authoredSep 7, 2018
Particles: Make collision with objects optional (#7682)
Also set it to false for node dig particles, as they are often created and high in number. Improve particle documentation.
1 parent 6ed9c6f commit 766fb7b

File tree

9 files changed

+120
-59
lines changed

9 files changed

+120
-59
lines changed
 

‎doc/lua_api.txt

+25-9
Original file line numberDiff line numberDiff line change
@@ -6619,14 +6619,21 @@ Used by `minetest.add_particle`.
66196619
-- Disappears after expirationtime seconds
66206620

66216621
size = 1,
6622+
-- Scales the visual size of the particle texture.
66226623

66236624
collisiondetection = false,
6624-
-- If true collides with physical objects
6625+
-- If true collides with `walkable` nodes and, depending on the
6626+
-- `object_collision` field, objects too.
66256627

66266628
collision_removal = false,
66276629
-- If true particle is removed when it collides.
66286630
-- Requires collisiondetection = true to have any effect.
66296631

6632+
object_collision = false,
6633+
-- If true particle collides with objects that are defined as
6634+
-- `physical = true,` and `collide_with_objects = true,`.
6635+
-- Requires collisiondetection = true to have any effect.
6636+
66306637
vertical = false,
66316638
-- If true faces player using y axis only
66326639

@@ -6651,10 +6658,12 @@ Used by `minetest.add_particlespawner`.
66516658

66526659
{
66536660
amount = 1,
6661+
-- Number of particles spawned over the time period `time`.
66546662

66556663
time = 1,
6656-
-- If time is 0 has infinite lifespan and spawns the amount on a
6657-
-- per-second basis.
6664+
-- Lifespan of spawner in seconds.
6665+
-- If time is 0 spawner has infinite lifespan and spawns the `amount` on
6666+
-- a per-second basis.
66586667

66596668
minpos = {x=0, y=0, z=0},
66606669
maxpos = {x=0, y=0, z=0},
@@ -6666,30 +6675,37 @@ Used by `minetest.add_particlespawner`.
66666675
maxexptime = 1,
66676676
minsize = 1,
66686677
maxsize = 1,
6669-
-- The particle's properties are random values in between the bounds
6678+
-- The particles' properties are random values between the min and max
6679+
-- values.
66706680
-- pos, velocity, acceleration, expirationtime, size
66716681

66726682
collisiondetection = false,
6673-
-- If true collides with physical objects
6683+
-- If true collide with `walkable` nodes and, depending on the
6684+
-- `object_collision` field, objects too.
66746685

66756686
collision_removal = false,
6676-
-- If true particle is removed when it collides.
6687+
-- If true particles are removed when they collide.
6688+
-- Requires collisiondetection = true to have any effect.
6689+
6690+
object_collision = false,
6691+
-- If true particles collide with objects that are defined as
6692+
-- `physical = true,` and `collide_with_objects = true,`.
66776693
-- Requires collisiondetection = true to have any effect.
66786694

66796695
attached = ObjectRef,
66806696
-- If defined, particle positions, velocities and accelerations are
66816697
-- relative to this object's position and yaw
66826698

66836699
vertical = false,
6684-
-- If true faces player using y axis only
6700+
-- If true face player using y axis only
66856701

66866702
texture = "image.png",
66876703

66886704
playername = "singleplayer",
6689-
-- Optional, if specified spawns particle only on the player's client
6705+
-- Optional, if specified spawns particles only on the player's client
66906706

66916707
animation = {Tile Animation definition},
6692-
-- Optional, specifies how to animate the particle texture
6708+
-- Optional, specifies how to animate the particles' texture
66936709

66946710
glow = 0
66956711
-- Optional, specify particle self-luminescence in darkness.

‎src/client/clientevent.h

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct ClientEvent
8282
f32 size;
8383
bool collisiondetection;
8484
bool collision_removal;
85+
bool object_collision;
8586
bool vertical;
8687
std::string *texture;
8788
struct TileAnimationParams animation;
@@ -103,6 +104,7 @@ struct ClientEvent
103104
f32 maxsize;
104105
bool collisiondetection;
105106
bool collision_removal;
107+
bool object_collision;
106108
u16 attached_id;
107109
bool vertical;
108110
std::string *texture;

‎src/network/clientpackethandler.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,19 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
889889
float size = readF1000(is);
890890
bool collisiondetection = readU8(is);
891891
std::string texture = deSerializeLongString(is);
892-
bool vertical = false;
893-
bool collision_removal = false;
892+
893+
bool vertical = false;
894+
bool collision_removal = false;
894895
TileAnimationParams animation;
895-
animation.type = TAT_NONE;
896-
u8 glow = 0;
896+
animation.type = TAT_NONE;
897+
u8 glow = 0;
898+
bool object_collision = false;
897899
try {
898900
vertical = readU8(is);
899901
collision_removal = readU8(is);
900902
animation.deSerialize(is, m_proto_ver);
901903
glow = readU8(is);
904+
object_collision = readU8(is);
902905
} catch (...) {}
903906

904907
ClientEvent *event = new ClientEvent();
@@ -910,6 +913,7 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
910913
event->spawn_particle.size = size;
911914
event->spawn_particle.collisiondetection = collisiondetection;
912915
event->spawn_particle.collision_removal = collision_removal;
916+
event->spawn_particle.object_collision = object_collision;
913917
event->spawn_particle.vertical = vertical;
914918
event->spawn_particle.texture = new std::string(texture);
915919
event->spawn_particle.animation = animation;
@@ -943,12 +947,13 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
943947

944948
*pkt >> server_id;
945949

946-
bool vertical = false;
950+
bool vertical = false;
947951
bool collision_removal = false;
952+
u16 attached_id = 0;
948953
TileAnimationParams animation;
949-
animation.type = TAT_NONE;
950-
u8 glow = 0;
951-
u16 attached_id = 0;
954+
animation.type = TAT_NONE;
955+
u8 glow = 0;
956+
bool object_collision = false;
952957
try {
953958
*pkt >> vertical;
954959
*pkt >> collision_removal;
@@ -959,6 +964,7 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
959964
std::istringstream is(datastring, std::ios_base::binary);
960965
animation.deSerialize(is, m_proto_ver);
961966
glow = readU8(is);
967+
object_collision = readU8(is);
962968
} catch (...) {}
963969

964970
u32 client_id = m_particle_manager.getSpawnerId();
@@ -980,6 +986,7 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
980986
event->add_particlespawner.maxsize = maxsize;
981987
event->add_particlespawner.collisiondetection = collisiondetection;
982988
event->add_particlespawner.collision_removal = collision_removal;
989+
event->add_particlespawner.object_collision = object_collision;
983990
event->add_particlespawner.attached_id = attached_id;
984991
event->add_particlespawner.vertical = vertical;
985992
event->add_particlespawner.texture = new std::string(texture);

‎src/network/networkprotocol.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,13 @@ enum ToClientCommand
477477
f1000 expirationtime
478478
f1000 size
479479
u8 bool collisiondetection
480-
u8 bool vertical
481480
u32 len
482481
u8[len] texture
482+
u8 bool vertical
483483
u8 collision_removal
484+
TileAnimation animation
485+
u8 glow
486+
u8 object_collision
484487
*/
485488

486489
TOCLIENT_ADD_PARTICLESPAWNER = 0x47,
@@ -498,11 +501,14 @@ enum ToClientCommand
498501
f1000 minsize
499502
f1000 maxsize
500503
u8 bool collisiondetection
501-
u8 bool vertical
502504
u32 len
503505
u8[len] texture
504-
u32 id
506+
u8 bool vertical
505507
u8 collision_removal
508+
u32 id
509+
TileAnimation animation
510+
u8 glow
511+
u8 object_collision
506512
*/
507513

508514
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY = 0x48, // Obsolete

‎src/particles.cpp

+30-10
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Particle::Particle(
5454
float size,
5555
bool collisiondetection,
5656
bool collision_removal,
57+
bool object_collision,
5758
bool vertical,
5859
video::ITexture *texture,
5960
v2f texpos,
@@ -93,6 +94,7 @@ Particle::Particle(
9394
m_size = size;
9495
m_collisiondetection = collisiondetection;
9596
m_collision_removal = collision_removal;
97+
m_object_collision = object_collision;
9698
m_vertical = vertical;
9799
m_glow = glow;
98100

@@ -135,9 +137,9 @@ void Particle::step(float dtime)
135137
aabb3f box = m_collisionbox;
136138
v3f p_pos = m_pos * BS;
137139
v3f p_velocity = m_velocity * BS;
138-
collisionMoveResult r = collisionMoveSimple(m_env,
139-
m_gamedef, BS * 0.5, box, 0, dtime, &p_pos,
140-
&p_velocity, m_acceleration * BS);
140+
collisionMoveResult r = collisionMoveSimple(m_env, m_gamedef, BS * 0.5f,
141+
box, 0.0f, dtime, &p_pos, &p_velocity, m_acceleration * BS, nullptr,
142+
m_object_collision);
141143
if (m_collision_removal && r.collides) {
142144
// force expiration of the particle
143145
m_expiration = -1.0;
@@ -243,14 +245,27 @@ void Particle::updateVertices()
243245
ParticleSpawner
244246
*/
245247

246-
ParticleSpawner::ParticleSpawner(IGameDef *gamedef, LocalPlayer *player,
247-
u16 amount, float time,
248-
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
249-
float minexptime, float maxexptime, float minsize, float maxsize,
250-
bool collisiondetection, bool collision_removal, u16 attached_id, bool vertical,
251-
video::ITexture *texture, u32 id, const struct TileAnimationParams &anim,
248+
ParticleSpawner::ParticleSpawner(
249+
IGameDef *gamedef,
250+
LocalPlayer *player,
251+
u16 amount,
252+
float time,
253+
v3f minpos, v3f maxpos,
254+
v3f minvel, v3f maxvel,
255+
v3f minacc, v3f maxacc,
256+
float minexptime, float maxexptime,
257+
float minsize, float maxsize,
258+
bool collisiondetection,
259+
bool collision_removal,
260+
bool object_collision,
261+
u16 attached_id,
262+
bool vertical,
263+
video::ITexture *texture,
264+
u32 id,
265+
const struct TileAnimationParams &anim,
252266
u8 glow,
253-
ParticleManager *p_manager) :
267+
ParticleManager *p_manager
268+
):
254269
m_particlemanager(p_manager)
255270
{
256271
m_gamedef = gamedef;
@@ -269,6 +284,7 @@ ParticleSpawner::ParticleSpawner(IGameDef *gamedef, LocalPlayer *player,
269284
m_maxsize = maxsize;
270285
m_collisiondetection = collisiondetection;
271286
m_collision_removal = collision_removal;
287+
m_object_collision = object_collision;
272288
m_attached_id = attached_id;
273289
m_vertical = vertical;
274290
m_texture = texture;
@@ -326,6 +342,7 @@ void ParticleSpawner::spawnParticle(ClientEnvironment *env, float radius,
326342
size,
327343
m_collisiondetection,
328344
m_collision_removal,
345+
m_object_collision,
329346
m_vertical,
330347
m_texture,
331348
v2f(0.0, 0.0),
@@ -507,6 +524,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
507524
event->add_particlespawner.maxsize,
508525
event->add_particlespawner.collisiondetection,
509526
event->add_particlespawner.collision_removal,
527+
event->add_particlespawner.object_collision,
510528
event->add_particlespawner.attached_id,
511529
event->add_particlespawner.vertical,
512530
texture,
@@ -545,6 +563,7 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
545563
event->spawn_particle.size,
546564
event->spawn_particle.collisiondetection,
547565
event->spawn_particle.collision_removal,
566+
event->spawn_particle.object_collision,
548567
event->spawn_particle.vertical,
549568
texture,
550569
v2f(0.0, 0.0),
@@ -637,6 +656,7 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef,
637656
true,
638657
false,
639658
false,
659+
false,
640660
texture,
641661
texpos,
642662
texsize,

‎src/particles.h

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Particle : public scene::ISceneNode
4545
float size,
4646
bool collisiondetection,
4747
bool collision_removal,
48+
bool object_collision,
4849
bool vertical,
4950
video::ITexture *texture,
5051
v2f texpos,
@@ -104,6 +105,7 @@ class Particle : public scene::ISceneNode
104105
video::SColor m_color;
105106
bool m_collisiondetection;
106107
bool m_collision_removal;
108+
bool m_object_collision;
107109
bool m_vertical;
108110
v3s16 m_camera_offset;
109111
struct TileAnimationParams m_animation;
@@ -126,6 +128,7 @@ class ParticleSpawner
126128
float minsize, float maxsize,
127129
bool collisiondetection,
128130
bool collision_removal,
131+
bool object_collision,
129132
u16 attached_id,
130133
bool vertical,
131134
video::ITexture *texture,
@@ -165,6 +168,7 @@ class ParticleSpawner
165168
std::vector<float> m_spawntimes;
166169
bool m_collisiondetection;
167170
bool m_collision_removal;
171+
bool m_object_collision;
168172
bool m_vertical;
169173
u16 m_attached_id;
170174
struct TileAnimationParams m_animation;

0 commit comments

Comments
 (0)
Please sign in to comment.