* Handle all procedures for bootstrapping OpenTTD without a base graphics set. * This requires all kinds of trickery that is needed to avoid the use of * sprites from the base graphics set which are pretty interwoven. * @return True if a base set exists, otherwise false. */
| 361 | * @return True if a base set exists, otherwise false. |
| 362 | */ |
| 363 | bool HandleBootstrap() |
| 364 | { |
| 365 | if (BaseGraphics::GetUsedSet() != nullptr) return true; |
| 366 | |
| 367 | /* No user interface, bail out with an error. */ |
| 368 | if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure; |
| 369 | |
| 370 | /* If there is no network or no non-sprite font, then there is nothing we can do. Go straight to failure. */ |
| 371 | #if defined(__EMSCRIPTEN__) || (defined(_WIN32) && defined(WITH_UNISCRIBE)) || (defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(__APPLE__))) || defined(WITH_COCOA) |
| 372 | if (!_network_available) goto failure; |
| 373 | |
| 374 | /* First tell the game we're bootstrapping. */ |
| 375 | _game_mode = GM_BOOTSTRAP; |
| 376 | |
| 377 | #if defined(__EMSCRIPTEN__) |
| 378 | new BootstrapEmscripten(); |
| 379 | #else |
| 380 | /* Initialise the font cache. */ |
| 381 | InitializeUnicodeGlyphMap(); |
| 382 | /* Next "force" finding a suitable non-sprite font as the local font is missing. */ |
| 383 | CheckForMissingGlyphs(); |
| 384 | |
| 385 | /* Initialise the palette. The biggest step is 'faking' some recolour sprites. |
| 386 | * This way the mauve and gray colours work and we can show the user interface. */ |
| 387 | GfxInitPalettes(); |
| 388 | static const uint8_t offsets[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0, 0, 0, 0x04, 0x08 }; |
| 389 | for (Colours i = COLOUR_BEGIN; i != COLOUR_END; i++) { |
| 390 | for (ColourShade j = SHADE_BEGIN; j < SHADE_END; j++) { |
| 391 | SetColourGradient(i, j, PixelColour(offsets[i] + j)); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /* Finally ask the question. */ |
| 396 | new BootstrapBackground(); |
| 397 | new BootstrapAskForDownloadWindow(); |
| 398 | #endif /* __EMSCRIPTEN__ */ |
| 399 | |
| 400 | /* Process the user events. */ |
| 401 | VideoDriver::GetInstance()->MainLoop(); |
| 402 | |
| 403 | /* _exit_game is used to get out of the video driver's main loop. |
| 404 | * In case GM_BOOTSTRAP is still set we did not exit it via the |
| 405 | * "download complete" event, so it was a manual exit. Obey it. */ |
| 406 | _exit_game = _game_mode == GM_BOOTSTRAP; |
| 407 | if (_exit_game) return false; |
| 408 | |
| 409 | /* Try to probe the graphics. Should work this time. */ |
| 410 | if (!BaseGraphics::SetSet(nullptr)) goto failure; |
| 411 | |
| 412 | /* Finally we can continue heading for the menu. */ |
| 413 | _game_mode = GM_MENU; |
| 414 | return true; |
| 415 | #endif |
| 416 | |
| 417 | /* Failure to get enough working to get a graphics set. */ |
| 418 | failure: |
| 419 | UserError("Failed to find a graphics set. Please acquire a graphics set for OpenTTD. See section 1.4 of README.md."); |
| 420 | return false; |
no test coverage detected