Wednesday, July 11, 2012

Work progress - part three

Welcome back!

After those few days of inactivity, it is time for a few words about the engine components that I have mentioned in a previous post, especially the Font and World Systems. Before that I would like to say a few words about Parallax Scrolling implemented in our engine. 



As you already know LD Engine supports up to 4 map layers (we thought about extending that value to 5 maybe even 6, but since 4 layers are probably enough for most games we will not change that in nearest future).
NinYawg Adventure is currently using two layers for map's purposes, basically it is a foreground and background world layers. We are using 4th layer to draw "parallax background", third layer is currently unused (maybe we will use it later to extend "parallax scrolling" posibilities, ie. by adding some decorations like trees, mountains or even clouds independant from sky layer, which will be scrolled a bit faster than a main "parallax background" - anyway it is just a cosmetic stuff, and we will not worry about that right now).
If you guys have any questions about "parallax scrolling" feel free to ask. I am not going to spent a whole day just to describe an idea of "parallax scrolling", because there are a lot of articles about that on the web.

Ok, let's say a few words about a Font System that we implemented in our engine. Since bitmaps are not small, including font bitmaps to mobile application is not best choice. If you want to draw text on all supported devices (fonts in this case), you have to prepare font map for all supported resolutions or scale them based on screen size (which will not give you decent quality). I borrowed an idea of loading font map from libgdx framework. Developers from Badlogic Games did a great job (I am not 100% sure if that is they idea) as well as author of Fractious Games blog. Based on that, I created fast and efficient Font System which is highly customizable and I have completly no idea what else could be added to it.
Idea is simple, system dynamically loads fonts from *.ttf file, then using the Android framework creates a Bitmap and a Canvas object, and draws on it every single character from font file. Of course there is a lot of math for counting margins, paddings, sizes of letters, bitmap dimension and even areas to render for every letter, but I will not write about algorithms which we have used (it is not realy that complicated as it sounds). When process is finished, a generated bitmap is loaded to GPU memory by one of our previously done graphics engine component.
For more information I highly recommend to read this post, author of this article perfectly described how system like this should looks like.

Let's finally talk about a World System that we have developed. It is a really huge component with great possibilities, and I probably do not have time to describe all of them, but I will try to introduce main abilities of that system.
Like in whole engine our goal while developing a World System was to create it as efficient and fast as we can. In current version our TileEngine is able to pre load up to 1.500.000 tiles to memory before game starts (maybe that is not much, but for purposes of our engine, that is targeted for mobile devices, it is even more than enough), which gives us 1200x1200 world in memory before a game starts (that is is only 54% available memory which Dalvik VM gives for our process, including all other systems, objects and textures). 
World Objects have their own onUse action, which can be easily connected to the Inventory System. World System is also connected to Camera System in many ways, but I am going to explain that in the next article. I implemented a fast method for rendering only that part of the world that can be seen on the screen. Worth noting fact is, while testing whole World Engine we have been able to achieve about 400fps on Samsung Galaxy S2 and about 260fps on Samsung Galaxy Mini. 

At the end I want to mention about a small but convenient change. We override a back button to display dialog box with exit confirmation. That home screen every few minutes was really annoying...

I will now reveal some details about the next article which unfortunately probably will appear only after my return. We will say something about Camera System and how it is linked with World System. Beside that we will talk about Level Editor and his possibilities that we have created for our engine. 

No comments:

Post a Comment