Source Code

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
User avatar
jfs
Tycoon
Tycoon
Posts: 1763
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Source Code

Post by jfs »

The rendering is quite spread out and you need many parts to get the full picture.
It's worth noting that this model is very much set in the 1990's world and not designed for hardware accelerated graphics.

Components:

Blitter - This is the part that does the low-level putting pixels onto a framebuffer, and has the algorithm to draw lines and paint sprites. There are multiple blitter implementations in OpenTTD for various combinations of colour depth (palette mode/8bpp or true-colour mode/32bpp) and optimization (palette animation on/off, SIMD instruction sets). These are in the src/blitter/ subdirectory.
Video driver - These take the composited image from the blitter and put on the screen.

Generic graphics functions - In the file gfx.cpp several generic blitter-independent algorithms are implemented, such as entry points for drawing lines, rectangles, and text. This is also where the dirty blocks system is implemented (to avoid redrawing the entire screen every frame).

Text formatting and layout - Taking strings and converting to a sequence of sprites that can be painted is done in string.cpp, while the management and formatting of the game's translated text system is in strings.cpp.

Sprite decoding and management - The file spritecache.cpp is where you will find the code to decode sprite bytestreams into the internal representation, and manage the sprite cache and zoom levels of different sprites.

World view rendering - The code to draw the game world is in viewport.cpp, this is also where sprite sorting and such happens. You also need to understand the NewGRF action 1-2-3 system for selecting sprites to draw for things for the full picture, this is very OpenTTD specific.

Generic GUI rendering - The base for GUI rendering and management is in window.cpp
Specific GUI rendering - All the specific GUI is implemented in the various *_gui.cpp files for various windows.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 29 guests