denniskaselow / dartemis

A Dart port of the Artemis Entity System Framework
BSD 2-Clause "Simplified" License
49 stars 6 forks source link

Add customizable properties to World #48

Closed xaguzman closed 9 years ago

xaguzman commented 9 years ago

In the java version, it's very annoying when you want to put some aditional stuff right into your world so all the systems have access to it.

Let's say for example that I want to have tweens available in all of my systems, if we were using the universal tween engine (shameless self promotion), we would need to extend world to add a TweenManager property to it:

class TweenableWorld extends World{
  TweenManager tManager = new TweenManager();

  TweenableWorld(): super();
}

class System extends EntityProcessingSystem{
 ///...lots of code

  process(e){
    world.tManager.update(world.delta);
  }
}

I think it would be nice to have some kind of built-in functionality so it could be called in the form of:

class System extends EntityProcessingSystem{
  process(e){
    // maybe get it by type? kind of limited
    world.customProperties[TweenManager].update(world.delta);

    // magicStrings?
    world.customProperties['tManager'].update(world.delta);
  }
}

Just so that there's no absolute need to do this by hand. It will, surely, not be enough for all cases, but I see quite some cases where this might be useful.

It might not seem as a huge gain, and it might actually not be, but I think nice-to-have functionalities are always very welcome

denniskaselow commented 9 years ago

The way I've used TweenManager so far was as a global variable and a simple system like this:

class TweeningSystem extends VoidEntitySystem {

  @override
  void processSystem() {
    tweenManager.update(world.delta);
  }
}

https://github.com/denniskaselow/gamedev_helpers/blob/master/lib/src/shared/dartemis/systems/tweening.dart

But your idea isn't bad because with the way I'm doing it I'm polluting the global namespace which isn't that good (and I'm doing it with some other things like a GameState too).

I'll consider your suggestion for the next version..

denniskaselow commented 9 years ago

Properties can now be accessed like this:

class System extends EntityProcessingSystem{
  process(e) {
    // direct
    world['tManager'].update(world.delta);

    // or via properties (if you need to do use some other map methods)
    world.properties['tManager'].update(world.delta);
  }
}
xaguzman commented 9 years ago

great! thanks! :)


Xavier Guzman

http://blog.xavierguzman.com http:////plus.google.com/u/0/113140404022814604923? http://mx.linkedin.com/in/xavierguz/ https://twitter.com/arkalain

Blog http://blog.xavierguzman.com | G+ http:////plus.google.com/u/0/113140404022814604923? | LinkedIn http://mx.linkedin.com/in/xavierguz/ | Twitter https://twitter.com/arkalain

On Sat, Mar 28, 2015 at 2:42 AM, Dennis Kaselow notifications@github.com wrote:

Properties can now be accessed like this:

class System extends EntityProcessingSystem{ process(e) { // direct world['tManager'].update(world.delta);

// or via properties (if you need to do use some other map methods)
world.properties['tManager'].update(world.delta);

} }

— Reply to this email directly or view it on GitHub https://github.com/denniskaselow/dartemis/issues/48#issuecomment-87191895 .