naev 0.12.5
naev.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
15#include "SDL.h"
16#include "SDL_error.h"
17#include "SDL_image.h"
18#include "linebreak.h"
19#include "physfsrwops.h"
20
21#include "naev.h"
22
23#if HAS_POSIX
24#include <time.h>
25#include <unistd.h>
26#endif /* HAS_POSIX */
28
29#include "ai.h"
30#include "background.h"
31#include "camera.h"
32#include "cond.h"
33#include "conf.h"
34#include "console.h"
35#include "damagetype.h"
36#include "debug.h"
37#include "dialogue.h"
38#include "difficulty.h"
39#include "economy.h"
40#include "env.h"
41#include "event.h"
42#include "faction.h"
43#include "font.h"
44#include "gui.h"
45#include "hook.h"
46#include "input.h"
47#include "joystick.h"
48#include "land.h"
49#include "load.h"
50#include "log.h"
51#include "map.h"
52#include "map_overlay.h"
53#include "map_system.h"
54#include "menu.h"
55#include "mission.h"
56#include "music.h"
57#include "ndata.h"
58#include "nebula.h"
59#include "news.h"
60#include "nfile.h"
61#include "nlua_colour.h"
62#include "nlua_data.h"
63#include "nlua_file.h"
64#include "nlua_gfx.h"
65#include "nlua_naev.h"
66#include "nlua_rnd.h"
67#include "nlua_tex.h"
68#include "nlua_var.h"
69#include "nlua_vec2.h"
70#include "npc.h"
71#include "ntracing.h"
72#include "opengl.h"
73#include "options.h"
74#include "outfit.h"
75#include "pause.h"
76#include "pilot.h"
77#include "player.h"
78#include "player_autonav.h"
79#include "plugin.h"
80#include "render.h"
81#include "rng.h"
82#include "safelanes.h"
83#include "semver.h"
84#include "ship.h"
85#include "slots.h"
86#include "sound.h"
87#include "space.h"
88#include "spfx.h"
89#include "start.h"
90#include "tech.h"
91#include "threadpool.h"
92#include "toolkit.h"
93#include "unidiff.h"
94#include "weapon.h"
95
96#define VERSION_FILE "VERSION"
97
98static int quit = 0;
99Uint32 SDL_LOOPDONE = 0;
100static Uint64 last_t = 0;
101static SDL_Surface *naev_icon = NULL;
102static int fps_skipped = 0;
103/* Version stuff. */
105
106/*
107 * FPS stuff.
108 */
109static double fps_dt = 1.;
110static double game_dt = 0.;
111static double real_dt = 0.;
112static double fps = 0.;
113static double fps_cur = 0.;
114static double fps_x = 15.;
115static double fps_y = -15.;
116const double fps_min = 1. / 10.;
117double elapsed_time_mod = 0.;
118
119static nlua_env load_env =
120 LUA_NOREF;
121static int load_force_render = 0;
122static unsigned int load_last_render = 0;
123static SDL_mutex *load_mutex;
124
125/*
126 * prototypes
127 */
128/* Loading. */
129static void print_SDLversion( void );
130static void loadscreen_load( void );
131static void loadscreen_unload( void );
132static void load_all( void );
133static void unload_all( void );
134static void window_caption( void );
135/* update */
136static void fps_init( void );
137static void update_all( int dohooks );
138/* Misc. */
139static void loadscreen_update( double done, const char *msg );
140void main_loop( int nested ); /* externed in dialogue.c */
141
145void naev_quit( void )
146{
147 quit = 1;
148}
149
153int naev_isQuit( void )
154{
155 return quit;
156}
157
158#ifndef NOMAIN
166int main( int argc, char **argv )
167{
168 char conf_file_path[PATH_MAX], **search_path;
169 Uint32 starttime;
170
171#ifdef DEBUGGING
172 /* Set Debugging flags. */
173 memset( debug_flags, 0, DEBUG_FLAGS_MAX );
174#endif /* DEBUGGING */
175
176 env_detect( argc, argv );
177
178 log_init();
179
180 /* Set up PhysicsFS. */
181 if ( PHYSFS_init( env.argv0 ) == 0 ) {
182 char buf[STRMAX];
183 snprintf( buf, sizeof( buf ), "PhysicsFS initialization failed: %s",
184 PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) );
185#if SDL_VERSION_ATLEAST( 3, 0, 0 )
186 SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,
187 _( "Naev Critical Error" ), buf,
188 gl_screen.window );
189#endif /* SDL_VERSION_ATLEAST( 3, 0, 0 ) */
190 ERR( "%s", buf );
191 return -1;
192 }
193 PHYSFS_permitSymbolicLinks( 1 );
194
195 /* Set up locales. */
196 gettext_init();
197 init_linebreak();
198
199 /* Parse version. */
200 if ( semver_parse( naev_version( 0 ), &version_binary ) )
201 WARN( _( "Failed to parse version string '%s'!" ), naev_version( 0 ) );
202
203 /* Print the version */
204 LOG( " %s v%s (%s)", APPNAME, naev_version( 0 ), HOST );
205
206#if __LINUX__
207 if ( env.isAppImage )
208 LOG( "AppImage detected. Running from: %s", env.appdir );
209 else
210 DEBUG( "AppImage not detected." );
211#endif /*__LINUX__ */
212
213 /* Initializes SDL for possible warnings. */
214 if ( SDL_Init( 0 ) ) {
215 char buf[STRMAX];
216 snprintf( buf, sizeof( buf ), _( "Unable to initialize SDL: %s" ),
217 SDL_GetError() );
218#if SDL_VERSION_ATLEAST( 3, 0, 0 )
219 SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,
220 _( "Naev Critical Error" ), buf,
221 gl_screen.window );
222#endif /* SDL_VERSION_ATLEAST( 3, 0, 0 ) */
223 ERR( "%s", buf );
224 return -1;
225 }
226 starttime = SDL_GetTicks();
227 SDL_LOOPDONE = SDL_RegisterEvents( 1 );
228
229 /* Initialize the threadpool */
230 threadpool_init();
231
232 /* Set up debug signal handlers. */
234
235#if HAS_UNIX
236 /* Set window class and name. */
237 SDL_setenv( "SDL_VIDEO_X11_WMCLASS", APPNAME, 0 );
238#endif /* HAS_UNIX */
239
240 /* Must be initialized before input_init is called. */
241 if ( SDL_InitSubSystem( SDL_INIT_VIDEO ) < 0 ) {
242 WARN( _( "Unable to initialize SDL Video: %s" ), SDL_GetError() );
243 return -1;
244 }
245
246 /* We'll be parsing XML. */
247 LIBXML_TEST_VERSION
248 xmlInitParser();
249
250 /* Input must be initialized for config to work. */
251 input_init();
252
253 lua_init(); /* initializes lua */
254
255 conf_setDefaults(); /* set the default config values */
256
257 /*
258 * Attempts to load the data path from datapath.lua
259 * At this early point in the load process, the binary path
260 * is the only place likely to be checked.
261 */
262 conf_loadConfigPath();
263
264 /* Create the home directory if needed. */
266 WARN( _( "Unable to create config directory '%s'" ), nfile_configPath() );
267
268 /* Set the configuration. */
269 snprintf( conf_file_path, sizeof( conf_file_path ), "%s" CONF_FILE,
271
272 conf_loadConfig( conf_file_path ); /* Lua to parse the configuration file */
273 conf_parseCLI( argc, argv ); /* parse CLI arguments */
274
275 /* Set up I/O. */
277 log_redirect();
279 gettext_setLanguage( conf.language ); /* now that we can find translations */
280 LOG( _( "Loaded configuration: %s" ), conf_file_path );
281 search_path = PHYSFS_getSearchPath();
282 LOG( "%s", _( "Read locations, searched in order:" ) );
283 for ( char **p = search_path; *p != NULL; p++ )
284 LOG( " %s", *p );
285 PHYSFS_freeList( search_path );
286 /* Logging the cache path is noisy, noisy is good at the DEBUG level. */
287 DEBUG( _( "Cache location: %s" ), nfile_cachePath() );
288 LOG( _( "Write location: %s\n" ), PHYSFS_getWriteDir() );
289
290 /* Enable FPU exceptions. */
291 if ( conf.fpu_except )
293
294 /* Load the start info. */
295 if ( start_load() ) {
296 char buf[STRMAX];
297 snprintf( buf, sizeof( buf ), _( "Failed to load module start data." ) );
298#if SDL_VERSION_ATLEAST( 3, 0, 0 )
299 SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,
300 _( "Naev Critical Error" ), buf,
301 gl_screen.window );
302#endif /* SDL_VERSION_ATLEAST( 3, 0, 0 ) */
303 ERR( "%s", buf );
304 }
305 LOG( " %s", start_name() );
306 DEBUG_BLANK();
307
308 /* Display the SDL Version. */
310 DEBUG_BLANK();
311
312 /* random numbers */
313 rng_init();
314
315 /*
316 * OpenGL
317 */
318 if ( gl_init( 0 ) ) { /* initializes video output */
319 char buf[STRMAX];
320 snprintf( buf, sizeof( buf ),
321 _( "Initializing video output failed, exiting…" ) );
322#if SDL_VERSION_ATLEAST( 3, 0, 0 )
323 SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,
324 _( "Naev Critical Error" ), buf,
325 gl_screen.window );
326#endif /* SDL_VERSION_ATLEAST( 3, 0, 0 ) */
327 ERR( "%s", buf );
328 // SDL_Quit();
329 exit( EXIT_FAILURE );
330 }
332
333 /* Have to set up fonts before rendering anything. */
334 // DEBUG("Using '%s' as main font and '%s' as monospace font.",
335 // _(FONT_DEFAULT_PATH), _(FONT_MONOSPACE_PATH));
336 gl_fontInit( &gl_defFont, _( FONT_DEFAULT_PATH ), conf.font_size_def,
337 FONT_PATH_PREFIX, 0 ); /* initializes default font to size */
338 gl_fontInit( &gl_smallFont, _( FONT_DEFAULT_PATH ), conf.font_size_small,
339 FONT_PATH_PREFIX, 0 ); /* small font */
340 gl_fontInit( &gl_defFontMono, _( FONT_MONOSPACE_PATH ), conf.font_size_def,
341 FONT_PATH_PREFIX, 0 );
342
343 /* Detect size changes that occurred after window creation. */
344 naev_resize();
345
346 /* Display the load screen. */
348 loadscreen_update( 0., _( "Initializing subsystems…" ) );
349 last_t = SDL_GetPerformanceCounter();
350
351 /*
352 * Input
353 */
354 if ( ( conf.joystick_ind >= 0 ) || ( conf.joystick_nam != NULL ) ) {
355 if ( joystick_init() )
356 WARN( _( "Error initializing joystick input" ) );
357 if ( conf.joystick_nam !=
358 NULL ) { /* use the joystick name to find a joystick */
359 if ( joystick_use( joystick_get( conf.joystick_nam ) ) ) {
360 WARN( _( "Failure to open any joystick, falling back to default "
361 "keybinds" ) );
362 input_setDefault( 1 );
363 }
364 free( conf.joystick_nam );
365 } else if ( conf.joystick_ind >= 0 ) /* use a joystick id instead */
366 if ( joystick_use( conf.joystick_ind ) ) {
367 WARN( _( "Failure to open any joystick, falling back to default "
368 "keybinds" ) );
369 input_setDefault( 1 );
370 }
371 }
372
373 /*
374 * OpenAL - Sound
375 */
376 if ( conf.nosound ) {
377 LOG( _( "Sound is disabled!" ) );
378 sound_disabled = 1;
379 music_disabled = 1;
380 }
381 if ( sound_init() )
382 WARN( _( "Problem setting up sound!" ) );
383 music_choose( "load" );
384
385 /* FPS stuff. */
386 fps_setPos( 15., (double)( gl_screen.h - 15 - gl_defFontMono.h ) );
387
388 /* Misc graphics init */
389 render_init();
390 nebu_init(); /* Initializes the nebula */
391 gui_init(); /* initializes the GUI graphics */
392 toolkit_init(); /* initializes the toolkit */
393 map_init(); /* initializes the map. */
394 map_system_init(); /* Initialise the solar system map */
395 cond_init(); /* Initialize conditional subsystem. */
396 cli_init(); /* Initialize console. */
397
398 /* Data loading */
399 load_all();
400
401 /* Detect size changes that occurred during load. */
402 naev_resize();
403
404 /* Unload load screen. */
406
407 /* Start menu. */
408 menu_main();
409
410 if ( conf.devmode )
411 LOG( _( "Reached main menu in %.3f s" ),
412 (double)( SDL_GetTicks() - starttime ) / 1000. );
413 else
414 LOG( _( "Reached main menu" ) );
415 NTracingMessageL( _( "Reached main menu" ) );
416
417 fps_init(); /* initializes the last_t */
418
419 /*
420 * main loop
421 */
422 SDL_Event event;
423 /* flushes the event loop since I noticed that when the joystick is loaded it
424 * creates button events that results in the player starting out acceling */
425 while ( SDL_PollEvent( &event ) )
426 ;
427
428 /* Show plugin compatibility. */
429 plugin_check();
430
431 /* Incomplete translation note (shows once if we pick an incomplete
432 * translation based on user's locale). */
433 if ( !conf.translation_warning_seen && conf.language == NULL ) {
434 const char *language = gettext_getLanguage();
435 double coverage = gettext_languageCoverage( language );
436
437 if ( coverage < 0.8 ) {
438 conf.translation_warning_seen = 1;
440 _( "Incomplete Translation" ),
441 _( "%s is partially translated (%.0f%%) into your language (%s),"
442 " but the remaining text will be English. Language settings"
443 " are available in the \"%s\" screen." ),
444 APPNAME, 100. * coverage, language, _( "Options" ) );
445 }
446 }
447
448 /* Incomplete game note (shows every time version number changes). */
449 if ( conf.lastversion == NULL ||
450 naev_versionCompare( conf.lastversion ) != 0 ) {
451 free( conf.lastversion );
452 conf.lastversion = strdup( naev_version( 0 ) );
454 _( "Welcome to Naev" ),
455 _( "Welcome to Naev version %s, and thank you for playing! We hope you"
456 " enjoy this game and all it has to offer. This is a passion"
457 " project developed exclusively by volunteers and it gives us all"
458 " great joy to know that there are others who love this game as"
459 " much as we do!\n"
460 " Of course, please note that this is an incomplete game. You"
461 " will encounter dead ends to storylines, missing storylines, and"
462 " possibly even some bugs, although we try to keep those to a"
463 " minimum of course. So be prepared for some rough edges for the"
464 " time being. That said, we are working on this game every day and"
465 " hope to one day finish this massive project on our hands."
466 " Perhaps you could become one of us, who knows?\n"
467 " For more information about the game and its development"
468 " state, take a look at naev.org; it has all the relevant links."
469 " And again, thank you for playing!" ),
470 conf.lastversion );
471 }
472
473 /* primary loop */
474 while ( !quit ) {
475 while ( !quit && SDL_PollEvent( &event ) ) { /* event loop */
476 if ( event.type == SDL_QUIT ) {
477 SDL_FlushEvent( SDL_QUIT ); /* flush event to prevent it from
478 quitting when lagging a bit. */
479 if ( quit || menu_askQuit() ) {
480 quit = 1; /* quit is handled here */
481 break;
482 }
483 } else if ( event.type == SDL_WINDOWEVENT &&
484 event.window.event == SDL_WINDOWEVENT_RESIZED ) {
485 naev_resize();
486 continue;
487 }
489 &event ); /* handles all the events and player keybinds */
490 }
491
492 main_loop( 0 );
493 }
494
495 /* Save configuration. */
496 conf_saveConfig( conf_file_path );
497
498 /* data unloading */
499 unload_all();
500
501 /* cleanup opengl fonts */
502 gl_freeFont( NULL );
505
506 start_cleanup(); /* Cleanup from start.c, not the first cleanup step. :) */
507
508 /* exit subsystems */
509 plugin_exit();
510 cli_exit(); /* Clean up the console. */
511 map_system_exit(); /* Destroys the solar system map. */
512 map_exit(); /* Destroys the map. */
513 ovr_mrkFree(); /* Clear markers. */
514 toolkit_exit(); /* Kills the toolkit */
515 ai_exit(); /* Stops the Lua AI magic */
516 joystick_exit(); /* Releases joystick */
517 input_exit(); /* Cleans up keybindings */
518 nebu_exit(); /* Destroys the nebula */
519 render_exit(); /* Cleans up post-processing. */
520 news_exit(); /* Destroys the news. */
521 difficulty_free(); /* Clean up difficulties. */
522 music_exit(); /* Kills Lua state. */
523 lua_exit(); /* Closes Lua state, and invalidates all Lua. */
524 sound_exit(); /* Kills the sound */
525 gl_exit(); /* Kills video output */
526
527 /* Has to be run last or it will mess up sound settings. */
528 conf_cleanup(); /* Free some memory the configuration allocated. */
529
530 /* Free the icon. */
531 if ( naev_icon )
532 SDL_FreeSurface( naev_icon );
533
534 IMG_Quit(); /* quits SDL_image */
535 SDL_Quit(); /* quits SDL */
536
537 /* Clean up parser. */
538 xmlCleanupParser();
539
540 /* Clean up signal handler. */
542
543 /* Delete logs if empty. */
544 log_clean();
545
546 /* Really turn the lights off. */
547 PHYSFS_deinit();
548 gl_fontExit();
549 gettext_exit();
550
551 /* all is well */
553 return 0;
554}
555#endif /* NOMAIN */
556
560void loadscreen_load( void )
561{
562 int r;
563
564 load_mutex = SDL_CreateMutex();
565 load_env = nlua_newEnv( "loadscreen" );
566
568 r |= nlua_loadNaev( load_env );
569 r |= nlua_loadRnd( load_env );
571 r |= nlua_loadFile( load_env );
572 r |= nlua_loadData( load_env );
573 r |= nlua_loadTex( load_env );
574 r |= nlua_loadCol( load_env );
575 r |= nlua_loadGFX( load_env );
576 if ( r )
577 WARN( _( "Something went wrong when loading Lua libraries for '%s'!" ),
578 LOADSCREEN_DATA_PATH );
579
580 size_t bufsize;
581 char *buf = ndata_read( LOADSCREEN_DATA_PATH, &bufsize );
582 if ( nlua_dobufenv( load_env, buf, bufsize, LOADSCREEN_DATA_PATH ) != 0 ) {
583 WARN( _( "Error loading file: %s\n"
584 "%s\n"
585 "Most likely Lua file has improper syntax, please check" ),
586 LOADSCREEN_DATA_PATH, lua_tostring( naevL, -1 ) );
587 free( buf );
588 return;
589 }
590 free( buf );
591}
592
597{
598 unsigned int t = SDL_GetTicks();
599 int ret;
600 SDL_mutexP( load_mutex );
601 /* Only render if forced or try for low 10 FPS. */
602 if ( !load_force_render && ( t - load_last_render ) < 100 )
603 ret = 0;
604 else
605 ret = 1;
606 SDL_mutexV( load_mutex );
607 return ret;
608}
609
610void naev_doRenderLoadscreen( void )
611{
612 SDL_mutexP( load_mutex );
613 load_last_render = SDL_GetTicks();
614
615 /* Clear background. */
616 glClearColor( 0., 0., 0., 1. );
617 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
618 glClearColor( 0., 0., 0., 0. );
619
620 /* Run Lua. */
621 nlua_getenv( naevL, load_env, "render" );
622 if ( nlua_pcall( load_env, 0, 0 ) ) { /* error has occurred */
623 WARN( _( "Loadscreen '%s': '%s'" ), "render", lua_tostring( naevL, -1 ) );
624 lua_pop( naevL, 1 );
625 }
626
627 /* Flip buffers. HACK: Also try to catch a late-breaking resize from the WM
628 * (...or a crazy user?). */
629 SDL_GL_SwapWindow( gl_screen.window );
630 naev_resize();
631
632 /* Clear forcing. */
633 load_force_render = 0;
634 SDL_mutexV( load_mutex );
635}
636
641{
643 naev_doRenderLoadscreen();
644}
645
652void loadscreen_update( double done, const char *msg )
653{
654 /* Run Lua. */
655 nlua_getenv( naevL, load_env, "update" );
656 lua_pushnumber( naevL, done );
657 lua_pushstring( naevL, msg );
658 if ( nlua_pcall( load_env, 2, 0 ) ) { /* error has occurred */
659 WARN( _( "Loadscreen '%s': '%s'" ), "update", lua_tostring( naevL, -1 ) );
660 lua_pop( naevL, 1 );
661 }
662
663 /* Force rerender. */
664 load_force_render = 1;
666}
667
671static void loadscreen_unload( void )
672{
673 nlua_freeEnv( load_env );
674 SDL_DestroyMutex( load_mutex );
675}
676
680#define LOADING_STAGES 17.
681void load_all( void )
682{
683 NTracingFrameMarkStart( "load_all" );
684
685 int stage = 0;
686 /* We can do fast stuff here. */
687 sp_load();
688
689 /* order is very important as they're interdependent */
690 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Commodities…" ) );
691 commodity_load(); /* dep for space */
692
694 _( "Loading Special Effects…" ) );
695 spfx_load(); /* no dep */
696
697 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Effects…" ) );
698 effect_load(); /* no dep */
699
700 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Damage Types…" ) );
701 dtype_load(); /* dep for outfits */
702
703 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Factions…" ) );
704 factions_load(); /* dep for fleet, space, missions, AI */
705
706 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Outfits…" ) );
707 outfit_load(); /* dep for ships, factions */
708
709 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Ships…" ) );
710 ships_load(); /* dep for fleet */
711
712 /* Handle dependent faction/outfit stuff. */
714
715 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading AI…" ) );
716 ai_load(); /* dep for fleets */
717
718 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Techs…" ) );
719 tech_load(); /* dep for space */
720
721 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading the Universe…" ) );
722 space_load(); /* dep for events/missions */
723
724 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Events…" ) );
725 events_load();
726
727 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading Missions…" ) );
729
730 loadscreen_update( ++stage / LOADING_STAGES, _( "Loading the UniDiffs…" ) );
731 diff_init();
732
733 loadscreen_update( ++stage / LOADING_STAGES, _( "Populating Maps…" ) );
735
736 loadscreen_update( ++stage / LOADING_STAGES, _( "Calculating Patrols…" ) );
738
739 /* Handled at the end, deals with equip / standing scripts. */
740 factions_loadPost();
741
742 loadscreen_update( ++stage / LOADING_STAGES, _( "Initializing Details…" ) );
743#if DEBUGGING
744 if ( stage > LOADING_STAGES )
745 WARN( _( "Too many loading stages, please increase LOADING_STAGES" ) );
746#endif /* DEBUGGING */
747 difficulty_load();
749 map_load();
750 map_system_load();
752 pilots_init();
753 weapon_init();
754 player_init(); /* Initialize player stuff. */
755 loadscreen_update( 1., _( "Loading Completed!" ) );
756
757 NTracingFrameMarkEnd( "load_all" );
758}
762void unload_all( void )
763{
764 /* cleanup some stuff */
765 player_cleanup(); /* cleans up the player stuff */
766 gui_free(); /* cleans up the player's GUI */
767 weapon_exit(); /* destroys all active weapons */
768 pilots_free(); /* frees the pilots, they were locked up :( */
769 cond_exit(); /* destroy conditional subsystem. */
770 land_exit(); /* Destroys landing vbo and friends. */
771 npc_clear(); /* In case exiting while landed. */
772 background_free(); /* Destroy backgrounds. */
773 load_free(); /* Clean up loading game stuff stuff. */
774 diff_exit();
776 economy_destroy(); /* must be called before space_exit */
777 space_exit(); /* cleans up the universe itself */
778 tech_free(); /* Frees tech stuff. */
779 ships_free();
780 outfit_free();
781 spfx_free(); /* gets rid of the special effect */
782 effect_exit();
783 dtype_free(); /* gets rid of the damage types */
785 events_exit(); /* Clean up events. */
788 var_cleanup(); /* cleans up mission variables */
789 sp_cleanup();
790}
791
795void main_loop( int nested )
796{
797 NTracingZone( _ctx, 1 );
798
799 /* Update elapsed time */
800 {
801 Uint64 t = SDL_GetPerformanceCounter();
802 double dt =
803 (double)( t - last_t ) / (double)SDL_GetPerformanceFrequency();
804 last_t = t;
805 real_dt = dt;
806 game_dt = real_dt * dt_mod; /* Apply the modifier. */
807 }
808
809 /*
810 * Handle update.
811 */
812 input_update( real_dt ); /* handle key repeats. */
813 sound_update( real_dt ); /* Update sounds. */
814 toolkit_update(); /* to simulate key repetition and get rid of windows */
815 if ( !paused ) {
816 update_all( !nested ); /* update game */
817 } else if ( !nested ) {
818 /* We run the exclusion end here to handle any hooks that are potentially
819 * manually triggered by hook.trigger. */
820 hook_exclusionEnd( 0. );
821 }
822
823 /* Safe hook should be run every frame regardless of whether game is paused
824 * or not. */
825 if ( !nested )
826 hooks_run( "safe" );
827
828 /* Checks to see if we want to land. */
830
831 /*
832 * Handle render.
833 */
834 if ( !quit ) { /* So if update sets up a nested main loop, we can end up in a
835 state where things are corrupted when trying to exit the
836 game. Avoid rendering when quitting just in case. */
837 /* Clear buffer. */
838 render_all( game_dt, real_dt );
839 /* Draw buffer. */
840 SDL_GL_SwapWindow( gl_screen.window );
841
842 /* if fps is limited */
843 if ( !conf.vsync && conf.fps_max != 0 ) {
844#if !SDL_VERSION_ATLEAST( 3, 0, 0 ) && HAS_POSIX
845 struct timespec ts;
846#endif /* HAS_POSIX */
847 const double fps_max = 1. / (double)conf.fps_max;
848 Uint64 t = SDL_GetPerformanceCounter();
849 double dt =
850 (double)( t - last_t ) / (double)SDL_GetPerformanceFrequency();
851 double delay = fps_max - dt;
852 if ( delay > 0. ) {
853#if SDL_VERSION_ATLEAST( 3, 0, 0 )
854 SDL_DelayNS( delay * 1e9 );
855#elif HAS_POSIX
856 ts.tv_sec = floor( delay );
857 ts.tv_nsec = fmod( delay, 1. ) * 1e9;
858 nanosleep( &ts, NULL );
859#else /* HAS_POSIX */
860 SDL_Delay( (unsigned int)round( delay * 1000. ) );
861#endif /* HAS_POSIX */
862 }
863 }
864
865 NTracingFrameMark;
866 }
867
868 NTracingZoneEnd( _ctx );
869}
870
874void naev_resize( void )
875{
876 /* Auto-detect window size. */
877 int w, h;
878 SDL_GL_GetDrawableSize( gl_screen.window, &w, &h );
879
880 /* Update options menu, if open. (Never skip, in case the fullscreen mode
881 * alone changed.) */
882 opt_resize();
883
884 /* Nothing to do. */
885 if ( ( w == gl_screen.rw ) && ( h == gl_screen.rh ) )
886 return;
887
888 /* Resize the GL context, etc. */
889 gl_resize();
890
891 /* Regenerate the background space dust. */
892 if ( cur_system != NULL ) {
893 background_initDust( cur_system->spacedust );
894 background_load( cur_system->background );
895 } else
896 background_initDust( 1000. ); /* from loadscreen_load */
897
898 /* Must be before gui_reload */
899 fps_setPos( 15., (double)( SCREEN_H - 15 - gl_defFontMono.h ) );
900
901 /* Reload the GUI (may regenerate land window) */
902 gui_reload();
903
904 /* Resets dimensions in other components which care. */
905 ovr_refresh();
908 nebu_resize();
909 ships_resize();
910
911 /* Lua stuff. */
912 nlua_resize();
913
914 /* Have to rerender the toolkit too. */
916
917 /* Finally do a render pass to avoid half-rendered stuff. */
918 render_all( 0., 0. );
919 SDL_GL_SwapWindow( gl_screen.window );
920
921 /* Force render. */
922 load_force_render = 1;
923}
924
925/*
926 * @brief Toggles between windowed and fullscreen mode.
927 */
928void naev_toggleFullscreen( void )
929{
930 opt_setVideoMode( conf.width, conf.height, !conf.fullscreen, 0 );
931}
932
936static void fps_init( void )
937{
938 last_t = SDL_GetPerformanceCounter();
939}
940
944void fps_setPos( double x, double y )
945{
946 fps_x = x;
947 fps_y = y;
948}
949
955void fps_display( double dt )
956{
957 double x, y;
958 double dt_mod_base = 1.;
959
960 fps_dt += dt;
961 fps_cur += 1.;
962 if ( fps_dt > 1. ) { /* recalculate every second */
963 fps = fps_cur / fps_dt;
964 fps_dt = fps_cur = 0.;
965 }
966
967 x = fps_x;
968 y = fps_y;
969 if ( conf.fps_show ) {
970 gl_print( &gl_defFontMono, x, y, &cFontWhite, "%3.2f", fps );
971 y -= gl_defFontMono.h + 5.;
972 }
973
974 if ( ( player.p != NULL ) && !player_isFlag( PLAYER_DESTROYED ) &&
975 !player_isFlag( PLAYER_CREATING ) ) {
976 dt_mod_base = player_dt_default();
977 }
978 if ( dt_mod != dt_mod_base )
979 gl_print( &gl_defFontMono, x, y, &cFontWhite, "%3.1fx",
980 dt_mod / dt_mod_base );
981
982 if ( !paused || !player_paused || !conf.pause_show )
983 return;
984
985 y = SCREEN_H / 3. - gl_defFontMono.h / 2.;
986 gl_printMidRaw( &gl_defFontMono, SCREEN_W, 0., y, &cFontWhite, -1.,
987 _( "PAUSED" ) );
988}
989
995double fps_current( void )
996{
997 return fps;
998}
999
1005static void update_all( int dohooks )
1006{
1007 NTracingZone( _ctx, 1 );
1008
1009 if ( ( real_dt > 0.25 ) &&
1010 ( fps_skipped == 0 ) ) { /* slow timers down and rerun calculations */
1011 fps_skipped = 1;
1012 NTracingZoneEnd( _ctx );
1013 return;
1014 } else if ( game_dt > fps_min ) { /* We'll force a minimum FPS for physics to
1015 work alright. */
1016 int n;
1017 double nf, microdt, accumdt;
1018
1019 /* Number of frames. */
1020 nf = ceil( game_dt / fps_min );
1021 microdt = game_dt / nf;
1022 n = (int)nf;
1023
1024 /* Update as much as needed, evenly. */
1025 accumdt = 0.;
1026 for ( int i = 0; i < n; i++ ) {
1027 update_routine( microdt, dohooks );
1028 /* OK, so we need a bit of hackish logic here in case we are chopping
1029 * up a very large dt and it turns out time compression changes so
1030 * we're now updating in "normal time compression" zone. This amounts
1031 * to many updates being run when time compression has changed and thus
1032 * can cause, say, the player to exceed their target position or get
1033 * mauled by an enemy ship.
1034 */
1035 accumdt += microdt;
1036 if ( accumdt > dt_mod * real_dt )
1037 break;
1038 }
1039
1040 /* Note we don't touch game_dt so that fps_display works well */
1041 } else /* Standard, just update with the last dt */
1042 update_routine( game_dt, dohooks );
1043
1044 fps_skipped = 0;
1045
1046 NTracingZoneEnd( _ctx );
1047}
1048
1056void update_routine( double dt, int dohooks )
1057{
1058 NTracingZone( _ctx, 1 );
1059
1060 double real_update = dt / dt_mod;
1061
1062 if ( dohooks ) {
1064
1065 /* Update time. */
1066 ntime_update( dt );
1067 }
1068
1069 /* Clean up dead elements and build quadtrees. */
1072
1073 /* Core stuff independent of collisions. */
1074 space_update( dt, real_update );
1075 spfx_update( dt, real_update );
1076
1077 if ( dt > 0. ) {
1078 /* First compute weapon collisions. */
1080 pilots_update( dt );
1081 weapons_update( dt ); /* Has weapons think and update positions. */
1082
1083 /* Update camera. */
1084 cam_update( dt );
1085 }
1086
1087 /* Player autonav. */
1088 player_updateAutonav( real_update );
1089
1090 if ( dohooks ) {
1091 NTracingZoneName( _ctx_hook, "hooks[update]", 1 );
1092 HookParam h[3];
1093 hook_exclusionEnd( dt );
1094 /* Hook set up. */
1095 h[0].type = HOOK_PARAM_NUMBER;
1096 h[0].u.num = dt;
1097 h[1].type = HOOK_PARAM_NUMBER;
1098 h[1].u.num = real_update;
1099 h[2].type = HOOK_PARAM_SENTINEL;
1100 /* Run the update hook. */
1101 hooks_runParam( "update", h );
1102 NTracingZoneEnd( _ctx_hook );
1103 }
1104
1105 /* Update the elapsed time, should be with all the modifications and such. */
1106 elapsed_time_mod += dt;
1107
1108 NTracingZoneEnd( _ctx );
1109}
1110
1114static void window_caption( void )
1115{
1116 char *buf;
1117 SDL_RWops *rw;
1118
1119 /* Load icon. */
1120 rw = PHYSFSRWOPS_openRead( GFX_PATH "icon.webp" );
1121 if ( rw == NULL ) {
1122 WARN( _( "Icon (icon.webp) not found!" ) );
1123 return;
1124 }
1125 naev_icon = IMG_Load_RW( rw, 1 );
1126 if ( naev_icon == NULL ) {
1127 WARN( _( "Unable to load icon.webp!" ) );
1128 return;
1129 }
1130
1131 /* Set caption. */
1132 SDL_asprintf( &buf, APPNAME " - %s", _( start_name() ) );
1133 SDL_SetWindowTitle( gl_screen.window, buf );
1134 SDL_SetWindowIcon( gl_screen.window, naev_icon );
1135 free( buf );
1136}
1137
1138static int binary_comparison( int x, int y )
1139{
1140 if ( x == y )
1141 return 0;
1142 if ( x > y )
1143 return 1;
1144 return -1;
1145}
1151int naev_versionCompare( const char *version )
1152{
1153 int res;
1154 semver_t sv;
1155
1156 if ( semver_parse( version, &sv ) ) {
1157 WARN( _( "Failed to parse version string '%s'!" ), version );
1158 return -1;
1159 }
1160
1161 if ( ( res = 3 * binary_comparison( version_binary.major, sv.major ) ) ==
1162 0 ) {
1163 if ( ( res = 2 * binary_comparison( version_binary.minor, sv.minor ) ) ==
1164 0 ) {
1165 res = semver_compare( version_binary, sv );
1166 }
1167 }
1168 semver_free( &sv );
1169 return res;
1170}
1171
1175int naev_versionCompareTarget( const char *version, const char *target )
1176{
1177 int res;
1178 semver_t sv_version, sv_target;
1179
1180 if ( semver_parse( version, &sv_version ) ) {
1181 WARN( _( "Failed to parse version string '%s'!" ), version );
1182 return -1;
1183 }
1184 if ( semver_parse( target, &sv_target ) ) {
1185 WARN( _( "Failed to parse version string '%s'!" ), target );
1186 return -1;
1187 }
1188
1189 res = semver_compare( sv_version, sv_target );
1190 semver_free( &sv_target );
1191 semver_free( &sv_version );
1192 return res;
1193}
1194
1198static void print_SDLversion( void )
1199{
1200 const SDL_version *linked;
1201 SDL_version compiled;
1202 unsigned int version_linked, version_compiled;
1203
1204 /* Extract information. */
1205 SDL_VERSION( &compiled );
1206 SDL_version ll;
1207 SDL_GetVersion( &ll );
1208 linked = &ll;
1209 DEBUG( _( "SDL: %d.%d.%d [compiled: %d.%d.%d]" ), linked->major,
1210 linked->minor, linked->patch, compiled.major, compiled.minor,
1211 compiled.patch );
1212#ifndef DEBUGGING /* Shuts up cppcheck. */
1213 (void)compiled.patch;
1214#endif /* DEBUGGING */
1215
1216 /* Get version as number. */
1217 version_linked = linked->major * 100 + linked->minor;
1218 version_compiled = compiled.major * 100 + compiled.minor;
1219
1220 /* Check if major/minor version differ. */
1221 if ( version_linked > version_compiled )
1222 WARN( _( "SDL is newer than compiled version" ) );
1223 if ( version_linked < version_compiled )
1224 WARN( _( "SDL is older than compiled version." ) );
1225}
1226
1230double naev_getrealdt( void )
1231{
1232 return real_dt;
1233}
void ai_exit(void)
Cleans up global AI.
Definition ai.c:788
int ai_load(void)
Initializes the AI stuff which is basically Lua.
Definition ai.c:589
int background_init(void)
Initializes the background system.
Definition background.c:492
void background_initDust(int n)
Initializes background dust.
Definition background.c:97
void background_free(void)
Cleans up and frees memory after the backgrounds.
Definition background.c:602
int background_load(const char *name)
Loads a background script by name.
Definition background.c:502
void cam_update(double dt)
Updates the camera.
Definition camera.c:232
void commodity_free(void)
Frees all the loaded commodities.
Definition commodity.c:586
int commodity_load(void)
Loads all the commodity data.
Definition commodity.c:513
void cond_exit(void)
Destroys the conditional subsystem.
Definition cond.c:40
int cond_init(void)
Initializes the conditional subsystem.
Definition cond.c:23
void cli_exit(void)
Destroys the CLI environment.
Definition console.c:528
int cli_init(void)
Initializes the CLI environment.
Definition console.c:508
int dtype_load(void)
Loads the dtype stack.
Definition damagetype.c:197
void dtype_free(void)
Frees the dtype stack.
Definition damagetype.c:233
void debug_sigInit(void)
Sets up the back-tracing signal handler.
Definition debug.c:259
void debug_enableLeakSanitizer(void)
Does nothing. Calling this tells our debug scripts to stop tracing.
Definition debug.c:313
void debug_sigClose(void)
Closes the back-tracing signal handler.
Definition debug.c:301
void debug_enableFPUExcept(void)
Enables FPU exceptions. Artificially limited to Linux until link issues are figured out.
Definition debug_fpu.c:27
void dialogue_msg(const char *caption, const char *fmt,...)
Opens a dialogue window with an ok button and a message.
Definition dialogue.c:227
void economy_destroy(void)
Destroys the economy.
Definition economy.c:583
int effect_load(void)
Loads all the effects.
Definition effect.c:199
void effect_exit(void)
Gets rid of all the effects.
Definition effect.c:244
void events_exit(void)
Exits the event subsystem.
Definition event.c:749
int events_load(void)
Loads all the events.
Definition event.c:567
int factions_load(void)
Loads up all the factions from the data file.
Definition faction.c:1994
void factions_free(void)
Frees the factions.
Definition faction.c:2188
glFont gl_smallFont
Definition font.c:159
glFont gl_defFont
Definition font.c:158
int gl_printMidRaw(const glFont *ft_font, int width, double x, double y, const glColour *c, double outlineR, const char *text)
Displays text centered in position and width.
Definition font.c:821
void gl_print(const glFont *ft_font, const double x, const double y, const glColour *c, const char *fmt,...)
Prints text on screen like printf.
Definition font.c:725
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
Definition font.c:1881
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
Definition font.c:1670
void gl_fontExit(void)
Frees all resources associated with the font system. This also resets font ID tracking,...
Definition font.c:1930
glFont gl_defFontMono
Definition font.c:160
void gettext_exit(void)
Free resources associated with the translation system. This invalidates previously returned pointers ...
Definition gettext.c:89
double gettext_languageCoverage(const char *lang)
Return the fraction of strings which have a translation into the given language.
Definition gettext.c:312
void gettext_setLanguage(const char *lang)
Set the translation language.
Definition gettext.c:135
const char * gettext_getLanguage(void)
Gets the active (primary) translation language. Even in case of a complex locale, this will be the na...
Definition gettext.c:122
void gettext_init(void)
Initialize the translation system. There's no presumption that PhysicsFS is available,...
Definition gettext.c:53
int gui_init(void)
Initializes the GUI system.
Definition gui.c:1714
void gui_free(void)
Frees the gui stuff.
Definition gui.c:2107
void gui_reload(void)
Reloads the GUI.
Definition gui.c:1845
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
Definition hook.c:1029
void hook_exclusionEnd(double dt)
Ends exclusion zone and runs all the queued hooks.
Definition hook.c:199
int hooks_run(const char *stack)
Runs all the hooks of stack.
Definition hook.c:1049
void hook_exclusionStart(void)
Starts the hook exclusion zone, this makes hooks queue until exclusion is done.
Definition hook.c:191
void input_init(void)
Initializes the input subsystem (does not set keys).
Definition input.c:371
void input_handle(SDL_Event *event)
Handles global input.
Definition input.c:1833
void input_setDefault(int wasd)
Sets the default input keys.
Definition input.c:267
void input_update(double dt)
Handles key repeating.
Definition input.c:740
void input_exit(void)
Exits the input system.
Definition input.c:420
int joystick_get(const char *namjoystick)
Gets the joystick index by name.
Definition joystick.c:35
int joystick_init(void)
Initializes the joystick subsystem.
Definition joystick.c:147
int joystick_use(int indjoystick)
Makes the game use a joystick by index.
Definition joystick.c:54
void joystick_exit(void)
Exits the joystick subsystem.
Definition joystick.c:171
void land_exit(void)
Exits all the landing stuff.
Definition land.c:1999
void load_free(void)
Frees loaded save stuff.
Definition load.c:595
void log_clean(void)
Deletes useless (empty) log files from the current session.
Definition log.c:228
void log_init(void)
Sets up the logging subsystem. (Calling this ensures logging output is preserved until we have a plac...
Definition log.c:164
void log_redirect(void)
Sets up redirection of stdout and stderr to files. PhysicsFS must be initialized for this to work.
Definition log.c:130
Handles the important game menus.
void menu_main(void)
Opens the main menu (titlescreen).
Definition menu.c:170
int menu_askQuit(void)
Menu to ask if player really wants to quit.
Definition menu.c:701
void menu_main_resize(void)
Resizes the main menu and its background.
Definition menu.c:279
void missions_free(void)
Frees all the mission data.
Definition mission.c:1304
int missions_load(void)
Loads all the mission data.
Definition mission.c:1168
int music_disabled
Definition music.c:29
int music_choose(const char *situation)
Actually runs the music stuff, based on situation.
Definition music.c:426
void music_exit(void)
Exits the music subsystem.
Definition music.c:142
void naev_renderLoadscreen(void)
Renders the loadscreen if necessary.
Definition naev.c:640
static double fps_dt
Definition naev.c:109
int naev_versionCompare(const char *version)
Compares the version against the current naev version.
Definition naev.c:1151
static int quit
Definition naev.c:98
static SDL_Surface * naev_icon
Definition naev.c:101
double elapsed_time_mod
Definition naev.c:117
static void fps_init(void)
Initializes the fps engine.
Definition naev.c:936
void update_routine(double dt, int dohooks)
Actually runs the updates.
Definition naev.c:1056
static int fps_skipped
Definition naev.c:102
int naev_shouldRenderLoadscreen(void)
Whether or not we want to render the loadscreen.
Definition naev.c:596
static void loadscreen_unload(void)
Frees the loading screen.
Definition naev.c:671
static void print_SDLversion(void)
Prints the SDL version to console.
Definition naev.c:1198
static void unload_all(void)
Unloads all data, simplifies main().
Definition naev.c:762
static double fps
Definition naev.c:112
void fps_display(double dt)
Displays FPS on the screen.
Definition naev.c:955
void naev_quit(void)
Flags naev to quit.
Definition naev.c:145
double fps_current(void)
Gets the current FPS.
Definition naev.c:995
#define LOADING_STAGES
Loads all the data, makes main() simpler.
Definition naev.c:680
void naev_resize(void)
Wrapper for gl_resize that handles non-GL reinitialization.
Definition naev.c:874
int naev_versionCompareTarget(const char *version, const char *target)
Does a comparison with a specific target.
Definition naev.c:1175
int naev_isQuit(void)
Get if Naev is trying to quit.
Definition naev.c:153
static void window_caption(void)
Sets the window caption.
Definition naev.c:1114
static void loadscreen_update(double done, const char *msg)
Renders the load screen with message.
Definition naev.c:652
static void loadscreen_load(void)
Loads a loading screen.
Definition naev.c:560
static semver_t version_binary
Definition naev.c:104
const double fps_min
Definition naev.c:116
void main_loop(int nested)
Split main loop from main() for secondary loop hack in toolkit.c.
Definition naev.c:795
static double fps_x
Definition naev.c:114
double naev_getrealdt(void)
Gets the last delta-tick.
Definition naev.c:1230
static nlua_env load_env
Definition naev.c:119
static void update_all(int dohooks)
Updates the game itself (player flying around and friends).
Definition naev.c:1005
static double game_dt
Definition naev.c:110
static double fps_y
Definition naev.c:115
Uint32 SDL_LOOPDONE
Definition naev.c:99
static double fps_cur
Definition naev.c:113
static double real_dt
Definition naev.c:111
static Uint64 last_t
Definition naev.c:100
void fps_setPos(double x, double y)
Sets the position to display the FPS.
Definition naev.c:944
Header file with generic functions and naev-specifics.
#define APPNAME
Definition naev.h:30
const char * naev_version(int long_version)
Returns the version in a human readable string.
#define PATH_MAX
Definition naev.h:57
void ndata_setupReadDirs(void)
Sets up the PhysicsFS search path.
Definition ndata.c:155
void ndata_setupWriteDir(void)
Gets Naev's data path (for user data such as saves and screenshots)
Definition ndata.c:132
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
Definition ndata.c:207
void nebu_exit(void)
Cleans up the nebu subsystem.
Definition nebula.c:132
int nebu_resize(void)
Handles a screen s.
Definition nebula.c:84
int nebu_init(void)
Initializes the nebula.
Definition nebula.c:73
void news_exit(void)
Kills the old news thread.
Definition news.c:139
const char * nfile_configPath(void)
Gets Naev's config path (for user preferences such as conf.lua)
Definition nfile.c:113
int nfile_dirMakeExist(const char *path)
Creates a directory if it doesn't exist.
Definition nfile.c:277
const char * nfile_cachePath(void)
Gets Naev's cache path (for cached data such as generated textures)
Definition nfile.c:162
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
Definition nlua.c:914
void nlua_resize(void)
Propagates a resize event to all the environments forcibly.
Definition nlua.c:1097
lua_State * naevL
Definition nlua.c:54
int nlua_loadCol(nlua_env env)
Loads the colour library.
Definition nlua_colour.c:57
int nlua_loadData(nlua_env env)
Loads the data library.
Definition nlua_data.c:51
int nlua_loadFile(nlua_env env)
Loads the file library.
Definition nlua_file.c:63
int nlua_loadGFX(nlua_env env)
Loads the graphics library.
Definition nlua_gfx.c:112
int nlua_loadNaev(nlua_env env)
Loads the Naev Lua library.
Definition nlua_naev.c:135
int nlua_loadRnd(nlua_env env)
Loads the Random Number Lua library.
Definition nlua_rnd.c:43
int nlua_loadTex(nlua_env env)
Loads the texture library.
Definition nlua_tex.c:59
void var_cleanup(void)
Cleans up all the mission variables.
Definition nlua_var.c:194
int nlua_loadVector(nlua_env env)
Loads the vector metatable.
Definition nlua_vec2.c:85
void npc_clear(void)
Cleans up the spaceport bar NPC.
Definition npc.c:477
void ntime_update(double dt)
Updatse the time based on realtime.
Definition ntime.c:74
void gl_resize(void)
Handles a window resize and resets gl_screen parameters.
Definition opengl.c:689
void gl_exit(void)
Cleans up OpenGL, the works.
Definition opengl.c:931
int gl_init(unsigned int extra_flags)
Initializes SDL/OpenGL and the works.
Definition opengl.c:600
glInfo gl_screen
Definition opengl.c:47
int opt_setVideoMode(int w, int h, int fullscreen, int confirm)
Applies new video-mode options.
Definition options.c:1646
void opt_resize(void)
Handles resize events for the options menu.
Definition options.c:241
int outfit_load(void)
Loads all the outfits.
Definition outfit.c:3023
int outfit_mapParse(void)
Parses all the maps.
Definition outfit.c:3257
void outfit_free(void)
Frees the outfit stack.
Definition outfit.c:3333
int outfit_loadPost(void)
Loads all the outfits legality.
Definition outfit.c:3203
int player_paused
Definition pause.c:19
int paused
Definition pause.c:18
double dt_mod
Definition pause.c:20
void pilots_updatePurge(void)
Purges pilots set for deletion.
Definition pilot.c:4176
void pilots_init(void)
Initializes pilot stuff.
Definition pilot.c:4010
void pilots_update(double dt)
Updates all the pilots.
Definition pilot.c:4216
void pilots_free(void)
Frees the pilot stack.
Definition pilot.c:4019
void player_cleanup(void)
Cleans up player stuff like player_stack.
Definition player.c:800
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
Definition player.c:2001
Player_t player
Definition player.c:77
int player_init(void)
Initializes player stuff.
Definition player.c:199
void player_updateAutonav(double dt)
Updates the player's autonav.
int plugin_check(void)
Checks to see if the plugins are self-declared compatible with Naev.
Definition plugin.c:341
void plugin_exit(void)
Exits the plugin stuff.
Definition plugin.c:299
void rng_init(void)
Initializes the random subsystem.
Definition rng.c:53
void safelanes_destroy(void)
Shuts down the safelanes system.
Definition safelanes.c:218
void safelanes_init(void)
Initializes the safelanes system.
Definition safelanes.c:206
int ships_load(void)
Loads all the ships in the data files.
Definition ship.c:1567
void ships_free(void)
Frees all the ships.
Definition ship.c:1743
void sp_cleanup(void)
Cleans up after the slot properties.
Definition slots.c:120
int sp_load(void)
Initializes the slot properties.
Definition slots.c:46
int sound_disabled
Definition sound.c:130
void sound_exit(void)
Cleans up after the sound subsytem.
Definition sound.c:670
int sound_update(double dt)
Updates the sounds removing obsolete ones and such.
Definition sound.c:914
int sound_init(void)
Initializes the sound subsystem.
Definition sound.c:609
void space_update(double dt, double real_dt)
Controls fleet spawning.
Definition space.c:1482
StarSystem * cur_system
Definition space.c:110
void space_exit(void)
Cleans up the system.
Definition space.c:3824
void space_checkLand(void)
Handles landing if necessary.
Definition space.c:1468
int space_load(void)
Loads the entire universe into ram - pretty big feat eh?
Definition space.c:3532
int space_loadLua(void)
initializes the Lua for all the spobs.
Definition space.c:3569
void spfx_free(void)
Frees the spfx stack.
Definition spfx.c:448
int spfx_load(void)
Loads the spfx stack.
Definition spfx.c:375
void spfx_update(const double dt, const double real_dt)
Updates all the spfx.
Definition spfx.c:582
void start_cleanup(void)
Cleans up after the module start data.
Definition start.c:161
int start_load(void)
Loads the module start data.
Definition start.c:51
const char * start_name(void)
Gets the module name.
Definition start.c:182
The actual hook parameter.
Definition hook.h:40
HookParamType type
Definition hook.h:41
union HookParam::@325330313164266255110350307176363262300250041145 u
double num
Definition hook.h:43
void tech_free(void)
Cleans up after the tech stuff.
Definition tech.c:161
int tech_load(void)
Loads the tech information.
Definition tech.c:106
void toolkit_resize(void)
Repositions windows and their children if resolution changes.
Definition toolkit.c:2612
void toolkit_update(void)
Updates the toolkit input for repeating keys.
Definition toolkit.c:2241
void toolkit_exit(void)
Exits the toolkit.
Definition toolkit.c:2682
int toolkit_init(void)
Initializes the toolkit.
Definition toolkit.c:2664
void toolkit_rerender(void)
Marks the toolkit for needing a full rerender.
Definition toolkit.c:1675
int diff_init(void)
Loads available universe diffs.
Definition unidiff.c:480
void diff_exit(void)
Clean up after diffs.
Definition unidiff.c:560
void weapons_update(double dt)
Updates all the weapons.
Definition weapon.c:742
void weapons_updatePurge(void)
Purges unnecessary weapons.
Definition weapon.c:609
void weapons_updateCollide(double dt)
Handles weapon collisions.
Definition weapon.c:658
void weapon_exit(void)
Destroys all the weapons and frees it all.
Definition weapon.c:2870
void weapon_init(void)
Initializes the weapon stuff.
Definition weapon.c:144