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