New FFilmation demo

Edit: Firefox users please update to the latest player version (9.0.124.0 ) for a big performance increase.

I have been working on a new demo for the FFilmation engine. I thought that the best way to decide which features were most important was to simulate making a “game” and see what was I missing the most along the way.

The demo will be updated continuously with the new features so I can see how everything works together. Besides, more complex scenes push the engine and the processor to its limits, and makes it easier to find performance bottlenecks.

The demo can be accessed here. Please note that It uses heavy lighting and a big scene. Slowdowns are to be expected in older machines. Here is a list of the new features showcased.

Materials

Perlin Material

Perlin materials are procedural materials formed by a base material and unlimited layers of other materials, each one rendered from a perlin noise definition. The perlin noise for each layer is used as the alpha-mask for that layer. With perlin materials, you can create more natural-looking environments without extra effort.

In this case, a 2-layer perlin material is used as ground for the forest scene.

Door material

The door material is not a big deal, but It has made my life a lot easier. It works as an standard tile material, but it draws a door of given dimensions in the middle of it. You can specify a base material, a material for the door itself and a material for the frame. The doors in the demo are defined like this:

<materialDefinition name="MNIP_ForestMaterials_Door" type="door">

<!-- Base "tile" material for the wall -->
<base>FFMaterials_woods2_Wood2_13</base>
<!-- Frame material -->
<frame>FFMaterials_woods2_Wood2_11</frame>
<!-- Door material -->
<door>FFMaterials_woods2_Wood2_13</door>
<!-- Door position, as percent of wall size, from -100 to 100.
The default 0 value centers the door in the wall -->
<position>0</position>
<!-- Door size, without frame -->
<width>150</width>
<height>200</height>
<!-- Frame size -->
<framesize>15</framesize>

</materialDefinition>

A subtle dropShadow filter is used to give the frame a bit of thickness, making the result less flat and quite convincing.

Controllers

Both elements and scenes can be assigned a controller object. Controllers are an elegant and scalable way of adding behaviours to your applications.

A typical element controller can be one that reads mouse input and moves a character, or the AI for the enemies in you game. For scenes, the controllers can control daylight or program specific behaviours such as the train arriving to the station every X minutes.

Controllers have an enabling/disabling methods. Disabling an scene disables its controller and controllers of all elements in that scene. This is useful to pause you game, bring in an options screen, launch a cutscene, load another scene, etc etc

An piece of the controller for the forest:

public function assignScene(scene:fScene):void {
   this.scene = scene
   // Follow Poncho
   var p:fCharacter = this.scene.all["Poncho"]
   this.scene.createOmniLight(”light_poncho”,p.x-20,p.y-20,p.z+10,200,”#ddffdd”,50,00,true)
   this.scene.all["light_poncho"].follow(p)
   // Look for all Money Bags and add a light above each of them
   for(var i:Number=0;i<this.scene.objects.length;i++) {
     var obj:fObject = this.scene.objects[i]
     if(obj.definitionID==”MNIP_MoneyBag”) {
        this.scene.createOmniLight(”light_”+obj.id,obj.x,obj.y,obj.z+25,300,”#ffffff”,100,0,true)
        obj.addEventListener(fRenderableElement.HIDE,this.hideListener)
     }
  }
}
private function hideListener(evt:Event):void {
    // Delete corresponding light
    this.scene.removeOmniLight(this.scene.all["light_"+evt.target.id])
}

A light is created and attached to the main character. For each money bag in the scene another light is added on top of it. When the money bag dissapears, the light is removed.

I could program this behaviour in my main game class, but what if I only want it to happen in this scene ? Instead of ugly conditionals, I use an scene controller. The generic Money Bag retrieve event is in my main game class, because I want my character to pick up money bags in all scenes where they appear. But I only want the lights on top of them in this scene.

Generators

A generator is a class that given some data from an scene XML, returns extra xml elements that are added to that XML at load time. This allows to use procedural methods to generate more complex scenes effortlessly. The scene looks for generators in the XML and calls the appropiate class to retrieve the extra elements.

In the demo, I use a scatter generator. The scatter generator is used to randomly fill an area with objects. You specify the area to cover and a list of candidate object definitions. Elements from these definitions are randomly selected and placed along the surface.

Optionally, a noise definition can be used. If so, the element’s positions are restricted to the area covered by the noise. This is useful for example if you have a Perlin ground and want to distribute trees only in the green areas of the material.

Here’s an example:

<generator>

    <classname>org.ffilmation.engine.generators.fScatterGenerator</classname>

     <data amount="8" minDistance="200" randomizeOrientation="true" noise="Ground_noise_1">

         <!-- Area covered by the objects -->
         <area>
            <origin x="0" y="1400" z="0"/>
            <end x="1000" y="4000" z="0"/>
         </area>

         <!-- A Weighed list of candidates, so you can define which types appear more -->
         <candidate definition="FFTrees_misc_tree5" weight="4"/>
         <candidate definition="FFTrees_misc_tree8" weight="2"/>
         <candidate definition="MNIP_MoneyBag" weight="1"/>

     </data>

</generator>

Camera occlusion

You can now specify an alpha value for elements in front of the camera. This will make walls and objects transparent as you walk behind them, and you will be able to see what you are doing. I found out that for walls and floors, using the OVERLAY blending mode gave the nicer results. This can be changed using the API of the fCamera object.

Finally…

Also, a several bugs have been fixed and I have optimized some of the algorythms. Adding new features has been less painful than I thought: the core of the engine is responding quite well. I hope I can release a 1.1 version with all these soon.

8 Responses to “New FFilmation demo”

  1. Love it! I can’t wait to get the 1.1 release and see this project living in a repository like subversion or CVS. We have added remoting hooks into the 1.0 version of the code to get a multi player environment going. There are still a few bugs, but once its stabilized and we’ll happily commit the code.

    As an aside, it looks like we will need to refactor our code into the new scene controllers. I look forward to the merge.

  2. man!! i really really love ffilmation!!. im new with cs3, i try to get the X,Y coord from the floor to execute moveTo() with the mouse, but i can’t xD, with localX or stageX i get wrong coords.. you have some cool tip? =)

    Thanks! ffilmation rulez!

  3. Hi Matias,

    this has been answered in the forum. Check it there.

  4. Hmm.. one thing to consider is how much to cram into any single technology - my fear being that things like procedural content generation doesn’t really belong mixed in with the core of the engine. They’re great things to offer, for sure, but if I’m using my own techniques to generate the content (such as an editor), then it’s just added code bloat..

  5. Hi Jason,

    you have a point here. In this particular case I thought that they made an interesting “core” feature, but this comes from my own needs. Other people might find that it should be a separate package.

    However, keeping it simple is a main concern for me, I want to have a small API and simple but well-done features. So don’t worry I won’t allow this to become overbloated.

    Best,

  6. Interesting ideas there.
    Would be nice to add some FPS output to see how it actually behaves. Would be nice to how fps changes from 9.0.115.0 to 9.0.124.0 in your app :)

  7. createCharacter is working?

  8. Yes it does work in the latest release.

Leave a Reply