11#include "physfsrwops.h"
21#include "nlua_audio.h"
29#define SPFX_GLOBAL (1<<1)
30#define SPFX_RELATIVE (1<<2)
31#define SPFX_MOVING (1<<3)
32#define SPFX_AUDIO (1<<4)
33#define SPFX_CLEANUP (1<<5)
40typedef struct LuaSpfxData_s {
60static int lua_spfx_idgen = 0;
61static int lua_spfx_lock = 0;
90static int spfx_cmp(
const void *p1,
const void *p2 )
95 return s1->
id - s2->
id;
119 return (LuaSpfx_t*) lua_touserdata(L,ind);
132 luaL_typerror(L, ind, SPFX_METATABLE);
135static LuaSpfxData_t* luaL_checkspfxdataNoWarn( lua_State *L,
int ind )
145static LuaSpfxData_t* luaL_checkspfxdata( lua_State *L,
int ind )
149 NLUA_ERROR( L, _(
"Spfx does not exist.") );
161 LuaSpfx_t *la = (LuaSpfx_t*) lua_newuserdata(L,
sizeof(LuaSpfx_t));
163 luaL_getmetatable(L, SPFX_METATABLE);
164 lua_setmetatable(L, -2);
178 if (lua_getmetatable(L,ind)==0)
180 lua_getfield(L, LUA_REGISTRYINDEX, SPFX_METATABLE);
183 if (lua_rawequal(L, -1, -2))
205 ls->
data = LUA_NOREF;
213 audio_cleanup( &ls->
sfx );
251 lua_pushboolean( L, (memcmp( s1, s2,
sizeof(LuaSpfx_t) )==0) );
272 lua_rawseti( L, -2, n++ );
302 ls.
id = ++lua_spfx_idgen;
303 ls.
ttl = luaL_checknumber(L,1);
310 if (!lua_isnoneornil(L,2))
312 if (!lua_isnoneornil(L,3))
314 if (!lua_isnoneornil(L,4))
316 if (!lua_isnoneornil(L,5))
320 if (!lua_isnoneornil(L,6)) {
321 if (lua_isboolean( L, 6 )) {
323 if (!lua_toboolean( L, 6 ))
331 if (!lua_isnoneornil(L,7)) {
337 if (!lua_isnoneornil(L,8)) {
342 audio_clone( &ls.
sfx, la );
347 alSourcei( ls.
sfx.
source, AL_LOOPING, AL_FALSE );
348 alSourcef( ls.
sfx.
source, AL_REFERENCE_DISTANCE, SOUND_REFERENCE_DISTANCE );
349 alSourcef( ls.
sfx.
source, AL_MAX_DISTANCE, SOUND_MAX_DISTANCE );
351 alSourcei( ls.
sfx.
source, AL_SOURCE_RELATIVE, AL_TRUE );
353 alSourcef( ls.
sfx.
source, AL_PITCH, 1. );
359 alSourcei( ls.
sfx.
source, AL_SOURCE_RELATIVE, AL_FALSE );
364 alSourcefv( ls.
sfx.
source, AL_POSITION, alf );
368 alSourcefv( ls.
sfx.
source, AL_VELOCITY, alf );
381 ls.
radius = luaL_optnumber(L,9,-1.);
385 ls.
data = luaL_ref( L, LUA_REGISTRYINDEX );
389 if (lua_spfx_queue == NULL)
503 lua_rawgeti( L, LUA_REGISTRYINDEX, ls->
data );
525 alSourcef( ls->
sfx.
source, AL_PITCH, s );
557static void spfx_lock (
void)
562static void spfx_unlock (
void)
566 if (lua_spfx_queue==NULL)
569 for (
int i=0; i<
array_size(lua_spfx_queue); i++)
582 for (
int i=0; i<
array_size(lua_spfx_queue); i++)
587void spfxL_exit (
void)
593 lua_spfx_queue = NULL;
627 alSourcefv( ls->
sfx.
source, AL_POSITION, alf );
634 if (ls->
update == LUA_NOREF)
638 lua_rawgeti( naevL, LUA_REGISTRYINDEX, ls->
update );
640 lua_pushnumber( naevL, dt );
641 if (lua_pcall( naevL, 2, 0, 0) != 0) {
642 WARN(_(
"Spfx failed to run 'update':\n%s"), lua_tostring( naevL, -1 ));
666 pos.
y = SCREEN_H-pos.
y;
669 lua_rawgeti( naevL, LUA_REGISTRYINDEX, ls->
render_bg );
671 lua_pushnumber( naevL, pos.
x );
672 lua_pushnumber( naevL, pos.
y );
673 lua_pushnumber( naevL, z );
674 if (lua_pcall( naevL, 4, 0, 0) != 0) {
675 WARN(_(
"Spfx failed to run 'renderbg':\n%s"), lua_tostring( naevL, -1 ));
702 if ((r > 0.) && ((pos.
x < -r) || (pos.
y < -r) ||
703 (pos.
x > SCREEN_W+r) || (pos.
y > SCREEN_H+r)))
707 pos.
y = SCREEN_H-pos.
y;
710 lua_rawgeti( naevL, LUA_REGISTRYINDEX, ls->
render_mg );
712 lua_pushnumber( naevL, pos.
x );
713 lua_pushnumber( naevL, pos.
y );
714 lua_pushnumber( naevL, z );
715 if (lua_pcall( naevL, 4, 0, 0) != 0) {
716 WARN(_(
"Spfx failed to run 'rendermg':\n%s"), lua_tostring( naevL, -1 ));
743 if ((r > 0.) && ((pos.
x < -r) || (pos.
y < -r) ||
744 (pos.
x > SCREEN_W+r) || (pos.
y > SCREEN_H+r)))
748 pos.
y = SCREEN_H-pos.
y;
751 lua_rawgeti( naevL, LUA_REGISTRYINDEX, ls->
render_fg );
753 lua_pushnumber( naevL, pos.
x );
754 lua_pushnumber( naevL, pos.
y );
755 lua_pushnumber( naevL, z );
756 if (lua_pcall( naevL, 4, 0, 0) != 0) {
757 WARN(_(
"Spfx failed to run 'renderfg':\n%s"), lua_tostring( naevL, -1 ));
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_end(array)
Returns a pointer to the end of the reserved memory space.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_begin(array)
Returns a pointer to the beginning of the reserved memory space.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
double cam_getZoom(void)
Gets the camera zoom.
Header file with generic functions and naev-specifics.
void nlua_unref(lua_State *L, int idx)
Removes a reference set with nlua_ref.
int nlua_ref(lua_State *L, int idx)
Creates a new reference to a Lua structure at a position.
LuaAudio_t * lua_pushaudio(lua_State *L, LuaAudio_t audio)
Pushes a audio on the stack.
LuaAudio_t * luaL_checkaudio(lua_State *L, int ind)
Gets audio at index or raises error if there is no audio at index.
static int spfxL_new(lua_State *L)
Creates a new special effect.
static int spfxL_vel(lua_State *L)
Gets the velocity of a spfx.
static int spfxL_sfx(lua_State *L)
Gets the sound effect of a spfx.
void spfxL_rendermg(void)
Renders the Lua SPFX in the midground.
static int spfxL_setVel(lua_State *L)
Sets the velocity of a spfx.
int lua_isspfx(lua_State *L, int ind)
Checks to see if ind is a spfx.
void spfxL_setSpeedVolume(double v)
Sets the speed volume due to autonav and the likes.
static const luaL_Reg spfxL_methods[]
static int spfxL_setPos(lua_State *L)
Sets the position of a spfx.
static int spfxL_pos(lua_State *L)
Gets the position of a spfx.
static int spfxL_eq(lua_State *L)
Compares two spfxs to see if they are the same.
void spfxL_clear(void)
Clears the Lua spfx.
static void spfx_cleanup(LuaSpfxData_t *ls)
Cleans up a special effect.
static int spfxL_data(lua_State *L)
Gets the data table of a spfx.
static int spfxL_rm(lua_State *L)
Removes a special effect.
void spfxL_renderbg(void)
Renders the Lua SPFX on the background.
static LuaSpfxData_t * lua_spfx
List of special effects being handled.
void spfxL_update(double dt)
Updates the spfx.
void spfxL_renderfg(void)
Renders the Lua SPFX in the foreground.
LuaSpfx_t * luaL_checkspfx(lua_State *L, int ind)
Gets spfx at index or raises error if there is no spfx at index.
static int spfxL_getAll(lua_State *L)
Gets all the active spfx.
int nlua_loadSpfx(nlua_env env)
Loads the spfx library.
LuaSpfx_t * lua_pushspfx(lua_State *L, LuaSpfx_t spfx)
Pushes a spfx on the stack.
void spfxL_setSpeed(double s)
Sets the speed of the playing spfx sounds.
LuaSpfx_t * lua_tospfx(lua_State *L, int ind)
Gets spfx at index.
static int spfxL_gc(lua_State *L)
Lua bindings to interact with spfx.
vec2 * luaL_checkvector(lua_State *L, int ind)
Gets vector at index making sure type is valid.
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
void gl_gameToScreenCoords(double *nx, double *ny, double bx, double by)
Converts in-game coordinates to screen coordinates.
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
ALuint sound_efx_directSlot
Handles the special effects Lua-side.