naev 0.11.5
spfx.c File Reference

Handles the special effects. More...

#include "spfx.h"
#include "conf.h"
#include "array.h"
#include "camera.h"
#include "debris.h"
#include "log.h"
#include "ndata.h"
#include "nxml.h"
#include "opengl.h"
#include "pause.h"
#include "physics.h"
#include "perlin.h"
#include "render.h"
#include "rng.h"
#include "space.h"
#include "nlua_shader.h"
#include "nlua_spfx.h"

Go to the source code of this file.

Data Structures

struct  SPFX_Base
 Generic special effect. More...
 
struct  SPFX
 An actual in-game active special effect. More...
 

Macros

#define SPFX_XML_ID   "spfx"
 
#define SHAKE_MASS   (1./400.) /** Shake mass. */
 
#define SHAKE_K   (1./50.)
 
#define SHAKE_B   (3.*sqrt(SHAKE_K*SHAKE_MASS))
 
#define HAPTIC_UPDATE_INTERVAL   0.1
 
#define TRAIL_UPDATE_DT   0.05
 
#define MELEMENT(o, s)
 
#define MELEMENT(o, s)
 

Functions

static int trailSpec_load (void)
 Loads the trail colour sets.
 
static int trailSpec_parse (TrailSpec *tc, const char *file, int firstpass)
 Parses raw values out of a "trail" element.
 
static TrailSpectrailSpec_getRaw (const char *name)
 
static void spfx_updateShake (double dt)
 Updates the shake position.
 
static void spfx_updateDamage (double dt)
 
static int spfx_base_cmp (const void *p1, const void *p2)
 For sorting and stuff.
 
static int spfx_base_parse (SPFX_Base *temp, const char *filename)
 Parses an xml node containing a SPFX.
 
static void spfx_base_free (SPFX_Base *effect)
 Frees a SPFX_Base.
 
static void spfx_update_layer (SPFX *layer, const double dt)
 Updates an individual spfx.
 
static int spfx_hapticInit (void)
 Initializes the rumble effect.
 
static void spfx_hapticRumble (double mod)
 Runs a rumble effect.
 
static void spfx_update_trails (double dt)
 Updates all trails (handling dispersal/fadeout).
 
static void spfx_trail_update (Trail_spfx *trail, double dt)
 Updates a trail.
 
static void spfx_trail_free (Trail_spfx *trail)
 Deallocates an unreferenced, expired trail.
 
int spfx_get (const char *name)
 Gets the id of an spfx based on name.
 
int spfx_load (void)
 Loads the spfx stack.
 
void spfx_free (void)
 Frees the spfx stack.
 
void spfx_add (int effect, const double px, const double py, const double vx, const double vy, int layer)
 Creates a new special effect.
 
void spfx_clear (void)
 Clears all the currently running effects.
 
void spfx_update (const double dt, const double real_dt)
 Updates all the spfx.
 
Trail_spfxspfx_trail_create (const TrailSpec *spec)
 Initalizes a trail.
 
void spfx_trail_sample (Trail_spfx *trail, double x, double y, TrailMode mode, int force)
 Makes a trail grow.
 
void spfx_trail_remove (Trail_spfx *trail)
 Removes a trail.
 
void spfx_trail_draw (const Trail_spfx *trail)
 Draws a trail on screen.
 
void spfx_shake (double mod)
 Increases the current rumble level.
 
void spfx_damage (double mod)
 Increases the current damage level.
 
void spfx_cinematic (void)
 Sets the cinematic mode.
 
static void spfx_renderStack (SPFX *spfx_stack)
 
void spfx_render (int layer, double dt)
 Renders the entire spfx layer.
 
const TrailSpectrailSpec_get (const char *name)
 Gets a trail spec by name.
 

Variables

static TrailSpectrail_spec_stack
 
static Trail_spfx ** trail_spfx_stack
 
static unsigned int shake_shader_pp_id = 0
 
static LuaShader_t shake_shader
 
static vec2 shake_pos = { .x = 0., .y = 0. }
 
static vec2 shake_vel = { .x = 0., .y = 0. }
 
static double shake_force_mod = 0.
 
static double shake_force_mean = 0.
 
static float shake_force_ang = 0.
 
static perlin_data_t * shake_noise = NULL
 
SDL_Haptic * haptic
 
unsigned int haptic_query
 
static int haptic_rumble = -1
 
static SDL_HapticEffect haptic_rumbleEffect
 
static double haptic_lastUpdate = 0.
 
static unsigned int damage_shader_pp_id = 0
 
static LuaShader_t damage_shader
 
static double damage_strength = 0.
 
static SPFX_Basespfx_effects = NULL
 
static SPFXspfx_stack_front = NULL
 
static SPFXspfx_stack_middle = NULL
 
static SPFXspfx_stack_back = NULL
 

Detailed Description

Handles the special effects.

Definition in file spfx.c.

Macro Definition Documentation

◆ HAPTIC_UPDATE_INTERVAL

#define HAPTIC_UPDATE_INTERVAL   0.1

Time between haptic updates.

Definition at line 45 of file spfx.c.

◆ MELEMENT [1/2]

#define MELEMENT ( o,
s )
Value:
if (o) WARN( _("SPFX '%s' missing/invalid '%s' element"), temp->name, s)

◆ MELEMENT [2/2]

#define MELEMENT ( o,
s )
Value:
if (o) WARN(_("Trail '%s' missing '%s' element"), tc->name, s)

◆ SHAKE_B

#define SHAKE_B   (3.*sqrt(SHAKE_K*SHAKE_MASS))

Constant for virtual dampener.

Definition at line 43 of file spfx.c.

◆ SHAKE_K

#define SHAKE_K   (1./50.)

Constant for virtual spring.

Definition at line 42 of file spfx.c.

◆ SHAKE_MASS

#define SHAKE_MASS   (1./400.) /** Shake mass. */

Definition at line 41 of file spfx.c.

◆ SPFX_XML_ID

#define SPFX_XML_ID   "spfx"

SPFX XML node tag.

Definition at line 36 of file spfx.c.

◆ TRAIL_UPDATE_DT

#define TRAIL_UPDATE_DT   0.05

Rate (in seconds) at which trail is updated.

Definition at line 48 of file spfx.c.

Function Documentation

◆ spfx_add()

void spfx_add ( int effect,
const double px,
const double py,
const double vx,
const double vy,
int layer )

Creates a new special effect.

Parameters
effectBase effect identifier to use.
pxX position of the effect.
pyY position of the effect.
vxX velocity of the effect.
vyY velocity of the effect.
layerLayer to put the effect on.

Definition at line 475 of file spfx.c.

◆ spfx_base_cmp()

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

For sorting and stuff.

Definition at line 157 of file spfx.c.

◆ spfx_base_free()

static void spfx_base_free ( SPFX_Base * effect)
static

Frees a SPFX_Base.

Parameters
effectSPFX_Base to free.

Definition at line 330 of file spfx.c.

◆ spfx_base_parse()

static int spfx_base_parse ( SPFX_Base * temp,
const char * filename )
static

Parses an xml node containing a SPFX.

Parameters
tempAddress to load SPFX into.
filenameName of the file to parse.
Returns
0 on success.

Definition at line 171 of file spfx.c.

◆ spfx_cinematic()

void spfx_cinematic ( void )

Sets the cinematic mode.

Should be run at the end of the render loop if needed.

Definition at line 1006 of file spfx.c.

◆ spfx_clear()

void spfx_clear ( void )

Clears all the currently running effects.

Definition at line 522 of file spfx.c.

◆ spfx_damage()

void spfx_damage ( double mod)

Increases the current damage level.

Damage will decay over time.

Parameters
modModifier to increase the level by.

Definition at line 918 of file spfx.c.

◆ spfx_free()

void spfx_free ( void )

Frees the spfx stack.

Definition at line 424 of file spfx.c.

◆ spfx_get()

int spfx_get ( const char * name)

Gets the id of an spfx based on name.

Parameters
nameName to match.
Returns
ID of the special effect or -1 on error.

Definition at line 342 of file spfx.c.

◆ spfx_hapticInit()

static int spfx_hapticInit ( void )
static

Initializes the rumble effect.

Returns
0 on success.

Definition at line 932 of file spfx.c.

◆ spfx_hapticRumble()

static void spfx_hapticRumble ( double mod)
static

Runs a rumble effect.

Current modifier being added.

Definition at line 964 of file spfx.c.

◆ spfx_load()

int spfx_load ( void )

Loads the spfx stack.

Returns
0 on success.
Todo
Make spfx not hard-coded.

Definition at line 360 of file spfx.c.

◆ spfx_render()

void spfx_render ( int layer,
double dt )

Renders the entire spfx layer.

Parameters
layerLayer to render.
dtDelta tick during rendering.

Definition at line 1093 of file spfx.c.

◆ spfx_renderStack()

static void spfx_renderStack ( SPFX * spfx_stack)
static

Definition at line 1012 of file spfx.c.

◆ spfx_shake()

void spfx_shake ( double mod)

Increases the current rumble level.

Rumble will decay over time.

Parameters
modModifier to increase the level by.

Definition at line 898 of file spfx.c.

◆ spfx_trail_create()

Trail_spfx * spfx_trail_create ( const TrailSpec * spec)

Initalizes a trail.

Returns
Pointer to initialized trail. When done (due e.g. to pilot death), call spfx_trail_remove.

Definition at line 688 of file spfx.c.

◆ spfx_trail_draw()

void spfx_trail_draw ( const Trail_spfx * trail)

Draws a trail on screen.

Definition at line 811 of file spfx.c.

◆ spfx_trail_free()

static void spfx_trail_free ( Trail_spfx * trail)
static

Deallocates an unreferenced, expired trail.

Definition at line 801 of file spfx.c.

◆ spfx_trail_remove()

void spfx_trail_remove ( Trail_spfx * trail)

Removes a trail.

Parameters
trailTrail to remove.

Definition at line 792 of file spfx.c.

◆ spfx_trail_sample()

void spfx_trail_sample ( Trail_spfx * trail,
double x,
double y,
TrailMode mode,
int force )

Makes a trail grow.

Parameters
trailTrail to update.
xX position of the new control point.
yY position of the new control point.
modeType of trail emission at this point.
forceWhether or not to force the addition of the sample.

Definition at line 756 of file spfx.c.

◆ spfx_trail_update()

static void spfx_trail_update ( Trail_spfx * trail,
double dt )
static

Updates a trail.

Parameters
trailTrail to update.
dtUpdate interval.

Definition at line 732 of file spfx.c.

◆ spfx_update()

void spfx_update ( const double dt,
const double real_dt )

Updates all the spfx.

Parameters
dtCurrent delta tick.
real_dtReal delta tick.

Definition at line 550 of file spfx.c.

◆ spfx_update_layer()

static void spfx_update_layer ( SPFX * layer,
const double dt )
static

Updates an individual spfx.

Parameters
layerLayer the spfx is on.
dtCurrent delta tick.

Definition at line 577 of file spfx.c.

◆ spfx_update_trails()

void spfx_update_trails ( double dt)
static

Updates all trails (handling dispersal/fadeout).

Parameters
dtUpdate interval.

Definition at line 711 of file spfx.c.

◆ spfx_updateDamage()

static void spfx_updateDamage ( double dt)
static

Definition at line 660 of file spfx.c.

◆ spfx_updateShake()

static void spfx_updateShake ( double dt)
static

Updates the shake position.

Definition at line 598 of file spfx.c.

◆ trailSpec_get()

const TrailSpec * trailSpec_get ( const char * name)

Gets a trail spec by name.

Returns
TrailSpec reference if found, else NULL.

Definition at line 1283 of file spfx.c.

◆ trailSpec_getRaw()

static TrailSpec * trailSpec_getRaw ( const char * name)
static

Definition at line 1268 of file spfx.c.

◆ trailSpec_load()

static int trailSpec_load ( void )
static

Loads the trail colour sets.

Returns
0 on success.

Definition at line 1235 of file spfx.c.

◆ trailSpec_parse()

static int trailSpec_parse ( TrailSpec * tc,
const char * file,
int firstpass )
static

Parses raw values out of a "trail" element.

Warning
This means values like idle->thick aren't ready to use.

Definition at line 1129 of file spfx.c.

Variable Documentation

◆ damage_shader

LuaShader_t damage_shader
static

Shader to use.

Definition at line 72 of file spfx.c.

◆ damage_shader_pp_id

unsigned int damage_shader_pp_id = 0
static

ID of the post-processing shader (0 when disabled)

Definition at line 71 of file spfx.c.

◆ damage_strength

double damage_strength = 0.
static

Damage shader strength intensity.

Definition at line 73 of file spfx.c.

◆ haptic

SDL_Haptic* haptic
extern

From joystick.c

Current haptic in use, externed in spfx.c.

Definition at line 24 of file joystick.c.

◆ haptic_lastUpdate

double haptic_lastUpdate = 0.
static

Timer to update haptic effect again.

Definition at line 69 of file spfx.c.

◆ haptic_query

unsigned int haptic_query
extern

From joystick.c

Properties of the haptic device.

Definition at line 25 of file joystick.c.

◆ haptic_rumble

int haptic_rumble = -1
static

Haptic rumble effect ID.

Definition at line 67 of file spfx.c.

◆ haptic_rumbleEffect

SDL_HapticEffect haptic_rumbleEffect
static

Haptic rumble effect.

Definition at line 68 of file spfx.c.

◆ shake_force_ang

float shake_force_ang = 0.
static

Shake force angle.

Definition at line 62 of file spfx.c.

◆ shake_force_mean

double shake_force_mean = 0.
static

Running mean of the force.

Definition at line 61 of file spfx.c.

◆ shake_force_mod

double shake_force_mod = 0.
static

Shake force modifier.

Definition at line 60 of file spfx.c.

◆ shake_noise

perlin_data_t* shake_noise = NULL
static

Shake noise.

Definition at line 63 of file spfx.c.

◆ shake_pos

vec2 shake_pos = { .x = 0., .y = 0. }
static

Current shake position.

Definition at line 58 of file spfx.c.

◆ shake_shader

LuaShader_t shake_shader
static

Shader to use for shake effects.

Definition at line 57 of file spfx.c.

◆ shake_shader_pp_id

unsigned int shake_shader_pp_id = 0
static

ID of the post-processing shader for the shake.

Definition at line 56 of file spfx.c.

◆ shake_vel

vec2 shake_vel = { .x = 0., .y = 0. }
static

Current shake velocity.

Definition at line 59 of file spfx.c.

◆ spfx_effects

SPFX_Base* spfx_effects = NULL
static

Total special effects.

Definition at line 112 of file spfx.c.

◆ spfx_stack_back

SPFX* spfx_stack_back = NULL
static

Back special effect layer.

Definition at line 136 of file spfx.c.

◆ spfx_stack_front

SPFX* spfx_stack_front = NULL
static

Frontal special effect layer.

Definition at line 134 of file spfx.c.

◆ spfx_stack_middle

SPFX* spfx_stack_middle = NULL
static

Middle special effect layer.

Definition at line 135 of file spfx.c.

◆ trail_spec_stack

TrailSpec* trail_spec_stack
static

Trail specifications.

Definition at line 49 of file spfx.c.

◆ trail_spfx_stack

Trail_spfx** trail_spfx_stack
static

Active trail effects.

Definition at line 50 of file spfx.c.