What does EntitySet.release do ? I’m using the MonkeyTrap approach with a service to spawn mobs, and in my terminate method I have (fired when exiting to main menu):

[java] @Override
public void terminate(GameSystems systems) {

But nothing happens here (as far as I can see).

What is the best approach with regards to entitydata and sets when creating new games etc.? To retain one entitydata with one (or many?) set(s?) ?

Ah, I see now that the EntityData>Sets> are the various component filter-sets. So a multitude of sets will always be present in the entitydata.

When you create an EntitySet, in the background it is receiving change events about entities. release() stops it from receiving further change events. If you don’t call release() when you are done with an entity set then it will never be garbage collected and its internal change events queue will continue to grow and grow as additional changes are made that may affect it.

From the javadoc for release():
* Releases this entity set from processing further entity
* updates. The entities contained in the set will remain
* until garbage collected normally or until clear() is
* called.

An EntitySet is just a view. releasing it does not delete any entities or anything. If you want to delete entities then you have to delete them. You can kind of think of EntitySet as a database ResultSet… only in this case, an EntitySet lets you ‘reissue the query’ in a way whenever you call applyChanges(). It’s just doing it in a more efficient way than reissuing the query would be.

1 Like


I guess I have to figure out how to reset the entitydata when creating a new game. It seems to get reused all the time.

@asser.fahrenholz said: Thanks.

I guess I have to figure out how to reset the entitydata when creating a new game. It seems to get reused all the time.

You don’t necessarily have to set a new EntityData… you can also just remove your entities when you are done with them. EntityData is like a database… it contains whatever you put into it. You don’t necessarily need to create a new database all the time… just remove the data already in it. After all, there are often some bits of data that you will need to keep from one run to the next.

Without knowing more about your game, it’s hard to comment on specifics… but If the game ends have your object spawner remove the objects it spawned, the AI system remove the mobs, etc… Stuff like that. Like so many other resources, make sure your game cleans up after itself at the entity level. The systems will follow.

Edit: it’s possible that Asteroid Panic is an example of this since when you die early it has to reset the asteroids and stuff.

Alternately, if you really want to “go nuclear” on your entity data… and you’ve followed the architecture I use. You could just detach the old states and attach new ones, including a new EntityState. They’ll all grab the new EntityState to get their EntityData.

It seems heavy-handed but it is guaranteed to give you a fresh new playing field. :slight_smile:

I’ll try getting around the clean up after myself. Seems more appropriate and should ensure better knowledge of how it works.

Thanks again. You are a true inspiration.