This information relates to the source in the glest_main directory. The code is then organised into different folders; ai, game etc.

Execution begins in the main/main.cpp file, specified by MAIN_FUNCTION(Glest::Game::glestMain); This tells the compiler that Glest::Game::glestMain function is the main function.

You have 2 design patterns at the beginning, singleton and state.

In glestMain() the pointer to the Program and MainWindow (taking the program pointer as an argument; which has events for mouse, keyboard, activate, resize and close) Classes are created and the mainWindow class pointer is used as an argument for the program->init function. Window::handleEvent() is used as the condition for a while loop where program->loop() is called. All of that is enclosed in a try block. When an exception occurs it is caught, the video mode is restored and exceptionMessage(e) called.

program.cpp contains the implementation for the Program Class.

Glest uses the state design pattern which is individual classes inherited from the ProgramState class which is called the interface. To change a state the function Program::setState(ProgramState *programState) is used. What it does is delete the pointer to the old programState then updates it with the one used as the argument. The programState is then loaded and initialised, the timer, CameraTimer and fpsTimer is reset.

The window parameter accepts MainWindow pointer becuase the class inherets the WindowGl (window_gl.h part of the shared library under sdl. The WindowGl class inherets the Window class) in the class.

In Program::init(WindowGl *window) the config instance is retrieved, the window and display settings are setup; the timers are initialised; the logger is started; instance of lang is retrieved; the window is initilised; core data is loaded; renderer initialised; sound initialised; and the state is set to the intro.

intro.cpp In Intro::update() the timer is incremented and if the intro has finished it sets the state to the MainMenu calling the constructor. If the user keyDown or mouseUpLeft the state is also changed to the MainMenu.

main_menu.cpp This file has the implementations for all the menu states which inheret the MenuState class. The MainMenu constructor calls MainMenu::setState(MenuState *state) for MenuStateRoot. Each menu state has its way of dealing with user input. When a user clicks their mouse on a particular button in MenuStateRoot the menu state is set according to the button pressed.

When the play button is pushed in MenuStateGameSettings the Game constructer is loaded with the gameSettings as an argument.

game.cpp The tech is loaded and the world is setup.

battle_end.cpp After the game ends the program state is changed to BattleEnd. Then when a key or mouse is pressed the program state changes back to MainMenu.

See AlsoEdit

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.