Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 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 | #include <unistd.h> // Pierre-Marie Baty -- for getuid() |
||
| 33 | #include <pwd.h> // Pierre-Marie Baty -- for getpwuid() |
||
| 34 | |||
| 35 | #include "config.h" |
||
| 36 | #include "pstypes.h" |
||
| 37 | #include "game.h" |
||
| 38 | #include "songs.h" |
||
| 39 | #include "kconfig.h" |
||
| 40 | #include "palette.h" |
||
| 41 | #include "args.h" |
||
| 42 | #include "player.h" |
||
| 43 | #include "digi.h" |
||
| 44 | #include "mission.h" |
||
| 45 | #include "u_mem.h" |
||
| 46 | #include "physfsx.h" |
||
| 47 | #include "nvparse.h" |
||
| 48 | #include <memory> |
||
| 49 | |||
| 50 | namespace dcx { |
||
| 51 | CCfg CGameCfg; |
||
| 52 | } |
||
| 53 | |||
| 54 | namespace dsx { |
||
| 55 | Cfg GameCfg; |
||
| 56 | |||
| 57 | #define DigiVolumeStr "DigiVolume" |
||
| 58 | #define MusicVolumeStr "MusicVolume" |
||
| 59 | #define ReverseStereoStr "ReverseStereo" |
||
| 60 | #define OrigTrackOrderStr "OrigTrackOrder" |
||
| 61 | #define MusicTypeStr "MusicType" |
||
| 62 | #define CMLevelMusicPlayOrderStr "CMLevelMusicPlayOrder" |
||
| 63 | #define CMLevelMusicTrack0Str "CMLevelMusicTrack0" |
||
| 64 | #define CMLevelMusicTrack1Str "CMLevelMusicTrack1" |
||
| 65 | #define CMLevelMusicPathStr "CMLevelMusicPath" |
||
| 66 | #define CMMiscMusic0Str "CMMiscMusic0" |
||
| 67 | #define CMMiscMusic1Str "CMMiscMusic1" |
||
| 68 | #define CMMiscMusic2Str "CMMiscMusic2" |
||
| 69 | #define CMMiscMusic3Str "CMMiscMusic3" |
||
| 70 | #define CMMiscMusic4Str "CMMiscMusic4" |
||
| 71 | #define GammaLevelStr "GammaLevel" |
||
| 72 | #define LastPlayerStr "LastPlayer" |
||
| 73 | #define LastMissionStr "LastMission" |
||
| 74 | #define ResolutionXStr "ResolutionX" |
||
| 75 | #define ResolutionYStr "ResolutionY" |
||
| 76 | #define AspectXStr "AspectX" |
||
| 77 | #define AspectYStr "AspectY" |
||
| 78 | #define WindowModeStr "WindowMode" |
||
| 79 | #define TexFiltStr "TexFilt" |
||
| 80 | #define TexAnisStr "TexAnisotropy" |
||
| 81 | #if defined(DXX_BUILD_DESCENT_II) |
||
| 82 | #define MovieTexFiltStr "MovieTexFilt" |
||
| 83 | #define MovieSubtitlesStr "MovieSubtitles" |
||
| 84 | #endif |
||
| 85 | #if DXX_USE_ADLMIDI |
||
| 86 | #define ADLMIDINumChipsStr "ADLMIDI_NumberOfChips" |
||
| 87 | #define ADLMIDIBankStr "ADLMIDI_Bank" |
||
| 88 | #define ADLMIDIEnabledStr "ADLMIDI_Enabled" |
||
| 89 | #endif |
||
| 90 | #define VSyncStr "VSync" |
||
| 91 | #define MultisampleStr "Multisample" |
||
| 92 | #define FPSIndicatorStr "FPSIndicator" |
||
| 93 | #define GrabinputStr "GrabInput" |
||
| 94 | |||
| 95 | int ReadConfigFile() |
||
| 96 | { |
||
| 97 | // set defaults |
||
| 98 | GameCfg.DigiVolume = 8; |
||
| 99 | GameCfg.MusicVolume = 8; |
||
| 100 | GameCfg.ReverseStereo = 0; |
||
| 101 | GameCfg.OrigTrackOrder = 0; |
||
| 102 | #if DXX_USE_SDL_REDBOOK_AUDIO && defined(__APPLE__) && defined(__MACH__) |
||
| 103 | GameCfg.MusicType = MUSIC_TYPE_REDBOOK; |
||
| 104 | #else |
||
| 105 | GameCfg.MusicType = MUSIC_TYPE_BUILTIN; |
||
| 106 | #endif |
||
| 107 | CGameCfg.CMLevelMusicPlayOrder = LevelMusicPlayOrder::Continuous; |
||
| 108 | CGameCfg.CMLevelMusicTrack[0] = -1; |
||
| 109 | CGameCfg.CMLevelMusicTrack[1] = -1; |
||
| 110 | CGameCfg.CMLevelMusicPath = {}; |
||
| 111 | CGameCfg.CMMiscMusic = {}; |
||
| 112 | #if defined(__APPLE__) && defined(__MACH__) |
||
| 113 | const auto userdir = /*PHYSFS_getUserDir()*/getpwuid(getuid())->pw_dir; // Pierre-Marie Baty -- work around PHYSFS_getUserDir() deprecation |
||
| 114 | GameCfg.OrigTrackOrder = 1; |
||
| 115 | #if defined(DXX_BUILD_DESCENT_I) |
||
| 116 | CGameCfg.CMLevelMusicPlayOrder = LevelMusicPlayOrder::Level; |
||
| 117 | CGameCfg.CMLevelMusicPath = "descent.m3u"; |
||
| 118 | snprintf(CGameCfg.CMMiscMusic[SONG_TITLE].data(), CGameCfg.CMMiscMusic[SONG_TITLE].size(), "%s/%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/02 Primitive Rage.mp3"); |
||
| 119 | snprintf(CGameCfg.CMMiscMusic[SONG_CREDITS].data(), CGameCfg.CMMiscMusic[SONG_CREDITS].size(), "%s/%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/05 The Darkness Of Space.mp3"); |
||
| 120 | #elif defined(DXX_BUILD_DESCENT_II) |
||
| 121 | CGameCfg.CMLevelMusicPath = "descent2.m3u"; |
||
| 122 | snprintf(CGameCfg.CMMiscMusic[SONG_TITLE].data(), CGameCfg.CMMiscMusic[SONG_TITLE].size(), "%s/%s", userdir, "Music/iTunes/iTunes Music/Redbook Soundtrack/Descent II, Macintosh CD-ROM/02 Title.mp3"); |
||
| 123 | snprintf(CGameCfg.CMMiscMusic[SONG_CREDITS].data(), CGameCfg.CMMiscMusic[SONG_CREDITS].size(), "%s/%s", userdir, "Music/iTunes/iTunes Music/Redbook Soundtrack/Descent II, Macintosh CD-ROM/03 Crawl.mp3"); |
||
| 124 | #endif |
||
| 125 | snprintf(CGameCfg.CMMiscMusic[SONG_BRIEFING].data(), CGameCfg.CMMiscMusic[SONG_BRIEFING].size(), "%s/%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/03 Outerlimits.mp3"); |
||
| 126 | snprintf(CGameCfg.CMMiscMusic[SONG_ENDLEVEL].data(), CGameCfg.CMMiscMusic[SONG_ENDLEVEL].size(), "%s/%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/04 Close Call.mp3"); |
||
| 127 | snprintf(CGameCfg.CMMiscMusic[SONG_ENDGAME].data(), CGameCfg.CMMiscMusic[SONG_ENDGAME].size(), "%s/%s", userdir, "Music/iTunes/iTunes Music/Insanity/Descent/14 Insanity.mp3"); |
||
| 128 | #endif |
||
| 129 | GameCfg.GammaLevel = 0; |
||
| 130 | GameCfg.LastPlayer = {}; |
||
| 131 | CGameCfg.LastMission = ""; |
||
| 132 | GameCfg.ResolutionX = 640; |
||
| 133 | GameCfg.ResolutionY = 480; |
||
| 134 | GameCfg.AspectX = 3; |
||
| 135 | GameCfg.AspectY = 4; |
||
| 136 | CGameCfg.WindowMode = false; |
||
| 137 | CGameCfg.TexFilt = 0; |
||
| 138 | CGameCfg.TexAnisotropy = 0; |
||
| 139 | #if defined(DXX_BUILD_DESCENT_II) |
||
| 140 | GameCfg.MovieTexFilt = 0; |
||
| 141 | GameCfg.MovieSubtitles = 0; |
||
| 142 | #endif |
||
| 143 | CGameCfg.VSync = false; |
||
| 144 | CGameCfg.Multisample = 0; |
||
| 145 | CGameCfg.FPSIndicator = 0; |
||
| 146 | CGameCfg.Grabinput = true; |
||
| 147 | |||
| 148 | |||
| 149 | auto infile = PHYSFSX_openReadBuffered("descent.cfg"); |
||
| 150 | if (!infile) |
||
| 151 | { |
||
| 152 | return 1; |
||
| 153 | } |
||
| 154 | |||
| 155 | // to be fully safe, assume the whole cfg consists of one big line |
||
| 156 | for (PHYSFSX_gets_line_t<0> line(PHYSFS_fileLength(infile) + 1); const char *const eol = PHYSFSX_fgets(line, infile);) |
||
| 157 | { |
||
| 158 | const auto lb = line.begin(); |
||
| 159 | if (eol == line.end()) |
||
| 160 | continue; |
||
| 161 | auto eq = std::find(lb, eol, '='); |
||
| 162 | if (eq == eol) |
||
| 163 | continue; |
||
| 164 | auto value = std::next(eq); |
||
| 165 | if (cmp(lb, eq, DigiVolumeStr)) |
||
| 166 | convert_integer(GameCfg.DigiVolume, value); |
||
| 167 | else if (cmp(lb, eq, MusicVolumeStr)) |
||
| 168 | convert_integer(GameCfg.MusicVolume, value); |
||
| 169 | else if (cmp(lb, eq, ReverseStereoStr)) |
||
| 170 | convert_integer(GameCfg.ReverseStereo, value); |
||
| 171 | else if (cmp(lb, eq, OrigTrackOrderStr)) |
||
| 172 | convert_integer(GameCfg.OrigTrackOrder, value); |
||
| 173 | else if (cmp(lb, eq, MusicTypeStr)) |
||
| 174 | convert_integer(GameCfg.MusicType, value); |
||
| 175 | else if (cmp(lb, eq, CMLevelMusicPlayOrderStr)) |
||
| 176 | { |
||
| 177 | unsigned CMLevelMusicPlayOrder; |
||
| 178 | if (convert_integer(CMLevelMusicPlayOrder, value) && CMLevelMusicPlayOrder <= static_cast<unsigned>(LevelMusicPlayOrder::Random)) |
||
| 179 | CGameCfg.CMLevelMusicPlayOrder = static_cast<LevelMusicPlayOrder>(CMLevelMusicPlayOrder); |
||
| 180 | } |
||
| 181 | else if (cmp(lb, eq, CMLevelMusicTrack0Str)) |
||
| 182 | convert_integer(CGameCfg.CMLevelMusicTrack[0], value); |
||
| 183 | else if (cmp(lb, eq, CMLevelMusicTrack1Str)) |
||
| 184 | convert_integer(CGameCfg.CMLevelMusicTrack[1], value); |
||
| 185 | else if (cmp(lb, eq, CMLevelMusicPathStr)) |
||
| 186 | convert_string(CGameCfg.CMLevelMusicPath, value, eol); |
||
| 187 | else if (cmp(lb, eq, CMMiscMusic0Str)) |
||
| 188 | convert_string(CGameCfg.CMMiscMusic[SONG_TITLE], value, eol); |
||
| 189 | else if (cmp(lb, eq, CMMiscMusic1Str)) |
||
| 190 | convert_string(CGameCfg.CMMiscMusic[SONG_BRIEFING], value, eol); |
||
| 191 | else if (cmp(lb, eq, CMMiscMusic2Str)) |
||
| 192 | convert_string(CGameCfg.CMMiscMusic[SONG_ENDLEVEL], value, eol); |
||
| 193 | else if (cmp(lb, eq, CMMiscMusic3Str)) |
||
| 194 | convert_string(CGameCfg.CMMiscMusic[SONG_ENDGAME], value, eol); |
||
| 195 | else if (cmp(lb, eq, CMMiscMusic4Str)) |
||
| 196 | convert_string(CGameCfg.CMMiscMusic[SONG_CREDITS], value, eol); |
||
| 197 | else if (cmp(lb, eq, GammaLevelStr)) |
||
| 198 | { |
||
| 199 | convert_integer(GameCfg.GammaLevel, value); |
||
| 200 | gr_palette_set_gamma( GameCfg.GammaLevel ); |
||
| 201 | } |
||
| 202 | else if (cmp(lb, eq, LastPlayerStr)) |
||
| 203 | GameCfg.LastPlayer.copy_lower(value, std::distance(value, eol)); |
||
| 204 | else if (cmp(lb, eq, LastMissionStr)) |
||
| 205 | convert_string(CGameCfg.LastMission, value, eol); |
||
| 206 | else if (cmp(lb, eq, ResolutionXStr)) |
||
| 207 | convert_integer(GameCfg.ResolutionX, value); |
||
| 208 | else if (cmp(lb, eq, ResolutionYStr)) |
||
| 209 | convert_integer(GameCfg.ResolutionY, value); |
||
| 210 | else if (cmp(lb, eq, AspectXStr)) |
||
| 211 | convert_integer(GameCfg.AspectX, value); |
||
| 212 | else if (cmp(lb, eq, AspectYStr)) |
||
| 213 | convert_integer(GameCfg.AspectY, value); |
||
| 214 | else if (cmp(lb, eq, WindowModeStr)) |
||
| 215 | convert_integer(CGameCfg.WindowMode, value); |
||
| 216 | else if (cmp(lb, eq, TexFiltStr)) |
||
| 217 | convert_integer(CGameCfg.TexFilt, value); |
||
| 218 | else if (cmp(lb, eq, TexAnisStr)) |
||
| 219 | convert_integer(CGameCfg.TexAnisotropy, value); |
||
| 220 | #if defined(DXX_BUILD_DESCENT_II) |
||
| 221 | else if (cmp(lb, eq, MovieTexFiltStr)) |
||
| 222 | convert_integer(GameCfg.MovieTexFilt, value); |
||
| 223 | else if (cmp(lb, eq, MovieSubtitlesStr)) |
||
| 224 | convert_integer(GameCfg.MovieSubtitles, value); |
||
| 225 | #endif |
||
| 226 | #if DXX_USE_ADLMIDI |
||
| 227 | else if (cmp(lb, eq, ADLMIDINumChipsStr)) |
||
| 228 | convert_integer(CGameCfg.ADLMIDI_num_chips, value); |
||
| 229 | else if (cmp(lb, eq, ADLMIDIBankStr)) |
||
| 230 | convert_integer(CGameCfg.ADLMIDI_bank, value); |
||
| 231 | else if (cmp(lb, eq, ADLMIDIEnabledStr)) |
||
| 232 | convert_integer(CGameCfg.ADLMIDI_enabled, value); |
||
| 233 | #endif |
||
| 234 | else if (cmp(lb, eq, VSyncStr)) |
||
| 235 | convert_integer(CGameCfg.VSync, value); |
||
| 236 | else if (cmp(lb, eq, MultisampleStr)) |
||
| 237 | convert_integer(CGameCfg.Multisample, value); |
||
| 238 | else if (cmp(lb, eq, FPSIndicatorStr)) |
||
| 239 | convert_integer(CGameCfg.FPSIndicator, value); |
||
| 240 | else if (cmp(lb, eq, GrabinputStr)) |
||
| 241 | convert_integer(CGameCfg.Grabinput, value); |
||
| 242 | } |
||
| 243 | if ( GameCfg.DigiVolume > 8 ) GameCfg.DigiVolume = 8; |
||
| 244 | if ( GameCfg.MusicVolume > 8 ) GameCfg.MusicVolume = 8; |
||
| 245 | |||
| 246 | if (GameCfg.ResolutionX >= 320 && GameCfg.ResolutionY >= 200) |
||
| 247 | { |
||
| 248 | Game_screen_mode.width = GameCfg.ResolutionX; |
||
| 249 | Game_screen_mode.height = GameCfg.ResolutionY; |
||
| 250 | } |
||
| 251 | |||
| 252 | return 0; |
||
| 253 | } |
||
| 254 | |||
| 255 | int WriteConfigFile() |
||
| 256 | { |
||
| 257 | GameCfg.GammaLevel = gr_palette_get_gamma(); |
||
| 258 | |||
| 259 | auto infile = PHYSFSX_openWriteBuffered("descent.cfg"); |
||
| 260 | if (!infile) |
||
| 261 | { |
||
| 262 | return 1; |
||
| 263 | } |
||
| 264 | PHYSFSX_printf(infile, "%s=%d\n", DigiVolumeStr, GameCfg.DigiVolume); |
||
| 265 | PHYSFSX_printf(infile, "%s=%d\n", MusicVolumeStr, GameCfg.MusicVolume); |
||
| 266 | PHYSFSX_printf(infile, "%s=%d\n", ReverseStereoStr, GameCfg.ReverseStereo); |
||
| 267 | PHYSFSX_printf(infile, "%s=%d\n", OrigTrackOrderStr, GameCfg.OrigTrackOrder); |
||
| 268 | PHYSFSX_printf(infile, "%s=%d\n", MusicTypeStr, GameCfg.MusicType); |
||
| 269 | PHYSFSX_printf(infile, "%s=%d\n", CMLevelMusicPlayOrderStr, static_cast<int>(CGameCfg.CMLevelMusicPlayOrder)); |
||
| 270 | PHYSFSX_printf(infile, "%s=%d\n", CMLevelMusicTrack0Str, CGameCfg.CMLevelMusicTrack[0]); |
||
| 271 | PHYSFSX_printf(infile, "%s=%d\n", CMLevelMusicTrack1Str, CGameCfg.CMLevelMusicTrack[1]); |
||
| 272 | PHYSFSX_printf(infile, "%s=%s\n", CMLevelMusicPathStr, CGameCfg.CMLevelMusicPath.data()); |
||
| 273 | PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic0Str, CGameCfg.CMMiscMusic[SONG_TITLE].data()); |
||
| 274 | PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic1Str, CGameCfg.CMMiscMusic[SONG_BRIEFING].data()); |
||
| 275 | PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic2Str, CGameCfg.CMMiscMusic[SONG_ENDLEVEL].data()); |
||
| 276 | PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic3Str, CGameCfg.CMMiscMusic[SONG_ENDGAME].data()); |
||
| 277 | PHYSFSX_printf(infile, "%s=%s\n", CMMiscMusic4Str, CGameCfg.CMMiscMusic[SONG_CREDITS].data()); |
||
| 278 | PHYSFSX_printf(infile, "%s=%d\n", GammaLevelStr, GameCfg.GammaLevel); |
||
| 279 | PHYSFSX_printf(infile, "%s=%s\n", LastPlayerStr, static_cast<const char *>(InterfaceUniqueState.PilotName)); |
||
| 280 | PHYSFSX_printf(infile, "%s=%s\n", LastMissionStr, static_cast<const char *>(CGameCfg.LastMission)); |
||
| 281 | PHYSFSX_printf(infile, "%s=%i\n", ResolutionXStr, SM_W(Game_screen_mode)); |
||
| 282 | PHYSFSX_printf(infile, "%s=%i\n", ResolutionYStr, SM_H(Game_screen_mode)); |
||
| 283 | PHYSFSX_printf(infile, "%s=%i\n", AspectXStr, GameCfg.AspectX); |
||
| 284 | PHYSFSX_printf(infile, "%s=%i\n", AspectYStr, GameCfg.AspectY); |
||
| 285 | PHYSFSX_printf(infile, "%s=%i\n", WindowModeStr, CGameCfg.WindowMode); |
||
| 286 | PHYSFSX_printf(infile, "%s=%i\n", TexFiltStr, CGameCfg.TexFilt); |
||
| 287 | PHYSFSX_printf(infile, "%s=%i\n", TexAnisStr, CGameCfg.TexAnisotropy); |
||
| 288 | #if defined(DXX_BUILD_DESCENT_II) |
||
| 289 | PHYSFSX_printf(infile, "%s=%i\n", MovieTexFiltStr, GameCfg.MovieTexFilt); |
||
| 290 | PHYSFSX_printf(infile, "%s=%i\n", MovieSubtitlesStr, GameCfg.MovieSubtitles); |
||
| 291 | #endif |
||
| 292 | #if DXX_USE_ADLMIDI |
||
| 293 | PHYSFSX_printf(infile, "%s=%i\n", ADLMIDINumChipsStr, CGameCfg.ADLMIDI_num_chips); |
||
| 294 | PHYSFSX_printf(infile, "%s=%i\n", ADLMIDIBankStr, CGameCfg.ADLMIDI_bank); |
||
| 295 | PHYSFSX_printf(infile, "%s=%i\n", ADLMIDIEnabledStr, CGameCfg.ADLMIDI_enabled); |
||
| 296 | #endif |
||
| 297 | PHYSFSX_printf(infile, "%s=%i\n", VSyncStr, CGameCfg.VSync); |
||
| 298 | PHYSFSX_printf(infile, "%s=%i\n", MultisampleStr, CGameCfg.Multisample); |
||
| 299 | PHYSFSX_printf(infile, "%s=%i\n", FPSIndicatorStr, CGameCfg.FPSIndicator); |
||
| 300 | PHYSFSX_printf(infile, "%s=%i\n", GrabinputStr, CGameCfg.Grabinput); |
||
| 301 | return 0; |
||
| 302 | } |
||
| 303 | |||
| 304 | } |