Skip to content

Commit 2b1eff7

Browse files
khonkhortisanShadowNinja
authored andcommittedJan 13, 2014
Allow vertical axis particle rotation constraint
Use tables for adding particles, deprecate former way. separate particles(pawner) definition, add default values, work with no arguments
1 parent a4c5f10 commit 2b1eff7

10 files changed

+259
-86
lines changed
 

‎doc/lua_api.txt

+53-16
Original file line numberDiff line numberDiff line change
@@ -1462,30 +1462,20 @@ minetest.ban_player(name) -> ban a player
14621462
minetest.unban_player_or_ip(name) -> unban player or IP address
14631463

14641464
Particles:
1465-
minetest.add_particle(pos, velocity, acceleration, expirationtime,
1465+
minetest.add_particle(particle definition)
1466+
^ Deprecated: minetest.add_particle(pos, velocity, acceleration, expirationtime,
14661467
size, collisiondetection, texture, playername)
1467-
^ Spawn particle at pos with velocity and acceleration
1468-
^ Disappears after expirationtime seconds
1469-
^ collisiondetection: if true collides with physical objects
1470-
^ Uses texture (string)
1471-
^ Playername is optional, if specified spawns particle only on the player's client
14721468

1473-
minetest.add_particlespawner(amount, time,
1469+
minetest.add_particlespawner(particlespawner definition)
1470+
^ Add a particlespawner, an object that spawns an amount of particles over time seconds
1471+
^ Returns an id
1472+
^ Deprecated: minetest.add_particlespawner(amount, time,
14741473
minpos, maxpos,
14751474
minvel, maxvel,
14761475
minacc, maxacc,
14771476
minexptime, maxexptime,
14781477
minsize, maxsize,
14791478
collisiondetection, texture, playername)
1480-
^ Add a particlespawner, an object that spawns an amount of particles over time seconds
1481-
^ The particle's properties are random values in between the boundings:
1482-
^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
1483-
^ minsize/maxsize, minexptime/maxexptime (expirationtime)
1484-
^ collisiondetection: if true uses collisiondetection
1485-
^ Uses texture (string)
1486-
^ Playername is optional, if specified spawns particle only on the player's client
1487-
^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
1488-
^ Returns and id
14891479

14901480
minetest.delete_particlespawner(id, player)
14911481
^ Delete ParticleSpawner with id (return value from add_particlespawner)
@@ -2443,3 +2433,50 @@ HUD Definition (hud_add, hud_get)
24432433
offset = {x=0, y=0},
24442434
^ See "HUD Element Types"
24452435
}
2436+
2437+
Particle definition (add_particle)
2438+
{
2439+
pos = {x=0, y=0, z=0},
2440+
velocity = {x=0, y=0, z=0},
2441+
acceleration = {x=0, y=0, z=0},
2442+
^ Spawn particle at pos with velocity and acceleration
2443+
expirationtime = 1,
2444+
^ Disappears after expirationtime seconds
2445+
size = 1,
2446+
collisiondetection = false,
2447+
^ collisiondetection: if true collides with physical objects
2448+
vertical = false,
2449+
^ vertical: if true faces player using y axis only
2450+
texture = "image.png",
2451+
^ Uses texture (string)
2452+
playername = "singleplayer"
2453+
^ Playername is optional, if specified spawns particle only on the player's client
2454+
}
2455+
2456+
Particlespawner definition (add_particlespawner)
2457+
{
2458+
amount = 1,
2459+
time = 1,
2460+
^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
2461+
minpos = {x=0, y=0, z=0},
2462+
maxpos = {x=0, y=0, z=0},
2463+
minvel = {x=0, y=0, z=0},
2464+
maxvel = {x=0, y=0, z=0},
2465+
minacc = {x=0, y=0, z=0},
2466+
maxacc = {x=0, y=0, z=0},
2467+
minexptime = 1,
2468+
maxexptime = 1,
2469+
minsize = 1,
2470+
maxsize = 1,
2471+
^ The particle's properties are random values in between the boundings:
2472+
^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
2473+
^ minsize/maxsize, minexptime/maxexptime (expirationtime)
2474+
collisiondetection = false,
2475+
^ collisiondetection: if true uses collisiondetection
2476+
vertical = false,
2477+
^ vertical: if true faces player using y axis only
2478+
texture = "image.png",
2479+
^ Uses texture (string)
2480+
playername = "singleplayer"
2481+
^ Playername is optional, if specified spawns particle only on the player's client
2482+
}

‎src/client.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,10 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
18441844
float size = readF1000(is);
18451845
bool collisiondetection = readU8(is);
18461846
std::string texture = deSerializeLongString(is);
1847+
bool vertical = false;
1848+
try {
1849+
vertical = readU8(is);
1850+
} catch (...) {}
18471851

18481852
ClientEvent event;
18491853
event.type = CE_SPAWN_PARTICLE;
@@ -1855,6 +1859,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
18551859
event.spawn_particle.size = size;
18561860
event.spawn_particle.collisiondetection =
18571861
collisiondetection;
1862+
event.spawn_particle.vertical = vertical;
18581863
event.spawn_particle.texture = new std::string(texture);
18591864

18601865
m_client_event_queue.push_back(event);
@@ -1879,6 +1884,10 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
18791884
bool collisiondetection = readU8(is);
18801885
std::string texture = deSerializeLongString(is);
18811886
u32 id = readU32(is);
1887+
bool vertical = false;
1888+
try {
1889+
vertical = readU8(is);
1890+
} catch (...) {}
18821891

18831892
ClientEvent event;
18841893
event.type = CE_ADD_PARTICLESPAWNER;
@@ -1897,6 +1906,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
18971906
event.add_particlespawner.minsize = minsize;
18981907
event.add_particlespawner.maxsize = maxsize;
18991908
event.add_particlespawner.collisiondetection = collisiondetection;
1909+
event.add_particlespawner.vertical = vertical;
19001910
event.add_particlespawner.texture = new std::string(texture);
19011911
event.add_particlespawner.id = id;
19021912

‎src/client.h

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ struct ClientEvent
168168
f32 expirationtime;
169169
f32 size;
170170
bool collisiondetection;
171+
bool vertical;
171172
std::string *texture;
172173
} spawn_particle;
173174
struct{
@@ -184,6 +185,7 @@ struct ClientEvent
184185
f32 minsize;
185186
f32 maxsize;
186187
bool collisiondetection;
188+
bool vertical;
187189
std::string *texture;
188190
u32 id;
189191
} add_particlespawner;

‎src/clientserver.h

+2
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ enum ToClientCommand
419419
f1000 expirationtime
420420
f1000 size
421421
u8 bool collisiondetection
422+
u8 bool vertical
422423
u32 len
423424
u8[len] texture
424425
*/
@@ -439,6 +440,7 @@ enum ToClientCommand
439440
f1000 minsize
440441
f1000 maxsize
441442
u8 bool collisiondetection
443+
u8 bool vertical
442444
u32 len
443445
u8[len] texture
444446
u32 id

‎src/game.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,7 @@ void the_game(
23212321
event.spawn_particle.expirationtime,
23222322
event.spawn_particle.size,
23232323
event.spawn_particle.collisiondetection,
2324+
event.spawn_particle.vertical,
23242325
texture,
23252326
v2f(0.0, 0.0),
23262327
v2f(1.0, 1.0));
@@ -2345,6 +2346,7 @@ void the_game(
23452346
event.add_particlespawner.minsize,
23462347
event.add_particlespawner.maxsize,
23472348
event.add_particlespawner.collisiondetection,
2349+
event.add_particlespawner.vertical,
23482350
texture,
23492351
event.add_particlespawner.id);
23502352
}

‎src/particles.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Particle::Particle(
5757
float expirationtime,
5858
float size,
5959
bool collisiondetection,
60+
bool vertical,
6061
video::ITexture *texture,
6162
v2f texpos,
6263
v2f texsize
@@ -86,6 +87,7 @@ Particle::Particle(
8687
m_player = player;
8788
m_size = size;
8889
m_collisiondetection = collisiondetection;
90+
m_vertical = vertical;
8991

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

200202
for(u16 i=0; i<4; i++)
201203
{
202-
m_vertices[i].Pos.rotateYZBy(m_player->getPitch());
203-
m_vertices[i].Pos.rotateXZBy(m_player->getYaw());
204+
if (m_vertical) {
205+
v3f ppos = m_player->getPosition()/BS;
206+
m_vertices[i].Pos.rotateXZBy(atan2(ppos.Z-m_pos.Z, ppos.X-m_pos.X)/core::DEGTORAD+90);
207+
} else {
208+
m_vertices[i].Pos.rotateYZBy(m_player->getPitch());
209+
m_vertices[i].Pos.rotateXZBy(m_player->getYaw());
210+
}
204211
m_box.addInternalPoint(m_vertices[i].Pos);
205212
m_vertices[i].Pos += m_pos*BS;
206213
}
@@ -293,6 +300,7 @@ void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
293300
rand()%100/100., // expiration time
294301
visual_size,
295302
true,
303+
false,
296304
texture,
297305
texpos,
298306
texsize);
@@ -306,7 +314,7 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr,
306314
u16 amount, float time,
307315
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
308316
float minexptime, float maxexptime, float minsize, float maxsize,
309-
bool collisiondetection, video::ITexture *texture, u32 id)
317+
bool collisiondetection, bool vertical, video::ITexture *texture, u32 id)
310318
{
311319
m_gamedef = gamedef;
312320
m_smgr = smgr;
@@ -324,6 +332,7 @@ ParticleSpawner::ParticleSpawner(IGameDef* gamedef, scene::ISceneManager *smgr,
324332
m_minsize = minsize;
325333
m_maxsize = maxsize;
326334
m_collisiondetection = collisiondetection;
335+
m_vertical = vertical;
327336
m_texture = texture;
328337
m_time = 0;
329338

@@ -372,6 +381,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment &env)
372381
exptime,
373382
size,
374383
m_collisiondetection,
384+
m_vertical,
375385
m_texture,
376386
v2f(0.0, 0.0),
377387
v2f(1.0, 1.0));
@@ -410,6 +420,7 @@ void ParticleSpawner::step(float dtime, ClientEnvironment &env)
410420
exptime,
411421
size,
412422
m_collisiondetection,
423+
m_vertical,
413424
m_texture,
414425
v2f(0.0, 0.0),
415426
v2f(1.0, 1.0));

‎src/particles.h

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Particle : public scene::ISceneNode
4242
float expirationtime,
4343
float size,
4444
bool collisiondetection,
45+
bool vertical,
4546
video::ITexture *texture,
4647
v2f texpos,
4748
v2f texsize
@@ -92,6 +93,7 @@ class Particle : public scene::ISceneNode
9293
float m_size;
9394
u8 m_light;
9495
bool m_collisiondetection;
96+
bool m_vertical;
9597
};
9698

9799
class ParticleSpawner
@@ -108,6 +110,7 @@ class ParticleSpawner
108110
float minexptime, float maxexptime,
109111
float minsize, float maxsize,
110112
bool collisiondetection,
113+
bool vertical,
111114
video::ITexture *texture,
112115
u32 id);
113116

@@ -138,6 +141,7 @@ class ParticleSpawner
138141
video::ITexture *m_texture;
139142
std::vector<float> m_spawntimes;
140143
bool m_collisiondetection;
144+
bool m_vertical;
141145
};
142146

143147
void allparticles_step (float dtime, ClientEnvironment &env);

0 commit comments

Comments
 (0)
Please sign in to comment.