Asset library and pure Haxe preloader tool

After KukkerMan's idea we have started a Haxe/neko project aiming to be able to assemble flash9+ resource libraries. The tool will be easily compilable on both Linux and Windows (and supposedly Mac?) as it is written for the nekovm target with as minimal external library dependencies as possible.

People will also be able to extend it via plugins to support importing their favourite formats into the library swf. So far we use it with success for importing png, jpg, alpha-masked jpeg images, binary data and mp3 sound into the asset library. As it turned out, the since far sought pure Haxe-based preloading is also possible via the tool. Read on for some insight!

(Edit: Don't forget to check out our latest article Preloading with Haxe and SamHaxe on the topic!)

KukkerMan does a nice work implementing the modular import system: The asset library is described with an xml file, something like swfmill's simple format. However, a separate configuration xml file describes which tags are handled by which import modules. For example, the image tag is currently handled by our default Image plugin, but you could easily change that in the configuration file. (By the way, KukkerMan had hard time trial-and-erroring how to use the poorly documented ImageMagick library, and is now considering to throw the whole code into trash and restart with a better library :)

About preloading with Haxe: I implemeted the Sound import module, currently with mp3 support and more to come. For that, the hxformat lib was extended with mp3 support (more to come of course). When testing the sound import, placing the DefineSound swf tag on the second frame of the asset lib made the flashplayer cry out loud. It had a SymbolClass exported. After experimenting, it turned out that flash requires (? correct me, I'm not an AVM2 insider) an AS3 class definition for resources with a SymbolClass.

But you can say: "Hey, I use an asset lib with Haxe and I don't write class definitions for my assets!" Well, that works because Haxe generates the class stubs for you if this is the case. "Ok, but then why did you get that error?" That happened because Haxe only generates these class stubs for resources on the first frame of the asset lib.

So basically if you can generate class stubs for those resources, you can put all your heavy assets on the first second frame, wait with Haxe code for the whole file to load (possibly displaying preloader gfx), and continue executing rest of the code once the whole file (or at least the required frames) are ready. How to generate class stubs?

  1. You can do that by hand, creating simple class definitions with a constructor calling super(), with Haxe. The stubs will be on frame 1, but they don't eat up much space.
  2. Or you can generate an AS3 code block along with the asset onto the frame it resides (frame 2 currently). I tried this and seems to work nice (not sure about generating a code block for frame1 would not collide with Haxe, I will have to research this later).
For generating the code blocks I use the hxformat abc library with minor modifications. The core is:
      // ctx is the format.abc.Context
      var cl = ctx.beginClass(_name, true); 
      cl.superclass = ctx.type("flash.media.Sound");
      ctx.endSubClass();
      ctx.finalize();
Here you may spot two differences from the standard lib. First, beginClass() has a second true parameter. With this I tell it to call the superclass constructor, resulting in the following code inside the method:
      ...
      beginFunction([],null);
      var cst = curFunction.f.type;
      curFunction.f.maxStack=1;
      if (callsuper) {    // this block was added
         op(OThis);
         op(OConstructSuper(0));
      }
      op(ORetVoid);
      endFunction();
      ...
Also, the endSubClass() method was added with the minor difference from endClass() that it registers the class name as inheriting from the proper superclass. This solution is not a general one, but is a good starting point for now.

As a bottom line, this tool would prove to be useful and is an interesting challenge, so I hope that we are able to have an initial release in some weeks time. In the meanwhile (or during the meanwhile, Brian? :) you can try to guess the name of the tool, you get three hints for this:

  1. Assets are not only important for flash developers, but also for whom?
  2. Let's hope that this friendly tool won't inform on you to the FBI ;)
  3. ???
Have fun coding!

Comments

Comment by Matus, on 09.07.16. 08:58
Cool news!!!

(btw isn’t there a typo? (first instead of second) you can put all your heavy assets on the first frame)

Comment by KukkerMan, on 09.07.22. 00:35
You’re absolutely right. It doesn’t make any sense to put heavy assets on the first frame and use a preloader anyway. :)
Typo corrected.

Comment by edA-qa mort-ora-y, () (URL) on 09.08.01. 18:34
Perhaps it might help you, the DHLIB has a Ruby script which reads a swfmill resource.xml file and produces the haXe definitions for all of the contained resources.

Comment by [ron], (URL) on 09.08.01. 23:51
Before we began writing this tool, we had a custom resource xml format, which we transformed into swfmill xml and haxe class definitions. Now the tool is able to generate proper as3 class definitions for resources into the asset lib itself. However what you suggest is a nice feature, and we may add support for it in an upcoming version (maybe not in 1.0, because KukkerMan is already bashing my head for incorporating too many stuff into the initial release – he doesn’t want the asset tool to be the second Duke Nukem Forever :)

Comment by edA-qa mort-ora-y, () (URL) on 09.08.02. 10:07
Alright, sounds reasonable. If you do need feel free to just take it from the DHLIB package on my site — it is just a simply Ruby script.

Let me know when you have a working first version and I can test it out — I have a project that needs it and have no interest installing the adobe tools.

Comment by [ron], () (URL) on 09.08.02. 13:09
We would like to based the tool with as few external dependencies as possible, so Ruby is no-go for now – but I’m sure that we will be able to manage writing out haxe class definitions ;)

Right now we are waiting for format.swf modifications to be reviewed and maybe merged, and adding the finishing touches in the meanwhile. I hope we can make a test release in one or two weeks.

Comment by Martin Quinson, (URL) on 09.08.12. 23:40
An Haxe asset handling solution is what I really need to get started with the toolset, so your work is more than welcomed.

However, I’m still unsure whether it will be a flash-only solution or whether it will be usable for the neko and cpp backends too. I was thinking of doing something similar to SuperPackMe in Haxe (transcoding the images to hexa strings at compilation time, embeeding the strings within the app and decoding them at run time).

What are your plans? Did I miss something obvious?

Comment by [KukkerMan], () on 09.08.13. 22:16
It’s a flash resource assembly tool so it’s output is an SWF file. It’s based on format.swf haXe library and runs on neko VM.

Comment by Martin Quinson, (URL) on 09.08.13. 22:31
I understood that your primary target was the flash backend of haxe, and that the tool itself was on the command line with neko. But I wanted to know whether your solution would be usable for the other backends too. Do you think it’ll be usable as is provided that ? Do you have any plans to increase the target backend? Any hints about how to do so if I find the time to help?

Comment by [KukkerMan], () on 09.08.15. 11:58
Ah I think I finally get it. :-) Well, we’re using neko mostly for file system access and loading neko primitives from .ndll files. It can easily be ported to cpp target for example. We’ll think about it.

Comment by [KukkerMan], () (URL) on 09.08.27. 19:45
SamHaXe (yes, that’s its name) is now available for testing. You can download it from here: http://mindless-labs.dyndns.org/trac/sam..

  
Remember personal info?

Emoticons / Textile

To prevent automated commentspam we require you to complete this silly task.
 

  (Register your username / Log in)

Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.

About

Flash game development using HaXe and pals.

Archives

01 Nov - 30 Nov 2009
01 Oct - 31 Oct 2009
01 Sep - 30 Sep 2009
01 Jul - 31 Jul 2009
01 May - 31 May 2009
01 Apr - 30 Apr 2009
01 Mar - 31 Mar 2009
01 Feb - 28 Feb 2009
01 Jan - 31 Jan 2009
01 Dec - 31 Dec 2008
01 Nov - 30 Nov 2008
01 Oct - 31 Oct 2008
01 Sep - 30 Sep 2008
01 Aug - 31 Aug 2008
01 Sep - 30 Sep 2007

Calendar

« March 2010
S M T W T F S
  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 26 27
28 29 30 31      

Linkdump

Game design document - §

If you are about to create a new game, be sure to read this nice article along with its predecessors.

09.11.24. 13:29 | comment!

VelociRapid game element preview - §

Click the banner to play a preview of prey fleeing, and also take a peek underneath to see the quadtree space partitioning (nodes do not collapse right now). WSAD to control the dino.

09.11.19. 23:18 | comment!

Gambit's response to recent virtual currency changes - §

An interesting read at the Gambit blog.

09.11.05. 10:19 | comment!

Dirty coding tricks of game developers - §

Read it at Gamasutra

09.11.03. 10:02 | comment!

Payment providers - §

Some alternative payment providers for running your own virtual curreny system:

09.07.13. 21:38 | comment!

ssh tunneling in linux - §

To forward the local port X to the local port Y of the remote machine:

ssh -L X:127.0.0.1:Y remote.machine -N

Usage example: Setup a local web proxy (like privoxy) on a remote university machine, and connect to it from home. This way you can access university resources with ease.

09.05.14. 10:28 | comment!

Free flag images - §

http://www.33ff.com/flags/index.htm

09.04.08. 11:52 | comment!

Render text with ImageMagick - §

convert -font font.ttf -background none -geometry +0+0 -fill \#ffffff -pointsize 18 label:"`cat txt`" -set label '' out.png

09.04.02. 15:16 | comment!

Online Latex equation editor - §

Online latex is

09.03.11. 09:02 | comment!

Create swc from a tree of as3 files - §

V1 (thanks to Jarrad Hope!) compc -output my_swc.swc -include-sources .

V2 (the old and hacky :) cd tree_top; compc -source-path . -output my_swc.swc -include-classes `find . -regex .*as | awk '{gsub(/\.\//, "", $0); gsub(/\.as/, "", $0); print $0}'`

09.03.06. 09:58 | two comments

Delete first line from file - §

sed -i '1d' file.txt

09.02.18. 12:28 | comment!

Gentoo: check security holes - §

glsa-check -p $(glsa-check -t all)

09.02.04. 11:30 | comment!

Execution speedup with fifo - §

Speed up the execution of programs that generate massive unwanted log-files by sending those logs to null through a fifo: mkfifo logfile
cat logfile > /dev/null &
./myprogram -log logfile

09.01.19. 14:09 | comment!

ImageMagick PNG background and auto-crop - §

Set background to white and auto-crop with ImageMagick: for i in `ls *png`; do convert -flatten $i x.png; convert -trim x.png out_$i; done

09.01.12. 17:15 | comment!

Linux: split file on pattern - §

awk '/PATTERN/{i++}{print > "file.pdb."i}' file, found here

08.12.15. 17:46 | comment!

Replace in multiple files on Linux - §

perl -pi -w -e 's/search/replace/g;' *.php
Found here.

08.12.10. 10:42 | comment!

XPath in Python - §

A nice summary about options for xpath with python here.

08.12.09. 18:41 | comment!

Christmas Icons - §

Free Chrismtas Icons!

08.12.08. 11:46 | comment!

PS print on WinXP - §

Print to PS on WinXP without any printers! Cool :)

08.12.04. 12:59 | comment!

Sorry, OpenOffice - §

OpenOffice is simply a no-go. Ill UI, missing features. Go for Latex or Crossover Office instead.

08.12.02. 14:31 | comment!

Last Referrers

Miscellany

Powered by Pivot - 1.40.7: 'Dreadwind' 
XML: RSS Feed 
XML: Atom Feed