bsimser / artemis-framework

Artemis is a high performance Entity System framework for games.
MIT License
2 stars 0 forks source link

Ordered Bag Implementation? #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
TL;DR: I want an OrderedBag implementation so that I only have to call 
glUseProgram once per OpenGL ES 2.0 shader.

Hi Artemis devs. I really like the library and it seems very nice so far. I was 
just integrating it with a libgdx game I am making and I was trying to make a 
RenderSystem for objects that use OpenGL ES 2.0. As you may know, it is more 
efficient if you do not repetitively use the glUseProgram method. It is much 
nicer to call glUseProgram once per shader and render everything that uses that 
shader in one hit. Therefore I was wondering if we could possibly add in an 
OrderedBag implementation to Artemis. It may be a little bit slower but it 
would guarantee that I could get speed improvements while the program was 
actually running and when everything was finally in the bag. 

Original issue reported on code.google.com by robertma...@gmail.com on 12 Aug 2012 at 4:22

GoogleCodeExporter commented 8 years ago
The Bag is used in Artemis to ensure high performance, but it does not have 
objects ordered by the insertion order.

The EntitySystem has two methods, inserted() and removed(), which you can 
override, and there you can put the entities into an ordered collection like 
ArrayList inside your system. A bit of a duplication, but solves the issue.

I do this here:
http://code.google.com/p/spaceship-warrior/source/browse/src/com/gamadu/spaceshi
pwarrior/systems/SpriteRenderSystem.java

I'm looking into how to add ordered support into Artemis without sacrificing 
performance. Not sure when I'll add it.

Original comment by arniar...@gmail.com on 2 Sep 2012 at 2:56

GoogleCodeExporter commented 8 years ago
Why not order only systems, and only to some level?

From API point of view, for my needs something like

world.setSystem(..., false, order (int with default 0))

would be enough - and then for certain "order" value, the order of calls does 
not matter, but one could place some systems (especially render ones) on higher 
levels. About implementation, I'm wasn't thinking about it yet (Array of 
Bag<EntitySystem> maybe? no idea), but I believe, that:

1) it is enough to solve most cases when we would want ordered processing - 
including original issue (UseShaderProgramSystem updated before any other 
rendering related systems), although it wouldn't solve everything (cases when 
one needs ordered entities, like in SpriteRenderSystem example posted)
2) it does not break compatibility with current code (in old code all would be 
in same "order" at level 0 (default), so it would be same behaviour - at the 
price of maybe single check per world.process to access element of Array (or 
something else) containing Bag with EntitySystems)
3) seems to be potentially faster than fully ordered approach
4) requires least work to solve the issue

what do you think?

Original comment by ggi...@gmail.com on 1 Jan 2013 at 10:10