![]() |
KTech 1.1.0
C++ 2D terminal game engine library
|
Complete engine containing all engine components. More...
#include <engine.hpp>
Public Member Functions | |
| Engine (UPoint imageSize, size_t ticksPerSecondLimit=24, bool noGameLoopMode=false) | |
| Construct the engine components. | |
| void | Quit () |
Set Engine::running to false. | |
Public Attributes | |
| bool | running = true |
| States whether the game loop should be running or not. | |
| const bool | noGameLoopMode |
| States whether the engine is in "no-game-loop mode" or not. | |
| Collision | collision |
Collision engine component. | |
| Input | input |
Input engine component. | |
| Memory | memory |
Memory engine component. | |
| Output | output |
Output engine component. | |
| Time | time |
Time engine component. | |
Complete engine containing all engine components.
You need an Engine instance to do nearly everything in KTech (including creating world structures). Normally, you should have 1 instance of this class in your game. Make sure you don't accidentally create duplicate instances, as those could lead to unexpected behavior, especially in the Input engine componenet.
However, the need for multiple instances of Engine in the same process is probable. For example, you might want 1 process managing multiple Engines (that were made headless, or that their Input and Output componenets were redirected), each handling a lobby in a server. Who knows.
| KTech::Engine::Engine | ( | UPoint | imageSize, |
| size_t | ticksPerSecondLimit = 24, | ||
| bool | noGameLoopMode = false ) |
Construct the engine components.
The engine components are your game's dependencies. For example, without Memory, you don't have anywhere to register your world structures at.
As part of that, a couple of noticeable things will happen to the terminal on construction (unless noGameLoopMode is set to true):
Input will set some terminal settings, and start waiting for user inputs.Output will move to an alternative terminal buffer, leaving the terminal empty until it starts printing images.Input and Output also correctly revert these changes in their destructors, as should a terminal application do.
| imageSize | The size of the game's viewport. |
| ticksPerSecondLimit | The rate at which your game loop should iterate. |
| noGameLoopMode | false: normal IO behavior. true: change some IO behavior so it's possible to write a test program with a game loop. See Engine::noGameLoopMode. |
Engine::noGameLoopMode | void KTech::Engine::Quit | ( | ) |
Set Engine::running to false.
Simply sets Engine::running to false (signifying the game loop should break). Use this if you need a function to do this operation (e.g., to provide as a callback function), and don't want to write one yourself.
| const bool KTech::Engine::noGameLoopMode |
States whether the engine is in "no-game-loop mode" or not.
You can optionally set this mode to true in Engine::Engine().
"No-game-loop mode" changes some of the behavior of the Input and Output engine components in order to facilitate writing a test program. For example, if you want to isolate testing of Textures, Object movement, etc., in order to see how these features work, you can use this mode.
This is what changes when no-game-loop mode is enabled (jargon warning):
Output::Print() (images will be printed bellow each other).The most significant change is the input-loop thread not starting, which is the thread that collects user input for later distribution by Input::CallCallbacks(): this change allows you to wait for user input yourself with something like std::cin. The rest of the changes mean the terminal will behave like a shell rather than a game. All of this allows you to write a test program without the burden of a game loop. Tutorial chapter 5 is an example of such program that enables this mode and doesn't use a game loop paradigm.
Engine::Engine() | bool KTech::Engine::running = true |
States whether the game loop should be running or not.
Your game loop should continue iterating as long as this variable is true, and should exit if it's false. For example:
Engine::Quit()