naev 0.11.5
naev.c File Reference

Controls the overall game flow: data loading/unloading and game loop. More...

#include "ai.h"
#include "background.h"
#include "camera.h"
#include "cond.h"
#include "conf.h"
#include "console.h"
#include "damagetype.h"
#include "debug.h"
#include "dialogue.h"
#include "difficulty.h"
#include "economy.h"
#include "env.h"
#include "event.h"
#include "faction.h"
#include "font.h"
#include "gui.h"
#include "hook.h"
#include "input.h"
#include "joystick.h"
#include "land.h"
#include "load.h"
#include "log.h"
#include "map.h"
#include "map_overlay.h"
#include "map_system.h"
#include "menu.h"
#include "mission.h"
#include "music.h"
#include "ndata.h"
#include "nebula.h"
#include "news.h"
#include "nfile.h"
#include "nlua_misn.h"
#include "nlua_var.h"
#include "nlua_tex.h"
#include "nlua_colour.h"
#include "nlua_gfx.h"
#include "nlua_naev.h"
#include "nlua_rnd.h"
#include "nlua_vec2.h"
#include "nlua_file.h"
#include "nlua_data.h"
#include "npc.h"
#include "nstring.h"
#include "nxml.h"
#include "opengl.h"
#include "options.h"
#include "outfit.h"
#include "pause.h"
#include "physics.h"
#include "pilot.h"
#include "player.h"
#include "plugin.h"
#include "render.h"
#include "rng.h"
#include "safelanes.h"
#include "semver.h"
#include "ship.h"
#include "slots.h"
#include "sound.h"
#include "space.h"
#include "spfx.h"
#include "start.h"
#include "tech.h"
#include "threadpool.h"
#include "toolkit.h"
#include "unidiff.h"
#include "weapon.h"

Go to the source code of this file.

Macros

#define VERSION_FILE   "VERSION"
 
#define LOADING_STAGES   17.
 Loads all the data, makes main() simpler.
 

Functions

static void print_SDLversion (void)
 Prints the SDL version to console.
 
static void loadscreen_load (void)
 Loads a loading screen.
 
static void loadscreen_unload (void)
 Frees the loading screen.
 
static void load_all (void)
 
static void unload_all (void)
 Unloads all data, simplifies main().
 
static void window_caption (void)
 Sets the window caption.
 
static void fps_init (void)
 Initializes the fps engine.
 
static double fps_elapsed (void)
 Gets the elapsed time.
 
static void fps_control (void)
 Controls the FPS.
 
static void update_all (int dohooks)
 Updates the game itself (player flying around and friends).
 
static void loadscreen_update (double done, const char *msg)
 Renders the load screen with message.
 
void main_loop (int nested)
 Split main loop from main() for secondary loop hack in toolkit.c.
 
void naev_quit (void)
 Flags naev to quit.
 
int naev_isQuit (void)
 Get if Naev is trying to quit.
 
int main (int argc, char **argv)
 The entry point of Naev.
 
int naev_shouldRenderLoadscreen (void)
 Whether or not we want to render the loadscreen.
 
void naev_doRenderLoadscreen (void)
 
void naev_renderLoadscreen (void)
 Renders the loadscreen if necessary.
 
void naev_resize (void)
 Wrapper for gl_resize that handles non-GL reinitialization.
 
void naev_toggleFullscreen (void)
 
void fps_setPos (double x, double y)
 Sets the position to display the FPS.
 
void fps_display (double dt)
 Displays FPS on the screen.
 
double fps_current (void)
 Gets the current FPS.
 
void update_routine (double dt, int dohooks)
 Actually runs the updates.
 
static int binary_comparison (int x, int y)
 
int naev_versionCompare (const char *version)
 Compares the version against the current naev version.
 
double naev_getrealdt (void)
 Gets the last delta-tick.
 

Variables

static int quit = 0
 
Uint32 SDL_LOOPDONE = 0
 
static Uint64 time_ms = 0
 
static SDL_Surface * naev_icon = NULL
 
static int fps_skipped = 0
 
static semver_t version_binary
 
static double fps_dt = 1.
 
static double game_dt = 0.
 
static double real_dt = 0.
 
static double fps = 0.
 
static double fps_cur = 0.
 
static double fps_x = 15.
 
static double fps_y = -15.
 
const double fps_min = 1./25.
 
double elapsed_time_mod = 0.
 
static nlua_env load_env = LUA_NOREF
 
static int load_force_render = 0
 
static unsigned int load_last_render = 0
 
static SDL_mutex * load_mutex
 

Detailed Description

Controls the overall game flow: data loading/unloading and game loop.

Definition in file naev.c.

Macro Definition Documentation

◆ LOADING_STAGES

#define LOADING_STAGES   17.

Loads all the data, makes main() simpler.

Amount of loading stages.

Definition at line 637 of file naev.c.

◆ VERSION_FILE

#define VERSION_FILE   "VERSION"

Version file by default.

Definition at line 98 of file naev.c.

Function Documentation

◆ binary_comparison()

static int binary_comparison ( int x,
int y )
static

Definition at line 1109 of file naev.c.

◆ fps_control()

static void fps_control ( void )
static

Controls the FPS.

Definition at line 904 of file naev.c.

◆ fps_current()

double fps_current ( void )

Gets the current FPS.

Returns
Current FPS as displayed to the player.

Definition at line 984 of file naev.c.

◆ fps_display()

void fps_display ( double dt)

Displays FPS on the screen.

Parameters
[in]dtCurrent delta tick.

Definition at line 945 of file naev.c.

◆ fps_elapsed()

static double fps_elapsed ( void )
static

Gets the elapsed time.

Returns
The elapsed time from the last frame.

Definition at line 874 of file naev.c.

◆ fps_init()

static void fps_init ( void )
static

Initializes the fps engine.

Definition at line 855 of file naev.c.

◆ fps_setPos()

void fps_setPos ( double x,
double y )

Sets the position to display the FPS.

Definition at line 934 of file naev.c.

◆ load_all()

void load_all ( void )
static

Definition at line 638 of file naev.c.

◆ loadscreen_load()

void loadscreen_load ( void )
static

Loads a loading screen.

Definition at line 521 of file naev.c.

◆ loadscreen_unload()

static void loadscreen_unload ( void )
static

Frees the loading screen.

Definition at line 628 of file naev.c.

◆ loadscreen_update()

void loadscreen_update ( double done,
const char * msg )
static

Renders the load screen with message.

Parameters
doneAmount done (1. == completed).
msgLoading screen message.

Definition at line 609 of file naev.c.

◆ main()

int main ( int argc,
char ** argv )

The entry point of Naev.

Parameters
[in]argcNumber of arguments.
[in]argvArray of argc arguments.
Returns
EXIT_SUCCESS on success.

Definition at line 170 of file naev.c.

◆ main_loop()

void main_loop ( int nested)

Split main loop from main() for secondary loop hack in toolkit.c.

Definition at line 744 of file naev.c.

◆ naev_doRenderLoadscreen()

void naev_doRenderLoadscreen ( void )

Definition at line 570 of file naev.c.

◆ naev_getrealdt()

double naev_getrealdt ( void )

Gets the last delta-tick.

Definition at line 1174 of file naev.c.

◆ naev_isQuit()

int naev_isQuit ( void )

Get if Naev is trying to quit.

Definition at line 158 of file naev.c.

◆ naev_quit()

void naev_quit ( void )

Flags naev to quit.

Definition at line 150 of file naev.c.

◆ naev_renderLoadscreen()

void naev_renderLoadscreen ( void )

Renders the loadscreen if necessary.

Definition at line 597 of file naev.c.

◆ naev_resize()

void naev_resize ( void )

Wrapper for gl_resize that handles non-GL reinitialization.

Definition at line 790 of file naev.c.

◆ naev_shouldRenderLoadscreen()

int naev_shouldRenderLoadscreen ( void )

Whether or not we want to render the loadscreen.

Definition at line 556 of file naev.c.

◆ naev_toggleFullscreen()

void naev_toggleFullscreen ( void )

Definition at line 843 of file naev.c.

◆ naev_versionCompare()

int naev_versionCompare ( const char * version)

Compares the version against the current naev version.

Returns
positive if version is newer or negative if version is older.

Definition at line 1120 of file naev.c.

◆ print_SDLversion()

static void print_SDLversion ( void )
static

Prints the SDL version to console.

Definition at line 1142 of file naev.c.

◆ unload_all()

void unload_all ( void )
static

Unloads all data, simplifies main().

Definition at line 711 of file naev.c.

◆ update_all()

static void update_all ( int dohooks)
static

Updates the game itself (player flying around and friends).

Mainly uses game dt.

Definition at line 994 of file naev.c.

◆ update_routine()

void update_routine ( double dt,
int dohooks )

Actually runs the updates.

Parameters
[in]dtCurrent delta tick.
[in]dohooksWhether or not we want to do hooks, such as the initial update upon entering a system.

Definition at line 1038 of file naev.c.

◆ window_caption()

static void window_caption ( void )
static

Sets the window caption.

Definition at line 1085 of file naev.c.

Variable Documentation

◆ elapsed_time_mod

double elapsed_time_mod = 0.

Elapsed modified time.

Definition at line 121 of file naev.c.

◆ fps

double fps = 0.
static

FPS to finally display.

Definition at line 114 of file naev.c.

◆ fps_cur

double fps_cur = 0.
static

FPS accumulator to trigger change.

Definition at line 115 of file naev.c.

◆ fps_dt

double fps_dt = 1.
static

Display fps accumulator.

Definition at line 111 of file naev.c.

◆ fps_min

const double fps_min = 1./25.

Minimum fps to run at. 1/25 seems to be acceptable value for fast ships. 1/15 can cause issues with hyenas and such.

Definition at line 118 of file naev.c.

◆ fps_skipped

int fps_skipped = 0
static

Skipped last frame?

Definition at line 104 of file naev.c.

◆ fps_x

double fps_x = 15.
static

FPS X position.

Definition at line 116 of file naev.c.

◆ fps_y

double fps_y = -15.
static

FPS Y position.

Definition at line 117 of file naev.c.

◆ game_dt

double game_dt = 0.
static

Current game deltatick (uses dt_mod).

Definition at line 112 of file naev.c.

◆ load_env

nlua_env load_env = LUA_NOREF
static

Environment for displaying load messages and stuff.

Definition at line 123 of file naev.c.

◆ load_force_render

int load_force_render = 0
static

Definition at line 124 of file naev.c.

◆ load_last_render

unsigned int load_last_render = 0
static

Definition at line 125 of file naev.c.

◆ load_mutex

SDL_mutex* load_mutex
static

Definition at line 126 of file naev.c.

◆ naev_icon

SDL_Surface* naev_icon = NULL
static

Icon.

Definition at line 103 of file naev.c.

◆ quit

int quit = 0
static

For primary loop

Definition at line 100 of file naev.c.

◆ real_dt

double real_dt = 0.
static

Real deltatick.

Definition at line 113 of file naev.c.

◆ SDL_LOOPDONE

Uint32 SDL_LOOPDONE = 0

For custom event to exit loops.

Definition at line 101 of file naev.c.

◆ time_ms

Uint64 time_ms = 0
static

used to calculate FPS and movement.

Definition at line 102 of file naev.c.

◆ version_binary

semver_t version_binary
static

Naev binary version.

Definition at line 106 of file naev.c.