BonzayRTS: documentationAs the engine is currently a work in progress, there is not much documentation for the engine, as of yet. Below is a brief overview of the engine and its main classes. Please check on the git source to familiarize yourself with the main abstractions, after reading below.
- Game-UI separation
- Game abstractions
- GUI abstractions
- Starcraft clone documentation
ArchitectureBonzayRTS is organized around a list of easily identifiable RTS concepts. These are high-level building blocks that can be customized to suit your game.
SubsystemsOne way to reduce the complexities of an RTS game is to divide it into orthogonal pieces that need little or no coupling. Subsystems divide the game at the "service" level - these are huge functionality blocks grouped to provide certain services, and they can be used from anywhere in the program.
A subsystem usually initializes some resources that it will use betweeen
end().It has its own configuration section in the configuration file and knows how to read it. A subsystem usually deals with initializing and controlling resources, but may provide game logic as well.
Once a subsystem has been started, it can be used like this:
GraphicsSubsystem::get_instance()->open_screen( 640, 480, 8 );
- DebuggingSubsystem - defines what parts of the engine require debugging output.
- LoggingSubsystem - starts and stops logging of debug, info, error, and fatal error messages.
- GraphicsSubsystem - initializes video mode, rezises the main screen, toggles show cursor.
- SoundSubsystem - initializes sound and provides sound services.
- InputSubsystem - provides input from the mouse and keyboard.
- NetworkSubsystem - provides transport for messages over a network.
- GameResourceSubsystem - handles loading and keeping of game resources.
- PhysicsSubsystem - provides pluggable physics via a wrapper.
- UISubsystem - provides the UI. This subsystem takes care of handling user input, repainting the screen, painting the mouse, etc.
- PathfinderSubsystem - provides configuration of pathfinder behaviour.
- SteeringSubsystem - provides configuration of steering behaviour.
- ScriptingSubsystem - provides scripting functionality for your game.
- ProfilerSubsystem - provides custom profiling if required.
Game-UI separationAnother way to drastically reduce complexity is to divide the code into game-specific and UI-specific code. Code that deals with the things happening in the game universe is game-specific. Code that only needs to convey changes to the player and process player input, is UI-specific. Keeping this separation reduces confusion, allows for more robust and maintainable code.
BonzayRTS enforces game-UI separation by having the GUI and the game logic as separate threads. The UI threads displays things regardless of the game, and the game logic runs separately. This makes game logic simpler, and GUI simpler. If game logic and GUI need to communicate, they may do so via
For servers, BonzayRTS provides
GameInstance class, holding the status of a game in progress.
For GUI, BonzayRTS provides
UISubsystem, which may be customized to a great extent.
EventsInside both the game and UI, a useful concept is
Event. Events happen in the game, or the UI, that may need not to be processed immediately. Perhaps you do not have all the required information to process it, or perhaps other code needs to know something happened in the game. Events also serve to alert the GUI about changes in the game (e.g., a worker finished gathering and now is carrying a load that should be displayed in the GUI.)
GUI::Event interfaces that encapsulate events. It also provides
EventConsumer interfaces to ease generation and handling of events.
EventManager handles the collection and dispatch of events using a subscriber model.
NetworkSubsystem- initializes/binds/releases network objects (sockets, etc).
GameMessage- a piece of data informing of network changes relating to a game.
NetworkMessage- translated GameMessage. GameMessages may not have a 1-1 correspondence to NetworkMessages.
MessageBridge- translates GameMessages to NetworkMessages and vice-versa.
Network- implements a specific protocol for communication over a transport.
Transport Engine- physical network. BonzayRTS provides UDP and Local transports.
MessagePacker/MessageUnpacker- packs/unpacks multiple network messages that are sent over transport.
On top of this layer, BonzayRTS provides a
synchronization layer to handle what we call game synchronization between peers. A
SyncEvent embodies change inside the game; e.g., a unit finishes performing an activity.
SyncEvents are encapsulated into the transport layer as payload and are delivered to the
SyncLayer object belonging a
BonzayRTS also uses the concept of
SyncEvents can be stored for later replay or desync recovery by
SynchronizationStrategiesto allow Peer2Peer or Client/Server style of synchronization. The
SynchThreadcan be used to implement the synchronization thread for a game. See Starcraft as an example.
Game AbstractionsBonzayRTS provides a lot of game abstractions, in the hope that they will simplify the design process of an RTS game. Below is a list of most significant:
Unit- contains a critter, unit, building, or resource on the map.
UnitClass- defines the properties of a unit. Defines how a unit is created, its allowed commands, its full HP, etc.
UnitClassGUI- GUI counterpart for UnitClass. Holds GUI properties of the unit class - appearance, sounds, visual size.
Weapon- If the game requires that the weapon wears out, this is required.
WeaponClass- the definition of a weapon - contains reload time, damage class, damage value, upgradeability, wear-out rate.
Armor- If the game supports damageable armor, this is required.
ArmorClass- Defines resistance to various types of damage, as well as other properties, like weight, suitability checks, etc.
Disturbance- source of an effect on any unit that falls under its range. May be applied to a unit or on the map.
Modifier- effect that modifies a unit's properties.
Damage- When instantiated, will apply various HP damage to units depending on range and unit type.
DamageClass- Defines the amount of HP hit taken by a unit, depending on the range from damage center, and unit type.
UnitFormation- a group of units executing the same command chain.
Command- contains the command that is assigned to a unit or unit formation.
Action- contains information concerning the command currently being performed.
Activity- performing a command may require many intermediate steps. Activity is one step in the list of steps being performed.
WalkabilityMap- contains the walkable bits on the map. This is for PathFinder's consumption
UnitTracker- keeps track of all the units on the map.
UnitMapper- keeps track of unit ID's and converts from UnitId to Unit* (this is required in Game/UI messaging).
TechTree- contains the tech tree information, plus there are classes to contain current tech tree.
As you can see, the abstractions provide for quite a flexible set of RTS and even RPG elements. It also assists in deciding what kind of features to include in an RTS game.
A few explanations regarding the need for
Damage: If the game deals with various damage types, like in Starcraft, where normal, concussive, and explosive damage types deal different damage depending on the unit size, then
DamageClass should be used. Additionally, for splash damage that covers an area and may fade with distance,
DamageClass allows to specify that. Instantiating a damage object will allow to apply damage in a programmatically uniform way.
Player- Identifies a player in a game.
PlayerStats- Holds information about player, including their network details.
Team- Holds the players in a team.
Scenario- Holds a game scenario, including game type, map name, and other game settings.
NegotiatedGame- Holds the details of a game in negotiation phase.
GameInProgress- Contains data for a game in progress.
GUI AbstractionsBonzayRTS tries to abstract away the gory details of painting 2D elements on the screen, to the point where one could swap out SDL in favour of something else and things should not break. Out of the box, BonzayRTS supports 2D drawing via SDL in 8-bit mode, PCX and GRP images, and playback of 8-bit SMK videos.
The lowest level of abstraction involves the following classes:
ScreenCanvas- This allows drawing on the screen.
Image- Interface for an entity that knows how to load itself and draw itself onto a canvas.
ImageFrame- An Image as part of a
FrameSet- A set of images that can be played sequentially.
ImageContainer- A set of images, not related to each other.
AnimatedImage- An animation consisting of a set of images played in sequence.
AnimatedImageDef- An animation definition - blueprint for creating an
MultiAnimation- An animation with multiple sides, for units that rotate.
Overlay- A layer put on top of the existing image, saving what's underneath, to be restored as if nothing was painted. This is very useful for displaying small things on top of other things, like the cursor, or tooltips.
Next is the widget set, which is not very interesting in itself - a standard widget library framework.Then there are GUI objects related to the UI, such as:
Pointer- Abstracts the mouse pointer.
HUD- Abstracts a Heads-Up-Display.
Minimap- Minimap display.
UnitAppearance- This class holds a unit's current appearance.
UnitAppearanceDriver- Unit's appearance driving code. Knows which appearance to use for the activity being performed.
LayeredDisplay- Repaints units in an area based on a multi-layered approach, where some units must be painted in lower layers. Needed in 2D games only.
TerrainTiles- This class is used in displaying the map terrain.
Viewport- Current Viewport of the player onto the map.
PointerTheme- A pointer theme allowing to switch pointer themes.
UITheme- UI theme, if the game has multiple UI versions (standard/experimental is often the case). Decides on how to paint the HUD and minimap
There is also the Unit's counterpart -
GUI::Unit, which holds the unit's appearance and other UI properties of the unit.