6#include "nlua_camera.h"
8#include "nlua_linopt.h"
12const char *__asan_default_options()
14 return "detect_leaks=0";
17int main(
int argc,
char **argv )
19 char conf_file_path[
PATH_MAX], **search_path;
23 memset( debug_flags, 0, DEBUG_FLAGS_MAX );
26 env_detect( argc, argv );
31 if ( PHYSFS_init( env.argv0 ) == 0 ) {
33 snprintf( buf,
sizeof( buf ),
"PhysicsFS initialization failed: %s",
34 PHYSFS_getErrorByCode( PHYSFS_getLastErrorCode() ) );
35#if SDL_VERSION_ATLEAST( 3, 0, 0 )
36 SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,
37 _(
"Naev Critical Error" ), buf,
43 PHYSFS_permitSymbolicLinks( 1 );
51 WARN( _(
"Failed to parse version string '%s'!" ),
naev_version( 0 ) );
58 LOG(
"AppImage detected. Running from: %s", env.appdir );
60 DEBUG(
"AppImage not detected." );
64 if ( SDL_Init( 0 ) ) {
66 snprintf( buf,
sizeof( buf ), _(
"Unable to initialize SDL: %s" ),
68#if SDL_VERSION_ATLEAST( 3, 0, 0 )
69 SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,
70 _(
"Naev Critical Error" ), buf,
85 SDL_setenv(
"SDL_VIDEO_X11_WMCLASS",
APPNAME, 0 );
89 if ( SDL_InitSubSystem( SDL_INIT_VIDEO ) < 0 ) {
90 WARN( _(
"Unable to initialize SDL Video: %s" ), SDL_GetError() );
111 conf_loadConfigPath();
118 snprintf( conf_file_path,
sizeof( conf_file_path ),
"%s" CONF_FILE,
121 conf_loadConfig( conf_file_path );
122 int opt = conf_parseCLI( argc, argv );
124 LOG( _(
"Missing Lua file!" ) );
127 strncpy( luafile, argv[opt++],
sizeof( luafile ) );
134 LOG( _(
"Loaded configuration: %s" ), conf_file_path );
135 search_path = PHYSFS_getSearchPath();
136 LOG(
"%s", _(
"Read locations, searched in order:" ) );
137 for (
char **p = search_path; *p != NULL; p++ )
139 PHYSFS_freeList( search_path );
142 LOG( _(
"Write location: %s\n" ), PHYSFS_getWriteDir() );
145 if ( conf.fpu_except )
151 snprintf( buf,
sizeof( buf ), _(
"Failed to load module start data." ) );
152#if SDL_VERSION_ATLEAST( 3, 0, 0 )
153 SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,
154 _(
"Naev Critical Error" ), buf,
172 if (
gl_init( SDL_WINDOW_HIDDEN ) ) {
174 snprintf( buf,
sizeof( buf ),
175 _(
"Initializing video output failed, exiting…" ) );
176#if SDL_VERSION_ATLEAST( 3, 0, 0 )
177 SDL_ShowSimpleMessageBox( SDL_MESSAGEBOX_ERROR,
178 _(
"Naev Critical Error" ), buf,
183 exit( EXIT_FAILURE );
191 FONT_PATH_PREFIX, 0 );
193 FONT_PATH_PREFIX, 0 );
195 FONT_PATH_PREFIX, 0 );
203 last_t = SDL_GetPerformanceCounter();
208 if ( ( conf.joystick_ind >= 0 ) || ( conf.joystick_nam != NULL ) ) {
210 WARN( _(
"Error initializing joystick input" ) );
211 if ( conf.joystick_nam !=
214 WARN( _(
"Failure to open any joystick, falling back to default "
218 free( conf.joystick_nam );
219 }
else if ( conf.joystick_ind >= 0 )
221 WARN( _(
"Failure to open any joystick, falling back to default "
230 if ( conf.nosound ) {
231 LOG( _(
"Sound is disabled!" ) );
236 WARN( _(
"Problem setting up sound!" ) );
261 nlua_env nenv = nlua_newEnv(
"naevlua" );
272 lua_pushcfunction(
naevL, luaopen_io );
273 nlua_pcall( nenv, 0, 1 );
274 nlua_setenv(
naevL, nenv,
"io" );
276 if ( luaL_loadfile(
naevL, luafile ) != 0 ) {
277 WARN( _(
"Script '%s' Lua error:\n%s" ), luafile,
278 lua_tostring(
naevL, -1 ) );
282 LOG( _(
"Processing '%s'..." ), luafile );
283 nlua_pushenv(
naevL, nenv );
284 lua_setfenv(
naevL, -2 );
286 lua_newtable(
naevL );
288 lua_pushstring(
naevL, luafile );
289 lua_rawseti(
naevL, -2, 0 );
290 while ( opt < argc ) {
291 lua_pushstring(
naevL, argv[opt++] );
292 lua_rawseti(
naevL, -2, ++nargs );
294 nlua_setenv(
naevL, nenv,
"arg" );
296 if ( nlua_pcall( nenv, 0, LUA_MULTRET ) != 0 ) {
297 WARN( _(
"Script '%s' Lua error:\n%s" ), luafile,
298 lua_tostring(
naevL, -1 ) );
int cond_init(void)
Initializes the conditional subsystem.
int cli_init(void)
Initializes the CLI environment.
void debug_sigInit(void)
Sets up the back-tracing signal handler.
void debug_enableFPUExcept(void)
Enables FPU exceptions. Artificially limited to Linux until link issues are figured out.
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
void gettext_setLanguage(const char *lang)
Set the translation language.
void gettext_init(void)
Initialize the translation system. There's no presumption that PhysicsFS is available,...
int gui_init(void)
Initializes the GUI system.
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 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.
int music_choose(const char *situation)
Actually runs the music stuff, based on situation.
Controls the overall game flow: data loading/unloading and game loop.
static void fps_init(void)
Initializes the fps engine.
static void loadscreen_unload(void)
Frees the loading screen.
static void print_SDLversion(void)
Prints the SDL version to console.
static void unload_all(void)
Unloads all data, simplifies main().
void naev_resize(void)
Wrapper for gl_resize that handles non-GL reinitialization.
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
void fps_setPos(double x, double y)
Sets the position to display the FPS.
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)
int nebu_init(void)
Initializes the nebula.
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.
int nlua_loadBackground(nlua_env env)
Loads the graphics library.
int nlua_loadCamera(nlua_env env)
Loads the camera library.
int nlua_loadCLI(nlua_env env)
Loads the CLI Lua library.
int nlua_loadCol(nlua_env env)
Loads the colour library.
int nlua_loadLinOpt(nlua_env env)
Loads the linopt library.
int nlua_loadMusic(nlua_env env)
Music Lua module.
int nlua_loadTex(nlua_env env)
Loads the texture library.
int nlua_loadTk(nlua_env env)
Loads the Toolkit Lua library.
int gl_init(unsigned int extra_flags)
Initializes SDL/OpenGL and the works.
void rng_init(void)
Initializes the random subsystem.
int sound_init(void)
Initializes the sound subsystem.
int start_load(void)
Loads the module start data.
const char * start_name(void)
Gets the module name.