Skip to content

Commit

Permalink
Allow vertical axis particle rotation constraint
Browse files Browse the repository at this point in the history
Use tables for adding particles, deprecate former way.

separate particles(pawner) definition, add default values, work with no
arguments
  • Loading branch information
khonkhortisan authored and ShadowNinja committed Jan 13, 2014
1 parent a4c5f10 commit 2b1eff7
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 86 deletions.
69 changes: 53 additions & 16 deletions doc/lua_api.txt
Expand Up @@ -1462,30 +1462,20 @@ minetest.ban_player(name) -> ban a player
minetest.unban_player_or_ip(name) -> unban player or IP address

Particles:
minetest.add_particle(pos, velocity, acceleration, expirationtime,
minetest.add_particle(particle definition)
^ Deprecated: minetest.add_particle(pos, velocity, acceleration, expirationtime,
size, collisiondetection, texture, playername)
^ Spawn particle at pos with velocity and acceleration
^ Disappears after expirationtime seconds
^ collisiondetection: if true collides with physical objects
^ Uses texture (string)
^ Playername is optional, if specified spawns particle only on the player's client

minetest.add_particlespawner(amount, time,
minetest.add_particlespawner(particlespawner definition)
^ Add a particlespawner, an object that spawns an amount of particles over time seconds
^ Returns an id
^ Deprecated: minetest.add_particlespawner(amount, time,
minpos, maxpos,
minvel, maxvel,
minacc, maxacc,
minexptime, maxexptime,
minsize, maxsize,
collisiondetection, texture, playername)
^ Add a particlespawner, an object that spawns an amount of particles over time seconds
^ The particle's properties are random values in between the boundings:
^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
^ minsize/maxsize, minexptime/maxexptime (expirationtime)
^ collisiondetection: if true uses collisiondetection
^ Uses texture (string)
^ Playername is optional, if specified spawns particle only on the player's client
^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
^ Returns and id

minetest.delete_particlespawner(id, player)
^ Delete ParticleSpawner with id (return value from add_particlespawner)
Expand Down Expand Up @@ -2443,3 +2433,50 @@ HUD Definition (hud_add, hud_get)
offset = {x=0, y=0},
^ See "HUD Element Types"
}

Particle definition (add_particle)
{
pos = {x=0, y=0, z=0},
velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0, z=0},
^ Spawn particle at pos with velocity and acceleration
expirationtime = 1,
^ Disappears after expirationtime seconds
size = 1,
collisiondetection = false,
^ collisiondetection: if true collides with physical objects
vertical = false,
^ vertical: if true faces player using y axis only
texture = "image.png",
^ Uses texture (string)
playername = "singleplayer"
^ Playername is optional, if specified spawns particle only on the player's client
}

Particlespawner definition (add_particlespawner)
{
amount = 1,
time = 1,
^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
minpos = {x=0, y=0, z=0},
maxpos = {x=0, y=0, z=0},
minvel = {x=0, y=0, z=0},
maxvel = {x=0, y=0, z=0},
minacc = {x=0, y=0, z=0},
maxacc = {x=0, y=0, z=0},
minexptime = 1,
maxexptime = 1,
minsize = 1,
maxsize = 1,
^ The particle's properties are random values in between the boundings:
^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
^ minsize/maxsize, minexptime/maxexptime (expirationtime)
collisiondetection = false,
^ collisiondetection: if true uses collisiondetection
vertical = false,
^ vertical: if true faces player using y axis only
texture = "image.png",
^ Uses texture (string)
playername = "singleplayer"
^ Playername is optional, if specified spawns particle only on the player's client
}
10 changes: 10 additions & 0 deletions src/client.cpp
Expand Up @@ -1844,6 +1844,10 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
float size = readF1000(is);
bool collisiondetection = readU8(is);
std::string texture = deSerializeLongString(is);
bool vertical = false;
try {
vertical = readU8(is);
} catch (...) {}

ClientEvent event;
event.type = CE_SPAWN_PARTICLE;
Expand All @@ -1855,6 +1859,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
event.spawn_particle.size = size;
event.spawn_particle.collisiondetection =
collisiondetection;
event.spawn_particle.vertical = vertical;
event.spawn_particle.texture = new std::string(texture);

m_client_event_queue.push_back(event);
Expand All @@ -1879,6 +1884,10 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
bool collisiondetection = readU8(is);
std::string texture = deSerializeLongString(is);
u32 id = readU32(is);
bool vertical = false;
try {
vertical = readU8(is);
} catch (...) {}

ClientEvent event;
event.type = CE_ADD_PARTICLESPAWNER;
Expand All @@ -1897,6 +1906,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
event.add_particlespawner.minsize = minsize;
event.add_particlespawner.maxsize = maxsize;
event.add_particlespawner.collisiondetection = collisiondetection;
event.add_particlespawner.vertical = vertical;
event.add_particlespawner.texture = new std::string(texture);
event.add_particlespawner.id = id;

Expand Down
2 changes: 2 additions & 0 deletions src/client.h
Expand Up @@ -168,6 +168,7 @@ struct ClientEvent
f32 expirationtime;
f32 size;
bool collisiondetection;
bool vertical;
std::string *texture;
} spawn_particle;
struct{
Expand All @@ -184,6 +185,7 @@ struct ClientEvent
f32 minsize;
f32 maxsize;
bool collisiondetection;
bool vertical;
std::string *texture;
u32 id;
} add_particlespawner;
Expand Down
2 changes: 2 additions & 0 deletions src/clientserver.h
Expand Up @@ -419,6 +419,7 @@ enum ToClientCommand
f1000 expirationtime
f1000 size
u8 bool collisiondetection
u8 bool vertical
u32 len
u8[len] texture
*/
Expand All @@ -439,6 +440,7 @@ enum ToClientCommand
f1000 minsize
f1000 maxsize
u8 bool collisiondetection
u8 bool vertical
u32 len
u8[len] texture
u32 id
Expand Down
2 changes: 2 additions & 0 deletions src/game.cpp
Expand Up @@ -2321,6 +2321,7 @@ void the_game(
event.spawn_particle.expirationtime,
event.spawn_particle.size,
event.spawn_particle.collisiondetection,
event.spawn_particle.vertical,
texture,
v2f(0.0, 0.0),
v2f(1.0, 1.0));
Expand All @@ -2345,6 +2346,7 @@ void the_game(
event.add_particlespawner.minsize,
event.add_particlespawner.maxsize,
event.add_particlespawner.collisiondetection,
event.add_particlespawner.vertical,
texture,
event.add_particlespawner.id);
}
Expand Down
17 changes: 14 additions & 3 deletions src/particles.cpp
Expand Up @@ -57,6 +57,7 @@ Particle::Particle(
float expirationtime,
float size,
bool collisiondetection,
bool vertical,
video::ITexture *texture,
v2f texpos,
v2f texsize
Expand Down Expand Up @@ -86,6 +87,7 @@ Particle::Particle(
m_player = player;
m_size = size;
m_collisiondetection = collisiondetection;
m_vertical = vertical;

// Irrlicht stuff
m_collisionbox = core::aabbox3d<f32>
Expand Down Expand Up @@ -199,8 +201,13 @@ void Particle::updateVertices()

for(u16 i=0; i<4; i++)
{
m_vertices[i].Pos.rotateYZBy(m_player->getPitch());
m_vertices[i].Pos.rotateXZBy(m_player->getYaw());
if (m_vertical) {
v3f ppos = m_player->getPosition()/BS;
m_vertices[i].Pos.rotateXZBy(atan2(ppos.Z-m_pos.Z, ppos.X-m_pos.X)/core::DEGTORAD+90);
} else {
m_vertices[i].Pos.rotateYZBy(m_player->getPitch());
m_vertices[i].Pos.rotateXZBy(m_player->getYaw());
}
m_box.addInternalPoint(m_vertices[i].Pos);
m_vertices[i].Pos += m_pos*BS;
}
Expand Down Expand Up @@ -293,6 +300,7 @@ void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
rand()%100/100., // expiration time
visual_size,
true,
false,
texture,
texpos,
texsize);
Expand All @@ -306,7 +314,7 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr,
u16 amount, float time,
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
float minexptime, float maxexptime, float minsize, float maxsize,
bool collisiondetection, video::ITexture *texture, u32 id)
bool collisiondetection, bool vertical, video::ITexture *texture, u32 id)
{
m_gamedef = gamedef;
m_smgr = smgr;
Expand All @@ -324,6 +332,7 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr,
m_minsize = minsize;
m_maxsize = maxsize;
m_collisiondetection = collisiondetection;
m_vertical = vertical;
m_texture = texture;
m_time = 0;

Expand Down Expand Up @@ -372,6 +381,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment &env)
exptime,
size,
m_collisiondetection,
m_vertical,
m_texture,
v2f(0.0, 0.0),
v2f(1.0, 1.0));
Expand Down Expand Up @@ -410,6 +420,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment &env)
exptime,
size,
m_collisiondetection,
m_vertical,
m_texture,
v2f(0.0, 0.0),
v2f(1.0, 1.0));
Expand Down
4 changes: 4 additions & 0 deletions src/particles.h
Expand Up @@ -42,6 +42,7 @@ class Particle : public scene::ISceneNode
float expirationtime,
float size,
bool collisiondetection,
bool vertical,
video::ITexture *texture,
v2f texpos,
v2f texsize
Expand Down Expand Up @@ -92,6 +93,7 @@ class Particle : public scene::ISceneNode
float m_size;
u8 m_light;
bool m_collisiondetection;
bool m_vertical;
};

class ParticleSpawner
Expand All @@ -108,6 +110,7 @@ class ParticleSpawner
float minexptime, float maxexptime,
float minsize, float maxsize,
bool collisiondetection,
bool vertical,
video::ITexture *texture,
u32 id);

Expand Down Expand Up @@ -138,6 +141,7 @@ class ParticleSpawner
video::ITexture *m_texture;
std::vector<float> m_spawntimes;
bool m_collisiondetection;
bool m_vertical;
};

void allparticles_step (float dtime, ClientEnvironment &env);
Expand Down

0 comments on commit 2b1eff7

Please sign in to comment.