16#include "physfsrwops.h"
30#include "background.h"
35#include "damagetype.h"
38#include "difficulty.h"
52#include "map_overlay.h"
53#include "map_system.h"
64#include "nlua_colour.h"
93#include "threadpool.h"
98#define VERSION_FILE "VERSION"
122static int load_force_render = 0;
123static unsigned int load_last_render = 0;
132static void load_all (
void);
167int main(
int argc,
char** argv )
169 char conf_file_path[
PATH_MAX], **search_path;
174 memset( debug_flags , 0, DEBUG_FLAGS_MAX );
177 env_detect( argc, argv );
182 if (PHYSFS_init( env.argv0 ) == 0) {
183 ERR(
"PhysicsFS initialization failed: %s",
184 _( PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) ) );
187 PHYSFS_permitSymbolicLinks( 1 );
195 WARN( _(
"Failed to parse version string '%s'!"),
naev_version( 0 ) );
201 LOG(
"AppImage detected. Running from: %s", env.appdir );
203 DEBUG(
"AppImage not detected." );
207 ERR( _(
"Unable to initialize SDL: %s" ), SDL_GetError() );
210 starttime = SDL_GetTicks();
221 nsetenv(
"SDL_VIDEO_X11_WMCLASS",
APPNAME, 0);
225 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
226 WARN( _(
"Unable to initialize SDL Video: %s"), SDL_GetError());
246 conf_loadConfigPath();
253 snprintf(conf_file_path,
sizeof(conf_file_path),
"%s"CONF_FILE,
nfile_configPath());
255 conf_loadConfig(conf_file_path);
256 conf_parseCLI( argc, argv );
263 LOG( _(
"Loaded configuration: %s"), conf_file_path );
264 search_path = PHYSFS_getSearchPath();
265 LOG(
"%s", _(
"Read locations, searched in order:") );
266 for (
char **p = search_path; *p != NULL; p++)
268 PHYSFS_freeList( search_path );
271 LOG( _(
"Write location: %s\n"), PHYSFS_getWriteDir() );
279 ERR( _(
"Failed to load module start data.") );
294 ERR( _(
"Initializing video output failed, exiting…") );
319 WARN( _(
"Error initializing joystick input") );
322 WARN( _(
"Failure to open any joystick, falling back to default keybinds") );
329 WARN( _(
"Failure to open any joystick, falling back to default keybinds") );
338 LOG( _(
"Sound is disabled!") );
343 WARN( _(
"Problem setting up sound!") );
353 ERR( _(
"Unable to initialize the Nebula subsystem!") );
376 LOG( _(
"Reached main menu in %.3f s" ), (SDL_GetTicks()-starttime)/1000. );
378 LOG( _(
"Reached main menu" ) );
388 while (SDL_PollEvent(&event));
398 if (coverage < 0.8) {
401 _(
"Incomplete Translation"),
402 _(
"%s is partially translated (%.0f%%) into your language (%s),"
403 " but the remaining text will be English. Language settings"
404 " are available in the \"%s\" screen."),
405 APPNAME, 100.*coverage, language, _(
"Options") );
414 _(
"Welcome to Naev"),
415 _(
"Welcome to Naev version %s, and thank you for playing! We hope you"
416 " enjoy this game and all it has to offer. This is a passion"
417 " project developed exclusively by volunteers and it gives us all"
418 " great joy to know that there are others who love this game as"
420 " Of course, please note that this is an incomplete game. You"
421 " will encounter dead ends to storylines, missing storylines, and"
422 " possibly even some bugs, although we try to keep those to a"
423 " minimum of course. So be prepared for some rough edges for the"
424 " time being. That said, we are working on this game every day and"
425 " hope to one day finish this massive project on our hands."
426 " Perhaps you could become one of us, who knows?\n"
427 " For more information about the game and its development"
428 " state, take a look at naev.org; it has all the relevant links."
429 " And again, thank you for playing!"), conf.
lastversion );
434 while (!
quit && SDL_PollEvent(&event)) {
435 if (event.type == SDL_QUIT) {
441 else if (event.type == SDL_WINDOWEVENT &&
442 event.window.event == SDL_WINDOWEVENT_RESIZED) {
453 conf_saveConfig(conf_file_path);
531 WARN(_(
"Something went wrong when loading Lua libraries for '%s'!"), LOADSCREEN_DATA_PATH);
534 char *buf =
ndata_read( LOADSCREEN_DATA_PATH, &bufsize );
535 if (nlua_dobufenv(
load_env, buf, bufsize, LOADSCREEN_DATA_PATH) != 0) {
536 WARN( _(
"Error loading file: %s\n"
538 "Most likely Lua file has improper syntax, please check"),
539 LOADSCREEN_DATA_PATH, lua_tostring(naevL,-1));
552 unsigned int t = SDL_GetTicks();
555 if (!load_force_render && (t-load_last_render) < 100 )
557 load_last_render = t;
560 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
563 nlua_getenv( naevL,
load_env,
"render" );
565 WARN( _(
"Loadscreen '%s': '%s'"),
"render", lua_tostring(naevL,-1));
570 while (SDL_PollEvent(&event));
577 load_force_render = 0;
589 nlua_getenv( naevL,
load_env,
"update" );
590 lua_pushnumber( naevL, done );
591 lua_pushstring( naevL, msg );
593 WARN( _(
"Loadscreen '%s': '%s'"),
"update", lua_tostring(naevL,-1));
598 load_force_render = 1;
613#define LOADING_STAGES 17.
672 WARN(_(
"Too many loading stages, please increase LOADING_STAGES"));
803 render_all( 0., 0. );
807 load_force_render = 1;
813void naev_toggleFullscreen (
void)
818#if HAS_POSIX && defined(CLOCK_MONOTONIC)
819static struct timespec global_time;
820static int use_posix_time;
827#if HAS_POSIX && defined(CLOCK_MONOTONIC)
832 if (clock_gettime(CLOCK_MONOTONIC, &global_time)==0)
834 WARN( _(
"clock_gettime failed, disabling POSIX time.") );
849#if HAS_POSIX && defined(CLOCK_MONOTONIC)
852 if (use_posix_time) {
853 if (clock_gettime(CLOCK_MONOTONIC, &ts)==0) {
854 dt = ts.tv_sec - global_time.tv_sec;
855 dt += (ts.tv_nsec - global_time.tv_nsec) / 1e9;
859 WARN( _(
"clock_gettime failed!") );
886 const double fps_max = 1./(double)conf.
fps_max;
888 double delay = fps_max -
real_dt;
890 ts.tv_sec = floor( delay );
891 ts.tv_nsec = fmod( delay, 1. ) * 1e9;
892 nanosleep( &ts, NULL );
894 SDL_Delay( (
unsigned int)(delay * 1000) );
918 double dt_mod_base = 1.;
934 if ((
player.
p != NULL) && !player_isFlag(PLAYER_DESTROYED) &&
935 !player_isFlag(PLAYER_CREATING)) {
938 if (
dt_mod != dt_mod_base)
946 &cFontWhite, -1., _(
"PAUSED") );
962 double nf, microdt, accumdt;
971 for (
int i=0; i<n; i++) {
1023 h[0].
type = HOOK_PARAM_NUMBER;
1025 h[1].
type = HOOK_PARAM_NUMBER;
1027 h[2].
type = HOOK_PARAM_SENTINEL;
1042 rw = PHYSFSRWOPS_openRead( GFX_PATH
"icon.webp" );
1044 WARN( _(
"Icon (icon.webp) not found!") );
1049 WARN( _(
"Unable to load icon.webp!") );
1060static int binary_comparison(
int x,
int y )
1062 if (x == y)
return 0;
1063 if (x > y)
return 1;
1076 if (semver_parse( version, &sv )) {
1077 WARN( _(
"Failed to parse version string '%s'!"), version );
1081 if ((res = 3*binary_comparison(
version_binary.major, sv.major)) == 0) {
1082 if ((res = 2*binary_comparison(
version_binary.minor, sv.minor)) == 0) {
1095 const SDL_version *linked;
1096 SDL_version compiled;
1097 unsigned int version_linked, version_compiled;
1100 SDL_VERSION(&compiled);
1102 SDL_GetVersion( &ll );
1104 DEBUG( _(
"SDL: %d.%d.%d [compiled: %d.%d.%d]"),
1105 linked->major, linked->minor, linked->patch,
1106 compiled.major, compiled.minor, compiled.patch);
1109 version_linked = linked->major*100 + linked->minor;
1110 version_compiled = compiled.major*100 + compiled.minor;
1113 if (version_linked > version_compiled)
1114 WARN( _(
"SDL is newer than compiled version") );
1115 if (version_linked < version_compiled)
1116 WARN( _(
"SDL is older than compiled version.") );
void ai_exit(void)
Cleans up global AI.
int ai_load(void)
Initializes the AI stuff which is basically Lua.
int background_init(void)
Initializes the background system.
void background_initDust(int n)
Initializes background stars.
void background_free(void)
Cleans up and frees memory after the backgrounds.
void cam_update(double dt)
Updates the camera.
void cond_exit(void)
Destroys the conditional subsystem.
int cond_init(void)
Initializes the conditional subsystem.
void cli_exit(void)
Destroys the CLI environment.
int cli_init(void)
Initializes the CLI environment.
int dtype_load(void)
Loads the dtype stack.
void dtype_free(void)
Frees the dtype stack.
void debug_sigInit(void)
Sets up the back-tracing signal handler.
void debug_enableLeakSanitizer(void)
Does nothing. Calling this tells our debug scripts to stop tracing.
void debug_sigClose(void)
Closes the back-tracing signal handler.
void debug_enableFPUExcept(void)
Enables FPU exceptions. Artificially limited to Linux until link issues are figured out.
void dialogue_msg(const char *caption, const char *fmt,...)
Opens a dialogue window with an ok button and a message.
int dialogue_isOpen(void)
Checks to see if a dialogue is open.
void economy_destroy(void)
Destroys the economy.
int effect_load(void)
Loads all the effects.
void effect_exit(void)
Gets rid of all the effects.
void events_exit(void)
Exits the event subsystem.
int events_load(void)
Loads all the events.
int factions_load(void)
Loads up all the factions from the data file.
void factions_free(void)
Frees the factions.
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.
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.
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
void gl_fontExit(void)
Frees all resources associated with the font system. This also resets font ID tracking,...
void gettext_exit(void)
Free resources associated with the translation system. This invalidates previously returned pointers ...
double gettext_languageCoverage(const char *lang)
Return the fraction of strings which have a translation into the given language.
void gettext_setLanguage(const char *lang)
Set the translation language.
const char * gettext_getLanguage(void)
Gets the active (primary) translation language. Even in case of a complex locale, this will be the na...
void gettext_init(void)
Initialize the translation system. There's no presumption that PhysicsFS is available,...
int gui_init(void)
Initializes the GUI system.
void gui_free(void)
Frees the gui stuff.
void gui_reload(void)
Reloads the GUI.
int hooks_runParam(const char *stack, const HookParam *param)
Runs all the hooks of stack.
void hook_exclusionEnd(double dt)
Ends exclusion zone and runs all the queued hooks.
int hooks_run(const char *stack)
Runs all the hooks of stack.
void hook_exclusionStart(void)
Starts the hook exclusion zone, this makes hooks queue until exclusion is done.
int joystick_get(const char *namjoystick)
Gets the joystick index by name.
int joystick_init(void)
Initializes the joystick subsystem.
int joystick_use(int indjoystick)
Makes the game use a joystick by index.
void joystick_exit(void)
Exits the joystick subsystem.
void land_exit(void)
Exits all the landing stuff.
void load_free(void)
Frees loaded save stuff.
void log_clean(void)
Deletes useless (empty) log files from the current session.
void log_init(void)
Sets up the logging subsystem. (Calling this ensures logging output is preserved until we have a plac...
void log_redirect(void)
Sets up redirection of stdout and stderr to files. PhysicsFS must be initialized for this to work.
void missions_free(void)
Frees all the mission data.
int missions_load(void)
Loads all the mission data.
int music_choose(const char *situation)
Actually runs the music stuff, based on situation.
void music_exit(void)
Exits the music subsystem.
void naev_renderLoadscreen(void)
Renders the loadscreen if necessary.
int naev_versionCompare(const char *version)
Compares the version against the current naev version.
static SDL_Surface * naev_icon
static void update_all(void)
Updates the game itself (player flying around and friends).
static unsigned int time_ms
int main(int argc, char **argv)
The entry point of Naev.
static void fps_init(void)
Initializes the fps engine.
static void loadscreen_unload(void)
Frees the loading screen.
void display_fps(const double dt)
Displays FPS on the screen.
void main_loop(int update)
Split main loop from main() for secondary loop hack in toolkit.c.
static void print_SDLversion(void)
Prints the SDL version to console.
static void unload_all(void)
Unloads all data, simplifies main().
void update_routine(double dt, int enter_sys)
Actually runs the updates.
void naev_quit(void)
Flags naev to quit.
static double fps_elapsed(void)
Gets the elapsed time.
#define LOADING_STAGES
Loads all the data, makes main() simpler.
void naev_resize(void)
Wrapper for gl_resize that handles non-GL reinitialization.
int naev_isQuit(void)
Get if Naev is trying to quit.
static void window_caption(void)
Sets the window caption.
static void loadscreen_update(double done, const char *msg)
Renders the load screen with message.
static void loadscreen_load(void)
Loads a loading screen.
static semver_t version_binary
double naev_getrealdt(void)
Gets the last delta-tick.
static void fps_control(void)
Controls the FPS.
void fps_setPos(double x, double y)
Sets the position to display the FPS.
Header file with generic functions and naev-specifics.
const char * naev_version(int long_version)
Returns the version in a human readable string.
void ndata_setupReadDirs(void)
Sets up the PhysicsFS search path.
void ndata_setupWriteDir(void)
Gets Naev's data path (for user data such as saves and screenshots)
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
void nebu_exit(void)
Cleans up the nebu subsystem.
int nebu_resize(void)
Handles a screen s.
int nebu_init(void)
Initializes the nebula.
void news_exit(void)
Kills the old news thread.
static char buf[NEWS_MAX_LENGTH]
const char * nfile_configPath(void)
Gets Naev's config path (for user preferences such as conf.lua)
int nfile_dirMakeExist(const char *path)
Creates a directory if it doesn't exist.
const char * nfile_cachePath(void)
Gets Naev's cache path (for cached data such as generated textures)
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
void nlua_resize(void)
Propagates a resize event to all the environments forcibly.
int nlua_loadCol(nlua_env env)
Loads the colour library.
int nlua_loadData(nlua_env env)
Loads the data library.
int nlua_loadFile(nlua_env env)
Loads the file library.
int nlua_loadGFX(nlua_env env)
Loads the graphics library.
int nlua_loadNaev(nlua_env env)
Loads the Naev Lua library.
int nlua_loadRnd(nlua_env env)
Loads the Random Number Lua library.
int nlua_loadTex(nlua_env env)
Loads the texture library.
void var_cleanup(void)
Cleans up all the mission variables.
int nlua_loadVector(nlua_env env)
Loads the vector metatable.
void npc_clear(void)
Cleans up the spaceport bar NPC.
int asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
void ntime_update(double dt)
Updatse the time based on realtime.
void gl_resize(void)
Handles a window resize and resets gl_screen parameters.
void gl_exit(void)
Cleans up OpenGL, the works.
int gl_init(void)
Initializes SDL/OpenGL and the works.
int opt_setVideoMode(int w, int h, int fullscreen, int confirm)
Applies new video-mode options.
void opt_resize(void)
Handles resize events for the options menu.
int outfit_load(void)
Loads all the outfits.
int outfit_mapParse(void)
Parses all the maps.
void outfit_free(void)
Frees the outfit stack.
int outfit_loadPost(void)
Loads all the outfits legality.
void pilots_init(void)
Initializes pilot stuff.
void pilots_update(double dt)
Updates all the pilots.
void pilots_free(void)
Frees the pilot stack.
void player_cleanup(void)
Cleans up player stuff like player_stack.
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
int player_init(void)
Initializes player stuff.
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.
void plugin_exit(void)
Exits the plugin stuff.
void rng_init(void)
Initializes the random subsystem.
void safelanes_destroy(void)
Shuts down the safelanes system.
void safelanes_init(void)
Initializes the safelanes system.
int ships_load(void)
Loads all the ships in the data files.
void ships_free(void)
Frees all the ships.
void sp_cleanup(void)
Cleans up after the slot properties.
int sp_load(void)
Initializes the slot properties.
void sound_exit(void)
Cleans up after the sound subsytem.
int sound_update(double dt)
Updates the sounds removing obsolete ones and such.
int sound_init(void)
Initializes the sound subsystem.
void space_update(double dt, double real_dt)
Controls fleet spawning.
void space_exit(void)
Cleans up the system.
void space_checkLand(void)
Handles landing if necessary.
int space_load(void)
Loads the entire universe into ram - pretty big feat eh?
int space_loadLua(void)
initializes the Lua for all the spobs.
void spfx_free(void)
Frees the spfx stack.
int spfx_load(void)
Loads the spfx stack.
void spfx_update(const double dt, const double real_dt)
Updates all the spfx.
void start_cleanup(void)
Cleans up after the module start data.
int start_load(void)
Loads the module start data.
const char * start_name(void)
Gets the module name.
The actual hook parameter.
int translation_warning_seen
void tech_free(void)
Cleans up after the tech stuff.
int tech_load(void)
Loads the tech information.
int diff_loadAvailable(void)
Loads available universe diffs.
void diff_free(void)
Clean up after diff_loadAvailable().
void weapons_update(const double dt)
Updates all the weapon layers.
void weapon_exit(void)
Destroys all the weapons and frees it all.
void weapon_init(void)
Initializes the weapon stuff.