Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by lucascaro

Hi all! This is my first post; I've recently bought impactjs and I'm a very satisfied customer :D so my congratulations to dominic for the great engine.

I've used impact for one project so far and was wondering if there are any plans in the roadmap to improve the Entity lifecycle, to make it more flexible, like this article:
The Life Cycle and Processing Architecture

Correct me if I'm wrong, but as I understand, the entitie's life cycle now is
init -> update / draw -> kill

What this article proposes is something like:
Construction -> Init -> Resolve -> Update / Draw -> Deinit -> Destruction.

I particularly would love to separate construction from initialization and / or have a way to initialize my entities after all of the entities are created (so I don't need to get a pointer to the player on update, for example).

Well this is just a thought, and maybe there is already a way to do this, which I don't know.

So far, I'm doing something like
update: function() {
  if(!this.initialized) {
    this.initialize();
    this.initialized = true;
  }
}

But I think this adds unnecessary overhead to the update function for a call that I need to do just once.

I don't know how the rest of you feel about this, but I'd like to know your opinion on this matter.

Thanks!

1 decade ago by gxxaxx

Hello lucascaro,

I can't speak to the life cycle issues. Don't know enough about software architecture to predict the pluses and minuses.

I can say that I have found myself in the position of needing to implement a postinit type function.

In main.js, I overwrote the loadlevel method.

	loadLevel: function(data) {
		this.parent(data);
		// do config postinit first
 		for( var i = 0; i < this.entities.length; i++ ) {
			var ent = this.entities[i];
			if( ent._killed || typeof(ent.postInit) != 'function') {
				continue;
			}
			ent.postInit();
		}
	}

This lets me put code in my entity's postinit that should only be run after all entities have been created.

The above is a cut down version of what I'm doing, but it gives an idea I hope. It isn't really that different than catching a postinit in the update method of an entity. But it helps me sort my head and code out. Of course, YMMV :)

[Edit: Just realized that I haven't actually addressed the more general question of changing the lifecycle.]

1 decade ago by lucascaro

thanks for the answer! I think that's way better than what I'm doing in the update method because it's executed once when loading the level vs. adding an if that gets tested on every frame, so +1 performance to this method!

I realize now that there might be an elegant way of modifying the lifecycle of entities using plugins, I just don't know how... yet ;)

thanks for sharing this idea, which I'm going to start using right away!
Page 1 of 1
« first « previous next › last »