75int main(
int argc,
char *argv[])
80 curl_global_init(CURL_GLOBAL_ALL);
89 App::GetConsole()->cVarSetupBuiltins();
92 App::GetAppContext()->SetUpThreads();
95 if (!App::GetAppContext()->SetUpProgramPaths())
101 App::GetAppContext()->SetUpLogging();
104 App::sys_config_dir ->setStr(PathCombine(App::sys_user_dir->getStr(),
"config"));
105 App::sys_cache_dir ->setStr(PathCombine(App::sys_user_dir->getStr(),
"cache"));
106 App::sys_thumbnails_dir->setStr(PathCombine(App::sys_user_dir->getStr(),
"thumbnails"));
107 App::sys_savegames_dir ->setStr(PathCombine(App::sys_user_dir->getStr(),
"savegames"));
108 App::sys_screenshot_dir->setStr(PathCombine(App::sys_user_dir->getStr(),
"screenshots"));
109 App::sys_scripts_dir ->setStr(PathCombine(App::sys_user_dir->getStr(),
"scripts"));
110 App::sys_server_scripts_dir->setStr(PathCombine(App::sys_user_dir->getStr(),
"server_scripts"));
111 App::sys_projects_dir ->setStr(PathCombine(App::sys_user_dir->getStr(),
"projects"));
112 App::sys_repo_attachments_dir->setStr(PathCombine(App::sys_user_dir->getStr(),
"repo_attachments"));
115 App::GetConsole()->loadConfig();
118 App::GetConsole()->processCommandLine(argc, argv);
120 if (App::app_state->getEnum<AppState>() == AppState::PRINT_HELP_EXIT)
122 App::GetConsole()->showCommandLineUsage();
125 if (App::app_state->getEnum<AppState>() == AppState::PRINT_VERSION_EXIT)
127 App::GetConsole()->showCommandLineVersion();
132 if (!App::GetAppContext()->SetUpResourcesDir())
138 CreateFolder(App::sys_config_dir->getStr());
141 if (!App::GetAppContext()->SetUpRendering())
146 Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
149 if (!App::GetAppContext()->SetUpConfigSkeleton())
154 Ogre::OverlaySystem* overlay_system =
new Ogre::OverlaySystem();
156 Ogre::ConfigOptionMap ropts = App::GetAppContext()->GetOgreRoot()->getRenderSystem()->getConfigOptions();
157 int resolution = Ogre::StringConverter::parseInt(Ogre::StringUtil::split(ropts[
"Video Mode"].currentValue,
" x ")[0], 1024);
158 int fsaa = 2 * (Ogre::StringConverter::parseInt(ropts[
"FSAA"].currentValue, 0) / 4);
159 int res = std::pow(2, std::floor(std::log2(resolution)));
161 Ogre::TextureManager::getSingleton().createManual (
"EnvironmentTexture",
162 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_CUBE_MAP, res / 4, res / 4, 0,
163 Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET, 0,
false, fsaa);
164 Ogre::TextureManager::getSingleton ().createManual (
"Refraction",
165 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, res / 2, res / 2, 0,
166 Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET, 0,
false, fsaa);
167 Ogre::TextureManager::getSingleton ().createManual (
"Reflection",
168 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, res / 2, res / 2, 0,
169 Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET, 0,
false, fsaa);
171 if (!App::diag_warning_texture->getBool())
174 Ogre::uchar data[3] = {0};
175 Ogre::PixelBox pixels(1, 1, 1, Ogre::PF_BYTE_RGB, &data);
176 Ogre::TextureManager::getSingleton()._getWarningTexture()->getBuffer()->blitFromMemory(pixels);
179 App::GetContentManager()->AddResourcePack(ContentManager::ResourcePack::FLAGS);
180 App::GetContentManager()->AddResourcePack(ContentManager::ResourcePack::FONTS);
181 App::GetContentManager()->AddResourcePack(ContentManager::ResourcePack::ICONS);
182 App::GetContentManager()->AddResourcePack(ContentManager::ResourcePack::OGRE_CORE);
183 App::GetContentManager()->AddResourcePack(ContentManager::ResourcePack::WALLPAPERS);
184 App::GetContentManager()->AddResourcePack(ContentManager::ResourcePack::SCRIPTS);
187 App::GetLanguageEngine()->setup();
189 App::GetConsole()->regBuiltinCommands();
191 App::GetContentManager()->InitContentManager();
194 App::CreateGfxScene();
195 App::GetGfxScene()->GetSceneManager()->addRenderQueueListener(overlay_system);
196 App::CreateCameraManager();
197 App::GetGfxScene()->GetEnvMap().SetupEnvMap();
199 App::CreateGuiManager();
201 App::GetDiscordRpc()->Init();
203 App::GetAppContext()->SetUpInput();
205#ifdef USE_ANGELSCRIPT
206 CreateFolder(App::sys_scripts_dir->getStr());
207 App::CreateScriptEngine();
208 CreateFolder(App::sys_server_scripts_dir->getStr());
209 App::CreateServerScript();
210 CreateFolder(App::sys_projects_dir->getStr());
213 App::GetGuiManager()->SetUpMenuWallpaper();
216 App::GetAppContext()->SetUpObsoleteConfMarker();
218 App::CreateThreadPool();
221 App::GetGameContext()->GetActorManager()->GetInertiaConfig().LoadDefaultInertiaModels();
224 if (App::app_force_cache_purge->getBool())
226 App::GetGameContext()->PushMessage(
Message(MSG_APP_MODCACHE_PURGE_REQUESTED));
228 else if (App::cli_force_cache_update->getBool() || App::app_force_cache_update->getBool())
230 App::GetGameContext()->PushMessage(
Message(MSG_APP_MODCACHE_UPDATE_REQUESTED));
234 App::GetGameContext()->PushMessage(
Message(MSG_APP_MODCACHE_LOAD_REQUESTED));
238 if (App::cli_custom_scripts->getStr() !=
"")
240 Ogre::StringVector script_names = Ogre::StringUtil::split(App::cli_custom_scripts->getStr(),
",");
241 for (Ogre::String
const& scriptname: script_names)
243 LOG(fmt::format(
"Loading startup script '{}' (from command line)", scriptname));
248 App::GetGameContext()->PushMessage(
Message(MSG_APP_LOAD_SCRIPT_REQUESTED, req));
252 if (App::app_custom_scripts->getStr() !=
"")
254 Ogre::StringVector script_names = Ogre::StringUtil::split(App::app_custom_scripts->getStr(),
",");
255 for (Ogre::String
const& scriptname: script_names)
257 LOG(fmt::format(
"Loading startup script '{}' (from config file)", scriptname));
262 App::GetGameContext()->PushMessage(
Message(MSG_APP_LOAD_SCRIPT_REQUESTED, req));
268 if (App::cli_server_host->getStr() !=
"" && App::cli_server_port->getInt() != 0)
270 App::mp_server_host->setStr(App::cli_server_host->getStr());
271 App::mp_server_port->setVal(App::cli_server_port->getInt());
272 App::GetGameContext()->PushMessage(
Message(MSG_NET_CONNECT_REQUESTED));
274 else if (App::mp_join_on_startup->getBool())
276 App::GetGameContext()->PushMessage(
Message(MSG_NET_CONNECT_REQUESTED));
280 if (App::cli_preset_terrain->getStr() !=
"")
282 App::GetGameContext()->PushMessage(
Message(MSG_SIM_LOAD_TERRN_REQUESTED, App::cli_preset_terrain->getStr()));
284 else if (App::diag_preset_terrain->getStr() !=
"")
286 App::GetGameContext()->PushMessage(
Message(MSG_SIM_LOAD_TERRN_REQUESTED, App::diag_preset_terrain->getStr()));
290 if (App::cli_resume_autosave->getBool())
292 if (FileExists(PathCombine(App::sys_savegames_dir->getStr(),
"autosave.sav")))
294 App::GetGameContext()->PushMessage(
RoR::Message(MSG_SIM_LOAD_SAVEGAME_REQUESTED,
"autosave.sav"));
297 else if (App::app_skip_main_menu->getBool())
302 App::GetGameContext()->PushMessage(m);
306 App::GetGameContext()->PushMessage(
Message(MSG_GUI_OPEN_MENU_REQUESTED));
311 App::app_state->setVal((
int)AppState::MAIN_MENU);
312 App::GetGuiManager()->MenuWallpaper->show();
315 if (App::audio_menu_music->getBool())
317 App::GetSoundScriptManager()->createInstance(
"tracks/main_menu_tune", -1);
324 App::GetGuiManager()->LoadingWindow.SetProgress(100,
"Hack",
true);
325 App::GetGuiManager()->LoadingWindow.SetVisible(
false);
331 auto start_time = std::chrono::high_resolution_clock::now();
333 while (App::app_state->getEnum<AppState>() != AppState::SHUTDOWN)
335 App::GetAppContext()->PrepareProfiler();
336 OgreBites::WindowEventUtilities::messagePump();
339 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
341 App::GetGameContext()->GetActorManager()->SyncWithSimThread();
345 OgreProfileBegin(
"RoR message queue");
346 while (App::GetGameContext()->HasMessages())
348 Message m = App::GetGameContext()->PopMessage();
349 bool failed_m =
false;
355 case MSG_APP_SHUTDOWN_REQUESTED:
359 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
361 App::GetGameContext()->SaveScene(
"autosave.sav");
363 App::GetConsole()->saveConfig();
364 App::GetDiscordRpc()->Shutdown();
366 if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED)
368 App::GetNetwork()->Disconnect();
371 App::app_state->setVal((
int)AppState::SHUTDOWN);
372 App::GetScriptEngine()->setEventsEnabled(
false);
376 HandleMsgQueueException(m.
type);
381 case MSG_APP_SCREENSHOT_REQUESTED:
385 App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::HIDDEN);
386 App::GetAppContext()->CaptureScreenshot();
387 App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::VISIBLE);
391 HandleMsgQueueException(m.
type);
396 case MSG_APP_DISPLAY_FULLSCREEN_REQUESTED:
400 App::GetAppContext()->ActivateFullscreen(
true);
401 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
402 _L(
"Display mode changed to fullscreen"));
406 HandleMsgQueueException(m.
type);
411 case MSG_APP_DISPLAY_WINDOWED_REQUESTED:
415 App::GetAppContext()->ActivateFullscreen(
false);
416 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
417 _L(
"Display mode changed to windowed"));
421 HandleMsgQueueException(m.
type);
426 case MSG_APP_MODCACHE_LOAD_REQUESTED:
430 if (!App::GetCacheSystem()->IsModCacheLoaded())
432 App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::HIDDEN);
433 App::GetContentManager()->InitModCache(CacheValidity::UNKNOWN);
438 HandleMsgQueueException(m.
type);
443 case MSG_APP_MODCACHE_UPDATE_REQUESTED:
447 if (App::app_state->getEnum<AppState>() == AppState::MAIN_MENU)
449 RoR::Log(
"[RoR|ModCache] Cache update requested");
450 App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::HIDDEN);
451 App::GetContentManager()->InitModCache(CacheValidity::NEEDS_UPDATE);
456 HandleMsgQueueException(m.
type);
461 case MSG_APP_MODCACHE_PURGE_REQUESTED:
465 if (App::app_state->getEnum<AppState>() == AppState::MAIN_MENU)
467 RoR::Log(
"[RoR|ModCache] Cache rebuild requested");
468 App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::HIDDEN);
469 App::GetContentManager()->InitModCache(CacheValidity::NEEDS_REBUILD);
474 HandleMsgQueueException(m.
type);
479 case MSG_APP_LOAD_SCRIPT_REQUESTED:
489 ROR_ASSERT(App::mp_state->getEnum<MpState>() == MpState::LOCAL_SCRIPT &&
"AI_BOT scripts can only be loaded under 'mp_state = LOCAL_SCRIPT (3)'.");
491 std::memset(&u, 0,
sizeof(u));
499 App::GetServerScript()->createClient(u);
502 App::GetNetwork()->AddBotUserInfo(u);
503 App::GetGuiManager()->MpClientList.UpdateClients();
507 if (nid == SCRIPTUNITID_INVALID && request->
lsr_category == ScriptCategory::AI_BOT)
510 App::GetServerScript()->queueMessageUserLeave(netuid);
511 App::GetNetwork()->RemoveBotUserInfo(netuid);
512 App::GetGuiManager()->MpClientList.UpdateClients();
517 HandleMsgQueueException(m.
type);
523 case MSG_APP_UNLOAD_SCRIPT_REQUESTED:
528 ScriptCategory cat = App::GetScriptEngine()->getScriptUnit(*id).scriptCategory;
529 int32_t netuid = App::GetScriptEngine()->getScriptUnit(*id).associatedNetUid;
531 App::GetScriptEngine()->unloadScript(*
id);
532 if (cat == ScriptCategory::AI_BOT)
535 App::GetNetwork()->RemoveBotUserInfo(netuid);
536 App::GetGuiManager()->MpClientList.UpdateClients();
538 for (
ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetLocalActors())
540 if (actor->ar_driveable == AI && actor->ar_net_source_id == netuid)
542 App::GetGameContext()->PushMessage(
Message(MSG_SIM_DELETE_ACTOR_REQUESTED,
static_cast<void*
>(
new ActorPtr(actor))));
549 HandleMsgQueueException(m.
type);
555 case MSG_APP_SCRIPT_THREAD_STATUS:
560 App::GetScriptEngine()->triggerEvent(SE_ANGELSCRIPT_THREAD_STATUS,
566 HandleMsgQueueException(m.
type);
571 case MSG_APP_REINIT_INPUT_REQUESTED:
575 LOG(fmt::format(
"[RoR] !! Reinitializing input engine !!"));
576 App::DestroyInputEngine();
577 App::GetAppContext()->SetUpInput();
578 LOG(fmt::format(
"[RoR] DONE Reinitializing input engine."));
579 App::GetGuiManager()->LoadingWindow.SetVisible(
false);
583 HandleMsgQueueException(m.
type);
588 case MSG_APP_REINIT_UI_REQUESTED:
592 float ui_scale_clamped = Ogre::Math::Clamp(App::ui_scale_factor->getFloat(), UI_SCALE_FACTOR_MIN, UI_SCALE_FACTOR_MAX);
593 if (App::ui_scale_factor->getFloat() != ui_scale_clamped)
595 LOG(fmt::format(
"[RoR] Invalid value of 'ui_scale_factor' ({}), clamping to bounds <{}, {}>",
596 App::ui_scale_factor->getFloat(), UI_SCALE_FACTOR_MIN, UI_SCALE_FACTOR_MAX));
597 App::ui_scale_factor->setVal(ui_scale_clamped);
599 LOG(fmt::format(
"[RoR] Reinitializing UI (scale factor: {})", App::ui_scale_factor->getFloat()));
600 App::GetGuiManager()->ReinitUI();
601 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
603 for (
ActorPtr& actor: App::GetGameContext()->GetActorManager()->GetActors())
605 actor->ar_dashboard->applyUiScale();
611 HandleMsgQueueException(m.
type);
618 case MSG_NET_CONNECT_REQUESTED:
623 if (App::GetServerScript()->IsRunning())
625 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_ACTOR, Console::CONSOLE_SYSTEM_NOTICE,
626 _L(
"Stopping local server script engine before connecting to remote server."));
627 App::GetServerScript()->Close();
628 App::mp_state->setVal((
int)MpState::DISABLED);
630 App::GetNetwork()->StartConnecting();
634 HandleMsgQueueException(m.
type);
640 case MSG_NET_DISCONNECT_REQUESTED:
645 if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED)
647 App::GetNetwork()->Disconnect();
648 if (App::app_state->getEnum<AppState>() == AppState::MAIN_MENU)
650 App::GetGuiManager()->MainSelector.Close();
651 App::GetGameContext()->PushMessage(
Message(MSG_GUI_OPEN_MENU_REQUESTED));
657 HandleMsgQueueException(m.
type);
663 case MSG_NET_SERVER_KICK:
667 App::GetGameContext()->PushMessage(
Message(MSG_NET_DISCONNECT_REQUESTED));
668 App::GetGameContext()->PushMessage(
Message(MSG_SIM_UNLOAD_TERRN_REQUESTED));
669 App::GetGameContext()->PushMessage(
Message(MSG_GUI_OPEN_MENU_REQUESTED));
670 App::GetGuiManager()->ShowMessageBox(
_LC(
"Network",
"Network disconnected"), m.
description.c_str());
674 HandleMsgQueueException(m.
type);
679 case MSG_NET_RECV_ERROR:
683 App::GetGameContext()->PushMessage(
Message(MSG_NET_DISCONNECT_REQUESTED));
684 App::GetGameContext()->PushMessage(
Message(MSG_SIM_UNLOAD_TERRN_REQUESTED));
685 App::GetGameContext()->PushMessage(
Message(MSG_GUI_OPEN_MENU_REQUESTED));
686 App::GetGuiManager()->ShowMessageBox(
_L(
"Network fatal error: "), m.
description.c_str());
690 HandleMsgQueueException(m.
type);
695 case MSG_NET_CONNECT_STARTED:
699 App::GetGuiManager()->LoadingWindow.SetProgressNetConnect(m.
description);
700 App::GetGuiManager()->MultiplayerSelector.SetVisible(
false);
701 App::GetGameContext()->PushMessage(
Message(MSG_GUI_CLOSE_MENU_REQUESTED));
705 HandleMsgQueueException(m.
type);
710 case MSG_NET_CONNECT_PROGRESS:
714 App::GetGuiManager()->LoadingWindow.SetProgressNetConnect(m.
description);
718 HandleMsgQueueException(m.
type);
723 case MSG_NET_CONNECT_SUCCESS:
728 App::GetGuiManager()->LoadingWindow.SetVisible(
false);
729 App::GetNetwork()->StopConnecting();
732 if (!App::GetMumble())
736 if (App::GetNetwork()->GetTerrainName() !=
"any")
738 App::GetGameContext()->PushMessage(
Message(MSG_SIM_LOAD_TERRN_REQUESTED, App::GetNetwork()->GetTerrainName()));
743 if (App::diag_preset_terrain->getStr().empty())
747 App::GetGameContext()->PushMessage(m);
751 App::GetGameContext()->PushMessage(
Message(MSG_SIM_LOAD_TERRN_REQUESTED, App::diag_preset_terrain->getStr()));
757 HandleMsgQueueException(m.
type);
763 case MSG_NET_CONNECT_FAILURE:
768 App::GetGuiManager()->LoadingWindow.SetVisible(
false);
769 App::GetNetwork()->StopConnecting();
770 App::GetGameContext()->PushMessage(
Message(MSG_NET_DISCONNECT_REQUESTED));
771 App::GetGameContext()->PushMessage(
Message(MSG_GUI_OPEN_MENU_REQUESTED));
772 App::GetGuiManager()->ShowMessageBox(
773 _LC(
"Network",
"Multiplayer: connection failed"), m.
description.c_str());
777 HandleMsgQueueException(m.
type);
783 case MSG_NET_REFRESH_SERVERLIST_SUCCESS:
788 App::GetGuiManager()->MultiplayerSelector.UpdateServerlist(data);
792 HandleMsgQueueException(m.
type);
798 case MSG_NET_REFRESH_SERVERLIST_FAILURE:
803 App::GetGuiManager()->MultiplayerSelector.DisplayRefreshFailed(failinfo);
807 HandleMsgQueueException(m.
type);
813 case MSG_NET_REFRESH_REPOLIST_SUCCESS:
818 App::GetGuiManager()->RepositorySelector.UpdateResources(data);
822 HandleMsgQueueException(m.
type);
828 case MSG_NET_OPEN_RESOURCE_SUCCESS:
833 App::GetGuiManager()->RepositorySelector.UpdateResourceFilesAndDescription(data);
837 HandleMsgQueueException(m.
type);
843 case MSG_NET_REFRESH_REPOLIST_FAILURE:
848 App::GetGuiManager()->RepositorySelector.ShowError(failinfo);
852 HandleMsgQueueException(m.
type);
858 case MSG_NET_FETCH_AI_PRESETS_SUCCESS:
862 App::GetGuiManager()->TopMenubar.ai_presets_extern_fetching =
false;
863 App::GetGuiManager()->TopMenubar.ai_presets_extern.Parse(m.
description.c_str());
864 App::GetGuiManager()->TopMenubar.RefreshAiPresets();
868 HandleMsgQueueException(m.
type);
873 case MSG_NET_FETCH_AI_PRESETS_FAILURE:
877 App::GetGuiManager()->TopMenubar.ai_presets_extern_fetching =
false;
878 App::GetGuiManager()->TopMenubar.ai_presets_extern_error = m.
description;
879 App::GetGuiManager()->TopMenubar.RefreshAiPresets();
883 HandleMsgQueueException(m.
type);
888 case MSG_NET_ADD_PEEROPTIONS_REQUESTED:
894 App::GetNetwork()->AddPeerOptions(request);
899 App::GetConsole()->purgeNetChatMessagesByUser(request->
por_uid);
905 for (
ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetActors())
907 if (actor->ar_net_source_id == request->
por_uid)
909 App::GetGameContext()->PushMessage(
Message(MSG_SIM_MUTE_NET_ACTOR_REQUESTED,
new ActorPtr(actor)));
917 for (
ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetActors())
919 if (actor->ar_net_source_id == request->
por_uid)
921 App::GetGameContext()->PushMessage(
Message(MSG_SIM_HIDE_NET_ACTOR_REQUESTED,
new ActorPtr(actor)));
928 HandleMsgQueueException(m.
type);
934 case MSG_NET_REMOVE_PEEROPTIONS_REQUESTED:
940 App::GetNetwork()->RemovePeerOptions(request);
945 for (
ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetActors())
947 if (actor->ar_net_source_id == request->
por_uid)
949 App::GetGameContext()->PushMessage(
Message(MSG_SIM_UNMUTE_NET_ACTOR_REQUESTED,
new ActorPtr(actor)));
957 for (
ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetActors())
959 if (actor->ar_net_source_id == request->
por_uid)
961 App::GetGameContext()->PushMessage(
Message(MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED,
new ActorPtr(actor)));
968 HandleMsgQueueException(m.
type);
974 case MSG_NET_DOWNLOAD_REPOIMAGE_SUCCESS:
975 case MSG_NET_DOWNLOAD_REPOIMAGE_FAILURE:
980 App::GetGuiManager()->RepositorySelector.LoadDownloadedImage(rq);
984 HandleMsgQueueException(m.
type);
990 case MSG_NET_DOWNLOAD_REPOFILE_REQUESTED:
995 App::GetGuiManager()->RepositorySelector.QueueInstallRepoFile(request);
997 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
998 fmt::format(
_LC(
"RepositorySelector",
"Repo file installation requested: {}"), request->
rfir_filename));
1002 HandleMsgQueueException(m.
type);
1010 case MSG_SIM_PAUSE_REQUESTED:
1014 for (
ActorPtr& actor: App::GetGameContext()->GetActorManager()->GetActors())
1016 actor->muteAllSounds();
1018 App::sim_state->setVal((
int)SimState::PAUSED);
1022 HandleMsgQueueException(m.
type);
1027 case MSG_SIM_UNPAUSE_REQUESTED:
1031 for (
ActorPtr& actor: App::GetGameContext()->GetActorManager()->GetActors())
1033 if (!actor->ar_muted_by_peeropt)
1035 actor->unmuteAllSounds();
1038 App::sim_state->setVal((
int)SimState::RUNNING);
1042 HandleMsgQueueException(m.
type);
1047 case MSG_SIM_LOAD_TERRN_REQUESTED:
1051 App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::HIDDEN);
1052 App::GetGuiManager()->LoadingWindow.SetProgress(5,
_L(
"Loading resources"));
1053 App::GetContentManager()->LoadGameplayResources();
1055 if (App::GetGameContext()->LoadTerrain(m.
description))
1057 App::GetGameContext()->CreatePlayerCharacter();
1059 if (App::cli_preset_vehicle->getStr() !=
"")
1060 App::GetGameContext()->SpawnPreselectedActor(App::cli_preset_vehicle->getStr(), App::cli_preset_veh_config->getStr());
1061 else if (App::diag_preset_vehicle->getStr() !=
"")
1062 App::GetGameContext()->SpawnPreselectedActor(App::diag_preset_vehicle->getStr(), App::diag_preset_veh_config->getStr());
1063 App::GetGameContext()->GetSceneMouse().InitializeVisuals();
1064 App::CreateOverlayWrapper();
1065 App::GetGuiManager()->DirectionArrow.LoadOverlay();
1066 if (App::audio_menu_music->getBool())
1070 if (App::gfx_sky_mode->getEnum<GfxSkyMode>() == GfxSkyMode::SANDSTORM)
1072 App::GetGfxScene()->GetSceneManager()->setAmbientLight(Ogre::ColourValue(0.7f, 0.7f, 0.7f));
1076 App::GetGfxScene()->GetSceneManager()->setAmbientLight(Ogre::ColourValue(0.3f, 0.3f, 0.3f));
1078 App::GetDiscordRpc()->UpdatePresence();
1079 App::sim_state->setVal((
int)SimState::RUNNING);
1080 App::app_state->setVal((
int)AppState::SIMULATION);
1081 App::GetGuiManager()->GameMainMenu .SetVisible(
false);
1082 App::GetGuiManager()->MenuWallpaper->hide();
1083 App::GetGuiManager()->LoadingWindow.SetVisible(
false);
1084 App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::VISIBLE);
1085 App::gfx_fov_external->setVal(App::gfx_fov_external_default->getInt());
1086 App::gfx_fov_internal->setVal(App::gfx_fov_internal_default->getInt());
1088 if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED)
1090 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
1091 fmt::format(
_LC(
"ChatBox",
"Press {} to start chatting"),
1092 App::GetInputEngine()->getEventCommandTrimmed(EV_COMMON_ENTER_CHATMODE)),
"lightbulb.png");
1095 if (App::io_outgauge_mode->getInt() > 0)
1097 App::GetOutGauge()->Connect();
1102 if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED)
1104 App::GetGameContext()->PushMessage(
Message(MSG_NET_DISCONNECT_REQUESTED));
1108 App::GetGameContext()->PushMessage(
Message(MSG_GUI_OPEN_MENU_REQUESTED));
1110 App::GetGuiManager()->LoadingWindow.SetVisible(
false);
1116 HandleMsgQueueException(m.
type);
1121 case MSG_SIM_UNLOAD_TERRN_REQUESTED:
1125 if (App::sim_state->getEnum<SimState>() == SimState::EDITOR_MODE)
1127 App::GetGameContext()->GetTerrain()->GetTerrainEditor()->WriteSeparateOutputFile();
1129 App::GetGameContext()->SaveScene(
"autosave.sav");
1130 App::GetGameContext()->ChangePlayerActor(
nullptr);
1131 App::GetGameContext()->GetActorManager()->CleanUpSimulation();
1132 App::GetGameContext()->GetCharacterFactory()->DeleteAllCharacters();
1133 App::GetGameContext()->GetSceneMouse().DiscardVisuals();
1134 App::DestroyOverlayWrapper();
1135 App::GetCameraManager()->ResetAllBehaviors();
1136 App::GetGuiManager()->CollisionsDebug.CleanUp();
1137 App::GetGuiManager()->MainSelector.Close();
1138 App::GetGuiManager()->LoadingWindow.SetVisible(
false);
1139 App::GetGuiManager()->MenuWallpaper->show();
1140 App::GetGuiManager()->TopMenubar.ai_waypoints.clear();
1141 App::sim_state->setVal((
int)SimState::OFF);
1142 App::app_state->setVal((
int)AppState::MAIN_MENU);
1143 App::GetGameContext()->UnloadTerrain();
1144 App::GetGfxScene()->ClearScene();
1145 App::sim_terrain_name->setStr(
"");
1146 App::sim_terrain_gui_name->setStr(
"");
1147 App::GetOutGauge()->Close();
1148 App::GetSoundScriptManager()->SetListener(Ogre::Vector3::ZERO, Ogre::Vector3::ZERO, Ogre::Vector3::UNIT_Y, Ogre::Vector3::ZERO);
1149 App::GetSoundScriptManager()->getSoundManager()->CleanUp();
1150 App::GetGameContext()->GetRaceSystem().ResetRaceUI();
1154 HandleMsgQueueException(m.
type);
1159 case MSG_SIM_LOAD_SAVEGAME_REQUESTED:
1163 std::string terrn_filename = App::GetGameContext()->ExtractSceneTerrain(m.
description);
1164 if (terrn_filename ==
"")
1167 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_ERROR, msg.
ToCStr());
1168 if (App::app_state->getEnum<AppState>() == AppState::MAIN_MENU)
1170 App::GetGameContext()->PushMessage(
Message(MSG_GUI_OPEN_MENU_REQUESTED));
1173 else if (terrn_filename == App::sim_terrain_name->getStr())
1177 else if (terrn_filename != App::sim_terrain_name->getStr() && App::mp_state->getEnum<MpState>() == MpState::CONNECTED)
1179 Str<400> msg; msg <<
_L(
"Error while loading scene: Terrain mismatch");
1180 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_ERROR, msg.
ToCStr());
1184 if (App::sim_terrain_name->getStr() !=
"")
1186 App::GetGameContext()->PushMessage(
Message(MSG_SIM_UNLOAD_TERRN_REQUESTED));
1189 RoR::LogFormat(
"[RoR|Savegame] Loading terrain '%s' ...", terrn_filename.c_str());
1190 App::GetGameContext()->PushMessage(
Message(MSG_SIM_LOAD_TERRN_REQUESTED, terrn_filename));
1192 App::GetGameContext()->ChainMessage(
Message(MSG_SIM_LOAD_SAVEGAME_REQUESTED, m.
description));
1197 HandleMsgQueueException(m.
type);
1202 case MSG_SIM_SPAWN_ACTOR_REQUESTED:
1207 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
1209 App::GetGameContext()->SpawnActor(*rq);
1214 HandleMsgQueueException(m.
type);
1220 case MSG_SIM_MODIFY_ACTOR_REQUESTED:
1225 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
1227 App::GetGameContext()->ModifyActor(*rq);
1232 HandleMsgQueueException(m.
type);
1238 case MSG_SIM_DELETE_ACTOR_REQUESTED:
1244 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
1246 App::GetGameContext()->DeleteActor(*actor_ptr);
1251 HandleMsgQueueException(m.
type);
1257 case MSG_SIM_SEAT_PLAYER_REQUESTED:
1263 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
1265 App::GetGameContext()->ChangePlayerActor(*actor_ptr);
1270 HandleMsgQueueException(m.
type);
1276 case MSG_SIM_TELEPORT_PLAYER_REQUESTED:
1278 Ogre::Vector3* pos =
static_cast<Ogre::Vector3*
>(m.
payload);
1281 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
1283 App::GetGameContext()->TeleportPlayer(pos->x, pos->z);
1288 HandleMsgQueueException(m.
type);
1294 case MSG_SIM_HIDE_NET_ACTOR_REQUESTED:
1300 if ((App::mp_state->getEnum<MpState>() == MpState::CONNECTED) &&
1301 ((*actor_ptr)->ar_state == ActorState::NETWORKED_OK))
1304 actor->ar_state = ActorState::NETWORKED_HIDDEN;
1305 App::GetGfxScene()->RemoveGfxActor(actor->GetGfxActor());
1306 actor->GetGfxActor()->GetSimDataBuffer().simbuf_actor_state = ActorState::NETWORKED_HIDDEN;
1307 actor->GetGfxActor()->SetAllMeshesVisible(
false);
1308 actor->GetGfxActor()->SetCastShadows(
false);
1309 actor->muteAllSounds();
1310 actor->forceAllFlaresOff();
1311 actor->setSmokeEnabled(
false);
1316 HandleMsgQueueException(m.
type);
1322 case MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED:
1328 if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED &&
1329 ((*actor_ptr)->ar_state == ActorState::NETWORKED_HIDDEN))
1332 actor->ar_state = ActorState::NETWORKED_OK;
1333 App::GetGfxScene()->RegisterGfxActor(actor->GetGfxActor());
1334 actor->GetGfxActor()->SetAllMeshesVisible(
true);
1335 actor->GetGfxActor()->SetCastShadows(
true);
1336 actor->unmuteAllSounds();
1337 actor->setSmokeEnabled(
true);
1342 HandleMsgQueueException(m.
type);
1348 case MSG_SIM_MUTE_NET_ACTOR_REQUESTED:
1355 const bool valid_remote_actor = (App::mp_state->getEnum<
MpState>() == MpState::CONNECTED) && actor->ar_state == ActorState::NETWORKED_OK;
1356 const bool valid_ai_actor = (App::mp_state->getEnum<
MpState>() == MpState::LOCAL_SCRIPT) && actor->ar_state == ActorState::LOCAL_SIMULATED && actor->ar_driveable == ActorType::AI;
1357 if (valid_remote_actor || valid_ai_actor)
1359 actor->ar_muted_by_peeropt =
true;
1360 actor->muteAllSounds();
1365 HandleMsgQueueException(m.
type);
1371 case MSG_SIM_UNMUTE_NET_ACTOR_REQUESTED:
1378 const bool valid_remote_actor = (App::mp_state->getEnum<
MpState>() == MpState::CONNECTED) && actor->ar_state == ActorState::NETWORKED_OK;
1379 const bool valid_ai_actor = (App::mp_state->getEnum<
MpState>() == MpState::LOCAL_SCRIPT) && actor->ar_state == ActorState::LOCAL_SIMULATED && actor->ar_driveable == ActorType::AI;
1380 if (valid_remote_actor || valid_ai_actor)
1382 actor->ar_muted_by_peeropt =
false;
1383 actor->unmuteAllSounds();
1388 HandleMsgQueueException(m.
type);
1394 case MSG_SIM_SCRIPT_EVENT_TRIGGERED:
1399 if (args->
type == SE_GENERIC_FREEFORCES_ACTIVITY && args->
arg1 == freeForcesActivityType::FREEFORCESACTIVITY_BROKEN)
1401 App::GetGfxScene()->OnFreeForceBroken(args->
arg2ex);
1403 else if (args->
type == SE_GENERIC_MODCACHE_ACTIVITY && args->
arg1 == modCacheActivityType::MODCACHEACTIVITY_ENTRY_ADDED && App::mp_state->getEnum<
MpState>() == MpState::CONNECTED)
1406 App::GetGameContext()->GetActorManager()->RetryFailedStreamRegistrations(args);
1413 HandleMsgQueueException(m.
type);
1419 case MSG_SIM_SCRIPT_CALLBACK_QUEUED:
1428 HandleMsgQueueException(m.
type);
1434 case MSG_SIM_ACTOR_LINKING_REQUESTED:
1448 case ActorLinkingRequestType::HOOK_LOCK:
1449 case ActorLinkingRequestType::HOOK_UNLOCK:
1450 case ActorLinkingRequestType::HOOK_TOGGLE:
1454 case ActorLinkingRequestType::HOOK_MOUSE_TOGGLE:
1459 case ActorLinkingRequestType::TIE_TOGGLE:
1463 case ActorLinkingRequestType::ROPE_TOGGLE:
1467 case ActorLinkingRequestType::SLIDENODE_TOGGLE:
1468 actor->toggleSlideNodeLock();
1475 HandleMsgQueueException(m.
type);
1481 case MSG_SIM_ADD_FREEFORCE_REQUESTED:
1486 App::GetGameContext()->GetActorManager()->AddFreeForce(rq);
1490 HandleMsgQueueException(m.
type);
1496 case MSG_SIM_MODIFY_FREEFORCE_REQUESTED:
1501 App::GetGameContext()->GetActorManager()->ModifyFreeForce(rq);
1505 HandleMsgQueueException(m.
type);
1511 case MSG_SIM_REMOVE_FREEFORCE_REQUESTED:
1516 App::GetGameContext()->GetActorManager()->RemoveFreeForce(*rq);
1517 App::GetGfxScene()->OnFreeForceRemoved(*rq);
1521 HandleMsgQueueException(m.
type);
1529 case MSG_GUI_OPEN_MENU_REQUESTED:
1533 App::GetGuiManager()->GameMainMenu.SetVisible(
true);
1537 HandleMsgQueueException(m.
type);
1542 case MSG_GUI_CLOSE_MENU_REQUESTED:
1546 App::GetGuiManager()->GameMainMenu.SetVisible(
false);
1550 HandleMsgQueueException(m.
type);
1555 case MSG_GUI_OPEN_SELECTOR_REQUESTED:
1560 App::GetGuiManager()->MainSelector.Show(*type, m.
description);
1564 HandleMsgQueueException(m.
type);
1570 case MSG_GUI_CLOSE_SELECTOR_REQUESTED:
1574 App::GetGuiManager()->MainSelector.Close();
1578 HandleMsgQueueException(m.
type);
1583 case MSG_GUI_MP_CLIENTS_REFRESH:
1587 App::GetGuiManager()->MpClientList.UpdateClients();
1591 HandleMsgQueueException(m.
type);
1596 case MSG_GUI_SHOW_MESSAGE_BOX_REQUESTED:
1601 App::GetGuiManager()->ShowMessageBox(*conf);
1605 HandleMsgQueueException(m.
type);
1611 case MSG_NET_DOWNLOAD_REPOFILE_PROGRESS:
1613 int* percentage =
static_cast<int*
>(m.
payload);
1618 App::GetGuiManager()->LoadingWindow.SetProgress(*percentage, m.
description,
false);
1623 HandleMsgQueueException(m.
type);
1629 case MSG_NET_DOWNLOAD_REPOFILE_SUCCESS:
1630 case MSG_NET_DOWNLOAD_REPOFILE_FAILURE:
1635 App::GetGuiManager()->LoadingWindow.SetVisible(
false);
1636 App::GetGuiManager()->RepositorySelector.SetVisible(
true);
1637 App::GetGuiManager()->RepositorySelector.InstallDownloadedRepoFile(m.
type, request);
1641 HandleMsgQueueException(m.
type);
1647 case MSG_GUI_REFRESH_TUNING_MENU_REQUESTED:
1651 App::GetGuiManager()->TopMenubar.RefreshTuningMenu();
1655 HandleMsgQueueException(m.
type);
1660 case MSG_GUI_SHOW_CHATBOX_REQUESTED:
1664 App::GetGuiManager()->ChatBox.SetVisible(
true);
1667 App::GetGuiManager()->ChatBox.AssignBuffer(m.
description);
1672 HandleMsgQueueException(m.
type);
1677 case MSG_GUI_OPEN_MP_SETTINGS_REQUESTED:
1681 App::GetGuiManager()->GameMainMenu.SetVisible(
false);
1682 App::GetGuiManager()->MultiplayerSelector.SetVisible(
true);
1683 App::GetGuiManager()->MultiplayerSelector.SetSettingsTabSelected();
1687 HandleMsgQueueException(m.
type);
1694 case MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED:
1699 ground_model_t* live_gm = App::GetGameContext()->GetTerrain()->GetCollisions()->getGroundModelByString(modified_gm->
name);
1700 *live_gm = *modified_gm;
1705 HandleMsgQueueException(m.
type);
1710 case MSG_EDI_ENTER_TERRN_EDITOR_REQUESTED:
1714 if (App::sim_state->getEnum<SimState>() != SimState::EDITOR_MODE)
1716 App::sim_state->setVal((
int)SimState::EDITOR_MODE);
1717 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
1718 _L(
"Entered terrain editing mode"));
1720 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
1721 fmt::format(
_L(
"Press {} or middle mouse click to select an object"),
1722 App::GetInputEngine()->getEventCommandTrimmed(EV_COMMON_ENTER_OR_EXIT_TRUCK)),
"lightbulb.png");
1728 HandleMsgQueueException(m.
type);
1733 case MSG_EDI_LEAVE_TERRN_EDITOR_REQUESTED:
1737 if (App::sim_state->getEnum<SimState>() == SimState::EDITOR_MODE)
1739 App::GetGameContext()->GetTerrain()->GetTerrainEditor()->WriteSeparateOutputFile();
1740 App::GetGameContext()->GetTerrain()->GetTerrainEditor()->ClearSelectedObject();
1741 App::sim_state->setVal((
int)SimState::RUNNING);
1742 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
1743 _L(
"Left terrain editing mode"));
1748 HandleMsgQueueException(m.
type);
1753 case MSG_EDI_SAVE_TERRN_CHANGES_REQUESTED:
1757 if (App::sim_state->getEnum<SimState>() == SimState::EDITOR_MODE
1758 && App::GetGameContext()->GetTerrain()->getCacheEntry()->resource_bundle_type ==
"FileSystem")
1761 App::GetGameContext()->GetTerrain()->GetTerrainEditor()->WriteEditsToTobjFiles();
1762 App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_NOTICE,
1763 _L(
"Terrain files have been updated"));
1768 HandleMsgQueueException(m.
type);
1773 case MSG_EDI_LOAD_BUNDLE_REQUESTED:
1778 App::GetCacheSystem()->LoadResource(*entry_ptr);
1779 TRIGGER_EVENT_ASYNC(SE_GENERIC_MODCACHE_ACTIVITY,
1780 MODCACHEACTIVITY_BUNDLE_LOADED, (*entry_ptr)->number, 0, 0,
1781 (*entry_ptr)->resource_group);
1785 HandleMsgQueueException(m.
type);
1791 case MSG_EDI_RELOAD_BUNDLE_REQUESTED:
1797 bool all_clear =
true;
1798 for (
ActorPtr& actor: App::GetGameContext()->GetActorManager()->GetActors())
1800 if (actor->GetGfxActor()->GetResourceGroup() == (*entry_ptr)->resource_group)
1802 App::GetGameContext()->PushMessage(
Message(MSG_SIM_DELETE_ACTOR_REQUESTED,
static_cast<void*
>(
new ActorPtr(actor))));
1810 App::GetCacheSystem()->ReLoadResource(*entry_ptr);
1812 TRIGGER_EVENT_ASYNC(SE_GENERIC_MODCACHE_ACTIVITY,
1813 MODCACHEACTIVITY_BUNDLE_RELOADED, (*entry_ptr)->number, 0, 0,
1814 (*entry_ptr)->resource_group);
1821 App::GetGameContext()->PushMessage(m);
1827 HandleMsgQueueException(m.
type);
1832 case MSG_EDI_UNLOAD_BUNDLE_REQUESTED:
1838 bool all_clear =
true;
1839 for (
ActorPtr& actor: App::GetGameContext()->GetActorManager()->GetActors())
1843 const bool uses_actor_rg = (actor->getUsedActorEntry()->resource_group == (*entry_ptr)->resource_group);
1845 const bool uses_skin_rg = (actor->getUsedSkinEntry() && actor->getUsedSkinEntry()->resource_group == (*entry_ptr)->resource_group);
1847 const bool uses_addonpart_rg = std::find_if(
1848 actor->getUsedAddonpartEntries().begin(),
1849 actor->getUsedAddonpartEntries().end(),
1852 return ap_entry->resource_group == (*entry_ptr)->resource_group;
1853 }) != actor->getUsedAddonpartEntries().end();
1855 const bool uses_assetpack_rg = std::find_if(
1856 actor->getUsedAssetpackEntries().begin(),
1857 actor->getUsedAssetpackEntries().end(),
1860 return ap_entry->resource_group == (*entry_ptr)->resource_group;
1861 }) != actor->getUsedAssetpackEntries().end();
1862 if (uses_actor_rg || uses_skin_rg || uses_addonpart_rg || uses_assetpack_rg)
1864 App::GetGameContext()->PushMessage(
Message(MSG_SIM_DELETE_ACTOR_REQUESTED,
static_cast<void*
>(
new ActorPtr(actor))));
1869 if (App::GetGameContext()->GetTerrain()
1870 && App::GetGameContext()->GetTerrain()->getCacheEntry()->resource_group == (*entry_ptr)->resource_group)
1872 if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED)
1874 App::GetGameContext()->PushMessage(
Message(MSG_NET_DISCONNECT_REQUESTED));
1878 App::GetGameContext()->PushMessage(
Message(MSG_SIM_UNLOAD_TERRN_REQUESTED));
1886 App::GetCacheSystem()->UnLoadResource(*entry_ptr);
1888 TRIGGER_EVENT_ASYNC(SE_GENERIC_MODCACHE_ACTIVITY,
1889 MODCACHEACTIVITY_BUNDLE_UNLOADED, (*entry_ptr)->number, 0, 0);
1896 App::GetGameContext()->PushMessage(m);
1902 HandleMsgQueueException(m.
type);
1908 case MSG_EDI_DELETE_BUNDLE_REQUESTED:
1912 std::string bundle_filepath;
1913 if (!App::GetCacheSystem()->IsRepoFileInstalled(m.
description, bundle_filepath))
1919 bool all_clear =
true;
1920 for (
const CacheEntryPtr& entry: App::GetCacheSystem()->GetEntries())
1922 if (entry->resource_bundle_path == bundle_filepath && entry->resource_group !=
"")
1924 App::GetGameContext()->PushMessage(
Message(MSG_EDI_UNLOAD_BUNDLE_REQUESTED,
static_cast<void*
>(
new CacheEntryPtr(entry))));
1931 std::string bundle_basename, bundle_dirpath;
1932 Ogre::StringUtil::splitFilename(bundle_filepath, bundle_basename, bundle_dirpath);
1933 App::GetCacheSystem()->DeleteResourceBundleByFilename(bundle_basename);
1934 App::GetGuiManager()->RepositorySelector.NotifyRepoFileUninstalled(bundle_basename);
1939 App::GetGameContext()->PushMessage(m);
1945 HandleMsgQueueException(m.
type);
1950 case MSG_EDI_CREATE_PROJECT_REQUESTED:
1955 if (!App::GetCacheSystem()->CreateProject(request))
1962 HandleMsgQueueException(m.
type);
1968 case MSG_EDI_MODIFY_PROJECT_REQUESTED:
1973 if (App::mp_state->getEnum<MpState>() != MpState::CONNECTED)
1975 App::GetCacheSystem()->ModifyProject(request);
1980 HandleMsgQueueException(m.
type);
1986 case MSG_EDI_DELETE_PROJECT_REQUESTED:
1991 App::GetCacheSystem()->DeleteProject(*entry_ptr);
1995 HandleMsgQueueException(m.
type);
2001 case MSG_EDI_ADD_FREEBEAMGFX_REQUESTED:
2006 App::GetGfxScene()->AddFreeBeamGfx(request);
2010 HandleMsgQueueException(m.
type);
2016 case MSG_EDI_MODIFY_FREEBEAMGFX_REQUESTED:
2021 App::GetGfxScene()->ModifyFreeBeamGfx(request);
2025 HandleMsgQueueException(m.
type);
2031 case MSG_EDI_DELETE_FREEBEAMGFX_REQUESTED:
2036 App::GetGfxScene()->RemoveFreeBeamGfx(*request);
2040 HandleMsgQueueException(m.
type);
2054 App::GetGameContext()->PushMessage(chained_msg);
2059 OgreProfileEnd(
"RoR message queue");
2062 if (App::gfx_fps_limit->getInt() > 0)
2064 OgreProfile(
"RoR FPS limiter");
2065 const float min_frame_time = 1.0f / Ogre::Math::Clamp(App::gfx_fps_limit->getInt(), 5, 240);
2066 float dt = std::chrono::duration<float>(std::chrono::high_resolution_clock::now() - start_time).count();
2067 while (dt < min_frame_time)
2069 dt = std::chrono::duration<float>(std::chrono::high_resolution_clock::now() - start_time).count();
2073 OgreProfileBegin(
"RoR Main Loop");
2075 const auto now = std::chrono::high_resolution_clock::now();
2076 const float dt = std::chrono::duration<float>(now - start_time).count();
2081 if (App::mp_state->getEnum<MpState>() == MpState::CONNECTED)
2083 std::vector<RoR::NetRecvPacket> packets = App::GetNetwork()->GetIncomingStreamData();
2084 if (!packets.empty())
2087 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
2089 App::GetGameContext()->GetActorManager()->HandleActorStreamData(packets);
2090 App::GetGameContext()->GetCharacterFactory()->handleStreamData(packets);
2098 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
2100 ActorPtr player_actor = App::GetGameContext()->GetPlayerActor();
2101 for (
ActorPtr actor : App::GetGameContext()->GetActorManager()->GetActors())
2103 bool is_player_actor = player_actor !=
nullptr && actor->getInstanceId() == player_actor->getInstanceId();
2104 actor->ar_arcade_controls = is_player_actor && App::io_arcade_controls->getBool();
2105 actor->ar_hydro_speed_coupling_enabled = is_player_actor && App::io_hydro_coupling->getBool();
2110 OgreProfileBegin(
"Input processing");
2113 App::GetInputEngine()->Capture();
2114 App::GetInputEngine()->updateKeyBounces(dt);
2116 if (!App::GetGuiManager()->GameControls.IsInteractiveKeyBindingActive())
2118 if (!App::GetGuiManager()->MainSelector.IsVisible() && !App::GetGuiManager()->MultiplayerSelector.IsVisible() &&
2119 !App::GetGuiManager()->GameSettings.IsVisible() && !App::GetGuiManager()->GameControls.IsVisible() &&
2120 !App::GetGuiManager()->GameAbout.IsVisible() && !App::GetGuiManager()->RepositorySelector.IsVisible())
2122 App::GetGameContext()->HandleSavegameHotkeys();
2124 App::GetGameContext()->UpdateGlobalInputEvents();
2125 App::GetGuiManager()->UpdateInputEvents(dt);
2127 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
2129 if (App::sim_state->getEnum<SimState>() == SimState::EDITOR_MODE)
2131 App::GetGameContext()->UpdateSkyInputEvents(dt);
2132 App::GetGameContext()->GetTerrain()->GetTerrainEditor()->UpdateInputEvents(dt);
2136 App::GetGameContext()->GetCharacterFactory()->Update(dt);
2138 App::GetCameraManager()->UpdateInputEvents(dt);
2139 App::GetOverlayWrapper()->update(dt);
2140 App::GetGameContext()->GetRepairMode().UpdateInputEvents(dt);
2141 App::GetGameContext()->GetActorManager()->UpdateInputEvents(dt);
2142 if (App::sim_state->getEnum<SimState>() == SimState::RUNNING)
2144 if (App::GetCameraManager()->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_FREE)
2146 App::GetGameContext()->UpdateSimInputEvents(dt);
2149 App::GetGameContext()->UpdateSkyInputEvents(dt);
2150 for (
ActorPtr actor : App::GetGameContext()->GetActorManager()->GetActors())
2152 if (actor->ar_state != ActorState::NETWORKED_OK)
2154 App::GetGameContext()->UpdateCommonInputEvents(dt, actor);
2155 if (actor->ar_state != ActorState::LOCAL_REPLAY)
2157 if (actor->ar_driveable == TRUCK)
2159 App::GetGameContext()->UpdateTruckInputEvents(dt, actor);
2161 if (actor->ar_driveable == AIRPLANE)
2163 App::GetGameContext()->UpdateAirplaneInputEvents(dt, actor);
2165 if (actor->ar_driveable == BOAT)
2167 App::GetGameContext()->UpdateBoatInputEvents(dt, actor);
2171 actor->UpdatePropAnimInputEvents();
2172 for (
ActorPtr linked_actor : actor->ar_linked_actors)
2174 linked_actor->UpdatePropAnimInputEvents();
2182 OgreProfileEnd(
"Input processing");
2185 if (App::io_outgauge_mode->getInt() > 0)
2187 OgreProfile(
"OutGauge");
2188 App::GetOutGauge()->Update(dt, App::GetGameContext()->GetPlayerActor());
2192 App::GetGuiManager()->NewImGuiFrame(dt);
2193 if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
2195 OgreProfile(
"Scene and GUI");
2196 App::GetGuiManager()->DrawSimulationGui(dt);
2197 for (
ActorPtr& actor : App::GetGameContext()->GetActorManager()->GetActors())
2199 actor->GetGfxActor()->UpdateDebugView();
2201 if (App::GetGameContext()->GetPlayerActor())
2203 App::GetGuiManager()->VehicleInfoTPanel.UpdateStats(dt, App::GetGameContext()->GetPlayerActor());
2204 if (App::GetGuiManager()->FrictionSettings.IsVisible())
2206 App::GetGuiManager()->FrictionSettings.setActiveCol(App::GetGameContext()->GetPlayerActor()->ar_last_fuzzy_ground_model);
2212 if (App::GetMumble())
2214 OgreProfile(
"Mumble");
2215 App::GetMumble()->Update();
2220 OgreProfileBegin(
"3D audio");
2221 App::GetSoundScriptManager()->update(dt);
2222 OgreProfileEnd(
"3D audio");
2225#ifdef USE_ANGELSCRIPT
2226 OgreProfileBegin(
"Scripting");
2227 App::GetScriptEngine()->framestep(dt);
2228 OgreProfileEnd(
"Scripting");
2231 if (App::io_ffb_enabled->getBool() &&
2232 App::sim_state->getEnum<SimState>() == SimState::RUNNING)
2234 OgreProfile(
"Force Feedback");
2235 App::GetAppContext()->GetForceFeedback().Update();
2238 OgreProfileBegin(
"Simulation");
2239 if (App::sim_state->getEnum<SimState>() == SimState::RUNNING)
2241 App::GetGameContext()->GetSceneMouse().UpdateSimulation();
2245 if (App::sim_state->getEnum<SimState>() == SimState::RUNNING ||
2246 App::sim_state->getEnum<SimState>() == SimState::PAUSED ||
2247 App::sim_state->getEnum<SimState>() == SimState::EDITOR_MODE)
2249 App::GetGfxScene()->BufferSimulationData();
2254 if (App::sim_state->getEnum<SimState>() == SimState::RUNNING && !App::GetGameContext()->GetActorManager()->IsSimulationPaused())
2256 dt_sim = dt * App::GetGameContext()->GetActorManager()->GetSimulationSpeed();
2260 if (App::sim_state->getEnum<SimState>() == SimState::RUNNING)
2262 if (App::GetGameContext()->GetTerrain()->getWater())
2264 App::GetGameContext()->GetTerrain()->getWater()->FrameStepWaveField(dt_sim);
2266 App::GetGameContext()->UpdateActors();
2268 OgreProfileEnd(
"Simulation");
2271 OgreProfileBegin(
"Scene and GUI");
2272 if (App::app_state->getEnum<AppState>() == AppState::MAIN_MENU)
2274 App::GetGuiManager()->DrawMainMenuGui();
2276 else if (App::app_state->getEnum<AppState>() == AppState::SIMULATION)
2278 App::GetGfxScene()->UpdateScene(dt_sim);
2280 OgreProfileEnd(
"Scene and GUI");
2282 OgreProfileEnd(
"RoR Main Loop");
2286 if (render_window->isClosed())
2288 App::GetGameContext()->PushMessage(
Message(MSG_APP_SHUTDOWN_REQUESTED));
2292 App::GetAppContext()->GetOgreRoot()->renderOneFrame();
2293 if (!render_window->isActive() && render_window->isVisible())
2295 render_window->update();
2299 App::GetGuiManager()->ApplyGuiCaptureKeyboard();
2301 App::GetGuiManager()->UpdateMouseCursorVisibility();
2307 catch (Ogre::Exception& e)
2309 LOG(e.getFullDescription());
2312 catch (std::runtime_error& e)