Skip to content

Commit 1357ea1

Browse files
authoredMay 22, 2020
Cleanup of particle & particlespawner structures and code (#9893)
1 parent 1bcdc2d commit 1357ea1

File tree

11 files changed

+502
-680
lines changed

11 files changed

+502
-680
lines changed
 

‎src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ set(common_SRCS
427427
noise.cpp
428428
objdef.cpp
429429
object_properties.cpp
430+
particles.cpp
430431
pathfinder.cpp
431432
player.cpp
432433
porting.cpp

‎src/client/clientevent.h

+9-36
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121

2222
#include <string>
2323
#include "irrlichttypes_bloated.h"
24-
#include "hud.h"
25-
#include "skyparams.h"
24+
25+
struct ParticleParameters;
26+
struct ParticleSpawnerParameters;
27+
struct SkyboxParams;
28+
struct SunParams;
29+
struct MoonParams;
30+
struct StarParams;
2631

2732
enum ClientEventType : u8
2833
{
@@ -77,44 +82,12 @@ struct ClientEvent
7782
} show_formspec;
7883
// struct{
7984
//} textures_updated;
85+
ParticleParameters *spawn_particle;
8086
struct
8187
{
82-
v3f *pos;
83-
v3f *vel;
84-
v3f *acc;
85-
f32 expirationtime;
86-
f32 size;
87-
bool collisiondetection;
88-
bool collision_removal;
89-
bool object_collision;
90-
bool vertical;
91-
std::string *texture;
92-
struct TileAnimationParams animation;
93-
u8 glow;
94-
} spawn_particle;
95-
struct
96-
{
97-
u16 amount;
98-
f32 spawntime;
99-
v3f *minpos;
100-
v3f *maxpos;
101-
v3f *minvel;
102-
v3f *maxvel;
103-
v3f *minacc;
104-
v3f *maxacc;
105-
f32 minexptime;
106-
f32 maxexptime;
107-
f32 minsize;
108-
f32 maxsize;
109-
bool collisiondetection;
110-
bool collision_removal;
111-
bool object_collision;
88+
ParticleSpawnerParameters *p;
11289
u16 attached_id;
113-
bool vertical;
114-
std::string *texture;
11590
u64 id;
116-
struct TileAnimationParams animation;
117-
u8 glow;
11891
} add_particlespawner;
11992
struct
12093
{

‎src/client/particles.cpp

+130-203
Large diffs are not rendered by default.

‎src/client/particles.h

+13-45
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "irrlichttypes_extrabloated.h"
2424
#include "client/tile.h"
2525
#include "localplayer.h"
26-
#include "tileanimation.h"
26+
#include "../particles.h"
2727

2828
struct ClientEvent;
2929
class ParticleManager;
@@ -38,20 +38,10 @@ class Particle : public scene::ISceneNode
3838
IGameDef* gamedef,
3939
LocalPlayer *player,
4040
ClientEnvironment *env,
41-
v3f pos,
42-
v3f velocity,
43-
v3f acceleration,
44-
float expirationtime,
45-
float size,
46-
bool collisiondetection,
47-
bool collision_removal,
48-
bool object_collision,
49-
bool vertical,
41+
const ParticleParameters &p,
5042
video::ITexture *texture,
5143
v2f texpos,
5244
v2f texsize,
53-
const struct TileAnimationParams &anim,
54-
u8 glow,
5545
video::SColor color = video::SColor(0xFFFFFFFF)
5646
);
5747
~Particle() = default;
@@ -119,28 +109,17 @@ class ParticleSpawner
119109
public:
120110
ParticleSpawner(IGameDef* gamedef,
121111
LocalPlayer *player,
122-
u16 amount,
123-
float time,
124-
v3f minp, v3f maxp,
125-
v3f minvel, v3f maxvel,
126-
v3f minacc, v3f maxacc,
127-
float minexptime, float maxexptime,
128-
float minsize, float maxsize,
129-
bool collisiondetection,
130-
bool collision_removal,
131-
bool object_collision,
112+
const ParticleSpawnerParameters &p,
132113
u16 attached_id,
133-
bool vertical,
134114
video::ITexture *texture,
135-
const struct TileAnimationParams &anim, u8 glow,
136115
ParticleManager* p_manager);
137116

138117
~ParticleSpawner() = default;
139118

140119
void step(float dtime, ClientEnvironment *env);
141120

142121
bool get_expired ()
143-
{ return (m_amount <= 0) && m_spawntime != 0; }
122+
{ return p.amount <= 0 && p.time != 0; }
144123

145124
private:
146125
void spawnParticle(ClientEnvironment *env, float radius,
@@ -150,27 +129,10 @@ class ParticleSpawner
150129
float m_time;
151130
IGameDef *m_gamedef;
152131
LocalPlayer *m_player;
153-
u16 m_amount;
154-
float m_spawntime;
155-
v3f m_minpos;
156-
v3f m_maxpos;
157-
v3f m_minvel;
158-
v3f m_maxvel;
159-
v3f m_minacc;
160-
v3f m_maxacc;
161-
float m_minexptime;
162-
float m_maxexptime;
163-
float m_minsize;
164-
float m_maxsize;
132+
ParticleSpawnerParameters p;
165133
video::ITexture *m_texture;
166134
std::vector<float> m_spawntimes;
167-
bool m_collisiondetection;
168-
bool m_collision_removal;
169-
bool m_object_collision;
170-
bool m_vertical;
171135
u16 m_attached_id;
172-
struct TileAnimationParams m_animation;
173-
u8 m_glow;
174136
};
175137

176138
/**
@@ -197,8 +159,8 @@ friend class ParticleSpawner;
197159
/**
198160
* This function is only used by client particle spawners
199161
*
200-
* We don't need to check the particle spawner list because client ID will n
201-
* ever overlap (u64)
162+
* We don't need to check the particle spawner list because client ID will
163+
* never overlap (u64)
202164
* @return new id
203165
*/
204166
u64 generateSpawnerId()
@@ -207,9 +169,15 @@ friend class ParticleSpawner;
207169
}
208170

209171
protected:
172+
static bool getNodeParticleParams(const MapNode &n, const ContentFeatures &f,
173+
ParticleParameters &p, video::ITexture **texture, v2f &texpos,
174+
v2f &texsize, video::SColor *color);
175+
210176
void addParticle(Particle* toadd);
211177

212178
private:
179+
void addParticleSpawner(u64 id, ParticleSpawner *toadd);
180+
void deleteParticleSpawner(u64 id);
213181

214182
void stepParticles(float dtime);
215183
void stepSpawners(float dtime);

‎src/network/clientpackethandler.cpp

+39-97
Original file line numberDiff line numberDiff line change
@@ -958,114 +958,56 @@ void Client::handleCommand_SpawnParticle(NetworkPacket* pkt)
958958
std::string datastring(pkt->getString(0), pkt->getSize());
959959
std::istringstream is(datastring, std::ios_base::binary);
960960

961-
v3f pos = readV3F32(is);
962-
v3f vel = readV3F32(is);
963-
v3f acc = readV3F32(is);
964-
float expirationtime = readF32(is);
965-
float size = readF32(is);
966-
bool collisiondetection = readU8(is);
967-
std::string texture = deSerializeLongString(is);
968-
969-
bool vertical = false;
970-
bool collision_removal = false;
971-
TileAnimationParams animation;
972-
animation.type = TAT_NONE;
973-
u8 glow = 0;
974-
bool object_collision = false;
975-
try {
976-
vertical = readU8(is);
977-
collision_removal = readU8(is);
978-
animation.deSerialize(is, m_proto_ver);
979-
glow = readU8(is);
980-
object_collision = readU8(is);
981-
} catch (...) {}
961+
ParticleParameters p;
962+
p.deSerialize(is, m_proto_ver);
982963

983964
ClientEvent *event = new ClientEvent();
984-
event->type = CE_SPAWN_PARTICLE;
985-
event->spawn_particle.pos = new v3f (pos);
986-
event->spawn_particle.vel = new v3f (vel);
987-
event->spawn_particle.acc = new v3f (acc);
988-
event->spawn_particle.expirationtime = expirationtime;
989-
event->spawn_particle.size = size;
990-
event->spawn_particle.collisiondetection = collisiondetection;
991-
event->spawn_particle.collision_removal = collision_removal;
992-
event->spawn_particle.object_collision = object_collision;
993-
event->spawn_particle.vertical = vertical;
994-
event->spawn_particle.texture = new std::string(texture);
995-
event->spawn_particle.animation = animation;
996-
event->spawn_particle.glow = glow;
965+
event->type = CE_SPAWN_PARTICLE;
966+
event->spawn_particle = new ParticleParameters(p);
997967

998968
m_client_event_queue.push(event);
999969
}
1000970

1001971
void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
1002972
{
1003-
u16 amount;
1004-
float spawntime;
1005-
v3f minpos;
1006-
v3f maxpos;
1007-
v3f minvel;
1008-
v3f maxvel;
1009-
v3f minacc;
1010-
v3f maxacc;
1011-
float minexptime;
1012-
float maxexptime;
1013-
float minsize;
1014-
float maxsize;
1015-
bool collisiondetection;
1016-
u32 server_id;
1017-
1018-
*pkt >> amount >> spawntime >> minpos >> maxpos >> minvel >> maxvel
1019-
>> minacc >> maxacc >> minexptime >> maxexptime >> minsize
1020-
>> maxsize >> collisiondetection;
1021-
1022-
std::string texture = pkt->readLongString();
1023-
1024-
*pkt >> server_id;
1025-
1026-
bool vertical = false;
1027-
bool collision_removal = false;
1028-
u16 attached_id = 0;
1029-
TileAnimationParams animation;
1030-
animation.type = TAT_NONE;
1031-
u8 glow = 0;
1032-
bool object_collision = false;
1033-
try {
1034-
*pkt >> vertical;
1035-
*pkt >> collision_removal;
1036-
*pkt >> attached_id;
973+
std::string datastring(pkt->getString(0), pkt->getSize());
974+
std::istringstream is(datastring, std::ios_base::binary);
1037975

1038-
// This is horrible but required (why are there two ways to deserialize pkts?)
1039-
std::string datastring(pkt->getRemainingString(), pkt->getRemainingBytes());
1040-
std::istringstream is(datastring, std::ios_base::binary);
1041-
animation.deSerialize(is, m_proto_ver);
1042-
glow = readU8(is);
1043-
object_collision = readU8(is);
1044-
} catch (...) {}
976+
ParticleSpawnerParameters p;
977+
u32 server_id;
978+
u16 attached_id = 0;
979+
980+
p.amount = readU16(is);
981+
p.time = readF32(is);
982+
p.minpos = readV3F32(is);
983+
p.maxpos = readV3F32(is);
984+
p.minvel = readV3F32(is);
985+
p.maxvel = readV3F32(is);
986+
p.minacc = readV3F32(is);
987+
p.maxacc = readV3F32(is);
988+
p.minexptime = readF32(is);
989+
p.maxexptime = readF32(is);
990+
p.minsize = readF32(is);
991+
p.maxsize = readF32(is);
992+
p.collisiondetection = readU8(is);
993+
p.texture = deSerializeLongString(is);
994+
995+
server_id = readU32(is);
996+
997+
p.vertical = readU8(is);
998+
p.collision_removal = readU8(is);
999+
1000+
attached_id = readU16(is);
1001+
1002+
p.animation.deSerialize(is, m_proto_ver);
Has conversations. Original line has conversations.
1003+
p.glow = readU8(is);
1004+
p.object_collision = readU8(is);
10451005

10461006
auto event = new ClientEvent();
1047-
event->type = CE_ADD_PARTICLESPAWNER;
1048-
event->add_particlespawner.amount = amount;
1049-
event->add_particlespawner.spawntime = spawntime;
1050-
event->add_particlespawner.minpos = new v3f (minpos);
1051-
event->add_particlespawner.maxpos = new v3f (maxpos);
1052-
event->add_particlespawner.minvel = new v3f (minvel);
1053-
event->add_particlespawner.maxvel = new v3f (maxvel);
1054-
event->add_particlespawner.minacc = new v3f (minacc);
1055-
event->add_particlespawner.maxacc = new v3f (maxacc);
1056-
event->add_particlespawner.minexptime = minexptime;
1057-
event->add_particlespawner.maxexptime = maxexptime;
1058-
event->add_particlespawner.minsize = minsize;
1059-
event->add_particlespawner.maxsize = maxsize;
1060-
event->add_particlespawner.collisiondetection = collisiondetection;
1061-
event->add_particlespawner.collision_removal = collision_removal;
1062-
event->add_particlespawner.object_collision = object_collision;
1063-
event->add_particlespawner.attached_id = attached_id;
1064-
event->add_particlespawner.vertical = vertical;
1065-
event->add_particlespawner.texture = new std::string(texture);
1066-
event->add_particlespawner.id = server_id;
1067-
event->add_particlespawner.animation = animation;
1068-
event->add_particlespawner.glow = glow;
1007+
event->type = CE_ADD_PARTICLESPAWNER;
1008+
event->add_particlespawner.p = new ParticleSpawnerParameters(p);
1009+
event->add_particlespawner.attached_id = attached_id;
1010+
event->add_particlespawner.id = server_id;
10691011

10701012
m_client_event_queue.push(event);
10711013
}

‎src/particles.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2020 sfan5 <sfan5@live.de>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#include "particles.h"
21+
#include "util/serialize.h"
22+
23+
void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const
24+
{
25+
writeV3F32(os, pos);
26+
writeV3F32(os, vel);
27+
writeV3F32(os, acc);
28+
writeF32(os, expirationtime);
29+
writeF32(os, size);
30+
writeU8(os, collisiondetection);
31+
os << serializeLongString(texture);
32+
writeU8(os, vertical);
33+
writeU8(os, collision_removal);
34+
animation.serialize(os, 6); /* NOT the protocol ver */
35+
writeU8(os, glow);
36+
writeU8(os, object_collision);
37+
}
38+
39+
void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver)
40+
{
41+
pos = readV3F32(is);
42+
vel = readV3F32(is);
43+
acc = readV3F32(is);
44+
expirationtime = readF32(is);
45+
size = readF32(is);
46+
collisiondetection = readU8(is);
47+
texture = deSerializeLongString(is);
48+
vertical = readU8(is);
49+
collision_removal = readU8(is);
50+
animation.deSerialize(is, 6); /* NOT the protocol ver */
51+
glow = readU8(is);
52+
object_collision = readU8(is);
53+
}

‎src/particles.h

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#pragma once
21+
22+
#include <string>
23+
#include "irrlichttypes_bloated.h"
24+
#include "tileanimation.h"
25+
26+
// This file defines the particle-related structures that both the server and
27+
// client need. The ParticleManager and rendering is in client/particles.h
28+
29+
struct CommonParticleParams {
30+
bool collisiondetection = false;
31+
bool collision_removal = false;
32+
bool object_collision = false;
33+
bool vertical = false;
34+
std::string texture;
35+
struct TileAnimationParams animation;
36+
u8 glow = 0;
37+
38+
CommonParticleParams() {
39+
animation.type = TAT_NONE;
40+
}
41+
42+
/* This helper is useful for copying params from
43+
* ParticleSpawnerParameters to ParticleParameters */
44+
inline void copyCommon(CommonParticleParams &to) const {
45+
to.collisiondetection = collisiondetection;
46+
to.collision_removal = collision_removal;
47+
to.object_collision = object_collision;
48+
to.vertical = vertical;
49+
to.texture = texture;
50+
to.animation = animation;
51+
to.glow = glow;
52+
}
53+
};
54+
55+
struct ParticleParameters : CommonParticleParams {
56+
v3f pos;
57+
v3f vel;
58+
v3f acc;
59+
f32 expirationtime = 1;
60+
f32 size = 1;
61+
62+
void serialize(std::ostream &os, u16 protocol_ver) const;
63+
void deSerialize(std::istream &is, u16 protocol_ver);
64+
};
65+
66+
struct ParticleSpawnerParameters : CommonParticleParams {
67+
u16 amount = 1;
68+
v3f minpos, maxpos, minvel, maxvel, minacc, maxacc;
69+
f32 time = 1;
70+
f32 minexptime = 1, maxexptime = 1, minsize = 1, maxsize = 1;
71+
72+
// For historical reasons no (de-)serialization methods here
73+
};

‎src/script/lua_api/l_particles.cpp

+84-102
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include "common/c_converter.h"
2424
#include "common/c_content.h"
2525
#include "server.h"
26-
#include "client/particles.h"
26+
#include "particles.h"
2727

2828
// add_particle({pos=, velocity=, acceleration=, expirationtime=,
2929
// size=, collisiondetection=, collision_removal=, object_collision=,
@@ -40,85 +40,81 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4040
// glow = num
4141
int ModApiParticles::l_add_particle(lua_State *L)
4242
{
43-
MAP_LOCK_REQUIRED;
43+
NO_MAP_LOCK_REQUIRED;
4444

4545
// Get parameters
46-
v3f pos, vel, acc;
47-
float expirationtime, size;
48-
expirationtime = size = 1;
49-
bool collisiondetection, vertical, collision_removal, object_collision;
50-
collisiondetection = vertical = collision_removal = object_collision = false;
51-
struct TileAnimationParams animation;
52-
animation.type = TAT_NONE;
53-
std::string texture;
46+
struct ParticleParameters p;
5447
std::string playername;
55-
u8 glow = 0;
5648

5749
if (lua_gettop(L) > 1) // deprecated
5850
{
59-
log_deprecated(L, "Deprecated add_particle call with individual parameters instead of definition");
60-
pos = check_v3f(L, 1);
61-
vel = check_v3f(L, 2);
62-
acc = check_v3f(L, 3);
63-
expirationtime = luaL_checknumber(L, 4);
64-
size = luaL_checknumber(L, 5);
65-
collisiondetection = readParam<bool>(L, 6);
66-
texture = luaL_checkstring(L, 7);
51+
log_deprecated(L, "Deprecated add_particle call with "
52+
"individual parameters instead of definition");
53+
p.pos = check_v3f(L, 1);
54+
p.vel = check_v3f(L, 2);
55+
p.acc = check_v3f(L, 3);
56+
p.expirationtime = luaL_checknumber(L, 4);
57+
p.size = luaL_checknumber(L, 5);
58+
p.collisiondetection = readParam<bool>(L, 6);
59+
p.texture = luaL_checkstring(L, 7);
6760
if (lua_gettop(L) == 8) // only spawn for a single player
6861
playername = luaL_checkstring(L, 8);
6962
}
7063
else if (lua_istable(L, 1))
7164
{
7265
lua_getfield(L, 1, "pos");
73-
pos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f();
66+
if (lua_istable(L, -1))
67+
p.pos = check_v3f(L, -1);
7468
lua_pop(L, 1);
7569

7670
lua_getfield(L, 1, "vel");
7771
if (lua_istable(L, -1)) {
78-
vel = check_v3f(L, -1);
72+
p.vel = check_v3f(L, -1);
7973
log_deprecated(L, "The use of vel is deprecated. "
8074
"Use velocity instead");
8175
}
8276
lua_pop(L, 1);
8377

8478
lua_getfield(L, 1, "velocity");
85-
vel = lua_istable(L, -1) ? check_v3f(L, -1) : vel;
79+
if (lua_istable(L, -1))
80+
p.vel = check_v3f(L, -1);
8681
lua_pop(L, 1);
8782

8883
lua_getfield(L, 1, "acc");
8984
if (lua_istable(L, -1)) {
90-
acc = check_v3f(L, -1);
85+
p.acc = check_v3f(L, -1);
9186
log_deprecated(L, "The use of acc is deprecated. "
9287
"Use acceleration instead");
9388
}
9489
lua_pop(L, 1);
9590

9691
lua_getfield(L, 1, "acceleration");
97-
acc = lua_istable(L, -1) ? check_v3f(L, -1) : acc;
92+
if (lua_istable(L, -1))
93+
p.acc = check_v3f(L, -1);
9894
lua_pop(L, 1);
9995

100-
expirationtime = getfloatfield_default(L, 1, "expirationtime", 1);
101-
size = getfloatfield_default(L, 1, "size", 1);
102-
collisiondetection = getboolfield_default(L, 1,
103-
"collisiondetection", collisiondetection);
104-
collision_removal = getboolfield_default(L, 1,
105-
"collision_removal", collision_removal);
106-
object_collision = getboolfield_default(L, 1,
107-
"object_collision", object_collision);
108-
vertical = getboolfield_default(L, 1, "vertical", vertical);
96+
p.expirationtime = getfloatfield_default(L, 1, "expirationtime",
97+
p.expirationtime);
98+
p.size = getfloatfield_default(L, 1, "size", p.size);
99+
p.collisiondetection = getboolfield_default(L, 1,
100+
"collisiondetection", p.collisiondetection);
101+
p.collision_removal = getboolfield_default(L, 1,
102+
"collision_removal", p.collision_removal);
103+
p.object_collision = getboolfield_default(L, 1,
104+
"object_collision", p.object_collision);
105+
p.vertical = getboolfield_default(L, 1, "vertical", p.vertical);
109106

110107
lua_getfield(L, 1, "animation");
111-
animation = read_animation_definition(L, -1);
108+
p.animation = read_animation_definition(L, -1);
112109
lua_pop(L, 1);
113110

114-
texture = getstringfield_default(L, 1, "texture", "");
115-
playername = getstringfield_default(L, 1, "playername", "");
111+
p.texture = getstringfield_default(L, 1, "texture", p.texture);
112+
p.glow = getintfield_default(L, 1, "glow", p.glow);
116113

117-
glow = getintfield_default(L, 1, "glow", 0);
114+
playername = getstringfield_default(L, 1, "playername", "");
118115
}
119-
getServer(L)->spawnParticle(playername, pos, vel, acc, expirationtime, size,
120-
collisiondetection, collision_removal, object_collision, vertical,
121-
texture, animation, glow);
116+
117+
getServer(L)->spawnParticle(playername, p);
122118
return 1;
123119
}
124120

@@ -146,84 +142,82 @@ int ModApiParticles::l_add_particle(lua_State *L)
146142
// glow = num
147143
int ModApiParticles::l_add_particlespawner(lua_State *L)
148144
{
149-
MAP_LOCK_REQUIRED;
145+
NO_MAP_LOCK_REQUIRED;
150146

151147
// Get parameters
152-
u16 amount = 1;
153-
v3f minpos, maxpos, minvel, maxvel, minacc, maxacc;
154-
float time, minexptime, maxexptime, minsize, maxsize;
155-
time = minexptime = maxexptime = minsize = maxsize = 1;
156-
bool collisiondetection, vertical, collision_removal, object_collision;
157-
collisiondetection = vertical = collision_removal = object_collision = false;
158-
struct TileAnimationParams animation;
159-
animation.type = TAT_NONE;
148+
ParticleSpawnerParameters p;
160149
ServerActiveObject *attached = NULL;
161-
std::string texture;
162150
std::string playername;
163-
u8 glow = 0;
164151

165152
if (lua_gettop(L) > 1) //deprecated
166153
{
167-
log_deprecated(L,"Deprecated add_particlespawner call with individual parameters instead of definition");
168-
amount = luaL_checknumber(L, 1);
169-
time = luaL_checknumber(L, 2);
170-
minpos = check_v3f(L, 3);
171-
maxpos = check_v3f(L, 4);
172-
minvel = check_v3f(L, 5);
173-
maxvel = check_v3f(L, 6);
174-
minacc = check_v3f(L, 7);
175-
maxacc = check_v3f(L, 8);
176-
minexptime = luaL_checknumber(L, 9);
177-
maxexptime = luaL_checknumber(L, 10);
178-
minsize = luaL_checknumber(L, 11);
179-
maxsize = luaL_checknumber(L, 12);
180-
collisiondetection = readParam<bool>(L, 13);
181-
texture = luaL_checkstring(L, 14);
154+
log_deprecated(L, "Deprecated add_particlespawner call with "
155+
"individual parameters instead of definition");
156+
p.amount = luaL_checknumber(L, 1);
157+
p.time = luaL_checknumber(L, 2);
158+
p.minpos = check_v3f(L, 3);
159+
p.maxpos = check_v3f(L, 4);
160+
p.minvel = check_v3f(L, 5);
161+
p.maxvel = check_v3f(L, 6);
162+
p.minacc = check_v3f(L, 7);
163+
p.maxacc = check_v3f(L, 8);
164+
p.minexptime = luaL_checknumber(L, 9);
165+
p.maxexptime = luaL_checknumber(L, 10);
166+
p.minsize = luaL_checknumber(L, 11);
167+
p.maxsize = luaL_checknumber(L, 12);
168+
p.collisiondetection = readParam<bool>(L, 13);
169+
p.texture = luaL_checkstring(L, 14);
182170
if (lua_gettop(L) == 15) // only spawn for a single player
183171
playername = luaL_checkstring(L, 15);
184172
}
185173
else if (lua_istable(L, 1))
186174
{
187-
amount = getintfield_default(L, 1, "amount", amount);
188-
time = getfloatfield_default(L, 1, "time", time);
175+
p.amount = getintfield_default(L, 1, "amount", p.amount);
176+
p.time = getfloatfield_default(L, 1, "time", p.time);
189177

190178
lua_getfield(L, 1, "minpos");
191-
minpos = lua_istable(L, -1) ? check_v3f(L, -1) : minpos;
179+
if (lua_istable(L, -1))
180+
p.minpos = check_v3f(L, -1);
192181
lua_pop(L, 1);
193182

194183
lua_getfield(L, 1, "maxpos");
195-
maxpos = lua_istable(L, -1) ? check_v3f(L, -1) : maxpos;
184+
if (lua_istable(L, -1))
185+
p.maxpos = check_v3f(L, -1);
196186
lua_pop(L, 1);
197187

198188
lua_getfield(L, 1, "minvel");
199-
minvel = lua_istable(L, -1) ? check_v3f(L, -1) : minvel;
189+
if (lua_istable(L, -1))
190+
p.minvel = check_v3f(L, -1);
200191
lua_pop(L, 1);
201192

202193
lua_getfield(L, 1, "maxvel");
203-
maxvel = lua_istable(L, -1) ? check_v3f(L, -1) : maxvel;
194+
if (lua_istable(L, -1))
195+
p.maxvel = check_v3f(L, -1);
204196
lua_pop(L, 1);
205197

206198
lua_getfield(L, 1, "minacc");
207-
minacc = lua_istable(L, -1) ? check_v3f(L, -1) : minacc;
199+
if (lua_istable(L, -1))
200+
p.minacc = check_v3f(L, -1);
208201
lua_pop(L, 1);
209202

210203
lua_getfield(L, 1, "maxacc");
211-
maxacc = lua_istable(L, -1) ? check_v3f(L, -1) : maxacc;
204+
if (lua_istable(L, -1))
205+
p.maxacc = check_v3f(L, -1);
212206
lua_pop(L, 1);
213207

214-
minexptime = getfloatfield_default(L, 1, "minexptime", minexptime);
215-
maxexptime = getfloatfield_default(L, 1, "maxexptime", maxexptime);
216-
minsize = getfloatfield_default(L, 1, "minsize", minsize);
217-
maxsize = getfloatfield_default(L, 1, "maxsize", maxsize);
218-
collisiondetection = getboolfield_default(L, 1,
219-
"collisiondetection", collisiondetection);
220-
collision_removal = getboolfield_default(L, 1,
221-
"collision_removal", collision_removal);
222-
object_collision = getboolfield_default(L, 1,
223-
"object_collision", object_collision);
208+
p.minexptime = getfloatfield_default(L, 1, "minexptime", p.minexptime);
209+
p.maxexptime = getfloatfield_default(L, 1, "maxexptime", p.maxexptime);
210+
p.minsize = getfloatfield_default(L, 1, "minsize", p.minsize);
211+
p.maxsize = getfloatfield_default(L, 1, "maxsize", p.maxsize);
212+
p.collisiondetection = getboolfield_default(L, 1,
213+
"collisiondetection", p.collisiondetection);
214+
p.collision_removal = getboolfield_default(L, 1,
215+
"collision_removal", p.collision_removal);
216+
p.object_collision = getboolfield_default(L, 1,
217+
"object_collision", p.object_collision);
224218

225219
lua_getfield(L, 1, "animation");
226-
animation = read_animation_definition(L, -1);
220+
p.animation = read_animation_definition(L, -1);
227221
lua_pop(L, 1);
228222

229223
lua_getfield(L, 1, "attached");
@@ -233,25 +227,13 @@ int ModApiParticles::l_add_particlespawner(lua_State *L)
233227
attached = ObjectRef::getobject(ref);
234228
}
235229

236-
vertical = getboolfield_default(L, 1, "vertical", vertical);
237-
texture = getstringfield_default(L, 1, "texture", "");
230+
p.vertical = getboolfield_default(L, 1, "vertical", p.vertical);
231+
p.texture = getstringfield_default(L, 1, "texture", p.texture);
238232
playername = getstringfield_default(L, 1, "playername", "");
239-
glow = getintfield_default(L, 1, "glow", 0);
233+
p.glow = getintfield_default(L, 1, "glow", p.glow);
240234
}
241235

242-
u32 id = getServer(L)->addParticleSpawner(amount, time,
243-
minpos, maxpos,
244-
minvel, maxvel,
245-
minacc, maxacc,
246-
minexptime, maxexptime,
247-
minsize, maxsize,
248-
collisiondetection,
249-
collision_removal,
250-
object_collision,
251-
attached,
252-
vertical,
253-
texture, playername,
254-
animation, glow);
236+
u32 id = getServer(L)->addParticleSpawner(p, attached, playername);
255237
lua_pushnumber(L, id);
256238

257239
return 1;
@@ -261,7 +243,7 @@ int ModApiParticles::l_add_particlespawner(lua_State *L)
261243
// player (string) is optional
262244
int ModApiParticles::l_delete_particlespawner(lua_State *L)
263245
{
264-
MAP_LOCK_REQUIRED;
246+
NO_MAP_LOCK_REQUIRED;
265247

266248
// Get parameters
267249
u32 id = luaL_checknumber(L, 1);

‎src/script/lua_api/l_particles_local.cpp

+56-93
Original file line numberDiff line numberDiff line change
@@ -32,56 +32,44 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L)
3232
luaL_checktype(L, 1, LUA_TTABLE);
3333

3434
// Get parameters
35-
v3f pos, vel, acc;
36-
float expirationtime, size;
37-
bool collisiondetection, vertical, collision_removal;
38-
39-
struct TileAnimationParams animation;
40-
animation.type = TAT_NONE;
41-
42-
std::string texture;
43-
44-
u8 glow;
35+
ParticleParameters p;
4536

4637
lua_getfield(L, 1, "pos");
47-
pos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
38+
if (lua_istable(L, -1))
39+
p.pos = check_v3f(L, -1);
4840
lua_pop(L, 1);
4941

5042
lua_getfield(L, 1, "velocity");
51-
vel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
43+
if (lua_istable(L, -1))
44+
p.vel = check_v3f(L, -1);
5245
lua_pop(L, 1);
5346

5447
lua_getfield(L, 1, "acceleration");
55-
acc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
48+
if (lua_istable(L, -1))
49+
p.acc = check_v3f(L, -1);
5650
lua_pop(L, 1);
5751

58-
expirationtime = getfloatfield_default(L, 1, "expirationtime", 1);
59-
size = getfloatfield_default(L, 1, "size", 1);
60-
collisiondetection = getboolfield_default(L, 1, "collisiondetection", false);
61-
collision_removal = getboolfield_default(L, 1, "collision_removal", false);
62-
vertical = getboolfield_default(L, 1, "vertical", false);
52+
p.expirationtime = getfloatfield_default(L, 1, "expirationtime",
53+
p.expirationtime);
54+
p.size = getfloatfield_default(L, 1, "size", p.size);
55+
p.collisiondetection = getboolfield_default(L, 1,
56+
"collisiondetection", p.collisiondetection);
57+
p.collision_removal = getboolfield_default(L, 1,
58+
"collision_removal", p.collision_removal);
59+
p.object_collision = getboolfield_default(L, 1,
60+
"object_collision", p.object_collision);
61+
p.vertical = getboolfield_default(L, 1, "vertical", p.vertical);
6362

6463
lua_getfield(L, 1, "animation");
65-
animation = read_animation_definition(L, -1);
64+
p.animation = read_animation_definition(L, -1);
6665
lua_pop(L, 1);
6766

68-
texture = getstringfield_default(L, 1, "texture", "");
69-
70-
glow = getintfield_default(L, 1, "glow", 0);
67+
p.texture = getstringfield_default(L, 1, "texture", p.texture);
68+
p.glow = getintfield_default(L, 1, "glow", p.glow);
7169

7270
ClientEvent *event = new ClientEvent();
73-
event->type = CE_SPAWN_PARTICLE;
74-
event->spawn_particle.pos = new v3f (pos);
75-
event->spawn_particle.vel = new v3f (vel);
76-
event->spawn_particle.acc = new v3f (acc);
77-
event->spawn_particle.expirationtime = expirationtime;
78-
event->spawn_particle.size = size;
79-
event->spawn_particle.collisiondetection = collisiondetection;
80-
event->spawn_particle.collision_removal = collision_removal;
81-
event->spawn_particle.vertical = vertical;
82-
event->spawn_particle.texture = new std::string(texture);
83-
event->spawn_particle.animation = animation;
84-
event->spawn_particle.glow = glow;
71+
event->type = CE_SPAWN_PARTICLE;
72+
event->spawn_particle = new ParticleParameters(p);
8573
getClient(L)->pushToEventQueue(event);
8674

8775
return 0;
@@ -90,94 +78,69 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L)
9078
int ModApiParticlesLocal::l_add_particlespawner(lua_State *L)
9179
{
9280
luaL_checktype(L, 1, LUA_TTABLE);
93-
// Get parameters
94-
u16 amount;
95-
v3f minpos, maxpos, minvel, maxvel, minacc, maxacc;
96-
float time, minexptime, maxexptime, minsize, maxsize;
97-
bool collisiondetection, vertical, collision_removal;
9881

99-
struct TileAnimationParams animation;
100-
animation.type = TAT_NONE;
101-
// TODO: Implement this when there is a way to get an objectref.
102-
// ServerActiveObject *attached = NULL;
103-
std::string texture;
104-
u8 glow;
82+
// Get parameters
83+
ParticleSpawnerParameters p;
10584

106-
amount = getintfield_default(L, 1, "amount", 1);
107-
time = getfloatfield_default(L, 1, "time", 1);
85+
p.amount = getintfield_default(L, 1, "amount", p.amount);
86+
p.time = getfloatfield_default(L, 1, "time", p.time);
10887

10988
lua_getfield(L, 1, "minpos");
110-
minpos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
89+
if (lua_istable(L, -1))
90+
p.minpos = check_v3f(L, -1);
11191
lua_pop(L, 1);
11292

11393
lua_getfield(L, 1, "maxpos");
114-
maxpos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
94+
if (lua_istable(L, -1))
95+
p.maxpos = check_v3f(L, -1);
11596
lua_pop(L, 1);
11697

11798
lua_getfield(L, 1, "minvel");
118-
minvel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
99+
if (lua_istable(L, -1))
100+
p.minvel = check_v3f(L, -1);
119101
lua_pop(L, 1);
120102

121103
lua_getfield(L, 1, "maxvel");
122-
maxvel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
104+
if (lua_istable(L, -1))
105+
p.maxvel = check_v3f(L, -1);
123106
lua_pop(L, 1);
124107

125108
lua_getfield(L, 1, "minacc");
126-
minacc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
109+
if (lua_istable(L, -1))
110+
p.minacc = check_v3f(L, -1);
127111
lua_pop(L, 1);
128112

129113
lua_getfield(L, 1, "maxacc");
130-
maxacc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
114+
if (lua_istable(L, -1))
115+
p.maxacc = check_v3f(L, -1);
131116
lua_pop(L, 1);
132117

133-
minexptime = getfloatfield_default(L, 1, "minexptime", 1);
134-
maxexptime = getfloatfield_default(L, 1, "maxexptime", 1);
135-
minsize = getfloatfield_default(L, 1, "minsize", 1);
136-
maxsize = getfloatfield_default(L, 1, "maxsize", 1);
137-
138-
collisiondetection = getboolfield_default(L, 1, "collisiondetection", false);
139-
collision_removal = getboolfield_default(L, 1, "collision_removal", false);
140-
vertical = getboolfield_default(L, 1, "vertical", false);
118+
p.minexptime = getfloatfield_default(L, 1, "minexptime", p.minexptime);
119+
p.maxexptime = getfloatfield_default(L, 1, "maxexptime", p.maxexptime);
120+
p.minsize = getfloatfield_default(L, 1, "minsize", p.minsize);
121+
p.maxsize = getfloatfield_default(L, 1, "maxsize", p.maxsize);
122+
p.collisiondetection = getboolfield_default(L, 1,
123+
"collisiondetection", p.collisiondetection);
124+
p.collision_removal = getboolfield_default(L, 1,
125+
"collision_removal", p.collision_removal);
126+
p.object_collision = getboolfield_default(L, 1,
127+
"object_collision", p.object_collision);
141128

142129
lua_getfield(L, 1, "animation");
143-
animation = read_animation_definition(L, -1);
130+
p.animation = read_animation_definition(L, -1);
144131
lua_pop(L, 1);
145132

146-
// TODO: Implement this when a way to get an objectref on the client is added
147-
// lua_getfield(L, 1, "attached");
148-
// if (!lua_isnil(L, -1)) {
149-
// ObjectRef *ref = ObjectRef::checkobject(L, -1);
150-
// lua_pop(L, 1);
151-
// attached = ObjectRef::getobject(ref);
152-
// }
153-
154-
texture = getstringfield_default(L, 1, "texture", "");
155-
glow = getintfield_default(L, 1, "glow", 0);
133+
p.vertical = getboolfield_default(L, 1, "vertical", p.vertical);
134+
p.texture = getstringfield_default(L, 1, "texture", p.texture);
135+
p.glow = getintfield_default(L, 1, "glow", p.glow);
156136

157137
u64 id = getClient(L)->getParticleManager()->generateSpawnerId();
158138

159139
auto event = new ClientEvent();
160-
event->type = CE_ADD_PARTICLESPAWNER;
161-
event->add_particlespawner.amount = amount;
162-
event->add_particlespawner.spawntime = time;
163-
event->add_particlespawner.minpos = new v3f (minpos);
164-
event->add_particlespawner.maxpos = new v3f (maxpos);
165-
event->add_particlespawner.minvel = new v3f (minvel);
166-
event->add_particlespawner.maxvel = new v3f (maxvel);
167-
event->add_particlespawner.minacc = new v3f (minacc);
168-
event->add_particlespawner.maxacc = new v3f (maxacc);
169-
event->add_particlespawner.minexptime = minexptime;
170-
event->add_particlespawner.maxexptime = maxexptime;
171-
event->add_particlespawner.minsize = minsize;
172-
event->add_particlespawner.maxsize = maxsize;
173-
event->add_particlespawner.collisiondetection = collisiondetection;
174-
event->add_particlespawner.collision_removal = collision_removal;
175-
event->add_particlespawner.attached_id = 0;
176-
event->add_particlespawner.vertical = vertical;
177-
event->add_particlespawner.texture = new std::string(texture);
178-
event->add_particlespawner.id = id;
179-
event->add_particlespawner.animation = animation;
180-
event->add_particlespawner.glow = glow;
140+
event->type = CE_ADD_PARTICLESPAWNER;
141+
event->add_particlespawner.p = new ParticleSpawnerParameters(p);
142+
event->add_particlespawner.attached_id = 0;
143+
event->add_particlespawner.id = id;
181144

182145
getClient(L)->pushToEventQueue(event);
183146
lua_pushnumber(L, id);

‎src/server.cpp

+35-71
Original file line numberDiff line numberDiff line change
@@ -1504,17 +1504,15 @@ void Server::SendShowFormspecMessage(session_t peer_id, const std::string &forms
15041504

15051505
// Spawns a particle on peer with peer_id
15061506
void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version,
1507-
v3f pos, v3f velocity, v3f acceleration,
1508-
float expirationtime, float size, bool collisiondetection,
1509-
bool collision_removal, bool object_collision,
1510-
bool vertical, const std::string &texture,
1511-
const struct TileAnimationParams &animation, u8 glow)
1507+
const ParticleParameters &p)
15121508
{
15131509
static thread_local const float radius =
15141510
g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE * BS;
15151511

15161512
if (peer_id == PEER_ID_INEXISTENT) {
15171513
std::vector<session_t> clients = m_clients.getClientIDs();
1514+
const v3f pos = p.pos * BS;
1515+
const float radius_sq = radius * radius;
15181516

15191517
for (const session_t client_id : clients) {
15201518
RemotePlayer *player = m_env->getPlayer(client_id);
@@ -1526,76 +1524,59 @@ void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version,
15261524
continue;
15271525

15281526
// Do not send to distant clients
1529-
if (sao->getBasePosition().getDistanceFrom(pos * BS) > radius)
1527+
if (sao->getBasePosition().getDistanceFromSQ(pos) > radius_sq)
15301528
continue;
15311529

1532-
SendSpawnParticle(client_id, player->protocol_version,
1533-
pos, velocity, acceleration,
1534-
expirationtime, size, collisiondetection, collision_removal,
1535-
object_collision, vertical, texture, animation, glow);
1530+
SendSpawnParticle(client_id, player->protocol_version, p);
15361531
}
15371532
return;
15381533
}
1534+
assert(protocol_version != 0);
15391535

15401536
NetworkPacket pkt(TOCLIENT_SPAWN_PARTICLE, 0, peer_id);
15411537

1542-
pkt << pos << velocity << acceleration << expirationtime
1543-
<< size << collisiondetection;
1544-
pkt.putLongString(texture);
1545-
pkt << vertical;
1546-
pkt << collision_removal;
1547-
// This is horrible but required (why are there two ways to serialize pkts?)
1548-
std::ostringstream os(std::ios_base::binary);
1549-
animation.serialize(os, protocol_version);
1550-
pkt.putRawString(os.str());
1551-
pkt << glow;
1552-
pkt << object_collision;
1538+
{
1539+
// NetworkPacket and iostreams are incompatible...
1540+
std::ostringstream oss(std::ios_base::binary);
1541+
p.serialize(oss, protocol_version);
1542+
pkt.putRawString(oss.str());
1543+
}
15531544

15541545
Send(&pkt);
15551546
}
15561547

15571548
// Adds a ParticleSpawner on peer with peer_id
15581549
void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version,
1559-
u16 amount, float spawntime, v3f minpos, v3f maxpos,
1560-
v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime,
1561-
float minsize, float maxsize, bool collisiondetection, bool collision_removal,
1562-
bool object_collision, u16 attached_id, bool vertical, const std::string &texture, u32 id,
1563-
const struct TileAnimationParams &animation, u8 glow)
1550+
const ParticleSpawnerParameters &p, u16 attached_id, u32 id)
15641551
{
15651552
if (peer_id == PEER_ID_INEXISTENT) {
1566-
// This sucks and should be replaced:
15671553
std::vector<session_t> clients = m_clients.getClientIDs();
15681554
for (const session_t client_id : clients) {
15691555
RemotePlayer *player = m_env->getPlayer(client_id);
15701556
if (!player)
15711557
continue;
15721558
SendAddParticleSpawner(client_id, player->protocol_version,
1573-
amount, spawntime, minpos, maxpos,
1574-
minvel, maxvel, minacc, maxacc, minexptime, maxexptime,
1575-
minsize, maxsize, collisiondetection, collision_removal,
1576-
object_collision, attached_id, vertical, texture, id,
1577-
animation, glow);
1559+
p, attached_id, id);
15781560
}
15791561
return;
15801562
}
1563+
assert(protocol_version != 0);
15811564

1582-
NetworkPacket pkt(TOCLIENT_ADD_PARTICLESPAWNER, 0, peer_id);
1565+
NetworkPacket pkt(TOCLIENT_ADD_PARTICLESPAWNER, 100, peer_id);
15831566

1584-
pkt << amount << spawntime << minpos << maxpos << minvel << maxvel
1585-
<< minacc << maxacc << minexptime << maxexptime << minsize
1586-
<< maxsize << collisiondetection;
1567+
pkt << p.amount << p.time << p.minpos << p.maxpos << p.minvel
1568+
<< p.maxvel << p.minacc << p.maxacc << p.minexptime << p.maxexptime
1569+
<< p.minsize << p.maxsize << p.collisiondetection;
15871570

1588-
pkt.putLongString(texture);
1571+
pkt.putLongString(p.texture);
15891572

1590-
pkt << id << vertical;
1591-
pkt << collision_removal;
1592-
pkt << attached_id;
1593-
// This is horrible but required
1594-
std::ostringstream os(std::ios_base::binary);
1595-
animation.serialize(os, protocol_version);
1596-
pkt.putRawString(os.str());
1597-
pkt << glow;
1598-
pkt << object_collision;
1573+
pkt << id << p.vertical << p.collision_removal << attached_id;
1574+
{
1575+
std::ostringstream os(std::ios_base::binary);
1576+
p.animation.serialize(os, protocol_version);
1577+
pkt.putRawString(os.str());
1578+
}
1579+
pkt << p.glow << p.object_collision;
15991580

16001581
Send(&pkt);
16011582
}
@@ -1604,7 +1585,6 @@ void Server::SendDeleteParticleSpawner(session_t peer_id, u32 id)
16041585
{
16051586
NetworkPacket pkt(TOCLIENT_DELETE_PARTICLESPAWNER, 4, peer_id);
16061587

1607-
// Ugly error in this packet
16081588
pkt << id;
16091589

16101590
if (peer_id != PEER_ID_INEXISTENT)
@@ -3365,12 +3345,8 @@ void Server::notifyPlayers(const std::wstring &msg)
33653345
SendChatMessage(PEER_ID_INEXISTENT, ChatMessage(msg));
33663346
}
33673347

3368-
void Server::spawnParticle(const std::string &playername, v3f pos,
3369-
v3f velocity, v3f acceleration,
3370-
float expirationtime, float size, bool
3371-
collisiondetection, bool collision_removal, bool object_collision,
3372-
bool vertical, const std::string &texture,
3373-
const struct TileAnimationParams &animation, u8 glow)
3348+
void Server::spawnParticle(const std::string &playername,
3349+
const ParticleParameters &p)
33743350
{
33753351
// m_env will be NULL if the server is initializing
33763352
if (!m_env)
@@ -3386,18 +3362,11 @@ void Server::spawnParticle(const std::string &playername, v3f pos,
33863362
proto_ver = player->protocol_version;
33873363
}
33883364

3389-
SendSpawnParticle(peer_id, proto_ver, pos, velocity, acceleration,
3390-
expirationtime, size, collisiondetection, collision_removal,
3391-
object_collision, vertical, texture, animation, glow);
3365+
SendSpawnParticle(peer_id, proto_ver, p);
33923366
}
33933367

3394-
u32 Server::addParticleSpawner(u16 amount, float spawntime,
3395-
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
3396-
float minexptime, float maxexptime, float minsize, float maxsize,
3397-
bool collisiondetection, bool collision_removal, bool object_collision,
3398-
ServerActiveObject *attached, bool vertical, const std::string &texture,
3399-
const std::string &playername, const struct TileAnimationParams &animation,
3400-
u8 glow)
3368+
u32 Server::addParticleSpawner(const ParticleSpawnerParameters &p,
3369+
ServerActiveObject *attached, const std::string &playername)
34013370
{
34023371
// m_env will be NULL if the server is initializing
34033372
if (!m_env)
@@ -3417,16 +3386,11 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime,
34173386

34183387
u32 id;
34193388
if (attached_id == 0)
3420-
id = m_env->addParticleSpawner(spawntime);
3389+
id = m_env->addParticleSpawner(p.time);
34213390
else
3422-
id = m_env->addParticleSpawner(spawntime, attached_id);
3423-
3424-
SendAddParticleSpawner(peer_id, proto_ver, amount, spawntime,
3425-
minpos, maxpos, minvel, maxvel, minacc, maxacc,
3426-
minexptime, maxexptime, minsize, maxsize, collisiondetection,
3427-
collision_removal, object_collision, attached_id, vertical,
3428-
texture, id, animation, glow);
3391+
id = m_env->addParticleSpawner(p.time, attached_id);
34293392

3393+
SendAddParticleSpawner(peer_id, proto_ver, p, attached_id, id);
34303394
return id;
34313395
}
34323396

‎src/server.h

+9-33
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
#include "content/mods.h"
2828
#include "inventorymanager.h"
2929
#include "content/subgames.h"
30-
#include "tileanimation.h" // struct TileAnimationParams
30+
#include "tileanimation.h" // TileAnimationParams
31+
#include "particles.h" // ParticleParams
3132
#include "network/peerhandler.h"
3233
#include "network/address.h"
3334
#include "util/numeric.h"
@@ -226,24 +227,12 @@ class Server : public con::PeerHandler, public MapEventReceiver,
226227

227228
void notifyPlayer(const char *name, const std::wstring &msg);
228229
void notifyPlayers(const std::wstring &msg);
230+
229231
void spawnParticle(const std::string &playername,
230-
v3f pos, v3f velocity, v3f acceleration,
231-
float expirationtime, float size,
232-
bool collisiondetection, bool collision_removal, bool object_collision,
233-
bool vertical, const std::string &texture,
234-
const struct TileAnimationParams &animation, u8 glow);
235-
236-
u32 addParticleSpawner(u16 amount, float spawntime,
237-
v3f minpos, v3f maxpos,
238-
v3f minvel, v3f maxvel,
239-
v3f minacc, v3f maxacc,
240-
float minexptime, float maxexptime,
241-
float minsize, float maxsize,
242-
bool collisiondetection, bool collision_removal, bool object_collision,
243-
ServerActiveObject *attached,
244-
bool vertical, const std::string &texture,
245-
const std::string &playername, const struct TileAnimationParams &animation,
246-
u8 glow);
232+
const ParticleParameters &p);
233+
234+
u32 addParticleSpawner(const ParticleSpawnerParameters &p,
235+
ServerActiveObject *attached, const std::string &playername);
247236

248237
void deleteParticleSpawner(const std::string &playername, u32 id);
249238

@@ -453,26 +442,13 @@ class Server : public con::PeerHandler, public MapEventReceiver,
453442

454443
// Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all)
455444
void SendAddParticleSpawner(session_t peer_id, u16 protocol_version,
456-
u16 amount, float spawntime,
457-
v3f minpos, v3f maxpos,
458-
v3f minvel, v3f maxvel,
459-
v3f minacc, v3f maxacc,
460-
float minexptime, float maxexptime,
461-
float minsize, float maxsize,
462-
bool collisiondetection, bool collision_removal, bool object_collision,
463-
u16 attached_id,
464-
bool vertical, const std::string &texture, u32 id,
465-
const struct TileAnimationParams &animation, u8 glow);
445+
const ParticleSpawnerParameters &p, u16 attached_id, u32 id);
466446

467447
void SendDeleteParticleSpawner(session_t peer_id, u32 id);
468448

469449
// Spawns particle on peer with peer_id (PEER_ID_INEXISTENT == all)
470450
void SendSpawnParticle(session_t peer_id, u16 protocol_version,
471-
v3f pos, v3f velocity, v3f acceleration,
472-
float expirationtime, float size,
473-
bool collisiondetection, bool collision_removal, bool object_collision,
474-
bool vertical, const std::string &texture,
475-
const struct TileAnimationParams &animation, u8 glow);
451+
const ParticleParameters &p);
476452

477453
void SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersao);
478454
void SendActiveObjectMessages(session_t peer_id, const std::string &datas,

0 commit comments

Comments
 (0)
Please sign in to comment.