engine.game Functions
This class contains functions to control the game logic of the application. It provides functionality for:
- Assigning a player to the editor_game viewport.
- Pausing, speeding up and slowing down the game logic.
Game Class
Members
void engine.game.setData(string data)
Updates user data associated with the game. This string is written directly into a *.world file. Namely, into the data child tag of the game tag, for example:<world version="1.21">
<game>
<data>User data</data>
</game>
</world>
Arguments
- string data - User data. Data can contain an XML formatted string.
string engine.game.getData()
Returns user data associated with the game. This string is written directly into a *.world file. Namely, into the data child tag of the game tag, for example:<world version="1.21">
<game>
<data>User data</data>
</game>
</world>
Return value
User data. Data can contain an XML formatted string.void engine.game.setEnabled(int enabled)
Pauses or resumes the current game.Arguments
- int enabled - Positive integer to resume the game, 0 to pause it.
int engine.game.isEnabled()
Returns a value indicating if the game is paused or not.Return value
Positive integer if the game is not paused; otherwise, 0.void engine.game.setFrame(int frame)
Sets a specified game frame.Arguments
- int frame - Frame number.
int engine.game.getFrame()
Returns the current game frame.Return value
Frame number.void engine.game.setFTime(float ftime)
Sets the maximum rendering frame duration value, that is, it restricts the frame rendering rate to a fixed one. There is no difference if the real rendering FPS is lower than the fixed frame FPS. But if the real rendering FPS is higher than the fixed frame FPS, the engine will wait until the fixed frame time is over.
To remove fixed frame duration, use -1.
Arguments
- float ftime - Frame time in seconds. -1 removes the FPS limitation.
float engine.game.getFTime()
Returns time spent between a previous update and a current one. This function takes time scaling into account.Return value
Frame duration in seconds.void engine.game.setIFps(float ifps)
Sets a fixed FPS that does not depend on the real FPS the hardware is capable of. That is, it forces constant frame time increments between rendered frames, used for animation/expression update etc.
This function is useful when grabbing the video reel with a fixed FPS value (for example, 25 frames per second). When this mode is activated, engine.game.getFTime() will return a fixed frame time value set with this function.
To remove fixed frame duration, use -1.
Arguments
- float ifps - Frame duration in seconds (1/FPS). -1 removes the FPS limitation.
float engine.game.getIFps()
Returns a scaled fixed frame duration.Return value
Frame duration in seconds (1 / FPS). If the game is paused, 0.Obstacle engine.game.getIntersection(Vec3 p0, Vec3 p1, float radius, int mask, GameIntersection intersection)
Performs intersection to find if a pathfinding obstacle is located within the cylinder between two points.
Usage Example
The following example shows how you can get the intersection point (vec3) of the cylinder between two points with an obstacle. In this example the cylinder is an invisible traced cylinder from the point of the camera (vec3 p0) to the point of the mouse pointer (vec3 p1) with the specific radius. The executing sequence is the following:
- Define and initialize two points (p0 and p1) by using the getPlayerMouseDirection() function from core/scripts/utils.h.
- Create an instance of the GameIntersection class to get the intersection point coordinates.
- Check, if there is a intersection with an obstacle. The engine.game.getIntersection() function returns an intersected obstacle when the obstacle appears in the area of the cylinder.
- After that GameIntersection instance gets the point of the nearest intersection point and you can get it by using the getPoint() function.
#include <core/scripts/utils.h>
/* ... */
// define two vec3 coordinates
vec3 p0,p1;
// get the mouse direction from camera (p0) to cursor pointer (p1)
getPlayerMouseDirection(p0,p1);
// create an instance of the GameIntersection class
GameIntersection intersection = new GameIntersection();
// try to get the intersection with an obstacle.
// cylinder has radius 0.1f, intersection mask equals to 1
Obstacle obstacle = engine.game.getIntersection(p0,p1,0.1f, 1, intersection);
// check, if the intersection of mouse direction with any obstacle was occurred;
if(obstacle !=NULL)
{
// show the coordinates of the intersection in console
log.message("The intersection with obstacle was here: %s\n", typeinfo(intersection.getPoint()));
}
/* ... */
Arguments
- Vec3 p0 - Start point.
- Vec3 p1 - End point.
- float radius - Radius of the intersection cylinder.
- int mask - Obstacle intersection mask. The obstacle is ignored if its mask does not match.
- GameIntersection intersection - GameIntersection class instance to put the result into.
Return value
Intersected obstacle.float engine.game.getNoise1(float pos, float size, int frequency)
Returns a noise value calculated using a Perlin noise function.Arguments
- float pos - Float position.
- float size - Size of the noise.
- int frequency - Noise frequency.
Return value
Noise value.float engine.game.getNoise2(vec2 pos, vec2 size, int frequency)
Returns a 2D noise value calculated using a Perlin noise function.Arguments
- vec2 pos - vec2 point position.
- vec2 size - vec2 size of the noise.
- int frequency - Noise frequency.
Return value
2D noise value.float engine.game.getNoise3(vec3 pos, vec3 size, int frequency)
Returns a 3D noise value calculated using a Perlin noise function.Arguments
- vec3 pos - vec3 point position.
- vec3 size - vec3 size of the noise.
- int frequency - Noise frequency.
Return value
3D noise value.void engine.game.setPlayer(Player player)
Sets the current player.Arguments
- Player player - Player to set as current.
Player engine.game.getPlayer()
Returns the current player.Return value
Current player.unsigned int engine.game.getRandom()
Returns a pseudo-random unsigned number.Return value
Random unsigned integer number.double engine.game.getRandomDouble(double from, double to)
Returns a pseudo-random double number within a given range.Arguments
- double from - The initial point of the range.
- double to
Return value
Random double integer number.float engine.game.getRandomFloat(float from, float to)
Returns a pseudo-random float number within a given range.Arguments
- float from - The initial point of the range.
- float to
Return value
Random float integer number.int engine.game.getRandomInt(int from, int to)
Returns a pseudo-random integer number within a given range.Arguments
- int from - The initial point of the range.
- int to - The endpoint of the range.
Return value
Random integer number.void engine.game.setScale(float scale)
Sets a value that is used to scale frame duration. It scales up or down the speed of rendering, physics and game logic. This function allows to create effects of slow/accelerated motion.
For example, if the scale equals 2, the rate of simulation of all effects (such as particles) speeds up to two times faster. As for physics, in reality it will be simulated with the same fixed physics FPS, but the number of iterations will be two times higher. (It is possible to scale the physics FPS separately via engine.physics.setScale() function).
This function scales both setIFps and setFTime.
Arguments
- float scale - Scaling factor. The provided values is clamped within range [0;32].
float engine.game.getScale()
Gets a value used to scale a frame duration.Return value
Value to scale the frame duration.void engine.game.setSeed(int seed)
Sets the seed for pseudo-random number generator.Arguments
- int seed - Number used to initialize a pseudo-random sequence of numbers. Non-negative value should be provided, as unsigned integer is used for it.
int engine.game.getSeed()
Returns the seed for pseudo-random number generator.Return value
Number used to initialize a pseudo-random sequence of numbers.void engine.game.setTime(float time)
Sets a specified time for the game. The time is counted off starting from the world loading and does not take game pauses into account.Arguments
- float time - Time in seconds.