naev 0.10.4
Data Structures | Macros | Functions | Variables
nlua_spfx.c File Reference

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

#include "nlua_spfx.h"
#include "conf.h"
#include "camera.h"
#include "array.h"
#include "nlua_audio.h"
#include "nlua_vec2.h"
#include "nluadef.h"
#include "sound.h"
#include "opengl.h"
#include "nopenal.h"
#include "player.h"

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. More...
 
static int spfxL_eq (lua_State *L)
 Compares two spfxs to see if they are the same. More...
 
static int spfxL_getAll (lua_State *L)
 Gets all the active spfx. More...
 
static int spfxL_new (lua_State *L)
 Creates a new special effect. More...
 
static int spfxL_rm (lua_State *L)
 Removes a special effect. More...
 
static int spfxL_pos (lua_State *L)
 Gets the position of a spfx. More...
 
static int spfxL_vel (lua_State *L)
 Gets the velocity of a spfx. More...
 
static int spfxL_setPos (lua_State *L)
 Sets the position of a spfx. More...
 
static int spfxL_setVel (lua_State *L)
 Sets the velocity of a spfx. More...
 
static int spfxL_sfx (lua_State *L)
 Gets the sound effect of a spfx. More...
 
static int spfxL_data (lua_State *L)
 Gets the data table of a spfx. More...
 
static int spfx_cmp (const void *p1, const void *p2)
 
int nlua_loadSpfx (nlua_env env)
 Loads the spfx library. More...
 
LuaSpfx_t * lua_tospfx (lua_State *L, int ind)
 Gets spfx at index. More...
 
LuaSpfx_t * luaL_checkspfx (lua_State *L, int ind)
 Gets spfx at index or raises error if there is no spfx at index. More...
 
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. More...
 
int lua_isspfx (lua_State *L, int ind)
 Checks to see if ind is a spfx. More...
 
static void spfx_cleanup (LuaSpfxData_t *ls)
 Cleans up a special effect. More...
 
void spfxL_setSpeed (double s)
 Sets the speed of the playing spfx sounds. More...
 
void spfxL_setSpeedVolume (double v)
 Sets the speed volume due to autonav and the likes. More...
 
static void spfx_lock (void)
 
static void spfx_unlock (void)
 
void spfxL_clear (void)
 Clears the Lua spfx. More...
 
void spfxL_exit (void)
 
void spfxL_update (double dt)
 Updates the spfx. More...
 
void spfxL_renderbg (void)
 Renders the Lua SPFX on the background. More...
 
void spfxL_rendermg (void)
 Renders the Lua SPFX in the midground. More...
 
void spfxL_renderfg (void)
 Renders the Lua SPFX in the foreground. More...
 

Variables

static LuaSpfxData_tlua_spfx = NULL
 List of special effects being handled. More...
 
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 32 of file nlua_spfx.c.

◆ SPFX_CLEANUP

#define SPFX_CLEANUP   (1<<5)

Spfx has to be cleaned up.

Definition at line 33 of file nlua_spfx.c.

◆ SPFX_GLOBAL

#define SPFX_GLOBAL   (1<<1)

Spfx sound ignores pitch changes.

Definition at line 29 of file nlua_spfx.c.

◆ SPFX_MOVING

#define SPFX_MOVING   (1<<3)

Spfx is moving.

Definition at line 31 of file nlua_spfx.c.

◆ SPFX_RELATIVE

#define SPFX_RELATIVE   (1<<2)

Spfx is relative.

Definition at line 30 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 174 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 159 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 117 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 128 of file nlua_spfx.c.

◆ luaL_checkspfxdata()

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

Definition at line 145 of file nlua_spfx.c.

◆ luaL_checkspfxdataNoWarn()

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

Definition at line 135 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 104 of file nlua_spfx.c.

◆ spfx_cleanup()

static void spfx_cleanup ( LuaSpfxData_t ls)
static

Cleans up a special effect.

Parameters
lsSpecial effect to clean up.

Definition at line 195 of file nlua_spfx.c.

◆ spfx_cmp()

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

Definition at line 90 of file nlua_spfx.c.

◆ spfx_lock()

static void spfx_lock ( void  )
static

Definition at line 557 of file nlua_spfx.c.

◆ spfx_unlock()

static void spfx_unlock ( void  )
static

Definition at line 562 of file nlua_spfx.c.

◆ spfxL_clear()

void spfxL_clear ( void  )

Clears the Lua spfx.

Definition at line 577 of file nlua_spfx.c.

◆ spfxL_data()

static 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 500 of file nlua_spfx.c.

◆ spfxL_eq()

static 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 246 of file nlua_spfx.c.

◆ spfxL_exit()

void spfxL_exit ( void  )

Definition at line 587 of file nlua_spfx.c.

◆ spfxL_gc()

static 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 231 of file nlua_spfx.c.

◆ spfxL_getAll()

static 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 261 of file nlua_spfx.c.

◆ spfxL_new()

static 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: Function|nil update Update function to use if applicable. Lua function parameter: Function|nil render_bg Background render function to use if applicable (behind ships). Lua function parameter: Function|nil render_mg Middle render function to use if applicable (infront of NPC ships, behind player). Lua function parameter: Function|nil render_fg Foregroundrender function to use if applicable (infront of player). Lua function parameter: vec2|boolean pos Position of the effect, or a boolean to indicate whether or not the effect is local. Lua function parameter: vec2 vel Velocity of the effect. Lua function parameter: audio sfx Sound effect associated with the spfx. Lua function parameter: number radius Radius to use to determine if should render. 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 296 of file nlua_spfx.c.

◆ spfxL_pos()

static 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 426 of file nlua_spfx.c.

◆ spfxL_renderbg()

void spfxL_renderbg ( void  )

Renders the Lua SPFX on the background.

Definition at line 652 of file nlua_spfx.c.

◆ spfxL_renderfg()

void spfxL_renderfg ( void  )

Renders the Lua SPFX in the foreground.

Definition at line 726 of file nlua_spfx.c.

◆ spfxL_rendermg()

void spfxL_rendermg ( void  )

Renders the Lua SPFX in the midground.

Definition at line 685 of file nlua_spfx.c.

◆ spfxL_rm()

static 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 409 of file nlua_spfx.c.

◆ spfxL_setPos()

static 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 454 of file nlua_spfx.c.

◆ spfxL_setSpeed()

void spfxL_setSpeed ( double  s)

Sets the speed of the playing spfx sounds.

Definition at line 510 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 536 of file nlua_spfx.c.

◆ spfxL_setVel()

static 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 469 of file nlua_spfx.c.

◆ spfxL_sfx()

static 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 484 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 601 of file nlua_spfx.c.

◆ spfxL_vel()

static 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 440 of file nlua_spfx.c.

Variable Documentation

◆ lua_spfx

LuaSpfxData_t* lua_spfx = NULL
static

List of special effects being handled.

Definition at line 58 of file nlua_spfx.c.

◆ lua_spfx_idgen

int lua_spfx_idgen = 0
static

Definition at line 60 of file nlua_spfx.c.

◆ lua_spfx_lock

int lua_spfx_lock = 0
static

Definition at line 61 of file nlua_spfx.c.

◆ lua_spfx_queue

LuaSpfxData_t* lua_spfx_queue = NULL
static

Definition at line 59 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 },
{0,0}
}
static int spfxL_new(lua_State *L)
Creates a new special effect.
Definition: nlua_spfx.c:296
static int spfxL_vel(lua_State *L)
Gets the velocity of a spfx.
Definition: nlua_spfx.c:440
static int spfxL_sfx(lua_State *L)
Gets the sound effect of a spfx.
Definition: nlua_spfx.c:484
static int spfxL_setVel(lua_State *L)
Sets the velocity of a spfx.
Definition: nlua_spfx.c:469
static int spfxL_setPos(lua_State *L)
Sets the position of a spfx.
Definition: nlua_spfx.c:454
static int spfxL_pos(lua_State *L)
Gets the position of a spfx.
Definition: nlua_spfx.c:426
static int spfxL_eq(lua_State *L)
Compares two spfxs to see if they are the same.
Definition: nlua_spfx.c:246
static int spfxL_data(lua_State *L)
Gets the data table of a spfx.
Definition: nlua_spfx.c:500
static int spfxL_rm(lua_State *L)
Removes a special effect.
Definition: nlua_spfx.c:409
static int spfxL_getAll(lua_State *L)
Gets all the active spfx.
Definition: nlua_spfx.c:261
static int spfxL_gc(lua_State *L)
Lua bindings to interact with spfx.
Definition: nlua_spfx.c:231

SpfxLua methods.

Definition at line 75 of file nlua_spfx.c.