| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file main.cpp |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created main.c |
| 10 | * - 22nd July 2008: Created util.c from parts of main.c |
| 11 | * - 3rd February 2009: Renamed main.c to main.cpp |
| 12 | * - 4th February 2009: Created palette.cpp from parts of main.cpp and util.cpp |
| 13 | * - 13th July 2009: Created controls.cpp from parts of main.cpp |
| 14 | * - 21st July 2013: Created setup.cpp from parts of main.cpp and setupmenu.cpp |
| 15 | * |
| 16 | * @par Licence: |
| 17 | * Copyright (c) 2005-2017 AJ Thomson |
| 18 | * Copyright (c) 2015-2026 Carsten Teibes |
| 19 | * |
| 20 | * OpenJazz is distributed under the terms of |
| 21 | * the GNU General Public License, version 2.0 |
| 22 | * |
| 23 | * @par Description: |
| 24 | * Contains the main function. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | // consume all external variables |
| 30 | #define EXTERNcxx . . $ `src/main.cpp:30:9`! |
| 31 | |
| 32 | #include "game/game.h"cxx . . $ `<file>/src/game/game.h`/ |
| 33 | #include "io/controls.h"cxx . . $ `<file>/src/io/controls.h`/ |
| 34 | #include "io/file.h"cxx . . $ `<file>/src/io/file.h`/ |
| 35 | #include "io/gfx/font.h"cxx . . $ `<file>/src/io/gfx/font.h`/ |
| 36 | #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/ |
| 37 | #include "io/network.h"cxx . . $ `<file>/src/io/network.h`/ |
| 38 | #include "io/sound.h"cxx . . $ `<file>/src/io/sound.h`/ |
| 39 | #ifdef ENABLE_JJ2 |
| 40 | #include "jj2/level/jj2level.h" |
| 41 | #endif |
| 42 | #include "jj1/level/jj1level.h"cxx . . $ `<file>/src/jj1/level/jj1level.h`/ |
| 43 | #include "menu/menu.h"cxx . . $ `<file>/src/menu/menu.h`/ |
| 44 | #include "player/player.h"cxx . . $ `<file>/src/player/player.h`/ |
| 45 | #include "jj1/scene/jj1scene.h"cxx . . $ `<file>/src/jj1/scene/jj1scene.h`/ |
| 46 | #include "loop.h"cxx . . $ `<file>/src/loop.h`/ |
| 47 | #include "setup.h"cxx . . $ `<file>/src/setup.h`/ |
| 48 | #include "util.h"cxx . . $ `<file>/src/util.h`/ |
| 49 | #include "io/log.h"cxx . . $ `<file>/src/io/log.h`/ |
| 50 | #include "platforms/platforms.h"cxx . . $ `<file>/src/platforms/platforms.h`/ |
| 51 | #include "version.h"cxx . . $ `<file>/src/version.h`/ |
| 52 | |
| 53 | #include <cstring> |
| 54 | #include <argparse.h>cxx . . $ `<file>/ext/argparse/argparse.h`/ |
| 55 | |
| 56 | #if !OJ_SDL3 |
| 57 | // Define some stuff to be SDL3 compatible |
| 58 | |
| 59 | #define SDL_EVENT_QUITcxx . . $ `src/main.cpp:59:10`! SDL_QUIT |
| 60 | #endif |
| 61 | |
| 62 | #ifndef __SYMBIAN32__ |
| 63 | #include <math.h> |
| 64 | #endif |
| 65 | |
| 66 | #define PIcxx . . $ `src/main.cpp:66:9`! 3.141592f |
| 67 | |
| 68 | // Fallback links, should be provided by the build system |
| 69 | #ifndef OJ_BUGREPORTcxx . . $ `<built-in>:468:9`! |
| 70 | #define OJ_BUGREPORT "https://github.com/AlisterT/openjazz/issues" |
| 71 | #endif |
| 72 | #ifndef OJ_URLcxx . . $ `<built-in>:469:9`! |
| 73 | #define OJ_URL "http://alister.eu/jazz/oj/" |
| 74 | #endif |
| 75 | |
| 76 | static struct CliOptionscxx . . $ CliOptions# { |
| 77 | bool muteAudiocxx . . $ CliOptions#muteAudio.; |
| 78 | int fullScreencxx . . $ CliOptions#fullScreen.; |
| 79 | int scaleFactorcxx . . $ CliOptions#scaleFactor.; |
| 80 | int levelcxx . . $ CliOptions#level.; |
| 81 | int worldcxx . . $ CliOptions#world.; |
| 82 | char *verboseLevelcxx . . $ CliOptions#verboseLevel.; |
| 83 | int quietcxx . . $ CliOptions#quiet.; |
| 84 | } clicxx . . $ cli. = { |
| 85 | false, -1, -1, -1, -1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0 |
| 86 | }; |
| 87 | |
| 88 | #ifndef FULLSCREEN_ONLY |
| 89 | int display_mode_cbcxx . . $ display_mode_cb(167e068defbc3e3b).(struct argparse *, const struct argparse_option *option) { |
| 90 | clicxx . . $ cli..fullScreencxx . . $ CliOptions#fullScreen. = (option->short_name == 'f') ? 1 : 0; |
| 91 | return 0; |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | int version_cbcxx . . $ version_cb(167e068defbc3e3b).(struct argparse *, const struct argparse_option */*option*/) { |
| 96 | printf("OpenJazz %s, built on %s.\n", oj_versioncxx . . $ oj_version., oj_datecxx . . $ oj_date.); |
| 97 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!); |
| 98 | } |
| 99 | |
| 100 | int checkOptionscxx . . $ checkOptions(afcd3168fc1188a4). (int argc, char *argv[]) { |
| 101 | |
| 102 | struct argparse argparse; |
| 103 | |
| 104 | // generic usage message |
| 105 | const char *usage[] = { |
| 106 | "OpenJazz [options] [[--] <game directory 1> <game directory 2>]", |
| 107 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, |
| 108 | }; |
| 109 | |
| 110 | // command line options |
| 111 | struct argparse_option opt[] = { |
| 112 | OPT_HELPcxx . . $ `ext/argparse/argparse.h:120:9`!(), |
| 113 | OPT_GROUPcxx . . $ `ext/argparse/argparse.h:119:9`!("Engine options"), |
| 114 | OPT_BOOLEANcxx . . $ `ext/argparse/argparse.h:112:9`!('m', "mute", &cli.muteAudio, "Mute audio output", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0), |
| 115 | #ifndef FULLSCREEN_ONLY |
| 116 | OPT_BOOLEANcxx . . $ `ext/argparse/argparse.h:112:9`!('f', "fullscreen", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, "Display in Fullscreen mode", |
| 117 | display_mode_cb, 0, OPT_NONEG), |
| 118 | OPT_BOOLEANcxx . . $ `ext/argparse/argparse.h:112:9`!('\0', "window", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, "Display in Window mode", |
| 119 | display_mode_cb, 0, OPT_NONEG), |
| 120 | #endif |
| 121 | OPT_INTEGERcxx . . $ `ext/argparse/argparse.h:114:9`!('s', "scale", &cli.scaleFactor, "Scale graphics <int> times", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0), |
| 122 | OPT_GROUPcxx . . $ `ext/argparse/argparse.h:119:9`!("Developer options"), |
| 123 | OPT_INTEGERcxx . . $ `ext/argparse/argparse.h:114:9`!('w', "world", &cli.world, "Load specific World", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0), |
| 124 | OPT_INTEGERcxx . . $ `ext/argparse/argparse.h:114:9`!('l', "level", &cli.level, "Load specific Level", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0), |
| 125 | OPT_BOOLEANcxx . . $ `ext/argparse/argparse.h:112:9`!('q', "quiet", &cli.quiet, "Disable console logging (Enable with --no-quiet)", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0), |
| 126 | OPT_STRINGcxx . . $ `ext/argparse/argparse.h:118:9`!('\0', "verbose", &cli.verboseLevel, |
| 127 | "Verbosity level: max, trace, debug, info, warn, error, fatal", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0), |
| 128 | OPT_BOOLEANcxx . . $ `ext/argparse/argparse.h:112:9`!('v', "version", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, "Show version information", version_cb, 0, OPT_NONEG), |
| 129 | OPT_ENDcxx . . $ `ext/argparse/argparse.h:111:9`!(), |
| 130 | }; |
| 131 | |
| 132 | argparse_init(&argparse, opt, usage, 0); |
| 133 | argparse_describe(&argparse, |
| 134 | "\nOpenJazz - Jack Jazzrabbit 1 game engine reimplementation", |
| 135 | "\nBug reports: " OJ_BUGREPORTcxx . . $ `<built-in>:468:9`! " - Homepage: " OJ_URLcxx . . $ `<built-in>:469:9`!); |
| 136 | argc = argparse_parse(&argparse, argc, argv); |
| 137 | |
| 138 | // apply logger options |
| 139 | if (clicxx . . $ cli..quietcxx . . $ CliOptions#quiet.) loggercxx . . $ logger..setQuietcxx . . $ Log#setQuiet(b45ddcbc8423892c).(clicxx . . $ cli..quietcxx . . $ CliOptions#quiet.); |
| 140 | int verbosity = loggercxx . . $ logger..getLevelcxx . . $ Log#getLevel(b126dc7c1de90089).(); |
| 141 | if (clicxx . . $ cli..verboseLevelcxx . . $ CliOptions#verboseLevel.) { |
| 142 | if (!strcmp(clicxx . . $ cli..verboseLevelcxx . . $ CliOptions#verboseLevel., "max")) verbosity = LL_MAXcxx . . $ LL_MAX.; |
| 143 | else if (!strcmp(clicxx . . $ cli..verboseLevelcxx . . $ CliOptions#verboseLevel., "trace")) verbosity = LL_TRACEcxx . . $ LL_TRACE.; |
| 144 | else if (!strcmp(clicxx . . $ cli..verboseLevelcxx . . $ CliOptions#verboseLevel., "debug")) verbosity = LL_DEBUGcxx . . $ LL_DEBUG.; |
| 145 | else if (!strcmp(clicxx . . $ cli..verboseLevelcxx . . $ CliOptions#verboseLevel., "info")) verbosity = LL_INFOcxx . . $ LL_INFO.; |
| 146 | else if (!strcmp(clicxx . . $ cli..verboseLevelcxx . . $ CliOptions#verboseLevel., "warn")) verbosity = LL_WARNcxx . . $ LL_WARN.; |
| 147 | else if (!strcmp(clicxx . . $ cli..verboseLevelcxx . . $ CliOptions#verboseLevel., "error")) verbosity = LL_ERRORcxx . . $ LL_ERROR.; |
| 148 | else if (!strcmp(clicxx . . $ cli..verboseLevelcxx . . $ CliOptions#verboseLevel., "fatal")) verbosity = LL_FATALcxx . . $ LL_FATAL.; |
| 149 | else { |
| 150 | |
| 151 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: option `--verbose` has invalid level\n"); |
| 152 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 153 | |
| 154 | } |
| 155 | } |
| 156 | loggercxx . . $ logger..setLevelcxx . . $ Log#setLevel(d4f767463ce0a6b3).(verbosity); |
| 157 | |
| 158 | return argc; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * Initialises OpenJazz. |
| 164 | * |
| 165 | * Establishes the paths from which to read files, loads configuration, sets up |
| 166 | * the game window and loads required data. |
| 167 | * |
| 168 | * @param argv0 program path |
| 169 | * @param pathCount Number of path arguments |
| 170 | * @param paths Array of path argument strings |
| 171 | */ |
| 172 | void startUpcxx . . $ startUp(9f647276e7804368). (const char *argv0, int pathCount, char *paths[]) { |
| 173 | |
| 174 | Filecxx . . $ File#* file; |
| 175 | unsigned char* pixels = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 176 | SetupOptionscxx . . $ SetupOptions# config; |
| 177 | |
| 178 | // Determine paths |
| 179 | platformcxx . . $ platform.->AddGamePathscxx . . $ IPlatform#AddGamePaths(49f6e7a06ebc5aa8).(); |
| 180 | |
| 181 | // Use any provided paths |
| 182 | for (int i = 0; i < pathCount; i++) |
| 183 | gamePathscxx . . $ gamePaths..addcxx . . $ PathMgr#add(37e8d18a243bba77).(createStringcxx . . $ createString(a8b8e32347182212).(paths[i]), PATH_TYPE_GAMEcxx . . $ PATH_TYPE_GAME.); |
| 184 | |
| 185 | |
| 186 | // Use the path of the program, but check before, since it is not always available |
| 187 | // At least crashes in Dolphin emulator (Wii) and 3DS (.cia build) |
| 188 | if (argv0) { |
| 189 | |
| 190 | int i = strlen(argv0) - 1; |
| 191 | |
| 192 | // Search for directory separator |
| 193 | while ((argv0[i] != OJ_DIR_SEPcxx . . $ `src/io/file.h:125:10`!) && (i > 0)) i--; |
| 194 | |
| 195 | // If a directory was found, copy it to the path |
| 196 | if (i > 0) { |
| 197 | |
| 198 | char *dir = createStringcxx . . $ createString(a8b8e32347182212).(argv0); |
| 199 | dir[i+1] = '\0'; |
| 200 | gamePathscxx . . $ gamePaths..addcxx . . $ PathMgr#add(37e8d18a243bba77).(dir, PATH_TYPE_SYSTEMcxx . . $ PATH_TYPE_SYSTEM.|PATH_TYPE_GAMEcxx . . $ PATH_TYPE_GAME.); |
| 201 | |
| 202 | } |
| 203 | |
| 204 | } |
| 205 | |
| 206 | // Use the current working directory |
| 207 | gamePathscxx . . $ gamePaths..addcxx . . $ PathMgr#add(37e8d18a243bba77).(createStringcxx . . $ createString(a8b8e32347182212).(""), PATH_TYPE_GAMEcxx . . $ PATH_TYPE_GAME.|PATH_TYPE_CONFIGcxx . . $ PATH_TYPE_CONFIG.|PATH_TYPE_TEMPcxx . . $ PATH_TYPE_TEMP.); |
| 208 | |
| 209 | // Use hard-coded data paths, if available |
| 210 | #ifdef DATAPATH |
| 211 | gamePaths.add(createString(DATAPATH), PATH_TYPE_SYSTEM|PATH_TYPE_GAME); |
| 212 | #endif |
| 213 | |
| 214 | // Default settings |
| 215 | |
| 216 | // Sound settings |
| 217 | #if defined(WIZ) || defined(GP2X) |
| 218 | volume = 40; |
| 219 | #endif |
| 220 | |
| 221 | // Create the network address |
| 222 | netAddresscxx . . $ netAddress. = createStringcxx . . $ createString(a8b8e32347182212).(NET_ADDRESScxx . . $ `src/io/network.h:36:10`!); |
| 223 | |
| 224 | |
| 225 | // Load settings from config file |
| 226 | config =cxx . . $ SetupOptions#`operator=`(f7c85a5acc1f0dd6). setupcxx . . $ setup..loadcxx . . $ Setup#load(48f624f2413f693b).(); |
| 227 | if (!config.validcxx . . $ SetupOptions#valid.) { |
| 228 | |
| 229 | // Invalid config - apply defaults |
| 230 | config.videoWidthcxx . . $ SetupOptions#videoWidth. = DEFAULT_SCREEN_WIDTHcxx . . $ `src/io/gfx/video.h:54:10`!; |
| 231 | config.videoHeightcxx . . $ SetupOptions#videoHeight. = DEFAULT_SCREEN_HEIGHTcxx . . $ `src/io/gfx/video.h:57:10`!; |
| 232 | config.videoScalecxx . . $ SetupOptions#videoScale. = MIN_SCALEcxx . . $ `src/io/gfx/video.h:41:9`!; |
| 233 | config.scaleMethodcxx . . $ SetupOptions#scaleMethod. = scalerTypecxx . . $ scalerType#::Nonecxx . . $ scalerType#None.; |
| 234 | |
| 235 | } |
| 236 | |
| 237 | // Apply command-line override |
| 238 | if (clicxx . . $ cli..fullScreencxx . . $ CliOptions#fullScreen. > -1) config.fullScreencxx . . $ SetupOptions#fullScreen. = clicxx . . $ cli..fullScreencxx . . $ CliOptions#fullScreen.; |
| 239 | if (clicxx . . $ cli..scaleFactorcxx . . $ CliOptions#scaleFactor. > 0) config.videoScalecxx . . $ SetupOptions#videoScale. = clicxx . . $ cli..scaleFactorcxx . . $ CliOptions#scaleFactor.; |
| 240 | if (clicxx . . $ cli..muteAudiocxx . . $ CliOptions#muteAudio.) { |
| 241 | |
| 242 | setMusicVolumecxx . . $ setMusicVolume(d4f767463ce0a6b3).(0); |
| 243 | setSoundVolumecxx . . $ setSoundVolume(d4f767463ce0a6b3).(0); |
| 244 | |
| 245 | } |
| 246 | |
| 247 | |
| 248 | // Create the game's window |
| 249 | canvascxx . . $ canvas. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 250 | if (!videocxx . . $ video..initcxx . . $ Video#init(63f3bea6ba3175f4).(config)) { |
| 251 | |
| 252 | throw E_VIDEOcxx . . $ `src/OpenJazz.h:61:9`!; |
| 253 | |
| 254 | } |
| 255 | |
| 256 | |
| 257 | controlscxx . . $ controls..initcxx . . $ Controls#init(49f6e7a06ebc5aa8).(); |
| 258 | |
| 259 | |
| 260 | // Set up audio |
| 261 | openAudiocxx . . $ openAudio(49f6e7a06ebc5aa8).(); |
| 262 | |
| 263 | |
| 264 | // Load fonts |
| 265 | |
| 266 | // Open the panel, which contains two fonts |
| 267 | |
| 268 | try { |
| 269 | |
| 270 | file = new Filecxx . . $ File#File(e99a0a23efd851c6).("PANEL.000", PATH_TYPE_GAMEcxx . . $ PATH_TYPE_GAME.); |
| 271 | |
| 272 | } catch (int e) { |
| 273 | |
| 274 | closeAudiocxx . . $ closeAudio(49f6e7a06ebc5aa8).(); |
| 275 | |
| 276 | LOG_FATALcxx . . $ `src/io/log.h:79:9`!("Unable to find game data files. When launching OpenJazz, \n" |
| 277 | " pass the location of the original game data, eg:\n" |
| 278 | " OpenJazz ~/jazz1"); |
| 279 | |
| 280 | platformcxx . . $ platform.->ErrorNoDatafilescxx . . $ IPlatform#ErrorNoDatafiles(49f6e7a06ebc5aa8).(); |
| 281 | |
| 282 | throw; |
| 283 | |
| 284 | } |
| 285 | |
| 286 | pixels = file->loadRLEcxx . . $ File#loadRLE(bf8b529691269f26).(46272); |
| 287 | |
| 288 | delete file; |
| 289 | |
| 290 | panelBigFontcxx . . $ panelBigFont. = nullptr; |
| 291 | panelSmallFontcxx . . $ panelSmallFont. = nullptr; |
| 292 | font2cxx . . $ font2. = nullptr; |
| 293 | fontbigcxx . . $ fontbig. = nullptr; |
| 294 | fontinycxx . . $ fontiny. = nullptr; |
| 295 | fontmn1cxx . . $ fontmn1. = nullptr; |
| 296 | |
| 297 | try { |
| 298 | |
| 299 | panelBigFontcxx . . $ panelBigFont. = new Fontcxx . . $ Font#Font(ff9db7b1d71f489c).(pixels + (40 * 320), true); |
| 300 | panelSmallFontcxx . . $ panelSmallFont. = new Fontcxx . . $ Font#Font(ff9db7b1d71f489c).(pixels + (48 * 320), false); |
| 301 | font2cxx . . $ font2. = new Fontcxx . . $ Font#Font(85c52e162fed56f9).("FONT2.0FN"); |
| 302 | fontbigcxx . . $ fontbig. = new Fontcxx . . $ Font#Font(85c52e162fed56f9).("FONTBIG.0FN"); |
| 303 | fontinycxx . . $ fontiny. = new Fontcxx . . $ Font#Font(85c52e162fed56f9).("FONTINY.0FN"); |
| 304 | fontmn1cxx . . $ fontmn1. = new Fontcxx . . $ Font#Font(85c52e162fed56f9).("FONTMN1.0FN"); |
| 305 | fontmn2cxx . . $ fontmn2. = new Fontcxx . . $ Font#Font(85c52e162fed56f9).("FONTMN2.0FN"); |
| 306 | |
| 307 | } catch (int e) { |
| 308 | |
| 309 | if (panelBigFontcxx . . $ panelBigFont.) delete panelBigFontcxx . . $ panelBigFont.; |
| 310 | if (panelSmallFontcxx . . $ panelSmallFont.) delete panelSmallFontcxx . . $ panelSmallFont.; |
| 311 | if (font2cxx . . $ font2.) delete font2cxx . . $ font2.; |
| 312 | if (fontbigcxx . . $ fontbig.) delete fontbigcxx . . $ fontbig.; |
| 313 | if (fontinycxx . . $ fontiny.) delete fontinycxx . . $ fontiny.; |
| 314 | if (fontmn1cxx . . $ fontmn1.) delete fontmn1cxx . . $ fontmn1.; |
| 315 | |
| 316 | delete[] pixels; |
| 317 | |
| 318 | closeAudiocxx . . $ closeAudio(49f6e7a06ebc5aa8).(); |
| 319 | |
| 320 | throw; |
| 321 | |
| 322 | } |
| 323 | #if DEBUG_FONTS |
| 324 | panelBigFont->saveAtlasAsBMP("panelbigfont.bmp"); |
| 325 | panelSmallFont->saveAtlasAsBMP("panelsmallfont.bmp"); |
| 326 | font2->saveAtlasAsBMP("font2.bmp"); |
| 327 | fontbig->saveAtlasAsBMP("fontbig.bmp"); |
| 328 | fontiny->saveAtlasAsBMP("fontiny.bmp"); |
| 329 | fontmn1->saveAtlasAsBMP("fontmn1.bmp"); |
| 330 | #endif |
| 331 | |
| 332 | delete[] pixels; |
| 333 | |
| 334 | // Establish arbitrary timing |
| 335 | globalTickscxx . . $ globalTicks. = SDL_GetTicks() - 20; |
| 336 | |
| 337 | |
| 338 | // Fill trigonometric function look-up tables |
| 339 | for (int i = 0; i < 1024; i++) |
| 340 | sinLutcxx . . $ sinLut.[i] = fixedcxx . . $ fixed#(sinf(2 * PIcxx . . $ `src/main.cpp:66:9`! * float(i) / 1024.0f) * 1024.0f); |
| 341 | |
| 342 | |
| 343 | // Initiate networking |
| 344 | netcxx . . $ net. = new Networkcxx . . $ Network#(); |
| 345 | |
| 346 | |
| 347 | levelcxx . . $ level. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 348 | |
| 349 | #ifdef ENABLE_JJ2 |
| 350 | jj2Level = NULL; |
| 351 | #endif |
| 352 | |
| 353 | } |
| 354 | |
| 355 | |
| 356 | /** |
| 357 | * De-initialises OpenJazz. |
| 358 | * |
| 359 | * Frees data, writes configuration, and shuts down SDL. |
| 360 | */ |
| 361 | void shutDowncxx . . $ shutDown(49f6e7a06ebc5aa8). () { |
| 362 | |
| 363 | delete netcxx . . $ net.; |
| 364 | |
| 365 | delete panelBigFontcxx . . $ panelBigFont.; |
| 366 | delete panelSmallFontcxx . . $ panelSmallFont.; |
| 367 | delete font2cxx . . $ font2.; |
| 368 | delete fontbigcxx . . $ fontbig.; |
| 369 | delete fontinycxx . . $ fontiny.; |
| 370 | delete fontmn1cxx . . $ fontmn1.; |
| 371 | delete fontmn2cxx . . $ fontmn2.; |
| 372 | |
| 373 | closeAudiocxx . . $ closeAudio(49f6e7a06ebc5aa8).(); |
| 374 | |
| 375 | controlscxx . . $ controls..deinitcxx . . $ Controls#deinit(49f6e7a06ebc5aa8).(); |
| 376 | |
| 377 | videocxx . . $ video..deinitcxx . . $ Video#deinit(49f6e7a06ebc5aa8).(); |
| 378 | |
| 379 | // Save settings to config file |
| 380 | setupcxx . . $ setup..savecxx . . $ Setup#save(49f6e7a06ebc5aa8).(); |
| 381 | |
| 382 | } |
| 383 | |
| 384 | |
| 385 | /** |
| 386 | * Run the cutscenes and the main menu. |
| 387 | * |
| 388 | * @return Error code |
| 389 | */ |
| 390 | int playcxx . . $ play(b126dc7c1de90089). () { |
| 391 | |
| 392 | MainMenucxx . . $ MainMenu# *mainMenu = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 393 | JJ1Scenecxx . . $ JJ1Scene# *scene = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 394 | |
| 395 | // Start the opening music |
| 396 | |
| 397 | playMusiccxx . . $ playMusic(90ef5b561fbcb8de).("MENUSNG.PSM"); |
| 398 | |
| 399 | // Try loading the user-specified level |
| 400 | |
| 401 | if (clicxx . . $ cli..levelcxx . . $ CliOptions#level. > -1 && clicxx . . $ cli..worldcxx . . $ CliOptions#world. > -1) { |
| 402 | |
| 403 | try { |
| 404 | |
| 405 | mainMenu = new MainMenucxx . . $ MainMenu#(); |
| 406 | |
| 407 | } catch (int e) { |
| 408 | |
| 409 | return e; |
| 410 | |
| 411 | } |
| 412 | |
| 413 | if (mainMenu->skipcxx . . $ MainMenu#skip(9b79fb6aee4c0440).(clicxx . . $ cli..levelcxx . . $ CliOptions#level., clicxx . . $ cli..worldcxx . . $ CliOptions#world.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) { |
| 414 | |
| 415 | delete mainMenu; |
| 416 | |
| 417 | } |
| 418 | |
| 419 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 420 | |
| 421 | } |
| 422 | |
| 423 | |
| 424 | // Load and play the startup cutscene |
| 425 | |
| 426 | try { |
| 427 | |
| 428 | scene = new JJ1Scenecxx . . $ JJ1Scene#("STARTUP.0SC"); |
| 429 | |
| 430 | } catch (int e) { |
| 431 | |
| 432 | return e; |
| 433 | |
| 434 | } |
| 435 | |
| 436 | if (scene->playcxx . . $ JJ1Scene#play(b126dc7c1de90089).() == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) { |
| 437 | |
| 438 | delete scene; |
| 439 | |
| 440 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 441 | |
| 442 | } |
| 443 | |
| 444 | delete scene; |
| 445 | |
| 446 | |
| 447 | // Load and run the menu |
| 448 | |
| 449 | try { |
| 450 | |
| 451 | mainMenu = new MainMenucxx . . $ MainMenu#(); |
| 452 | |
| 453 | } catch (int e) { |
| 454 | |
| 455 | return e; |
| 456 | |
| 457 | } |
| 458 | |
| 459 | if (mainMenu->maincxx . . $ MainMenu#main(b126dc7c1de90089).() == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) { |
| 460 | |
| 461 | delete mainMenu; |
| 462 | |
| 463 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 464 | |
| 465 | } |
| 466 | |
| 467 | delete mainMenu; |
| 468 | |
| 469 | |
| 470 | // Load and play the ending cutscene |
| 471 | |
| 472 | try { |
| 473 | |
| 474 | scene = new JJ1Scenecxx . . $ JJ1Scene#("END.0SC"); |
| 475 | |
| 476 | } catch (int e) { |
| 477 | |
| 478 | return e; |
| 479 | |
| 480 | } |
| 481 | |
| 482 | scene->playcxx . . $ JJ1Scene#play(b126dc7c1de90089).(); |
| 483 | |
| 484 | delete scene; |
| 485 | |
| 486 | |
| 487 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 488 | |
| 489 | } |
| 490 | |
| 491 | |
| 492 | /** |
| 493 | * Process iteration. |
| 494 | * |
| 495 | * Called once per game iteration. Updates timing, video, and input |
| 496 | * |
| 497 | * @param type Type of loop. Normal, typing, or input configuration |
| 498 | * @param paletteEffects Palette effects to apply to video output |
| 499 | * @param effectsStopped Whether the effects should be applied without advancing |
| 500 | * |
| 501 | * @return Error code |
| 502 | */ |
| 503 | int loopcxx . . $ loop(fd873fd06cfe1135). (LoopTypecxx . . $ LoopType# type, PaletteEffectcxx . . $ PaletteEffect#* paletteEffects, bool effectsStopped) { |
| 504 | |
| 505 | SDL_Event event; |
| 506 | int prevTicks, ret; |
| 507 | |
| 508 | |
| 509 | // Update tick count |
| 510 | prevTicks = globalTickscxx . . $ globalTicks.; |
| 511 | globalTickscxx . . $ globalTicks. = SDL_GetTicks(); |
| 512 | |
| 513 | if (globalTickscxx . . $ globalTicks. - prevTicks < 4) { |
| 514 | |
| 515 | // Limit framerate |
| 516 | SDL_Delay(4 + prevTicks - globalTickscxx . . $ globalTicks.); |
| 517 | globalTickscxx . . $ globalTicks. = SDL_GetTicks(); |
| 518 | |
| 519 | } |
| 520 | |
| 521 | // Show what has been drawn |
| 522 | videocxx . . $ video..flipcxx . . $ Video#flip(b4cc491d773144d4).(globalTickscxx . . $ globalTicks. - prevTicks, paletteEffects, effectsStopped); |
| 523 | |
| 524 | |
| 525 | // Process system events |
| 526 | while (SDL_PollEvent(&event)) { |
| 527 | |
| 528 | if (event.typecxx . . $ SDL_Event#type. == SDL_EVENT_QUITcxx . . $ `src/main.cpp:59:10`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 529 | |
| 530 | ret = controlscxx . . $ controls..updatecxx . . $ Controls#update(db42b6765f9e21b0).(&event, type); |
| 531 | |
| 532 | if (ret != E_NONEcxx . . $ `src/OpenJazz.h:69:9`!) return ret; |
| 533 | |
| 534 | videocxx . . $ video..updatecxx . . $ Video#update(568d8a17e3151145).(&event); |
| 535 | |
| 536 | #if defined(WIZ) || defined(GP2X) |
| 537 | if ((event.type == SDL_JOYBUTTONDOWN) || |
| 538 | (event.type == SDL_JOYBUTTONUP)) { |
| 539 | |
| 540 | if (event.jbutton.button == GP2X_BUTTON_VOLUP ) { |
| 541 | if( event.type == SDL_JOYBUTTONDOWN ) |
| 542 | volume_direction = VOLUME_UP; |
| 543 | else |
| 544 | volume_direction = VOLUME_NOCHG; |
| 545 | } |
| 546 | if (event.jbutton.button == GP2X_BUTTON_VOLDOWN ) { |
| 547 | if( event.type == SDL_JOYBUTTONDOWN ) |
| 548 | volume_direction = VOLUME_DOWN; |
| 549 | else |
| 550 | volume_direction = VOLUME_NOCHG; |
| 551 | } |
| 552 | |
| 553 | } |
| 554 | #endif |
| 555 | |
| 556 | } |
| 557 | |
| 558 | controlscxx . . $ controls..loopcxx . . $ Controls#loop(49f6e7a06ebc5aa8).(); |
| 559 | |
| 560 | if (platformcxx . . $ platform.->WantsExitcxx . . $ IPlatform#WantsExit(c9857a73d68e59ba).()) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 561 | |
| 562 | #if defined(WIZ) || defined(GP2X) |
| 563 | WIZ_AdjustVolume( volume_direction ); |
| 564 | #endif |
| 565 | |
| 566 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 567 | |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Shows version information of used SDL library. |
| 572 | * |
| 573 | */ |
| 574 | void logSDLVersioncxx . . $ logSDLVersion(49f6e7a06ebc5aa8).() { |
| 575 | #if OJ_SDL3 |
| 576 | // define a compatible struct |
| 577 | struct SDL_version { Uint8 major; Uint8 minor; Uint8 patch; }; |
| 578 | |
| 579 | const int compiledVer = SDL_VERSION; |
| 580 | const int linkedVer = SDL_GetVersion(); |
| 581 | |
| 582 | struct SDL_version compiled = { SDL_VERSIONNUM_MAJOR(compiledVer), |
| 583 | SDL_VERSIONNUM_MINOR(compiledVer), SDL_VERSIONNUM_MICRO(compiledVer) }; |
| 584 | struct SDL_version linked = { SDL_VERSIONNUM_MAJOR(linkedVer), |
| 585 | SDL_VERSIONNUM_MINOR(linkedVer), SDL_VERSIONNUM_MICRO(linkedVer) }; |
| 586 | #elif OJ_SDL2cxx . . $ `<built-in>:465:9`! |
| 587 | SDL_version compiled, linked; |
| 588 | |
| 589 | SDL_VERSIONcxx . . $ `<external>/11196385350576350796/SDL_version.h:77:9`!(&compiled); |
| 590 | SDL_GetVersion(&linked); |
| 591 | #else |
| 592 | SDL_version compiled, linked; |
| 593 | |
| 594 | SDL_VERSION(&compiled); |
| 595 | |
| 596 | const SDL_version* linkedVer = SDL_Linked_Version(); |
| 597 | linked.major = linkedVer->major; |
| 598 | linked.minor = linkedVer->minor; |
| 599 | linked.patch = linkedVer->patch; |
| 600 | #endif |
| 601 | |
| 602 | LOG_DEBUGcxx . . $ `src/io/log.h:75:9`!("built with SDL %d.%d.%d (running with SDL %d.%d.%d)", |
| 603 | compiled.major, compiled.minor, compiled.patch, |
| 604 | linked.major, linked.minor, linked.patch); |
| 605 | } |
| 606 | |
| 607 | |
| 608 | /** |
| 609 | * Main. |
| 610 | * |
| 611 | * Initialises SDL and launches game. |
| 612 | */ |
| 613 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) { |
| 614 | |
| 615 | int ret; |
| 616 | const char *argv0 = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 617 | |
| 618 | // Initialize platform interface |
| 619 | platformcxx . . $ platform. = IPlatformcxx . . $ IPlatform#::makecxx . . $ IPlatform#make(764857a803c45864).(); |
| 620 | |
| 621 | // Some platforms (and emulators) do not provide arguments |
| 622 | |
| 623 | if (argc) { |
| 624 | |
| 625 | // Save program path |
| 626 | argv0 = argv[0]; |
| 627 | |
| 628 | // Check command line options |
| 629 | argc = checkOptionscxx . . $ checkOptions(afcd3168fc1188a4).(argc, argv); |
| 630 | |
| 631 | } |
| 632 | |
| 633 | // Log current version |
| 634 | LOG_INFOcxx . . $ `src/io/log.h:76:9`!("This is OpenJazz %s, built on %s.", oj_version, oj_date); |
| 635 | |
| 636 | // Initialise SDL |
| 637 | |
| 638 | bool sdlOk = false; |
| 639 | #if OJ_SDL3 |
| 640 | sdlOk = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK); |
| 641 | #else |
| 642 | sdlOk = SDL_Init(SDL_INIT_VIDEOcxx . . $ `<external>/13597568925221565411/SDL.h:85:9`! | SDL_INIT_AUDIOcxx . . $ `<external>/13597568925221565411/SDL.h:84:9`! | SDL_INIT_TIMERcxx . . $ `<external>/13597568925221565411/SDL.h:83:9`! | SDL_INIT_JOYSTICKcxx . . $ `<external>/13597568925221565411/SDL.h:86:9`!) == 0; |
| 643 | #endif |
| 644 | if (!sdlOk) { |
| 645 | LOG_FATALcxx . . $ `src/io/log.h:79:9`!("Could not start SDL: %s\n", SDL_GetError()); |
| 646 | |
| 647 | return -1; |
| 648 | } |
| 649 | logSDLVersioncxx . . $ logSDLVersion(49f6e7a06ebc5aa8).(); |
| 650 | |
| 651 | // Load configuration and establish a window |
| 652 | |
| 653 | try { |
| 654 | |
| 655 | startUpcxx . . $ startUp(9f647276e7804368).(argv0, argc, argv); |
| 656 | |
| 657 | } catch (int e) { |
| 658 | |
| 659 | SDL_Quit(); |
| 660 | |
| 661 | return -1; |
| 662 | |
| 663 | } |
| 664 | |
| 665 | |
| 666 | // Play the opening cutscene, run the main menu, etc. |
| 667 | |
| 668 | ret = playcxx . . $ play(b126dc7c1de90089).(); |
| 669 | |
| 670 | |
| 671 | // Save configuration and shut down |
| 672 | |
| 673 | LOG_DEBUGcxx . . $ `src/io/log.h:75:9`!("Shutting down engine."); |
| 674 | |
| 675 | shutDowncxx . . $ shutDown(49f6e7a06ebc5aa8).(); |
| 676 | |
| 677 | delete platformcxx . . $ platform.; |
| 678 | |
| 679 | SDL_Quit(); |
| 680 | |
| 681 | return ret; |
| 682 | |
| 683 | } |