Core

The core module features the main data structures representing an engine, as well as functions and utility tools to bootstrap them.

The heart is the abstract class REGoth::Engine, which already implements lots of functionality to run the game. An engine needs a configuration, which is represented by the struct REGoth::EngineConfig. In most cases, the configuration options covered by REGoth::EngineConfig are enough, so the concrete class REGoth::EmptyGame (extends REGoth::Engine) can be used. A concrete example on how to use REGoth::EmptyGame can be found here.

If the default configuration covered by REGoth::EngineConfig is not enough, it is best practice to extend directly from REGoth::Engine and implement the function REGoth::Engine::config(). Make sure that your specialised configuration object extends REGoth::EngineConfig. For a code example on how employ a custom configuration, see here.

To construct an REGoth::EngineConfig from command line parameters, the convenience function REGoth::parseArguments() is provided. It is best practice to surrender the ownership of an engine configuration object to the engine by std::move-ing it into the constructor call.

To run an engine, the convenience function REGoth::runEngine() is provided.

Reference

group core

REGoth core module, in #include <core.hpp>.

Functions

template <class T>
std::unique_ptr<const T> parseArguments(int argc, char **argv)

Parses the given command line arguments in argv and returns a newly constructed EngineConfig of subtype T.

The returned EngineConfig can be used to be std::moved into an Engine while construction.

Return
Unique pointer to a newly constructed and valid EngineConfig of subtype T.
Note
A static assertion ensures that T is an EngineConfig.
Parameters
  • argc: Main’s argc (argument count).
  • argv: Main’s argv (arguments vector).

int runEngine(Engine &engine)

Bootstrap and run the given engine.

This is a convenience function to properly setup, bootstrap, and operate an engine.

Return
Windows errorlevel / POSIX status code.
Parameters
  • engine: Concrete engine to run.

class EmptyGame : public REGoth::Engine
#include <core/EmptyGame.hpp>

A concrete, yet empty REGoth engine which uses the default configuration object EngineConfig.

This is a convenience class which can be extended and used if the default configuration object EngineConfig is sufficient, and no custom configuration is needed.

If you wish to use a custom configuration, however, Engine should be extended, and Engine::config() overridden to avoid confusion between different configuration members.

Subclassed by REGoth::Gothic1Game, REGoth::Gothic2Game, REGothCharacterMovementTester, REGothCharacterMovementTester, REGothCharacterViewer, REGothFontViewer, REGothMobViewer, REGothScriptTester, REGothWaynetTester, REGothWorldCacheTest, REGothWorldMeshViewer

Public Functions

EmptyGame(std::unique_ptr<const EngineConfig> &&config)

Constructs an engine object given a configuration.

Parameters
  • config: Engine configuration.

const EngineConfig *config() const

Gets the engine’s configuration.

Return
Engine configuration data structure.

Private Members

std::unique_ptr<const EngineConfig> mConfig

Engine base configuration.

class Engine
#include <core/Engine.hpp>

The core class of REGoth, which offers a lot of default implementations to initialize the engine, setup the input, the scene, and others.

To handle more use cases, and if a custom EngineConfig is desired Engine can be extended (otherwise, see EmptyGame). The base implementations provided here will not load any world and start on an empty scene, but with most of the utilities set up to load original content and game mechanics.

Therefore, the Engine can be used to implement viewers and other tools, as well as the actual reimplementations of the Gothic games.

Some important virtual functions exist which can be overridden:

Some pure virtual functions must be implemented:

  • setupScene(): Set up the scene this engine should handle.
  • config(): Return the engine’s configuration. To use a default implementation, see EmptyGame.

To actually run an instance of the engine, see runEngine().

Subclassed by REGoth::EmptyGame, REGothWorldViewer

Public Functions

void loadGamePackages()

Load VDFS packages from the original game.

Will load data in the following order:

  1. Data/ (*.vdf)
  2. _world/ (Recursive)
  3. Data/modvdf/ (*.mod, recursive)

void loadModPackages(const OriginalGameFiles &files)

Called by loadOriginalGamePackages().

Can be overriden by the user to load specific MOD-packages.

To load a MOD-package, use gVirtualFileSystem().loadPackage(p).

Parameters
  • files: Reference to OriginalGameFiles object, which has some utility methods to access files in the original game directory.

bool hasFoundGameFiles()

When called after loadOriginalGamePackages(), this will check whether Gothics game files were found at the location given to loadOriginalGamePackages().

Return
Whether game files were found.

void initializeBsf()

Initializes bsf and opens the window.

void loadCachedResourceManifests()

Load all resource manifests written by previous runs of REGoth.

void populateResourceCache()

Goes through the loaded VDFS packages and imports the original games resources which were not already cached.

void saveCachedResourceManifests()

Save resource manifests containing resources loaded during this run.

void setupInput()

Assign buttons and axis to control the game.

void setupMainCamera()

Sets up the main camera of this engine.

virtual void setupScene() = 0

Load scenes and other objects and add them to the scene.

void setShaders()

Set shaders to be used when re-caching the materials.

void findEngineContent()

Find the location of REGoths own content directory.

void run()

Run the main loop.

void shutdown()

Shutdown bsf.

virtual const EngineConfig *config() const = 0

Grants access to the engine’s configuration.

If you do not need a custom engine configuration, and EngineConfig is enough, consider extending EmptyGame instead of Engine, which features a default implementation using EngineConfig.

Return
The engine configuration data structure.

Protected Attributes

bs::HCamera mMainCamera

Main camera this engines renders with.

bs::SPtr<EngineContent> mEngineContent

Path to REGoth’s own content directory and resource loader.

struct EngineConfig
#include <core/EngineConfig.hpp>

The base configuration for an Engine.

Configuration objects are required to construct an engine. An EngineConfig is the default configuration object, which is used in the definition of Engine::config(), and which is also the configuration object for the default engine implementation EmptyGame.

If a specialised EngineConfig is needed, Engine must be extended and Engine::config() overridden accordingly.

Subclassed by WorldViewerConfig

Public Functions

~EngineConfig()

Frees acquired resources.

void registerCLIEngineOptions(cxxopts::Options &options)

Registers CLI engine options via the given cxxopts options parameter.

Parameters
  • options: A cxxopts options configurations object.

void verifyCLIEngineOptions()

Verifies CLI engine options after parsing.

void registerCLIOptions(cxxopts::Options&)

Registers CLI options via the given cxxopts options parameter.

Parameters
  • options: A cxxopts options configurations object.

void verifyCLIOptions()

Verifies CLI options after parsing.

Public Members

unsigned int verbosity = 0

Verbosity level.

0 = quiet. The higher, the more verbose.

bs::Path engineExecutablePath

Path to the executable of REGoth.

bs::Path originalAssetsPath

Path to the game assets of Gothic or Gothic II.

GameType gameType = GameType::Unidentified

The current game type (i.e.

Gothic vs Gothic II).

unsigned int resolutionX = 1280

X resolution of the game.

unsigned int resolutionY = 720

Y resolution of the game.

bool isFullscreen = false

Whether the game should be run in fullscreen.

Sky::RenderMode skyRenderMode = Sky::RenderMode::Plane

The sky render mode of the game.