flashgameblog.at

28.12.2009
14:22

Preventing function calls brings performance

 

It isn't a secret. The overhead of function calls decreases the performance of your programs. So prevent them where ever you can. In software design encapsulation and modularity are two major, but oppositional topics. Good design finds the well balanced middle.

With some lines of code from my current project I want to show you how to prevent function calls at the usage of event dispatching. In my project I have one class dispatching an event to a lot of other objects. Each of these objects has got an ID and each event is just for one of them.

The easy way to code this is to register each object for the event and in the object's event handler I check the ID saved in the event object and skip the handler if the ID is not corresponding to the ID in the event object.

 

  1. ...
  2. for ( var i:int = 0; i < 200000; i++) {
  3.    arReceivers.push( new Receiever(i) );
  4.    sender.addEventListener( "test", arReceivers[i].evt );
  5. }
  6. ...
  7.  
  8. ...
  9. public function evt(e:MyEvent):void {
  10.     if (e.id != this.id )
  11.         return;
  12.  
  13.     // the event is for me
  14. }
  15. ..

In my test code I have 200,000 receiver objects and this codes leads two 200,000 function calls.

A better way of coding is to register one "global" handler for the event and to find the corresponding receiver object in this handler.

  1. ...
  2. sender.addEventListener( "test", evt );
  3.  
  4. for ( var i:int = 0; i < 200000; i++) {
  5.    arReceivers.push( new Receiever(i) );
  6. }
  7. ...
  8.  
  9. ...
  10. public function evt(e:MyEvent):void {
  11.     for ( var i:int = 0; i < arReceivers.length; i++) {
  12.         if (e.id == arReceivers[i].id ){
  13.             arReceivers[i].evt(e);
  14.             break;
  15.         }
  16.     }
  17. }
  18. ...
  19.  

In this code just two function calls occur independent from the number of receiver objects.

 

This is the last post for 2009. I wish you a happy new year and keep curious in 2010 :-)

15.12.2009
01:00

my isoengine

 
Last week I was looking for an iso framework for my next project. On FGL I was suggested to use AS3IsoLib. So I read some tutorials about it and made a prototype with 200 moving objects on screen. The swf ran at about 9 frames per second, what was a disappointment. With the experience I made with my sprite engine for canonrun I felt this can be done much better. Today after 5 days of coding I finished my first prototype. It runs at about 65 frames per second with 200 objects on screen, and yes z sorting is working correctly as far as it is tested :-)


I don't think As3IsoLib is a bad framework, I just think it's probably too big or too feature rich.


We have got AS3 and OOP what allows to build great general frameworks. But as far as performance is concerned I am convinced we should make smaller and specialized frameworks.
Here are some videos
 


06.12.2009
13:56

rendering ISO-tiles with blender


For a project I am planning I want to render iso tiles with blender. After some research with google and in some blender forums, I just found no satisfying solutions. So I had to build up something myself. First let's consider the situation in an iso game to get some cornerstones for our system to work efficiently.

1. Buildings and landscape tiles need to be rendered from four directions.
2. Creatures need to be rendered from four or eight directions depending on the game design.

This leads to a render scene with eight cameras.

3. We need a system to synchronize all properties, positions and angles of all cameras. This makes the perspective of an object stays the same if we use the images of a different camera in the game.

That leads to a system where:
- all eight cameras are looking exactly at the same point.
- all eight cameras are at the same distance of the focus point. So, their positions are building a circle around the the focus point with an angle of 45 degrees between each camera.
- all eight cameras have exactly the same properties, like focal distance, ...

I am not an expert in blender, so it took me some hours to build up a system providing all that points.

How does it work:

1. I created an empty at {0,0,0} and named it "camTarget". This is the focus point.
2. I created a circle at {0,0,10} and named it "camCircle.001".
3. I created a camera and named it "cam.001". To this camera I added two constraints.
   a) a FollowPath to "camCircle.001".
   b) a TrackTo to camTarget.

4. I repeated these steps eight times, where I duplicated the camera with ALT+D to secure all cameras will have the same properties.
5. Each camCircle is rotated +45 degrees.

6. I added an empty and named it "camRing" all camCircles are child object of this empty.
7. I added an empty and named it "camAll" camRing and camTarget are child objects of this empty.

8. I locked some properties to allow the three empty just to move along the z axis.

That's it.

To change the perspective you can drag camTarget and camRing. To lift the whole system without changing the perspective you can drag camAll.

 

You can download the blender file here.

 

02.12.2009
23:03

plasma

You can reload the page to see different effects.

 

Some weeks ago I needed some eye candy for my latest game. The easiest way was to put some plasma in the background. But mostly plasma algorithms generate a repetitive pattern and i wanted a better one.

 

I found this post in david's blog: http://www.gibbongames.com/?p=167

 

Unfortunatley this program is written in blitzmax, a language I don't know at all. But the syntax is easy to understand, so it took just some hours to port it.

I have added one nice feature. You can define how many lines are calculated by render circle. So you can screw down the fps of the plasma effect and use the CPU for what you really want to do.

download: click hear to download a demo project.

 

p.s.: My favourite line of code in this project is

 

if ( ubyte[plasma_id] & 128 )
                            ubyte[plasma_id] =  (~ubyte[plasma_id])&0x7F;

 

It's a very good example of the power of bit operation.

< < December 2009 > >
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    

Blog rolls

Latest Comments

Blur Filter
17.01.2011 11:01
ISO FTW!
18.09.2010 20:17
ISO Blender Camera Setup
24.04.2010 06:58
update
21.03.2010 01:15

Archive

  • [-]2010(9)
    • [-]November(1)
    • [-]August(1)
    • [-]July(1)
    • [-]June(2)
    • [-]April(1)
    • [-]March(2)
    • [-]February(1)
  • [-]2009(13)
    • [-]December(4)
    • [-]November(8)
    • [-]October(1)

Copy and paste this link into your RSS news reader

RSS 0.91Posts
RSS 2.0Posts

Social Bookmarking

Bookmark bei: Mr. Wong Bookmark bei: Webnews Bookmark bei: Icio Bookmark bei: Oneview Bookmark bei: Linkarena Bookmark bei: Favoriten Bookmark bei: Seekxl Bookmark bei: Favit Bookmark bei: Social Bookmarking Tool Bookmark bei: Power Oldie Bookmark bei: Bookmarks.cc Bookmark bei: Newskick Bookmark bei: Newsider Bookmark bei: Linksilo Bookmark bei: Readster Bookmark bei: Folkd Bookmark bei: Yigg Bookmark bei: Digg Bookmark bei: Del.icio.us Bookmark bei: Reddit Bookmark bei: Simpy Bookmark bei: StumbleUpon Bookmark bei: Slashdot Bookmark bei: Netscape Bookmark bei: Furl Bookmark bei: Yahoo Bookmark bei: Spurl Bookmark bei: Google Bookmark bei: Blinklist Bookmark bei: Blogmarks Bookmark bei: Diigo Bookmark bei: Technorati Bookmark bei: Newsvine Bookmark bei: Blinkbits Bookmark bei: Ma.Gnolia Bookmark bei: Smarking Bookmark bei: Netvouz Information