Debian Codegraph @

similar/main/config.cpp

raw
1 /*
2 * Portions of this file are copyright Rebirth contributors and licensed as
3 * described in COPYING.txt.
4 * Portions of this file are copyright Parallax Software and licensed
5 * according to the Parallax license below.
6 * See COPYING.txt for license details.
7
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
18 */
19
20 /*
21 *
22 * contains routine(s) to read in the configuration file which contains
23 * game configuration stuff like detail level, sound card, etc
24 *
25 */
26
27 #include <memory>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <ctype.h>
32
33 #include "config.h"
34 #include "pstypes.h"
35 #include "game.h"
36 #include "songs.h"
37 #include "kconfig.h"
38 #include "palette.h"
39 #include "digi.h"
40 #include "mission.h"
41 #include "u_mem.h"
42 #include "physfsx.h"
43 #include "strutil.h"
44 #include "nvparse.h"
45 #if DXX_USE_OGL
46 #include "ogl_init.h"
47 #endif
48 #include <memory>
49
50 namespace dcx {
51
52 #define DXX_DESCENT_CFG_NAME "descent.cfg"
53
54 CCfg CGameCfg;
55
56 namespace {
57
58 static char dxx_descent_cfg_name[]{DXX_DESCENT_CFG_NAME};
59
60 /* This is declared for use in `decltype`, and never defined. */
61 template <std::size_t N>
62 std::integral_constant<std::size_t, N> field_value_length(const std::array<char, N> &);
63
64 }
65
66 }
67
68 namespace dsx {
69 Cfg GameCfg;
70
71 #define DigiVolumeStr "DigiVolume"
72 #define MusicVolumeStr "MusicVolume"
73 #define ReverseStereoStr "ReverseStereo"
74 #define OrigTrackOrderStr "OrigTrackOrder"
75 #define MusicTypeStr "MusicType"
76 #define CMLevelMusicPlayOrderStr "CMLevelMusicPlayOrder"
77 #define CMLevelMusicTrack0Str "CMLevelMusicTrack0"
78 #define CMLevelMusicTrack1Str "CMLevelMusicTrack1"
79 #define CMLevelMusicPathStr "CMLevelMusicPath"
80 #define CMMiscMusic0Str "CMMiscMusic0"
81 #define CMMiscMusic1Str "CMMiscMusic1"
82 #define CMMiscMusic2Str "CMMiscMusic2"
83 #define CMMiscMusic3Str "CMMiscMusic3"
84 #define CMMiscMusic4Str "CMMiscMusic4"
85 #define GammaLevelStr "GammaLevel"
86 #define LastPlayerStr "LastPlayer"
87 #define LastMissionStr "LastMission"
88 #define ResolutionXStr "ResolutionX"
89 #define ResolutionYStr "ResolutionY"
90 #define AspectXStr "AspectX"
91 #define AspectYStr "AspectY"
92 #define WindowModeStr "WindowMode"
93 #define TexFiltStr "TexFilt"
94 #define TexAnisStr "TexAnisotropy"
95 #if DXX_BUILD_DESCENT == 2
96 #define MovieTexFiltStr "MovieTexFilt"
97 #define MovieSubtitlesStr "MovieSubtitles"
98 #endif
99 #if DXX_USE_ADLMIDI
100 #define ADLMIDINumChipsStr "ADLMIDI_NumberOfChips"
101 #define ADLMIDIBankStr "ADLMIDI_Bank"
102 #define ADLMIDIEnabledStr "ADLMIDI_Enabled"
103 #define DXX_DESCENT_CFG_ADLMIDI_BLOCK(VERB_d) \
104 VERB_d(ADLMIDINumChipsStr, CGameCfg.ADLMIDI_num_chips) \
105 VERB_d(ADLMIDIBankStr, CGameCfg.ADLMIDI_bank) \
106 VERB_d(ADLMIDIEnabledStr, CGameCfg.ADLMIDI_enabled) \
107
108 #else
109 #define DXX_DESCENT_CFG_ADLMIDI_BLOCK(VERB_d) /* ADLMIDI is disabled - expand to nothing */
110 #endif
111 #define VSyncStr "VSync"
112 #define MultisampleStr "Multisample"
113 #define FPSIndicatorStr "FPSIndicator"
114 #define GrabinputStr "GrabInput"
115
116 namespace {
117
118 #if DXX_BUILD_DESCENT == 1
119 #define D2X_DESCENT_CFG_TEXT(VERB_d) /* For Descent 1, expand to nothing */
120
121 #elif DXX_BUILD_DESCENT == 2
122 #define D2X_DESCENT_CFG_TEXT(VERB_d) /* For Descent 2, expand to values specific to D2. */ \
123 VERB_d(MovieTexFiltStr, GameCfg.MovieTexFilt) \
124 VERB_d(MovieSubtitlesStr, GameCfg.MovieSubtitles) \
125
126 #endif
127
128 #define DXX_DESCENT_CFG_TEXT(VERB_d,VERB_s) \
129 VERB_d(DigiVolumeStr, CGameCfg.DigiVolume) \
130 VERB_d(MusicVolumeStr, CGameCfg.MusicVolume) \
131 VERB_d(ReverseStereoStr, CGameCfg.ReverseStereo) \
132 VERB_d(OrigTrackOrderStr, CGameCfg.OrigTrackOrder) \
133 VERB_d(MusicTypeStr, underlying_value(CGameCfg.MusicType)) \
134 VERB_d(CMLevelMusicPlayOrderStr, static_cast<int>(CGameCfg.CMLevelMusicPlayOrder)) \
135 VERB_d(CMLevelMusicTrack0Str, CGameCfg.CMLevelMusicTrack[0]) \
136 VERB_d(CMLevelMusicTrack1Str, CGameCfg.CMLevelMusicTrack[1]) \
137 VERB_s(CMLevelMusicPathStr, CGameCfg.CMLevelMusicPath) \
138 VERB_s(CMMiscMusic0Str, CGameCfg.CMMiscMusic[song_number::title]) \
139 VERB_s(CMMiscMusic1Str, CGameCfg.CMMiscMusic[song_number::briefing]) \
140 VERB_s(CMMiscMusic2Str, CGameCfg.CMMiscMusic[song_number::endlevel]) \
141 VERB_s(CMMiscMusic3Str, CGameCfg.CMMiscMusic[song_number::endgame]) \
142 VERB_s(CMMiscMusic4Str, CGameCfg.CMMiscMusic[song_number::credits]) \
143 VERB_d(GammaLevelStr, CGameCfg.GammaLevel) \
144 VERB_s(LastPlayerStr, InterfaceUniqueState.PilotName.a) \
145 VERB_s(LastMissionStr, CGameCfg.LastMission) \
146 VERB_d(ResolutionXStr, SM_W(Game_screen_mode)) \
147 VERB_d(ResolutionYStr, SM_H(Game_screen_mode)) \
148 VERB_d(AspectXStr, CGameCfg.AspectX) \
149 VERB_d(AspectYStr, CGameCfg.AspectY) \
150 VERB_d(WindowModeStr, CGameCfg.WindowMode) \
151 VERB_d(TexFiltStr, underlying_value(CGameCfg.TexFilt)) \
152 VERB_d(TexAnisStr, CGameCfg.TexAnisotropy) \
153 D2X_DESCENT_CFG_TEXT(VERB_d) \
154 DXX_DESCENT_CFG_ADLMIDI_BLOCK(VERB_d) \
155 VERB_d(VSyncStr, CGameCfg.VSync) \
156 VERB_d(MultisampleStr, CGameCfg.Multisample) \
157 VERB_d(FPSIndicatorStr, CGameCfg.FPSIndicator) \
158 VERB_d(GrabinputStr, CGameCfg.Grabinput) \
159
160 struct descent_cfg_file_prepared_text
161 {
162 #define DXX_DESCENT_CFG_FIELD_NAME_LENGTH(NAME) + sizeof(NAME) /* includes the trailing null, so there is no need to add 1 for the equal sign */ + 1 /* trailing newline */
163 #define DXX_DESCENT_CFG_FIELD_LENGTH_d(NAME, VALUE) DXX_DESCENT_CFG_FIELD_NAME_LENGTH(NAME) + 1 /* for negative sign, if needed */ + number_to_text_length<std::numeric_limits<typename std::remove_reference_t<decltype(VALUE)>>::max()> + 1 /* for newline */
164 #define DXX_DESCENT_CFG_FIELD_LENGTH_s(NAME, VALUE) DXX_DESCENT_CFG_FIELD_NAME_LENGTH(NAME) + decltype(field_value_length(VALUE))::value
165 /* Declare a function to bring the macro's variable names into scope so
166 * that `DXX_DESCENT_CFG_TEXT` can refer to them. It is never defined.
167 */
168 static auto configuration_text_file_length(const CCfg &CGameCfg, const Cfg &GameCfg) -> std::integral_constant<std::size_t, DXX_DESCENT_CFG_TEXT(DXX_DESCENT_CFG_FIELD_LENGTH_d, DXX_DESCENT_CFG_FIELD_LENGTH_s)>;
169 using buffer_type = std::array<char, decltype(configuration_text_file_length(std::declval<CCfg>(), std::declval<Cfg>()))::value>;
170 #undef DXX_DESCENT_CFG_FIELD_LENGTH_s
171 #undef DXX_DESCENT_CFG_FIELD_LENGTH_d
172 #undef DXX_DESCENT_CFG_FIELD_NAME_LENGTH
173 std::size_t written;
174 buffer_type buf;
175 };
176
177 static bool cfg_file_unchanged(const descent_cfg_file_prepared_text &current_cfg_text)
178 {
179 const auto &&[f, physfserr]{PHYSFSX_openReadBuffered_updateCase(dxx_descent_cfg_name)};
180 if (!f)
181 {
182 /* If the file cannot be read, assume that a new file must be written. */
183 con_printf(physfserr == PHYSFS_ERR_NOT_FOUND ? CON_VERBOSE : CON_NORMAL, "Failed to read \"" DXX_DESCENT_CFG_NAME "\": %s", PHYSFS_getErrorByCode(physfserr));
184 return false;
185 }
186 const auto existing_file_size{PHYSFS_fileLength(f)};
187 if (existing_file_size != current_cfg_text.written)
188 {
189 /* The file is of a different length, so its contents must be
190 * different. A new file must be written.
191 */
192 con_printf(CON_VERBOSE, "Replacing configuration file \"" DXX_DESCENT_CFG_NAME "\" due to size mismatch: current=%" DXX_PRI_size_type "; new=%" DXX_PRI_size_type, static_cast<std::size_t>(existing_file_size), current_cfg_text.written);
193 return false;
194 }
195 descent_cfg_file_prepared_text::buffer_type previous_cfg_text;
196 if (const auto rb{PHYSFS_readBytes(f, previous_cfg_text.data(), previous_cfg_text.size())}; rb != existing_file_size)
197 {
198 /* Log this at a higher level because it is strange for the file to
199 * change size between when `PHYSFS_fileLength` examines it and when
200 * `PHYSFS_readBytes` reads it.
201 */
202 con_printf(CON_NORMAL, "Replacing configuration file \"" DXX_DESCENT_CFG_NAME "\" due to read count mismatch: expected=%" DXX_PRI_size_type "; read=%" DXX_PRI_size_type, static_cast<std::size_t>(existing_file_size), static_cast<std::size_t>(rb));
203 return false;
204 }
205 const auto pcbegin{previous_cfg_text.begin()};
206 const auto pcend{std::next(pcbegin, existing_file_size)};
207 const auto ccbegin{current_cfg_text.buf.begin()};
208 const auto ccend{std::next(ccbegin, existing_file_size)};
209 /* The two ranges are of equal length, so `in1 == pcend` if and only if `in2 == ccend`. */
210 if (const auto mm{std::ranges::mismatch(pcbegin, pcend, ccbegin, ccend)}; mm.in1 != pcend)
211 {
212 con_printf(CON_VERBOSE, "Replacing configuration file \"" DXX_DESCENT_CFG_NAME "\" due to content mismatch at offset %" DXX_PRI_size_type, mm.in1 - pcbegin);
213 return false;
214 }
215 con_puts(CON_VERBOSE, "Retaining configuration file \"" DXX_DESCENT_CFG_NAME "\"");
216 return true;
217 }
218
219 static auto build_cfg_file_text(const CCfg &CGameCfg, const Cfg &GameCfg)
220 {
221 #if DXX_BUILD_DESCENT == 1
222 (void)GameCfg; /* Only Descent 2 uses this variable. */
223 #endif
224 descent_cfg_file_prepared_text result;
225 const auto written{std::snprintf(result.buf.data(), result.buf.size(),
226 #define DXX_DESCENT_CFG_FIELD_FORMAT_d(unused_name, unused_value) "%s=%d\n"
227 #define DXX_DESCENT_CFG_FIELD_FORMAT_s(unused_name, unused_value) "%s=%s\n"
228 DXX_DESCENT_CFG_TEXT(DXX_DESCENT_CFG_FIELD_FORMAT_d, DXX_DESCENT_CFG_FIELD_FORMAT_s)
229 #undef DXX_DESCENT_CFG_FIELD_FORMAT_s
230 #undef DXX_DESCENT_CFG_FIELD_FORMAT_d
231 #define DXX_DESCENT_CFG_FIELD_VALUE_d(NAME, VALUE) , NAME, VALUE
232 #define DXX_DESCENT_CFG_FIELD_VALUE_s(NAME, VALUE) , NAME, (VALUE).data()
233 DXX_DESCENT_CFG_TEXT(DXX_DESCENT_CFG_FIELD_VALUE_d, DXX_DESCENT_CFG_FIELD_VALUE_s)
234 #undef DXX_DESCENT_CFG_FIELD_VALUE_s
235 #undef DXX_DESCENT_CFG_FIELD_VALUE_d
236 )};
237 if (static_cast<std::size_t>(written) >= result.buf.size())
238 result.buf[0] = 0;
239 result.written = written;
240 return result;
241 }
242
243 }
244
245 void ReadConfigFile(CCfg &CGameCfg, Cfg &GameCfg)
246 {
247 // set defaults
248 CGameCfg.DigiVolume = 8;
249 CGameCfg.MusicVolume = 8;
250 CGameCfg.ReverseStereo = false;
251 CGameCfg.OrigTrackOrder = false;
252 #if DXX_USE_SDL_REDBOOK_AUDIO && defined(__APPLE__) && defined(__MACH__)
253 CGameCfg.MusicType = music_type::Redbook;
254 #else
255 CGameCfg.MusicType = music_type::Builtin;
256 #endif
257 CGameCfg.CMLevelMusicPlayOrder = LevelMusicPlayOrder::Continuous;
258 CGameCfg.CMLevelMusicTrack[0] = -1;
259 CGameCfg.CMLevelMusicTrack[1] = -1;
260 CGameCfg.CMLevelMusicPath = {};
261 CGameCfg.CMMiscMusic = {};
262 #if defined(__APPLE__) && defined(__MACH__)
263 CGameCfg.OrigTrackOrder = true;
264 const auto userdir = PHYSFS_getUserDir();
265 #if DXX_BUILD_DESCENT == 1
266 CGameCfg.CMLevelMusicPlayOrder = LevelMusicPlayOrder::Level;
267 CGameCfg.CMLevelMusicPath = "descent.m3u";
268 snprintf(CGameCfg.CMMiscMusic[song_number::title].data(), CGameCfg.CMMiscMusic[song_number::title].size(), "%s%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/02 Primitive Rage.mp3");
269 snprintf(CGameCfg.CMMiscMusic[song_number::credits].data(), CGameCfg.CMMiscMusic[song_number::credits].size(), "%s%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/05 The Darkness Of Space.mp3");
270 #elif DXX_BUILD_DESCENT == 2
271 CGameCfg.CMLevelMusicPath = "descent2.m3u";
272 snprintf(CGameCfg.CMMiscMusic[song_number::title].data(), CGameCfg.CMMiscMusic[song_number::title].size(), "%s%s", userdir, "Music/iTunes/iTunes Music/Redbook Soundtrack/Descent II, Macintosh CD-ROM/02 Title.mp3");
273 snprintf(CGameCfg.CMMiscMusic[song_number::credits].data(), CGameCfg.CMMiscMusic[song_number::credits].size(), "%s%s", userdir, "Music/iTunes/iTunes Music/Redbook Soundtrack/Descent II, Macintosh CD-ROM/03 Crawl.mp3");
274 #endif
275 snprintf(CGameCfg.CMMiscMusic[song_number::briefing].data(), CGameCfg.CMMiscMusic[song_number::briefing].size(), "%s%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/03 Outerlimits.mp3");
276 snprintf(CGameCfg.CMMiscMusic[song_number::endlevel].data(), CGameCfg.CMMiscMusic[song_number::endlevel].size(), "%s%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/04 Close Call.mp3");
277 snprintf(CGameCfg.CMMiscMusic[song_number::endgame].data(), CGameCfg.CMMiscMusic[song_number::endgame].size(), "%s%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/14 Insanity.mp3");
278 #endif
279 CGameCfg.GammaLevel = 0;
280 GameCfg.LastPlayer = {};
281 CGameCfg.LastMission = "";
282 CGameCfg.ResolutionX = 1024;
283 CGameCfg.ResolutionY = 768;
284 CGameCfg.AspectX = 3;
285 CGameCfg.AspectY = 4;
286 CGameCfg.WindowMode = false;
287 #if DXX_USE_OGL
288 CGameCfg.TexFilt = opengl_texture_filter::classic;
289 #endif
290 CGameCfg.TexAnisotropy = 0;
291 #if DXX_BUILD_DESCENT == 2
292 GameCfg.MovieTexFilt = 0;
293 GameCfg.MovieSubtitles = 0;
294 #endif
295 CGameCfg.VSync = false;
296 CGameCfg.Multisample = 0;
297 CGameCfg.FPSIndicator = 0;
298 CGameCfg.Grabinput = true;
299
300 auto &&[infile, physfserr]{PHYSFSX_openReadBuffered_updateCase(dxx_descent_cfg_name)};
301 if (!infile)
302 {
303 /* "File not found" is less important, and happens naturally on a first
304 * install. Log it at a lower verbosity level.
305 */
306 con_printf(physfserr == PHYSFS_ERR_NOT_FOUND ? CON_VERBOSE : CON_NORMAL, "Failed to read \"" DXX_DESCENT_CFG_NAME "\": %s", PHYSFS_getErrorByCode(physfserr));
307 return;
308 }
309
310 // to be fully safe, assume the whole cfg consists of one big line
311 for (PHYSFSX_gets_line_t<0> line(PHYSFS_fileLength(infile) + 1); const auto rc{PHYSFSX_fgets(line, infile)};)
312 {
313 const auto eol{rc.end()};
314 const auto lb{rc.begin()};
315 const auto eq{std::ranges::find(lb, eol, '=')};
316 if (eq == eol)
317 continue;
318 const auto value{std::next(eq)};
319 if (const std::ranges::subrange name{lb, eq}; compare_nonterminated_name(name, DigiVolumeStr))
320 {
321 if (const auto r = convert_integer<uint8_t>(value))
322 if (const auto v = *r; v < 8)
323 CGameCfg.DigiVolume = v;
324 }
325 else if (compare_nonterminated_name(name, MusicVolumeStr))
326 {
327 if (const auto r = convert_integer<uint8_t>(value))
328 if (const auto v = *r; v < 8)
329 CGameCfg.MusicVolume = v;
330 }
331 else if (compare_nonterminated_name(name, ReverseStereoStr))
332 convert_integer(CGameCfg.ReverseStereo, value);
333 else if (compare_nonterminated_name(name, OrigTrackOrderStr))
334 convert_integer(CGameCfg.OrigTrackOrder, value);
335 else if (compare_nonterminated_name(name, MusicTypeStr))
336 {
337 if (const auto r = convert_integer<uint8_t>(value))
338 switch (const music_type v{*r})
339 {
340 case music_type::None:
341 case music_type::Builtin:
342 #if DXX_USE_SDL_REDBOOK_AUDIO
343 case music_type::Redbook:
344 #endif
345 case music_type::Custom:
346 CGameCfg.MusicType = v;
347 break;
348 }
349 }
350 else if (compare_nonterminated_name(name, CMLevelMusicPlayOrderStr))
351 {
352 if (auto r = convert_integer<uint8_t>(value))
353 if (auto CMLevelMusicPlayOrder = *r; CMLevelMusicPlayOrder <= static_cast<uint8_t>(LevelMusicPlayOrder::Random))
354 CGameCfg.CMLevelMusicPlayOrder = LevelMusicPlayOrder{CMLevelMusicPlayOrder};
355 }
356 else if (compare_nonterminated_name(name, CMLevelMusicTrack0Str))
357 convert_integer(CGameCfg.CMLevelMusicTrack[0], value);
358 else if (compare_nonterminated_name(name, CMLevelMusicTrack1Str))
359 convert_integer(CGameCfg.CMLevelMusicTrack[1], value);
360 else if (compare_nonterminated_name(name, CMLevelMusicPathStr))
361 convert_string(CGameCfg.CMLevelMusicPath, value, eol);
362 else if (compare_nonterminated_name(name, CMMiscMusic0Str))
363 convert_string(CGameCfg.CMMiscMusic[song_number::title], value, eol);
364 else if (compare_nonterminated_name(name, CMMiscMusic1Str))
365 convert_string(CGameCfg.CMMiscMusic[song_number::briefing], value, eol);
366 else if (compare_nonterminated_name(name, CMMiscMusic2Str))
367 convert_string(CGameCfg.CMMiscMusic[song_number::endlevel], value, eol);
368 else if (compare_nonterminated_name(name, CMMiscMusic3Str))
369 convert_string(CGameCfg.CMMiscMusic[song_number::endgame], value, eol);
370 else if (compare_nonterminated_name(name, CMMiscMusic4Str))
371 convert_string(CGameCfg.CMMiscMusic[song_number::credits], value, eol);
372 else if (compare_nonterminated_name(name, GammaLevelStr))
373 {
374 convert_integer(CGameCfg.GammaLevel, value);
375 gr_palette_set_gamma(CGameCfg.GammaLevel);
376 }
377 else if (compare_nonterminated_name(name, LastPlayerStr))
378 GameCfg.LastPlayer.copy_lower(std::span(value, std::distance(value, eol)));
379 else if (compare_nonterminated_name(name, LastMissionStr))
380 convert_string(CGameCfg.LastMission, value, eol);
381 else if (compare_nonterminated_name(name, ResolutionXStr))
382 convert_integer(CGameCfg.ResolutionX, value);
383 else if (compare_nonterminated_name(name, ResolutionYStr))
384 convert_integer(CGameCfg.ResolutionY, value);
385 else if (compare_nonterminated_name(name, AspectXStr))
386 convert_integer(CGameCfg.AspectX, value);
387 else if (compare_nonterminated_name(name, AspectYStr))
388 convert_integer(CGameCfg.AspectY, value);
389 else if (compare_nonterminated_name(name, WindowModeStr))
390 convert_integer(CGameCfg.WindowMode, value);
391 else if (compare_nonterminated_name(name, TexFiltStr))
392 {
393 if (auto r = convert_integer<uint8_t>(value))
394 {
395 switch (const auto TexFilt = *r)
396 {
397 #if DXX_USE_OGL
398 case static_cast<unsigned>(opengl_texture_filter::classic):
399 case static_cast<unsigned>(opengl_texture_filter::upscale):
400 case static_cast<unsigned>(opengl_texture_filter::trilinear):
401 #else
402 default:
403 /* In SDL-only builds, accept any value and save it.
404 * The value will not be used, but it will be written
405 * back to the configuration file, to avoid deleting
406 * settings for players who use both SDL-only and
407 * OpenGL-enabled builds.
408 */
409 #endif
410 CGameCfg.TexFilt = opengl_texture_filter{TexFilt};
411 break;
412 }
413 }
414 }
415 else if (compare_nonterminated_name(name, TexAnisStr))
416 convert_integer(CGameCfg.TexAnisotropy, value);
417 #if DXX_BUILD_DESCENT == 2
418 else if (compare_nonterminated_name(name, MovieTexFiltStr))
419 convert_integer(GameCfg.MovieTexFilt, value);
420 else if (compare_nonterminated_name(name, MovieSubtitlesStr))
421 convert_integer(GameCfg.MovieSubtitles, value);
422 #endif
423 #if DXX_USE_ADLMIDI
424 else if (compare_nonterminated_name(name, ADLMIDINumChipsStr))
425 convert_integer(CGameCfg.ADLMIDI_num_chips, value);
426 else if (compare_nonterminated_name(name, ADLMIDIBankStr))
427 convert_integer(CGameCfg.ADLMIDI_bank, value);
428 else if (compare_nonterminated_name(name, ADLMIDIEnabledStr))
429 convert_integer(CGameCfg.ADLMIDI_enabled, value);
430 #endif
431 else if (compare_nonterminated_name(name, VSyncStr))
432 convert_integer(CGameCfg.VSync, value);
433 else if (compare_nonterminated_name(name, MultisampleStr))
434 convert_integer(CGameCfg.Multisample, value);
435 else if (compare_nonterminated_name(name, FPSIndicatorStr))
436 convert_integer(CGameCfg.FPSIndicator, value);
437 else if (compare_nonterminated_name(name, GrabinputStr))
438 convert_integer(CGameCfg.Grabinput, value);
439 }
440
441 if (CGameCfg.ResolutionX >= 320 && CGameCfg.ResolutionY >= 200)
442 {
443 Game_screen_mode.width = CGameCfg.ResolutionX;
444 Game_screen_mode.height = CGameCfg.ResolutionY;
445 }
446 }
447
448 int WriteConfigFile(const CCfg &CGameCfg, const Cfg &GameCfg)
449 {
450 const auto current_cfg_text{build_cfg_file_text(CGameCfg, GameCfg)};
451 if (cfg_file_unchanged(current_cfg_text))
452 return 0;
453 auto &&[outfile, physfserr]{PHYSFSX_openWriteBuffered(DXX_DESCENT_CFG_NAME)};
454 if (!outfile)
455 {
456 con_printf(CON_NORMAL, "Failed to write \"" DXX_DESCENT_CFG_NAME "\": %s", PHYSFS_getErrorByCode(physfserr));
457 return 1;
458 }
459 PHYSFSX_writeBytes(outfile, current_cfg_text.buf.data(), current_cfg_text.written);
460 return 0;
461 }
462
463 }