2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023 John Tsiombikas <nuclear@mutantstargoat.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
30 #define DEF_MOUSE_SPEED 50
31 #define DEF_SBALL_SPEED 50
34 struct options opt = {
35 DEF_XRES, DEF_YRES, DEF_BPP,
38 DEF_MOUSE_SPEED, DEF_SBALL_SPEED,
41 int load_options(const char *fname)
45 if(!(cfg = ts_load(fname))) {
48 infomsg("loaded config: %s\n", fname);
50 opt.xres = ts_lookup_int(cfg, "options.video.xres", DEF_XRES);
51 opt.yres = ts_lookup_int(cfg, "options.video.yres", DEF_YRES);
52 opt.bpp = ts_lookup_int(cfg, "options.video.bpp", DEF_BPP);
53 opt.vsync = ts_lookup_int(cfg, "options.video.vsync", DEF_VSYNC);
54 opt.fullscreen = ts_lookup_int(cfg, "options.video.fullscreen", DEF_FULLSCR);
56 opt.mouse_speed = ts_lookup_int(cfg, "options.input.mousespeed", DEF_MOUSE_SPEED);
57 opt.sball_speed = ts_lookup_int(cfg, "options.input.sballspeed", DEF_SBALL_SPEED);
63 #define WROPT(lvl, fmt, val, defval) \
66 for(i=0; i<lvl; i++) fputc('\t', fp); \
67 if((val) == (defval)) fputc('#', fp); \
68 fprintf(fp, fmt "\n", val); \
71 int save_options(const char *fname)
75 printf("writing config: %s\n", fname);
77 if(!(fp = fopen(fname, "wb"))) {
78 fprintf(stderr, "failed to save options (%s): %s\n", fname, strerror(errno));
80 fprintf(fp, "options {\n");
81 fprintf(fp, "\tvideo {\n");
82 WROPT(2, "xres = %d", opt.xres, DEF_XRES);
83 WROPT(2, "yres = %d", opt.yres, DEF_YRES);
84 WROPT(2, "bpp = %d", opt.bpp, DEF_BPP);
85 WROPT(2, "vsync = %d", opt.vsync, DEF_VSYNC);
86 WROPT(2, "fullscreen = %d", opt.fullscreen, DEF_FULLSCR);
89 fprintf(fp, "\tinput {\n");
90 WROPT(2, "mousespeed = %d", opt.mouse_speed, DEF_MOUSE_SPEED);
91 WROPT(2, "sballspeed = %d", opt.sball_speed, DEF_SBALL_SPEED);
95 fprintf(fp, "# v" "i:ts=4 sts=4 sw=4 noexpandtab:\n");