Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 2:50 pm

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 420 posts ]  Go to page Previous  1 ... 18, 19, 20, 21, 22, 23, 24 ... 28  Next
Author Message
 Post subject:
PostPosted: Fri Sep 23, 2011 4:22 pm 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
Exposing the typeFlags of Systems to know its components and its active entities could solve this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2011 4:39 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
No, I was talking about different entities in my case, inside a System named SpriteUpdateSystem, for each entity, I convert values from one Component to another Component to be ready for be rendered later. Again, in this particular case, I can process all those entities in parallel in that specific system.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2011 6:24 pm 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
Ah got it, you are totally right on this!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2011 4:00 pm 
Offline

Joined: Fri May 20, 2011 6:08 pm
Posts: 27
Added multithreading support on the C# port:

https://github.com/thelinuxlich/artemis_CSharp


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2011 7:52 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
thelinuxlich wrote:
Added multithreading support on the C# port:

https://github.com/thelinuxlich/artemis_CSharp


Interesting, I knew it was quite easy to add, but my main concerns were about the data in components being available to multiple systems. So either you need some strict rules regarding that or make components thread safe as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 5:27 am 
Offline

Joined: Sun Sep 18, 2011 5:40 pm
Posts: 13
Ran into a crash today:

Code:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 16
   at com.artemis.utils.Bag.get(Bag.java:140)
   at com.artemis.EntityManager.getComponent(EntityManager.java:117)
   at com.artemis.Entity.getComponent(Entity.java:129)
   at com.artemis.Entity.getComponent(Entity.java:140)
   at com.gemserk.commons.artemis.components.Components.getTextComponent(Components.java:56)
...


I noticed this in Bag.java:

Code:
   /**
    * Constructs an empty Bag with an initial capacity of 64.
    *
    */
   public Bag() {
      this(16);
   }


Should that be this(64) instead of this(16)? I might have just added my 17th component type. It's hard to know for sure since I'm using arielsan's library and that has some component types of its own.

Although, with that said, the Bag is supposed to grow if something gets added to it, so that's not the bug. I think what happened is, I have a system that's looking for a component type that hasn't been used by any entities (yet), so the component type doesn't exist. So it never went through EntityManager.addComponent, which means it never got added to componentsByType. But when the system tried to look up this component, it ended up in EntityManager.getComponent, which crashed because I now have > 16 component types.

Maybe the answer here is "Don't do this", in which case, please let me know. My simple-minded fix would be to protect Bag.get as follows:

Code:
   public E get(int index) {
      if (index >= data.length)
         return null;
      
      return (E) data[index];
   }


This would return null for the component lookup, which is the behavior I want in this situation.

Thanks,
Ziggy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 1:13 pm 
Offline
Regular
User avatar

Joined: Tue Apr 07, 2009 12:58 pm
Posts: 232
Location: Uruguay
I believe it is the same bug we already posted in this thread before.

There is also a patch available with a fix (already tested), in case it is the same bug.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 3:58 pm 
Offline

Joined: Sun Sep 18, 2011 5:40 pm
Posts: 13
Yep, same bug. Your patch would work as well. I'll switch to that, since it may end up in the artemis svn at some point.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2011 8:04 am 
Offline

Joined: Wed Nov 09, 2011 8:00 am
Posts: 2
Don't wanna necro the thread, but I registered because I have a question concerning Artemis.

I created an SoundSystem (and a Sound components) and I can make it play sounds however I want (for conveniance, I also created a createSound() method in my utility factory). However, I have a problem when trying to use SoundRenderSystem based on Tankz code.


Code:
private Graphics graphics;
   private ComponentMapper<SoundFile> soundMapper;

   @SuppressWarnings("unchecked")
   public SoundRenderSystem(GameContainer container)
   {
      super(SoundFile.class);
      this.graphics = container.getGraphics();
   }

   @Override
   public void initialize()
   {
      soundMapper = new ComponentMapper<SoundFile>(SoundFile.class, world);
   }

   @Override
   protected void process(Entity e)
   {
      SoundFile sound = soundMapper.get(e);
      graphics.drawString("Now playing : " + sound.getSoundFile(), 50, 50);
   }   


So this is basically what I have in my SoundRenderSystem. Pretty basic, I just want to draw a string on the screen displaying the name of the song. In the Game.java file I have , in the render method :

Code:
soundRenderSystem.process();


The problem is the following : I enter render every single frame (duh) in the Game.java method, but it enter the process method of the soundRenderSystem only once, so it display the name of the song for exactly 1 frame, then never display it again...

What am I doing wrong? Great framework so far though, I'm loving it :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2011 1:08 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
hawke wrote:
Don't wanna necro the thread, but I registered because I have a question concerning Artemis.

I created an SoundSystem (and a Sound components) and I can make it play sounds however I want (for conveniance, I also created a createSound() method in my utility factory). However, I have a problem when trying to use SoundRenderSystem based on Tankz code.


Code:
private Graphics graphics;
   private ComponentMapper<SoundFile> soundMapper;

   @SuppressWarnings("unchecked")
   public SoundRenderSystem(GameContainer container)
   {
      super(SoundFile.class);
      this.graphics = container.getGraphics();
   }

   @Override
   public void initialize()
   {
      soundMapper = new ComponentMapper<SoundFile>(SoundFile.class, world);
   }

   @Override
   protected void process(Entity e)
   {
      SoundFile sound = soundMapper.get(e);
      graphics.drawString("Now playing : " + sound.getSoundFile(), 50, 50);
   }   


So this is basically what I have in my SoundRenderSystem. Pretty basic, I just want to draw a string on the screen displaying the name of the song. In the Game.java file I have , in the render method :

Code:
soundRenderSystem.process();


The problem is the following : I enter render every single frame (duh) in the Game.java method, but it enter the process method of the soundRenderSystem only once, so it display the name of the song for exactly 1 frame, then never display it again...

What am I doing wrong? Great framework so far though, I'm loving it :)


Are you removing the SoundFile from the entity somewhere?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2011 3:49 pm 
Offline

Joined: Wed Nov 09, 2011 8:00 am
Posts: 2
Hmmmm...

If I'm putting breakpoint to debug in the render() method, I only get there once. In the soundFile process() method though, I'm having entity.remove(e) (or whatever the code is to remove the entity from the world), but since the music was continuing playing, I didn't make a big deal out of it. Is it possible that it removed itself from the loop so when I call the SoundRenderSystem.process() in the render() method, the sound isn't registered in the world anymore so it does not render ?

If so, how come it doesn't throw a NPE, or how come the sounds continue playing ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2011 4:37 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
hawke wrote:
Hmmmm...

If I'm putting breakpoint to debug in the render() method, I only get there once. In the soundFile process() method though, I'm having entity.remove(e) (or whatever the code is to remove the entity from the world), but since the music was continuing playing, I didn't make a big deal out of it. Is it possible that it removed itself from the loop so when I call the SoundRenderSystem.process() in the render() method, the sound isn't registered in the world anymore so it does not render ?

If so, how come it doesn't throw a NPE, or how come the sounds continue playing ?

It is, I think, enough just to do "sound.play" and instantly remove the entity, yet the sound will continue to play, because that's a different library that takes care of that.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2011 4:49 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
hrm, demo webstart is broke.

Question about this entity system. Can you dynamically save/load entities to/from disk?

I would imagine that any game would probably want different entities on different levels, how is that managed?

In the example you create a 'World'; so I assume you also treat levels/maps inside that world as Entities also?


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Nov 25, 2011 8:09 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
dime wrote:
hrm, demo webstart is broke.

Question about this entity system. Can you dynamically save/load entities to/from disk?

I would imagine that any game would probably want different entities on different levels, how is that managed?

In the example you create a 'World'; so I assume you also treat levels/maps inside that world as Entities also?

Sorry, been absent.

I guess there are many ways to load some gameobject(s) into a game, that's not anything specific or special to artemis, and yes, you can do that in artemis (there's nothing that forbids it, but you have to code it yourself.)

Each level can be treated as a different world, so when you level up, you really load in a new world which has a collection of entities in it.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Nov 25, 2011 9:20 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
arielsan wrote:
I added an array length check before returning the component on getComponent(e, type) to avoid the exception, here is the patch:

Code:
--- a/src/com/artemis/EntityManager.java
+++ b/src/com/artemis/EntityManager.java
@@ -114,7 +114,13 @@ public class EntityManager {
   }
   
   protected Component getComponent(Entity e, ComponentType type) {
-      Bag<Component> bag = componentsByType.get(type.getId());
+      int componentTypeId = type.getId();
+
+      // if asking for a component type never added before, then return null directly
+      if (componentTypeId >= componentsByType.getCapacity())
+         return null;
+      
+      Bag<Component> bag = componentsByType.get(componentTypeId);
      if(bag != null && e.getId() < bag.getCapacity())
         return bag.get(e.getId());
      return null;


Hope you could see it and apply it.


I fixed the problem, but didn't apply that patch because it affects all getComponent retrievals. I just ensured that whenever a new component type is created the entitymanager is notified and ensures componentsByType can handle retrieval of it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 420 posts ]  Go to page Previous  1 ... 18, 19, 20, 21, 22, 23, 24 ... 28  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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:  
Powered by phpBB® Forum Software © phpBB Group