Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

red-001
Copy link
Contributor

@red-001 red-001 commented Mar 31, 2017

  • Add core.add_particle
  • Add core.add_particlespawner
  • Add core.delete_particlespawner
  • Document new API
  • Fix code style
  • Test if everything works

Part of #5394
You can't attach the particle spawner to objects yet as there is no objectref on the client.

@red-001 red-001 mentioned this pull request Mar 31, 2017
27 tasks

u8 glow = 0;

if (lua_istable(L, 1)) {
Copy link
Member

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

@red-001 red-001 force-pushed the csm_particles branch 2 times, most recently from 31f38d3 to eff6596 Compare April 1, 2017 12:03
void ParticleManager::stepSpawnersLocal (float dtime)
{
MutexAutoLock lock(m_spawner_local_list_lock);
for (std::map<u32, ParticleSpawner*>::iterator i =
Copy link
Member

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

@@ -455,6 +456,26 @@ void ParticleManager::stepSpawners (float dtime)
}
}

void ParticleManager::stepSpawnersLocal (float dtime)
{
MutexAutoLock lock(m_spawner_local_list_lock);
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@red-001 red-001 changed the title [CSM] Start work on csm particles. [CSM] Add local particles and particlespawners. Apr 1, 2017
@red-001 red-001 force-pushed the csm_particles branch 2 times, most recently from 37e8dd5 to f496806 Compare April 2, 2017 07:26
@@ -433,6 +430,7 @@ void ParticleManager::step(float dtime)
{
stepParticles (dtime);
stepSpawners (dtime);
stepSpawnersLocal (dtime);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stepSpawnersLocal(dtime); (without space)

{
i->second->step(dtime, m_env);
++i;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs code style fixes.

for(UNORDERED_MAP<u32, ParticleSpawner*>::iterator i =
m_particle_spawners_local.begin();
i != m_particle_spawners_local.end();)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (<snip>) {

m_particle_spawners_local.erase(event->delete_particlespawner.id);
}
// no allocated memory in delete event
break;
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1x Space missing

u32 ParticleManager::getSpawnerId()
{
u32 id = 0;
for (;;) { // look for unused particlespawner id
Copy link
Member

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 @@
/*
Copy link
Member

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

Copy link
Contributor Author

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.

@red-001 red-001 force-pushed the csm_particles branch 2 times, most recently from 6c61d93 to b22ce8f Compare April 4, 2017 17:30
@sofar
Copy link
Contributor

sofar commented Apr 6, 2017

Tested. Getting easily 1k+ particles client side. Very nice.

👍

@bigfoot547
Copy link
Contributor

@sofar Is that an approval?

@@ -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) !=
Copy link
Member

@SmallJoker SmallJoker Apr 8, 2017

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:

i != m_particle_spawners_local.end();) {
delete i->second;
m_particle_spawners_local.erase(i++);
}
Copy link
Member

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);
}

@nerzhul nerzhul added the Rebase needed The PR needs to be rebased by its author. label Apr 27, 2017
@SmallJoker SmallJoker dismissed nerzhul’s stale review April 29, 2017 13:49

Changes were made.

}

### `ParticleSpawner` definition (`add_particlespawner`)
**NOTE: `attached` is not implemented yet.**
Copy link
Member

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);
Copy link
Member

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++);
Copy link
Member

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?

stepSpawners (dtime);
stepParticles(dtime);
stepSpawners(dtime);
stepSpawnersLocal(dtime);
}

void ParticleManager::stepSpawners (float dtime)
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested this

}
break;
// no allocated memory in delete event
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double break

delete it->second;
m_particle_spawners_local.erase(it);
}
}
Copy link
Member

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?

delete event->add_particlespawner.texture;
delete event->add_particlespawner.maxacc;

{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

m_particle_spawners_local.find(id);
if (f == m_particle_spawners_local.end()) {
return id;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brace removal possible

@sfan5 sfan5 removed the Rebase needed The PR needs to be rebased by its author. label Apr 29, 2017
@nerzhul nerzhul added this to To Do in Minetest 0.4.16 Apr 29, 2017
@sofar
Copy link
Contributor

sofar commented May 4, 2017

doesn't compile:

CMake Error at src/CMakeLists.txt:575 (add_executable):
  Cannot find source file:

    /home/sofar/git/minetest/src/script/lua_api/l_particles_local.cpp

@red-001 red-001 force-pushed the csm_particles branch 2 times, most recently from b82c8ce to d00e0e2 Compare May 6, 2017 10:11
@nerzhul nerzhul moved this from To Do to Requests in Minetest 0.4.16 May 21, 2017
@nerzhul nerzhul removed this from the 0.4.16 milestone May 21, 2017
@nerzhul nerzhul removed this from Requests in Minetest 0.4.16 May 21, 2017
@SmallJoker SmallJoker added Feature ✨ PRs that add or enhance a feature Rebase needed The PR needs to be rebased by its author. labels Jun 17, 2017
@red-001
Copy link
Contributor Author

red-001 commented Jun 28, 2017

closing this as I'm working on a better way to implement this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Client Script API Feature ✨ PRs that add or enhance a feature Rebase needed The PR needs to be rebased by its author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants