Monday, September 15, 2008

Laptop dead

Unfortunately my laptop died last night (well it boots OK but the screen doesn't work and it won't drive an external monitor) so development has ground to a bit of a halt.

I managed to get my files off by remote logging in from another computer and copying them across. I wouldn't have been completely screwed anyway as I keep all my code on an external SVN server.

Now to start shopping for a replacement...

Thursday, August 28, 2008

Collision detection systems for RTS games

From observing the unit movement behavior of several real time strategy games it becomes apparent that there are two major collision detection systems, each with their own pros and cons.

Tile based collision detection system
With this system each unit sits in a discrete tile on the tilemap. Only one unit can occupy a tile at any one time. As a unit moves around the map, it moves from one tile to another. Before moving into the next tile, it checks to see if any other units already occupy this tile. If the tile is occupied, the unit recalculates its path, if not then it moves into the tile.

There are some great advantages to this implementation:
1) It is extremely simple to implement
2) It is a very stable system (no units will ever get stuck in one another etc)
3) It has little CPU and memory cost which scale well

The main disadvantage of this method is the rigid nature of the movement of units. It is very clear of the fact that units sit in discrete tiles and there is a lack of fluidity in their movement.

As an example, here is a youtube clip of Warcraft: Orcs & Humans which uses the tile based collision detection system:


Note the fixed movement at 45 degree angles (i.e. North, North-East, East etc) is particularly rigid-looking and not really suitable for modern RTS games.

Object based collision detection system
Each unit is modeled as a sphere, and each building as a box. Standard collision detection techniques which may been seen in other genres of computer games are used. At each frame of movement for each unit, collisions are checked for, and upon collision are moved appropriately.

The clear advantage of this system is that the units move very fluidly and with a natural motion. It also makes it easier to make troops walk and fight in formation, as they are not constrained to discrete tiles.

However, it is particularly difficult to implement effectively and with low CPU cost. The main problem is that each unit must check the positions of surrounding units and buildings to test for collisions. For large groups of units, the checks become greater in number, having a heavy impact on the CPU.

Path finding/following also becomes an issue as it becomes more difficult to avoid dynamically moving obstacles. This is discussed in this article on Gamasutra.

An example of a game using object-based collision would be Empires: Dawn of the modern world. A youtube clip below shows this in action:


You can note at the beginning of the clip that as the soldiers line up to shoot at the building, the units kind of 'bounce' off each other.

The solution for Warring States
At first I implemented an object-based collision detection system purely for aesthetic reasons. However I soon noticed the problems that are discussed above, particularly with object avoidance. Units tended to get stuck when they tried to navigate around large groups and it would take a lot of work to make the system work well enough to my satisfaction.

As I want to start focusing on the AI system, I've decided to revert to a tile based collision detection system. However I'm not restricting the movements of units to grid-based movement as seen in Warcraft.

Thursday, August 14, 2008

Fog of war, building animation and gui interface

I've added a 'fog of war' effect to hide areas of the map that have not yet been explored by the player. A grey scale texture contains the data of which areas have been explored, and then this is fed into the terrain shader to darken the areas which are yet to be explored. I'm quite happy with the effect, although objects and trees tend to 'pop' in and I'd rather put a fading in effect as they become visible.

I've also modified the building animation, so a 'scaffold' model is erected first, then the building and then the scaffold descends again. This makes it easier to see where the building is being built, and the progress of its construction.

The last thing visible in this post is the GUI that I have started implementing. The selected units or building are displayed across the bottom of the screen, and their actions are available along the left side of the screen. The minimap is displayed on the bottom left side of the screen.

Below is a video to show the effects mentioned:

Friday, August 1, 2008

Two new youtube videos

I've uploaded two new youtube movies showing details of the game. The first shows a number of workers collecting gold and lumber and returning them back to the town center. The second video demonstrates the grass shader as it is too difficult to see in the first video due to the compression of the video.



Monday, May 5, 2008

Update on progress

It has been almost 2 months since I last made a post and a lot has progressed in this time. Below is a screenshot of the latest build:


To briefly go through the features in the screenshot:
- New unit models are featured for the worker, soldier and archer and are all fully textured
- The building model from a previous post is now in-game and fully textured
- Volumetric shadows from units and buildings
- Trees are randomly scattered on the terrain with variations in size and will flutter in the wind.
- There is a new water shader in the game, although I am not yet satisfied enough to display it in full.

Other features under the hood which you can't really see in a screenshot include:
- The first pass of networking code is in and running. Multiple computers can connect to the same game although if any network errors occur the game currently quits on all computers. I am yet to implement the team/player mechanics so everyone can effectively control everything. I haven't noticed any sync issues yet and I am also yet to try over a long distance/high latency environment.
- A database back-end system controls the various game data structures. These include information about models, shaders, textures and materials as well as statistics about various game units and buildings. It is quite trivial to add an extra game unit or building and can be done by editing the database file. This file also specifies which units can build which buildings, which buildings can train which units etc. The database is just an XML file so is easily human readable. I have used the TinyXML library to do my parsing as I needed a simple lightweight cross platform parser and this works quite well.
- The groundwork for the GUI system has been written with button widgets and event messaging systems in place. Font rendering has not yet been implemented which is why this has not progressed much so far.
- First pass for fog of war has been done but I don't like the way the fog looks so I haven't showcased this yet.

My objectives are currently set on the game logic:
- Implement the player/team structures
- Add mechanics for resource collection
- Add build mechanics
- Add training mechanics
- Add the combat system

When these are all in place the game will be playable (although in a fairly crude state) . I will then be able to move on to interface controls and general polish.

Saturday, March 15, 2008

Technology tree


I created a technology tree diagram for the game's different entities and how they interact with each other.

Green: Building
Purple: Unit
Yellow: Technology

Oriental style building


This is an oriental style building I threw together in 3ds max one evening. It has the general shape and just needs texturing and and a bit of tweaking before I put it in the game.

There has been progress on the game logic and I've put together an A-Star pathfinder which balances searches across frames. However at the moment it seems that it grinds to a halt when searching for an impossible path so it may require a bit of tweaking.

Animation is now in game and uses vertex programs to linearly interpolate vertices between frames. This type of animation isn't as effective as skeletal animation but its cheap and quick and when the characters are quite small you won't notice the difference between implementations.

I'm now working on collision detection and updating the collision grid. Currently units will not update the collision grid and will only plot paths around static obstacles. Next I'll be adding buildings into the game.

Wednesday, February 27, 2008

Walking animation

I've been working on the walking animation for my characters and created a short video which I uploaded to youtube to demonstrate:



I've not yet textured the model (just a standard checkerboard texture) but the animation is quite smooth and I'm happy with the polygon count (currently 144 polygons). The model is quite square looking around some areas but this shouldn't be too noticeable in-game as the camera will be viewing character models from a fairly long distance.

The models are going to be animated in-game by using several key frames and linearly interpolating vertex positions on the GPU. Each key frame will be stored as a standard .OBJ file and an XML file will reference which frames are used in which animations etc. Although this won't achieve as nice looking results as a proper skeletal animation system, it is far easier to code and will scale quite nicely with large numbers of characters on screen.

Once I have implemented the animation system I will be moving on to the pathfinding logic.

Friday, December 21, 2007

Progression on the project

A number of areas have progressed with the project so I thought it was about time I updated my blog.

Firstly the most noticeable update is on the graphics front. Here's a screenshot of the current build:


1) 3-D textures
The terrain is now textured with a 3-D texture. 3-D textures are basically stacks of standard 2-D textures which allows you to gently blend between different layers. In the case of the terrain, there are 6 different layers ranging from sand to dirt, to grass, to smoother grass, to rougher grass and eventually to a snow type texture. In the case of the terrain, the height at each point dictates which texture layer should be used. This means that low areas near the water have a sandy beach effect whilst high areas blend into snow capped mountains.

I noticed that originally the terrain looked very artificial because the layers were very clear, so I randomly offset the layer on each point of the terrain to add extra variation. This isn't the best solution, but it certainly gives an overall more natural feel. I may create a separate blend map layer to allow for extra terrain features such as roads.

2) Shaders
I have implemented a system to use the OpenGL shader language (GLSL) to create some shader effects. Currently this supports per-pixel diffuse lighting on the terrain and models. I want to extend this for more complex materials, bump mapping and special effects.

3) OBJ Model loading
I have chosen to use the OBJ format for model loading as nearly every 3-D modelling program supports it and its a relatively easy format to import. The model loader will read position, normal and texture coordinate data, and will generate normal data if none is available. It also generates edge data for use in shadow volumes (see below)

4) Shadows
I have opted to use a shadow volume technique for generating shadows. Basically for each object a volume is created to represent the space which is occluded from the light source. The area where this volume intersects with surrounding geometry is where it is in shadow. I'm not quite happy with my current implementation as there are a few graphical glitches. Also the lighting model is not quite finished which is why the shadows are completely blacked out. I'll post more on the topic when the lighting model is in place.

5) Object instancing
I have written a dynamically sized object container which allows for speedy random access. It is basically a tree structure which increases in size as you add more objects. Each object is given an ID value which means searching for it is just a matter of traversing the correct nodes on the tree. This is a big plus as it means when it comes to implementing multiplayer, objects can be referenced by ID during communication.

6) Picking
I have implemented a system to decipher which object in the scene the mouse pointer is hovering over which will be very useful for the overall input system. All objects are redrawn in the scene in 'select' mode with each object assigned an ID value. The same system should allow the user to click and drag a rectangular area to select multiple objects.

Thats about it for now. Here are some of the next things I want to be working on:
- Lighting model (ambient occlusion, directional light source, correct shadowing)
- Selecting objects
+- Object messaging infrastructure (issuing commands)
+- Movement and pathfinding
- Animation
- Occlusion culling

Saturday, November 17, 2007

Terrain rendering

This is an early preview of the terrain rendering engine. It's using a heightmap generated from Terragen which is then imported as a grey scale bitmap. The program is rendering the mesh without any material textures but does use a precalculated ambient map.

The ambient light map is calculated by using a ray-casting algorithm to estimate the angle of the horizon at various angles for each vertex on the height field. Using these angle values, an approximation of the sky lighting contribution can be made.

The next step for lighting is to calculate the sun contribution. Using the same ray-casting algorithm the angle of the horizon will be stored in a horizon map. This can then be compared with the angle of the sun to determine if a point is in shadow or in direct sun light. The added benefit of using a horizon map is that the angle of the sun can be changed with light and shadow being generated dynamically, so different times of day can be simulated.

Pixel shaders are going to be used to incorporate the lighting and materials. I hope to also support bump mapping to give the terrain a more rough 'feel' to it.

Change of project direction

After some careful consideration and weighing up the advantages and disadvantages, I have decided to change the project so it will no longer be a Java applet embedded in a webpage, and will instead be an offline application that can be downloaded and played single player or multiplayer, internet or LAN. The game will now be written in C++ and use OpenGL for the graphics rendering.

The main reason for this change is that I was finding Java to be quite a limitation and although this was pushing me to write well optimised code, I was unhappy with the quality of the graphics. Graphics is certainly the strongest aspect of my programming skills and it would seem a shame to limit myself so much in this area of the game. The game will now feature a fully 3-D environment making use of available graphics hardware. Lighting and effects will be used by writing custom vertex and pixel shaders.

The game will still remain cross platform, and will be released for Windows, Mac OS X and Linux. I will be using the SDL library to handle input, sound, window management so the porting to other platforms should be fairly trivial.

Tuesday, September 11, 2007

Concept soldier


I sketched a soldier as part of the concept art for warring states as shown above. I'm now going about making it into a 3-D model for the game.

On some other notes, I've set up a subversion repository for version control and the code is progressing quite nicely. The basic rendering system is in place with an isometric style map being drawn and culled correctly, and sprites in the game are sorted and displayed correctly.

Saturday, September 1, 2007

Interesting youtube video

I stumbled across this youtube video which has some really interesting background about the weapons used during the warring states period in china. It will be a very good reference to make when designing the units in the game:

Monday, August 27, 2007

First preview of assets


Here are some of the model designs that I have been working on for the game. The models will all be pre-rendered and used as sprites in the game. As can be seen I haven't added textures or materials yet but the structures are taking shape.

Blog started!

I've started this blog to record the development of my final year university project. It will be an online multiplayer real time strategy (RTS) game which will be played through a web browser. The game will be written in Java and aims to feature multiplayer as well as a challenging computer AI as a single player option.

The name 'Warring States' refers to the period of time that the game will be set. This was a time in China's history where the country was split into seven seperate states, each at war for the control of the known world. In multiplayer games, each players will choose which faction they want to play as, and the single player game will feature a campaign mode which will follow the state of Qin who aim to unite the country.

I hope to update this blog whenever I implement anything particularly interesting. I plan to release a public beta for testing when the game reaches a stable state.