21#include "nlua_pilot.h"
50 xmlNodePtr node, parent;
55 parent = doc->xmlChildrenNode;
57 ERR( _(
"Malformed '%s' file: does not contain elements"), file );
70 xmlr_attr_strd(parent,
"name",efx->
name);
71 if (efx->
name == NULL)
72 WARN(_(
"Effect '%s' has invalid or no name"), file);
74 node = parent->xmlChildrenNode;
79 xmlr_strd(node,
"description", efx->
desc);
80 xmlr_strd(node,
"overwrite", efx->
overwrite);
81 xmlr_int(node,
"priority", efx->
priority);
82 xmlr_float(node,
"duration", efx->
duration);
83 if (xml_isNode(node,
"icon")) {
87 if (xml_isNode(node,
"shader")) {
89 xmlr_attr_strd(node,
"vertex",vertex);
91 vertex = strdup(
"effect.vert");
92 efx->program = gl_program_vert_frag( vertex, xml_get(node) );
94 efx->vertex = glGetAttribLocation( efx->program,
"vertex" );
95 efx->projection= glGetUniformLocation( efx->program,
"projection" );
96 efx->tex_mat = glGetUniformLocation( efx->program,
"tex_mat" );
97 efx->dimensions= glGetUniformLocation( efx->program,
"dimensions" );
98 efx->u_r = glGetUniformLocation( efx->program,
"u_r" );
99 efx->u_tex = glGetUniformLocation( efx->program,
"u_tex" );
100 efx->u_timer = glGetUniformLocation( efx->program,
"u_timer" );
101 efx->u_elapsed = glGetUniformLocation( efx->program,
"u_elapsed" );
104 if (xml_isNode(node,
"lua")) {
107 const char *filename = xml_get(node);
110 WARN(_(
"Effect '%s' failed to read Lua '%s'!"), efx->
name, filename );
116 if (nlua_dobufenv( env, dat, sz, filename ) != 0) {
117 WARN(_(
"Effect '%s' Lua error:\n%s"), efx->
name, lua_tostring(naevL,-1));
131 if (xml_isNode(node,
"stats")) {
132 xmlNodePtr cur = node->children;
143 WARN(_(
"Effect '%s' has unknown node '%s'"), efx->
name, cur->name);
144 }
while (xml_nextNode(cur));
147 WARN(_(
"Effect '%s' has unknown node '%s'"),efx->
name, node->name);
148 }
while (xml_nextNode(node));
150#define MELEMENT(o,s) \
151if (o) WARN( _("Effect '%s' missing/invalid '%s' element"), efx->name, s)
152 MELEMENT(efx->
name==NULL,
"name");
153 MELEMENT(efx->
desc==NULL,
"description");
154 MELEMENT(efx->
duration<0.,
"duration");
155 MELEMENT(efx->
icon==NULL,
"icon");
171 Uint32 time = SDL_GetTicks();
175 for (
int i=0; i<
array_size(effect_files); i++) {
182 free( effect_files[i] );
190 time = SDL_GetTicks() - time;
191 DEBUG( n_(
"Loaded %d Effect in %.3f s",
"Loaded %d Effects in %.3f s", ne ), ne, time/1000. );
194 DEBUG( n_(
"Loaded %d Effect",
"Loaded %d Effects", ne ), ne );
204 for (
int i=0; i<
array_size(effect_list); i++) {
227 WARN(_(
"Trying to get unknown effect data '%s'!"), name);
241 for (
int i=
array_size(*efxlist)-1; i>=0; i--) {
242 Effect *e = &(*efxlist)[i];
253 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
282 if (*efxlist == NULL)
288 Effect *el = &(*efxlist)[i];
300 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
328 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"extend", lua_tostring(naevL,-1));
334 if (efx->
lua_add != LUA_NOREF) {
335 lua_rawgeti(naevL, LUA_REGISTRYINDEX, e->
data->
lua_add);
338 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"add", lua_tostring(naevL,-1));
361 for (
int i=
array_size(*efxlist)-1; i>=0; i++) {
362 const Effect *e = &(*efxlist)[i];
370 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
390 const Effect *e = &(*efxlist)[i];
396 WARN(_(
"Effect '%s' failed to run '%s':\n%s"), e->
data->
name,
"remove", lua_tostring(naevL,-1));
413 const Effect *e = &efxlist[i];
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_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#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’.
static int effect_cmp(const void *p1, const void *p2)
Compares effects based on name.
int effect_rm(Effect **efxlist, const EffectData *efx, int all)
Removes an effect from an effect list.
static int effect_parse(EffectData *efx, const char *file)
Parsess an effect.
const EffectData * effect_get(const char *name)
Gets an effect by name.
void effect_cleanup(Effect *efxlist)
Cleans up an effect list freeing it.
void effect_clear(Effect **efxlist)
Clears an effect list, removing all active effects.
int effect_add(Effect **efxlist, const EffectData *efx, double duration, double scale, unsigned int parent)
Adds an effect to an effect list.
static int effect_cmpTimer(const void *p1, const void *p2)
Compares effects based on timer.
void effect_compute(ShipStats *s, const Effect *efxlist)
Updates shipstats from effect list.
int effect_load(void)
Loads all the effects.
void effect_exit(void)
Gets rid of all the effects.
int effect_update(Effect **efxlist, double dt)
Updates an effect list.
Header file with generic functions and naev-specifics.
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
int ndata_matchExt(const char *path, const char *ext)
Sees if a file matches an extension.
char ** ndata_listRecursive(const char *path)
Lists all the visible files in a directory, at any depth.
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
int nlua_refenvtype(nlua_env env, const char *name, int type)
Gets the reference of a global in a lua environment if it matches a type.
LuaPilot * lua_pushpilot(lua_State *L, LuaPilot pilot)
Pushes a pilot on the stack.
glTexture * xml_parseTexture(xmlNodePtr node, const char *path, int defsx, int defsy, const unsigned int flags)
Parses a texture handling the sx and sy elements.
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
void gl_freeTexture(glTexture *texture)
Frees a texture.
void ss_free(ShipStatList *ll)
Frees a list of ship stats.
int ss_statsModFromListScale(ShipStats *stats, const ShipStatList *list, double scale)
Updates a stat structure from a stat list.
ShipStatList * ss_listFromXML(xmlNodePtr node)
Creates a shipstat list element from an xml node.
Represents relative ship statistics as a linked list.
struct ShipStatList_ * next
Represents ship statistics, properties ship can use.