-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
146 lines (117 loc) · 3.32 KB
/
settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "config.h" // for CONFIG_CURRENT_DIR
#include "settings.h"
#include "replay.h"
#include "settings.fdh"
char *setfilename;
const uint16_t SETTINGS_VERSION = 0x1602; // serves as both a version and magic
Settings normal_settings;
Settings replay_settings;
Settings *settings = &normal_settings;
void settings_setfilename()
{
// set the setfilename variable
#ifndef CONFIG_CURRENT_DIR
const char *setfilename_1 = getenv("HOME");
const char *setfilename_2 = "/.joynxengine/settings.dat";
setfilename = (char*) malloc((strlen(setfilename_1) + strlen(setfilename_2) + 1) * sizeof(char));
sprintf(setfilename, "%s%s", setfilename_1, setfilename_2);
#else
const char *setfilename_1 = "settings.dat";
setfilename = (char*) malloc((strlen(setfilename_1) + 1) * sizeof(char));
sprintf(setfilename, "%s", setfilename_1);
#endif
}
bool settings_load(Settings *setfile)
{
if (!setfile) setfile = &normal_settings;
if (tryload(settings))
{
stat("No saved settings; using defaults.");
memset(setfile, 0, sizeof(Settings));
setfile->resolution = 2; // 640x480 Windowed, should be safe value
setfile->last_save_slot = 0;
setfile->multisave = true;
setfile->enable_debug_keys = false;
setfile->sound_enabled = true;
setfile->music_enabled = 1; // both Boss and Regular music
setfile->volume = SDL_MIX_MAXVOLUME;
setfile->instant_quit = false;
setfile->emulate_bugs = false;
setfile->no_quake_in_hell = false;
setfile->inhibit_fullscreen = false;
setfile->files_extracted = false;
// I found that 8bpp->32bpp blits are actually noticably faster
// than 32bpp->32bpp blits on several systems I tested. Not sure why
// but calling SDL_DisplayFormat seems to actually be slowing things
// down. This goes against established wisdom so if you want it back on,
// run "displayformat 1" in the console and restart.
setfile->displayformat = false;
return 1;
}
else
{
#ifdef __SDLSHIM__
stat("settings_load(): Hey FIXME!!!");
settings->show_fps = true;
#else
input_set_mappings(settings->input_mappings);
input_set_button_mappings(settings->input_button_mappings);
#endif
}
return 0;
}
/*
void c------------------------------() {}
*/
static bool tryload(Settings *setfile)
{
FILE *fp;
stat("Loading settings...");
settings_setfilename();
fp = fileopen(setfilename, "rb");
if (!fp)
{
stat("Couldn't open file %s.", setfilename);
free(setfilename);
return 1;
}
free(setfilename);
setfile->version = 0;
fread(setfile, sizeof(Settings), 1, fp);
if (setfile->version != SETTINGS_VERSION)
{
stat("Wrong settings version %04x.", setfile->version);
return 1;
}
fclose(fp);
return 0;
}
bool settings_save(Settings *setfile)
{
FILE *fp;
if (!setfile)
setfile = &normal_settings;
stat("Writing settings...");
settings_setfilename();
fp = fileopen(setfilename, "wb");
if (!fp)
{
stat("Couldn't open file %s.", setfilename);
free(setfilename);
return 1;
}
free(setfilename);
for(int i=0;i<INPUT_COUNT;i++)
setfile->input_mappings[i] = input_get_mapping(i);
for(int i=0;i<BUTTON_COUNT;i++)
setfile->input_button_mappings[i] = input_get_button_mapping(i);
setfile->version = SETTINGS_VERSION;
fwrite(setfile, sizeof(Settings), 1, fp);
fclose(fp);
return 0;
}