Potato Engine
Loading...
Searching...
No Matches
Setup

Engine Setup

This page covers setup of the engine prior to making the game

Remarks
The engine is still under development and this page is subject to change.

TODO: includes

Game Setup

Prior to initializing the engine, game functionality may be designed. This includes game variables, constants, functions, or class instantiations.

Only game functionality that is independant of engine functionality may be performed here.

void Welcome() {
std::cout << "Welcome to the game!" << '\n';
std::cout << "This game is a fighting game..." << '\n';
// ...
}
int main() {
const std::string GAME_NAME = "Enemy fighter";
const int GAME_VERSION = 4;
const int NUM_ENEMIES = 3;
Welcome();
// Initialize engine
// ...
return 0;
}

A welcome message function, as well as game constants are defined prior to initializing the engine

Initializing the engine

The global engine object must be initialized using Get(), prior to any engine operations. Engine subobjects must also be loaded using LoadSubobjects().

engine.LoadSubobjects();
Global engine singleton class.
static PotatoEngine & Get()
Global access to engine object.

Initializes the engine object and returns a PotatoEngine&. It is stored in the engine object. LoadSubobjects() is called.


Ensure PotatoEngine::Get() is called before anything else (see Game Setup for more info)

Instance Settings

Setup engine constants and settings using GameInstance.

instance->FRAMES_PER_SECOND = 24.f;
instance->MS_REPEAT_THRESHOLD = 195;
Singleton with various game properties and functions. This class also manages game subobjects.
int MS_REPEAT_THRESHOLD
Threshold to wait for input completion in milliseconds.
static GameInstance * get()
Gets singleton instance.
float FRAMES_PER_SECOND
Global FPS constant for screen refresh.

Gets the game instance and sets the FPS and repeat threshold values

Level Setup

Load the persistent level. Fetch dynamic actors (TODO) and load static actors into world using LoadStaticActors().
A valid save file must be placed under Saves/.

PersistentLevel level("mySave.json"); // "Saves/mySave.json" exists!
level.LoadStaticActors();
Level object that stores persistent save data.

Creates a level object associated with "mySave.json" and loads static actors.

UI Setup

Add widgets and other UI elements using the HUDController.

// engine declared
IHUDController* HUDController = engine.GetHUDController();
HealthBarWidget* healthBar = HUDController->AddWidget<HealthBarWidget>("healthbar");
MapWidget* minimap = HUDController->AddWidget<MapWidget>("minimap");
InventoryWidget* inventoryDisplay = HUDController->AddWidget<InventoryWidget>("inventory");
Manages global HUD.
WidgetClass * AddWidget(std::string UID)
Construct and add widget to the screen.
IHUDController * GetHUDController() const
Gets HUD controller.

Adds health bar, minimap, and inventory widgets to the HUD. Note that these are placeholder classes not implemented by the engine.

Other Game Setup

Other game settings that involve engine functionality may be performed here. This includes player setup or player controller settings.

// instance declared
PlayerController* playerController = instance->GetPlayerController();
Player* player = playerController->GetPlayer();
player->Texture = 'P';
player->SetVisibility(false);
void SetVisibility(bool visibility)
Sets visibility of actor.
Definition Actor.cpp:77
PlayerController * GetPlayerController() const
Gets player controller object.
Main managing class for the player, controlling interactions and non-local behavior.
Player * GetPlayer() const
Gets assigned Player.
User controllable character.
Definition Player.hpp:12

Sets the player texture to 'P' and hides the actor (prior to game start).

Game Loop

Start the main game loop using BeginPlay() and handle loop exit using Resolve().

After starting the game loop, Resolve() will only be called after the loop has completed and the engine is shutting down.

// engine declared
engine.BeginPlay();
engine.Resolve();
void BeginPlay()
Starts gameplay.
void Resolve() noexcept
Resolve all subobjects and perform resolving engine functionality.

Calls BeginPlay() and Resolve() sequentially


Ensure Resolve() is called prior to post-game functionality. This is vital to ensure proper memory cleanup for engine internals.

Exit

Complete post-game operations and exit program.

Only game functionality that is independant of engine functionality may be performed here.

// engine declared
void Goodbye() {
std::cout << "Thanks for playing!";
}
int main() {
// ...
engine.Resolve()
Goodbye();
return 0;
}

After resolving engine, a goodbye message is displayed and the program returns

Example

This is a full example of a prototype game main function

void Welcome() {
std::cout << "Welcome to Enemy fighter!" << '\n';
std::cout << "This game was developed by bob." << '\n';
std::cout << "Press enter to start...";
std::cin.get();
}
void Goodbye() {
std::cout << "Thanks for playing Enemy Fighter!";
std::cout << "Support me at bob.com!";
}
int main() {
const std::string GAME_NAME = "Enemy fighter";
const int GAME_VERSION = 4;
const int NUM_ENEMIES = 3;
Welcome();
engine.LoadSubobjects();
GameInstance* instance = GameInstance::get();
instance->FRAMES_PER_SECOND = 24.f;
instance->MS_REPEAT_THRESHOLD = 195;
PersistentLevel level("mySave.json");
level.LoadStaticActors();
IHUDController* HUDController = engine.GetHUDController();
HealthBarWidget* healthBar = HUDController->AddWidget<HealthBarWidget>("healthbar");
MapWidget* minimap = HUDController->AddWidget<MapWidget>("minimap");
InventoryWidget* inventoryDisplay = HUDController->AddWidget<InventoryWidget>("inventory");
PlayerController* playerController = instance->GetPlayerController();
Player* player = playerController->GetPlayer();
player->Texture = 'P';
// GAME START
engine.BeginPlay();
engine.Resolve();
// GAME END
Goodbye();
return 0;
}