-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.c
108 lines (92 loc) · 2 KB
/
settings.c
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
#include <settings.h>
static int resolution_x;
static int resolution_y;
static Uint8 fullscreen_toggle;
static int music_volume;
static int sfx_volume;
void load_settings()
{
int file;
if((file = open("setting.conf", O_RDONLY)) != -1)
{
read(file, &resolution_x, sizeof(resolution_x));
read(file, &resolution_y, sizeof(resolution_y));
read(file, &fullscreen_toggle, sizeof(fullscreen_toggle));
read(file, &music_volume, sizeof(music_volume));
read(file, &sfx_volume, sizeof(sfx_volume));
close(file);
}
else
{
/* create and safe new settings */
resolution_x = 800;
resolution_y = 600;
fullscreen_toggle = 0;
music_volume = (int)(MIX_MAX_VOLUME/2);
sfx_volume = (int)(MIX_MAX_VOLUME/2);
save_settings();
}
}
void save_settings()
{
int file;
if((file = open("setting.conf", O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE)) != -1)
{
write(file, &resolution_x, sizeof(resolution_x));
write(file, &resolution_y, sizeof(resolution_y));
write(file, &fullscreen_toggle, sizeof(fullscreen_toggle));
write(file, &music_volume, sizeof(music_volume));
write(file, &sfx_volume, sizeof(sfx_volume));
close(file);
}
}
int get_resolution_x()
{
return resolution_x;
}
void set_resolution_x(const int num)
{
resolution_x = num;
}
int get_resolution_y()
{
return resolution_y;
}
void set_resolution_y(const int num)
{
resolution_y = num;
}
int get_fullscreen_toggle()
{
return fullscreen_toggle;
}
void set_fullscreen_toggle(const int num)
{
fullscreen_toggle = num;
}
int get_music_volume()
{
return music_volume;
}
void set_music_volume(const int num)
{
if(num < 0)
music_volume = 0;
else if(num > MIX_MAX_VOLUME)
music_volume = MIX_MAX_VOLUME;
else
music_volume = num;
}
int get_sfx_volume()
{
return sfx_volume;
}
void set_sfx_volume(const int num)
{
if(num < 0)
sfx_volume = 0;
else if(num > MIX_MAX_VOLUME)
sfx_volume = MIX_MAX_VOLUME;
else
sfx_volume = num;
}