summaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorAuke Kok <sofar+github@foo-projects.org>2016-05-27 21:08:23 -0700
committerkwolekr <kwolekr@minetest.net>2016-05-28 00:08:23 -0400
commitd499ec483837fa7210176ef39beba2d5a3a5a61d (patch)
tree8476d09d0c351481a7b14fc32e51b95a4e07dd3e /src/server.cpp
parent62d15ac7c1fcd7214a9e45d46bbc560f998edb95 (diff)
downloadminetest-d499ec483837fa7210176ef39beba2d5a3a5a61d.tar.gz
minetest-d499ec483837fa7210176ef39beba2d5a3a5a61d.tar.bz2
minetest-d499ec483837fa7210176ef39beba2d5a3a5a61d.zip
Particles: Add option to remove particles on collision
Adds the particle option `collision_removal = bool` Some particles are hard to use right now since they either go through solid blocks (without collision detection), and with collision detection enabled they (e.g. raindrops) would just stop dead on the floor and sit there until they expire, or worse, scrape along a wall or ceiling. We can solve the problem by adding a boolean flag that tells the particle to be removed if it ever collides with something. This will make it easier to add rain that doesn't fall through your roof or stick on the top of it. Or clouds and smoke that don't go through trees. Particles that collide with this flag are marked expired unconditionally, causing them to be treated like normal expired particles and cleaned up normally. Documentation is adjusted accordingly. An added bonus of this patch is that particles can potentially collide many times with nodes, and this reduces the amount of collisions to 1 (max), which may end up reducing particle load on the client.
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/server.cpp b/src/server.cpp
index a3b686c25..ada45dc68 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1673,7 +1673,8 @@ void Server::SendShowFormspecMessage(u16 peer_id, const std::string &formspec,
// Spawns a particle on peer with peer_id
void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f acceleration,
float expirationtime, float size, bool collisiondetection,
- bool vertical, std::string texture)
+ bool collision_removal,
+ bool vertical, const std::string &texture)
{
DSTACK(FUNCTION_NAME);
@@ -1683,6 +1684,7 @@ void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f accelerat
<< size << collisiondetection;
pkt.putLongString(texture);
pkt << vertical;
+ pkt << collision_removal;
if (peer_id != PEER_ID_INEXISTENT) {
Send(&pkt);
@@ -1695,7 +1697,8 @@ void Server::SendSpawnParticle(u16 peer_id, v3f pos, v3f velocity, v3f accelerat
// Adds a ParticleSpawner on peer with peer_id
void Server::SendAddParticleSpawner(u16 peer_id, u16 amount, float spawntime, v3f minpos, v3f maxpos,
v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime,
- float minsize, float maxsize, bool collisiondetection, bool vertical, std::string texture, u32 id)
+ float minsize, float maxsize, bool collisiondetection, bool collision_removal,
+ bool vertical, const std::string &texture, u32 id)
{
DSTACK(FUNCTION_NAME);
@@ -1708,6 +1711,7 @@ void Server::SendAddParticleSpawner(u16 peer_id, u16 amount, float spawntime, v3
pkt.putLongString(texture);
pkt << id << vertical;
+ pkt << collision_removal;
if (peer_id != PEER_ID_INEXISTENT) {
Send(&pkt);
@@ -3160,7 +3164,8 @@ void Server::notifyPlayers(const std::wstring &msg)
void Server::spawnParticle(const std::string &playername, v3f pos,
v3f velocity, v3f acceleration,
float expirationtime, float size, bool
- collisiondetection, bool vertical, const std::string &texture)
+ collisiondetection, bool collision_removal,
+ bool vertical, const std::string &texture)
{
// m_env will be NULL if the server is initializing
if (!m_env)
@@ -3175,13 +3180,15 @@ void Server::spawnParticle(const std::string &playername, v3f pos,
}
SendSpawnParticle(peer_id, pos, velocity, acceleration,
- expirationtime, size, collisiondetection, vertical, texture);
+ expirationtime, size, collisiondetection,
+ collision_removal, vertical, texture);
}
u32 Server::addParticleSpawner(u16 amount, float spawntime,
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
float minexptime, float maxexptime, float minsize, float maxsize,
- bool collisiondetection, bool vertical, const std::string &texture,
+ bool collisiondetection, bool collision_removal,
+ bool vertical, const std::string &texture,
const std::string &playername)
{
// m_env will be NULL if the server is initializing
@@ -3200,7 +3207,7 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime,
SendAddParticleSpawner(peer_id, amount, spawntime,
minpos, maxpos, minvel, maxvel, minacc, maxacc,
minexptime, maxexptime, minsize, maxsize,
- collisiondetection, vertical, texture, id);
+ collisiondetection, collision_removal, vertical, texture, id);
return id;
}