Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve code style and comment out dead code.
  • Loading branch information
red-001 authored and sofar committed Apr 9, 2017
1 parent f955b24 commit 330b38d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 92 deletions.
26 changes: 12 additions & 14 deletions src/particles.cpp
Expand Up @@ -428,9 +428,9 @@ ParticleManager::~ParticleManager()

void ParticleManager::step(float dtime)
{
stepParticles (dtime);
stepSpawners (dtime);
stepSpawnersLocal (dtime);
stepParticles(dtime);
stepSpawners(dtime);
stepSpawnersLocal(dtime);
}

void ParticleManager::stepSpawners (float dtime)
Expand Down Expand Up @@ -540,14 +540,14 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
break;
}
case CE_DELETE_LOCAL_PARTICLESPAWNER: {
MutexAutoLock lock(m_spawner_local_list_lock);
if (m_particle_spawners_local.find(event->delete_particlespawner.id) !=
m_particle_spawners_local.end()) {
delete m_particle_spawners_local.find(event->delete_particlespawner.id)->second;
m_particle_spawners_local.erase(event->delete_particlespawner.id);
}
// no allocated memory in delete event
break;
MutexAutoLock lock(m_spawner_local_list_lock);
if (m_particle_spawners_local.find(event->delete_particlespawner.id) !=
m_particle_spawners_local.end()) {
delete m_particle_spawners_local.find(event->delete_particlespawner.id)->second;
m_particle_spawners_local.erase(event->delete_particlespawner.id);
}
// no allocated memory in delete event
break;
}
case CE_ADD_PARTICLESPAWNER: {
{
Expand Down Expand Up @@ -773,9 +773,7 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef,

u32 ParticleManager::getSpawnerId()
{
u32 id = 0;
for (;;) { // look for unused particlespawner id
id++;
for (u32 id = 0;; ++id) { // look for unused particlespawner id
UNORDERED_MAP<u32, ParticleSpawner*>::iterator f =
m_particle_spawners_local.find(id);
if (f == m_particle_spawners_local.end()) {
Expand Down
117 changes: 39 additions & 78 deletions src/script/lua_api/l_particles_local.cpp
Expand Up @@ -25,56 +25,40 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_object.h"
#include "particles.h"

// add_particle({pos=, velocity=, acceleration=, expirationtime=,
// size=, collisiondetection=, collision_removal=, vertical=,
// texture=})
// pos/velocity/acceleration = {x=num, y=num, z=num}
// expirationtime = num (seconds)
// size = num
// collisiondetection = bool
// collision_removal = bool
// vertical = bool
// texture = e.g."default_wood.png"
// animation = TileAnimation definition
// glow = num

int ModApiParticlesLocal::l_add_particle(lua_State *L)
{
luaL_checktype(L, 1, LUA_TTABLE);

// Get parameters
v3f pos, vel, acc;
pos = vel = acc = v3f(0, 0, 0);

float expirationtime, size;
expirationtime = size = 1;

bool collisiondetection, vertical, collision_removal;
collisiondetection = vertical = collision_removal = false;

struct TileAnimationParams animation;
animation.type = TAT_NONE;

std::string texture = "";
std::string texture;

u8 glow = 0;
u8 glow;

lua_getfield(L, 1, "pos");
pos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f();
pos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

lua_getfield(L, 1, "velocity");
vel = lua_istable(L, -1) ? check_v3f(L, -1) : vel;
vel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

lua_getfield(L, 1, "acceleration");
acc = lua_istable(L, -1) ? check_v3f(L, -1) : acc;
acc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

expirationtime = getfloatfield_default(L, 1, "expirationtime", 1);
size = getfloatfield_default(L, 1, "size", 1);
collisiondetection =
getboolfield_default(L, 1, "collisiondetection", collisiondetection);
collision_removal =
getboolfield_default(L, 1, "collision_removal", collision_removal);
vertical = getboolfield_default(L, 1, "vertical", vertical);
collisiondetection = getboolfield_default(L, 1, "collisiondetection", false);
collision_removal = getboolfield_default(L, 1, "collision_removal", false);
vertical = getboolfield_default(L, 1, "vertical", false);

lua_getfield(L, 1, "animation");
animation = read_animation_definition(L, -1);
Expand Down Expand Up @@ -102,92 +86,70 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L)
return 0;
}

// add_particlespawner({amount=, time=,
// minpos=, maxpos=,
// minvel=, maxvel=,
// minacc=, maxacc=,
// minexptime=, maxexptime=,
// minsize=, maxsize=,
// collisiondetection=,
// collision_removal=,
// vertical=,
// texture=})
// minpos/maxpos/minvel/maxvel/minacc/maxacc = {x=num, y=num, z=num}
// minexptime/maxexptime = num (seconds)
// minsize/maxsize = num
// collisiondetection = bool
// collision_removal = bool
// vertical = bool
// texture = e.g."default_wood.png"
// animation = TileAnimation definition
// glow = num
int ModApiParticlesLocal::l_add_particlespawner(lua_State *L)
{
luaL_checktype(L, 1, LUA_TTABLE);
// Get parameters
u16 amount = 1;
u16 amount;
v3f minpos, maxpos, minvel, maxvel, minacc, maxacc;
minpos = maxpos = minvel = maxvel = minacc = maxacc = v3f(0, 0, 0);
float time, minexptime, maxexptime, minsize, maxsize;
time = minexptime = maxexptime = minsize = maxsize = 1;
bool collisiondetection, vertical, collision_removal;
collisiondetection = vertical = collision_removal = false;

struct TileAnimationParams animation;
animation.type = TAT_NONE;
// TODO: Implement this when there is a way to get an objectref.
ServerActiveObject *attached = NULL;
std::string texture = "";
u8 glow = 0;
// ServerActiveObject *attached = NULL;
std::string texture;
u8 glow;

amount = getintfield_default(L, 1, "amount", amount);
time = getfloatfield_default(L, 1, "time", time);
amount = getintfield_default(L, 1, "amount", 1);
time = getfloatfield_default(L, 1, "time", 1);

lua_getfield(L, 1, "minpos");
minpos = lua_istable(L, -1) ? check_v3f(L, -1) : minpos;
minpos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

lua_getfield(L, 1, "maxpos");
maxpos = lua_istable(L, -1) ? check_v3f(L, -1) : maxpos;
maxpos = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

lua_getfield(L, 1, "minvel");
minvel = lua_istable(L, -1) ? check_v3f(L, -1) : minvel;
minvel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

lua_getfield(L, 1, "maxvel");
maxvel = lua_istable(L, -1) ? check_v3f(L, -1) : maxvel;
maxvel = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

lua_getfield(L, 1, "minacc");
minacc = lua_istable(L, -1) ? check_v3f(L, -1) : minacc;
minacc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

lua_getfield(L, 1, "maxacc");
maxacc = lua_istable(L, -1) ? check_v3f(L, -1) : maxacc;
maxacc = lua_istable(L, -1) ? check_v3f(L, -1) : v3f(0, 0, 0);
lua_pop(L, 1);

minexptime = getfloatfield_default(L, 1, "minexptime", minexptime);
maxexptime = getfloatfield_default(L, 1, "maxexptime", maxexptime);
minsize = getfloatfield_default(L, 1, "minsize", minsize);
maxsize = getfloatfield_default(L, 1, "maxsize", maxsize);
collisiondetection =
getboolfield_default(L, 1,"collisiondetection", collisiondetection);
collision_removal =
getboolfield_default(L, 1, "collision_removal", collision_removal);
minexptime = getfloatfield_default(L, 1, "minexptime", 1);
maxexptime = getfloatfield_default(L, 1, "maxexptime", 1);
minsize = getfloatfield_default(L, 1, "minsize", 1);
maxsize = getfloatfield_default(L, 1, "maxsize", 1);

collisiondetection = getboolfield_default(L, 1, "collisiondetection", false);
collision_removal = getboolfield_default(L, 1, "collision_removal", false);
vertical = getboolfield_default(L, 1, "vertical", false);

lua_getfield(L, 1, "animation");
animation = read_animation_definition(L, -1);
lua_pop(L, 1);

// TODO: Implement this when a way to get an objectref on the client is added
lua_getfield(L, 1, "attached");
if (!lua_isnil(L, -1)) {
ObjectRef *ref = ObjectRef::checkobject(L, -1);
lua_pop(L, 1);
attached = ObjectRef::getobject(ref);
}

vertical = getboolfield_default(L, 1, "vertical", vertical);
// lua_getfield(L, 1, "attached");
// if (!lua_isnil(L, -1)) {
// ObjectRef *ref = ObjectRef::checkobject(L, -1);
// lua_pop(L, 1);
// attached = ObjectRef::getobject(ref);
// }

texture = getstringfield_default(L, 1, "texture", "");
glow = getintfield_default(L, 1, "glow", 0);

Expand Down Expand Up @@ -222,7 +184,6 @@ int ModApiParticlesLocal::l_add_particlespawner(lua_State *L)
return 1;
}

// delete_particlespawner(id)
int ModApiParticlesLocal::l_delete_particlespawner(lua_State *L)
{
// Get parameters
Expand Down

0 comments on commit 330b38d

Please sign in to comment.