-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CSM] Add local particles and particlespawners. #5492
Conversation
|
||
u8 glow = 0; | ||
|
||
if (lua_istable(L, 1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should just abort if it isn't a table
31f38d3
to
eff6596
Compare
src/particles.cpp
Outdated
void ParticleManager::stepSpawnersLocal (float dtime) | ||
{ | ||
MutexAutoLock lock(m_spawner_local_list_lock); | ||
for (std::map<u32, ParticleSpawner*>::iterator i = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you should use a UNORDERED_MAP for this
src/particles.cpp
Outdated
@@ -455,6 +456,26 @@ void ParticleManager::stepSpawners (float dtime) | |||
} | |||
} | |||
|
|||
void ParticleManager::stepSpawnersLocal (float dtime) | |||
{ | |||
MutexAutoLock lock(m_spawner_local_list_lock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why a mutex ? i don't see any other thread using it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just duplicated the way that the list of particlespawners sent by the server is handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay this should be removed as client doesn't have locks here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
37e8dd5
to
f496806
Compare
src/particles.cpp
Outdated
@@ -433,6 +430,7 @@ void ParticleManager::step(float dtime) | |||
{ | |||
stepParticles (dtime); | |||
stepSpawners (dtime); | |||
stepSpawnersLocal (dtime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stepSpawnersLocal(dtime);
(without space)
src/particles.cpp
Outdated
{ | ||
i->second->step(dtime, m_env); | ||
++i; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs code style fixes.
src/particles.cpp
Outdated
for(UNORDERED_MAP<u32, ParticleSpawner*>::iterator i = | ||
m_particle_spawners_local.begin(); | ||
i != m_particle_spawners_local.end();) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (<snip>) {
src/particles.cpp
Outdated
m_particle_spawners_local.erase(event->delete_particlespawner.id); | ||
} | ||
// no allocated memory in delete event | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-2 indents for the whole block
// vertical = bool | ||
// texture = e.g."default_wood.png" | ||
// animation = TileAnimation definition | ||
// glow = num |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types should be embedded into line 28-30 or removed entirely (we have the documentation in lua_api.txt
)
lua_pop(L, 1); | ||
|
||
lua_getfield(L, 1, "velocity"); | ||
vel = lua_istable(L, -1) ? check_v3f(L, -1) : vel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent with pos
.
// vertical = bool | ||
// texture = e.g."default_wood.png" | ||
// animation = TileAnimation definition | ||
// glow = num |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types here again.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this would look better if the default values were set in the conditional expressions below.
minsize = getfloatfield_default(L, 1, "minsize", minsize); | ||
maxsize = getfloatfield_default(L, 1, "maxsize", maxsize); | ||
collisiondetection = | ||
getboolfield_default(L, 1,"collisiondetection", collisiondetection); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1x Space missing
src/particles.cpp
Outdated
u32 ParticleManager::getSpawnerId() | ||
{ | ||
u32 id = 0; | ||
for (;;) { // look for unused particlespawner id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (u32 id = 0;; ++id) {
@@ -0,0 +1,205 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it not possible to reuse the server's particles? Ie: by adding a member variable to indicate is_local
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could but that file includes a lot of backwards compatibility related stuff that isn't really wanted in a new api.
6c61d93
to
b22ce8f
Compare
Tested. Getting easily 1k+ particles client side. Very nice. 👍 |
@sofar Is that an approval? |
src/particles.cpp
Outdated
@@ -511,6 +527,15 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client, | |||
// no allocated memory in delete event | |||
break; | |||
} | |||
case CE_DELETE_LOCAL_PARTICLESPAWNER: { | |||
if (m_particle_spawners_local.find(event->delete_particlespawner.id) != |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UNORDERED_MAP<u32, ParticleSpawner*>::iterator it =
m_particle_spawners_local.find(event->delete_particlespawner.id);
if (it != m_particle_spawners_local.end()) {
delete it->second;
m_particle_spawners_local.erase(it);
}
Makes the whole thing easier to read (yes, it's done this way aswell below).
EDIT: same for case CE_ADD_LOCAL_PARTICLESPAWNER:
src/particles.cpp
Outdated
i != m_particle_spawners_local.end();) { | ||
delete i->second; | ||
m_particle_spawners_local.erase(i++); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (UNORDERED_MAP<u32, ParticleSpawner*>::iterator it =
m_particle_spawners_local.begin();
it != m_particle_spawners_local.end(); ++it) {
delete it->second;
m_particle_spawners_local.erase(it);
}
doc/client_lua_api.md
Outdated
} | ||
|
||
### `ParticleSpawner` definition (`add_particlespawner`) | ||
**NOTE: `attached` is not implemented yet.** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then remove it from here?
delete i->second; | ||
m_particle_spawners.erase(i++); | ||
m_particle_spawners.erase(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure this works?
erasing & iterating at the same time needs some special care
i != m_particle_spawners_local.end();) { | ||
if (i->second->get_expired()) { | ||
delete i->second; | ||
m_particle_spawners_local.erase(i++); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now why is this different from stepSpawners
?
src/particles.cpp
Outdated
stepSpawners (dtime); | ||
stepParticles(dtime); | ||
stepSpawners(dtime); | ||
stepSpawnersLocal(dtime); | ||
} | ||
|
||
void ParticleManager::stepSpawners (float dtime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space could be removed here too
delete i->second; | ||
m_particle_spawners.erase(i++); | ||
m_particle_spawners.erase(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tested this
src/particles.cpp
Outdated
} | ||
break; | ||
// no allocated memory in delete event | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double break
src/particles.cpp
Outdated
delete it->second; | ||
m_particle_spawners_local.erase(it); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this in {
}
's?
src/particles.cpp
Outdated
delete event->add_particlespawner.texture; | ||
delete event->add_particlespawner.maxacc; | ||
|
||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
src/particles.cpp
Outdated
m_particle_spawners_local.find(id); | ||
if (f == m_particle_spawners_local.end()) { | ||
return id; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
brace removal possible
doesn't compile:
|
b82c8ce
to
d00e0e2
Compare
closing this as I'm working on a better way to implement this. |
core.add_particle
core.add_particlespawner
core.delete_particlespawner
Part of #5394
You can't attach the particle spawner to objects yet as there is no objectref on the client.