Debian Codegraph @

prboom2/src/dsda/preferences.c

raw
1 //
2 // Copyright(C) 2023 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 Preferences
16 //
17
18 #include "lprintf.h"
19 #include "w_wad.h"
20 #include "v_video.h"
21
22 #include "dsda/args.h"
23 #include "dsda/messenger.h"
24 #include "dsda/utility.h"
25
26 #include "preferences.h"
27
28 typedef struct {
29 dboolean opengl;
30 dboolean software;
31 dboolean mapinfo;
32 } preferences_t;
33
34 static preferences_t map_preferences;
35 static preferences_t wad_preferences;
36
37 void dsda_LoadWadPreferences(void) {
38 char* lump;
39 char** lines;
40 const char* line;
41 int line_i;
42 int value;
43 char key[33] = { 0 };
44
45 lump = W_ReadLumpToString(W_CheckNumForName("DSDAPREF"));
46
47 if (!lump)
48 return;
49
50 lines = dsda_SplitString(lump, "\n\r");
51
52 for (line_i = 0; lines[line_i]; ++line_i) {
53 line = lines[line_i];
54
55 if (!line[0] || line[0] == '/')
56 continue;
57
58 value = 1;
59 if (!sscanf(line, "%32s %d", key, &value))
60 I_Error("DSDAPREF lump has unknown format! (%s)", line);
61
62 if (!strcasecmp(key, "prefer_opengl"))
63 wad_preferences.opengl = !!value;
64 else if (!strcasecmp(key, "prefer_software"))
65 wad_preferences.software = !!value;
66 else if (!strcasecmp(key, "use_mapinfo"))
67 wad_preferences.mapinfo = !!value;
68 else
69 lprintf(LO_WARN, "Unknown DSDAPREF key: %s\n", key);
70 }
71
72 Z_Free(lines);
73 Z_Free(lump);
74 }
75
76 static void dsda_HandleWadPreferences(void) {
77 DO_ONCE
78 if (wad_preferences.opengl && V_IsSoftwareMode())
79 dsda_AddAlert("This wad may have rendering errors\nin software mode!");
80
81 if (wad_preferences.software && V_IsOpenGLMode())
82 dsda_AddAlert("This wad may have rendering errors\nin opengl mode!");
83 END_ONCE
84 }
85
86 void dsda_HandleMapPreferences(void) {
87 dsda_HandleWadPreferences();
88
89 if (map_preferences.opengl && V_IsSoftwareMode())
90 dsda_AddAlert("This level may have rendering errors\nin software mode!");
91
92 if (map_preferences.software && V_IsOpenGLMode())
93 dsda_AddAlert("This level may have rendering errors\nin opengl mode!");
94
95 memset(&map_preferences, 0, sizeof(map_preferences));
96 }
97
98 void dsda_PreferOpenGL(void) {
99 map_preferences.opengl = true;
100 }
101
102 void dsda_PreferSoftware(void) {
103 map_preferences.software = true;
104 }
105
106 dboolean dsda_UseMapinfo(void) {
107 return dsda_Flag(dsda_arg_debug_mapinfo) || wad_preferences.mapinfo;
108 }