Raylib Bubbles
C++11 Raylib bubble shooter game.
GameUtils Class Reference

Provides utility functions for the game. More...

#include <util.hpp>

Static Public Member Functions

File I/O tools.
static std::string getAbsDir ()
 Get the absolute path to the game's directory. More...
 
static std::string getCfgStr (const std::string &section, const std::string &key)
 Get a string from the configuration file. More...
 
static size_t getCfgSizeT (const std::string &section, const std::string &key)
 Get a size_t from the configuration file. More...
 
static float getCfgFloat (const std::string &section, const std::string &key)
 Get a float from the configuration file. More...
 
static bool getCfgBool (const std::string &section, const std::string &key)
 Get a bool from the configuration file. More...
 
Float clamping tools.
static float clampLH (float &value, const float lowLimit, const float highLimit)
 Clamp a float value between two limits and return the excess. More...
 
static float clampL (float &value, const float lowLimit)
 Clamp a float value to a minimum and return the excess. More...
 
static float clampH (float &value, const float highLimit)
 Clamp a float value to a maximum and return the excess. More...
 
Random number generation from Raylib.
static float randf ()
 Get a random float value between 0.0f and 1.0f. More...
 
static int randi (const int low, const int high)
 Get a random integer value between two limits. More...
 

Detailed Description

Provides utility functions for the game.

This class provides static utilities for use throughout the game codebase.

Note
The I/O tools use the configuration file as defined in the CFG_RELATIVE_PATH macro. section and key are used as parameters in the I/O tools because of the INI file format.
See also
GameWindow, GameBoard

Member Function Documentation

◆ clampH()

static float GameUtils::clampH ( float &  value,
const float  highLimit 
)
inlinestatic

Clamp a float value to a maximum and return the excess.

Parameters
valueThe float value to clamp.
highLimitThe upper limit.
Returns
The positive or negative excess by which the value was clamped.

◆ clampL()

static float GameUtils::clampL ( float &  value,
const float  lowLimit 
)
inlinestatic

Clamp a float value to a minimum and return the excess.

Parameters
valueThe float value to clamp.
lowLimitThe lower limit.
Returns
The positive or negative excess by which the value was clamped.

◆ clampLH()

static float GameUtils::clampLH ( float &  value,
const float  lowLimit,
const float  highLimit 
)
inlinestatic

Clamp a float value between two limits and return the excess.

Parameters
valueThe float value to clamp.
lowLimitThe lower limit.
highLimitThe upper limit.
Returns
The positive or negative excess by which the value was clamped.

◆ getAbsDir()

std::string GameUtils::getAbsDir ( )
static

Get the absolute path to the game's directory.

This method uses the readlink() system call to get the absolute path to the game's directory.

Excerpt on readlink() from unistd.h:
Read the contents of the symbolic link PATH into no more than LEN bytes of BUF. The contents are not null-terminated. Returns the number of characters read, or -1 for errors.
Warning
This static method currently only works on Linux, due to the use of the readlink() system call.
Returns
The absolute path to the game's directory.
Exceptions
std::runtime_errorif an error occurs.

◆ getCfgBool()

bool GameUtils::getCfgBool ( const std::string &  section,
const std::string &  key 
)
static

Get a bool from the configuration file.

Parameters
sectionThe section in the configuration file.
keyThe key in the configuration file.
Warning
The value is found by comparing the key to "true" as a string.
Returns
The bool value from the configuration file.
Exceptions
std::runtime_errorif the value is neither "true" nor "false".

◆ getCfgFloat()

float GameUtils::getCfgFloat ( const std::string &  section,
const std::string &  key 
)
static

Get a float from the configuration file.

Parameters
sectionThe section in the configuration file.
keyThe key in the configuration file.
Returns
The float value from the configuration file.
Exceptions
std::runtime_errorif the value is not a number or out of range.

◆ getCfgSizeT()

size_t GameUtils::getCfgSizeT ( const std::string &  section,
const std::string &  key 
)
static

Get a size_t from the configuration file.

Parameters
sectionThe section in the configuration file.
keyThe key in the configuration file.
Returns
The size_t value from the configuration file.
Exceptions
std::runtime_errorif the value is negative, not a number, or out of range.

◆ getCfgStr()

std::string GameUtils::getCfgStr ( const std::string &  section,
const std::string &  key 
)
static

Get a string from the configuration file.

Parameters
sectionThe section in the configuration file.
keyThe key in the configuration file.
Returns
The string value from the configuration file.
Exceptions
std::runtime_errorif the value is empty.

◆ randf()

static float GameUtils::randf ( )
inlinestatic

Get a random float value between 0.0f and 1.0f.

Returns
A random float value between 0.0f and 1.0f.

◆ randi()

static int GameUtils::randi ( const int  low,
const int  high 
)
inlinestatic

Get a random integer value between two limits.

Parameters
lowThe lower limit.
highThe upper limit.
Returns
A random integer value between the two limits.

The documentation for this class was generated from the following files: