naev 0.12.6
spfx.c File Reference

Handles the special effects. More...

#include "spfx.h"
#include "array.h"
#include "camera.h"
#include "conf.h"
#include "debris.h"
#include "log.h"
#include "naev.h"
#include "ndata.h"
#include "nlua_shader.h"
#include "nlua_spfx.h"
#include "ntracing.h"
#include "nxml.h"
#include "opengl.h"
#include "pause.h"
#include "perlin.h"
#include "render.h"
#include "rng.h"
#include "vec2.h"
Include dependency graph for spfx.c:

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, double z, double dx, double dy, 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_setNebulaColour (double r, double g, double b)
 Sets the nebula colour where applicable.
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
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
static unsigned int damage_shader_pp_id
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 41 of file spfx.c.

◆ SHAKE_K

#define SHAKE_K   ( 1. / 50. )

Constant for virtual spring.

Definition at line 40 of file spfx.c.

◆ SHAKE_MASS

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

Definition at line 39 of file spfx.c.

◆ SPFX_XML_ID

#define SPFX_XML_ID   "spfx"

SPFX XML node tag.

Definition at line 34 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 504 of file spfx.c.

◆ spfx_base_cmp()

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

For sorting and stuff.

Definition at line 161 of file spfx.c.

◆ spfx_base_free()

void spfx_base_free ( SPFX_Base * effect)
static

Frees a SPFX_Base.

Parameters
effectSPFX_Base to free.

Definition at line 343 of file spfx.c.

◆ spfx_base_parse()

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 175 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 1093 of file spfx.c.

◆ spfx_clear()

void spfx_clear ( void )

Clears all the currently running effects.

Definition at line 549 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 988 of file spfx.c.

◆ spfx_free()

void spfx_free ( void )

Frees the spfx stack.

Definition at line 448 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 355 of file spfx.c.

◆ spfx_hapticInit()

int spfx_hapticInit ( void )
static

Initializes the rumble effect.

Returns
0 on success.

Definition at line 1017 of file spfx.c.

◆ spfx_hapticRumble()

void spfx_hapticRumble ( double mod)
static

Runs a rumble effect.

Current modifier being added.

Definition at line 1049 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 375 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 1178 of file spfx.c.

◆ spfx_renderStack()

void spfx_renderStack ( SPFX * spfx_stack)
static

Definition at line 1099 of file spfx.c.

◆ spfx_setNebulaColour()

void spfx_setNebulaColour ( double r,
double g,
double b )

Sets the nebula colour where applicable.

Definition at line 1002 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 966 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 735 of file spfx.c.

◆ spfx_trail_draw()

void spfx_trail_draw ( const Trail_spfx * trail)

Draws a trail on screen.

Assumes depth testing is enabled.

Definition at line 878 of file spfx.c.

◆ spfx_trail_free()

void spfx_trail_free ( Trail_spfx * trail)
static

Deallocates an unreferenced, expired trail.

Definition at line 866 of file spfx.c.

◆ spfx_trail_remove()

void spfx_trail_remove ( Trail_spfx * trail)

Removes a trail.

Parameters
trailTrail to remove.

Definition at line 857 of file spfx.c.

◆ spfx_trail_sample()

void spfx_trail_sample ( Trail_spfx * trail,
double x,
double y,
double z,
double dx,
double dy,
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.
zZ position of the new control point.
dxX derivative if applicable.
dyY derivative if applicable.
modeType of trail emission at this point.
forceWhether or not to force the addition of the sample.

Definition at line 811 of file spfx.c.

◆ spfx_trail_update()

void spfx_trail_update ( Trail_spfx * trail,
double dt )
static

Updates a trail.

Parameters
trailTrail to update.
dtUpdate interval.

Definition at line 779 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 582 of file spfx.c.

◆ spfx_update_layer()

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 617 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 758 of file spfx.c.

◆ spfx_updateDamage()

void spfx_updateDamage ( double dt)
static

Definition at line 706 of file spfx.c.

◆ spfx_updateShake()

void spfx_updateShake ( double dt)
static

Updates the shake position.

Definition at line 639 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 1396 of file spfx.c.

◆ trailSpec_getRaw()

TrailSpec * trailSpec_getRaw ( const char * name)
static

Definition at line 1381 of file spfx.c.

◆ trailSpec_load()

int trailSpec_load ( void )
static

Loads the trail colour sets.

Returns
0 on success.

Definition at line 1348 of file spfx.c.

◆ trailSpec_parse()

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 1220 of file spfx.c.

Variable Documentation

◆ damage_shader

LuaShader_t damage_shader
static

Shader to use.

Definition at line 76 of file spfx.c.

◆ damage_shader_pp_id

unsigned int damage_shader_pp_id
static
Initial value:
=
0

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

Definition at line 74 of file spfx.c.

◆ damage_strength

double damage_strength = 0.
static

Damage shader strength intensity.

Definition at line 77 of file spfx.c.

◆ haptic

SDL_Haptic* haptic
extern

From joystick.c

Current haptic in use, externed in spfx.c.

Definition at line 21 of file joystick.c.

◆ haptic_lastUpdate

double haptic_lastUpdate
static
Initial value:
=
0.

Timer to update haptic effect again.

Definition at line 71 of file spfx.c.

◆ haptic_query

unsigned int haptic_query
extern

From joystick.c

Properties of the haptic device.

Definition at line 22 of file joystick.c.

◆ haptic_rumble

int haptic_rumble = -1
static

Haptic rumble effect ID.

Definition at line 69 of file spfx.c.

◆ haptic_rumbleEffect

SDL_HapticEffect haptic_rumbleEffect
static

Haptic rumble effect.

Definition at line 70 of file spfx.c.

◆ shake_force_ang

float shake_force_ang = 0.
static

Shake force angle.

Definition at line 64 of file spfx.c.

◆ shake_force_mean

double shake_force_mean = 0.
static

Running mean of the force.

Definition at line 63 of file spfx.c.

◆ shake_force_mod

double shake_force_mod = 0.
static

Shake force modifier.

Definition at line 62 of file spfx.c.

◆ shake_noise

perlin_data_t* shake_noise = NULL
static

Shake noise.

Definition at line 65 of file spfx.c.

◆ shake_pos

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

Current shake position.

Definition at line 60 of file spfx.c.

◆ shake_shader

LuaShader_t shake_shader
static

Shader to use for shake effects.

Definition at line 59 of file spfx.c.

◆ shake_shader_pp_id

unsigned int shake_shader_pp_id
static
Initial value:
=
0

ID of the post-processing shader for the shake.

Definition at line 57 of file spfx.c.

◆ shake_vel

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

Current shake velocity.

Definition at line 61 of file spfx.c.

◆ spfx_effects

SPFX_Base* spfx_effects = NULL
static

Total special effects.

Definition at line 116 of file spfx.c.

◆ spfx_stack_back

SPFX* spfx_stack_back = NULL
static

Back special effect layer.

Definition at line 140 of file spfx.c.

◆ spfx_stack_front

SPFX* spfx_stack_front = NULL
static

Frontal special effect layer.

Definition at line 138 of file spfx.c.

◆ spfx_stack_middle

SPFX* spfx_stack_middle = NULL
static

Middle special effect layer.

Definition at line 139 of file spfx.c.

◆ trail_spec_stack

TrailSpec* trail_spec_stack
static

Trail specifications.

Definition at line 50 of file spfx.c.

◆ trail_spfx_stack

Trail_spfx** trail_spfx_stack
static

Active trail effects.

Definition at line 51 of file spfx.c.