Skip to content

Commit

Permalink
Tuning: added ✉️ MSG_GUI_REFRESH_TUNING_MENU_REQUESTED
Browse files Browse the repository at this point in the history
This removes the huge UI lag on first open of the tuning menu, which was caused by loading all addonparts to evaluate conflicts. But the lag isnt gone - it now happens upon spawning the actor. It could only be fully eliminated by caching the tweaked element IDs directly in `CacheEntry`, something I'll eventually do but not now.

Codechanges:
* CacheSystem: added dummy TuneupDef with addonpart data to CacheEntry.
* AddonPartFileFormat: added silent mode, using the new CacheEntry field.
* GameContext: also push MSG_SIM_REFRESH_TUNING_MENU_REQUESTED after spawning new actor and seating player there. Deleted duplicate code in SpawnActor()
  • Loading branch information
ohlidalp committed Apr 23, 2024
1 parent 912c0ab commit 5c411e8
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 54 deletions.
1 change: 1 addition & 0 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ enum MsgType
MSG_GUI_SHOW_MESSAGE_BOX_REQUESTED, //!< Payload = MessageBoxConfig* (owner)
MSG_GUI_DOWNLOAD_PROGRESS,
MSG_GUI_DOWNLOAD_FINISHED,
MSG_GUI_REFRESH_TUNING_MENU_REQUESTED,
// Editing
MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED, //!< Payload = RoR::ground_model_t* (weak)
MSG_EDI_ENTER_TERRN_EDITOR_REQUESTED,
Expand Down
20 changes: 11 additions & 9 deletions source/main/GameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ ActorPtr GameContext::SpawnActor(ActorSpawnRequest& rq)
#endif //SOCKETW

ActorPtr fresh_actor = m_actor_manager.CreateNewActor(rq, def);
bool fresh_actor_seat_player = false;

// lock slide nodes after spawning the actor?
if (def->slide_nodes_connect_instantly)
Expand All @@ -284,7 +285,7 @@ ActorPtr GameContext::SpawnActor(ActorSpawnRequest& rq)
m_last_spawned_actor = fresh_actor;
if (fresh_actor->ar_driveable != NOT_DRIVEABLE)
{
this->PushMessage(Message(MSG_SIM_SEAT_PLAYER_REQUESTED, static_cast<void*>(new ActorPtr(fresh_actor))));
fresh_actor_seat_player = true;
}
if (rq.asr_spawnbox == nullptr)
{
Expand All @@ -298,13 +299,7 @@ ActorPtr GameContext::SpawnActor(ActorSpawnRequest& rq)
fresh_actor->ar_num_nodes > 0 &&
App::diag_preset_veh_enter->getBool())
{
this->PushMessage(Message(MSG_SIM_SEAT_PLAYER_REQUESTED, static_cast<void*>(new ActorPtr(fresh_actor))));
}
if (fresh_actor->ar_driveable != NOT_DRIVEABLE &&
fresh_actor->ar_num_nodes > 0 &&
App::cli_preset_veh_enter->getBool())
{
this->PushMessage(Message(MSG_SIM_SEAT_PLAYER_REQUESTED, static_cast<void*>(new ActorPtr(fresh_actor))));
fresh_actor_seat_player = true;
}
}
else if (rq.asr_origin == ActorSpawnRequest::Origin::TERRN_DEF)
Expand Down Expand Up @@ -347,10 +342,17 @@ ActorPtr GameContext::SpawnActor(ActorSpawnRequest& rq)
rq.asr_origin != ActorSpawnRequest::Origin::NETWORK &&
rq.asr_enter)
{
this->PushMessage(Message(MSG_SIM_SEAT_PLAYER_REQUESTED, static_cast<void*>(new ActorPtr(fresh_actor))));
fresh_actor_seat_player = true;
}
}

if (fresh_actor_seat_player)
{
this->PushMessage(Message(MSG_SIM_SEAT_PLAYER_REQUESTED, new ActorPtr(fresh_actor)));
// Loading all addonparts to resolve conflicts is slow and would cause huge UI lag if not forced now. Do it right after player was seated in the actor.
this->ChainMessage(Message(MSG_GUI_REFRESH_TUNING_MENU_REQUESTED));
}

return fresh_actor;
}

Expand Down
2 changes: 1 addition & 1 deletion source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,7 @@ void TopMenubar::RefreshTuningMenu()
if (App::sim_tuning_enabled->getBool()
&& (App::mp_state->getEnum<MpState>() != MpState::CONNECTED)
&& current_actor
&& (tuning_actor != current_actor || tuning_force_refresh))
&& (tuning_actor != current_actor))
{
ROR_ASSERT(current_actor->getUsedActorEntry());

Expand Down
1 change: 0 additions & 1 deletion source/main/gui/panels/GUI_TopMenubar.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class TopMenubar
bool tuning_savebox_overwrite = false; //!< Status of "Overwrite?" checkbox
const ImVec4 TUNING_HOLDTOCONFIRM_COLOR = ImVec4(0.25f, 0.15f, 0.2f, 0.5f);
const float TUNING_HOLDTOCONFIRM_TIMELIMIT = 1.5f; //!< Delete button must be held for several sec to confirm.
bool tuning_force_refresh = false;
float tuning_rwidget_cursorx_min = 0.f; //!< Avoid drawing right-side widgets ('Delete' button or 'Protected' chk) over saved tuneup names.
CacheEntryPtr tuning_hovered_addonpart;
void RefreshTuningMenu();
Expand Down
6 changes: 6 additions & 0 deletions source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,12 @@ int main(int argc, char *argv[])
App::GetGuiManager()->RepositorySelector.DownloadFinished();
break;

case MSG_GUI_REFRESH_TUNING_MENU_REQUESTED:
{
App::GetGuiManager()->TopMenubar.RefreshTuningMenu();
break;
}

// -- Editing events --

case MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED:
Expand Down
1 change: 1 addition & 0 deletions source/main/resources/CacheSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class CacheEntry: public RefCountingObject<CacheEntry>
RigDef::DocumentPtr actor_def; //!< Cached actor definition (aka truckfile) after first spawn.
std::shared_ptr<RoR::SkinDef> skin_def; //!< Cached skin info, added on first use or during cache rebuild
RoR::TuneupDefPtr tuneup_def; //!< Cached tuning info, added on first use or during cache rebuild
RoR::TuneupDefPtr addonpart_data_only; //!< Cached addonpart data (dummy tuneup), only used for evaluating conflicts, see `AddonPartUtility::RecordAddonpartConflicts()`
// TBD: Make Terrn2Def a RefcountingObjectPtr<> and cache it here too.

// following all TRUCK detail information:
Expand Down
Loading

0 comments on commit 5c411e8

Please sign in to comment.