naev 0.11.5
conf.c
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
5#include <getopt.h> /* getopt_long */
6#include <stdlib.h> /* atoi */
7#include <unistd.h> /* getopt */
8
9#include "naev.h"
12#include "physfs.h"
13
14#include "conf.h"
15
16#include "env.h"
17#include "background.h"
18#include "input.h"
19#include "log.h"
20#include "music.h"
21#include "ndata.h"
22#include "nfile.h"
23#include "nlua.h"
24#include "nstring.h"
25#include "opengl.h"
26#include "player.h"
27#include "utf8.h"
28
29#define conf_loadInt( env, n, i ) \
30 { \
31 nlua_getenv( naevL, env, n ); \
32 if ( lua_isnumber( naevL, -1 ) ) { \
33 i = (int)lua_tonumber( naevL, -1 ); \
34 } \
35 lua_pop( naevL, 1 ); \
36 }
37
38#define conf_loadFloat( env, n, f ) \
39 { \
40 nlua_getenv( naevL, env, n ); \
41 if ( lua_isnumber( naevL, -1 ) ) { \
42 f = (double)lua_tonumber( naevL, -1 ); \
43 } \
44 lua_pop( naevL, 1 ); \
45 }
46
47#define conf_loadTime( env, n, i ) \
48 { \
49 nlua_getenv( naevL, env, n ); \
50 if ( lua_isnumber( naevL, -1 ) ) { \
51 i = (time_t)lua_tonumber( naevL, -1 ); \
52 } \
53 lua_pop( naevL, 1 ); \
54 }
55
56#define conf_loadBool( env, n, b ) \
57 { \
58 nlua_getenv( naevL, env, n ); \
59 if ( lua_isnumber( naevL, -1 ) ) \
60 b = ( lua_tonumber( naevL, -1 ) != 0. ); \
61 else if ( !lua_isnil( naevL, -1 ) ) \
62 b = lua_toboolean( naevL, -1 ); \
63 lua_pop( naevL, 1 ); \
64 }
65
66#define conf_loadString( env, n, s ) \
67 { \
68 nlua_getenv( naevL, env, n ); \
69 if ( lua_isstring( naevL, -1 ) ) { \
70 free( s ); \
71 s = strdup( lua_tostring( naevL, -1 ) ); \
72 } \
73 lua_pop( naevL, 1 ); \
74 }
75
76/* Global configuration. */
77PlayerConf_t conf = {
78 .loaded = 0,
79 .ndata = NULL,
80 .language=NULL,
81 .joystick_nam = NULL
82};
83
84/* from main.c */
85extern int show_fps;
86extern int max_fps;
87extern int indjoystick;
88extern char* namjoystick;
89
90/*
91 * prototypes
92 */
93static void print_usage( void );
94
95/*
96 * prints usage
97 */
98static void print_usage( void )
99{
100 LOG( _( "Usage: %s [OPTIONS] [DATA]" ), env.argv0 );
101 LOG(_("Options are:"));
102 LOG(_(" -f, --fullscreen activate fullscreen"));
103 LOG(_(" -F n, --fps n limit frames per second to n"));
104 LOG(_(" -V, --vsync enable vsync"));
105 LOG(_(" -W n set width to n"));
106 LOG(_(" -H n set height to n"));
107 LOG(_(" -j n, --joystick n use joystick n"));
108 LOG(_(" -J s, --Joystick s use joystick whose name contains s"));
109 LOG(_(" -M, --mute disables sound"));
110 LOG(_(" -S, --sound forces sound"));
111 LOG(_(" -m f, --mvol f sets the music volume to f"));
112 LOG(_(" -s f, --svol f sets the sound volume to f"));
113 LOG(_(" -d, --datapath adds a new datapath to be mounted (i.e., appends it to the search path for game assets)"));
114 LOG(_(" -X, --scale defines the scale factor"));
115 LOG(_(" --devmode enables dev mode perks like the editors"));
116 LOG(_(" -h, --help display this message and exit"));
117 LOG(_(" -v, --version print the version and exit"));
118}
119
123void conf_setDefaults (void)
124{
125 conf_cleanup();
126
127 /* Joystick. */
128 conf.joystick_ind = -1;
129
130 /* GUI. */
131 conf.mesg_visible = 5;
132 conf.map_overlay_opacity = MAP_OVERLAY_OPACITY_DEFAULT;
133 conf.big_icons = BIG_ICONS_DEFAULT;
134 conf.always_radar = 0;
135
136 /* Repeat. */
137 conf.repeat_delay = 500;
138 conf.repeat_freq = 30;
139
140 /* Dynamic zoom. */
141 conf.zoom_manual = MANUAL_ZOOM_DEFAULT;
142 conf.zoom_far = ZOOM_FAR_DEFAULT;
143 conf.zoom_near = ZOOM_NEAR_DEFAULT;
144 conf.zoom_speed = ZOOM_SPEED_DEFAULT;
145
146 /* Font sizes. */
147 conf.font_size_console = FONT_SIZE_CONSOLE_DEFAULT;
148 conf.font_size_intro = FONT_SIZE_INTRO_DEFAULT;
149 conf.font_size_def = FONT_SIZE_DEF_DEFAULT;
150 conf.font_size_small = FONT_SIZE_SMALL_DEFAULT;
151
152 /* Misc. */
153 conf.redirect_file = 1;
154 conf.nosave = 0;
155 conf.devmode = 0;
156 conf.devautosave = 0;
157 conf.lua_enet = 0;
158 conf.lua_repl = 0;
159 conf.lastversion = strdup( "" );
161 memset( &conf.last_played, 0, sizeof(time_t) );
162
163 /* Gameplay. */
164 conf_setGameplayDefaults();
165
166 /* Audio. */
167 conf_setAudioDefaults();
168
169 /* Video. */
170 conf_setVideoDefaults();
171
172 /* Input */
174
175 /* Debugging. */
176 conf.fpu_except = 0; /* Causes many issues. */
177
178 /* Editor. */
179 conf.dev_save_sys = strdup( DEV_SAVE_SYSTEM_DEFAULT );
180 conf.dev_save_map = strdup( DEV_SAVE_MAP_DEFAULT );
181 conf.dev_save_spob = strdup( DEV_SAVE_SPOB_DEFAULT );
182}
183
187void conf_setGameplayDefaults (void)
188{
189 conf.difficulty = DIFFICULTY_DEFAULT;
190 conf.doubletap_sens = DOUBLETAP_SENSITIVITY_DEFAULT;
191 conf.save_compress = SAVE_COMPRESSION_DEFAULT;
192 conf.mouse_hide = MOUSE_HIDE_DEFAULT;
193 conf.mouse_accel = MOUSE_ACCEL_DEFAULT;
194 conf.mouse_doubleclick = MOUSE_DOUBLECLICK_TIME;
195 conf.mouse_fly = MOUSE_FLY_DEFAULT;
196 conf.zoom_manual = MANUAL_ZOOM_DEFAULT;
197}
198
202void conf_setAudioDefaults (void)
203{
204 /* Sound. */
205 conf.al_efx = USE_EFX_DEFAULT;
206 conf.nosound = MUTE_SOUND_DEFAULT;
207 conf.sound = SOUND_VOLUME_DEFAULT;
208 conf.music = MUSIC_VOLUME_DEFAULT;
209 conf.engine_vol = ENGINE_VOLUME_DEFAULT;
210}
211
215void conf_setVideoDefaults (void)
216{
217 int w, h, f;
218 SDL_DisplayMode resolution;
219
220 /* More complex resolution handling. */
221 f = 0;
222 if (SDL_GetCurrentDisplayMode( 0, &resolution ) == 0) {
223 /* Try higher resolution. */
224 w = RESOLUTION_W_DEFAULT;
225 h = RESOLUTION_H_DEFAULT;
226
227 /* Fullscreen and fit everything onscreen. */
228 if ((resolution.w <= w) || (resolution.h <= h)) {
229 w = resolution.w;
230 h = resolution.h;
231 f = FULLSCREEN_DEFAULT;
232 }
233 }
234 else {
235 w = 800;
236 h = 600;
237 }
238
239 /* OpenGL. */
240 conf.fsaa = FSAA_DEFAULT;
241 conf.vsync = VSYNC_DEFAULT;
242
243 /* Window. */
244 conf.fullscreen = f;
245 conf.width = w;
246 conf.height = h;
247 conf.explicit_dim = 0; /* No need for a define, this is only for first-run. */
248 conf.scalefactor = SCALE_FACTOR_DEFAULT;
249 conf.nebu_scale = NEBULA_SCALE_FACTOR_DEFAULT;
250 conf.minimize = MINIMIZE_DEFAULT;
251 conf.colourblind = COLORBLIND_DEFAULT;
252 conf.healthbars = HEALTHBARS_DEFAULT;
253 conf.bg_brightness = BG_BRIGHTNESS_DEFAULT;
254 conf.nebu_nonuniformity = NEBU_NONUNIFORMITY_DEFAULT;
255 conf.jump_brightness = JUMP_BRIGHTNESS_DEFAULT;
256 conf.gamma_correction = GAMMA_CORRECTION_DEFAULT;
257 conf.background_fancy = BACKGROUND_FANCY_DEFAULT;
258
260 if (cur_system)
261 background_load( cur_system->background );
262
263 /* FPS. */
264 conf.fps_show = SHOW_FPS_DEFAULT;
265 conf.fps_max = FPS_MAX_DEFAULT;
266
267 /* Pause. */
268 conf.pause_show = SHOW_PAUSE_DEFAULT;
269}
270
271/*
272 * Frees some memory the conf allocated.
273 */
274void conf_cleanup (void)
275{
276 conf_free( &conf );
277}
278
279/*
280 * @brief Parses the local conf that dictates where user data goes.
281 */
282void conf_loadConfigPath( void )
283{
284 const char *file = "datapath.lua";
285
286 if (!nfile_fileExists(file))
287 return;
288
289 nlua_env lEnv = nlua_newEnv();
290 if ( nlua_dofileenv( lEnv, file ) == 0 )
291 conf_loadString( lEnv, "datapath", conf.datapath );
292
293 nlua_freeEnv( lEnv );
294}
295
296/*
297 * parses the config file
298 */
299int conf_loadConfig ( const char* file )
300{
301 int i, t;
302 const char *str, *mod;
303 SDL_Keycode key;
304 int type;
305 int w,h;
306 SDL_Keymod m;
307
308 /* Check to see if file exists. */
309 if (!nfile_fileExists(file)) {
310 conf.loaded = 1;
311 return nfile_touch(file);
312 }
313
314 /* Load the configuration. */
315 nlua_env lEnv = nlua_newEnv();
316 if (nlua_dofileenv( lEnv, file ) == 0) {
317
318 /* ndata. */
319 conf_loadString( lEnv, "data", conf.ndata );
320
321 /* Language. */
322 conf_loadString( lEnv, "language", conf.language );
323
324 /* OpenGL. */
325 conf_loadInt( lEnv, "fsaa", conf.fsaa );
326 conf_loadBool( lEnv, "vsync", conf.vsync );
327
328 /* Window. */
329 w = h = 0;
330 conf_loadInt( lEnv, "width", w );
331 conf_loadInt( lEnv, "height", h );
332 if (w != 0) {
333 conf.explicit_dim = 1;
334 conf.width = w;
335 }
336 if (h != 0) {
337 conf.explicit_dim = 1;
338 conf.height = h;
339 }
340 conf_loadFloat( lEnv, "scalefactor", conf.scalefactor );
341 conf_loadFloat( lEnv, "nebu_scale", conf.nebu_scale );
342 conf_loadBool( lEnv, "fullscreen", conf.fullscreen );
343 conf_loadBool( lEnv, "modesetting", conf.modesetting );
344 conf_loadBool( lEnv, "notresizable", conf.notresizable );
345 conf_loadBool( lEnv, "borderless", conf.borderless );
346 conf_loadBool( lEnv, "minimize", conf.minimize );
347 conf_loadBool( lEnv, "colourblind", conf.colourblind );
348 conf_loadBool( lEnv, "healthbars", conf.healthbars );
349 conf_loadFloat( lEnv, "bg_brightness", conf.bg_brightness );
350 /* todo leave only nebu_nonuniformity sometime */
351 conf_loadFloat( lEnv, "nebu_brightness", conf.nebu_nonuniformity ); /* Old conf name. */
352 conf_loadFloat( lEnv, "nebu_uniformity", conf.nebu_nonuniformity );
353 conf_loadFloat( lEnv, "nebu_nonuniformity", conf.nebu_nonuniformity );
354 /* end todo */
355 conf_loadFloat( lEnv, "jump_brightness", conf.jump_brightness );
356 conf_loadFloat( lEnv, "gamma_correction", conf.gamma_correction );
357 conf_loadBool( lEnv, "background_fancy", conf.background_fancy );
358
359 /* FPS */
360 conf_loadBool( lEnv, "showfps", conf.fps_show );
361 conf_loadInt( lEnv, "maxfps", conf.fps_max );
362
363 /* Pause */
364 conf_loadBool( lEnv, "showpause", conf.pause_show );
365
366 /* Sound. */
367 conf_loadBool( lEnv, "al_efx", conf.al_efx );
368 conf_loadBool( lEnv, "nosound", conf.nosound );
369 conf_loadFloat( lEnv, "sound", conf.sound );
370 conf_loadFloat( lEnv, "music", conf.music );
371 conf_loadFloat( lEnv, "engine_vol", conf.engine_vol );
372
373 /* Joystick. */
374 nlua_getenv( naevL, lEnv, "joystick" );
375 if (lua_isnumber(naevL, -1))
376 conf.joystick_ind = (int)lua_tonumber(naevL, -1);
377 else if (lua_isstring(naevL, -1))
378 conf.joystick_nam = strdup(lua_tostring(naevL, -1));
379 lua_pop(naevL,1);
380
381 /* GUI. */
382 conf_loadInt( lEnv, "mesg_visible", conf.mesg_visible );
383 if (conf.mesg_visible <= 0)
384 conf.mesg_visible = 5;
385 conf_loadFloat( lEnv, "map_overlay_opacity", conf.map_overlay_opacity );
387 conf_loadBool( lEnv, "big_icons", conf.big_icons );
388 conf_loadBool( lEnv, "always_radar", conf.always_radar );
389
390 /* Key repeat. */
391 conf_loadInt( lEnv, "repeat_delay", conf.repeat_delay );
392 conf_loadInt( lEnv, "repeat_freq", conf.repeat_freq );
393
394 /* Zoom. */
395 conf_loadBool( lEnv, "zoom_manual", conf.zoom_manual );
396 conf_loadFloat( lEnv, "zoom_far", conf.zoom_far );
397 conf_loadFloat( lEnv, "zoom_near", conf.zoom_near );
398 conf_loadFloat( lEnv, "zoom_speed", conf.zoom_speed );
399
400 /* Font size. */
401 conf_loadInt( lEnv, "font_size_console", conf.font_size_console );
402 conf_loadInt( lEnv, "font_size_intro", conf.font_size_intro );
403 conf_loadInt( lEnv, "font_size_def", conf.font_size_def );
404 conf_loadInt( lEnv, "font_size_small", conf.font_size_small );
405
406 /* Misc. */
407 conf_loadString( lEnv, "difficulty", conf.difficulty );
408 conf_loadFloat( lEnv, "compression_velocity", conf.compression_velocity );
409 conf_loadFloat( lEnv, "compression_mult", conf.compression_mult );
410 conf_loadBool( lEnv, "redirect_file", conf.redirect_file );
411 conf_loadBool( lEnv, "save_compress", conf.save_compress );
412 conf_loadInt( lEnv, "doubletap_sensitivity", conf.doubletap_sens );
413 conf_loadFloat( lEnv, "mouse_hide", conf.mouse_hide );
414 conf_loadBool( lEnv, "mouse_fly", conf.mouse_fly );
415 conf_loadInt( lEnv, "mouse_thrust", conf.mouse_accel ); /* Old format, TODO remove around 0.12.0 or so. */
416 conf_loadInt( lEnv, "mouse_accel", conf.mouse_accel );
417 conf_loadFloat( lEnv, "mouse_doubleclick", conf.mouse_doubleclick );
418 conf_loadFloat( lEnv, "autonav_reset_dist", conf.autonav_reset_dist );
419 conf_loadFloat( lEnv, "autonav_reset_shield", conf.autonav_reset_shield );
420 conf_loadBool( lEnv, "devmode", conf.devmode );
421 conf_loadBool( lEnv, "devautosave", conf.devautosave );
422 conf_loadBool( lEnv, "lua_enet", conf.lua_enet );
423 conf_loadBool( lEnv, "lua_repl", conf.lua_repl );
424 conf_loadBool( lEnv, "conf_nosave", conf.nosave );
425 conf_loadString( lEnv, "lastversion", conf.lastversion );
426 conf_loadBool( lEnv, "translation_warning_seen", conf.translation_warning_seen );
427 conf_loadTime( lEnv, "last_played", conf.last_played );
428
429 /* Debugging. */
430 conf_loadBool( lEnv, "fpu_except", conf.fpu_except );
431
432 /* Editor. */
433 conf_loadString( lEnv, "dev_save_sys", conf.dev_save_sys );
434 conf_loadString( lEnv, "dev_save_map", conf.dev_save_map );
435 conf_loadString( lEnv, "dev_save_spob", conf.dev_save_spob );
436
437 /*
438 * Keybindings.
439 */
440 for (i=0; keybind_info[i][0] != NULL; i++) {
441 nlua_getenv( naevL, lEnv, keybind_info[ i ][ 0 ] );
442 /* Handle "none". */
443 if (lua_isstring(naevL,-1)) {
444 str = lua_tostring(naevL,-1);
445 if (strcmp(str,"none")==0) {
447 KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE );
448 }
449 }
450 else if (lua_istable(naevL, -1)) { /* it's a table */
451 /* gets the event type */
452 lua_pushstring(naevL, "type");
453 lua_gettable(naevL, -2);
454 if (lua_isstring(naevL, -1))
455 str = lua_tostring(naevL, -1);
456 else if (lua_isnil(naevL, -1)) {
457 WARN(_("Found keybind with no type field!"));
458 str = "null";
459 }
460 else {
461 WARN(_("Found keybind with invalid type field!"));
462 str = "null";
463 }
464 lua_pop(naevL,1);
465
466 /* gets the key */
467 lua_pushstring(naevL, "key");
468 lua_gettable(naevL, -2);
469 t = lua_type(naevL, -1);
470 if (t == LUA_TNUMBER)
471 key = (int)lua_tonumber(naevL, -1);
472 else if (t == LUA_TSTRING)
473 key = input_keyConv( lua_tostring(naevL, -1));
474 else if (t == LUA_TNIL) {
475 WARN(_("Found keybind with no key field!"));
476 key = SDLK_UNKNOWN;
477 }
478 else {
479 WARN(_("Found keybind with invalid key field!"));
480 key = SDLK_UNKNOWN;
481 }
482 lua_pop(naevL,1);
483
484 /* Get the modifier. */
485 lua_pushstring(naevL, "mod");
486 lua_gettable(naevL, -2);
487 if (lua_isstring(naevL, -1))
488 mod = lua_tostring(naevL, -1);
489 else
490 mod = NULL;
491 lua_pop(naevL,1);
492
493 if (str != NULL) { /* keybind is valid */
494 /* get type */
495 if (strcmp(str,"null")==0) type = KEYBIND_NULL;
496 else if (strcmp(str,"keyboard")==0) type = KEYBIND_KEYBOARD;
497 else if (strcmp(str,"jaxispos")==0) type = KEYBIND_JAXISPOS;
498 else if (strcmp(str,"jaxisneg")==0) type = KEYBIND_JAXISNEG;
499 else if (strcmp(str,"jbutton")==0) type = KEYBIND_JBUTTON;
500 else if (strcmp(str,"jhat_up")==0) type = KEYBIND_JHAT_UP;
501 else if (strcmp(str,"jhat_down")==0) type = KEYBIND_JHAT_DOWN;
502 else if (strcmp(str,"jhat_left")==0) type = KEYBIND_JHAT_LEFT;
503 else if (strcmp(str,"jhat_right")==0) type = KEYBIND_JHAT_RIGHT;
504 else {
505 WARN(_("Unknown keybinding of type %s"), str);
506 continue;
507 }
508
509 /* Check to see if it is valid. */
510 if ((key == SDLK_UNKNOWN) && (type == KEYBIND_KEYBOARD)) {
511 WARN(_("Keybind for '%s' is invalid"), keybind_info[i][0]);
512 continue;
513 }
514
515 /* Set modifier, probably should be able to handle two at a time. */
516 if (mod != NULL) {
517 if (strcmp(mod,"ctrl")==0) m = NMOD_CTRL;
518 else if (strcmp(mod,"shift")==0) m = NMOD_SHIFT;
519 else if (strcmp(mod,"alt")==0) m = NMOD_ALT;
520 else if (strcmp(mod,"meta")==0) m = NMOD_META;
521 else if (strcmp(mod,"any")==0) m = NMOD_ANY;
522 else if (strcmp(mod,"none")==0) m = NMOD_NONE;
523 else {
524 WARN(_("Unknown keybinding mod of type %s"), mod);
525 m = NMOD_NONE;
526 }
527 }
528 else
529 m = NMOD_NONE;
530
531 /* set the keybind */
532 input_setKeybind( keybind_info[i][0], type, key, m );
533 }
534 else
535 WARN(_("Malformed keybind for '%s' in '%s'."), keybind_info[i][0], file);
536 }
537 /* clean up after table stuff */
538 lua_pop(naevL,1);
539 }
540 }
541 else { /* failed to load the config file */
542 WARN(_("Config file '%s' has invalid syntax:"), file );
543 WARN(" %s", lua_tostring(naevL,-1));
544 nlua_freeEnv( lEnv );
545 return 1;
546 }
547
548 conf.loaded = 1;
549 nlua_freeEnv( lEnv );
550 return 0;
551}
552
553/*
554 * parses the CLI options
555 */
556void conf_parseCLI( int argc, char** argv )
557{
558 static struct option long_options[] = {
559 { "datapath", required_argument, 0, 'd' },
560 { "fullscreen", no_argument, 0, 'f' },
561 { "fps", required_argument, 0, 'F' },
562 { "vsync", no_argument, 0, 'V' },
563 { "joystick", required_argument, 0, 'j' },
564 { "Joystick", required_argument, 0, 'J' },
565 { "width", required_argument, 0, 'W' },
566 { "height", required_argument, 0, 'H' },
567 { "mute", no_argument, 0, 'M' },
568 { "sound", no_argument, 0, 'S' },
569 { "mvol", required_argument, 0, 'm' },
570 { "svol", required_argument, 0, 's' },
571 { "scale", required_argument, 0, 'X' },
572 { "devmode", no_argument, 0, 'D' },
573 { "help", no_argument, 0, 'h' },
574 { "version", no_argument, 0, 'v' },
575 { NULL, 0, 0, 0 } };
576 int option_index = 1;
577 int c = 0;
578
579 /* man 3 getopt says optind should be initialized to 1, but that seems to
580 * cause all options to get parsed, i.e. we cannot detect a trailing ndata
581 * option.
582 */
583 optind = 0;
584 while ((c = getopt_long(argc, argv,
585 "fF:Vd:j:J:W:H:MSm:s:X:Nhv",
586 long_options, &option_index)) != -1) {
587 switch (c) {
588 case 'd':
589 PHYSFS_mount( optarg, NULL, 1 );
590 break;
591 case 'f':
592 conf.fullscreen = 1;
593 break;
594 case 'F':
595 conf.fps_max = atoi(optarg);
596 break;
597 case 'V':
598 conf.vsync = 1;
599 break;
600 case 'j':
601 conf.joystick_ind = atoi(optarg);
602 break;
603 case 'J':
604 conf.joystick_nam = strdup(optarg);
605 break;
606 case 'W':
607 conf.width = atoi(optarg);
608 conf.explicit_dim = 1;
609 break;
610 case 'H':
611 conf.height = atoi(optarg);
612 conf.explicit_dim = 1;
613 break;
614 case 'M':
615 conf.nosound = 1;
616 break;
617 case 'S':
618 conf.nosound = 0;
619 break;
620 case 'm':
621 conf.music = atof(optarg);
622 break;
623 case 's':
624 conf.sound = atof(optarg);
625 break;
626 case 'N':
627 free(conf.ndata);
628 conf.ndata = NULL;
629 break;
630 case 'X':
631 conf.scalefactor = atof(optarg);
632 break;
633 case 'D':
634 conf.devmode = 1;
635 LOG(_("Enabling developer mode."));
636 break;
637
638 case 'v':
639 /* by now it has already displayed the version */
640 exit(EXIT_SUCCESS);
641 case 'h':
642 print_usage();
643 exit(EXIT_SUCCESS);
644 }
645 }
646
648 if (optind < argc) {
649 free(conf.ndata);
650 conf.ndata = strdup( argv[ optind ] );
651 }
652}
653
662static size_t quoteLuaString(char *str, size_t size, const char *text)
663{
664 char slashescape;
665 size_t count, i;
666 uint32_t ch;
667
668 if (size == 0)
669 return 0;
670
671 /* Write a Lua nil if we are given a NULL pointer */
672 if (text == NULL)
673 return scnprintf(str, size, "nil");
674
675 count = 0;
676
677 /* Quote start */
678 str[count++] = '\"';
679 if (count == size)
680 return count;
681
682 /* Iterate over the characters in text */
683 i = 0;
684 while ((ch = u8_nextchar( text, &i ))) {
685 /* Check if we can print this as a friendly backslash-escape */
686 switch (ch) {
687 case '#': slashescape = 'a'; break;
688 case '\b': slashescape = 'b'; break;
689 case '\f': slashescape = 'f'; break;
690 case '\n': slashescape = 'n'; break;
691 case '\r': slashescape = 'r'; break;
692 case '\t': slashescape = 't'; break;
693 case '\v': slashescape = 'v'; break;
694 case '\\': slashescape = '\\'; break;
695 case '\"': slashescape = '\"'; break;
696 case '\'': slashescape = '\''; break;
697 /* Technically, Lua can also represent \0, but we can't in our input */
698 default: slashescape = 0; break;
699 }
700 if (slashescape != 0) {
701 /* Yes, we can use a backslash-escape! */
702 str[count++] = '\\';
703 if (count == size)
704 return count;
705
706 str[count++] = slashescape;
707 if (count == size)
708 return count;
709
710 continue;
711 }
712
713 /* Render UTF8. */
714 count += u8_toutf8( &str[count], size-count, &ch, 1 );
715 if (count >= size)
716 return count;
717 }
718
719 /* Quote end */
720 str[count++] = '\"';
721 if (count == size)
722 return count;
723
724 /* zero-terminate, if possible */
725 if (count != size)
726 str[count] = '\0'; /* don't increase count, like snprintf */
727
728 /* return the amount of characters written */
729 return count;
730}
731
732#define conf_saveComment(t) \
733pos += scnprintf(&buf[pos], sizeof(buf)-pos, "-- %s\n", t);
734
735#define conf_saveEmptyLine() \
736if (sizeof(buf) != pos) \
737 buf[pos++] = '\n';
738
739#define conf_saveInt(n,i) \
740pos += scnprintf(&buf[pos], sizeof(buf)-pos, "%s = %d\n", n, i);
741
742#define conf_saveULong(n,i) \
743pos += scnprintf(&buf[pos], sizeof(buf)-pos, "%s = %lu\n", n, i);
744
745#define conf_saveTime(n,i) \
746pos += scnprintf(&buf[pos], sizeof(buf)-pos, "%s = %llu\n", n, (unsigned long long) i);
747
748#define conf_saveFloat(n,f) \
749pos += scnprintf(&buf[pos], sizeof(buf)-pos, "%s = %f\n", n, f);
750
751#define conf_saveBool(n,b) \
752if (b) \
753 pos += scnprintf(&buf[pos], sizeof(buf)-pos, "%s = true\n", n); \
754else \
755 pos += scnprintf(&buf[pos], sizeof(buf)-pos, "%s = false\n", n);
756
757#define conf_saveString(n,s) \
758pos += scnprintf(&buf[pos], sizeof(buf)-pos, "%s = ", n); \
759pos += quoteLuaString(&buf[pos], sizeof(buf)-pos, s); \
760if (sizeof(buf) != pos) \
761 buf[pos++] = '\n';
762
763#define GENERATED_START_COMMENT "START GENERATED SECTION"
764#define GENERATED_END_COMMENT "END GENERATED SECTION"
765
766/*
767 * saves the current configuration
768 */
769int conf_saveConfig ( const char* file )
770{
771 char *old;
772 const char *oldfooter;
773 size_t oldsize;
774 char buf[32*1024];
775 size_t pos;
776
777 pos = 0;
778 oldfooter = NULL;
779
780 /* User doesn't want to save the config. */
781 if (conf.nosave)
782 return 0;
783
784 /* Read the old configuration, if possible */
785 if (nfile_fileExists(file) && (old = nfile_readFile(&oldsize, file)) != NULL) {
786 /* See if we can find the generated section and preserve
787 * whatever the user wrote before it */
788 const char *tmp = strnstr(old, "-- "GENERATED_START_COMMENT"\n", oldsize);
789 if (tmp != NULL) {
790 /* Copy over the user content */
791 pos = MIN(sizeof(buf), (size_t)(tmp - old));
792 memcpy(buf, old, pos);
793
794 /* See if we can find the end of the section */
795 tmp = strnstr(tmp, "-- "GENERATED_END_COMMENT"\n", oldsize-pos);
796 if (tmp != NULL) {
797 /* Everything after this should also be preserved */
798 oldfooter = tmp + strlen("-- "GENERATED_END_COMMENT"\n");
799 oldsize -= (oldfooter - old);
800 }
801 }
802 else {
803 /* Treat the contents of the old file as a footer. */
804 oldfooter = old;
805 }
806 }
807 else {
808 old = NULL;
809
810 /* Write a nice header for new configuration files */
811 conf_saveComment(_("Naev configuration file"));
812 conf_saveEmptyLine();
813 }
814
815 /* Back up old configuration. */
816 if (nfile_backupIfExists(file) < 0) {
817 WARN(_("Not saving configuration."));
818 return -1;
819 }
820
821 /* Header. */
822 conf_saveComment(GENERATED_START_COMMENT);
823 conf_saveComment(_("The contents of this section will be rewritten by Naev!"));
824 conf_saveEmptyLine();
825
826 /* ndata. */
827 conf_saveComment(_("The location of Naev's data pack, usually called 'ndata'"));
828 conf_saveString("data",conf.ndata);
829 conf_saveEmptyLine();
830
831 /* Language. */
832 conf_saveComment(_("Language to use. Set to the two character identifier to the language (e.g., \"en\" for English), and nil for autodetect."));
833 conf_saveString("language",conf.language);
834 conf_saveEmptyLine();
835
836 /* Difficulty. */
837 conf_saveComment(_("Global difficulty to set the game to. Can be overwritten by saved game settings. Has to match one of the difficulties defined in \"difficulty.xml\" in the data files."));
838 if (conf.difficulty==NULL) {
839 conf_saveComment("difficulty = nil");
840 }
841 else {
842 conf_saveString("difficulty",conf.difficulty);
843 }
844 conf_saveEmptyLine();
845
846 /* OpenGL. */
847 conf_saveComment(_("The factor to use in Full-Scene Anti-Aliasing"));
848 conf_saveComment(_("Anything lower than 2 will simply disable FSAA"));
849 conf_saveInt("fsaa",conf.fsaa);
850 conf_saveEmptyLine();
851
852 conf_saveComment(_("Synchronize framebuffer updates with the vertical blanking interval"));
853 conf_saveBool("vsync",conf.vsync);
854 conf_saveEmptyLine();
855
856 /* Window. */
857 conf_saveComment(_("The window size or screen resolution"));
858 conf_saveComment(_("Set both of these to 0 to make Naev try the desktop resolution"));
859 if (conf.explicit_dim) {
860 conf_saveInt("width",conf.width);
861 conf_saveInt("height",conf.height);
862 } else {
863 conf_saveInt("width",0);
864 conf_saveInt("height",0);
865 }
866 conf_saveEmptyLine();
867
868 conf_saveComment(_("Factor used to divide the above resolution with"));
869 conf_saveComment(_("This is used to lower the rendering resolution, and scale to the above"));
870 conf_saveFloat("scalefactor",conf.scalefactor);
871 conf_saveEmptyLine();
872
873 conf_saveComment(_("Scale factor for rendered nebula backgrounds."));
874 conf_saveComment(_("Larger values can save time but lead to a blurrier appearance."));
875 conf_saveFloat("nebu_scale",conf.nebu_scale);
876 conf_saveEmptyLine();
877
878 conf_saveComment(_("Run Naev in full-screen mode"));
879 conf_saveBool("fullscreen",conf.fullscreen);
880 conf_saveEmptyLine();
881
882 conf_saveComment(_("Use video modesetting when fullscreen is enabled"));
883 conf_saveBool("modesetting",conf.modesetting);
884 conf_saveEmptyLine();
885
886 conf_saveComment(_("Disable allowing resizing the window."));
887 conf_saveBool("notresizable",conf.notresizable);
888 conf_saveEmptyLine();
889
890 conf_saveComment(_("Disable window decorations. Use with care and know the keyboard controls to quit and toggle fullscreen."));
891 conf_saveBool("borderless",conf.borderless);
892 conf_saveEmptyLine();
893
894 conf_saveComment(_("Minimize the game on focus loss."));
895 conf_saveBool("minimize",conf.minimize);
896 conf_saveEmptyLine();
897
898 conf_saveComment(_("Enables colourblind mode. Good for simulating colourblindness."));
899 conf_saveBool("colourblind",conf.colourblind);
900 conf_saveEmptyLine();
901
902 conf_saveComment(_("Enable health bars. These show hostility/friendliness and health of pilots on screen."));
903 conf_saveBool("healthbars",conf.healthbars);
904 conf_saveEmptyLine();
905
906 conf_saveComment(_("Background brightness. 1 is normal brightness while setting it to 0 would make the backgrounds pitch black."));
907 conf_saveFloat("bg_brightness",conf.bg_brightness);
908 conf_saveEmptyLine();
909
910 conf_saveComment(_("Nebula non-uniformity. 1 is normal nebula while setting it to 0 would make the nebula a solid colour."));
911 conf_saveFloat("nebu_nonuniformity",conf.nebu_nonuniformity);
912 conf_saveEmptyLine();
913
914 conf_saveComment(_("Controls the intensity to which the screen fades when jumping. 1.0 would be pure white, while 0.0 would be pure black."));
915 conf_saveFloat("jump_brightness",conf.jump_brightness);
916 conf_saveEmptyLine();
917
918 conf_saveComment(_("Gamma correction parameter. A value of 1 disables it (no curve)."))
919 conf_saveFloat("gamma_correction",conf.gamma_correction);
920 conf_saveEmptyLine();
921
922 conf_saveComment(_("Expensive high quality shaders for the background. Defaults to false."))
923 conf_saveBool("background_fancy",conf.background_fancy);
924 conf_saveEmptyLine();
925
926 /* FPS */
927 conf_saveComment(_("Display a frame rate counter"));
928 conf_saveBool("showfps",conf.fps_show);
929 conf_saveEmptyLine();
930
931 conf_saveComment(_("Limit the rendering frame rate"));
932 conf_saveInt("maxfps",conf.fps_max);
933 conf_saveEmptyLine();
934
935 /* Pause */
936 conf_saveComment(_("Show 'PAUSED' on screen while paused"));
937 conf_saveBool("showpause",conf.pause_show);
938 conf_saveEmptyLine();
939
940 /* Sound. */
941 conf_saveComment(_("Enables EFX extension for OpenAL backend."));
942 conf_saveBool("al_efx",conf.al_efx);
943 conf_saveEmptyLine();
944
945 conf_saveComment(_("Disable all sound"));
946 conf_saveBool("nosound",conf.nosound);
947 conf_saveEmptyLine();
948
949 conf_saveComment(_("Volume of sound effects and music, between 0.0 and 1.0"));
950 conf_saveFloat("sound",(sound_disabled) ? conf.sound : sound_getVolume());
951 conf_saveFloat("music",(music_disabled) ? conf.music : music_getVolume());
952 conf_saveComment(_("Relative engine sound volume. Should be between 0.0 and 1.0"));
953 conf_saveFloat("engine_vol", conf.engine_vol);
954 conf_saveEmptyLine();
955
956 /* Joystick. */
957 conf_saveComment(_("The name or numeric index of the joystick to use"));
958 conf_saveComment(_("Setting this to nil disables the joystick support"));
959 if (conf.joystick_nam != NULL) {
960 conf_saveString("joystick",conf.joystick_nam);
961 }
962 else if (conf.joystick_ind >= 0) {
963 conf_saveInt("joystick",conf.joystick_ind);
964 }
965 else {
966 conf_saveString("joystick",NULL);
967 }
968 conf_saveEmptyLine();
969
970 /* GUI. */
971 conf_saveComment(_("Number of lines visible in the comm window."));
972 conf_saveInt("mesg_visible",conf.mesg_visible);
973 conf_saveComment(_("Opacity fraction (0-1) for the overlay map."));
974 conf_saveFloat("map_overlay_opacity", conf.map_overlay_opacity);
975 conf_saveComment(_("Use bigger icons in the outfit, shipyard, and other lists."));
976 conf_saveBool("big_icons", conf.big_icons);
977 conf_saveComment(_("Always show the radar and don't hide it when the overlay is active."));
978 conf_saveBool("always_radar", conf.always_radar);
979 conf_saveEmptyLine();
980
981 /* Key repeat. */
982 conf_saveComment(_("Delay in ms before starting to repeat (0 disables)"));
983 conf_saveInt("repeat_delay",conf.repeat_delay);
984 conf_saveComment(_("Delay in ms between repeats once it starts to repeat"));
985 conf_saveInt("repeat_freq",conf.repeat_freq);
986 conf_saveEmptyLine();
987
988 /* Zoom. */
989 conf_saveComment(_("Minimum and maximum zoom factor to use in-game"));
990 conf_saveComment(_("At 1.0, no sprites are scaled"));
991 conf_saveComment(_("zoom_far should be less then zoom_near"));
992 conf_saveBool("zoom_manual",conf.zoom_manual);
993 conf_saveFloat("zoom_far",conf.zoom_far);
994 conf_saveFloat("zoom_near",conf.zoom_near);
995 conf_saveEmptyLine();
996
997 conf_saveComment(_("Zooming speed in factor increments per second"));
998 conf_saveFloat("zoom_speed",conf.zoom_speed);
999 conf_saveEmptyLine();
1000
1001 /* Fonts. */
1002 conf_saveComment(_("Font sizes (in pixels) for Naev"));
1003 conf_saveComment(_("Warning, setting to other than the default can cause visual glitches!"));
1004 pos += scnprintf(&buf[pos], sizeof(buf)-pos, _("-- Console default: %d\n"), FONT_SIZE_CONSOLE_DEFAULT);
1005 conf_saveInt("font_size_console",conf.font_size_console);
1006 pos += scnprintf(&buf[pos], sizeof(buf)-pos, _("-- Intro default: %d\n"), FONT_SIZE_INTRO_DEFAULT);
1007 conf_saveInt("font_size_intro",conf.font_size_intro);
1008 pos += scnprintf(&buf[pos], sizeof(buf)-pos, _("-- Default size: %d\n"), FONT_SIZE_DEF_DEFAULT);
1009 conf_saveInt("font_size_def",conf.font_size_def);
1010 pos += scnprintf(&buf[pos], sizeof(buf)-pos, _("-- Small size: %d\n"), FONT_SIZE_SMALL_DEFAULT);
1011 conf_saveInt("font_size_small",conf.font_size_small);
1012
1013 /* Misc. */
1014 conf_saveComment(_("Redirects log and error output to files"));
1015 conf_saveBool("redirect_file",conf.redirect_file);
1016 conf_saveEmptyLine();
1017
1018 conf_saveComment(_("Enables compression on saved games"));
1019 conf_saveBool("save_compress",conf.save_compress);
1020 conf_saveEmptyLine();
1021
1022 conf_saveComment(_("Doubletap sensitivity (used for double tap accel for afterburner or double tap reverse for cooldown)"));
1023 conf_saveInt("doubletap_sensitivity",conf.doubletap_sens);
1024 conf_saveEmptyLine();
1025
1026 conf_saveComment(_("Time (in seconds) to wait until hiding mouse when not used."));
1027 conf_saveBool("mouse_hide",conf.mouse_hide);
1028 conf_saveEmptyLine();
1029
1030 conf_saveComment(_("Whether or not clicking the middle mouse button toggles mouse flying mode."));
1031 conf_saveBool("mouse_fly",conf.mouse_fly);
1032 conf_saveEmptyLine();
1033
1034 conf_saveComment(_("Mouse-flying accel control"));
1035 conf_saveInt("mouse_accel",conf.mouse_accel);
1036 conf_saveEmptyLine();
1037
1038 conf_saveComment(_("Maximum interval to count as a double-click (0 disables)."));
1039 conf_saveFloat("mouse_doubleclick",conf.mouse_doubleclick);
1040 conf_saveEmptyLine();
1041
1042 conf_saveComment(_("Enables developer mode (universe editor and the likes)"));
1043 conf_saveBool("devmode",conf.devmode);
1044 conf_saveEmptyLine();
1045
1046 conf_saveComment(_("Automatic saving for when using the universe editor whenever an edit is done"));
1047 conf_saveBool("devautosave",conf.devautosave);
1048 conf_saveEmptyLine();
1049
1050 conf_saveComment(_("Enable the lua-enet library, for use by online/multiplayer mods (CAUTION: online Lua scripts may have security vulnerabilities!)"));
1051 conf_saveBool("lua_enet",conf.lua_enet);
1052 conf_saveComment(_("Enable the experimental CLI based on lua-repl."));
1053 conf_saveBool("lua_repl",conf.lua_repl);
1054 conf_saveEmptyLine();
1055
1056 conf_saveComment(_("Save the config every time game exits (rewriting this bit)"));
1057 conf_saveInt("conf_nosave",conf.nosave);
1058 conf_saveEmptyLine();
1059
1060 conf_saveComment(_("Indicates the last version the game has run in before"));
1061 conf_saveString("lastversion", conf.lastversion);
1062 conf_saveEmptyLine();
1063
1064 conf_saveComment(_("Indicates whether we've already warned about incomplete game translations."));
1065 conf_saveBool("translation_warning_seen",conf.translation_warning_seen);
1066 conf_saveEmptyLine();
1067
1068 conf_saveComment(_("Time Naev was last played. This gets refreshed each time you exit Naev."));
1069 conf_saveTime("last_played",time(NULL));
1070 conf_saveEmptyLine();
1071
1072 /* Debugging. */
1073 conf_saveComment(_("Enables FPU exceptions - only works on DEBUG builds"));
1074 conf_saveBool("fpu_except",conf.fpu_except);
1075 conf_saveEmptyLine();
1076
1077 /* Editor. */
1078 conf_saveComment(_("Paths for saving different files from the editor"));
1079 conf_saveString("dev_save_sys",conf.dev_save_sys);
1080 conf_saveString("dev_save_map",conf.dev_save_map);
1081 conf_saveString("dev_save_spob",conf.dev_save_spob);
1082 conf_saveEmptyLine();
1083
1084 /* TODO remove the following in 0.12.0 */
1085 conf_saveComment(_("The following are for legacy purposes and will be removed in 0.12.0."))
1086 conf_saveFloat("compression_velocity",conf.compression_velocity);
1087 conf_saveFloat("compression_mult",conf.compression_mult);
1088 conf_saveFloat("autonav_reset_dist",conf.autonav_reset_dist);
1089 conf_saveFloat("autonav_reset_shield",conf.autonav_reset_shield);
1090
1091 /*
1092 * Keybindings.
1093 */
1094 conf_saveEmptyLine();
1095 conf_saveComment(_("Keybindings"));
1096 conf_saveEmptyLine();
1097
1098 /* Iterate over the keybinding names */
1099 for (int i=0; keybind_info[i][0] != NULL; i++) {
1100 SDL_Keycode key;
1101 KeybindType type;
1102 const char *typename;
1103 SDL_Keymod mod;
1104 const char *modname;
1105 char keyname[17];
1106
1107 /* Use an extra character in keyname to make sure it's always zero-terminated */
1108 keyname[sizeof(keyname)-1] = '\0';
1109
1110 /* Save a comment line containing the description */
1111 conf_saveComment(input_getKeybindDescription( keybind_info[i][0] ));
1112
1113 /* Get the keybind */
1114 key = input_getKeybind( keybind_info[i][0], &type, &mod );
1115
1116 /* Determine the textual name for the keybind type */
1117 switch (type) {
1118 case KEYBIND_KEYBOARD: typename = "keyboard"; break;
1119 case KEYBIND_JAXISPOS: typename = "jaxispos"; break;
1120 case KEYBIND_JAXISNEG: typename = "jaxisneg"; break;
1121 case KEYBIND_JBUTTON: typename = "jbutton"; break;
1122 case KEYBIND_JHAT_UP: typename = "jhat_up"; break;
1123 case KEYBIND_JHAT_DOWN: typename = "jhat_down"; break;
1124 case KEYBIND_JHAT_LEFT: typename = "jhat_left"; break;
1125 case KEYBIND_JHAT_RIGHT:typename = "jhat_right";break;
1126 default: typename = NULL; break;
1127 }
1128 /* Write a nil if an unknown type */
1129 if ((typename == NULL) || (key == SDLK_UNKNOWN && type == KEYBIND_KEYBOARD)) {
1130 conf_saveString( keybind_info[i][0],"none");
1131 continue;
1132 }
1133
1134 /* Determine the textual name for the modifier */
1135 switch ((int)mod) {
1136 case NMOD_CTRL: modname = "ctrl"; break;
1137 case NMOD_SHIFT: modname = "shift"; break;
1138 case NMOD_ALT: modname = "alt"; break;
1139 case NMOD_META: modname = "meta"; break;
1140 case NMOD_ANY: modname = "any"; break;
1141 default: modname = "none"; break;
1142 }
1143
1144 /* Determine the textual name for the key, if a keyboard keybind */
1145 if (type == KEYBIND_KEYBOARD)
1146 quoteLuaString(keyname, sizeof(keyname)-1, SDL_GetKeyName(key));
1147 /* If SDL can't describe the key, store it as an integer */
1148 if (type != KEYBIND_KEYBOARD || strcmp(keyname, "\"unknown key\"") == 0)
1149 scnprintf(keyname, sizeof(keyname)-1, "%d", key);
1150
1151 /* Write out a simple Lua table containing the keybind info */
1152 pos += scnprintf(&buf[pos], sizeof(buf)-pos, "%s = { type = \"%s\", mod = \"%s\", key = %s }\n",
1153 keybind_info[i][0], typename, modname, keyname);
1154 }
1155 conf_saveEmptyLine();
1156
1157 /* Footer. */
1158 conf_saveComment(GENERATED_END_COMMENT);
1159
1160 if (old != NULL) {
1161 if (oldfooter != NULL) {
1162 /* oldfooter and oldsize now reference the old content past the footer */
1163 oldsize = MIN((size_t)oldsize, sizeof(buf)-pos);
1164 memcpy(&buf[pos], oldfooter, oldsize);
1165 pos += oldsize;
1166 }
1167 free(old);
1168 }
1169
1170 if (nfile_writeFile(buf, pos, file) < 0) {
1171 WARN(_("Failed to write configuration! You'll most likely have to restore it by copying your backup configuration over your current configuration."));
1172 return -1;
1173 }
1174
1175 return 0;
1176}
1177
1181void conf_copy( PlayerConf_t *dest, const PlayerConf_t *src )
1182{
1183 conf_free( dest );
1184 memcpy( dest, src, sizeof(PlayerConf_t) );
1185#define STRDUP(s) dest->s = ((src->s==NULL)?NULL:strdup(src->s))
1186 STRDUP(ndata);
1187 STRDUP(datapath);
1188 STRDUP(language);
1189 STRDUP(joystick_nam);
1190 STRDUP(lastversion);
1191 STRDUP(dev_save_sys);
1192 STRDUP(dev_save_map);
1193 STRDUP(dev_save_spob);
1194 if (src->difficulty != NULL)
1195 STRDUP(difficulty);
1196#undef STRDUP
1197}
1198
1202void conf_free( PlayerConf_t *config )
1203{
1204 free(config->ndata);
1205 free(config->datapath);
1206 free(config->language);
1207 free(config->joystick_nam);
1208 free(config->lastversion);
1209 free(config->dev_save_sys);
1210 free(config->dev_save_map);
1211 free(config->dev_save_spob);
1212 free(config->difficulty);
1213
1214 /* Clear memory. */
1215 memset( config, 0, sizeof(PlayerConf_t) );
1216}
int background_load(const char *name)
Loads a background script by name.
Definition background.c:427
SDL_Keycode input_getKeybind(const char *keybind, KeybindType *type, SDL_Keymod *mod)
Gets the value of a keybind.
Definition input.c:431
const char * keybind_info[][3]
Definition input.c:50
SDL_Keycode input_keyConv(const char *name)
Gets the key id from its name.
Definition input.c:392
void input_setDefault(int wasd)
Sets the default input keys.
Definition input.c:172
void input_setKeybind(const char *keybind, KeybindType type, SDL_Keycode key, SDL_Keymod mod)
Binds key of type type to action keybind.
Definition input.c:409
const char * input_getKeybindDescription(const char *keybind)
Gets the description of the keybinding.
Definition input.c:582
static SDL_Joystick * joystick
Definition joystick.c:22
int music_disabled
Definition music.c:32
double music_getVolume(void)
Gets the current music volume (linear).
Definition music.c:218
Header file with generic functions and naev-specifics.
#define MIN(x, y)
Definition naev.h:40
#define CLAMP(a, b, x)
Definition naev.h:41
int nfile_writeFile(const char *data, size_t len, const char *path)
Tries to write a file.
Definition nfile.c:538
char * nfile_readFile(size_t *filesize, const char *path)
Tries to read a file.
Definition nfile.c:427
int nfile_backupIfExists(const char *path)
Backup a file, if it exists.
Definition nfile.c:343
int nfile_fileExists(const char *path)
Checks to see if a file exists.
Definition nfile.c:316
int nfile_touch(const char *path)
Tries to create the file if it doesn't exist.
Definition nfile.c:512
char * strnstr(const char *haystack, const char *needle, size_t size)
A bounded version of strstr. Conforms to BSD semantics.
Definition nstring.c:26
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
Definition nstring.c:99
void gl_colourblind(int enable)
Enables or disables the colourblind shader.
Definition opengl.c:674
int paused
Definition pause.c:21
static const double c[]
Definition rng.c:264
double sound_getVolume(void)
Gets the current sound volume (linear).
Definition sound.c:1282
int sound_disabled
Definition sound.c:133
StarSystem * cur_system
Definition space.c:106
Struct containing player options.
Definition conf.h:71
double jump_brightness
Definition conf.h:100
int lua_repl
Definition conf.h:160
int always_radar
Definition conf.h:126
int nosound
Definition conf.h:106
double engine_vol
Definition conf.h:109
double scalefactor
Definition conf.h:89
int healthbars
Definition conf.h:97
char * dev_save_map
Definition conf.h:171
int font_size_def
Definition conf.h:141
double autonav_reset_shield
Definition conf.h:156
char * datapath
Definition conf.h:76
int colourblind
Definition conf.h:96
int fullscreen
Definition conf.h:91
int vsync
Definition conf.h:83
double compression_velocity
Definition conf.h:146
int modesetting
Definition conf.h:92
int fps_max
Definition conf.h:113
int width
Definition conf.h:86
time_t last_played
Definition conf.h:164
double zoom_speed
Definition conf.h:136
int minimize
Definition conf.h:95
int font_size_small
Definition conf.h:142
char * language
Definition conf.h:79
int devmode
Definition conf.h:157
int pause_show
Definition conf.h:116
int mouse_accel
Definition conf.h:153
int height
Definition conf.h:87
int loaded
Definition conf.h:72
double mouse_hide
Definition conf.h:151
int notresizable
Definition conf.h:93
int big_icons
Definition conf.h:125
unsigned int repeat_freq
Definition conf.h:130
double music
Definition conf.h:108
double mouse_doubleclick
Definition conf.h:154
char * ndata
Definition conf.h:75
double autonav_reset_dist
Definition conf.h:155
int devautosave
Definition conf.h:158
int al_efx
Definition conf.h:105
unsigned int repeat_delay
Definition conf.h:129
char * difficulty
Definition conf.h:145
double compression_mult
Definition conf.h:147
int background_fancy
Definition conf.h:102
int fps_show
Definition conf.h:112
int mesg_visible
Definition conf.h:123
double sound
Definition conf.h:107
double zoom_far
Definition conf.h:134
double gamma_correction
Definition conf.h:101
int explicit_dim
Definition conf.h:88
int nosave
Definition conf.h:161
unsigned int doubletap_sens
Definition conf.h:150
int lua_enet
Definition conf.h:159
double bg_brightness
Definition conf.h:98
int font_size_console
Definition conf.h:139
int zoom_manual
Definition conf.h:133
int save_compress
Definition conf.h:149
int redirect_file
Definition conf.h:148
double map_overlay_opacity
Definition conf.h:124
double nebu_scale
Definition conf.h:90
char * dev_save_spob
Definition conf.h:172
int mouse_fly
Definition conf.h:152
double nebu_nonuniformity
Definition conf.h:99
double zoom_near
Definition conf.h:135
char * lastversion
Definition conf.h:162
int translation_warning_seen
Definition conf.h:163
int fsaa
Definition conf.h:82
int fpu_except
Definition conf.h:167
int borderless
Definition conf.h:94
int font_size_intro
Definition conf.h:140
int joystick_ind
Definition conf.h:119
char * dev_save_sys
Definition conf.h:170
char * joystick_nam
Definition conf.h:120