Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 3:15 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Delay systems
PostPosted: Sun Sep 02, 2012 8:11 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
I've been thinking about these Delay systems, DelayedEntitySystem and DelayedEntityProcessingSystem. They're a hassle to use. Extending them gives you no idea how they work. How you would tell the system to start a delayed run, when to do it, etc. You ended up having to do a lot of code just to make it work like it's supposed to.

I've changed it so there is only one system now, DelayedEntityProcessingSystem (deleted the other).

Now it should be simpler to use it. Here's an example usage of adding support to delete entities after a certain expiration time:
Code:
public class ExpiringSystem extends DelayedEntityProcessingSystem {
   @Mapper
   ComponentMapper<Expires> em;

   public ExpiringSystem() {
      super(Aspect.getAspectForAll(Expires.class));
   }
   
   @Override
   protected void processDelta(Entity e, float accumulatedDelta) {
      Expires expires = em.get(e);
      expires.delay -= accumulatedDelta;
   }
   
   @Override
   protected void processExpired(Entity e) {
      e.deleteFromWorld();
   }
   
   @Override
   protected float getRemainingDelay(Entity e) {
      Expires expires = em.get(e);
      return expires.delay;
   }
}


The system only runs when some entity needs to be processed, but does not run every loop.
It automatically picks up on inserted entities, so no need to worry about them.

You need to override three methods:
In processDelta you must subtract the accumulatedDelta from all the entities "delay".
getRemainingDelay should return how much "delay" remains of the entity after the processDelta.
processExpired is called on all entities who's delay has expired.


I haven't pushed in the changes because I wonder if anyone actually used the other systems who think this change is in the wrong direction. This change is quite dramatic, but I think gives it a more useful purpose.


Top
 Profile  
 
 Post subject: Re: Delay systems
PostPosted: Sun Sep 02, 2012 8:37 pm 
Offline

Joined: Sun Aug 05, 2012 3:37 pm
Posts: 23
Wow! This is extremely well-timed! Just today I started working on an implementation derived from the DelayedEntityProcessingSystem found in the example Gamadu-Tankz project. However, I ran into a snag -- the system would terminate certain entities well before their expiration time was up. The problem stems from the fact that if you have an expiration type component, you are only dealing with delta with no idea where along the game timeline the object was defined. For example, if I have a 500ms expiration timeout for all my entities, and generate one at t=0, and then another one that gets inserted at t=495, the DelayedEntityProcessingSystem would apply the same accumulated delta time (500ms) to both in the process method. The net result was that the first entity would expire normally and the second one would expire after being alive for only 5ms.

Based on your description, your new system would fix that.

FWIW, my workaround under the current system has been to simply make the elapsed timing interval 10x faster than the max interval. In this way, if things get terminated earlier, it's not really noticeable. Still, I'm doing more processing than I needed to do which kind of defeats the purpose of using the DelayedEntityProcessingSystem as it is currently written.

So, you certainly have my vote to commit your proposed changes! :)


Top
 Profile  
 
 Post subject: Re: Delay systems
PostPosted: Mon Sep 03, 2012 1:56 pm 
Offline

Joined: Fri Jul 13, 2012 9:59 pm
Posts: 25
In my opinion, you could maintain the parent's class of this entity system, or transform all processAllEntities methods into non-final. In some cases, specific behaviours are needed, and if the methods are final, there's nothing much that can be done. If a user chooses to override those methods, you can be sure that they know what they are doing.


Top
 Profile  
 
 Post subject: Re: Delay systems
PostPosted: Mon Sep 03, 2012 4:07 pm 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
Shirkit wrote:
In my opinion, you could maintain the parent's class of this entity system, or transform all processAllEntities methods into non-final. In some cases, specific behaviours are needed, and if the methods are final, there's nothing much that can be done. If a user chooses to override those methods, you can be sure that they know what they are doing.


There is begin() and end() in which processEntities takes place in between.
There's also now a getActives() method which returns all the entities in the system. So if you need to do some checking on the entities you could do it there.


Top
 Profile  
 
 Post subject: Re: Delay systems
PostPosted: Wed Sep 05, 2012 12:04 am 
Offline
Game Developer
User avatar

Joined: Tue Nov 21, 2006 4:46 am
Posts: 619
Location: Iceland
The new Delay system is flawed. I'm going back to the drawing board. It's not an essential system, and rarely used anyway, but still kinda bad :oops:


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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