jade-engine
0.0
|
Public Member Functions | |
Game () | |
bool | Initialize (const GameInitParams &initParams, char *argv[]) |
void | CleanUp () |
void | Start () |
Game (const Game &)=delete | |
Game & | operator= (const Game &)=delete |
void | AddScene (const int32_t id, const std::shared_ptr< IScene > &scene) |
void | PlayScene (const int32_t id) |
void | End () |
void | SetFullscreen (const bool fullscreen) |
bool | RandomBool () |
int32_t | RandomNumber (int32_t min, int32_t max) |
float | RandomNumber (float min, float max) |
float | RandomNumber01 () |
void | SetCursor (const std::string &name) |
Sprite * | CreateSolidColorSprite (const uint32_t width, const uint32_t height, const SDL_Color &color, int32_t z, ObjectLayer layer) |
int32_t | GetWidth () const |
int32_t | GetHeight () const |
int32_t | GetHalfWidth () const |
int32_t | GetHalfHeight () const |
Vector2D_i32 | GetHalfSize () const |
Vector2D_i32 | GetMiddlePoint () const |
const Sprite * | GetHoveredSprite () const |
SDL_Renderer * | GetRenderer () |
bool | IsFullscreen () const |
void | SetDisplayMode (const int32_t index) |
const int32_t | GetCurrentDisplayMode () const |
const std::vector< DisplayModeInfo > & | GetDisplayModes () const |
template<typename Class , typename CreationStruct > | |
std::add_pointer_t< Class > | Create (const CreationStruct ¶ms) |
void | StartBatchCreate () |
void | EndBatchCreate () |
const SpriteSheetDescription * | GetSpriteSheetDescription (const std::string &name) |
void | SetKeybinding (const int32_t settingsId, const int32_t newValue) |
const std::unordered_map< int32_t, KeyBindingDescription > & | GetKeyBindings () const |
int32_t | GeyKeyFromKeybind (const int32_t keybindSettingId) |
int32_t | GetMajorVersion () const |
int32_t | GetMinorVersion () const |
const std::string & | GetHashVersion () const |
int32_t | GetCopyrightYear () const |
const std::string & | GetAuthor () const |
void | SetVersion (const int32_t major, const int32_t minor, const std::string &hash) |
void | SetCopyrightYear (const int32_t year) |
void | SetAuthor (const std::string &author) |
uint32_t | GetNativeTextureFormats () const |
TTF_Font * | FindFont (const std::string &fontName, const uint32_t size) const |
std::shared_ptr< Texture > | FindTexture (const std::string &textureName) const |
std::shared_ptr< Texture > | CopyTexture (const std::shared_ptr< Texture > &textureDesc, const TextureSampling sampling) |
void | DestroyCopyTexture (SDL_Texture *texture) |
JadeEngine::Game::Game | ( | ) |
Default ctor for Game class.
|
delete |
Copying not-allowed, use GGame global variable as the single Game instance.
void JadeEngine::Game::AddScene | ( | const int32_t | id, |
const std::shared_ptr< IScene > & | scene | ||
) |
Add a scene instance to the Game map of scenes.
Adding scene should generally be done after successful Initialize() and before Start() call.
id | Identification of the scene that will serve as a key in the map of scenes. For built-in scene use Scene enum in EngineConstants.h. For new scenes it is recommended to create new enum starting with kScene_JadeEngineScenesEnd to guarantee uniqueness. |
scene | Scene instance. Game class will make a copy of this shared_ptr so it's not necessary to hold onto it and can be constructed in place. |
void JadeEngine::Game::CleanUp | ( | ) |
Destroy all loaded assets, close any outstanding handles, "quit" internal SDL2 systems.
Should be last operation on GGame before exiting the program.
std::shared_ptr< Texture > JadeEngine::Game::CopyTexture | ( | const std::shared_ptr< Texture > & | textureDesc, |
const TextureSampling | sampling | ||
) |
Create a new deep copy of Texture. Note that it is not possible to look-up this new texture later hence the return value should be captured.
Used for tinting and setting transparency of sprites as an unique instance is necessary otherwise such operations would change all sprites using this texture.
textureDesc | Existing texture that can be obtained with Game::FindTexture. |
sampling | Wanted texture sampling for the new texture. |
|
inline |
Create a new game object.
The object must inherit from IGameObject interface.
The object will belong to the current scene unless kObjectLayer_Persistent_UI is specified in which case it will belong to special persistent scene.
When creating large amount of objects consider doing so between GGame.StartBatchCreate() and GGame.EndBatchCreate() block.
params | Creation structure. For the actual type and its description see the class's constructor or header. |
|
inline |
Request the game loop to finish and stop updating. Typically used when exiting the game.
The game loop will exit at the beginning of the next tick. All updates and rendering will stop. However nothing gets cleaned up for that use Game::CleanUp.
TTF_Font * JadeEngine::Game::FindFont | ( | const std::string & | fontName, |
const uint32_t | size | ||
) | const |
Find underlying SDL2 TTF font instance given a font name and a size.
fontName | The font identification string as defined in GameInitParamsFontEntry when initializing the game. For fonts included in Jade Engine see EngineDefaultInitParams.h : kDefaultFonts. |
size | The font size as listed in GameInitParams::fontSizes when initializing the game. For font sizes for fonts included in Jade Engine see EngineDefaultInitParams.h : kDefaultFontSizes. |
std::shared_ptr< Texture > JadeEngine::Game::FindTexture | ( | const std::string & | textureName | ) | const |
Find Texture instance given a texture name.
textureName | The texture identification string as defined in GameInitParamsTextureEntry when initializing the game. |
bool JadeEngine::Game::Initialize | ( | const GameInitParams & | initParams, |
char * | argv[] | ||
) |
Initialize a new game.
initParams | Parameters required to initialize the game. |
argv | Argument vector as passed to the main function. |
Copying not-allowed, use GGame global variable as the single Game instance.
void JadeEngine::Game::PlayScene | ( | const int32_t | id | ) |
Play a previously added scene, making it the current scene.
Among other things, the current scene receives Update() callbacks and all game objects created during this scene are rendered.
If the scene is being played for the first time its Start() callback is triggered.
Nothing happens if a scene that was not previously added is played.
name | Scene identification number as specified in Game::AddScene. |
bool JadeEngine::Game::RandomBool | ( | ) |
Return a random boolean value.
Internally uses std::mt19937 and std::uniform_int_distribution.
float JadeEngine::Game::RandomNumber | ( | float | min, |
float | max | ||
) |
Returns a random floating value.
Internally uses std::mt19937 and std::uniform_real_distribution.
min | Minimum value of random number. The potential random value includes this minimum. |
max | Maximum value of random number. The potential random value includes this maximum. |
int32_t JadeEngine::Game::RandomNumber | ( | int32_t | min, |
int32_t | max | ||
) |
Returns a random integer value.
Internally uses std::mt19937 and std::uniform_int_distribution.
min | Minimum value of random number. The potential random value includes this minimum. |
max | Maximum value of random number. The potential random value includes this maximum. |
float JadeEngine::Game::RandomNumber01 | ( | ) |
Returns a random floating value between 0.0f and 1.0f (including both values).
Internally uses std::mt19937 and std::uniform_real_distribution.
void JadeEngine::Game::SetCursor | ( | const std::string & | name | ) |
Set a cursor as an active one.
name | Cursor name as specified in GameInitParamsCursorEntry::assetName |
void JadeEngine::Game::SetFullscreen | ( | const bool | fullscreen | ) |
Signal the game to switch to fullscreen or windowed mode.
It is advised to also update Setting::FullScreen settings value if this change is meant to persist across sessions. The actual change happens as the very first thing next game loop tick.
fullscreen | Whether the game should be in fullscreen mode or not. Nothing happens if it's currently already in the desired mode. // Assuming we have created a Checkbox _fullScreenCheckbox
if (_fullScreenCheckbox->Changed())
{
GGame.SetFullscreen(_fullScreenCheckbox->Checked());
GPersistence.SetSettingTyped<Setting::FullScreen>(_fullScreenCheckbox->Checked());
}
|
void JadeEngine::Game::Start | ( | ) |
Enter a blocking game-loop and start the game.
In order to exit the loop call Game::End.
It will also start GTime ticking.