Topic : Isometric Game Engine Opt
Author : Zhen Yang
Page : 1
Isometric Game Engine Optimization

by Zhenhua Yang

Introduction

Recent years, isometric engines are making a come back. Popular games like Ages of Empire(my favorite), C&C Red Alert 2(everyone else's favorite), and a slew of Role Playing Games(RGP). A good isometric engine can minimize the lags in Massive Multi-player Online Role Playing Games(MMORPG), and thus maximize what the players are there for, the fun stuff. In this tutorial, we are going to look at some of the tricks I developed that can make your isometric games go a little smoother. I will try not to be platform specific, but just keep it in mind that I am using VC++ and the DirectX technology.

With that aside, let's take a general overview of the isometric engines. In most of the ISO engines, everything is cell-based, and the render function draws the cells from left to right, from bottom to top to create the illusion of depth. This method, theoretically, is a good approach to z-ordering in a 2D engine, and is accepted by programmers around the world. But, this method creates a very inflexible environment, and thus, it gives developers a hard time when it comes to dealing with tiles of varying height. And even if you solve the height problem, the map has a very unnatural look because cell-based engines tends to line its objects up.

Now let's go back to what the cell-based engines are trying to achieve at the first place:

1. To create a smooth scrolling back-ground with minimum amount of RAM..

2. To draw objects in a certain order to create the illusion of depth.

A normal isometric engine can do both of these things at the same time, but what if we take them apart. In the following paragraphs, we are going to discuss how to achieve No.1 with a technic I invented - Quadrilateral Scrolling(QS), and No.2 with a key technology used in Microsoft Excel - a double linked list for sorting.

Scrolling is easy, but the catch is you have to do it with minimum amount of RAM, and at the same time keep things simple to prevent the image from tearing. The basic idea of QS is to scroll screen within a large bitmap. Hence, if you have a 800 by 600, 16 bit display surface, the source bitmap can well exceed 1 MB. This is where the "Quadrilateral" stuff comes in. Take a look at Figure1.0. Here we divide the destination(display) surface into four quadrants, and they are all pointed to the same source surface. Of course, you can divide the destination surface into even smaller areas, but you also have to consider that there are machines that do not support hardware blitting, and thus too many blitting operations can bottle-neck the game loop.
(go to www.geocities.com/z_yang2000/tutorials.html to see the graph).
Scrolling effect is created by moving the source rectangle inside the source surface, and the source rectangle bounces back to the center if it touches the edge of the source surface. It is very important that you use a back ground with a synchronized pattern. Now that you have a background, we need something to populate the surface. All you have to do is to store the coordinates of all the objects in their own class and sort them from left to right, from top to bottom, which brings us to the next topic, object sorting.

Object Sorting

In a MMORPG game, the map is huge. You have a slew of objects in the virtual world, so it is necessary that you divide the world into smaller regions. Back in 1997, the new Microsoft Excel can work around the cells a lot faster than the old versions, and this is made possible simply by using a double linked list. A double linked list can be sorted by a simple trial and error operation, and because it's dynamic, you can have unlimited number of objects(notes) added to it. Take a look at Figure 2.0. In an ideal world, all the objects in your local region can be sorted by their z value(the sum of x and y), and all you have to do is to update the list and render it from head to tail. But game programmers tend to overlook the dynamic lists because you have to cycle through the entire list to find the node you need. In a MMORPG, there could be over a thousand objects in one region, and thus it's just too slow to update the whole list. But who said you need to update the entire list in at once. Objects don't move that fast in isometric games, so we are going to take advantage of that, and update the linked list one node at a time. That's why we need a double linked list. So we can move our objects freely in the list.
(go to www.geocities.com/z_yang2000/tutorials.html to see the graph).

Bounding Circles

Collision Detection

In most of the isometric games, collision detection is achieved by using bounding boxes around the objects. But I find bounding circles are more appropriate in most of the cases. Because collision detection is used on moving objects(animals, monsters, etc.), and animals all have some kind of eye sight or sensor to tell them where to go. So if they see a building in front of them, they're not going to walk right into it and contour along the side of the building(unless their blood type is B:). On the other hand, if you use a bounding circle, the moving character can "see" the obstacles before he actually touches it, and form a nice curved path around the obstacle. Plus, bounding circles should be easy to apply. All you need is the object's center coordinate, instead of two coordinates you need to have in bounding boxes, and check the distance(circle radii) between objects. List 1.0 shows how to find the distance between two points with relatively less processing cycles; it was taken directly from the T3DLIB1 created by Andre LaMothe(go to www.geocities.com/z_yang2000/tutorials.html to see the list).

AI

Bounding circles can also be applied to AI. You need to create a secondary bounding circle outside the collition detection circle, and we can call it the Vision Detection. So if anything is inside your vision circle, you can program the object to go after it or get away from it. I'm pretty sure that's how they do it in most of the isometric games.

Conclusion

Quadrilateral Scrolling(try to say that five times real fast:), is an old 2D technic reinvented to create the scrolling effects in isometric games with a low memory demand. It creates a empty scrolling background, and for the rest of the objects, like trees, rocks, monsters, have to be sorted and drawn independently. Even though the double linked list sorting is designed to work with the QS, I find it quite useful for other purposes. For example, in a conventional cell-based isometric engine, a double linked list can be used to store and sort the larger tiles, and thus solve the height problem in cell-based engines.

Well, that's all I got for you this time, feel free to send me a email if you have any comments or questions:-)

<Back

Page : 1