CategoryOpen Source

Promises in Haxe Composure

After learning recently that Lubos Lenco was using my Composure library as the foundation of his impressive ZBlend game framework, I decided to add a few more really helpful features.

Promises

Sometimes when using @inject to inject multiple properties, it’s helpful to know when all of the properties have been injected. This can be done by adding the @promise metadata to a method with a list of the properties that should be watched for. The method will be called immediately after all properties get set.

Notice that it is possible to use non-injected variables in your promises (‘active’ in the below example). At compile-time these variables will be wrapped in getter/setters to facilitate the watching process (or the setter will be amended if it already has one).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    class MainPlayer extends AbstractTrait{

        public var active:Bool;

        @inject({asc:true})
        private var gamepad:IInputDevice;

        @inject
        private var controller:CharacterMotionControl;

        public function new(){
            super();
        }

        @promise("active", "gamepad", "controller")
        public function onPromiseMet(met:Bool):Void{
            if(met){
                trace("Both traits have been added and are ready to bind together");
                controller.setInput(gamepad);
            }else{
                trace("One of the traits is about to be removed, unbind them now");
                controller.setInput(null);
            }
        }
    }

How promises behave

  • The first call to your bound method will be called as soon as all applicable variables have been injected, the met parameter will always be true on the first call.
  • If any of the properties get set to another value, then the method will be called twice, once before the property is committed with met=false, then again after the value has been set with met=true. This will really only happen when promises are pointing to non-injected properties (which are set outside of the composure framework).
  • If any of the applicable traits are removed (i.e. the property is set to null) then the method will be called again with met=false

Future features

There are a few other ideas floating around for more features and improvements, which I’ll have a look at when I get a chance:

  • Compile-time binding for certain pre-established objects. This will make things much faster and lighter when generating lots of the same type of game objects (a bunch of enemies, for example).
  • A light and simple event system for communicating events between the traits of a ComposeItem. This would also come with metadata support.
  • A simpler, lighter version of the @inject metadata that trades some flexibility for performance.

SVG Animation Exporter v3.0

SVG is a great graphic format, it scales perfectly for different screen pixel densities, so that it looks crystal clear on all devices.
Being a vector format it’s also typically smaller than raster based formats (i.e. JPEG, GIF, etc)
It’s only drawback is that it consumes resources to be rendered, but this has been almost entirely mitigated in recent years by all browser vendors optimising their rendering software.
It also has the power to include animations within a single file, through the underutilised SMIL standard. These animations are also very clean and light.
Unfortunately there is little in the way of generating these animations, this is why I have been working on this export panel for flash for some time now.

Continue reading

Export Flash to Animated SVG

While working on a project which required rich vector animations in the browser, I came across Dave Belias’ library for exporting still SVG frames from flash. I wondered if I could re-purpose it to export Animated SVGs, a relatively unknown standard for containing fully animated imagery within a single SVG file.
Continue reading

© 2017 Thomas Byrne

Theme by Anders NorenUp ↑