Difference between revisions of "Code structure"
(→Json parser and writer) |
(→Client) |
||
Line 44: | Line 44: | ||
Rendering of graphics relies heavily on SDL. Currently we do not have any wrapper for SDL internal structures and most of rendering is about blitting surfaces using SDL_BlitSurface. We have a few function that make rendering easier or make specific parts of rendering (like printing text). They are places in client/SDL_Extensions and client/SDL_Framerate (the second one contains code responsible for keeping appropriate framerate, it should work more smart than just SDL_Delay(miliseconds)). In rendering, Interface object system is quite helpful. Its base is CIntObject class that is basically a base class for our library of GUI components and other objects. | Rendering of graphics relies heavily on SDL. Currently we do not have any wrapper for SDL internal structures and most of rendering is about blitting surfaces using SDL_BlitSurface. We have a few function that make rendering easier or make specific parts of rendering (like printing text). They are places in client/SDL_Extensions and client/SDL_Framerate (the second one contains code responsible for keeping appropriate framerate, it should work more smart than just SDL_Delay(miliseconds)). In rendering, Interface object system is quite helpful. Its base is CIntObject class that is basically a base class for our library of GUI components and other objects. | ||
+ | |||
+ | === Video player === | ||
+ | |||
+ | Located in client/VideoHandler.cpp/.h, have several platform-specific versions: | ||
+ | * For 32-bit Windows - using original 32-bit libraries (binkw32.dll, smackw32.dll) | ||
+ | * For *nix systems - using ffmpeg libraries, this player can't play original bink videos (only smack video or video from native release by LOKI) | ||
+ | * Empty player for 64-bit Windows | ||
=== [[Primitive controls]] === | === [[Primitive controls]] === |
Revision as of 16:29, 14 December 2011
The code of VCMI is divided into several main parts: client, server, lib and AIs, each one in a separate binary file.
The big picture
VCMI contains three core projects: VCMI_lib (dll / so), VCMI_client (executable) and VCMI_server (executable). Server handles all game mechanics and events. Client presents game state and events to player and collects input from him.
During the game, we have one (and only one) server and one or more (one for each player computer) clients.
Important: State of the game and its mechanics are synchronized between clients and server. All changes to the game state or mechanics must be done by server which will send appropriate notices to clients.
Game state
It's basically CGameState class object and everything that's accessible from it: map (with objects), player statuses, game options, etc.
Bonus system
One of the more important pieces of VCMI is the bonus system. It's described in a separate article.
Configuration
Most of VCMI configuration files uses Json format and located in "config" directory
Json parser and writer
Capable of error checking and basic error recovery. Also have optional schema validation. Located at lib/JsonNode.h. Currently supports only local encoding - no conversion from unicode.
Main class JsonNode represents one "node" from Json file (array, string, etc.). Basic usage:
const JsonNode node("some_config.json"); std::string value = node["value"].String();
Client
Main purposes of client
Client is responsible for:
- displaying state of game to human player
- capturing player's actions and sending requests to server
- displaying changes in state of game indicated by server
Rendering of graphics
Rendering of graphics relies heavily on SDL. Currently we do not have any wrapper for SDL internal structures and most of rendering is about blitting surfaces using SDL_BlitSurface. We have a few function that make rendering easier or make specific parts of rendering (like printing text). They are places in client/SDL_Extensions and client/SDL_Framerate (the second one contains code responsible for keeping appropriate framerate, it should work more smart than just SDL_Delay(miliseconds)). In rendering, Interface object system is quite helpful. Its base is CIntObject class that is basically a base class for our library of GUI components and other objects.
Video player
Located in client/VideoHandler.cpp/.h, have several platform-specific versions:
- For 32-bit Windows - using original 32-bit libraries (binkw32.dll, smackw32.dll)
- For *nix systems - using ffmpeg libraries, this player can't play original bink videos (only smack video or video from native release by LOKI)
- Empty player for 64-bit Windows
Primitive controls
Adventure map interface
TBD
Town interface
TBD
Battle interface
Server
Main purposes of server
Server is responsible for:
- maintaining state of the game
- handling requests from all clients participating in game
- informing all clients about changes in state of the game that are visible to them
Lib
Main purposes of lib
VCMI_Lib is a library that contains code common to server and client, so we avoid it's duplication. Important: the library code is common for client and server and used by them, but the library instance (in opposition to the library as file) is not shared by them! Both client and server create their own "copies" of lib with all its class instances.
Lib contains code responsible for:
- handling most of Heroes III files (.lod, .txt setting files)
- storing information common to server and client like state of the game
- managing armies, buildings, artifacts, spells, bonuses and other game objects
- handling general game mechanics and related actions (only adventure map objects; it's an unwanted remnant of past development - all game mechanics should be handled by the server)
- networking and serialization
Artificial Intelligence (AI)
GeniusAI
Genius AI is first and obsolete battle AI.
StupidAI
Stupid AI is recent and used battle AI.
Adventure AI
Programming challenge
Neural network
Neural network is an unused and abandoned part of GeniusAI.
Expert System
Expert system is unfinished AI module which could allow understanding of game mechanics in rule-based fashion. It is supposed to utilize bonus system which holds info about many different game mechanics and could be potentially used to build complex strategies.
Modding tools
Modding engine and tools are not yet finished nor avaliable to end user.