Slick Forums
http://slick.ninjacave.com/forum/

Bug with adding entities to world?
http://slick.ninjacave.com/forum/viewtopic.php?f=28&t=6752
Page 1 of 1

Author:  Eliwood [ Mon Oct 21, 2013 2:55 am ]
Post subject:  Bug with adding entities to world?

I have a method that creates an entity and returns it, similar to the ones for the demos. However, when I try to add it to the world, it doesn't appear. After checking using println that it was actually being created, I came up with this:

1 entities created, 0 entities added, 0 active entities.

Huh-what? Can someone explain what I'm doing wrong? I very specifically make sure to add the entity to the world. So why's it not being added? The world's been instantiated and initialized with all of its systems - why, then doesn't it accept entities?

Author:  junkdog [ Mon Oct 21, 2013 3:36 pm ]
Post subject:  Re: Bug with adding entities to world?

It should work, have you called World#process after adding the entity? New entities are only reported to EntitySystems at the beginning of each processing round.

Author:  bagpipes100 [ Thu Jan 09, 2014 11:24 pm ]
Post subject:  Re: Bug with adding entities to world?

I'm experiencing the same issue, I think.

Code:
public void render(float delta) {
      // TODO Auto-generated method stub
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      world.setDelta(delta);
      
      if(world.getEntity(1)==null)
      {System.out.println("only one entity");}
      else{System.out.println("more than one entity");}
         
      world.process();
      game.renderSystem.process();
      game.movementSystem.process();
      game.camera.update();
   }


Here is what is in my render method. I got a test in the middle there, which, when I add another entity, the test flaggs it as there being more than one entity, but it doesn't get processed.

Author:  junkdog [ Fri Jan 10, 2014 2:12 pm ]
Post subject:  Re: Bug with adding entities to world?

Hard to say without looking at your code, but if you call #getActives on the EntitySystems (or something similar, don't have the code in front of me atm), how many entities are in each system's bag?

Author:  bagpipes100 [ Sat Jan 11, 2014 10:06 pm ]
Post subject:  Re: Bug with adding entities to world?

I like that, I didn't know what #getActivities did before. :)

Anywho, I put this code in

Code:
if(world.getEntity(1)==null)
      {System.out.println("only one entity");}
      else{System.out.println("more than one entity");}
      
      System.out.println("Render System has "+game.renderSystem.getActives().size()+" activities");
      System.out.println("Movement System has "+game.movementSystem.getActives().size()+" activities");
      
      world.process();
      game.renderSystem.process();
      game.movementSystem.process();
      game.camera.update();


and got this for an output.

more than one entity
Render System has 1 activities
Movement System has 1 activities

Does artemis act funny if you start adding things in from other threads? I this game has two devices connected to each other, (the one as a controller) when a packet is sent to the one acting like a screen it tries to add the entity to the world in the server thread.

Author:  junkdog [ Sun Jan 12, 2014 1:13 pm ]
Post subject:  Re: Bug with adding entities to world?

Hmm... a few things come to mind:

- Are systems passive, ie, added with world.setSystem(new RenderSystem(), true)? If not, you shouldn't call #process on systems as it's done for you by world.process().
- Have you called world.process() after adding the 2nd entity?

As for multi-threading: artemis itself is single-threaded, so the thread running artemis should do all artemis-related stuff.

Author:  bagpipes100 [ Sun Jan 12, 2014 9:16 pm ]
Post subject:  Re: Bug with adding entities to world?

Yes they are passive in the sense you wrote junkdog. Though I've tried commenting out the lines calling them to process, and then I don't get anything rendered. Also, world.process() is called after the second entity is called.

So how are separate threads normally handled with Artemis? Any good links for that kind of thing?

Author:  apotapov [ Mon Jan 13, 2014 7:40 pm ]
Post subject:  Re: Bug with adding entities to world?

As I understand, Artemis is not thread safe. I would be careful with multithreaded code in game development. OpenGL is inherently not thread safe, for instance.

Can you post a unit test that reproduces the issue. There a should be a simple one that does. It would be easier to help debug.

Author:  junkdog [ Mon Jan 13, 2014 7:49 pm ]
Post subject:  Re: Bug with adding entities to world?

What apotapov said ;) If you utilize multiple threads, you should "post" stuff to your main/artemis thread - and/or encapsulate the threads inside systems. About to leave the office, but I'll see if I can dig up some multi-threaded code tomorrow, know I have some defunct code lying around in some repository or other. Not sure to what extent it would overlap your design though.

If libgdx is part of the mix, check out AtomicQueue - http://libgdx.badlogicgames.com/nightli ... Queue.html

@apotapov - been meaning to check your recent release - plan on exploring it during the weekend.

Author:  bagpipes100 [ Tue Jan 14, 2014 6:51 pm ]
Post subject:  Re: Bug with adding entities to world?

I'm using three main libraries besides the standard java stuff. Artemis, LibGdx, and Kryonet. I have been trying to add the new entities in the world from the Kryonet Server I have running in the app. Should I instead have it bounce it to a client? I only have one client that needs to know about the entities, as only one gets used as a screen and the rest as controllers.

Author:  bagpipes100 [ Tue Jan 14, 2014 6:53 pm ]
Post subject:  Re: Bug with adding entities to world?

Do you have an example of the use of AtomicQueue?

Author:  junkdog [ Thu Jan 16, 2014 12:06 pm ]
Post subject:  Re: Bug with adding entities to world?

From an old log visualization project: https://gist.github.com/junkdog/8453832

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/