Debian Codegraph @

prboom2/src/dsda/settings.c

raw
1 //
2 // Copyright(C) 2020 by Ryan Krafnick
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 // DSDA Settings
16 //
17
18 #include "doomstat.h"
19 #include "m_menu.h"
20 #include "e6y.h"
21 #include "r_things.h"
22 #include "w_wad.h"
23 #include "g_game.h"
24 #include "gl_struct.h"
25 #include "lprintf.h"
26 #include "i_main.h"
27 #include "i_video.h"
28
29 #include "dsda/args.h"
30 #include "dsda/build.h"
31 #include "dsda/configuration.h"
32 #include "dsda/exhud.h"
33 #include "dsda/features.h"
34 #include "dsda/key_frame.h"
35 #include "dsda/map_format.h"
36 #include "dsda/skip.h"
37
38 #include "settings.h"
39
40 int dsda_skip_next_wipe;
41
42 void dsda_InitSettings(void) {
43 void G_UpdateMouseSensitivity(void);
44 void dsda_InitQuickstartCache(void);
45 void dsda_InitParallelSFXFilter(void);
46 void gld_ResetAutomapTransparency(void);
47
48 dsda_UpdateStrictMode();
49 G_UpdateMouseSensitivity();
50 dsda_InitQuickstartCache();
51 dsda_InitParallelSFXFilter();
52 gld_ResetAutomapTransparency();
53 }
54
55 static int dsda_WadCompatibilityLevel(void) {
56 static int complvl = -1;
57 static int last_numwadfiles = -1;
58
59 // This might be called before all wads are loaded
60 if (numwadfiles != last_numwadfiles) {
61 int num;
62
63 last_numwadfiles = numwadfiles;
64 num = W_CheckNumForName("COMPLVL");
65
66 if (num != LUMP_NOT_FOUND) {
67 int length;
68 const char* data;
69
70 length = W_LumpLength(num);
71 data = W_LumpByNum(num);
72
73 if (length == 7 && !strncasecmp("vanilla", data, 7)) {
74 if (gamemode == commercial) {
75 if (gamemission == pack_plut || gamemission == pack_tnt)
76 complvl = 4;
77 else
78 complvl = 2;
79 }
80 else
81 complvl = 3;
82 }
83 else if (length == 4 && !strncasecmp("boom", data, 4))
84 complvl = 9;
85 else if (length == 3 && !strncasecmp("mbf", data, 3))
86 complvl = 11;
87 else if (length == 5 && !strncasecmp("mbf21", data, 5))
88 complvl = 21;
89
90 lprintf(LO_INFO, "Detected COMPLVL lump: %i\n", complvl);
91 }
92 }
93
94 return complvl;
95 }
96
97 int dsda_CompatibilityLevel(void) {
98 int level;
99 dsda_arg_t* complevel_arg;
100
101 if (raven) return doom_12_compatibility;
102
103 if (map_format.zdoom) return mbf21_compatibility;
104
105 complevel_arg = dsda_Arg(dsda_arg_complevel);
106
107 if (complevel_arg->count)
108 return complevel_arg->value.v_int;
109
110 if (!demoplayback) {
111 level = dsda_WadCompatibilityLevel();
112
113 if (level >= 0)
114 return level;
115 }
116
117 return UNSPECIFIED_COMPLEVEL;
118 }
119
120 void dsda_SetTas(dboolean t) {
121 dsda_UpdateIntConfig(dsda_config_strict_mode, !t, true);
122 }
123
124 int dsda_ViewBob(void) {
125 return dsda_IntConfig(dsda_config_viewbob);
126 }
127
128 int dsda_WeaponBob(void) {
129 return dsda_IntConfig(dsda_config_weaponbob);
130 }
131
132 dboolean dsda_ShowMessages(void) {
133 return dsda_IntConfig(dsda_config_show_messages);
134 }
135
136 dboolean dsda_AutoRun(void) {
137 return dsda_IntConfig(dsda_config_autorun);
138 }
139
140 dboolean dsda_MouseLook(void) {
141 return dsda_IntConfig(dsda_config_freelook);
142 }
143
144 dboolean dsda_VertMouse(void) {
145 return dsda_IntConfig(dsda_config_vertmouse);
146 }
147
148 dboolean dsda_StrictMode(void) {
149 return dsda_IntConfig(dsda_config_strict_mode) && demorecording;
150 }
151
152 dboolean dsda_MuteSfx(void) {
153 return dsda_IntConfig(dsda_config_mute_sfx) ||
154 (!I_WindowFocused() && dsda_IntConfig(dsda_config_mute_unfocused_window));
155 }
156
157 dboolean dsda_MuteMusic(void) {
158 return dsda_IntConfig(dsda_config_mute_music) ||
159 (!I_WindowFocused() && dsda_IntConfig(dsda_config_mute_unfocused_window));
160 }
161
162 dboolean dsda_ProcessCheatCodes(void) {
163 return dsda_IntConfig(dsda_config_cheat_codes);
164 }
165
166 dboolean dsda_CycleGhostColors(void) {
167 return dsda_IntConfig(dsda_config_cycle_ghost_colors);
168 }
169
170 dboolean dsda_AlwaysSR50(void) {
171 return dsda_IntConfig(dsda_config_movement_strafe50);
172 }
173
174 dboolean dsda_HideHorns(void) {
175 return dsda_IntConfig(dsda_config_hide_horns);
176 }
177
178 dboolean dsda_HideWeapon(void) {
179 return dsda_IntConfig(dsda_config_hide_weapon);
180 }
181
182 dboolean dsda_SwitchWhenAmmoRunsOut(void) {
183 return dsda_IntConfig(dsda_config_switch_when_ammo_runs_out);
184 }
185
186 dboolean dsda_SkipQuitPrompt(void) {
187 return dsda_IntConfig(dsda_config_skip_quit_prompt) || dsda_SkipMode();
188 }
189
190 dboolean dsda_TrackSplits(void) {
191 return demorecording || (demoplayback && dsda_Flag(dsda_arg_track_playback));
192 }
193
194 dboolean dsda_ShowSplitData(void) {
195 return dsda_IntConfig(dsda_config_show_split_data);
196 }
197
198 dboolean dsda_CommandDisplay(void) {
199 return dsda_IntConfig(dsda_config_command_display) || dsda_BuildMode();
200 }
201
202 dboolean dsda_CoordinateDisplay(void) {
203 return dsda_IntConfig(dsda_config_coordinate_display);
204 }
205
206 dboolean dsda_ShowFPS(void) {
207 return dsda_IntConfig(dsda_config_show_fps);
208 }
209
210 dboolean dsda_ShowMinimap(void) {
211 return dsda_IntConfig(dsda_config_show_minimap);
212 }
213
214 dboolean dsda_ShowLevelSplits(void) {
215 return dsda_IntConfig(dsda_config_show_level_splits);
216 }
217
218 dboolean dsda_ShowDemoAttempts(void) {
219 return dsda_IntConfig(dsda_config_show_demo_attempts) && demorecording;
220 }
221
222 dboolean dsda_MapCoordinates(void) {
223 return dsda_IntConfig(dsda_config_map_coordinates);
224 }
225
226 dboolean dsda_MapTotals(void) {
227 return dsda_IntConfig(dsda_config_map_totals);
228 }
229
230 dboolean dsda_MapTime(void) {
231 return dsda_IntConfig(dsda_config_map_time);
232 }
233
234 dboolean dsda_MapTitle(void) {
235 return dsda_IntConfig(dsda_config_map_title);
236 }
237
238 dboolean dsda_PainPalette(void) {
239 return dsda_IntConfig(dsda_config_palette_ondamage);
240 }
241
242 dboolean dsda_BonusPalette(void) {
243 return dsda_IntConfig(dsda_config_palette_onbonus);
244 }
245
246 dboolean dsda_PowerPalette(void) {
247 return dsda_IntConfig(dsda_config_palette_onpowers);
248 }
249
250 dboolean dsda_ShowHealthBars(void) {
251 return dsda_IntConfig(dsda_config_gl_health_bar);
252 }
253
254 dboolean dsda_WipeAtFullSpeed(void) {
255 return dsda_IntConfig(dsda_config_wipe_at_full_speed);
256 }
257
258 int dsda_ShowAliveMonsters(void) {
259 return dsda_IntConfig(dsda_config_show_alive_monsters);
260 }
261
262 int dsda_reveal_map;
263
264 int dsda_RevealAutomap(void) {
265 if (dsda_StrictMode()) return 0;
266
267 return dsda_reveal_map;
268 }
269
270 void dsda_ResetRevealMap(void) {
271 dsda_reveal_map = 0;
272 }
273
274 int dsda_GameSpeed(void) {
275 return dsda_IntConfig(dsda_config_game_speed);
276 }
277
278 void dsda_UpdateGameSpeed(int value) {
279 dsda_UpdateIntConfig(dsda_config_game_speed, value, true);
280 }
281
282 void dsda_SkipNextWipe(void) {
283 dsda_skip_next_wipe = 1;
284 }
285
286 // In raven, strict mode does not affect this setting
287 dboolean dsda_RenderWipeScreen(void) {
288 return raven ? dsda_TransientIntConfig(dsda_config_render_wipescreen) :
289 dsda_IntConfig(dsda_config_render_wipescreen);
290 }
291
292 dboolean dsda_PendingSkipWipe(void) {
293 return dsda_skip_next_wipe || !dsda_RenderWipeScreen();
294 }
295
296 dboolean dsda_SkipWipe(void) {
297 if (dsda_skip_next_wipe) {
298 dsda_skip_next_wipe = 0;
299 return true;
300 }
301
302 return !dsda_RenderWipeScreen() || hexen;
303 }
304
305 static dboolean game_controller_used;
306 static dboolean mouse_used;
307
308 dboolean dsda_AllowGameController(void) {
309 return !dsda_StrictMode() || !mouse_used;
310 }
311
312 dboolean dsda_AllowMouse(void) {
313 return !dsda_StrictMode() || !game_controller_used;
314 }
315
316 void dsda_WatchGameControllerEvent(void) {
317 game_controller_used = true;
318
319 if (mouse_used)
320 dsda_TrackFeature(uf_mouse_and_controller);
321 }
322
323 void dsda_WatchMouseEvent(void) {
324 mouse_used = true;
325
326 if (game_controller_used)
327 dsda_TrackFeature(uf_mouse_and_controller);
328 }
329
330 void dsda_LiftInputRestrictions(void) {
331 game_controller_used = false;
332 mouse_used = false;
333 }