Note: for some reason today my grammar sucks more than usual. Live with it.
Today i decided to rewrite the RayFaster 1 export plugin for Mapas. The reason was mostly that i lost the source to the previous plugin and i wanted to make some modifications to Rombo. Since i also released the source of RayFaster 1 (Rombo's engine) and the engine is redesigned to be reusable, i thought that it would be a nice idea to make the new exporter be a little more user friendly. One aspect of this was to make it run the game from within the editor.
Now, Rombo is a Flash game so it has to be executed using Adobe's Flash Player. There is a standalone version for that and thankfully it registers itself in Mac OS X as the right program to open swf files. So from command line all you have to do is type "open foo.swf" to open the swf file.
Rombo uses RayFaster 1, which as i mentioned above is (now) designed to be reusable. There is no game-specific code in it. To use the engine, a game has to include a Python script which provides a Builder class and configure a Builder object. The class does some dirty work (combines the RayFaster 1 code with the game code and uses m4 to preprocess the sources, generates swfmill XML files for resources, generates dummy class files for importing the resources from haXe and other stuff). The idea was to make a building system in a more flexible manner than what is available from stock haXe and automate some processes.
With the addition of the launch command in the editor, the code was modified a bit so that the game can be compiled in a way that starts from the currently active map in the editor. To do this, the plugin provides a dialog where the user can configure a command to be executed when the F5 key is pressed (or the RayFaster -> Launch menu item is selected). Unfortunately i couldn't find a nice way to make the editor properly change to the game's directory and run it from here, so i wrote a "launcher" Python script which does the job.
So what happens when i press F5 to play-test the current map is:
- The map project is exported to a single file named mapdata.bin which is used as a resource for the engine.
- The plugin executes the launcher script mapasrun.py with the argument -start %MAP% where %MAP% is the index of the active map.
- The launcher script changes the current directory to the directory where the game is located and executes the run.py script.
- The run.py script executes the build.py script.
- The build.py script includes the RayFaster1Builder script which implements the Builder class. It creates a builder object which is configured with the path of the engine's source, the target build path, output file and the game-specific resources needed. Also it specifies optional M4 macros. In this case, it defines the FIRST_MAP_VALUE to the editor's active map index.
- The build() function is called which collects all source files (passing them via the m4 preprocessor), all resources, generates swfmill XML files, dummy classes and other helper stuff and finally uses the swfmill tool to generate the swf library and the haxe compiler to compile and link the final swf file.
- The build.py script calls my SOB SWF Obfuscator to obfuscate the swf file (in a copy outside the build directory). This is a swf file ready to be published (although i never publish this file directly but via mochiads to add a preloader).
- Finally the run.py gains control and uses open to run the swf file in the Flash Player.
However i plan to make a new Rombo game using RayFaster 1, so the new one will have better levels.
Now i have to go back and finish the game update :-)

0 comments:
Post a Comment