the official as3isolib blog

actionscript3 isometric library (v1/v2)

Variable Elevation/Terrain

As I am working on making the demo application, I have encountered an issue with the DefaultSceneRenderer.  Check out these screen shots:

The issue arises not from the comparison algorithm used in Array.sort(compareFunc) but rather in the fact that the built-in Array sort method does not iterate between the two objects that should be swapped in the 2nd image.  I am investigating other options however implementation of manual sorting methods (e.g. Insertion Sort, Merge Sort, Bubble Sort) does not yield any better results.

The ideal scenario would be to have a sort method that compares all possible obj pairs.  Though not ideal in terms of performance, this would be mitigated in the idea that maps containing variable elevations/terrain could be separated into unique scenes such that it uses a different ISceneLayoutRenderer.

The other approach is that I might have to implement some sort of parenting of animated objects to static objects and pass them over to adjacent tiles.  This is the current method that the Open Space Engine utilizes.  I also have my suspecions that the engine used in Dofus and Wakfu might utilize this method as well.

All commentary is welcome.

[EDIT 2009.02.16]

I ventured down the object-parenting-to-tile scenario and had success.  Though this works, it is restrictive in the sense that everything seems to be handled by the prototype ISceneLayoutRenderer.  One good thing about my findings is that I was able to do this without modifying the API at all.  But this was achieved at a significant cost.   I can already see class-coupling and poor OOP further down the road.  There is much manual checking against parenting tiles and bounds collisions.

In practice I think the idea of the whole object-parenting-to-tile scenario is poor OOP but I will continue to investigate this further.


3 responses to “Variable Elevation/Terrain

  1. isilweo February 16, 2009 at 1:15 pm

    i was thinking about some speed optimizations and one of my thoughts was exaclty the same. Why sort all the objects in the scene?
    Normally the scene is made from tiles, static objects and animated objects.
    Static objects are like tree, rock or something. Animated is player character, or a monster. I know that my static objects will not move so i can presort their depth location and only insert animated objects to presorted static objects array. this would give me only one sorting iteration per animated object. Also you could remember last position (in array) of animated object and start sorting it from there. An example:


    this is presorted array, now i’m moving my character to location between house and tree so i would get tree,PC, house, rock
    if I move my PC a little so it would not change depth position i only check prev and next objects from array.

    Hope you understand what i was trying to write above 😉

  2. jwopitz February 16, 2009 at 4:20 pm

    well the cool thing is that since the layout is done by an ISceneLayoutRenderer, we can do whatever we want with regards to sorting.

    I spent the weekend trying to improve upon the DefaultSceneLayoutRenderer which is perfect for small scenes. It does not handle stacked objects very well. And my tests to manually fix this did not prevail. But I did get started on the “Object Parented to Tile” idea since the framework is open enough to get in there and do it after all children have renderered.

    I certainly understand what you have written. Feel free to try to make an ISceneLayoutRenderer. If you send it to me, I can test it out with my suite of tests and if it survives, we can pop it into the lib.

  3. isilweo February 17, 2009 at 7:16 am

    I’ll see your code in a minute. Just to make a note.

    Fact is that flash is slow. If you want make fast game you must optimize it and using full OOP is bad way to achieve it. i’m afraid in order to make optimizations less oop you use is better. I remember from c++ game programming that even casting from one data type to another was something to optimize.
    So don’t worry about going away from oop 🙂 if you want fast game you’ll have to go away from it a bit.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: