naev 0.12.5
nlua_spfx.c File Reference

Bindings for Special effects functionality from Lua. More...

#include "nlua_spfx.h"
#include "array.h"
#include "camera.h"
#include "debris.h"
#include "nlua_audio.h"
#include "nlua_colour.h"
#include "nlua_vec2.h"
#include "nluadef.h"
#include "nopenal.h"
#include "ntracing.h"
#include "opengl.h"
#include "player.h"
#include "sound.h"
Include dependency graph for nlua_spfx.c:

Go to the source code of this file.

Data Structures

struct  LuaSpfxData_t
 Handles the special effects Lua-side. More...

Macros

#define SPFX_GLOBAL   ( 1 << 1 )
#define SPFX_RELATIVE   ( 1 << 2 )
#define SPFX_MOVING   ( 1 << 3 )
#define SPFX_AUDIO   ( 1 << 4 )
#define SPFX_CLEANUP   ( 1 << 5 )

Functions

static int spfxL_gc (lua_State *L)
 Lua bindings to interact with spfx.
static int spfxL_eq (lua_State *L)
 Compares two spfxs to see if they are the same.
static int spfxL_getAll (lua_State *L)
 Gets all the active spfx.
static int spfxL_new (lua_State *L)
 Creates a new special effect.
static int spfxL_rm (lua_State *L)
 Removes a special effect.
static int spfxL_pos (lua_State *L)
 Gets the position of a spfx.
static int spfxL_vel (lua_State *L)
 Gets the velocity of a spfx.
static int spfxL_setPos (lua_State *L)
 Sets the position of a spfx.
static int spfxL_setVel (lua_State *L)
 Sets the velocity of a spfx.
static int spfxL_sfx (lua_State *L)
 Gets the sound effect of a spfx.
static int spfxL_data (lua_State *L)
 Gets the data table of a spfx.
static int spfxL_debris (lua_State *L)
 Creates a cloud of debris.
static int spfxL_nebulaColour (lua_State *L)
 Sets the nebula colour.
static int spfx_cmp (const void *p1, const void *p2)
int nlua_loadSpfx (nlua_env env)
 Loads the spfx library.
LuaSpfx_t * lua_tospfx (lua_State *L, int ind)
 Gets spfx at index.
LuaSpfx_t * luaL_checkspfx (lua_State *L, int ind)
 Gets spfx at index or raises error if there is no spfx at index.
static LuaSpfxData_tluaL_checkspfxdataNoWarn (lua_State *L, int ind)
static LuaSpfxData_tluaL_checkspfxdata (lua_State *L, int ind)
LuaSpfx_t * lua_pushspfx (lua_State *L, LuaSpfx_t spfx)
 Pushes a spfx on the stack.
int lua_isspfx (lua_State *L, int ind)
 Checks to see if ind is a spfx.
static void spfx_cleanup (LuaSpfxData_t *ls)
 Cleans up a special effect.
void spfxL_setSpeed (double s)
 Sets the speed of the playing spfx sounds.
void spfxL_setSpeedVolume (double v)
 Sets the speed volume due to autonav and the likes.
static void spfx_lock (void)
static void spfx_unlock (void)
void spfxL_clear (void)
 Clears the Lua spfx.
void spfxL_exit (void)
void spfxL_update (double dt)
 Updates the spfx.
static void spfxL_renderLayer (int func, const char *funcname, double dt)
void spfxL_renderbg (double dt)
 Renders the Lua SPFX on the background.
void spfxL_rendermg (double dt)
 Renders the Lua SPFX in the midground.
void spfxL_renderfg (double dt)
 Renders the Lua SPFX in the foreground.

Variables

static LuaSpfxData_tlua_spfx = NULL
 List of special effects being handled.
static LuaSpfxData_tlua_spfx_queue = NULL
static int lua_spfx_idgen = 0
static int lua_spfx_lock = 0
static const luaL_Reg spfxL_methods []

Detailed Description

Bindings for Special effects functionality from Lua.

Definition in file nlua_spfx.c.

Macro Definition Documentation

◆ SPFX_AUDIO

#define SPFX_AUDIO   ( 1 << 4 )

Spfx has audio.

Definition at line 31 of file nlua_spfx.c.

◆ SPFX_CLEANUP

#define SPFX_CLEANUP   ( 1 << 5 )

Spfx has to be cleaned up.

Definition at line 32 of file nlua_spfx.c.

◆ SPFX_GLOBAL

#define SPFX_GLOBAL   ( 1 << 1 )

Spfx sound ignores pitch changes.

Definition at line 28 of file nlua_spfx.c.

◆ SPFX_MOVING

#define SPFX_MOVING   ( 1 << 3 )

Spfx is moving.

Definition at line 30 of file nlua_spfx.c.

◆ SPFX_RELATIVE

#define SPFX_RELATIVE   ( 1 << 2 )

Spfx is relative.

Definition at line 29 of file nlua_spfx.c.

Function Documentation

◆ lua_isspfx()

int lua_isspfx ( lua_State * L,
int ind )

Checks to see if ind is a spfx.

Parameters
LLua state to check.
indIndex position to check.
Returns
1 if ind is a spfx.

Definition at line 185 of file nlua_spfx.c.

◆ lua_pushspfx()

LuaSpfx_t * lua_pushspfx ( lua_State * L,
LuaSpfx_t spfx )

Pushes a spfx on the stack.

Parameters
LLua state to push spfx into.
spfxSpfx to push.
Returns
Newly pushed spfx.

Definition at line 170 of file nlua_spfx.c.

◆ lua_tospfx()

LuaSpfx_t * lua_tospfx ( lua_State * L,
int ind )

Gets spfx at index.

Parameters
LLua state to get spfx from.
indIndex position to find the spfx.
Returns
Spfx found at the index in the state.

Definition at line 126 of file nlua_spfx.c.

◆ luaL_checkspfx()

LuaSpfx_t * luaL_checkspfx ( lua_State * L,
int ind )

Gets spfx at index or raises error if there is no spfx at index.

Parameters
LLua state to get spfx from.
indIndex position to find spfx.
Returns
Spfx found at the index in the state.

Definition at line 137 of file nlua_spfx.c.

◆ luaL_checkspfxdata()

LuaSpfxData_t * luaL_checkspfxdata ( lua_State * L,
int ind )
static

Definition at line 156 of file nlua_spfx.c.

◆ luaL_checkspfxdataNoWarn()

LuaSpfxData_t * luaL_checkspfxdataNoWarn ( lua_State * L,
int ind )
static

Definition at line 144 of file nlua_spfx.c.

◆ nlua_loadSpfx()

int nlua_loadSpfx ( nlua_env env)

Loads the spfx library.

Parameters
envLua environment.
Returns
0 on success.

Definition at line 113 of file nlua_spfx.c.

◆ spfx_cleanup()

void spfx_cleanup ( LuaSpfxData_t * ls)
static

Cleans up a special effect.

Parameters
lsSpecial effect to clean up.

Definition at line 206 of file nlua_spfx.c.

◆ spfx_cmp()

int spfx_cmp ( const void * p1,
const void * p2 )
static

Definition at line 100 of file nlua_spfx.c.

◆ spfx_lock()

void spfx_lock ( void )
static

Definition at line 615 of file nlua_spfx.c.

◆ spfx_unlock()

void spfx_unlock ( void )
static

Definition at line 620 of file nlua_spfx.c.

◆ spfxL_clear()

void spfxL_clear ( void )

Clears the Lua spfx.

Definition at line 636 of file nlua_spfx.c.

◆ spfxL_data()

int spfxL_data ( lua_State * L)
static

Gets the data table of a spfx.

This table is unique to each instance.

Lua function parameter: spfx s Spfx to get data table of. Lua return parameter: table Data table of the spfx.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: data

Definition at line 550 of file nlua_spfx.c.

◆ spfxL_debris()

int spfxL_debris ( lua_State * L)
static

Creates a cloud of debris.

Lua function parameter: number mass Mass of the cloud. Lua function parameter: number radius Radius of the cloud. Lua function parameter: Vec2 pos Position of the cloud. Lua function parameter: Vec2 vel Velocity of the cloud.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: debris

Definition at line 814 of file nlua_spfx.c.

◆ spfxL_eq()

int spfxL_eq ( lua_State * L)
static

Compares two spfxs to see if they are the same.

Lua function parameter: Spfx s1 Spfx 1 to compare. Lua function parameter: Spfx s2 Spfx 2 to compare. Lua return parameter: boolean true if both spfxs are the same.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __eq

Definition at line 259 of file nlua_spfx.c.

◆ spfxL_exit()

void spfxL_exit ( void )

Definition at line 647 of file nlua_spfx.c.

◆ spfxL_gc()

int spfxL_gc ( lua_State * L)
static

Lua bindings to interact with spfx.

Lua module: spfx

Frees a spfx.

Lua function parameter: Spfx spfx Spfx to free.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: __gc

Definition at line 244 of file nlua_spfx.c.

◆ spfxL_getAll()

int spfxL_getAll ( lua_State * L)
static

Gets all the active spfx.

Lua return parameter: table A table containing all the spfx.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: getAll

Definition at line 274 of file nlua_spfx.c.

◆ spfxL_nebulaColour()

int spfxL_nebulaColour ( lua_State * L)
static

Sets the nebula colour.

Lua usage parameter: spfx.nebulaColour( 0.3, 0.5, 0.8 ) Lua usage parameter: spfx.nebulaColour( colour.new( 0.3, 0.5, 0.8 ) )

Lua function parameter: Colour|number col Colour to set.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: nebulaColour

Definition at line 833 of file nlua_spfx.c.

◆ spfxL_new()

int spfxL_new ( lua_State * L)
static

Creates a new special effect.

Lua usage parameter: spfx.new( 5, update, nil, nil, render, player.pos(), player.pilot():vel(), sfx ) – Play effect with update and render functions at player position/velocity Lua usage parameter: spfx.new( 10, nil, nil, nil, nil, true, nil, sfx ) – Play an effect locally (affected by time compression and autonav stuff) Lua usage parameter: spfx.new( 10, nil, nil, nil, nil, nil, nil, sfx ) – Play a global effect (not affected by time stuff )

Lua function parameter: Number ttl Time to live of the effect. Lua function parameter:[opt] Function|nil update Update function to use if applicable. Lua function parameter:[opt] Function|nil render_bg Background render function to use if applicable (behind ships). Lua function parameter:[opt] Function|nil render_mg Middle render function to use if applicable (infront of NPC ships, behind player). Lua function parameter:[opt] Function|nil render_fg Foregroundrender function to use if applicable (infront of player). Lua function parameter:[opt] vec2|boolean pos Position of the effect, or a boolean to indicate whether or not the effect is local. Lua function parameter:[opt] vec2 vel Velocity of the effect. Lua function parameter:[opt] audio sfx Sound effect associated with the spfx. Lua function parameter:[opt] number radius Radius to use to determine if should render. Lua function parameter:[opt] Function|nil remove Function to run when removing the outfit. Lua return parameter: spfx New spfx corresponding to the data.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: new

Definition at line 319 of file nlua_spfx.c.

◆ spfxL_pos()

int spfxL_pos ( lua_State * L)
static

Gets the position of a spfx.

Lua function parameter: spfx s Spfx to get position of. Lua return parameter: vec2 Position of the spfx.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: pos( s )

Definition at line 476 of file nlua_spfx.c.

◆ spfxL_renderbg()

void spfxL_renderbg ( double dt)

Renders the Lua SPFX on the background.

Definition at line 778 of file nlua_spfx.c.

◆ spfxL_renderfg()

void spfxL_renderfg ( double dt)

Renders the Lua SPFX in the foreground.

Definition at line 798 of file nlua_spfx.c.

◆ spfxL_renderLayer()

void spfxL_renderLayer ( int func,
const char * funcname,
double dt )
static

Definition at line 717 of file nlua_spfx.c.

◆ spfxL_rendermg()

void spfxL_rendermg ( double dt)

Renders the Lua SPFX in the midground.

Definition at line 788 of file nlua_spfx.c.

◆ spfxL_rm()

int spfxL_rm ( lua_State * L)
static

Removes a special effect.

Lua function parameter: spfx s Spfx to remove.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: rm

Definition at line 447 of file nlua_spfx.c.

◆ spfxL_setPos()

int spfxL_setPos ( lua_State * L)
static

Sets the position of a spfx.

Lua function parameter: spfx s Spfx to set the position of. Lua function parameter: vec2 p Position to set to.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setPos

Definition at line 504 of file nlua_spfx.c.

◆ spfxL_setSpeed()

void spfxL_setSpeed ( double s)

Sets the speed of the playing spfx sounds.

Definition at line 560 of file nlua_spfx.c.

◆ spfxL_setSpeedVolume()

void spfxL_setSpeedVolume ( double v)

Sets the speed volume due to autonav and the likes.

Parameters
vSpeed volume to use.

Definition at line 590 of file nlua_spfx.c.

◆ spfxL_setVel()

int spfxL_setVel ( lua_State * L)
static

Sets the velocity of a spfx.

Lua function parameter: spfx s Spfx to set the velocity of. Lua function parameter: vec2 v Velocity to set to.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: setVel

Definition at line 519 of file nlua_spfx.c.

◆ spfxL_sfx()

int spfxL_sfx ( lua_State * L)
static

Gets the sound effect of a spfx.

Lua function parameter: spfx s Spfx to get sound effect of. Lua return parameter: audio Sound effect of the spfx.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: vel

Definition at line 534 of file nlua_spfx.c.

◆ spfxL_update()

void spfxL_update ( double dt)

Updates the spfx.

Lua function parameter: dt Delta tick to use for the update.

Definition at line 661 of file nlua_spfx.c.

◆ spfxL_vel()

int spfxL_vel ( lua_State * L)
static

Gets the velocity of a spfx.

Lua function parameter: spfx s Spfx to get velocity of. Lua return parameter: vec2 Velocity of the spfx.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: vel

Definition at line 490 of file nlua_spfx.c.

Variable Documentation

◆ lua_spfx

LuaSpfxData_t* lua_spfx = NULL
static

List of special effects being handled.

Definition at line 64 of file nlua_spfx.c.

◆ lua_spfx_idgen

int lua_spfx_idgen = 0
static

Definition at line 66 of file nlua_spfx.c.

◆ lua_spfx_lock

int lua_spfx_lock = 0
static

Definition at line 67 of file nlua_spfx.c.

◆ lua_spfx_queue

LuaSpfxData_t* lua_spfx_queue = NULL
static

Definition at line 65 of file nlua_spfx.c.

◆ spfxL_methods

const luaL_Reg spfxL_methods[]
static
Initial value:
= {
{ "__gc", spfxL_gc },
{ "__eq", spfxL_eq },
{ "getAll", spfxL_getAll },
{ "new", spfxL_new },
{ "rm", spfxL_rm },
{ "pos", spfxL_pos },
{ "vel", spfxL_vel },
{ "setPos", spfxL_setPos },
{ "setVel", spfxL_setVel },
{ "sfx", spfxL_sfx },
{ "data", spfxL_data },
{ "debris", spfxL_debris },
{ "nebulaColour", spfxL_nebulaColour },
{ 0, 0 } }
static int spfxL_new(lua_State *L)
Creates a new special effect.
Definition nlua_spfx.c:319
static int spfxL_vel(lua_State *L)
Gets the velocity of a spfx.
Definition nlua_spfx.c:490
static int spfxL_sfx(lua_State *L)
Gets the sound effect of a spfx.
Definition nlua_spfx.c:534
static int spfxL_setVel(lua_State *L)
Sets the velocity of a spfx.
Definition nlua_spfx.c:519
static int spfxL_nebulaColour(lua_State *L)
Sets the nebula colour.
Definition nlua_spfx.c:833
static int spfxL_setPos(lua_State *L)
Sets the position of a spfx.
Definition nlua_spfx.c:504
static int spfxL_pos(lua_State *L)
Gets the position of a spfx.
Definition nlua_spfx.c:476
static int spfxL_eq(lua_State *L)
Compares two spfxs to see if they are the same.
Definition nlua_spfx.c:259
static int spfxL_data(lua_State *L)
Gets the data table of a spfx.
Definition nlua_spfx.c:550
static int spfxL_rm(lua_State *L)
Removes a special effect.
Definition nlua_spfx.c:447
static int spfxL_debris(lua_State *L)
Creates a cloud of debris.
Definition nlua_spfx.c:814
static int spfxL_getAll(lua_State *L)
Gets all the active spfx.
Definition nlua_spfx.c:274
static int spfxL_gc(lua_State *L)
Lua bindings to interact with spfx.
Definition nlua_spfx.c:244

SpfxLua methods.

Definition at line 84 of file nlua_spfx.c.