mirror of
https://github.com/moparisthebest/minetest
synced 2025-01-11 05:38:01 -05:00
Cleanup server addparticle(spawner) by merge two identical functions.
This commit is contained in:
parent
a8c5841140
commit
4e6971e593
@ -96,14 +96,8 @@ int ModApiParticles::l_add_particle(lua_State *L)
|
|||||||
texture = getstringfield_default(L, 1, "texture", "");
|
texture = getstringfield_default(L, 1, "texture", "");
|
||||||
playername = getstringfield_default(L, 1, "playername", "");
|
playername = getstringfield_default(L, 1, "playername", "");
|
||||||
}
|
}
|
||||||
if (playername == "") { // spawn for all players
|
getServer(L)->spawnParticle(playername, pos, vel, acc,
|
||||||
getServer(L)->spawnParticleAll(pos, vel, acc,
|
|
||||||
expirationtime, size, collisiondetection, vertical, texture);
|
expirationtime, size, collisiondetection, vertical, texture);
|
||||||
} else {
|
|
||||||
getServer(L)->spawnParticle(playername.c_str(),
|
|
||||||
pos, vel, acc, expirationtime,
|
|
||||||
size, collisiondetection, vertical, texture);
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,30 +189,18 @@ int ModApiParticles::l_add_particlespawner(lua_State *L)
|
|||||||
texture = getstringfield_default(L, 1, "texture", "");
|
texture = getstringfield_default(L, 1, "texture", "");
|
||||||
playername = getstringfield_default(L, 1, "playername", "");
|
playername = getstringfield_default(L, 1, "playername", "");
|
||||||
}
|
}
|
||||||
if (playername == "") { //spawn for all players
|
|
||||||
u32 id = getServer(L)->addParticleSpawnerAll( amount, time,
|
u32 id = getServer(L)->addParticleSpawner(amount, time,
|
||||||
minpos, maxpos,
|
minpos, maxpos,
|
||||||
minvel, maxvel,
|
minvel, maxvel,
|
||||||
minacc, maxacc,
|
minacc, maxacc,
|
||||||
minexptime, maxexptime,
|
minexptime, maxexptime,
|
||||||
minsize, maxsize,
|
minsize, maxsize,
|
||||||
collisiondetection,
|
collisiondetection,
|
||||||
vertical,
|
vertical,
|
||||||
texture);
|
texture, playername);
|
||||||
lua_pushnumber(L, id);
|
lua_pushnumber(L, id);
|
||||||
} else {
|
|
||||||
u32 id = getServer(L)->addParticleSpawner(playername.c_str(),
|
|
||||||
amount, time,
|
|
||||||
minpos, maxpos,
|
|
||||||
minvel, maxvel,
|
|
||||||
minacc, maxacc,
|
|
||||||
minexptime, maxexptime,
|
|
||||||
minsize, maxsize,
|
|
||||||
collisiondetection,
|
|
||||||
vertical,
|
|
||||||
texture);
|
|
||||||
lua_pushnumber(L, id);
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,16 +210,12 @@ int ModApiParticles::l_delete_particlespawner(lua_State *L)
|
|||||||
{
|
{
|
||||||
// Get parameters
|
// Get parameters
|
||||||
u32 id = luaL_checknumber(L, 1);
|
u32 id = luaL_checknumber(L, 1);
|
||||||
|
std::string playername = "";
|
||||||
|
if (lua_gettop(L) == 2) {
|
||||||
|
playername = luaL_checkstring(L, 2);
|
||||||
|
}
|
||||||
|
|
||||||
if (lua_gettop(L) == 2) // only delete for one player
|
getServer(L)->deleteParticleSpawner(playername, id);
|
||||||
{
|
|
||||||
const char *playername = luaL_checkstring(L, 2);
|
|
||||||
getServer(L)->deleteParticleSpawner(playername, id);
|
|
||||||
}
|
|
||||||
else // delete for all players
|
|
||||||
{
|
|
||||||
getServer(L)->deleteParticleSpawnerAll(id);
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3067,34 +3067,36 @@ void Server::notifyPlayers(const std::wstring &msg)
|
|||||||
SendChatMessage(PEER_ID_INEXISTENT,msg);
|
SendChatMessage(PEER_ID_INEXISTENT,msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::spawnParticle(const char *playername, v3f pos,
|
void Server::spawnParticle(const std::string &playername, v3f pos,
|
||||||
v3f velocity, v3f acceleration,
|
v3f velocity, v3f acceleration,
|
||||||
float expirationtime, float size, bool
|
float expirationtime, float size, bool
|
||||||
collisiondetection, bool vertical, const std::string &texture)
|
collisiondetection, bool vertical, const std::string &texture)
|
||||||
{
|
{
|
||||||
Player *player = m_env->getPlayer(playername);
|
u16 peer_id = PEER_ID_INEXISTENT;
|
||||||
if(!player)
|
if (playername != "") {
|
||||||
return;
|
Player* player = m_env->getPlayer(playername.c_str());
|
||||||
SendSpawnParticle(player->peer_id, pos, velocity, acceleration,
|
if (!player)
|
||||||
|
return;
|
||||||
|
peer_id = player->peer_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
SendSpawnParticle(peer_id, pos, velocity, acceleration,
|
||||||
expirationtime, size, collisiondetection, vertical, texture);
|
expirationtime, size, collisiondetection, vertical, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
|
u32 Server::addParticleSpawner(u16 amount, float spawntime,
|
||||||
float expirationtime, float size,
|
|
||||||
bool collisiondetection, bool vertical, const std::string &texture)
|
|
||||||
{
|
|
||||||
SendSpawnParticle(PEER_ID_INEXISTENT,pos, velocity, acceleration,
|
|
||||||
expirationtime, size, collisiondetection, vertical, texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 Server::addParticleSpawner(const char *playername, u16 amount, float spawntime,
|
|
||||||
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
|
v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
|
||||||
float minexptime, float maxexptime, float minsize, float maxsize,
|
float minexptime, float maxexptime, float minsize, float maxsize,
|
||||||
bool collisiondetection, bool vertical, const std::string &texture)
|
bool collisiondetection, bool vertical, const std::string &texture,
|
||||||
|
const std::string &playername)
|
||||||
{
|
{
|
||||||
Player *player = m_env->getPlayer(playername);
|
u16 peer_id = PEER_ID_INEXISTENT;
|
||||||
if(!player)
|
if (playername != "") {
|
||||||
return -1;
|
Player* player = m_env->getPlayer(playername.c_str());
|
||||||
|
if (!player)
|
||||||
|
return -1;
|
||||||
|
peer_id = player->peer_id;
|
||||||
|
}
|
||||||
|
|
||||||
u32 id = 0;
|
u32 id = 0;
|
||||||
for(;;) // look for unused particlespawner id
|
for(;;) // look for unused particlespawner id
|
||||||
@ -3109,7 +3111,7 @@ u32 Server::addParticleSpawner(const char *playername, u16 amount, float spawnti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SendAddParticleSpawner(player->peer_id, amount, spawntime,
|
SendAddParticleSpawner(peer_id, amount, spawntime,
|
||||||
minpos, maxpos, minvel, maxvel, minacc, maxacc,
|
minpos, maxpos, minvel, maxvel, minacc, maxacc,
|
||||||
minexptime, maxexptime, minsize, maxsize,
|
minexptime, maxexptime, minsize, maxsize,
|
||||||
collisiondetection, vertical, texture, id);
|
collisiondetection, vertical, texture, id);
|
||||||
@ -3117,55 +3119,21 @@ u32 Server::addParticleSpawner(const char *playername, u16 amount, float spawnti
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Server::addParticleSpawnerAll(u16 amount, float spawntime,
|
void Server::deleteParticleSpawner(const std::string &playername, u32 id)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
u32 id = 0;
|
u16 peer_id = PEER_ID_INEXISTENT;
|
||||||
for(;;) // look for unused particlespawner id
|
if (playername != "") {
|
||||||
{
|
Player* player = m_env->getPlayer(playername.c_str());
|
||||||
id++;
|
if (!player)
|
||||||
if (std::find(m_particlespawner_ids.begin(),
|
return;
|
||||||
m_particlespawner_ids.end(), id)
|
peer_id = player->peer_id;
|
||||||
== m_particlespawner_ids.end())
|
|
||||||
{
|
|
||||||
m_particlespawner_ids.push_back(id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SendAddParticleSpawner(PEER_ID_INEXISTENT, amount, spawntime,
|
|
||||||
minpos, maxpos, minvel, maxvel, minacc, maxacc,
|
|
||||||
minexptime, maxexptime, minsize, maxsize,
|
|
||||||
collisiondetection, vertical, texture, id);
|
|
||||||
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Server::deleteParticleSpawner(const char *playername, u32 id)
|
|
||||||
{
|
|
||||||
Player *player = m_env->getPlayer(playername);
|
|
||||||
if(!player)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_particlespawner_ids.erase(
|
m_particlespawner_ids.erase(
|
||||||
std::remove(m_particlespawner_ids.begin(),
|
std::remove(m_particlespawner_ids.begin(),
|
||||||
m_particlespawner_ids.end(), id),
|
m_particlespawner_ids.end(), id),
|
||||||
m_particlespawner_ids.end());
|
m_particlespawner_ids.end());
|
||||||
SendDeleteParticleSpawner(player->peer_id, id);
|
SendDeleteParticleSpawner(peer_id, id);
|
||||||
}
|
|
||||||
|
|
||||||
void Server::deleteParticleSpawnerAll(u32 id)
|
|
||||||
{
|
|
||||||
m_particlespawner_ids.erase(
|
|
||||||
std::remove(m_particlespawner_ids.begin(),
|
|
||||||
m_particlespawner_ids.end(), id),
|
|
||||||
m_particlespawner_ids.end());
|
|
||||||
SendDeleteParticleSpawner(PEER_ID_INEXISTENT, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Inventory* Server::createDetachedInventory(const std::string &name)
|
Inventory* Server::createDetachedInventory(const std::string &name)
|
||||||
|
23
src/server.h
23
src/server.h
@ -269,34 +269,21 @@ public:
|
|||||||
|
|
||||||
void notifyPlayer(const char *name, const std::wstring &msg);
|
void notifyPlayer(const char *name, const std::wstring &msg);
|
||||||
void notifyPlayers(const std::wstring &msg);
|
void notifyPlayers(const std::wstring &msg);
|
||||||
void spawnParticle(const char *playername,
|
void spawnParticle(const std::string &playername,
|
||||||
v3f pos, v3f velocity, v3f acceleration,
|
v3f pos, v3f velocity, v3f acceleration,
|
||||||
float expirationtime, float size,
|
float expirationtime, float size,
|
||||||
bool collisiondetection, bool vertical, const std::string &texture);
|
bool collisiondetection, bool vertical, const std::string &texture);
|
||||||
|
|
||||||
void spawnParticleAll(v3f pos, v3f velocity, v3f acceleration,
|
u32 addParticleSpawner(u16 amount, float spawntime,
|
||||||
float expirationtime, float size,
|
|
||||||
bool collisiondetection, bool vertical, const std::string &texture);
|
|
||||||
|
|
||||||
u32 addParticleSpawner(const char *playername,
|
|
||||||
u16 amount, float spawntime,
|
|
||||||
v3f minpos, v3f maxpos,
|
v3f minpos, v3f maxpos,
|
||||||
v3f minvel, v3f maxvel,
|
v3f minvel, v3f maxvel,
|
||||||
v3f minacc, v3f maxacc,
|
v3f minacc, v3f maxacc,
|
||||||
float minexptime, float maxexptime,
|
float minexptime, float maxexptime,
|
||||||
float minsize, float maxsize,
|
float minsize, float maxsize,
|
||||||
bool collisiondetection, bool vertical, const std::string &texture);
|
bool collisiondetection, bool vertical, const std::string &texture,
|
||||||
|
const std::string &playername);
|
||||||
|
|
||||||
u32 addParticleSpawnerAll(u16 amount, float spawntime,
|
void deleteParticleSpawner(const std::string &playername, u32 id);
|
||||||
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);
|
|
||||||
|
|
||||||
void deleteParticleSpawner(const char *playername, u32 id);
|
|
||||||
void deleteParticleSpawnerAll(u32 id);
|
|
||||||
|
|
||||||
// Creates or resets inventory
|
// Creates or resets inventory
|
||||||
Inventory* createDetachedInventory(const std::string &name);
|
Inventory* createDetachedInventory(const std::string &name);
|
||||||
|
Loading…
Reference in New Issue
Block a user