Slick Forums

Discuss the Slick 2D Library
It is currently Thu Nov 14, 2019 6:30 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Mon Oct 21, 2013 2:55 am 
Offline

Joined: Mon Jul 01, 2013 7:44 pm
Posts: 4
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?


Top
 Profile  
 
PostPosted: Mon Oct 21, 2013 3:36 pm 
Offline

Joined: Sun Jun 03, 2012 9:21 pm
Posts: 49
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.

_________________
agrotera: bytecode-weaving antiboilerplate lib for artemis. | artemis-odb: bugfixing and performance optimized fork.


Top
 Profile  
 
PostPosted: Thu Jan 09, 2014 11:24 pm 
Offline

Joined: Thu Oct 25, 2012 5:29 pm
Posts: 31
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.


Top
 Profile  
 
PostPosted: Fri Jan 10, 2014 2:12 pm 
Offline

Joined: Sun Jun 03, 2012 9:21 pm
Posts: 49
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?

_________________
agrotera: bytecode-weaving antiboilerplate lib for artemis. | artemis-odb: bugfixing and performance optimized fork.


Top
 Profile  
 
PostPosted: Sat Jan 11, 2014 10:06 pm 
Offline

Joined: Thu Oct 25, 2012 5:29 pm
Posts: 31
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.


Top
 Profile  
 
PostPosted: Sun Jan 12, 2014 1:13 pm 
Offline

Joined: Sun Jun 03, 2012 9:21 pm
Posts: 49
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.

_________________
agrotera: bytecode-weaving antiboilerplate lib for artemis. | artemis-odb: bugfixing and performance optimized fork.


Top
 Profile  
 
PostPosted: Sun Jan 12, 2014 9:16 pm 
Offline

Joined: Thu Oct 25, 2012 5:29 pm
Posts: 31
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?


Top
 Profile  
 
PostPosted: Mon Jan 13, 2014 7:40 pm 
Offline

Joined: Mon Sep 30, 2013 12:48 pm
Posts: 6
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.


Top
 Profile  
 
PostPosted: Mon Jan 13, 2014 7:49 pm 
Offline

Joined: Sun Jun 03, 2012 9:21 pm
Posts: 49
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.

_________________
agrotera: bytecode-weaving antiboilerplate lib for artemis. | artemis-odb: bugfixing and performance optimized fork.


Top
 Profile  
 
PostPosted: Tue Jan 14, 2014 6:51 pm 
Offline

Joined: Thu Oct 25, 2012 5:29 pm
Posts: 31
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.


Top
 Profile  
 
PostPosted: Tue Jan 14, 2014 6:53 pm 
Offline

Joined: Thu Oct 25, 2012 5:29 pm
Posts: 31
Do you have an example of the use of AtomicQueue?


Top
 Profile  
 
PostPosted: Thu Jan 16, 2014 12:06 pm 
Offline

Joined: Sun Jun 03, 2012 9:21 pm
Posts: 49
From an old log visualization project: https://gist.github.com/junkdog/8453832

_________________
agrotera: bytecode-weaving antiboilerplate lib for artemis. | artemis-odb: bugfixing and performance optimized fork.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group