A Vector3 is a three component vector (x, y, z). It is used to represents
positions, directions, velocities, etc. Note that Vector3:s are temporary
objects. You can only use a Vector3 during the frame it was created.
Creates a new Vector3Box. This will allocate memory, so use sparingly. Typically you
should create the boxes in the init() function of your class and then just use store()
to store values in it.
Represents a rotation in the quaternion formulation (x, y, z, w). Note
that it is not strictly necessary to understand quaternions to use this
class, you can just treat it as an opaque representation of a rotation.
Lerps between quaternions q1 and q2 and returns the result. The lerp performed by this
function is a normalized lerp, or nlerp, which usually gives the best result.
Creates a new QuaternionBox. This will allocate memory, so use sparingly. Typically you
should create the boxes in the init() function of your class and then just use store()
to store values in it.
Transforms the vector v using the matrix, without translating. This is useful when you want to transform directions, rather than positions, from one coordinate system to another.
Produces a new matrix by lerping between m1 and m2. This is accomplished by lerping
the translation and rotation of the matrix individually. (Scale, etc, is not lerped.)
Creates a new Matrix4x4Box. This will allocate memory, so use sparingly. Typically you
should create the boxes in the init() function of your class and then just use store()
to store values in it.
Computes the intersection between the ray (from, dir) and the
OOBB (pose, radius). If the ray collides with any of the planes
of the OOBB, the distance to the collision point along the ray is
returned (regardless of whether the ray started inside or outside
the OOBB). If there is no collision, -1 is returned.
Returns true if the OOBB defined by (pose, radius) is completely
enclosed by frustum defined by (n1, o1), (n2, o2). Each such pair
specifies one plane of the frustum, with n being the normal of the
plane (pointing out of the frustum) and o being the position of
the plane along the normal n.
Merges a number of OOBBs (described by a Matrix4x4 and a radius)
into a single OOBBs. The resulting OOBB will have the same axes
as the first OOBB in the input. (I. e., the function will not return
the minimum fitting OOBB.)
Interface to access global application functionality. Note that since the application is a singleton (there is only one application), you don’t need to pass any Application object to the application functions. All the functions operate on the application singleton.
Returns a string identifying the build version (such as "2437 branch:release2".
You can set the build identifier in a post processing step after you have built your exe.
The built exe will contain the string "a4e915264ceaa4424b3ed6d3d2fe5e1a" followed by 128 zero characters.
You can replace the zero characters with whatever you want build_identifier() to return.
Returns an object containing the script settings from the settings.ini file. I. e.,
anything found under the "script_data" tag in the settings.ini file.
Creates a new game world and returns it. You can have as many game worlds as you like. Multiple game worlds are useful for things like loading screens or inventory rooms.
Debug helper function that tries to find the "most important" world. This is usually the world where stuff is happening and where you want to test particle effects, sounds, etc. The "most important" world is defined as the world that was rendered last frame that contains the most units.
Sets the property preference order for loading resources. See the documentation on localization. Note that the platform should never be specified here, since that is automatic.
Creates a viewport to be used when rendering the specified world using the named viewport_template. The viewport_template properties are specified in the render config file.
Gets a global script data object from the Application. i1, i2, …, in is a sequence of indices that can be either integers or strings. See section 3.5 Storing Data in Units for a description of how to use script data.
Creates a combined hash out of the arguments. Numbers, nil, strings and hex numbers as strings can be hashed. The result is a string
with a 64 bit hexadecimal hash.
Saves the win32 user settings file to disk. The file which the data is saved to is determined by the key win32.user_settings in the settings.ini file. There you can specify a filename. The string %APPDATA% in the file name will be expanded to the user's AppData folder, i.e.:
Controls how the application's time step is advanced. Possible parameters
are:
"variable"
Configures the engine to use variable time stepping. (This is the default.)
"fixed", fps
Configures the engine to run with fixed time steps at the specified
frame rate. This means that the time steps taken will always be a
multiple of 1/fps. If the engine runs faster than the specified
frame rate it will take zero-length time steps to compensate.
"throttle", fps
Throttles the engine to the specified frame rate. The engine will be
slowed down to run at the requested rate. This can be used to debug
problems that only appear when the frame rate is low.
"no_throttle"
Disables throttling. (This is the default.)
"smoothing", frames, outliers, lerp
Configures the engine to use time step smoothing. When variable time
stepping is used, smoothing the time steps over a number of frames
can make the game feel less jerky. frames specifies the number of
frames that should be averaged. outliers specifies how many extreme
values to remove. With outliers=2, the two highest and the two
lowest values are removed before the average is computed. lerp
specifies how fast the value is allowed to change from the computed
average. A low value means more smoothing, a higher value less
smoothing. (Default is 11, 2, 0.1.)
"no_smoothing"
Disables time step smoothing.
"debt_payback", frames
If set to a non-zero value, the timer will try to keep track of its
time debt -- i.e. how much the game time has drifted from an external
world clock (because of smoothing, etc) and pay that debt back over
the specified number of frames by adding extra time to them. This
can be useful if you need your game to stay in sync to external clocks
(for example for networking), because otherwise your game can "lose"
time. (Default is 0.)
"external_step_range", min, max
Specifies that the external world time should be clamped to the specified
range before it is inputted to the system. This is useful for preventing
the system from taking really large steps when you break in the debugger.
(Default value is 0, 0.02.)
"external_multiplier", multiplier
Sets a multiplier that can be used to accelerate or slow down the time
for debugging purposes. (Default value is 1.)
"system_step_range", min, max
Specifies the minimum and maximum steps that the game is allowed to
take. (Default value is 0, 0.02.)
"clear_history"
Clears the history of accumulated time debt, smoothing history, etc.
Adds a job to be run in the script worker threads. function is the name of the global function that should be called in the worker threads and unit is the unit that should be passed as argument.
Represents an application window. (On Win32, on other platforms there may not be a window.)
This class can be used either as a singleton or as a regular class. When it is used as a singleton it affects the main application window.
-- Sets the title of the main window
Window.set_title("main window")
-- Creates a new window and sets its title
win = Window.open()
Window.set_title(win, "new window")
Returns true if the window has mouse focus. When the window has mouse focus it will hide the mouse pointer from the user and prevent it from leaving the window.
Creates a new window using the settings from the table. If parent is true, it is interpreted as an integer representation of a HWND pointer. The window is created as a child window to that window and all other parameters are ignored.
Updates the engine representation of the world. You should call this as part of the update() callback. The delta_time is the time step that the world should use when updating. If you don’t specify a time step, the application’s global time step will be used.
Instead of calling update() you can call update_animations() and then update_scene(). This allows the script to do some processing between the update of the animations and the update of the scene.
Spawns a new instance of the game unit name at the specified position and rotation (should be a Quaternion). You can leave out position and rotation to spawn at (0,0,0) with default rotation.
Links the root node of the unit child to the node with index node in the parent unit. The child unit will slave after the parentnode’s movement after this call. Calling link_unit() automatically resets the transform of the child’s root node to the identity matrix, so it will be positioned at the exact location of the parentnode. If you want to offset the child from the parentnode, you should set the local position of the root node after the call to link_unit().
Unlinks the unit child from its parent node if it has any. When unlinked, the root node’s local position is set to its world position, so it will remain in its current position unless it is moved after it is unlinked.
Forces an update of the unit’s scene graph after the main world update has been performed. This can be used to implement units that are dependent on other units positions in complicated ways that cannot be expressed just with link_unit(). It should be used sparingly.
Creates a new line object to be used for debug drawing. If disable_depth_test is specified and set to true, the lines will be drawn without depth test.
Links the particle effect id to the unit in the world. The effect is linked to the unitobject with its coordinates in the local coordinate system of that object specified by pose.
Orphaned_policy specifies what happens to the effect if the unit dies. The possible values are:
"destroy"
The effect is destroyed when the unit dies.
"stop"
The effect stops spawning new particles but remains in place.
"unlink"
The effect is unlinked from the unit. It stays at its current position in the world and keeps spawning particles.
Returns the number of active particles in the world. If an id is specified, returns
the number of particles in that effect. If a cloud index is specified, returns the
number of particles in that cloud.
Creates a new screen space gui at pixel coordinates (x,y). (0,0) is the bottom left corner of the screen. Use Application.resolution() to find the size of the screen.
"scale", w_scale, h_scale
If specified, the coordinates in the gui will be scaled by the specified amount. With a scale of 2 an object that has size 100 pixels in the gui will be drawn with 200 pixels on the screen.
"material", material
Specifies the name of a .material file to use for this gui. A gui that contains textures and/or fonts needs a material files that contains the used textures and fonts.
You can have more than one material file for the gui, just add more “material” parameters. The different material files should not contain any materials with the same name.
"immediate"
If specified, the gui will be run in immediate mode. This means that everything you place on the gui will be drawn for just one frame. You have to redraw the objects you want to see every frame. If not in immediate mode, objects remain until you explicitly remove them.
"dock_right"
Specifies that the gui should dock to the right margin when the window is resized.
"dock_top"
Specifies that the gui should dock to the top when the window is resized.
Creates a new gui that lives in the 3D world. pose specifies the position of the Gui as a Matrix4x4. width and height specfies the internal width and height of the Gui in pixels, i.e. the internal coordinate system.
Loads the named level into the world at the specified position and rotation (should be a Quaternion). If not supplied, the level will be loaded at the world origin with the default rotation.
Same as load_level above, but does not spawn any objects that are members of object sets unless explicitly told to do so. The object_set_names parameter should be a Lua table listing the names of the object sets to spawn. An object will be spawned if it is a member of any of the named object sets, or if it is not a member of any object set. Object sets are defined using the level editor. You can get a list of all object set names within a level resource using the Level.object_set_names() function.
Destroys the supplied level and all units that were spawned when the level was loaded. You are not required to call this function, since all levels will be destroyed when the world ends.
Deprecated. You can use levels(world)[1], but this creates a table that will have to be garbage collected. A better approach is to store the Level reference returned from load_level().
Plays the sound resource name in the world and returns an id to it. If loop is set to true the sound will be played looping. range is the distance in meters that the sound is heard. position is the position of the sound source. If the position is not specified the sound is played as a 2D sound. mixer_category is the mixer category used for the sound, see set_mixer_volume().
Sets the volume of the sound in the range 0-1. For 2D sounds, this is the output volume of the sound. For 3D sound, this volume is multiplied by the distance attenuation caused by the distance between the sound and the listener.
Sets the volume for a mixer category such as "music" or "fx". The volume should be a value in the range 0-1. The volume of the category is multiplied with the sound's own volume.
Gets a script data object from the world. i1, i2, …, in is a sequence of indices
that can be either integers or strings. See section 3.5 Storing Data in Units for
a description of how to use script data.
Returns the value of the external flow variable with the specified name.
Note that a variable shown as "My Unit" in the editor has the real name: "my_unit".
Returns a list of all the still remaining units that were spawned when the level was loaded. You should not keep this list around, since it will contain invalid references if a unit is destroyed after the list was obtained.
Returns the index of the unit in the level or nil if the unit is not in the level. You can turn the index back to a unit with unit_by_index(). This can be used to send unit identities over the network. Note that you can only use this function with units that are statically spawned in the level, not with units that are spawned by scripts or flow nodes.
With set_local_rotation_and_scale() the scale is specified as a Vector3 specifying
the ammount to scale the node in each principle axis. Note that you cannot set
scale and rotation separately. The reason is that doing so could cause the
scale of the underlying Matrix4x4 to drift if you repeatedly changed the rotation
without resetting the scale.
As set_local_position(), but the node is teleported rather than moved to the specified location. This affects how keyframed physic objects behave. When objects are moved, they will collide with everything between the current position and the destination. When they are teleported, they will pop up at the destination without colliding with objects on the way there.
Links the scene graph node i to the scene graph node parent. Note
that you can only link objects to earlier objects in the scene graph
(i.e. objects with a lower index).
Copy all local matrixes from the unit src_unit to the unit dest_unit,
except for the root node. This can be used to support "instancing".
An expensive unit is simulated and then its transforms are copied to
simpler units.
Gets a script data object from the unit. i1, i2, …, in is a sequence of indices that can be either integers or strings. See section 3.5 Storing Data in Units for a description of how to use script data.
Marks the unit as moving for the following number of frames. This means that the world will update the unit.
When you call one of the set_local functions on a unit, the unit is automatically marked as moving, so in that case you do not need to mark the unit as moving. However, if you do some other special processing on the unit, you may need to call this function.
Note
Currently this function is not needed. Maybe it will never be. It is a
tradeoff between speed and convenience if all operations that change a unit
should automatically set it as moving, or if the gameplay programmer has to
do that explicitly.
Plays the simple animation track stored in the unit (the animation exported from MAX). The animation is played from the time fromto the time to. You can use nil for fromto start at the current time and nil for toto play to the end of the animation. If loop is set the animation will loop in the specified time interval. speed controls the playback speed.
If a group is specified, that simple animation group is played, otherwise the simple animation affects all bones in the unit.
Crossfades in the animation on the specified unit in the specified animationlayer over the specified blend time. animation is the name of the animation. layer is the number of the layer. blend_time is the time for the crossfade. And loop specified if the animation should loop when it reaches the end or just stay in the end pose.
You should only use these calls on units that have an animation blender but no animation state machine. (I. e., units with a script driven blender.)
Returns an id that can be used to control the animation.
Returns true if the unit is currently crossfading any animation. You can use this to avoid overlaying too many crossfading animations on top of each other.
Sets the speed at which the crossfaded animation id will play with respect to the blender. A value of 1 means it uses the same time step as the blender. A value of 0 means it is frozen. You cannot use negative values for the speed.
Triggers the event named event in the unit’s animation state machine, possibly causing a transition to a different animation state. You should only call this on units that have an animation state machine.
Sets the value of an animation state machine constraint target.
The value can be a Matrix4x4, a Quaternion or a Vector3, depending on if you
whether you want to set position and rotation or just one of them.
Sets the way in which animations will update the root node of a unit. There are two possible values:
"ignore"
Root animations are ignored, they will not affect the unit’s root node. This is the default mode.
If you use this mode you use animation_wanted_root_pose() to extract the position the animation
wanted to move the root to and apply that position programmatically.
"delta_transform"
The delta changes to the root position and rotation that occur in the animation will be applied
to the root node of the Unit. I.e., the unit’s root will be moved by the animation.
"delta_position"
As delta_transform, but only position updates are transferred to the root node.
"delta_rotation"
As delta_transform, but only rotation updates are transferred to the root node.
In “ignore” mode, this function returns the pose that the animation would have wanted to move the root node to. You can use this to apply the animation movement manually from the script or pass it through other systems (such as the unit’s mover, etc).
Disables the unit’s animation state machine, so that you can control its blender directly with the crossfade operations. This is typically only used by tools and for debugging purposes.
Sets the animation state machine of the unit to something other than the default. machine should be the name of the state machine resource you want to use.
Returns the current animation state of the unit as a tuple of data. You can restore this state later
with a call to set_state(). Note that the state only includes the state of the state machine, not the
play head offsets, animation variables or constraint targets.
Returns the name of the unit. This should only be used to print the name for debugging purposes. In release versions the real name will not be available and this function will return a hexadecimal string instead of the name.
Returns a hash representation of the unit name. The representation will not be
meaningful, but you can pass it as an argument to World.spawn_unit() in order to
create another unit of the same type.
Returns false if the unit has been deleted. Units are always held as weak references by the script and the script can check if the reference is still valid by calling Unit.alive on the unit. Note: only units are held as weak references, the script cannot call alive() on any other objects to detect if they have been deleted.
Calling any other function than alive() on a unit that has been deleted will result in a script error.
Returns an object-oriented box that encloses all the meshes in the unit. The box is represented by Matrix4x4 that describes the position and orientation of the box center and a Vector3 that describes the radius of the box (i.e. its half-extent in the x-, y- and z-directions).
Sets the light's local position, orientation or pose. When changing the light position you must pass the unit that the light belongs to, so that it knows that it needs updating.
Sets the camera's local position, orientation or pose. When changing the camera position you must pass the unit that the camera belongs to, so that it knows that it needs updating.
Converts a point p from screen coordinates to world coordinates. In screen coordinates,
(x,z) are the pixel positions of the point on the screen and the y-coordinate indicates
the depth into the screen where the point lies (the distance from the camera plane) in
meters.
Tests whether the Vector3p is inside the camera's frustum. A positive return value means the
point is inside the frustum. The value specifies how many meters inside the frustum
the point is. A negative value means the point is outside the frustum. The value specifies
how far outside the frustum the point is.
A LineObject is used to draw debug lines in the game world. It is created with World.create_line_object(). You add lines to a line object using the add_* functions and queue it for rendering with dispatch(). The lines in a line object are not cleared automatically between frames, so any lines you add will persist on screen as long as you continue to dispatch the line object. To clear the lines of a line object call reset().
To draw lines that follow a moving object, you should call reset() every frame to clear out the old lines and then add the new lines.
Adds a line between (from, to) to the line_object. The line will be given the specified color.
The color of a line object is specified as an ARGB value in a Quaternion with each component ranging from 0-255. You can create such a value with Color(), passing three arguments for an RGB value and four for an ARGB value. So to draw a bright yellow line you would use the colorColor(255, 255, 0).
Adds a circle at center with specified radius and normal vector. If segments is given, it specifies how many individual line segments the circle will be composed of.
Adds a sphere at center with specified radius. segments specifies the number of line segments in the circles making up the sphere and parts specifies the number of circles.
Adds an oriented box. The pose is a Matrix4x4 specifying the position and orientation of the box. Extents is a Vector3 specifying the size of the box in the x-, y- and z-directions.
Sets the mesh local position, orientation or pose. When changing the mesh position you must pass the unit that the mesh belongs to, so that it knows that it needs updating.
Shading Environments specify a set of variables used for lighting and post
processing when rendering a World. Typically it includes data such as sun
direction, sun color, shadow settings etc. The contents of a shading
environment is defined from shading_environment_template files and is setup
on a per project basis. The Lighting Editor is used to author shading
environments.
Creates a raycast object that can be used to make raycasts. Doing a raycast is a two step process. First you use make_raycast() to create the raycast object. Then you call cast() on that object to perform the actual raycast. The raycast object keeps an internal cache that makes it more efficient if you use it to make many similar raycasts. If you just want a one-off raycast, you can call make_raycast():cast() and then forget about the raycast object.
The callback is the function that will be called with the result of the raycast in the next few frames. In the Bitsquid engine all raycasts are asynchronous operations.
Note
We may change this in the future if there is enough pressure… But asynchronous raycasts are much better from an engine efficiency standpoint.
params is a list of parameters for the raycast. The possible parameters are:
“closest” (default)
Specifies that the raycast should return a single hit, the closest to the origin of the raycast.
“any”
Specifies that this raycast should just return a true or false value that specifies whether it has hit anything or not.
“all”
Specifies that the raycast should return all hits along the ray path.
“types”, “both” (default)
Specifies that the ray should test against both static and dynamic objects.
“types”, “statics”
Specifies that the ray should only test against static objects.
“types”, “dynamics”
Specifies that the ray should only test against dynamic objects.
“collision_filter”, name
Specifies the name of the collision filter that the ray should use to determine which objects it collides with. By default, the ray collides with all objects in the scene.
The Raycast object returned by make_raycast() is a full userdata object that will be automatically garbage collected when the script no longer refers to it.
Call this on the raycast returned by make_raycast to actually perform the raycast.
from should be a Vector3 containing the origin of the ray. dir should be a unit vector specifying the direction of the raycast. If length is given, it specifies the length of the raycast, otherwise the ray is assumed to be infinitely long.
The result of the raycast is returned with a call to the callback function specified in make_raycast. The callback will use one of the following forms:
callback(any_hit)
For an “any” cast the callback is called with just true or false depending on whether the ray hit anything or not.
For a “closest” hit, the first argument will tell if there was a hit or not, as before. If there was a hit, the callback will also be called with the position of the hit, the distance from the origin, the normal of the surface that was hit and the actor that was hit.
callback(hits)
For an “all” raycast the callback will be called with a table containing all the hits. If there were no hits, the table will be empty.
Each entry in the table is in turn a table with four elements: {position, distance, normal, actor}.
Performs an overlap test in the physics world. I. e., it finds all the actors in the world that are in a particular shape. (For example, all actors in a 20 meter sphere around the player.)
All overlap calls are performed asynchronously and returned to the gameplay programmer a couple of frames after the request has been made through a call to the specified callback function.
The parameters specify the shape of the overlap. Possible values are:
“shape”, “sphere” (default)
Specifies that the shape should be a sphere.
“shape”, “aabb”
Specifies that the shape should be an axis-aligned bounding box.
“shape”, “oobb”
Specifies that the shape should be an object-oriented bounding box.
Specifies the size of the shape. The value can either be a Vector3 specifying the size in the x, y and z-directions or a float specifying the size in all three directions with a single value.
“types”, “both” (default)
Specifies that the overlap function should find both static and dynamic actors.
“types”, “dynamics”
Specifies that the overlap function should only find dynamic actors.
“types”, “statics”
Specifies that the overlap function should only find static actors.
“collision_filter”, filter
Specifies the name of a collision filter to use for the overlap test. If no collision filter is specified, a filter that matches all actors in the scene will be used.
When the overlap test completes, the callback function will be called as:
callback(actors)
Where actors is a table containing all the actors that were found in the overlap test.
Most physics objects in a scene come from the units through the physics settings specified in the .physics file. But sometimes it can be useful to spawn a completely improvised physics actor. This function spawns an improvised sphere.
The sphere will be spawned at position with radius. The actor, shape and material parameters are the names of the actor template, shape template and material template that should be used when constructing the sphere.
Pushes the actor as if it was hit by an object with velocity and mass. Use this to simulate collision with objects that are not physics simulated, such as bullets.
Sets the timpani listener at the specified index to the specified pose or position.
Currently, only one listener is allowed, so you can only set the listener at index
0.
Loads a timpani master file. Normally you specify the Timpanimaster file in your .ini
settings. This function is mostly for tools that are not able to do that.
Note that any Worlds created before load_master() will still point to the old timpani
master and are likely to cause errors. You should have no active worlds when calling
load_master().
Directly loads a timpani bank. Normally, you should never do this, you should only
load the banks through the resource packages. This function is just called by tools
that use autoloading and need to load banks directly.
Represents the interface to an input controller. There are a number of input controllers exposed as singletons: Mouse, Keyboard, Pad1, Pad2, Pad3, up to the number of pads supported. So to check if the keyboard button k is pressed, you can use:
For keyboards this returns the name of the i’th button with respect to the keyboard type (locale).
This string may be empty if there is no name for the key. Shift and alt for example will be empty strings.
Set the threshold([0,1]) of when a button is considered 'down'. Default is 0.5. Larger values will result in the user has to press the button harder in order indicate it as 'down'.
The engine has a built-in "rumble effect system" that lets you play rumble pulses with specific
strength and duration. When you use the rumble effect system you only need to call rumble_effect()
once to start a rumble effect. The engine will take care of modulating the rumble and fade it out
at the end of its duration. If there are multiple rumble effects in play, their effects are added.
If you need more detailed control over the rumbling you can use the set_rumble() method instead.
That method allows you to directly set the rumble strength of each motor. Note, that if you use
that method you are responsible for fading out rumbles, etc.
Sets the strength of the rumbling in the i'th motor as a value between 0.0 and 1.0.
The rumbling remains at this strength until you call set_rumble() again to set a
different value.
Creates a rumble effect on the i'th motor. parameters is a table that specifies the
properties of the effect. Note that you only need to specify the parameters that you want to
change from their default values.
frequency = 0
The frequency of the sine wave. If you use a frequency of 0, the sine wave will not be used and the strength of the rumble will only be affected by the ADSR envelope.
Note that since the motors on most controllers cannot change speed instantly it does not make sense to use frequencies above 6 Hz or so.
period = #inf
The period of the sine wave. You can specify this instead of the frequency if you want. Note that period = 1 / frequency.
offset = 0
The offset of the sine wave. Normally the sine wave is offset so that it starts in its lowest position. You can specify a value between 0 and 1 to start the oscillation at a different position. For example, with a value of 0.5 the sine wave will start in its highest position.
attack_level = 1
The strength of the rumble at the maximum attack position.
sustain_level = 1
The strength of the rumble in the sustain part of the envelope.
Stops all rumble effects on the i'th motor. Note that this doesn't zero any rumble value
set with set_rumble(). You need to call set_rumble(i,0) for that.
Calls to start() and stop() must be balanced, i. e., every start must be followed by a stop. Otherwise you will mess up the nesting of the profile scopes.
Sets the number of temporary vectors, quaternions and matrices.
If you have a function that uses a lot of temporary objects you can use this call to reset the temporary buffers and free those objects. Be aware though, that the function has not exported any of those objects to variables that live beyond the length of the function call. If so, those variables may be assigned new values, since the system considers them “freed”.
Looks up the key in the localizer. If a string with the specified key is found in the database that string is returned, otherwise the function returns nil.
A data structure that allows you to quickly search for units in a game level. The units inserted into the broadphase gets sorted into a grid for quick access.
is the radius of the grid cells. For maximum efficiency you should set the cell radius to the radius of the largest query you are going to make to the broadphase. (The broadphase will not allow you to make queries larger than the cell radius, also, you cannot insert objects bigger than the cell radius.)
num_objects
is the expected number of objects that will be inserted into the broadphase. This will determine how many grid cells are created.
Finds the polygon in the mesh that the Vector3p is closest to and returns its
index. If the point is outside the navmesh, the function will return nil.
Constrains the Vector3p to the polygon with index poly and returns the result.
Also returns a bool specifying whether the character was outside the polygon and needed
to be moved.
Used to move a character on the navigation mesh. Given a new position p and the index
poly of the polygon the character was on the last frame, this function will compute
which polygon the character is on now. It will also constrain the character's position to
the navmesh.
The return values are:
the new position of the character (possibly constrained to the mesh)
the normal of the polygon the character is on
the index of the polygon the character is on
true if the character needed to be constrained (i.e. collided with the mesh edges)
Returns the indices of the polygon neighbors to the polygon with
index poly. If an edge of the polygon doesn't have a neighbor
the corresponding index will be returned as nil.
Does an A* search to find the closest path from polygon start to polygon end.
The resulting path is returned as a table of nodes.
focus specifies how aggressive the search should be. A value > 1 means
a more aggressive search that expands fewer nodes but may not find the absolute
shortest path. For example, with a focus of 1.2 the returned path is allowed to
be 1.2 times longer than the shortest possible path.
max_search_nodes specifies the maximum number of graph nodes that will be
looked at in the search. It is a way of bounding the run time of the search.
If you specify a low value, you may not always be able to find a path between two
nodes, even when such a path exists.
Note that vertices can be repeated in the returned lists (when the polygons form a fan).
The returned lists will always contain #path - 1 items. I.e., one item for each polygon
edge crossed.
Colors are internally represented as quaternions (i.e. a value with four floats).
This means that they are temporary objects that cannot be stored from one frame
to another.
Creates a matrix that can be used to draw a rotated 2D object with the 3D
functions.
pos is a Vector2 specifying the position of the object.
angle is the angle the object should be rotated (clockwise in radians).
If a pivot is specified it specifies the Vector2 position that the object
should be rotated around. If no pivot is specified the object is rotated
around pos.
Represents a gui created by World.create_screen_gui() or World.create_world_gui().
Depending on the creation parameters the Gui can either be in immediate mode
(which means that you draw all the GUI objects that you want visible every frame)
or in retained mode (which means that you use a create/update/destroy pattern to
manage gui objects).
Returns the width and height of pixels that can be used in a screen Gui. This is normally the same as Application.resolution(). The two values only differ if the screen has non-square pixels. In that case, the Gui pixels are stretched horizontally to ensure that a Gui object with size (100,100) is still a perfect square. This means that there will be fewer or more Gui pixels horizontally than actual screen pixels.
Creates (or in immediate mode – draws) a rectangle on the gui. pos is a Vector3 that specifies the position. (x,y) are the x- and y- coordinates and z is an integer specifying the draw layer. Objects with a high value of z appear in front of other objects. size is a Vector2 specifying the dimensions.
The function returns an id identifying this rectangle. (This id is only useful in retained mode.)
Draws a single line of text. text is the string to draw. font specifies the name of the font. material is the material to use. font_size specifies the size of the font in pixels. It should match the font size used to generate the font for pixel perfect drawing.
As rect(…), etc, but positions the objects in 3D with the transform matrix tm. This allows you to rotate the objects freely in the 3D world. Using this method, you can use a single world gui to draw objects at lots of different positions in the world which is useful. Note that with this method, the layer is specified separately from the position, so you can use the z-coordinate of the position to offset the depth of the object.
Returns two Vector3’s min and max describing the extent of the texttext when drawn with the specified font and font_size. This can be used to center or right-align the text.
The width of the text is returned in the x component of the vectors and the height of the text is returned in the z component of the vectors.
Interface to access save functionality on Windows. Note that since the object is a singleton
(there is only one SaveSystem), you don’t need to pass any SaveSystem object to the
functions. All the functions operate on the SaveSystem singleton. This interface is
described here is specific to Windows and may exist but be different on other platforms.
Asynchronous operations return a SaveToken object that is used to fetch progress
during the operation. This object should be closed to free the information that is used
during the save, otherwise the game will run out of memory eventually.
Call this function to start an auto save. An auto save is a silent save that is used
when the game knows the save game to save to and will overwrite this file silently.
filename [string]
Name of file to store. No directory needs to be specified and is not allowed. Only
a-z, 0-9 and _ is allowed in the filename.
data [table, number, string, bool or vector3]
Normally this is a table containing the stuff that needs to be saved. Supported
datatypes are tables, numbers, strings, bools and vector3s.
You must call close() on the token returned to release the memory.
Call this function to start an auto load. An auto load is a silent load that is used when
the game knows the save game to load to and will read this save game silently.pt the file.
filename [string]
Name of file to load. No directory needs to be specified and is not allowed. Only
a-z, 0-9 and _ is allowed in the filename.
You must call close() on the token returned to release the memory.
Main interface to the system used for playing multiplayer games over the network.
(Other network functionality, such as DLC, leaderboards, etc is not found here.)
The Network system is set up with one of the init-functions that determines which
network subsystem to use (LanClient, etc). You need to call one of the init functions
before you can use any other parts of the Network interface.
You can only have one network subsystem running at any one time. Once you are completely
done with using the network, you should call the corresponding shutdown() function to
shutdown the network subsystem.
After initializing the network, you use the lobby-functionality of the network subsystem
you are using to either create a new lobby or find an existing one (with a lobby browser).
When you have enough players in the lobby you can start a NetworkGame.
The NetworkGame class is used to manage a running multiplayer game. You use the same class
no matter which network subsystem you are using.
Creates a new network game. You can only have one network game running at any one time.
If you have an existing game, you must shut it down first with shutdown_game() before
creating a new one.
Note: Both the server and the client should call create_game(), the server when it starts
the game, and the client when it drops into the game.
Updates the network system. dt is the current time step.
The callback_object is a lua object that will receive callbacks from the network.
There are two types of callbacks that can be received: RPC callbacks and NetworkGame callbacks.
RPC callbacks are received whenever another network entity sends us an RPC message. A method
with the same name as the RPC message will be called in the callback_object. The first
argument to the method will be the player_id of the sender and the remaining arguments will
be the parameters of the message.
So if someone sends us the message set_score(10) it will be convert to the call
object:set_score(remote_id, 10). See the RPC class for documentation on
how to send RPC messages.
NetworkGame callbacks inform you about changes to game_objects in a game that you are
participating in. The following functions can be called:
game_object_created(id, remote_id)
The game object identified by id was created by remote_id.
game_object_destroyed(id, remote_id)
The game object identified by id was destroyed by remote_id.
game_object_migrated_to_me(id, remote_id)
You have now become the owner of the game object identified by id.remote_id is the old owner of the game object.
game_object_migrated_away(id, remote_id)
You are no longer the owner of the game object identified by id.
remote_id is the new owner of the game object.
Note that you will only receive callbacks during the update call, not at any other time.
Note
In the future it will be possible to make separate calls to receive() and transmit()
instead of a single call to update() in order to minimize network latency.
Construct a hash based on the contents of a network config. This can be used to
determine if two peers are compatible. Specify the resource name of the network
configuration as argument to the function.
Inits the network as a client running on a LAN. config should be the name of the
.network_game_config file that you want to use, it specifies the supported game objects
and RPC messages.
game_port is the network TCP/IP port you want to use for network configuration. If you specify 0, a
random free port will be picked. This is good for testing multiple network nodes on the same machine,
since it ensures port numbers won't collide.
Creates a lobby on the LAN. lobby_port is the TCP/IP port that the lobby should run on. Note that this
should not be the same as the game_port. Clients browsing for lobbies will specify the lobby_port number
so you should use a single well-known number to run the port on.
max_members is the maximum number of members allowed in the lobby.
When you create a lobby you automatically join it, you don't have to call join_lan_lobby().
Joins the lobby at the specified address. The address is a string on the format "127.0.0.1:21000".
lobby_port specifies the port that the lobby should use. There are two options. You can use 0 at let the
computer pick a random free port. This is good when you are testing multiple nodes on the same machine, because
it means the port won't collide with the public port used by create_lan_lobby().
The drawback of this is that if the lobby host quits and the lobby migrates to you, other nodes won't
find the lobby because it is running on a random port. To make the lobby publicly findable if it
migrates to you, you need to use the same public port as you use in create_lan_lobby(). But this means
that you cannot run multiple network nodes on the same machine.
Leaves the specified lobby. If you are hosting the lobby, it will migrate to a different user
in the lobby. If you are the last member of the lobby, the lobby will be removed.
The RPC class is used to make remote procedure calls to other nodes in the network.
The members of the RPC class are determined by the content of the network_game_config
file you have loaded. All the messages in the config file appear as members of the
RPC class. So if you have this in your config file:
The remote player will receive the messages as calls to the callback object he
specifies when he calls Network.update().
You don't have to create a NetworkGame in order to send RPC messages, but you must
have established a connection with the remote player (by being in the same lobby,
etc).
Note
Some way of conveniently sending messages to more than one recipient will be
added.
NetworkGame is responsible for replicating and synchronizing game objects between the players
that participate in a game session.
To the NetworkGame a game object is just a table of fields (keys and values) identified by an ID.
When you create a game object, you become its owner and get back an ID that you can
use to manipulate the object. As owner, you can change the values of the object fields. The
changes you make get replicated to all other players. If you delete the object, that too
gets replicated.
Game objects can have different types. Each type has its own set of keys and values.
The game object types are defined in the .network_game_config file.
Typically, the game objects represent something in the game world, such as units, physical
bodies, etc, but the NetworkGame layer does not care about that. It is the responsibility of
the user to move data back and forth between the network game objects and the real world
entities.
Ownership of objects can be moved between players in the game. This can be used for network
load balancing or to get a better fidelity of the play experience (the owner of an object
does not have to worry about lag or synchronization problems when interacting with it).
When a remote node has created, destroyed or migrated a game object, you get notified by a
callback to the callback object you specify when you call Network.update() see the documentation
of Network.update() for a description of these calls.
Become the server of the game. You can only call this on a game that was just created
and that doesn't have any other players in it. The server of the game is the only
one that can add players to or remove players from the game.
When you call make_server() you automatically also join the game.
Called by a client to tell the server that it wants to leave the game. After calling this you should
wait until in_game() returns false before shutting down the game. This ensures that
all other players are informed that you have left the game.
Returns true if you are in the game. If this function returns false you have been
removed from the game because of a bad connection or because the server kicked you
out. In that case you should shut down the game.
Called by the server to detect broken connections. If the connection to a player has
been broken, the function will return that player's id. The server should respond by
removing the player from the game after destroying or migrating his objects.
If all connections are good, the function will return nil.
If there are more than one broken connections you will get them by calling this function
repeatedly.
If a player has asked to leave the game, this function will return that player's id.
The server should respond by removing the player from the game after destroying or
migrating his objects.
If no one wants to leave, the function will return nil.
If there are more than one player that wants to leave, you will get them by calling
this function repeatedly.
Migrates the game object to a new owner. After this call player_id will be the new owner
of the object. This function can only be called by the game server.
callback is a callback object similar to the one passed to Network.update().
If you are migrating the object from or to yourself you will receive an immediate
game_object_migrated_away() or game_object_migrated_to_me() message to the
callback object.
Returns the unit synchronizer corresponding to the game. The unit synchronizer is a
helper class that can do automatic synchronizing between game objects and units.
You don't have to use the UnitSynchronizer if you don't want to, you can also synhronize
game objects and units manually.
Sets the interval in seconds between updates of the upload and download pies in the network perfhud.
A short interval will find spikes but will change rapidly. The default is 1.
A helper class to make it easier to synchronize units with game objects.
If you use this class it will synchronize the creation and destruction of units.
It will also synchronize the position and rotation of the units' root objects.
This class can provide a "quick-and-dirty" way of synchronizing game units
without having to handle game_object_created callbacks, etc. If you want more
detailed control over how the units are synchronized, you probably want to do
your own unit synchronization instead of using the synchronizer.
To use the unit synchronizer, the game objects you sync must have four standard
fields: synchronizer_id,unit_name,position and rotation. You can
have additional fields if you want to that you synchronize manually, outside
the scope of the unit synchronizer.
types = {
position = {type = "vector3" min = -1000 max = 1000
bits = 20 tolerance=0.05 interpolated=true}
rotation = {type = "quaternion" tolerance=0.01 interpolated=true}
unit_name = {type = "resource_id"}
synchronizer_id = {type = "int" min = 0 max = 255}
}
objects = {
unit = {
fields = [
"synchronizer_id"
"unit_name"
"position"
"rotation"
]
}
}
Returns the current state of the lobby. The state can be one of the following
values:
LanLobby.CREATING
This is the state of the lobby after it has been created with
Network.create_lan_lobby().
If the lobby is successfully
created, the state will change to LanLobby.JOINED. If the creation fails,
the state will be LanLobby.FAILED.
LanLobby.JOINING
The state of the lobby after it has been created with
Network.join_lan_lobby().
This state means the lobby is waiting for the lobby server to accept us as a
lobby member. When we are accepted the state will change to LanLobby.JOINED.
If we are not accepted, the state will be LanLobby.FAILED.
LanLobby.JOINED
The player is in the lobby.
LanLobby.FAILED
The player has dropped out of the lobby for some reason, connection problem,
rejected by the server, etc.
Each lobby can contain a number of stringvalues identified by stringkeys. You can use that to store a description of the lobby, name of the game,
map name, etc.
As set_data() but sets a data field for the current player in the lobby. The
data will be mirrored out to other members and they can use get_member_data()
to query it.
Returns the game server of the lobby or nil if no game server has been set.
If a client detects that a game server has been set, it should typically first load the
level map and then send a message to the game server saying that it wants to drop into
the game. Upon receiving that message the game server should call NetworkGame.add_client()
to add the player to the game.
Refreshes the list of game lobbies by broadcasting a search on the LAN. port is
the port number that the broadcast should search on. The search will only find LanLobbies
with a matching port number.
Returns true if the list is currently refreshing. If you are already refreshing refresh()
will do nothing. You can't refresh more than once every 3 seconds.