64 #include "newgrf_house.h" |
63 #include "newgrf_house.h" |
65 #include "newgrf_commons.h" |
64 #include "newgrf_commons.h" |
66 #include "player_face.h" |
65 #include "player_face.h" |
67 #include "group.h" |
66 #include "group.h" |
68 #include "blitter/factory.hpp" |
67 #include "blitter/factory.hpp" |
|
68 #include "sound/sound_driver.hpp" |
|
69 #include "music/music_driver.hpp" |
|
70 #include "video/video_driver.hpp" |
69 |
71 |
70 #include "bridge_map.h" |
72 #include "bridge_map.h" |
71 #include "clear_map.h" |
73 #include "clear_map.h" |
72 #include "rail_map.h" |
74 #include "rail_map.h" |
73 #include "road_map.h" |
75 #include "road_map.h" |
186 " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n" |
188 " -c config_file = Use 'config_file' instead of 'openttd.cfg'\n" |
187 " -x = Do not automatically save to config file on exit\n\n", |
189 " -x = Do not automatically save to config file on exit\n\n", |
188 lastof(buf) |
190 lastof(buf) |
189 ); |
191 ); |
190 |
192 |
191 p = GetDriverList(p, lastof(buf)); |
193 /* List the drivers */ |
|
194 p = VideoDriverFactoryBase::GetDriversInfo(p, lastof(buf)); |
192 |
195 |
193 /* List the blitters */ |
196 /* List the blitters */ |
194 p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf)); |
197 p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf)); |
195 |
198 |
196 /* We need to initialize the AI, so it finds the AIs */ |
199 /* We need to initialize the AI, so it finds the AIs */ |
345 _scrolling_viewport = 0; |
350 _scrolling_viewport = 0; |
346 _cursor.fix_at = false; |
351 _cursor.fix_at = false; |
347 MarkWholeScreenDirty(); |
352 MarkWholeScreenDirty(); |
348 |
353 |
349 /* Play main theme */ |
354 /* Play main theme */ |
350 if (_music_driver->is_song_playing()) ResetMusic(); |
355 if (_music_driver->IsSongPlaying()) ResetMusic(); |
351 } |
356 } |
352 |
357 |
353 #if defined(UNIX) && !defined(__MORPHOS__) |
358 #if defined(UNIX) && !defined(__MORPHOS__) |
354 extern void DedicatedFork(); |
359 extern void DedicatedFork(); |
355 #endif |
360 #endif |
519 GfxInitPalettes(); |
524 GfxInitPalettes(); |
520 |
525 |
521 DEBUG(misc, 1, "Loading blitter '%s'...", blitter); |
526 DEBUG(misc, 1, "Loading blitter '%s'...", blitter); |
522 if (BlitterFactoryBase::SelectBlitter(blitter) == NULL) |
527 if (BlitterFactoryBase::SelectBlitter(blitter) == NULL) |
523 error("Failed to select requested blitter '%s'; does it exist?", blitter); |
528 error("Failed to select requested blitter '%s'; does it exist?", blitter); |
|
529 |
524 DEBUG(driver, 1, "Loading drivers..."); |
530 DEBUG(driver, 1, "Loading drivers..."); |
525 LoadDriver(SOUND_DRIVER, _ini_sounddriver); |
531 |
526 LoadDriver(MUSIC_DRIVER, _ini_musicdriver); |
532 _sound_driver = (SoundDriver*)SoundDriverFactoryBase::SelectDriver(_ini_sounddriver, Driver::DT_SOUND); |
527 LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads |
533 if (_sound_driver == NULL) { |
|
534 StrEmpty(_ini_sounddriver) ? |
|
535 error("Failed to autoprobe sound driver") : |
|
536 error("Failed to select requested sound driver '%s'", _ini_sounddriver); |
|
537 } |
|
538 |
|
539 _music_driver = (MusicDriver*)MusicDriverFactoryBase::SelectDriver(_ini_musicdriver, Driver::DT_MUSIC); |
|
540 if (_music_driver == NULL) { |
|
541 StrEmpty(_ini_musicdriver) ? |
|
542 error("Failed to autoprobe music driver") : |
|
543 error("Failed to select requested music driver '%s'", _ini_musicdriver); |
|
544 } |
|
545 |
|
546 _video_driver = (VideoDriver*)VideoDriverFactoryBase::SelectDriver(_ini_videodriver, Driver::DT_VIDEO); |
|
547 if (_video_driver == NULL) { |
|
548 StrEmpty(_ini_videodriver) ? |
|
549 error("Failed to autoprobe video driver") : |
|
550 error("Failed to select requested video driver '%s'", _ini_videodriver); |
|
551 } |
|
552 |
528 _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING; |
553 _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING; |
529 /* Initialize the zoom level of the screen to normal */ |
554 /* Initialize the zoom level of the screen to normal */ |
530 _screen.zoom = ZOOM_LVL_NORMAL; |
555 _screen.zoom = ZOOM_LVL_NORMAL; |
531 |
556 |
532 /* restore saved music volume */ |
557 /* restore saved music volume */ |
533 _music_driver->set_volume(msf.music_vol); |
558 _music_driver->SetVolume(msf.music_vol); |
534 |
559 |
535 NetworkStartUp(); // initialize network-core |
560 NetworkStartUp(); // initialize network-core |
536 |
561 |
537 #if defined(ENABLE_NETWORK) |
562 #if defined(ENABLE_NETWORK) |
538 if (debuglog_conn != NULL && _network_available) { |
563 if (debuglog_conn != NULL && _network_available) { |
599 NetworkClientConnectGame(network_conn, rport); |
624 NetworkClientConnectGame(network_conn, rport); |
600 } |
625 } |
601 } |
626 } |
602 #endif /* ENABLE_NETWORK */ |
627 #endif /* ENABLE_NETWORK */ |
603 |
628 |
604 _video_driver->main_loop(); |
629 _video_driver->MainLoop(); |
605 |
630 |
606 WaitTillSaved(); |
631 WaitTillSaved(); |
607 IConsoleFree(); |
632 IConsoleFree(); |
608 |
633 |
609 if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections |
634 if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections |
610 |
635 |
611 _video_driver->stop(); |
636 _video_driver->Stop(); |
612 _music_driver->stop(); |
637 _music_driver->Stop(); |
613 _sound_driver->stop(); |
638 _sound_driver->Stop(); |
614 |
639 |
615 /* only save config if we have to */ |
640 /* only save config if we have to */ |
616 if (save_config) { |
641 if (save_config) { |
617 SaveToConfig(); |
642 SaveToConfig(); |
618 SaveToHighScore(); |
643 SaveToHighScore(); |
711 { |
736 { |
712 _game_mode = GM_NORMAL; |
737 _game_mode = GM_NORMAL; |
713 |
738 |
714 ResetGRFConfig(true); |
739 ResetGRFConfig(true); |
715 _house_mngr.ResetMapping(); |
740 _house_mngr.ResetMapping(); |
|
741 _industile_mngr.ResetMapping(); |
|
742 _industry_mngr.ResetMapping(); |
716 |
743 |
717 GenerateWorldSetCallback(&MakeNewGameDone); |
744 GenerateWorldSetCallback(&MakeNewGameDone); |
718 GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y); |
745 GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _patches.map_x, 1 << _patches.map_y); |
719 } |
746 } |
720 |
747 |
945 if (_switch_mode_errorstr != INVALID_STRING_ID) { |
972 if (_switch_mode_errorstr != INVALID_STRING_ID) { |
946 ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0); |
973 ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0); |
947 } |
974 } |
948 } |
975 } |
949 |
976 |
950 #include "cargopacket.h" |
|
951 void CheckCargoPacketLeaks() |
|
952 { |
|
953 CargoPacket *cp; |
|
954 FOR_ALL_CARGOPACKETS(cp) cp->touched = false; |
|
955 |
|
956 Vehicle *v; |
|
957 FOR_ALL_VEHICLES(v) { |
|
958 const CargoList::List *packets = v->cargo.Packets(); |
|
959 for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) (*it)->touched = true; |
|
960 } |
|
961 |
|
962 Station *st; |
|
963 FOR_ALL_STATIONS(st) { |
|
964 for (CargoID c = 0; c < NUM_CARGO; c++) { |
|
965 GoodsEntry *ge = &st->goods[c]; |
|
966 |
|
967 const CargoList::List *packets = ge->cargo.Packets(); |
|
968 for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) (*it)->touched = true; |
|
969 } |
|
970 } |
|
971 |
|
972 FOR_ALL_CARGOPACKETS(cp) assert(cp->touched); |
|
973 } |
|
974 |
|
975 |
977 |
976 /* State controlling game loop. |
978 /* State controlling game loop. |
977 * The state must not be changed from anywhere |
979 * The state must not be changed from anywhere |
978 * but here. |
980 * but here. |
979 * That check is enforced in DoCommand. */ |
981 * That check is enforced in DoCommand. */ |