From 009bcf666f80ba52180cacf30ea678e9471bfb35 Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Thu, 10 Jun 2021 20:56:16 +0300 Subject: [PATCH 01/24] added hide/unhide/remove buttons in mp actor list --- source/main/Application.h | 2 ++ source/main/gui/panels/GUI_TopMenubar.cpp | 31 ++++++++++++++++++++++- source/main/main.cpp | 30 ++++++++++++++++++++++ source/main/physics/Actor.h | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/source/main/Application.h b/source/main/Application.h index 8afd444223..7e5cdddc00 100644 --- a/source/main/Application.h +++ b/source/main/Application.h @@ -89,6 +89,8 @@ enum MsgType MSG_SIM_DELETE_ACTOR_REQUESTED, //!< Payload = Actor* (weak) MSG_SIM_SEAT_PLAYER_REQUESTED, //!< Payload = Actor* (weak) | nullptr MSG_SIM_TELEPORT_PLAYER_REQUESTED, //!< Payload = Ogre::Vector3* (owner) + MSG_SIM_HIDE_NET_ACTOR_REQUESTED, //!< Payload = Actor* (weak) + MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED, //!< Payload = Actor* (weak) // GUI MSG_GUI_OPEN_MENU_REQUESTED, MSG_GUI_CLOSE_MENU_REQUESTED, diff --git a/source/main/gui/panels/GUI_TopMenubar.cpp b/source/main/gui/panels/GUI_TopMenubar.cpp index e43b2f76ab..77a9b2c188 100644 --- a/source/main/gui/panels/GUI_TopMenubar.cpp +++ b/source/main/gui/panels/GUI_TopMenubar.cpp @@ -743,12 +743,41 @@ void TopMenubar::DrawMpUserToActorList(RoRnet::UserInfo &user) ImGui::PopStyleColor(); // Display actor list + Ogre::TexturePtr tex1 = FetchIcon("control_pause.png"); + Ogre::TexturePtr tex2 = FetchIcon("control_play.png"); + Ogre::TexturePtr tex3 = FetchIcon("delete.png"); int i = 0; for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { if ((!actor->ar_hide_in_actor_list) && (actor->ar_net_source_id == user.uniqueid)) { - std::string actortext_buf = fmt::format(" + {} ({}) ##[{}:{}]", actor->ar_design_name.c_str(), actor->ar_filename.c_str(), i++, user.uniqueid); + std::string id = fmt::format("{}:{}", i++, user.uniqueid); + ImGui::PushID(id.c_str()); + if (actor->ar_sim_state == Actor::SimState::NETWORKED_OK) + { + if (ImGui::ImageButton(reinterpret_cast(tex1->getHandle()), ImVec2(16, 16))) + { + App::GetGameContext()->PushMessage(Message(MSG_SIM_HIDE_NET_ACTOR_REQUESTED, (void*)actor)); + } + } + else if (actor->ar_sim_state == Actor::SimState::NETWORKED_HIDDEN) + { + if (ImGui::ImageButton(reinterpret_cast(tex2->getHandle()), ImVec2(16, 16))) + { + App::GetGameContext()->PushMessage(Message(MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED, (void*)actor)); + } + } + else // Our actor(s) + { + if (ImGui::ImageButton(reinterpret_cast(tex3->getHandle()), ImVec2(16, 16))) + { + App::GetGameContext()->PushMessage(Message(MSG_SIM_DELETE_ACTOR_REQUESTED, (void*)actor)); + } + } + ImGui::PopID(); + ImGui::SameLine(); + + std::string actortext_buf = fmt::format("{} ({}) ##[{}:{}]", actor->ar_design_name.c_str(), actor->ar_filename.c_str(), i++, user.uniqueid); if (ImGui::Button(actortext_buf.c_str())) // Button clicked? { App::GetGameContext()->PushMessage(Message(MSG_SIM_SEAT_PLAYER_REQUESTED, (void*)actor)); diff --git a/source/main/main.cpp b/source/main/main.cpp index 2fc7c76efc..fa93d4aaf9 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -629,6 +629,36 @@ int main(int argc, char *argv[]) } break; + case MSG_SIM_HIDE_NET_ACTOR_REQUESTED: + if (App::mp_state->GetEnum() == MpState::CONNECTED && + ((Actor*)m.payload)->ar_sim_state == Actor::SimState::NETWORKED_OK) + { + Actor* actor = (Actor*)m.payload; + actor->ar_sim_state = Actor::SimState::NETWORKED_HIDDEN; // Stop net. updates + App::GetGfxScene()->RemoveGfxActor(actor->GetGfxActor()); // Remove visuals + actor->GetGfxActor()->SetFlexbodyVisible(false); + actor->GetGfxActor()->SetWheelsVisible(false); + actor->GetGfxActor()->SetAllMeshesVisible(false); + actor->GetGfxActor()->SetCastShadows(false); + actor->GetGfxActor()->SetRodsVisible(false); + } + break; + + case MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED: + if (App::mp_state->GetEnum() == MpState::CONNECTED && + ((Actor*)m.payload)->ar_sim_state == Actor::SimState::NETWORKED_HIDDEN) + { + Actor* actor = (Actor*)m.payload; + actor->ar_sim_state = Actor::SimState::NETWORKED_OK; // Resume net. updates + App::GetGfxScene()->RegisterGfxActor(actor->GetGfxActor()); // Restore visuals + actor->GetGfxActor()->SetFlexbodyVisible(true); + actor->GetGfxActor()->SetWheelsVisible(true); + actor->GetGfxActor()->SetAllMeshesVisible(true); + actor->GetGfxActor()->SetCastShadows(true); + actor->GetGfxActor()->SetRodsVisible(true); + } + break; + // -- GUI events --- case MSG_GUI_OPEN_MENU_REQUESTED: diff --git a/source/main/physics/Actor.h b/source/main/physics/Actor.h index 4aeaee4e3d..746c9f5522 100644 --- a/source/main/physics/Actor.h +++ b/source/main/physics/Actor.h @@ -48,6 +48,7 @@ class Actor : public ZeroedMemoryAllocator { LOCAL_SIMULATED, //!< simulated (local) actor NETWORKED_OK, //!< not simulated (remote) actor + NETWORKED_HIDDEN, //!< not simulated, not updated (remote) LOCAL_REPLAY, LOCAL_SLEEPING, //!< sleeping (local) actor }; From 6f01450207e1dd3efcb993656898068eced4d01e Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Fri, 11 Jun 2021 22:35:24 +0300 Subject: [PATCH 02/24] use eject button --- source/main/gui/panels/GUI_TopMenubar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/main/gui/panels/GUI_TopMenubar.cpp b/source/main/gui/panels/GUI_TopMenubar.cpp index 77a9b2c188..361c7edbe6 100644 --- a/source/main/gui/panels/GUI_TopMenubar.cpp +++ b/source/main/gui/panels/GUI_TopMenubar.cpp @@ -745,7 +745,7 @@ void TopMenubar::DrawMpUserToActorList(RoRnet::UserInfo &user) // Display actor list Ogre::TexturePtr tex1 = FetchIcon("control_pause.png"); Ogre::TexturePtr tex2 = FetchIcon("control_play.png"); - Ogre::TexturePtr tex3 = FetchIcon("delete.png"); + Ogre::TexturePtr tex3 = FetchIcon("control_eject.png"); int i = 0; for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { From a6a5b0e9afa172a8216e9dcba6f4d2e2cdb3c9d0 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 13 Sep 2021 20:50:49 +0200 Subject: [PATCH 03/24] :triangular_ruler: Reorganized actor state enum + variable. Mostly just find&replace, except: 1. Moved enumeration `Actor::SimState` from "Actor.h" to "SimData.h" and renamed to `ActorState` . 2. Actor.h: Renamed `Actor::ar_sim_state` to `Actor::ar_state`, added include Differentials. 3. Differentials.h/cpp: added namespace RoR --- source/main/GameContext.cpp | 6 +- source/main/gameplay/RecoveryMode.cpp | 4 +- source/main/gameplay/Replay.cpp | 8 +-- source/main/gameplay/SceneMouse.cpp | 2 +- source/main/gfx/GfxActor.cpp | 8 +-- source/main/gfx/camera/CameraManager.cpp | 4 +- source/main/gui/panels/GUI_SurveyMap.cpp | 4 +- source/main/gui/panels/GUI_TopMenubar.cpp | 12 ++-- source/main/main.cpp | 16 ++--- source/main/physics/Actor.cpp | 16 ++--- source/main/physics/Actor.h | 16 ++--- source/main/physics/ActorForcesEuler.cpp | 2 +- source/main/physics/ActorManager.cpp | 72 +++++++++---------- source/main/physics/ActorSpawner.cpp | 8 +-- source/main/physics/Differentials.cpp | 2 + source/main/physics/Differentials.h | 4 ++ source/main/physics/Savegame.cpp | 4 +- source/main/physics/SimData.h | 8 +++ .../physics/collision/DynamicCollisions.cpp | 2 +- source/main/scripting/GameScript.cpp | 2 +- source/main/scripting/ScriptEngine.cpp | 6 +- 21 files changed, 107 insertions(+), 99 deletions(-) diff --git a/source/main/GameContext.cpp b/source/main/GameContext.cpp index 21afc6cc7d..cd0726eb9c 100644 --- a/source/main/GameContext.cpp +++ b/source/main/GameContext.cpp @@ -291,9 +291,9 @@ void GameContext::ModifyActor(ActorModifyRequest& rq) m_actor_manager.RestoreSavedState(rq.amr_actor, *rq.amr_saved_state.get()); } else if (rq.amr_type == ActorModifyRequest::Type::WAKE_UP && - rq.amr_actor->ar_sim_state == Actor::SimState::LOCAL_SLEEPING) + rq.amr_actor->ar_state == ActorState::LOCAL_SLEEPING) { - rq.amr_actor->ar_sim_state = Actor::SimState::LOCAL_SIMULATED; + rq.amr_actor->ar_state = ActorState::LOCAL_SIMULATED; rq.amr_actor->ar_sleep_counter = 0.0f; } else if (rq.amr_type == ActorModifyRequest::Type::RELOAD) @@ -886,7 +886,7 @@ void GameContext::UpdateSimInputEvents(float dt) else // We're in a vehicle -> If moving slowly enough, get out { if (this->GetPlayerActor()->ar_nodes[0].Velocity.squaredLength() < 1.0f || - this->GetPlayerActor()->ar_sim_state == Actor::SimState::NETWORKED_OK) + this->GetPlayerActor()->ar_state == ActorState::NETWORKED_OK) { this->PushMessage(Message(MSG_SIM_SEAT_PLAYER_REQUESTED, nullptr)); } diff --git a/source/main/gameplay/RecoveryMode.cpp b/source/main/gameplay/RecoveryMode.cpp index 3712bcabfd..f2b67a324e 100644 --- a/source/main/gameplay/RecoveryMode.cpp +++ b/source/main/gameplay/RecoveryMode.cpp @@ -30,8 +30,8 @@ void RecoveryMode::UpdateInputEvents(float dt) { if (App::sim_state->getEnum() != SimState::RUNNING && App::GetGameContext()->GetPlayerActor() && - App::GetGameContext()->GetPlayerActor()->ar_sim_state != Actor::SimState::NETWORKED_OK && - App::GetGameContext()->GetPlayerActor()->ar_sim_state != Actor::SimState::LOCAL_REPLAY) + App::GetGameContext()->GetPlayerActor()->ar_state != ActorState::NETWORKED_OK && + App::GetGameContext()->GetPlayerActor()->ar_state != ActorState::LOCAL_REPLAY) { return; } diff --git a/source/main/gameplay/Replay.cpp b/source/main/gameplay/Replay.cpp index de65e1cd15..b2fbc779b2 100644 --- a/source/main/gameplay/Replay.cpp +++ b/source/main/gameplay/Replay.cpp @@ -250,13 +250,13 @@ void Replay::UpdateInputEvents() { if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_TOGGLE_REPLAY_MODE)) { - if (m_actor->ar_sim_state == Actor::SimState::LOCAL_REPLAY) - m_actor->ar_sim_state = Actor::SimState::LOCAL_SIMULATED; + if (m_actor->ar_state == ActorState::LOCAL_REPLAY) + m_actor->ar_state = ActorState::LOCAL_SIMULATED; else - m_actor->ar_sim_state = Actor::SimState::LOCAL_REPLAY; + m_actor->ar_state = ActorState::LOCAL_REPLAY; } - if (m_actor->ar_sim_state == Actor::SimState::LOCAL_REPLAY) + if (m_actor->ar_state == ActorState::LOCAL_REPLAY) { if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_REPLAY_FORWARD, 0.1f) && this->ar_replay_pos <= 0) { diff --git a/source/main/gameplay/SceneMouse.cpp b/source/main/gameplay/SceneMouse.cpp index c062f8d2dc..3455d8ba07 100644 --- a/source/main/gameplay/SceneMouse.cpp +++ b/source/main/gameplay/SceneMouse.cpp @@ -127,7 +127,7 @@ bool SceneMouse::mouseMoved(const OIS::MouseEvent& _arg) grab_truck = NULL; for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { - if (actor->ar_sim_state == Actor::SimState::LOCAL_SIMULATED) + if (actor->ar_state == ActorState::LOCAL_SIMULATED) { // check if our ray intersects with the bounding box of the truck std::pair pair = mouseRay.intersects(actor->ar_bounding_box); diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index a035f0b5b6..546d56c265 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -1726,7 +1726,7 @@ void RoR::GfxActor::SetRodsVisible(bool visible) void RoR::GfxActor::UpdateSimDataBuffer() { - m_simbuf.simbuf_live_local = (m_actor->ar_sim_state == Actor::SimState::LOCAL_SIMULATED); + m_simbuf.simbuf_live_local = (m_actor->ar_state == ActorState::LOCAL_SIMULATED); m_simbuf.simbuf_physics_paused = m_actor->ar_physics_paused; m_simbuf.simbuf_pos = m_actor->getRotationCenter(); m_simbuf.simbuf_rotation = m_actor->getRotation(); @@ -1749,7 +1749,7 @@ void RoR::GfxActor::UpdateSimDataBuffer() m_simbuf.simbuf_top_speed = m_actor->ar_top_speed; m_simbuf.simbuf_node0_velo = m_actor->ar_nodes[0].Velocity; m_simbuf.simbuf_net_username = m_actor->m_net_username; - m_simbuf.simbuf_is_remote = m_actor->ar_sim_state == Actor::SimState::NETWORKED_OK; + m_simbuf.simbuf_is_remote = m_actor->ar_state == ActorState::NETWORKED_OK; // nodes const int num_nodes = m_actor->ar_num_nodes; @@ -1875,7 +1875,7 @@ void RoR::GfxActor::UpdateSimDataBuffer() bool RoR::GfxActor::IsActorLive() const { - return (m_actor->ar_sim_state < Actor::SimState::LOCAL_SLEEPING); + return (m_actor->ar_state < ActorState::LOCAL_SLEEPING); } void RoR::GfxActor::UpdateCabMesh() @@ -1953,7 +1953,7 @@ void RoR::GfxActor::SetWheelsVisible(bool value) int RoR::GfxActor::GetActorId () const { return m_actor->ar_instance_id; } -int RoR::GfxActor::GetActorState () const { return static_cast(m_actor->ar_sim_state); } +int RoR::GfxActor::GetActorState () const { return static_cast(m_actor->ar_state); } ActorType RoR::GfxActor::GetActorDriveable() const { diff --git a/source/main/gfx/camera/CameraManager.cpp b/source/main/gfx/camera/CameraManager.cpp index 3deefe6b85..9a91b15eac 100644 --- a/source/main/gfx/camera/CameraManager.cpp +++ b/source/main/gfx/camera/CameraManager.cpp @@ -718,7 +718,7 @@ void CameraManager::UpdateCameraBehaviorStatic() angle = (m_staticcam_look_at - m_staticcam_position).angleBetween(velocity); speed = velocity.normalise(); - if (m_cct_player_actor->ar_sim_state == Actor::SimState::LOCAL_REPLAY) + if (m_cct_player_actor->ar_state == ActorState::LOCAL_REPLAY) { speed *= m_cct_player_actor->getReplay()->getPrecision(); } @@ -918,7 +918,7 @@ void CameraManager::CameraBehaviorOrbitUpdate() } else { - if (m_cct_player_actor && m_cct_player_actor->ar_sim_state == Actor::SimState::LOCAL_REPLAY && camDisplacement != Vector3::ZERO) + if (m_cct_player_actor && m_cct_player_actor->ar_state == ActorState::LOCAL_REPLAY && camDisplacement != Vector3::ZERO) this->GetCameraNode()->setPosition(desiredPosition); else this->GetCameraNode()->setPosition(camPosition); diff --git a/source/main/gui/panels/GUI_SurveyMap.cpp b/source/main/gui/panels/GUI_SurveyMap.cpp index d031cd6d2b..2155cff5fd 100644 --- a/source/main/gui/panels/GUI_SurveyMap.cpp +++ b/source/main/gui/panels/GUI_SurveyMap.cpp @@ -201,9 +201,9 @@ void SurveyMap::Draw() int truckstate = gfx_actor->GetActorState(); Str<100> fileName; - if (truckstate == static_cast(Actor::SimState::LOCAL_SIMULATED)) + if (truckstate == static_cast(ActorState::LOCAL_SIMULATED)) fileName << "icon_" << type_str << "_activated.dds"; // green icon - else if (truckstate == static_cast(Actor::SimState::NETWORKED_OK)) + else if (truckstate == static_cast(ActorState::NETWORKED_OK)) fileName << "icon_" << type_str << "_networked.dds"; // blue icon else fileName << "icon_" << type_str << ".dds"; // gray icon diff --git a/source/main/gui/panels/GUI_TopMenubar.cpp b/source/main/gui/panels/GUI_TopMenubar.cpp index 361c7edbe6..524ce41001 100644 --- a/source/main/gui/panels/GUI_TopMenubar.cpp +++ b/source/main/gui/panels/GUI_TopMenubar.cpp @@ -189,7 +189,7 @@ void TopMenubar::Update() App::GetGuiManager()->SetVisible_VehicleDescription(true); } - if (current_actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + if (current_actor->ar_state != ActorState::NETWORKED_OK) { if (ImGui::Button(_LC("TopMenubar", "Reload current vehicle"))) { @@ -244,7 +244,7 @@ void TopMenubar::Update() for (auto actor : App::GetGameContext()->GetActorManager()->GetLocalActors()) { if (!actor->ar_hide_in_actor_list && !actor->isPreloadedWithTerrain() && - actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + actor->ar_state != ActorState::NETWORKED_OK) { App::GetGameContext()->PushMessage(Message(MSG_SIM_DELETE_ACTOR_REQUESTED, (void*)actor)); } @@ -753,14 +753,14 @@ void TopMenubar::DrawMpUserToActorList(RoRnet::UserInfo &user) { std::string id = fmt::format("{}:{}", i++, user.uniqueid); ImGui::PushID(id.c_str()); - if (actor->ar_sim_state == Actor::SimState::NETWORKED_OK) + if (actor->ar_state == ActorState::NETWORKED_OK) { if (ImGui::ImageButton(reinterpret_cast(tex1->getHandle()), ImVec2(16, 16))) { App::GetGameContext()->PushMessage(Message(MSG_SIM_HIDE_NET_ACTOR_REQUESTED, (void*)actor)); } } - else if (actor->ar_sim_state == Actor::SimState::NETWORKED_HIDDEN) + else if (actor->ar_state == ActorState::NETWORKED_HIDDEN) { if (ImGui::ImageButton(reinterpret_cast(tex2->getHandle()), ImVec2(16, 16))) { @@ -828,7 +828,7 @@ void TopMenubar::DrawActorListSinglePlayer() { ImGui::PushStyleColor(ImGuiCol_Text, ORANGE_TEXT); } - else if (actor->ar_sim_state == Actor::SimState::LOCAL_SIMULATED) + else if (actor->ar_state == ActorState::LOCAL_SIMULATED) { ImGui::PushStyleColor(ImGuiCol_Text, WHITE_TEXT); } @@ -875,7 +875,7 @@ void TopMenubar::DrawSpecialStateBox(float top_offset) content_width = ImGui::CalcTextSize(special_text.c_str()).x; } else if (App::GetGameContext()->GetPlayerActor() && - App::GetGameContext()->GetPlayerActor()->ar_sim_state == Actor::SimState::LOCAL_REPLAY) + App::GetGameContext()->GetPlayerActor()->ar_state == ActorState::LOCAL_REPLAY) { content_width = 300; replay_box = true; diff --git a/source/main/main.cpp b/source/main/main.cpp index fa93d4aaf9..7721dd1ad6 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -630,11 +630,11 @@ int main(int argc, char *argv[]) break; case MSG_SIM_HIDE_NET_ACTOR_REQUESTED: - if (App::mp_state->GetEnum() == MpState::CONNECTED && - ((Actor*)m.payload)->ar_sim_state == Actor::SimState::NETWORKED_OK) + if (App::mp_state->getEnum() == MpState::CONNECTED && + ((Actor*)m.payload)->ar_state == ActorState::NETWORKED_OK) { Actor* actor = (Actor*)m.payload; - actor->ar_sim_state = Actor::SimState::NETWORKED_HIDDEN; // Stop net. updates + actor->ar_state = ActorState::NETWORKED_HIDDEN; // Stop net. updates App::GetGfxScene()->RemoveGfxActor(actor->GetGfxActor()); // Remove visuals actor->GetGfxActor()->SetFlexbodyVisible(false); actor->GetGfxActor()->SetWheelsVisible(false); @@ -645,11 +645,11 @@ int main(int argc, char *argv[]) break; case MSG_SIM_UNHIDE_NET_ACTOR_REQUESTED: - if (App::mp_state->GetEnum() == MpState::CONNECTED && - ((Actor*)m.payload)->ar_sim_state == Actor::SimState::NETWORKED_HIDDEN) + if (App::mp_state->getEnum() == MpState::CONNECTED && + ((Actor*)m.payload)->ar_state == ActorState::NETWORKED_HIDDEN) { Actor* actor = (Actor*)m.payload; - actor->ar_sim_state = Actor::SimState::NETWORKED_OK; // Resume net. updates + actor->ar_state = ActorState::NETWORKED_OK; // Resume net. updates App::GetGfxScene()->RegisterGfxActor(actor->GetGfxActor()); // Restore visuals actor->GetGfxActor()->SetFlexbodyVisible(true); actor->GetGfxActor()->SetWheelsVisible(true); @@ -818,10 +818,10 @@ int main(int argc, char *argv[]) App::GetGameContext()->UpdateSimInputEvents(dt); App::GetGameContext()->UpdateSkyInputEvents(dt); if (App::GetGameContext()->GetPlayerActor() && - App::GetGameContext()->GetPlayerActor()->ar_sim_state != Actor::SimState::NETWORKED_OK) // we are in a vehicle + App::GetGameContext()->GetPlayerActor()->ar_state != ActorState::NETWORKED_OK) // we are in a vehicle { App::GetGameContext()->UpdateCommonInputEvents(dt); - if (App::GetGameContext()->GetPlayerActor()->ar_sim_state != Actor::SimState::LOCAL_REPLAY) + if (App::GetGameContext()->GetPlayerActor()->ar_state != ActorState::LOCAL_REPLAY) { if (App::GetGameContext()->GetPlayerActor()->ar_driveable == TRUCK) { diff --git a/source/main/physics/Actor.cpp b/source/main/physics/Actor.cpp index 5f3fae82c1..4e194cf43c 100644 --- a/source/main/physics/Actor.cpp +++ b/source/main/physics/Actor.cpp @@ -2948,11 +2948,11 @@ void Actor::lightsToggle() { // export light command Actor* player_actor = App::GetGameContext()->GetPlayerActor(); - if (ar_sim_state == Actor::SimState::LOCAL_SIMULATED && this == player_actor && ar_forward_commands) + if (ar_state == ActorState::LOCAL_SIMULATED && this == player_actor && ar_forward_commands) { for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { - if (actor->ar_sim_state == Actor::SimState::LOCAL_SIMULATED && this != actor && actor->ar_import_commands) + if (actor->ar_state == ActorState::LOCAL_SIMULATED && this != actor && actor->ar_import_commands) actor->lightsToggle(); } } @@ -3171,7 +3171,7 @@ void Actor::updateVisual(float dt) #ifdef USE_OPENAL //airplane radio chatter - if (ar_driveable == AIRPLANE && ar_sim_state != SimState::LOCAL_SLEEPING) + if (ar_driveable == AIRPLANE && ar_state != ActorState::LOCAL_SLEEPING) { // play random chatter at random time m_avionic_chatter_timer -= dt; @@ -3420,7 +3420,7 @@ void Actor::tieToggle(int group) // iterate over all actors for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { - if (actor->ar_sim_state == SimState::LOCAL_SLEEPING || + if (actor->ar_state == ActorState::LOCAL_SLEEPING || (actor == this && it->ti_no_self_lock)) { continue; @@ -3549,7 +3549,7 @@ void Actor::ropeToggle(int group) // iterate over all actor_slots for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { - if (actor->ar_sim_state == SimState::LOCAL_SLEEPING) + if (actor->ar_state == ActorState::LOCAL_SLEEPING) continue; // and their ropables for (std::vector::iterator itr = actor->ar_ropables.begin(); itr != actor->ar_ropables.end(); itr++) @@ -3658,7 +3658,7 @@ void Actor::hookToggle(int group, HookAction mode, int node_number) // iterate over all actor_slots for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { - if (actor->ar_sim_state == SimState::LOCAL_SLEEPING) + if (actor->ar_state == ActorState::LOCAL_SLEEPING) continue; if (this == actor && !it->hk_selflock) continue; // don't lock to self @@ -3780,7 +3780,7 @@ void Actor::beaconsToggle() bool Actor::getReverseLightVisible() { - if (ar_sim_state == SimState::NETWORKED_OK) + if (ar_state == ActorState::NETWORKED_OK) return m_net_reverse_light_on; if (ar_engine) @@ -4496,7 +4496,7 @@ void Actor::setMass(float m) bool Actor::getBrakeLightVisible() { - if (ar_sim_state == SimState::NETWORKED_OK) + if (ar_state == ActorState::NETWORKED_OK) return m_net_brake_light_on; return (ar_brake > 0.01f && !ar_parking_brake); diff --git a/source/main/physics/Actor.h b/source/main/physics/Actor.h index 746c9f5522..49b02f5929 100644 --- a/source/main/physics/Actor.h +++ b/source/main/physics/Actor.h @@ -22,12 +22,13 @@ #pragma once #include "Application.h" -#include "SimData.h" #include "CmdKeyInertia.h" +#include "Differentials.h" #include "GfxActor.h" #include "MovableText.h" #include "PerVehicleCameraContext.h" #include "RigDef_Prerequisites.h" +#include "SimData.h" #include "TyrePressure.h" #include @@ -44,15 +45,6 @@ class Actor : public ZeroedMemoryAllocator friend class OutGauge; public: - enum class SimState - { - LOCAL_SIMULATED, //!< simulated (local) actor - NETWORKED_OK, //!< not simulated (remote) actor - NETWORKED_HIDDEN, //!< not simulated, not updated (remote) - LOCAL_REPLAY, - LOCAL_SLEEPING, //!< sleeping (local) actor - }; - Actor( int actor_id , unsigned int vector_index @@ -360,11 +352,13 @@ class Actor : public ZeroedMemoryAllocator Ogre::Timer ar_net_timer; unsigned long ar_net_last_update_time; DashBoardManager* ar_dashboard; - SimState ar_sim_state; //!< Sim state float ar_collision_range; //!< Physics attr float ar_top_speed; //!< Sim state ground_model_t* ar_last_fuzzy_ground_model; //!< GUI state + // Gameplay state + ActorState ar_state; + // Realtime node/beam structure editing helpers bool ar_nb_initialized; std::vector ar_nb_optimum; //!< Temporary storage of the optimum search result diff --git a/source/main/physics/ActorForcesEuler.cpp b/source/main/physics/ActorForcesEuler.cpp index c82497c45f..b043e03aea 100644 --- a/source/main/physics/ActorForcesEuler.cpp +++ b/source/main/physics/ActorForcesEuler.cpp @@ -1098,7 +1098,7 @@ bool Actor::CalcForcesEulerPrepare(bool doUpdate) return false; if (ar_physics_paused) return false; - if (ar_sim_state != Actor::SimState::LOCAL_SIMULATED) + if (ar_state != ActorState::LOCAL_SIMULATED) return false; if (doUpdate) diff --git a/source/main/physics/ActorManager.cpp b/source/main/physics/ActorManager.cpp index 074fe4a113..e09d6d9307 100644 --- a/source/main/physics/ActorManager.cpp +++ b/source/main/physics/ActorManager.cpp @@ -291,7 +291,7 @@ void ActorManager::SetupActor(Actor* actor, ActorSpawnRequest rq, std::shared_pt actor->getTyrePressure().ModifyTyrePressure(0.f); // Initialize springiness of pressure-beams. } - actor->ar_sim_state = Actor::SimState::LOCAL_SLEEPING; + actor->ar_state = ActorState::LOCAL_SLEEPING; if (App::mp_state->getEnum() == RoR::MpState::CONNECTED) { @@ -306,7 +306,7 @@ void ActorManager::SetupActor(Actor* actor, ActorSpawnRequest rq, std::shared_pt if (rq.asr_origin == ActorSpawnRequest::Origin::NETWORK) { - actor->ar_sim_state = Actor::SimState::NETWORKED_OK; + actor->ar_state = ActorState::NETWORKED_OK; if (actor->ar_engine) { actor->ar_engine->StartEngine(); @@ -360,7 +360,7 @@ void ActorManager::RemoveStreamSource(int sourceid) for (auto actor : m_actors) { - if (actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + if (actor->ar_state != ActorState::NETWORKED_OK) continue; if (actor->ar_net_source_id == sourceid) @@ -483,7 +483,7 @@ void ActorManager::HandleActorStreamData(std::vector packet_ else if (packet.header.command == RoRnet::MSG2_STREAM_UNREGISTER) { Actor* b = this->GetActorByNetworkLinks(packet.header.source, packet.header.streamid); - if (b && b->ar_sim_state == Actor::SimState::NETWORKED_OK) + if (b && b->ar_state == ActorState::NETWORKED_OK) { App::GetGameContext()->PushMessage(Message(MSG_SIM_DELETE_ACTOR_REQUESTED, (void*)b)); } @@ -497,7 +497,7 @@ void ActorManager::HandleActorStreamData(std::vector packet_ { for (auto actor : m_actors) { - if (actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + if (actor->ar_state != ActorState::NETWORKED_OK) continue; if (packet.header.source == actor->ar_net_source_id && packet.header.streamid == actor->ar_net_stream_id) { @@ -535,7 +535,7 @@ int ActorManager::CheckNetworkStreamsOk(int sourceid) for (auto actor : m_actors) { - if (actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + if (actor->ar_state != ActorState::NETWORKED_OK) continue; if (actor->ar_net_source_id == sourceid) @@ -553,7 +553,7 @@ int ActorManager::CheckNetRemoteStreamsOk(int sourceid) for (auto actor : m_actors) { - if (actor->ar_sim_state == Actor::SimState::NETWORKED_OK) + if (actor->ar_state == ActorState::NETWORKED_OK) continue; int stream_result = actor->ar_net_stream_results[sourceid]; @@ -639,7 +639,7 @@ bool ActorManager::PredictActorCollAabbIntersect(int a, int b) void ActorManager::RecursiveActivation(int j, std::vector& visited) { - if (visited[j] || m_actors[j]->ar_sim_state != Actor::SimState::LOCAL_SIMULATED) + if (visited[j] || m_actors[j]->ar_state != ActorState::LOCAL_SIMULATED) return; visited[j] = true; @@ -648,15 +648,15 @@ void ActorManager::RecursiveActivation(int j, std::vector& visited) { if (t == j || visited[t]) continue; - if (m_actors[t]->ar_sim_state == Actor::SimState::LOCAL_SIMULATED && CheckActorCollAabbIntersect(t, j)) + if (m_actors[t]->ar_state == ActorState::LOCAL_SIMULATED && CheckActorCollAabbIntersect(t, j)) { m_actors[t]->ar_sleep_counter = 0.0f; this->RecursiveActivation(t, visited); } - if (m_actors[t]->ar_sim_state == Actor::SimState::LOCAL_SLEEPING && PredictActorCollAabbIntersect(t, j)) + if (m_actors[t]->ar_state == ActorState::LOCAL_SLEEPING && PredictActorCollAabbIntersect(t, j)) { m_actors[t]->ar_sleep_counter = 0.0f; - m_actors[t]->ar_sim_state = Actor::SimState::LOCAL_SIMULATED; + m_actors[t]->ar_state = ActorState::LOCAL_SIMULATED; this->RecursiveActivation(t, visited); } } @@ -675,10 +675,10 @@ void ActorManager::ForwardCommands(Actor* source_actor) actor->m_min_camera_radius + source_actor->m_min_camera_radius)) { // activate the truck - if (actor->ar_sim_state == Actor::SimState::LOCAL_SLEEPING) + if (actor->ar_state == ActorState::LOCAL_SLEEPING) { actor->ar_sleep_counter = 0.0f; - actor->ar_sim_state = Actor::SimState::LOCAL_SIMULATED; + actor->ar_state = ActorState::LOCAL_SIMULATED; } if (App::sim_realistic_commands->getBool()) @@ -730,7 +730,7 @@ void ActorManager::UpdateSleepingState(Actor* player_actor, float dt) { for (auto actor : m_actors) { - if (actor->ar_sim_state != Actor::SimState::LOCAL_SIMULATED) + if (actor->ar_state != ActorState::LOCAL_SIMULATED) continue; if (actor->getVelocity().squaredLength() > 0.01f) { @@ -742,19 +742,19 @@ void ActorManager::UpdateSleepingState(Actor* player_actor, float dt) if (actor->ar_sleep_counter >= 10.0f) { - actor->ar_sim_state = Actor::SimState::LOCAL_SLEEPING; + actor->ar_state = ActorState::LOCAL_SLEEPING; } } } - if (player_actor && player_actor->ar_sim_state == Actor::SimState::LOCAL_SLEEPING) + if (player_actor && player_actor->ar_state == ActorState::LOCAL_SLEEPING) { - player_actor->ar_sim_state = Actor::SimState::LOCAL_SIMULATED; + player_actor->ar_state = ActorState::LOCAL_SIMULATED; } std::vector visited(m_actors.size()); // Recursivly activate all actors which can be reached from current actor - if (player_actor && player_actor->ar_sim_state == Actor::SimState::LOCAL_SIMULATED) + if (player_actor && player_actor->ar_state == ActorState::LOCAL_SIMULATED) { player_actor->ar_sleep_counter = 0.0f; this->RecursiveActivation(player_actor->ar_vector_index, visited); @@ -762,7 +762,7 @@ void ActorManager::UpdateSleepingState(Actor* player_actor, float dt) // Snowball effect (activate all actors which might soon get hit by a moving actor) for (unsigned int t = 0; t < m_actors.size(); t++) { - if (m_actors[t]->ar_sim_state == Actor::SimState::LOCAL_SIMULATED && m_actors[t]->ar_sleep_counter == 0.0f) + if (m_actors[t]->ar_state == ActorState::LOCAL_SIMULATED && m_actors[t]->ar_sleep_counter == 0.0f) this->RecursiveActivation(t, visited); } } @@ -771,9 +771,9 @@ void ActorManager::WakeUpAllActors() { for (auto actor : m_actors) { - if (actor->ar_sim_state == Actor::SimState::LOCAL_SLEEPING) + if (actor->ar_state == ActorState::LOCAL_SLEEPING) { - actor->ar_sim_state = Actor::SimState::LOCAL_SIMULATED; + actor->ar_state = ActorState::LOCAL_SIMULATED; actor->ar_sleep_counter = 0.0f; } } @@ -784,9 +784,9 @@ void ActorManager::SendAllActorsSleeping() m_forced_awake = false; for (auto actor : m_actors) { - if (actor->ar_sim_state == Actor::SimState::LOCAL_SIMULATED) + if (actor->ar_state == ActorState::LOCAL_SIMULATED) { - actor->ar_sim_state = Actor::SimState::LOCAL_SLEEPING; + actor->ar_state = ActorState::LOCAL_SLEEPING; } } } @@ -880,7 +880,7 @@ void ActorManager::DeleteActorInternal(Actor* actor) #ifdef USE_SOCKETW if (App::mp_state->getEnum() == RoR::MpState::CONNECTED) { - if (actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + if (actor->ar_state != ActorState::NETWORKED_OK) { App::GetNetwork()->AddPacket(actor->ar_net_stream_id, RoRnet::MSG2_STREAM_UNREGISTER, 0, 0); } @@ -916,7 +916,7 @@ Actor* ActorManager::FetchNextVehicleOnList(Actor* player, Actor* prev_player) for (int i = pivot_index + 1; i < m_actors.size(); i++) { - if (m_actors[i]->ar_sim_state != Actor::SimState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) + if (m_actors[i]->ar_state != ActorState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) { return m_actors[i]; } @@ -924,13 +924,13 @@ Actor* ActorManager::FetchNextVehicleOnList(Actor* player, Actor* prev_player) for (int i = 0; i < pivot_index; i++) { - if (m_actors[i]->ar_sim_state != Actor::SimState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) + if (m_actors[i]->ar_state != ActorState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) { return m_actors[i]; } } - if (pivot_index >= 0 && m_actors[pivot_index]->ar_sim_state != Actor::SimState::NETWORKED_OK && !m_actors[pivot_index]->isPreloadedWithTerrain()) + if (pivot_index >= 0 && m_actors[pivot_index]->ar_state != ActorState::NETWORKED_OK && !m_actors[pivot_index]->isPreloadedWithTerrain()) { return m_actors[pivot_index]; } @@ -944,7 +944,7 @@ Actor* ActorManager::FetchPreviousVehicleOnList(Actor* player, Actor* prev_playe for (int i = pivot_index - 1; i >= 0; i--) { - if (m_actors[i]->ar_sim_state != Actor::SimState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) + if (m_actors[i]->ar_state != ActorState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) { return m_actors[i]; } @@ -952,13 +952,13 @@ Actor* ActorManager::FetchPreviousVehicleOnList(Actor* player, Actor* prev_playe for (int i = static_cast(m_actors.size()) - 1; i > pivot_index; i--) { - if (m_actors[i]->ar_sim_state != Actor::SimState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) + if (m_actors[i]->ar_state != ActorState::NETWORKED_OK && !m_actors[i]->isPreloadedWithTerrain()) { return m_actors[i]; } } - if (pivot_index >= 0 && m_actors[pivot_index]->ar_sim_state != Actor::SimState::NETWORKED_OK && !m_actors[pivot_index]->isPreloadedWithTerrain()) + if (pivot_index >= 0 && m_actors[pivot_index]->ar_state != ActorState::NETWORKED_OK && !m_actors[pivot_index]->isPreloadedWithTerrain()) { return m_actors[pivot_index]; } @@ -1017,7 +1017,7 @@ void ActorManager::UpdateActors(Actor* player_actor) { this->UpdateTruckFeatures(actor, dt); } - if (actor->ar_sim_state == Actor::SimState::LOCAL_SLEEPING) + if (actor->ar_state == ActorState::LOCAL_SLEEPING) { actor->ar_engine->UpdateEngineSim(dt, 1); } @@ -1030,7 +1030,7 @@ void ActorManager::UpdateActors(Actor* player_actor) // Blinkers (turn signals) must always be updated actor->updateFlareStates(dt); - if (actor->ar_sim_state != Actor::SimState::LOCAL_SLEEPING) + if (actor->ar_state != ActorState::LOCAL_SLEEPING) { actor->updateVisual(dt); if (actor->ar_update_physics && App::gfx_skidmarks_mode->getInt() > 0) @@ -1040,7 +1040,7 @@ void ActorManager::UpdateActors(Actor* player_actor) } if (App::mp_state->getEnum() == RoR::MpState::CONNECTED) { - if (actor->ar_sim_state == Actor::SimState::NETWORKED_OK) + if (actor->ar_state == ActorState::NETWORKED_OK) actor->calcNetwork(); else actor->sendStreamData(); @@ -1063,7 +1063,7 @@ void ActorManager::UpdateActors(Actor* player_actor) player_actor->ForceFeedbackStep(m_physics_steps); - if (player_actor->ar_sim_state == Actor::SimState::LOCAL_REPLAY) + if (player_actor->ar_state == ActorState::LOCAL_REPLAY) { player_actor->getReplay()->replayStepActor(); } @@ -1128,7 +1128,7 @@ void ActorManager::UpdatePhysicsSimulation() for (auto actor : m_actors) { if (actor->m_inter_point_col_detector != nullptr && (actor->ar_update_physics || - (App::mp_pseudo_collisions->getBool() && actor->ar_sim_state == Actor::SimState::NETWORKED_OK))) + (App::mp_pseudo_collisions->getBool() && actor->ar_state == ActorState::NETWORKED_OK))) { auto func = std::function([this, actor]() { @@ -1280,7 +1280,7 @@ std::vector ActorManager::GetLocalActors() std::vector actors; for (auto actor : m_actors) { - if (actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + if (actor->ar_state != ActorState::NETWORKED_OK) actors.push_back(actor); } return actors; diff --git a/source/main/physics/ActorSpawner.cpp b/source/main/physics/ActorSpawner.cpp index e28876f763..57cc2df323 100644 --- a/source/main/physics/ActorSpawner.cpp +++ b/source/main/physics/ActorSpawner.cpp @@ -280,7 +280,7 @@ void ActorSpawner::InitializeRig() m_actor->ar_num_cinecams=0; m_actor->m_deletion_scene_nodes.clear(); - m_actor->ar_sim_state = Actor::SimState::LOCAL_SLEEPING; + m_actor->ar_state = ActorState::LOCAL_SLEEPING; m_actor->m_fusealge_airfoil = nullptr; m_actor->m_fusealge_front = nullptr; m_actor->m_fusealge_back = nullptr; @@ -660,7 +660,7 @@ void ActorSpawner::ProcessTurbojet(RigDef::Turbojet & def) m_actor->ar_aeroengines[m_actor->ar_num_aeroengines]=tj; m_actor->ar_driveable=AIRPLANE; - if (m_actor->ar_autopilot == nullptr && m_actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + if (m_actor->ar_autopilot == nullptr && m_actor->ar_state != ActorState::NETWORKED_OK) { m_actor->ar_autopilot=new Autopilot(m_actor->ar_instance_id); } @@ -783,7 +783,7 @@ void ActorSpawner::BuildAerialEngine( m_actor->ar_driveable = AIRPLANE; /* Autopilot */ - if (m_actor->ar_autopilot == nullptr && m_actor->ar_sim_state != Actor::SimState::NETWORKED_OK) + if (m_actor->ar_autopilot == nullptr && m_actor->ar_state != ActorState::NETWORKED_OK) { m_actor->ar_autopilot = new Autopilot(m_actor->ar_instance_id); } @@ -910,7 +910,7 @@ void ActorSpawner::ProcessWing(RigDef::Wing & def) def.max_deflection, def.airfoil, def.efficacy_coef, - m_actor->ar_sim_state != Actor::SimState::NETWORKED_OK + m_actor->ar_state != ActorState::NETWORKED_OK ); Ogre::Entity* entity = nullptr; diff --git a/source/main/physics/Differentials.cpp b/source/main/physics/Differentials.cpp index 439080f2d7..bfe7b45cb7 100644 --- a/source/main/physics/Differentials.cpp +++ b/source/main/physics/Differentials.cpp @@ -22,6 +22,8 @@ #include "Differentials.h" #include "Language.h" +using namespace RoR; + void Differential::ToggleDifferentialMode() { if (m_available_diffs.size() > 1) diff --git a/source/main/physics/Differentials.h b/source/main/physics/Differentials.h index a00f9bf8a7..9a06d888fa 100644 --- a/source/main/physics/Differentials.h +++ b/source/main/physics/Differentials.h @@ -23,6 +23,8 @@ #include #include +namespace RoR { + struct DifferentialData { float speed[2]; @@ -80,3 +82,5 @@ class Differential std::vector m_available_diffs; }; +} // namespace RoR + diff --git a/source/main/physics/Savegame.cpp b/source/main/physics/Savegame.cpp index 695dd765d7..a7808b6009 100644 --- a/source/main/physics/Savegame.cpp +++ b/source/main/physics/Savegame.cpp @@ -480,7 +480,7 @@ bool ActorManager::SaveScene(Ogre::String filename) j_entry.AddMember("min_height", actor->getMinHeight(), j_doc.GetAllocator()); j_entry.AddMember("spawn_rotation", actor->m_spawn_rotation, j_doc.GetAllocator()); j_entry.AddMember("preloaded_with_terrain", actor->isPreloadedWithTerrain(), j_doc.GetAllocator()); - j_entry.AddMember("sim_state", static_cast(actor->ar_sim_state), j_doc.GetAllocator()); + j_entry.AddMember("sim_state", static_cast(actor->ar_state), j_doc.GetAllocator()); j_entry.AddMember("physics_paused", actor->ar_physics_paused, j_doc.GetAllocator()); j_entry.AddMember("player_actor", actor==App::GetGameContext()->GetPlayerActor(), j_doc.GetAllocator()); j_entry.AddMember("prev_player_actor", actor==App::GetGameContext()->GetPrevPlayerActor(), j_doc.GetAllocator()); @@ -751,7 +751,7 @@ bool ActorManager::SaveScene(Ogre::String filename) void ActorManager::RestoreSavedState(Actor* actor, rapidjson::Value const& j_entry) { actor->m_spawn_rotation = j_entry["spawn_rotation"].GetFloat(); - actor->ar_sim_state = static_cast(j_entry["sim_state"].GetInt()); + actor->ar_state = static_cast(j_entry["sim_state"].GetInt()); actor->ar_physics_paused = j_entry["physics_paused"].GetBool(); if (j_entry["player_actor"].GetBool()) diff --git a/source/main/physics/SimData.h b/source/main/physics/SimData.h index 0bcd1f0732..75f070c4ee 100644 --- a/source/main/physics/SimData.h +++ b/source/main/physics/SimData.h @@ -213,6 +213,14 @@ enum LocalizerType LOCALIZER_VOR }; +enum class ActorState +{ + LOCAL_SIMULATED, //!< simulated (local) actor + NETWORKED_OK, //!< not simulated (remote) actor + NETWORKED_HIDDEN, //!< not simulated, not updated (remote) + LOCAL_REPLAY, + LOCAL_SLEEPING, //!< sleeping (local) actor +}; // -------------------------------- // Soft body physics diff --git a/source/main/physics/collision/DynamicCollisions.cpp b/source/main/physics/collision/DynamicCollisions.cpp index 8508df6d1c..39451bbbad 100644 --- a/source/main/physics/collision/DynamicCollisions.cpp +++ b/source/main/physics/collision/DynamicCollisions.cpp @@ -176,7 +176,7 @@ void RoR::ResolveInterActorCollisions(const float dt, PointColDetector &interPoi const auto penetration_depth = collrange - distance; - const bool remote = (hit_actor->ar_sim_state == Actor::SimState::NETWORKED_OK); + const bool remote = (hit_actor->ar_state == ActorState::NETWORKED_OK); ResolveCollisionForces(penetration_depth, *hitnode, *na, *nb, *no, coord.alpha, coord.beta, coord.gamma, normal, dt, remote, submesh_ground_model); diff --git a/source/main/scripting/GameScript.cpp b/source/main/scripting/GameScript.cpp index ed9d3b6689..235889bd27 100644 --- a/source/main/scripting/GameScript.cpp +++ b/source/main/scripting/GameScript.cpp @@ -266,7 +266,7 @@ int GameScript::getNumTrucksByFlag(int flag) int result = 0; for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { - if (!flag || static_cast(actor->ar_sim_state) == flag) + if (!flag || static_cast(actor->ar_state) == flag) result++; } return result; diff --git a/source/main/scripting/ScriptEngine.cpp b/source/main/scripting/ScriptEngine.cpp index 6d141e9306..f39180f1dc 100644 --- a/source/main/scripting/ScriptEngine.cpp +++ b/source/main/scripting/ScriptEngine.cpp @@ -377,9 +377,9 @@ void ScriptEngine::init() // enum truckStates result = engine->RegisterEnum("truckStates"); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckStates", "TS_SIMULATED", static_cast(Actor::SimState::LOCAL_SIMULATED)); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckStates", "TS_SLEEPING", static_cast(Actor::SimState::LOCAL_SLEEPING)); ROR_ASSERT(result>=0); - result = engine->RegisterEnumValue("truckStates", "TS_NETWORKED", static_cast(Actor::SimState::NETWORKED_OK)); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckStates", "TS_SIMULATED", static_cast(ActorState::LOCAL_SIMULATED)); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckStates", "TS_SLEEPING", static_cast(ActorState::LOCAL_SLEEPING)); ROR_ASSERT(result>=0); + result = engine->RegisterEnumValue("truckStates", "TS_NETWORKED", static_cast(ActorState::NETWORKED_OK)); ROR_ASSERT(result>=0); // enum truckTypes result = engine->RegisterEnum("truckTypes"); ROR_ASSERT(result>=0); From 65e3c3a78401662de511c05373d2b8db3fd403d5 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 13 Sep 2021 21:07:32 +0200 Subject: [PATCH 04/24] :wrench: when hiding remote vehicle, also hide seated character. --- source/main/gameplay/Character.cpp | 21 +++++++++++++++++-- source/main/gfx/GfxActor.cpp | 13 ++++++++---- source/main/gfx/GfxActor.h | 7 ++++--- source/main/gui/panels/GUI_DirectionArrow.cpp | 1 + source/main/gui/panels/GUI_TopMenubar.cpp | 2 +- source/main/main.cpp | 5 +++-- 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/source/main/gameplay/Character.cpp b/source/main/gameplay/Character.cpp index 0f7957e761..2bdac8ae52 100644 --- a/source/main/gameplay/Character.cpp +++ b/source/main/gameplay/Character.cpp @@ -632,9 +632,27 @@ void RoR::GfxCharacter::UpdateCharacterInScene() } // Position + Orientation + Ogre::Entity* entity = static_cast(xc_scenenode->getAttachedObject(0)); if (xc_simbuf.simbuf_actor_coupling != nullptr) { - if (xc_simbuf.simbuf_actor_coupling->GetGfxActor()->HasDriverSeatProp()) + // We're in vehicle + GfxActor* gfx_actor = xc_simbuf.simbuf_actor_coupling->GetGfxActor(); + + // Update character visibility first + switch (gfx_actor->GetSimDataBuffer().simbuf_actor_state) + { + case ActorState::NETWORKED_HIDDEN: + entity->setVisible(false); + break; + case ActorState::NETWORKED_OK: + entity->setVisible(true); + break; + default: + break; // no change. + } + + // If visible, update position + if (entity->isVisible() && gfx_actor->HasDriverSeatProp()) { if (xc_movable_text != nullptr) { @@ -657,7 +675,6 @@ void RoR::GfxCharacter::UpdateCharacterInScene() } // Animation - Ogre::Entity* entity = static_cast(xc_scenenode->getAttachedObject(0)); if (xc_simbuf.simbuf_anim_name != xc_simbuf_prev.simbuf_anim_name) { // 'Classic' method - enable one anim, exterminate the others ~ only_a_ptr, 06/2018 diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index 546d56c265..16b283968b 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -1726,8 +1726,6 @@ void RoR::GfxActor::SetRodsVisible(bool visible) void RoR::GfxActor::UpdateSimDataBuffer() { - m_simbuf.simbuf_live_local = (m_actor->ar_state == ActorState::LOCAL_SIMULATED); - m_simbuf.simbuf_physics_paused = m_actor->ar_physics_paused; m_simbuf.simbuf_pos = m_actor->getRotationCenter(); m_simbuf.simbuf_rotation = m_actor->getRotation(); m_simbuf.simbuf_tyre_pressure = m_actor->getTyrePressure().GetCurPressure(); @@ -1749,7 +1747,10 @@ void RoR::GfxActor::UpdateSimDataBuffer() m_simbuf.simbuf_top_speed = m_actor->ar_top_speed; m_simbuf.simbuf_node0_velo = m_actor->ar_nodes[0].Velocity; m_simbuf.simbuf_net_username = m_actor->m_net_username; - m_simbuf.simbuf_is_remote = m_actor->ar_state == ActorState::NETWORKED_OK; + + // General info + m_simbuf.simbuf_actor_state = m_actor->ar_state; + m_simbuf.simbuf_physics_paused = m_actor->ar_physics_paused; // nodes const int num_nodes = m_actor->ar_num_nodes; @@ -2053,7 +2054,11 @@ void RoR::GfxActor::UpdateNetLabels(float dt) // TODO: Remake network player labels via GUI... they shouldn't be billboards inside the scene ~ only_a_ptr, 05/2018 if (m_actor->m_net_label_node && m_actor->m_net_label_mt) { - if (App::mp_hide_net_labels->getBool() || (!m_simbuf.simbuf_is_remote && App::mp_hide_own_net_label->getBool())) + const bool is_remote = + m_simbuf.simbuf_actor_state == ActorState::NETWORKED_OK || + m_simbuf.simbuf_actor_state == ActorState::NETWORKED_HIDDEN; + + if (App::mp_hide_net_labels->getBool() || (!is_remote && App::mp_hide_own_net_label->getBool())) { m_actor->m_net_label_mt->setVisible(false); return; diff --git a/source/main/gfx/GfxActor.h b/source/main/gfx/GfxActor.h index 0d17840d29..f2bf7328f1 100644 --- a/source/main/gfx/GfxActor.h +++ b/source/main/gfx/GfxActor.h @@ -26,6 +26,7 @@ #pragma once +#include "Actor.h" #include "AutoPilot.h" #include "Differentials.h" #include "ForwardDeclarations.h" @@ -114,14 +115,11 @@ class GfxActor std::unique_ptr simbuf_nodes; Ogre::Vector3 simbuf_pos = Ogre::Vector3::ZERO; Ogre::Vector3 simbuf_node0_velo = Ogre::Vector3::ZERO; - bool simbuf_live_local = false; - bool simbuf_physics_paused = false; float simbuf_rotation = 0; float simbuf_tyre_pressure = 0; bool simbuf_tyre_pressurizing = false; Ogre::AxisAlignedBox simbuf_aabb = Ogre::AxisAlignedBox::BOX_NULL; std::string simbuf_net_username; - bool simbuf_is_remote = false; int simbuf_gear = 0; int simbuf_autoshift = 0; float simbuf_wheel_speed = 0; @@ -152,6 +150,9 @@ class GfxActor bool simbuf_headlight_on = 0; Ogre::Vector3 simbuf_direction = Ogre::Vector3::ZERO; //!< Output of `Actor::getDirection()` float simbuf_top_speed = 0; + // Gameplay state + ActorState simbuf_actor_state = ActorState::LOCAL_SLEEPING; + bool simbuf_physics_paused = false; // Autopilot int simbuf_ap_heading_mode = Autopilot::HEADING_NONE; int simbuf_ap_heading_value = 0; diff --git a/source/main/gui/panels/GUI_DirectionArrow.cpp b/source/main/gui/panels/GUI_DirectionArrow.cpp index 9aa2cca78d..bfad07affe 100644 --- a/source/main/gui/panels/GUI_DirectionArrow.cpp +++ b/source/main/gui/panels/GUI_DirectionArrow.cpp @@ -22,6 +22,7 @@ #include "GUI_DirectionArrow.h" +#include "Actor.h" #include "AppContext.h" #include "GfxActor.h" #include "GfxScene.h" diff --git a/source/main/gui/panels/GUI_TopMenubar.cpp b/source/main/gui/panels/GUI_TopMenubar.cpp index 524ce41001..8308331f96 100644 --- a/source/main/gui/panels/GUI_TopMenubar.cpp +++ b/source/main/gui/panels/GUI_TopMenubar.cpp @@ -891,7 +891,7 @@ void TopMenubar::DrawSpecialStateBox(float top_offset) float distance = 0.0f; Actor* player_actor = App::GetGfxScene()->GetSimDataBuffer().simbuf_player_actor; if (player_actor != nullptr && App::GetGameContext()->GetPlayerActor() && - player_actor->GetGfxActor()->GetSimDataBuffer().simbuf_live_local) + player_actor->GetGfxActor()->GetSimDataBuffer().simbuf_actor_state == ActorState::LOCAL_SIMULATED) { distance = player_actor->GetGfxActor()->GetSimDataBuffer().simbuf_pos.distance(data.simbuf_dir_arrow_target); } diff --git a/source/main/main.cpp b/source/main/main.cpp index 7721dd1ad6..6cba319b00 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -635,7 +635,8 @@ int main(int argc, char *argv[]) { Actor* actor = (Actor*)m.payload; actor->ar_state = ActorState::NETWORKED_HIDDEN; // Stop net. updates - App::GetGfxScene()->RemoveGfxActor(actor->GetGfxActor()); // Remove visuals + App::GetGfxScene()->RemoveGfxActor(actor->GetGfxActor()); // Remove visuals (also stops updating SimBuffer) + actor->GetGfxActor()->GetSimDataBuffer().simbuf_actor_state = ActorState::NETWORKED_HIDDEN; // Hack - manually propagate the new state to SimBuffer so Character can reflect it. actor->GetGfxActor()->SetFlexbodyVisible(false); actor->GetGfxActor()->SetWheelsVisible(false); actor->GetGfxActor()->SetAllMeshesVisible(false); @@ -650,7 +651,7 @@ int main(int argc, char *argv[]) { Actor* actor = (Actor*)m.payload; actor->ar_state = ActorState::NETWORKED_OK; // Resume net. updates - App::GetGfxScene()->RegisterGfxActor(actor->GetGfxActor()); // Restore visuals + App::GetGfxScene()->RegisterGfxActor(actor->GetGfxActor()); // Restore visuals (also resumes updating SimBuffer) actor->GetGfxActor()->SetFlexbodyVisible(true); actor->GetGfxActor()->SetWheelsVisible(true); actor->GetGfxActor()->SetAllMeshesVisible(true); From fd134133fe7a02023a868f27f1d42bedc5efe494 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 12 Jun 2021 16:06:59 +0200 Subject: [PATCH 05/24] Fixed character appearing even if vehicle has no driverseat! --- source/main/gameplay/Character.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/main/gameplay/Character.cpp b/source/main/gameplay/Character.cpp index 2bdac8ae52..0280d3c7be 100644 --- a/source/main/gameplay/Character.cpp +++ b/source/main/gameplay/Character.cpp @@ -645,14 +645,14 @@ void RoR::GfxCharacter::UpdateCharacterInScene() entity->setVisible(false); break; case ActorState::NETWORKED_OK: - entity->setVisible(true); + entity->setVisible(gfx_actor->HasDriverSeatProp()); break; default: break; // no change. } // If visible, update position - if (entity->isVisible() && gfx_actor->HasDriverSeatProp()) + if (entity->isVisible()) { if (xc_movable_text != nullptr) { From 81cb6893df7f68c5e9b0af86a9b862bf620b900e Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Sat, 12 Jun 2021 18:45:47 +0300 Subject: [PATCH 06/24] use X for remove button, mute/unmute sounds, alligned buttons --- source/main/gui/panels/GUI_TopMenubar.cpp | 6 ++++-- source/main/main.cpp | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/main/gui/panels/GUI_TopMenubar.cpp b/source/main/gui/panels/GUI_TopMenubar.cpp index 8308331f96..b42bf6d814 100644 --- a/source/main/gui/panels/GUI_TopMenubar.cpp +++ b/source/main/gui/panels/GUI_TopMenubar.cpp @@ -745,7 +745,6 @@ void TopMenubar::DrawMpUserToActorList(RoRnet::UserInfo &user) // Display actor list Ogre::TexturePtr tex1 = FetchIcon("control_pause.png"); Ogre::TexturePtr tex2 = FetchIcon("control_play.png"); - Ogre::TexturePtr tex3 = FetchIcon("control_eject.png"); int i = 0; for (auto actor : App::GetGameContext()->GetActorManager()->GetActors()) { @@ -769,10 +768,13 @@ void TopMenubar::DrawMpUserToActorList(RoRnet::UserInfo &user) } else // Our actor(s) { - if (ImGui::ImageButton(reinterpret_cast(tex3->getHandle()), ImVec2(16, 16))) + std::string text_buf_rem = fmt::format(" X ##[{}]", i); + ImGui::PushStyleColor(ImGuiCol_Text, RED_TEXT); + if (ImGui::Button(text_buf_rem.c_str())) { App::GetGameContext()->PushMessage(Message(MSG_SIM_DELETE_ACTOR_REQUESTED, (void*)actor)); } + ImGui::PopStyleColor(); } ImGui::PopID(); ImGui::SameLine(); diff --git a/source/main/main.cpp b/source/main/main.cpp index 6cba319b00..30189b8711 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -642,6 +642,7 @@ int main(int argc, char *argv[]) actor->GetGfxActor()->SetAllMeshesVisible(false); actor->GetGfxActor()->SetCastShadows(false); actor->GetGfxActor()->SetRodsVisible(false); + actor->muteAllSounds(); // Stop sounds } break; @@ -657,6 +658,7 @@ int main(int argc, char *argv[]) actor->GetGfxActor()->SetAllMeshesVisible(true); actor->GetGfxActor()->SetCastShadows(true); actor->GetGfxActor()->SetRodsVisible(true); + actor->unmuteAllSounds(); // Unmute sounds } break; From e9255272f2edd0dbf7922b7acd02e4f3945117aa Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Tue, 15 Jun 2021 21:58:53 +0300 Subject: [PATCH 07/24] hide lights --- source/main/main.cpp | 1 + source/main/physics/Actor.cpp | 8 ++++++++ source/main/physics/Actor.h | 1 + 3 files changed, 10 insertions(+) diff --git a/source/main/main.cpp b/source/main/main.cpp index 30189b8711..85ac163637 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -643,6 +643,7 @@ int main(int argc, char *argv[]) actor->GetGfxActor()->SetCastShadows(false); actor->GetGfxActor()->SetRodsVisible(false); actor->muteAllSounds(); // Stop sounds + actor->setLightsOff(); // Turn all lights off } break; diff --git a/source/main/physics/Actor.cpp b/source/main/physics/Actor.cpp index 4e194cf43c..6b784ee219 100644 --- a/source/main/physics/Actor.cpp +++ b/source/main/physics/Actor.cpp @@ -2992,6 +2992,14 @@ void Actor::lightsToggle() TRIGGER_EVENT(SE_TRUCK_LIGHT_TOGGLE, ar_instance_id); } +void Actor::setLightsOff() +{ + for (size_t i = 0; i < ar_flares.size(); i++) + { + ar_flares[i].snode->setVisible(false); + } +} + void Actor::updateFlareStates(float dt) { if (m_flares_mode == GfxFlaresMode::NONE) { return; } diff --git a/source/main/physics/Actor.h b/source/main/physics/Actor.h index 49b02f5929..a1eea7a72d 100644 --- a/source/main/physics/Actor.h +++ b/source/main/physics/Actor.h @@ -103,6 +103,7 @@ class Actor : public ZeroedMemoryAllocator //! @{ User interaction functions void mouseMove(int node, Ogre::Vector3 pos, float force); void lightsToggle(); + void setLightsOff(); void tieToggle(int group=-1); bool isTied(); void hookToggle(int group=-1, HookAction mode=HOOK_TOGGLE, int node_number=-1); From f6604afd8474be706c51b9ef5067012610e3263b Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Tue, 15 Jun 2021 22:07:04 +0300 Subject: [PATCH 08/24] fixed remote actor not unregistering when hidden --- source/main/physics/ActorManager.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/main/physics/ActorManager.cpp b/source/main/physics/ActorManager.cpp index e09d6d9307..1204b701e1 100644 --- a/source/main/physics/ActorManager.cpp +++ b/source/main/physics/ActorManager.cpp @@ -483,9 +483,12 @@ void ActorManager::HandleActorStreamData(std::vector packet_ else if (packet.header.command == RoRnet::MSG2_STREAM_UNREGISTER) { Actor* b = this->GetActorByNetworkLinks(packet.header.source, packet.header.streamid); - if (b && b->ar_state == ActorState::NETWORKED_OK) + if (b) { - App::GetGameContext()->PushMessage(Message(MSG_SIM_DELETE_ACTOR_REQUESTED, (void*)b)); + if (b->ar_state == ActorState::NETWORKED_OK || b->ar_state == ActorState::NETWORKED_HIDDEN) + { + App::GetGameContext()->PushMessage(Message(MSG_SIM_DELETE_ACTOR_REQUESTED, (void*)b)); + } } m_stream_mismatches[packet.header.source].erase(packet.header.streamid); } From 8187fed0ed67b588ad6fc0f40131c5a10ac7f706 Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Tue, 15 Jun 2021 22:56:46 +0300 Subject: [PATCH 09/24] hide wings --- source/main/gfx/GfxActor.cpp | 16 ++++++++++++++++ source/main/gfx/GfxActor.h | 1 + source/main/main.cpp | 2 ++ 3 files changed, 19 insertions(+) diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index 16b283968b..b09835f071 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -3313,6 +3313,22 @@ void RoR::GfxActor::SetAllMeshesVisible(bool visible) this->SetFlexbodyVisible(visible); } +void RoR::GfxActor::SetWingsVisible(bool visible) +{ + for (int i = 0; i < m_actor->ar_num_wings; ++i) + { + wing_t& wing = m_actor->ar_wings[i]; + if (!visible) + { + wing.cnode->setVisible(false); + } + else + { + wing.cnode->setVisible(true); + } + } +} + void RoR::GfxActor::UpdateWingMeshes() { for (int i = 0; i < m_actor->ar_num_wings; ++i) diff --git a/source/main/gfx/GfxActor.h b/source/main/gfx/GfxActor.h index f2bf7328f1..e808512f3c 100644 --- a/source/main/gfx/GfxActor.h +++ b/source/main/gfx/GfxActor.h @@ -212,6 +212,7 @@ class GfxActor void SetFlexbodyVisible (bool visible); void SetWheelsVisible (bool value); void SetAllMeshesVisible(bool value); + void SetWingsVisible (bool visible); void SetCastShadows (bool value); void UpdateDebugView (); void ToggleDebugView (); diff --git a/source/main/main.cpp b/source/main/main.cpp index 85ac163637..b80e0f0aab 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -640,6 +640,7 @@ int main(int argc, char *argv[]) actor->GetGfxActor()->SetFlexbodyVisible(false); actor->GetGfxActor()->SetWheelsVisible(false); actor->GetGfxActor()->SetAllMeshesVisible(false); + actor->GetGfxActor()->SetWingsVisible(false); actor->GetGfxActor()->SetCastShadows(false); actor->GetGfxActor()->SetRodsVisible(false); actor->muteAllSounds(); // Stop sounds @@ -657,6 +658,7 @@ int main(int argc, char *argv[]) actor->GetGfxActor()->SetFlexbodyVisible(true); actor->GetGfxActor()->SetWheelsVisible(true); actor->GetGfxActor()->SetAllMeshesVisible(true); + actor->GetGfxActor()->SetWingsVisible(true); actor->GetGfxActor()->SetCastShadows(true); actor->GetGfxActor()->SetRodsVisible(true); actor->unmuteAllSounds(); // Unmute sounds From 7dcdb9a75905130e406fab244be1f120a5e44a52 Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Wed, 16 Jun 2021 01:30:43 +0300 Subject: [PATCH 10/24] hide airbrakes --- source/main/gfx/GfxActor.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index b09835f071..676e8ca0ad 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -3317,14 +3317,25 @@ void RoR::GfxActor::SetWingsVisible(bool visible) { for (int i = 0; i < m_actor->ar_num_wings; ++i) { - wing_t& wing = m_actor->ar_wings[i]; if (!visible) { - wing.cnode->setVisible(false); + m_actor->ar_wings[i].cnode->setVisible(false); + } + else + { + m_actor->ar_wings[i].cnode->setVisible(true); + } + } + + for (size_t i=0; i< m_actor->ar_airbrakes.size(); ++i) + { + if (!visible) + { + m_gfx_airbrakes[i].abx_scenenode->setVisible(false); } else { - wing.cnode->setVisible(true); + m_gfx_airbrakes[i].abx_scenenode->setVisible(true); } } } From 1911bc08e2cbfc54c8326b0dd2399fe3c9faf204 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 28 Jun 2021 00:06:18 +0200 Subject: [PATCH 11/24] :label: MP labels are now drawn by DearIMGUI (prototype). TODO: text color, highlight and distance-resizing. --- source/main/gfx/GfxActor.cpp | 52 ++++++++++++++++++++---------------- source/main/gui/GUIUtils.cpp | 18 +++++++++++++ source/main/gui/GUIUtils.h | 2 ++ source/main/main.cpp | 1 + 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index 676e8ca0ad..de3baec479 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -29,6 +29,7 @@ #include "EngineSim.h" #include "GfxScene.h" #include "GUIManager.h" +#include "GUIUtils.h" #include "HydraxWater.h" #include "FlexAirfoil.h" #include "FlexBody.h" @@ -48,6 +49,8 @@ #include "TurboProp.h" #include "Utils.h" +#include "imgui_internal.h" + #include RoR::GfxActor::GfxActor(Actor* actor, ActorSpawner* spawner, std::string ogre_resource_group, @@ -638,16 +641,7 @@ void RoR::GfxActor::UpdateDebugView() World2ScreenConverter world2screen( App::GetCameraManager()->GetCamera()->getViewMatrix(true), App::GetCameraManager()->GetCamera()->getProjectionMatrix(), Ogre::Vector2(screen_size.x, screen_size.y)); - // Dummy fullscreen window to draw to - int window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar| ImGuiWindowFlags_NoInputs - | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus; - ImGui::SetNextWindowPos(ImVec2(0,0)); - ImGui::SetNextWindowSize(screen_size); - ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0,0,0,0)); // Fully transparent background! - ImGui::Begin(("RoR-SoftBodyView-" + TOSTRING(m_actor->ar_instance_id)).c_str(), NULL, window_flags); - ImDrawList* drawlist = ImGui::GetWindowDrawList(); - ImGui::End(); - ImGui::PopStyleColor(1); // WindowBg + ImDrawList* drawlist = GetImDummyFullscreenWindow(); if (m_actor->ar_physics_paused && !App::GetGuiManager()->IsGuiHidden()) { @@ -2051,43 +2045,55 @@ void RoR::GfxActor::UpdateAeroEngines() void RoR::GfxActor::UpdateNetLabels(float dt) { - // TODO: Remake network player labels via GUI... they shouldn't be billboards inside the scene ~ only_a_ptr, 05/2018 - if (m_actor->m_net_label_node && m_actor->m_net_label_mt) - { const bool is_remote = m_simbuf.simbuf_actor_state == ActorState::NETWORKED_OK || m_simbuf.simbuf_actor_state == ActorState::NETWORKED_HIDDEN; if (App::mp_hide_net_labels->getBool() || (!is_remote && App::mp_hide_own_net_label->getBool())) { - m_actor->m_net_label_mt->setVisible(false); return; } float vlen = m_simbuf.simbuf_pos.distance(App::GetCameraManager()->GetCameraNode()->getPosition()); float y_offset = (m_simbuf.simbuf_aabb.getMaximum().y - m_simbuf.simbuf_pos.y) + (vlen / 100.0); - m_actor->m_net_label_node->setPosition(m_simbuf.simbuf_pos + Ogre::Vector3::UNIT_Y * y_offset); + Ogre::Vector3 scene_pos = m_simbuf.simbuf_pos + Ogre::Vector3::UNIT_Y * y_offset; // this ensures that the nickname is always in a readable size - m_actor->m_net_label_mt->setCharacterHeight(std::max(0.6, vlen / 40.0)); - + float font_size = std::max(0.6, vlen / 40.0); + std::string caption; if (vlen > 1000) // 1000 ... vlen { - m_actor->m_net_label_mt->setCaption( - m_simbuf.simbuf_net_username + " (" + TOSTRING((float)(ceil(vlen / 100) / 10.0) ) + " km)"); + caption = + m_simbuf.simbuf_net_username + " (" + TOSTRING((float)(ceil(vlen / 100) / 10.0) ) + " km)"; } else if (vlen > 20) // 20 ... vlen ... 1000 { - m_actor->m_net_label_mt->setCaption( - m_simbuf.simbuf_net_username + " (" + TOSTRING((int)vlen) + " m)"); + caption = + m_simbuf.simbuf_net_username + " (" + TOSTRING((int)vlen) + " m)"; } else // 0 ... vlen ... 20 { - m_actor->m_net_label_mt->setCaption(m_simbuf.simbuf_net_username); + caption = m_simbuf.simbuf_net_username; } - m_actor->m_net_label_mt->setVisible(true); + + // draw with DearIMGUI + + ImVec2 screen_size = ImGui::GetIO().DisplaySize; + World2ScreenConverter world2screen( + App::GetCameraManager()->GetCamera()->getViewMatrix(true), App::GetCameraManager()->GetCamera()->getProjectionMatrix(), Ogre::Vector2(screen_size.x, screen_size.y)); + + ImDrawList* drawlist = GetImDummyFullscreenWindow(); + ImGuiContext* g = ImGui::GetCurrentContext(); + Ogre::Vector3 pos = world2screen.Convert(scene_pos); + + // only draw when in front of camera + if (pos.z < 0.f) + { + ImVec2 screen_pos(pos.x, pos.y); + drawlist->AddText(g->Font, g->FontSize, screen_pos, ImGui::GetColorU32(ImGuiCol_Text), caption.c_str()); } + } void RoR::GfxActor::CalculateDriverPos(Ogre::Vector3& out_pos, Ogre::Quaternion& out_rot) diff --git a/source/main/gui/GUIUtils.cpp b/source/main/gui/GUIUtils.cpp index f9c943f481..cc2082c2e6 100644 --- a/source/main/gui/GUIUtils.cpp +++ b/source/main/gui/GUIUtils.cpp @@ -349,3 +349,21 @@ Ogre::TexturePtr RoR::FetchIcon(const char* name) return Ogre::TexturePtr(); // null } + +ImDrawList* RoR::GetImDummyFullscreenWindow() +{ + ImVec2 screen_size = ImGui::GetIO().DisplaySize; + + // Dummy fullscreen window to draw to + int window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar| ImGuiWindowFlags_NoInputs + | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus; + ImGui::SetNextWindowPos(ImVec2(0,0)); + ImGui::SetNextWindowSize(screen_size); + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0,0,0,0)); // Fully transparent background! + ImGui::Begin("RoR_TransparentFullscreenWindow", NULL, window_flags); + ImDrawList* drawlist = ImGui::GetWindowDrawList(); + ImGui::End(); + ImGui::PopStyleColor(1); // WindowBg + + return drawlist; +} diff --git a/source/main/gui/GUIUtils.h b/source/main/gui/GUIUtils.h index d8c61e198f..12cb7dbd1c 100644 --- a/source/main/gui/GUIUtils.h +++ b/source/main/gui/GUIUtils.h @@ -74,4 +74,6 @@ void DrawGCombo(CVar* cvar, const char* label, const char* values); Ogre::TexturePtr FetchIcon(const char* name); +ImDrawList* GetImDummyFullscreenWindow(); + } // namespace RoR diff --git a/source/main/main.cpp b/source/main/main.cpp index b80e0f0aab..e59b65afaa 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -645,6 +645,7 @@ int main(int argc, char *argv[]) actor->GetGfxActor()->SetRodsVisible(false); actor->muteAllSounds(); // Stop sounds actor->setLightsOff(); // Turn all lights off + } break; From 448aae712131bac81ff73ad260983f4fa1b87a60 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 28 Jun 2021 21:18:54 +0200 Subject: [PATCH 12/24] :triangular_ruler: (minor) Rem. redundant namespace qualifier --- source/main/gfx/GfxScene.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/main/gfx/GfxScene.cpp b/source/main/gfx/GfxScene.cpp index 5a85d33b80..e6064f0e2f 100644 --- a/source/main/gfx/GfxScene.cpp +++ b/source/main/gfx/GfxScene.cpp @@ -75,7 +75,7 @@ void GfxScene::ClearScene() App::GetGuiManager()->GetDirectionArrow()->CreateArrow(); } -void RoR::GfxScene::Init() +void GfxScene::Init() { ROR_ASSERT(!m_scene_manager); m_scene_manager = App::GetAppContext()->GetOgreRoot()->createSceneManager(Ogre::ST_EXTERIOR_CLOSE, "main_scene_manager"); @@ -83,7 +83,7 @@ void RoR::GfxScene::Init() m_skidmark_conf.LoadDefaultSkidmarkDefs(); } -void RoR::GfxScene::UpdateScene(float dt_sec) +void GfxScene::UpdateScene(float dt_sec) { // Actors - start threaded tasks for (GfxActor* gfx_actor: m_live_gfx_actors) @@ -251,7 +251,7 @@ void RoR::GfxScene::UpdateScene(float dt_sec) } } -void RoR::GfxScene::SetParticlesVisible(bool visible) +void GfxScene::SetParticlesVisible(bool visible) { for (auto itor : m_dustpools) { @@ -259,7 +259,7 @@ void RoR::GfxScene::SetParticlesVisible(bool visible) } } -DustPool* RoR::GfxScene::GetDustPool(const char* name) +DustPool* GfxScene::GetDustPool(const char* name) { auto found = m_dustpools.find(name); if (found != m_dustpools.end()) @@ -272,12 +272,12 @@ DustPool* RoR::GfxScene::GetDustPool(const char* name) } } -void RoR::GfxScene::RegisterGfxActor(RoR::GfxActor* gfx_actor) +void GfxScene::RegisterGfxActor(RoR::GfxActor* gfx_actor) { m_all_gfx_actors.push_back(gfx_actor); } -void RoR::GfxScene::BufferSimulationData() +void GfxScene::BufferSimulationData() { m_simbuf.simbuf_player_actor = App::GetGameContext()->GetPlayerActor(); m_simbuf.simbuf_character_pos = App::GetGameContext()->GetPlayerCharacter()->getPosition(); @@ -312,18 +312,18 @@ void RoR::GfxScene::BufferSimulationData() } } -void RoR::GfxScene::RemoveGfxActor(RoR::GfxActor* remove_me) +void GfxScene::RemoveGfxActor(RoR::GfxActor* remove_me) { auto itor = std::remove(m_all_gfx_actors.begin(), m_all_gfx_actors.end(), remove_me); m_all_gfx_actors.erase(itor, m_all_gfx_actors.end()); } -void RoR::GfxScene::RegisterGfxCharacter(RoR::GfxCharacter* gfx_character) +void GfxScene::RegisterGfxCharacter(RoR::GfxCharacter* gfx_character) { m_all_gfx_characters.push_back(gfx_character); } -void RoR::GfxScene::RemoveGfxCharacter(RoR::GfxCharacter* remove_me) +void GfxScene::RemoveGfxCharacter(RoR::GfxCharacter* remove_me) { auto itor = std::remove(m_all_gfx_characters.begin(), m_all_gfx_characters.end(), remove_me); m_all_gfx_characters.erase(itor, m_all_gfx_characters.end()); From b322a87bc2546531cbbe16fd7ec9e6c32a78107c Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 28 Jun 2021 22:20:01 +0200 Subject: [PATCH 13/24] :label: Character net labels also drawn by DearIMGUI Added common drawing function `App::GetGfxScene()->DrawNetLabel()` --- source/main/gameplay/Character.cpp | 15 ++-------- source/main/gfx/GfxActor.cpp | 36 ++---------------------- source/main/gfx/GfxActor.h | 1 + source/main/gfx/GfxScene.cpp | 42 ++++++++++++++++++++++++++++ source/main/gfx/GfxScene.h | 1 + source/main/physics/Actor.h | 1 + source/main/physics/ActorManager.cpp | 1 + 7 files changed, 51 insertions(+), 46 deletions(-) diff --git a/source/main/gameplay/Character.cpp b/source/main/gameplay/Character.cpp index 0280d3c7be..be71dd7d9b 100644 --- a/source/main/gameplay/Character.cpp +++ b/source/main/gameplay/Character.cpp @@ -738,19 +738,10 @@ void RoR::GfxCharacter::UpdateCharacterInScene() } float camDist = (xc_scenenode->getPosition() - App::GetCameraManager()->GetCameraNode()->getPosition()).length(); + Ogre::Vector3 scene_pos = xc_scenenode->getPosition(); + scene_pos.y += (1.9f + camDist / 100.0f); - xc_movable_text->setCaption(xc_simbuf.simbuf_net_username); - if (camDist > 1000.0f) - xc_movable_text->setCaption(xc_simbuf.simbuf_net_username + " (" + TOSTRING((float)(ceil(camDist / 100) / 10.0f)) + " km)"); - else if (camDist > 20.0f && camDist <= 1000.0f) - xc_movable_text->setCaption(xc_simbuf.simbuf_net_username + " (" + TOSTRING((int)camDist) + " m)"); - else - xc_movable_text->setCaption(xc_simbuf.simbuf_net_username); - - float h = std::max(9.0f, camDist * 1.2f); - xc_movable_text->setAdditionalHeight(1.9f + camDist / 100.0f); - xc_movable_text->setCharacterHeight(h); - xc_movable_text->setVisible(true); + App::GetGfxScene()->DrawNetLabel(scene_pos, camDist, xc_simbuf.simbuf_net_username, xc_simbuf.simbuf_color_number); } } #endif // USE_SOCKETW diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index de3baec479..3f599935c4 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -1741,6 +1741,7 @@ void RoR::GfxActor::UpdateSimDataBuffer() m_simbuf.simbuf_top_speed = m_actor->ar_top_speed; m_simbuf.simbuf_node0_velo = m_actor->ar_nodes[0].Velocity; m_simbuf.simbuf_net_username = m_actor->m_net_username; + m_simbuf.simbuf_net_colornum = m_actor->m_net_color_num; // General info m_simbuf.simbuf_actor_state = m_actor->ar_state; @@ -2059,40 +2060,7 @@ void RoR::GfxActor::UpdateNetLabels(float dt) float y_offset = (m_simbuf.simbuf_aabb.getMaximum().y - m_simbuf.simbuf_pos.y) + (vlen / 100.0); Ogre::Vector3 scene_pos = m_simbuf.simbuf_pos + Ogre::Vector3::UNIT_Y * y_offset; - // this ensures that the nickname is always in a readable size - float font_size = std::max(0.6, vlen / 40.0); - std::string caption; - if (vlen > 1000) // 1000 ... vlen - { - caption = - m_simbuf.simbuf_net_username + " (" + TOSTRING((float)(ceil(vlen / 100) / 10.0) ) + " km)"; - } - else if (vlen > 20) // 20 ... vlen ... 1000 - { - caption = - m_simbuf.simbuf_net_username + " (" + TOSTRING((int)vlen) + " m)"; - } - else // 0 ... vlen ... 20 - { - caption = m_simbuf.simbuf_net_username; - } - - // draw with DearIMGUI - - ImVec2 screen_size = ImGui::GetIO().DisplaySize; - World2ScreenConverter world2screen( - App::GetCameraManager()->GetCamera()->getViewMatrix(true), App::GetCameraManager()->GetCamera()->getProjectionMatrix(), Ogre::Vector2(screen_size.x, screen_size.y)); - - ImDrawList* drawlist = GetImDummyFullscreenWindow(); - ImGuiContext* g = ImGui::GetCurrentContext(); - Ogre::Vector3 pos = world2screen.Convert(scene_pos); - - // only draw when in front of camera - if (pos.z < 0.f) - { - ImVec2 screen_pos(pos.x, pos.y); - drawlist->AddText(g->Font, g->FontSize, screen_pos, ImGui::GetColorU32(ImGuiCol_Text), caption.c_str()); - } + App::GetGfxScene()->DrawNetLabel(scene_pos, vlen, m_simbuf.simbuf_net_username, m_simbuf.simbuf_net_colornum); } diff --git a/source/main/gfx/GfxActor.h b/source/main/gfx/GfxActor.h index e808512f3c..7ff5026b2a 100644 --- a/source/main/gfx/GfxActor.h +++ b/source/main/gfx/GfxActor.h @@ -120,6 +120,7 @@ class GfxActor bool simbuf_tyre_pressurizing = false; Ogre::AxisAlignedBox simbuf_aabb = Ogre::AxisAlignedBox::BOX_NULL; std::string simbuf_net_username; + int simbuf_net_colornum; int simbuf_gear = 0; int simbuf_autoshift = 0; float simbuf_wheel_speed = 0; diff --git a/source/main/gfx/GfxScene.cpp b/source/main/gfx/GfxScene.cpp index e6064f0e2f..2ce13fe1af 100644 --- a/source/main/gfx/GfxScene.cpp +++ b/source/main/gfx/GfxScene.cpp @@ -29,6 +29,7 @@ #include "HydraxWater.h" #include "GameContext.h" #include "GUIManager.h" +#include "GUIUtils.h" #include "GUI_DirectionArrow.h" #include "OverlayWrapper.h" #include "SkyManager.h" @@ -36,6 +37,9 @@ #include "TerrainGeometryManager.h" #include "TerrainManager.h" #include "TerrainObjectManager.h" +#include "Utils.h" + +#include "imgui_internal.h" #include @@ -329,3 +333,41 @@ void GfxScene::RemoveGfxCharacter(RoR::GfxCharacter* remove_me) m_all_gfx_characters.erase(itor, m_all_gfx_characters.end()); } +void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string const& nick, int colornum) +{ + // this ensures that the nickname is always in a readable size + float font_size = std::max(0.6, cam_dist / 40.0); + std::string caption; + if (cam_dist > 1000) // 1000 ... vlen + { + caption = + nick + " (" + TOSTRING((float)(ceil(cam_dist / 100) / 10.0) ) + " km)"; + } + else if (cam_dist > 20) // 20 ... vlen ... 1000 + { + caption = + nick + " (" + TOSTRING((int)cam_dist) + " m)"; + } + else // 0 ... vlen ... 20 + { + caption = nick; + } + + // draw with DearIMGUI + + ImVec2 screen_size = ImGui::GetIO().DisplaySize; + World2ScreenConverter world2screen( + App::GetCameraManager()->GetCamera()->getViewMatrix(true), App::GetCameraManager()->GetCamera()->getProjectionMatrix(), Ogre::Vector2(screen_size.x, screen_size.y)); + + ImDrawList* drawlist = GetImDummyFullscreenWindow(); + ImGuiContext* g = ImGui::GetCurrentContext(); + Ogre::Vector3 pos = world2screen.Convert(scene_pos); + + // only draw when in front of camera + if (pos.z < 0.f) + { + ImVec2 screen_pos(pos.x, pos.y); + drawlist->AddText(g->Font, g->FontSize, screen_pos, ImGui::GetColorU32(ImGuiCol_Text), caption.c_str()); + } +} + diff --git a/source/main/gfx/GfxScene.h b/source/main/gfx/GfxScene.h index 1a4754549f..33bfc59f6c 100644 --- a/source/main/gfx/GfxScene.h +++ b/source/main/gfx/GfxScene.h @@ -66,6 +66,7 @@ class GfxScene void CreateDustPools(); DustPool* GetDustPool(const char* name); void SetParticlesVisible(bool visible); + void DrawNetLabel(Ogre::Vector3 pos, float cam_dist, std::string const& nick, int colornum); void UpdateScene(float dt_sec); void ClearScene(); void RegisterGfxActor(RoR::GfxActor* gfx_actor); diff --git a/source/main/physics/Actor.h b/source/main/physics/Actor.h index a1eea7a72d..1269fa0bff 100644 --- a/source/main/physics/Actor.h +++ b/source/main/physics/Actor.h @@ -470,6 +470,7 @@ class Actor : public ZeroedMemoryAllocator MovableText* m_net_label_mt; Ogre::SceneNode* m_net_label_node; Ogre::UTFString m_net_username; + int m_net_color_num; Ogre::Timer m_reset_timer; Ogre::Vector3 m_rotation_request_center; float m_rotation_request; //!< Accumulator diff --git a/source/main/physics/ActorManager.cpp b/source/main/physics/ActorManager.cpp index 1204b701e1..c352f9ab2f 100644 --- a/source/main/physics/ActorManager.cpp +++ b/source/main/physics/ActorManager.cpp @@ -314,6 +314,7 @@ void ActorManager::SetupActor(Actor* actor, ActorSpawnRequest rq, std::shared_pt } actor->m_net_username = rq.asr_net_username; + actor->m_net_color_num = rq.asr_net_color; RoR::Str<100> element_name; ActorSpawner::ComposeName(element_name, "NetLabel", 0, actor->ar_instance_id); From b9c0320a85d0d0ce858a8e1144f7205dbf30bfb8 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 28 Jun 2021 22:43:07 +0200 Subject: [PATCH 14/24] :label: Net. labels now colored and highlighted. --- source/main/gfx/GfxScene.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/source/main/gfx/GfxScene.cpp b/source/main/gfx/GfxScene.cpp index 2ce13fe1af..9bd48d235a 100644 --- a/source/main/gfx/GfxScene.cpp +++ b/source/main/gfx/GfxScene.cpp @@ -359,15 +359,29 @@ void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string World2ScreenConverter world2screen( App::GetCameraManager()->GetCamera()->getViewMatrix(true), App::GetCameraManager()->GetCamera()->getProjectionMatrix(), Ogre::Vector2(screen_size.x, screen_size.y)); - ImDrawList* drawlist = GetImDummyFullscreenWindow(); - ImGuiContext* g = ImGui::GetCurrentContext(); Ogre::Vector3 pos = world2screen.Convert(scene_pos); // only draw when in front of camera if (pos.z < 0.f) { - ImVec2 screen_pos(pos.x, pos.y); - drawlist->AddText(g->Font, g->FontSize, screen_pos, ImGui::GetColorU32(ImGuiCol_Text), caption.c_str()); + ImVec2 text_size = ImGui::CalcTextSize(caption.c_str()); + GUIManager::GuiTheme const& theme = App::GetGuiManager()->GetTheme(); + + ImDrawList* drawlist = GetImDummyFullscreenWindow(); + ImGuiContext* g = ImGui::GetCurrentContext(); + + // Draw background quad + ImVec2 screen_pos(pos.x, pos.y - (text_size.y/2)); + const ImVec2 QUAD_PAD(4.f, 4.f); // pixels + ImVec2 quad_tl = screen_pos - QUAD_PAD; + ImVec2 quad_br = quad_tl + text_size + QUAD_PAD; + drawlist->AddQuadFilled(quad_tl, ImVec2(quad_tl.x, quad_br.y), quad_br, ImVec2(quad_br.x, quad_tl.y), // clockwise + ImColor(theme.semitransparent_window_bg)); + + // draw colored text + Ogre::ColourValue color = App::GetNetwork()->GetPlayerColor(colornum); + ImVec4 text_color(color.r, color.g, color.b, 1.f); + drawlist->AddText(g->Font, g->FontSize, screen_pos, ImColor(text_color), caption.c_str()); } } From f54ab479c0ca33a797acf44d406ff7c7549d91ac Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Tue, 29 Jun 2021 19:02:11 +0300 Subject: [PATCH 15/24] use AddRectFilled, rounded corners --- source/main/gfx/GfxScene.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/source/main/gfx/GfxScene.cpp b/source/main/gfx/GfxScene.cpp index 9bd48d235a..61d82ecf2d 100644 --- a/source/main/gfx/GfxScene.cpp +++ b/source/main/gfx/GfxScene.cpp @@ -370,13 +370,9 @@ void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string ImDrawList* drawlist = GetImDummyFullscreenWindow(); ImGuiContext* g = ImGui::GetCurrentContext(); - // Draw background quad + // Draw background rectangle ImVec2 screen_pos(pos.x, pos.y - (text_size.y/2)); - const ImVec2 QUAD_PAD(4.f, 4.f); // pixels - ImVec2 quad_tl = screen_pos - QUAD_PAD; - ImVec2 quad_br = quad_tl + text_size + QUAD_PAD; - drawlist->AddQuadFilled(quad_tl, ImVec2(quad_tl.x, quad_br.y), quad_br, ImVec2(quad_br.x, quad_tl.y), // clockwise - ImColor(theme.semitransparent_window_bg)); + drawlist->AddRectFilled(ImVec2(pos.x - 4.f, pos.y - text_size.y / 2), ImVec2(pos.x + text_size.x + 4.f, pos.y + text_size.y / 2), ImColor(theme.semitransparent_window_bg), 4.f); // draw colored text Ogre::ColourValue color = App::GetNetwork()->GetPlayerColor(colornum); From 04a2edfda129d72b1b34923aca759a0044bd662f Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 23 Aug 2021 21:41:49 +0200 Subject: [PATCH 16/24] :label: DearIMGUI net labels - corrected centering. --- source/main/gfx/GfxScene.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/source/main/gfx/GfxScene.cpp b/source/main/gfx/GfxScene.cpp index 61d82ecf2d..0d2d68d477 100644 --- a/source/main/gfx/GfxScene.cpp +++ b/source/main/gfx/GfxScene.cpp @@ -359,25 +359,34 @@ void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos, float cam_dist, std::string World2ScreenConverter world2screen( App::GetCameraManager()->GetCamera()->getViewMatrix(true), App::GetCameraManager()->GetCamera()->getProjectionMatrix(), Ogre::Vector2(screen_size.x, screen_size.y)); - Ogre::Vector3 pos = world2screen.Convert(scene_pos); + Ogre::Vector3 pos_xyz = world2screen.Convert(scene_pos); // only draw when in front of camera - if (pos.z < 0.f) + if (pos_xyz.z < 0.f) { + // Align position to whole pixels, to minimize jitter. + ImVec2 pos((int)pos_xyz.x+0.5, (int)pos_xyz.y+0.5); + ImVec2 text_size = ImGui::CalcTextSize(caption.c_str()); GUIManager::GuiTheme const& theme = App::GetGuiManager()->GetTheme(); ImDrawList* drawlist = GetImDummyFullscreenWindow(); ImGuiContext* g = ImGui::GetCurrentContext(); + ImVec2 text_pos(pos.x - ((text_size.x / 2)), pos.y - ((text_size.y / 2))); + // Draw background rectangle - ImVec2 screen_pos(pos.x, pos.y - (text_size.y/2)); - drawlist->AddRectFilled(ImVec2(pos.x - 4.f, pos.y - text_size.y / 2), ImVec2(pos.x + text_size.x + 4.f, pos.y + text_size.y / 2), ImColor(theme.semitransparent_window_bg), 4.f); + const float PADDING = 4.f; + drawlist->AddRectFilled( + text_pos - ImVec2(PADDING, PADDING), + text_pos + text_size + ImVec2(PADDING, PADDING), + ImColor(theme.semitransparent_window_bg), + ImGui::GetStyle().WindowRounding); // draw colored text Ogre::ColourValue color = App::GetNetwork()->GetPlayerColor(colornum); ImVec4 text_color(color.r, color.g, color.b, 1.f); - drawlist->AddText(g->Font, g->FontSize, screen_pos, ImColor(text_color), caption.c_str()); + drawlist->AddText(g->Font, g->FontSize, text_pos, ImColor(text_color), caption.c_str()); } } From b8ad1b8d2e0f9c09c01f7a2e7400d8cde2279b83 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 23 Aug 2021 22:26:56 +0200 Subject: [PATCH 17/24] :wastebasket: Rem. unused MovableText - now using DearIMGUI. --- source/main/gameplay/Character.cpp | 36 ++---------------------------- source/main/gameplay/Character.h | 1 - 2 files changed, 2 insertions(+), 35 deletions(-) diff --git a/source/main/gameplay/Character.cpp b/source/main/gameplay/Character.cpp index be71dd7d9b..614f3b0446 100644 --- a/source/main/gameplay/Character.cpp +++ b/source/main/gameplay/Character.cpp @@ -570,7 +570,6 @@ GfxCharacter* Character::SetupGfx() m_gfx_character = new GfxCharacter(); m_gfx_character->xc_scenenode = scenenode; - m_gfx_character->xc_movable_text = nullptr; m_gfx_character->xc_character = this; m_gfx_character->xc_instance_name = m_instance_name; @@ -583,10 +582,6 @@ RoR::GfxCharacter::~GfxCharacter() xc_scenenode->detachAllObjects(); App::GetGfxScene()->GetSceneManager()->destroySceneNode(xc_scenenode); App::GetGfxScene()->GetSceneManager()->destroyEntity(ent); - if (xc_movable_text != nullptr) - { - delete xc_movable_text; - } MaterialManager::getSingleton().unload("tracks/" + xc_instance_name); } @@ -612,20 +607,12 @@ void RoR::GfxCharacter::UpdateCharacterInScene() if (xc_simbuf.simbuf_actor_coupling != nullptr) { // Entering/switching vehicle - if (xc_movable_text != nullptr) - { - xc_movable_text->setVisible(false); - } xc_scenenode->getAttachedObject(0)->setCastShadows(false); xc_scenenode->setVisible(xc_simbuf.simbuf_actor_coupling->GetGfxActor()->HasDriverSeatProp()); } else if (xc_simbuf_prev.simbuf_actor_coupling != nullptr) { // Leaving vehicle - if (xc_movable_text != nullptr) - { - xc_movable_text->setVisible(true); - } xc_scenenode->getAttachedObject(0)->setCastShadows(true); xc_scenenode->resetOrientation(); } @@ -654,10 +641,6 @@ void RoR::GfxCharacter::UpdateCharacterInScene() // If visible, update position if (entity->isVisible()) { - if (xc_movable_text != nullptr) - { - xc_movable_text->setVisible(false); - } Ogre::Vector3 pos; Ogre::Quaternion rot; xc_simbuf.simbuf_actor_coupling->GetGfxActor()->CalculateDriverPos(pos, rot); @@ -707,14 +690,6 @@ void RoR::GfxCharacter::UpdateCharacterInScene() #ifdef USE_SOCKETW if (App::mp_state->getEnum() == MpState::CONNECTED && !xc_simbuf.simbuf_actor_coupling) { - if (xc_movable_text == nullptr) - { - xc_movable_text = new MovableText("netlabel-" + xc_instance_name, ""); - xc_movable_text->setTextAlignment(MovableText::H_CENTER, MovableText::V_ABOVE); - xc_movable_text->setColor(ColourValue::Black); - xc_scenenode->attachObject(xc_movable_text); - } - // From 'updateCharacterNetworkColor()' const String materialName = "tracks/" + xc_instance_name; @@ -725,18 +700,11 @@ void RoR::GfxCharacter::UpdateCharacterInScene() const auto& state = mat->getTechnique(0)->getPass(1)->getTextureUnitState(1); Ogre::ColourValue color = App::GetNetwork()->GetPlayerColor(xc_simbuf.simbuf_color_number); state->setColourOperationEx(LBX_BLEND_CURRENT_ALPHA, LBS_MANUAL, LBS_CURRENT, color); - if (xc_movable_text != nullptr) - xc_movable_text->setColor(color); } - if (xc_movable_text != nullptr) + if ((!xc_simbuf.simbuf_is_remote && !App::mp_hide_own_net_label->getBool()) || + (xc_simbuf.simbuf_is_remote && !App::mp_hide_net_labels->getBool())) { - if (App::mp_hide_net_labels->getBool() || (!xc_simbuf.simbuf_is_remote && App::mp_hide_own_net_label->getBool())) - { - xc_movable_text->setVisible(false); - return; - } - float camDist = (xc_scenenode->getPosition() - App::GetCameraManager()->GetCameraNode()->getPosition()).length(); Ogre::Vector3 scene_pos = xc_scenenode->getPosition(); scene_pos.y += (1.9f + camDist / 100.0f); diff --git a/source/main/gameplay/Character.h b/source/main/gameplay/Character.h index c1c2e8bbc3..8615d4f56c 100644 --- a/source/main/gameplay/Character.h +++ b/source/main/gameplay/Character.h @@ -106,7 +106,6 @@ struct GfxCharacter void UpdateCharacterInScene(); Ogre::SceneNode* xc_scenenode; - MovableText* xc_movable_text; // TODO: Remake using GUI; the network labels shouldn't be part of scene. ~only_a_ptr, 05/2018 SimBuffer xc_simbuf; SimBuffer xc_simbuf_prev; Character* xc_character; From e8b71d775f7b37e9c30ffe6108d3bd6577759f42 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 23 Aug 2021 23:31:18 +0200 Subject: [PATCH 18/24] :wastebasket: Rem. unused MovableText from Actor - using imgui. --- source/main/physics/Actor.cpp | 9 --------- source/main/physics/Actor.h | 3 --- source/main/physics/ActorManager.cpp | 14 -------------- 3 files changed, 26 deletions(-) diff --git a/source/main/physics/Actor.cpp b/source/main/physics/Actor.cpp index 6b784ee219..1680eb6853 100644 --- a/source/main/physics/Actor.cpp +++ b/source/main/physics/Actor.cpp @@ -245,13 +245,6 @@ Actor::~Actor() delete (*it); } - if (m_net_label_mt) - { - m_net_label_mt->setVisible(false); - delete m_net_label_mt; - m_net_label_mt = nullptr; - } - if (m_intra_point_col_detector) { delete m_intra_point_col_detector; @@ -4417,8 +4410,6 @@ Actor::Actor( , m_mouse_grab_node(-1) , m_mouse_grab_pos(Ogre::Vector3::ZERO) , m_net_initialized(false) - , m_net_label_node(0) - , m_net_label_mt(0) , ar_initial_total_mass(0) , ar_parking_brake(false) , ar_trailer_parking_brake(false) diff --git a/source/main/physics/Actor.h b/source/main/physics/Actor.h index 1269fa0bff..7acd0110ef 100644 --- a/source/main/physics/Actor.h +++ b/source/main/physics/Actor.h @@ -25,7 +25,6 @@ #include "CmdKeyInertia.h" #include "Differentials.h" #include "GfxActor.h" -#include "MovableText.h" #include "PerVehicleCameraContext.h" #include "RigDef_Prerequisites.h" #include "SimData.h" @@ -467,8 +466,6 @@ class Actor : public ZeroedMemoryAllocator Ogre::Vector3 m_mouse_grab_pos; float m_mouse_grab_move_force; float m_spawn_rotation; - MovableText* m_net_label_mt; - Ogre::SceneNode* m_net_label_node; Ogre::UTFString m_net_username; int m_net_color_num; Ogre::Timer m_reset_timer; diff --git a/source/main/physics/ActorManager.cpp b/source/main/physics/ActorManager.cpp index c352f9ab2f..2af7a6b768 100644 --- a/source/main/physics/ActorManager.cpp +++ b/source/main/physics/ActorManager.cpp @@ -315,20 +315,6 @@ void ActorManager::SetupActor(Actor* actor, ActorSpawnRequest rq, std::shared_pt actor->m_net_username = rq.asr_net_username; actor->m_net_color_num = rq.asr_net_color; - - RoR::Str<100> element_name; - ActorSpawner::ComposeName(element_name, "NetLabel", 0, actor->ar_instance_id); - actor->m_net_label_mt = new MovableText(element_name.ToCStr(), actor->m_net_username); - actor->m_net_label_mt->setTextAlignment(MovableText::H_CENTER, MovableText::V_ABOVE); -#ifdef USE_SOCKETW - actor->m_net_label_mt->setColor(App::GetNetwork()->GetPlayerColor((rq.asr_net_color))); -#endif // USE_SOCKETW - actor->m_net_label_mt->setVisible(true); - - actor->m_net_label_node = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode(); - actor->m_net_label_node->attachObject(actor->m_net_label_mt); - actor->m_net_label_node->setVisible(true); - actor->m_deletion_scene_nodes.emplace_back(actor->m_net_label_node); } else if (App::sim_replay_enabled->getBool()) { From cde43f8d6d2ed514d5620b1a68dee04c1d6b9ae9 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 28 Aug 2021 18:56:37 +0200 Subject: [PATCH 19/24] Removed dupli. code - SetAllMeshesVisible() handles that. --- source/main/main.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/main/main.cpp b/source/main/main.cpp index e59b65afaa..e138a95c02 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -637,8 +637,6 @@ int main(int argc, char *argv[]) actor->ar_state = ActorState::NETWORKED_HIDDEN; // Stop net. updates App::GetGfxScene()->RemoveGfxActor(actor->GetGfxActor()); // Remove visuals (also stops updating SimBuffer) actor->GetGfxActor()->GetSimDataBuffer().simbuf_actor_state = ActorState::NETWORKED_HIDDEN; // Hack - manually propagate the new state to SimBuffer so Character can reflect it. - actor->GetGfxActor()->SetFlexbodyVisible(false); - actor->GetGfxActor()->SetWheelsVisible(false); actor->GetGfxActor()->SetAllMeshesVisible(false); actor->GetGfxActor()->SetWingsVisible(false); actor->GetGfxActor()->SetCastShadows(false); @@ -656,8 +654,6 @@ int main(int argc, char *argv[]) Actor* actor = (Actor*)m.payload; actor->ar_state = ActorState::NETWORKED_OK; // Resume net. updates App::GetGfxScene()->RegisterGfxActor(actor->GetGfxActor()); // Restore visuals (also resumes updating SimBuffer) - actor->GetGfxActor()->SetFlexbodyVisible(true); - actor->GetGfxActor()->SetWheelsVisible(true); actor->GetGfxActor()->SetAllMeshesVisible(true); actor->GetGfxActor()->SetWingsVisible(true); actor->GetGfxActor()->SetCastShadows(true); From 39274ee125308b3ee931b50740d170eed864094e Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 28 Aug 2021 19:00:20 +0200 Subject: [PATCH 20/24] Code cleanup - do more in SetAllMeshesVisible() --- source/main/gfx/GfxActor.cpp | 20 ++++---------------- source/main/main.cpp | 4 ---- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index 3f599935c4..7cad417554 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -3285,32 +3285,20 @@ void RoR::GfxActor::SetAllMeshesVisible(bool visible) this->SetWheelsVisible(visible); this->SetPropsVisible(visible); this->SetFlexbodyVisible(visible); + this->SetWingsVisible(visible); + this->SetRodsVisible(visible); } void RoR::GfxActor::SetWingsVisible(bool visible) { for (int i = 0; i < m_actor->ar_num_wings; ++i) { - if (!visible) - { - m_actor->ar_wings[i].cnode->setVisible(false); - } - else - { - m_actor->ar_wings[i].cnode->setVisible(true); - } + m_actor->ar_wings[i].cnode->setVisible(visible); } for (size_t i=0; i< m_actor->ar_airbrakes.size(); ++i) { - if (!visible) - { - m_gfx_airbrakes[i].abx_scenenode->setVisible(false); - } - else - { - m_gfx_airbrakes[i].abx_scenenode->setVisible(true); - } + m_gfx_airbrakes[i].abx_scenenode->setVisible(visible); } } diff --git a/source/main/main.cpp b/source/main/main.cpp index e138a95c02..b3f89e23f9 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -638,9 +638,7 @@ int main(int argc, char *argv[]) App::GetGfxScene()->RemoveGfxActor(actor->GetGfxActor()); // Remove visuals (also stops updating SimBuffer) actor->GetGfxActor()->GetSimDataBuffer().simbuf_actor_state = ActorState::NETWORKED_HIDDEN; // Hack - manually propagate the new state to SimBuffer so Character can reflect it. actor->GetGfxActor()->SetAllMeshesVisible(false); - actor->GetGfxActor()->SetWingsVisible(false); actor->GetGfxActor()->SetCastShadows(false); - actor->GetGfxActor()->SetRodsVisible(false); actor->muteAllSounds(); // Stop sounds actor->setLightsOff(); // Turn all lights off @@ -655,9 +653,7 @@ int main(int argc, char *argv[]) actor->ar_state = ActorState::NETWORKED_OK; // Resume net. updates App::GetGfxScene()->RegisterGfxActor(actor->GetGfxActor()); // Restore visuals (also resumes updating SimBuffer) actor->GetGfxActor()->SetAllMeshesVisible(true); - actor->GetGfxActor()->SetWingsVisible(true); actor->GetGfxActor()->SetCastShadows(true); - actor->GetGfxActor()->SetRodsVisible(true); actor->unmuteAllSounds(); // Unmute sounds } break; From 86ecc5bc5148a97e9689c359c184b9d2f3dffbf8 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 28 Aug 2021 19:21:05 +0200 Subject: [PATCH 21/24] :triangular_ruler: Big re-format of GfxActor.h, grouped functions. --- source/main/gfx/GfxActor.h | 151 +++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 67 deletions(-) diff --git a/source/main/gfx/GfxActor.h b/source/main/gfx/GfxActor.h index 7ff5026b2a..c1eb400812 100644 --- a/source/main/gfx/GfxActor.h +++ b/source/main/gfx/GfxActor.h @@ -188,76 +188,93 @@ class GfxActor ~GfxActor(); - void AddMaterialFlare (int flare_index, Ogre::MaterialPtr mat); - void SetMaterialFlareOn (int flare_index, bool state_on); - void RegisterCabMaterial(Ogre::MaterialPtr mat, Ogre::MaterialPtr mat_trans); - void RegisterCabMesh (Ogre::Entity* ent, Ogre::SceneNode* snode, FlexObj* flexobj); - void SetCabLightsActive (bool state_on); - void SetVideoCamState (VideoCamState state); - void UpdateVideoCameras (float dt_sec); - void UpdateParticles (float dt_sec); - void AddRod (int beam_index, int node1_index, int node2_index, const char* material_name, bool visible, float diameter_meters); - void UpdateRods (); - void SetRodsVisible (bool visible); - void ScaleActor (Ogre::Vector3 relpos, float ratio); - bool IsActorLive () const; //!< Should the visuals be updated for this actor? - bool IsActorInitialized () const { return m_initialized; } //!< Temporary TODO: Remove once the spawn routine is fixed - void InitializeActor () { m_initialized = true; } //!< Temporary TODO: Remove once the spawn routine is fixed - void UpdateSimDataBuffer(); //!< Copies sim. data from `Actor` to `GfxActor` for later update - void SetWheelVisuals (uint16_t index, WheelGfx wheel_gfx); - void CalculateDriverPos (Ogre::Vector3& out_pos, Ogre::Quaternion& out_rot); - void UpdateWheelVisuals (); - void FinishWheelUpdates (); - void UpdateFlexbodies (); - void FinishFlexbodyTasks(); - void SetFlexbodyVisible (bool visible); - void SetWheelsVisible (bool value); - void SetAllMeshesVisible(bool value); - void SetWingsVisible (bool visible); - void SetCastShadows (bool value); - void UpdateDebugView (); - void ToggleDebugView (); - void CycleDebugViews (); - void UpdateCabMesh (); - void UpdateWingMeshes (); - int GetActorId () const; - int GetActorState () const; - int GetNumFlexbodies () const { return static_cast(m_flexbodies.size()); } - void ResetFlexbodies (); - void SetFlexbodiesVisible(bool visible); - ActorType GetActorDriveable () const; - void RegisterAirbrakes (); - void RegisterProps (std::vector const& props, int driverseat_prop_idx); - void UpdateAirbrakes (); - void UpdateCParticles (); - void UpdateAeroEngines (); - void UpdateNetLabels (float dt); - void SetDebugView (DebugViewType dv); - void SortFlexbodies (); - void AddFlexbody (FlexBody* fb) { m_flexbodies.push_back(fb); } - Attributes& GetAttributes () { return m_attr; } - inline Ogre::MaterialPtr& GetCabTransMaterial() { return m_cab_mat_visual_trans; } - inline VideoCamState GetVideoCamState () const { return m_vidcam_state; } - inline DebugViewType GetDebugView () const { return m_debug_view; } - SimBuffer & GetSimDataBuffer () { return m_simbuf; } - SimBuffer::NodeSB* GetSimNodeBuffer () { return m_simbuf.simbuf_nodes.get(); } - std::set GetLinkedGfxActors () { return m_linked_gfx_actors; } - Ogre::String GetResourceGroup () { return m_custom_resource_group; } - Actor* GetActor () { return m_actor; } // Watch out for multithreading with this! - int FetchNumBeams () const ; - int FetchNumNodes () const ; - int FetchNumWheelNodes () const ; - bool HasDriverSeatProp () const { return m_driverseat_prop_index != -1; } - void UpdateBeaconFlare (Prop & prop, float dt, bool is_player_actor); - void UpdateProps (float dt, bool is_player_actor); + // Adding elements + + void AddMaterialFlare(int flare_index, Ogre::MaterialPtr mat); + void RegisterCabMaterial(Ogre::MaterialPtr mat, Ogre::MaterialPtr mat_trans); + void RegisterCabMesh(Ogre::Entity* ent, Ogre::SceneNode* snode, FlexObj* flexobj); + void AddRod(int beam_index, int node1_index, int node2_index, const char* material_name, bool visible, float diameter_meters); + void SetWheelVisuals(uint16_t index, WheelGfx wheel_gfx); + void RegisterAirbrakes(); + void RegisterProps(std::vector const& props, int driverseat_prop_idx); + void AddFlexbody(FlexBody* fb) { m_flexbodies.push_back(fb); } + void SortFlexbodies(); + + // Visual changes + + void SetMaterialFlareOn(int flare_index, bool state_on); + void SetCabLightsActive(bool state_on); + void SetVideoCamState(VideoCamState state); + void ScaleActor(Ogre::Vector3 relpos, float ratio); + void ToggleDebugView(); + void CycleDebugViews(); + void ResetFlexbodies(); + void SetRenderdashActive(bool active); + void SetBeaconsEnabled(bool beacon_light_is_active); + void SetDebugView(DebugViewType dv); + + // Visibility + + void SetRodsVisible(bool visible); + void SetFlexbodyVisible (bool visible); + void SetWheelsVisible(bool value); + void SetAllMeshesVisible(bool value); + void SetWingsVisible(bool visible); + void SetCastShadows(bool value); + void SetFlexbodiesVisible(bool visible); + void SetPropsVisible(bool visible); + + // Visual updates + + void UpdateVideoCameras(float dt_sec); + void UpdateParticles(float dt_sec); + void UpdateRods(); + void UpdateWheelVisuals(); + void UpdateFlexbodies(); + void UpdateDebugView(); + void UpdateCabMesh(); + void UpdateWingMeshes(); + void UpdateBeaconFlare(Prop & prop, float dt, bool is_player_actor); + void UpdateProps(float dt, bool is_player_actor); void UpdatePropAnimations(float dt, bool is_player_connected); - void SetPropsVisible (bool visible); - void SetRenderdashActive (bool active); + void UpdateAirbrakes(); + void UpdateCParticles(); + void UpdateAeroEngines(); + void UpdateNetLabels(float dt); + void UpdateFlares(float dt_sec, bool is_player); void UpdateRenderdashRTT (); - void SetBeaconsEnabled (bool beacon_light_is_active); - void CalcPropAnimation (const int flag_state, float& cstate, int& div, float timer, + + // Internal updates + + void UpdateSimDataBuffer(); //!< Copies sim. data from `Actor` to `GfxActor` for later update + void FinishWheelUpdates(); + void FinishFlexbodyTasks(); + + // Helpers + + bool IsActorLive() const; //!< Should the visuals be updated for this actor? + bool IsActorInitialized() const { return m_initialized; } //!< Temporary TODO: Remove once the spawn routine is fixed + void InitializeActor() { m_initialized = true; } //!< Temporary TODO: Remove once the spawn routine is fixed + void CalculateDriverPos(Ogre::Vector3& out_pos, Ogre::Quaternion& out_rot); + int GetActorId() const; + int GetActorState() const; + int GetNumFlexbodies() const { return static_cast(m_flexbodies.size()); } + ActorType GetActorDriveable() const; + Attributes& GetAttributes() { return m_attr; } + Ogre::MaterialPtr& GetCabTransMaterial() { return m_cab_mat_visual_trans; } + VideoCamState GetVideoCamState() const { return m_vidcam_state; } + DebugViewType GetDebugView() const { return m_debug_view; } + SimBuffer & GetSimDataBuffer() { return m_simbuf; } + SimBuffer::NodeSB* GetSimNodeBuffer() { return m_simbuf.simbuf_nodes.get(); } + std::set GetLinkedGfxActors() { return m_linked_gfx_actors; } + Ogre::String GetResourceGroup() { return m_custom_resource_group; } + Actor* GetActor() { return m_actor; } // Watch out for multithreading with this! + int FetchNumBeams() const ; + int FetchNumNodes() const ; + int FetchNumWheelNodes() const ; + bool HasDriverSeatProp() const { return m_driverseat_prop_index != -1; } + void CalcPropAnimation(const int flag_state, float& cstate, int& div, float timer, const float lower_limit, const float upper_limit, const float option3); - void UpdateFlares (float dt_sec, bool is_player); private: From 1d188f242c84a2476ac3c37e757dc263921f9db3 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 28 Aug 2021 20:20:39 +0200 Subject: [PATCH 22/24] :wrench: Ability to hide aeroengines --- source/main/gfx/GfxActor.cpp | 12 ++++++++++++ source/main/gfx/GfxActor.h | 2 ++ source/main/physics/air/AeroEngine.h | 5 ++++- source/main/physics/air/TurboJet.cpp | 20 +++++++++++++++++++- source/main/physics/air/TurboJet.h | 9 ++++++++- source/main/physics/air/TurboProp.cpp | 5 +++++ source/main/physics/air/TurboProp.h | 5 ++++- 7 files changed, 54 insertions(+), 4 deletions(-) diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index 7cad417554..fbfd4d1f48 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -2351,6 +2351,17 @@ void RoR::GfxActor::SetPropsVisible(bool visible) } } +void RoR::GfxActor::SetAeroEnginesVisible(bool visible) +{ + // For turbojets, this hides meshes (nozzle, abflame) and particles + // For turbo/piston-props, this only hides particles, meshes are in props. + + for (int i = 0; i < m_actor->ar_num_aeroengines; i++) + { + m_actor->ar_aeroengines[i]->setVisible(visible); + } +} + void RoR::GfxActor::SetRenderdashActive(bool active) { if (m_renderdash != nullptr) @@ -3287,6 +3298,7 @@ void RoR::GfxActor::SetAllMeshesVisible(bool visible) this->SetFlexbodyVisible(visible); this->SetWingsVisible(visible); this->SetRodsVisible(visible); + this->SetAeroEnginesVisible(visible); } void RoR::GfxActor::SetWingsVisible(bool visible) diff --git a/source/main/gfx/GfxActor.h b/source/main/gfx/GfxActor.h index c1eb400812..9d5ca92569 100644 --- a/source/main/gfx/GfxActor.h +++ b/source/main/gfx/GfxActor.h @@ -223,6 +223,8 @@ class GfxActor void SetCastShadows(bool value); void SetFlexbodiesVisible(bool visible); void SetPropsVisible(bool visible); + void SetAeroEnginesVisible(bool visible); + // Visual updates diff --git a/source/main/physics/air/AeroEngine.h b/source/main/physics/air/AeroEngine.h index 596b225f87..2f5572b4e4 100644 --- a/source/main/physics/air/AeroEngine.h +++ b/source/main/physics/air/AeroEngine.h @@ -37,7 +37,6 @@ class AeroEngine virtual ~AeroEngine() {} - virtual void updateVisuals(RoR::GfxActor* gfx_actor) =0; virtual void updateForces(float dt, int doUpdate) =0; virtual void setThrottle(float val) =0; @@ -65,6 +64,10 @@ class AeroEngine virtual int getNoderef() =0; virtual bool getWarmup() =0; virtual float getRadius() =0; + + // Visuals + virtual void updateVisuals(RoR::GfxActor* gfx_actor) = 0; + virtual void setVisible(bool visible) = 0; }; } // namespace RoR diff --git a/source/main/physics/air/TurboJet.cpp b/source/main/physics/air/TurboJet.cpp index 74c2b7ceb8..2a1b23122a 100644 --- a/source/main/physics/air/TurboJet.cpp +++ b/source/main/physics/air/TurboJet.cpp @@ -144,7 +144,13 @@ TurbojetVisual::~TurbojetVisual() void Turbojet::updateVisuals(RoR::GfxActor* gfx_actor) { - this->tjet_visual.UpdateVisuals(gfx_actor); + if (this->tjet_visual.IsVisible()) + this->tjet_visual.UpdateVisuals(gfx_actor); +} + +void Turbojet::setVisible(bool visible) +{ + this->tjet_visual.SetVisible(visible); } void TurbojetVisual::UpdateVisuals(RoR::GfxActor* gfx_actor) @@ -206,6 +212,18 @@ void TurbojetVisual::UpdateVisuals(RoR::GfxActor* gfx_actor) } } +void TurbojetVisual::SetVisible(bool visible) +{ + m_visible = visible; + m_smoke_particle->setVisible(visible); + m_nozzle_scenenode->setVisible(visible); + if (!visible) + { + // only hide, regular update will restore visibility if needed. + m_flame_scenenode->setVisible(false); + } +} + void Turbojet::updateForces(float dt, int doUpdate) { if (doUpdate) diff --git a/source/main/physics/air/TurboJet.h b/source/main/physics/air/TurboJet.h index 6e758e7e00..3f0481cc0e 100644 --- a/source/main/physics/air/TurboJet.h +++ b/source/main/physics/air/TurboJet.h @@ -33,6 +33,8 @@ class TurbojetVisual void SetupVisuals(RigDef::Turbojet & def, int num, std::string const& propname, Ogre::Entity* nozzle, Ogre::Entity* afterburner_flame, bool disable_smoke); void SetNodes(int front, int back, int ref); void UpdateVisuals(RoR::GfxActor* gfx_actor); + void SetVisible(bool visible); + bool IsVisible() const { return m_visible; } private: Ogre::SceneNode* m_smoke_scenenode; @@ -42,6 +44,7 @@ class TurbojetVisual Ogre::Entity* m_nozzle_entity; Ogre::SceneNode* m_nozzle_scenenode; + bool m_visible = false; // Needed for flames which are hidden by default. int m_number; float m_radius; uint16_t m_node_back; @@ -65,7 +68,6 @@ class Turbojet: public AeroEngine, public ZeroedMemoryAllocator void setReverse(bool val); bool getReverse() { return m_reverse; }; void updateForces(float dt, int doUpdate); - void updateVisuals(RoR::GfxActor* gfx_actor) override; Ogre::Vector3 getAxis() { return m_axis; }; @@ -84,6 +86,11 @@ class Turbojet: public AeroEngine, public ZeroedMemoryAllocator int getNoderef() { return m_node_back; }; int getType() { return AEROENGINE_TYPE_TURBOJET; }; + // AeroEngine visuals + + void updateVisuals(RoR::GfxActor* gfx_actor) override; + void setVisible(bool visible) override; + bool tjet_afterburnable; TurbojetVisual tjet_visual; diff --git a/source/main/physics/air/TurboProp.cpp b/source/main/physics/air/TurboProp.cpp index 541c6b8fad..d83a72c806 100644 --- a/source/main/physics/air/TurboProp.cpp +++ b/source/main/physics/air/TurboProp.cpp @@ -208,6 +208,11 @@ void Turboprop::updateVisuals(RoR::GfxActor* gfx_actor) #endif } +void Turboprop::setVisible(bool visible) +{ + smokePS->setVisible(visible); +} + void Turboprop::updateForces(float dt, int doUpdate) { if (doUpdate) diff --git a/source/main/physics/air/TurboProp.h b/source/main/physics/air/TurboProp.h index 0b8532a0d7..80993f5b72 100644 --- a/source/main/physics/air/TurboProp.h +++ b/source/main/physics/air/TurboProp.h @@ -55,7 +55,6 @@ class Turboprop: public AeroEngine, public ZeroedMemoryAllocator ); ~Turboprop(); - void updateVisuals(RoR::GfxActor* gfx_actor) override; void updateForces(float dt, int doUpdate); void setThrottle(float val); @@ -83,6 +82,10 @@ class Turboprop: public AeroEngine, public ZeroedMemoryAllocator bool getWarmup() { return warmup; }; float getRadius() { return radius; }; + // Visuals + void updateVisuals(RoR::GfxActor* gfx_actor) override; + void setVisible(bool visible) override; + private: node_t* nodes; From 1194484828e598e4f79a2badd709b61287314338 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Mon, 13 Sep 2021 22:44:05 +0200 Subject: [PATCH 23/24] Actor: added `get/setSmokeEnabled()` for ad-hoc use. Fixed `m_disable_smoke` field - now valid to be changed in real time, previously mixed - would affect exhausts but not turbojets. --- source/main/gfx/GfxActor.cpp | 1 + source/main/gfx/GfxActor.h | 1 + source/main/main.cpp | 3 ++- source/main/physics/Actor.h | 4 +++- source/main/physics/ActorSpawner.cpp | 6 +----- source/main/physics/air/TurboJet.cpp | 28 ++++++++++++---------------- source/main/physics/air/TurboJet.h | 2 +- 7 files changed, 21 insertions(+), 24 deletions(-) diff --git a/source/main/gfx/GfxActor.cpp b/source/main/gfx/GfxActor.cpp index fbfd4d1f48..bdf8dec23d 100644 --- a/source/main/gfx/GfxActor.cpp +++ b/source/main/gfx/GfxActor.cpp @@ -1742,6 +1742,7 @@ void RoR::GfxActor::UpdateSimDataBuffer() m_simbuf.simbuf_node0_velo = m_actor->ar_nodes[0].Velocity; m_simbuf.simbuf_net_username = m_actor->m_net_username; m_simbuf.simbuf_net_colornum = m_actor->m_net_color_num; + m_simbuf.simbuf_smoke_enabled = m_actor->getSmokeEnabled(); // General info m_simbuf.simbuf_actor_state = m_actor->ar_state; diff --git a/source/main/gfx/GfxActor.h b/source/main/gfx/GfxActor.h index 9d5ca92569..17e1d8c39a 100644 --- a/source/main/gfx/GfxActor.h +++ b/source/main/gfx/GfxActor.h @@ -132,6 +132,7 @@ class GfxActor float simbuf_inputshaft_rpm = 0; // Land vehicle only float simbuf_drive_ratio = 0; // Land vehicle only bool simbuf_beaconlight_active = false; + bool simbuf_smoke_enabled = false; float simbuf_hydro_dir_state = 0; // State of steering actuator ('hydro'), for steeringwheel display float simbuf_hydro_aileron_state = 0; float simbuf_hydro_elevator_state = 0; diff --git a/source/main/main.cpp b/source/main/main.cpp index b3f89e23f9..8cb5e0f72a 100644 --- a/source/main/main.cpp +++ b/source/main/main.cpp @@ -641,7 +641,7 @@ int main(int argc, char *argv[]) actor->GetGfxActor()->SetCastShadows(false); actor->muteAllSounds(); // Stop sounds actor->setLightsOff(); // Turn all lights off - + actor->setSmokeEnabled(false); } break; @@ -655,6 +655,7 @@ int main(int argc, char *argv[]) actor->GetGfxActor()->SetAllMeshesVisible(true); actor->GetGfxActor()->SetCastShadows(true); actor->unmuteAllSounds(); // Unmute sounds + actor->setSmokeEnabled(true); } break; diff --git a/source/main/physics/Actor.h b/source/main/physics/Actor.h index 7acd0110ef..cee5c966ee 100644 --- a/source/main/physics/Actor.h +++ b/source/main/physics/Actor.h @@ -123,6 +123,8 @@ class Actor : public ZeroedMemoryAllocator Ogre::String getTransferCaseName(); //! Gets the current transfer case mode name (4WD Hi, ...) void displayTransferCaseMode(); //! Writes info to console/notify area void toggleCustomParticles(); + void setSmokeEnabled(bool enabled) { m_disable_smoke = !enabled; } + bool getSmokeEnabled() const { return !m_disable_smoke; } bool getCustomParticleMode(); void beaconsToggle(); bool getBrakeLightVisible(); @@ -534,7 +536,7 @@ class Actor : public ZeroedMemoryAllocator bool m_beam_deform_debug_enabled:1; //!< Logging state bool m_trigger_debug_enabled:1; //!< Logging state bool m_disable_default_sounds:1; //!< Spawner context; TODO: remove - bool m_disable_smoke:1; //!< Gfx state + bool m_disable_smoke:1; //!< Stops/starts smoke particles (i.e. exhausts, turbojets). struct VehicleForceSensors { diff --git a/source/main/physics/ActorSpawner.cpp b/source/main/physics/ActorSpawner.cpp index 57cc2df323..a58a77ae5e 100644 --- a/source/main/physics/ActorSpawner.cpp +++ b/source/main/physics/ActorSpawner.cpp @@ -656,7 +656,7 @@ void ActorSpawner::ProcessTurbojet(RigDef::Turbojet & def) std::string propname = this->ComposeName("Turbojet", m_actor->ar_num_aeroengines); tj->tjet_visual.SetNodes(front, back, ref); tj->tjet_visual.SetupVisuals(def, m_actor->ar_num_aeroengines, - propname, nozzle_ent, afterburn_ent, m_actor->m_disable_smoke); + propname, nozzle_ent, afterburn_ent); m_actor->ar_aeroengines[m_actor->ar_num_aeroengines]=tj; m_actor->ar_driveable=AIRPLANE; @@ -5749,10 +5749,6 @@ void ActorSpawner::AddExhaust( unsigned int direction_node_idx ) { - if (m_actor->m_disable_smoke) - { - return; - } exhaust_t exhaust; exhaust.emitterNode = emitter_node_idx; exhaust.directionNode = direction_node_idx; diff --git a/source/main/physics/air/TurboJet.cpp b/source/main/physics/air/TurboJet.cpp index 2a1b23122a..121dec559c 100644 --- a/source/main/physics/air/TurboJet.cpp +++ b/source/main/physics/air/TurboJet.cpp @@ -70,7 +70,7 @@ Turbojet::Turbojet(Actor* actor, int tnodefront, int tnodeback, int tnoderef, Ri reset(); } -void TurbojetVisual::SetupVisuals(RigDef::Turbojet & def, int num, std::string const& propname, Ogre::Entity* nozzle, Ogre::Entity* afterburner_flame, bool disable_smoke) +void TurbojetVisual::SetupVisuals(RigDef::Turbojet & def, int num, std::string const& propname, Ogre::Entity* nozzle, Ogre::Entity* afterburner_flame) { m_radius = def.back_diameter / 2.0; m_number = num; @@ -88,23 +88,17 @@ void TurbojetVisual::SetupVisuals(RigDef::Turbojet & def, int num, std::string c m_flame_scenenode->setScale(1.0, def.back_diameter, def.back_diameter); m_flame_scenenode->setVisible(false); } + //smoke visual - if (disable_smoke) + m_smoke_scenenode = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode(); + m_smoke_particle = App::GetGfxScene()->GetSceneManager()->createParticleSystem("SmokeParticle-"+propname, "tracks/TurbopropSmoke"); + if (m_smoke_particle) { - m_smoke_scenenode = 0; - m_smoke_particle = 0; - } - else - { - m_smoke_scenenode = App::GetGfxScene()->GetSceneManager()->getRootSceneNode()->createChildSceneNode(); - m_smoke_particle = App::GetGfxScene()->GetSceneManager()->createParticleSystem("SmokeParticle-"+propname, "tracks/TurbopropSmoke"); - if (m_smoke_particle) - { - m_smoke_particle->setVisibilityFlags(DEPTHMAP_DISABLED); // disable particles in depthmap - m_smoke_scenenode->attachObject(m_smoke_particle); - m_smoke_particle->setCastShadows(false); - } + m_smoke_particle->setVisibilityFlags(DEPTHMAP_DISABLED); // disable particles in depthmap + m_smoke_scenenode->attachObject(m_smoke_particle); + m_smoke_particle->setCastShadows(false); } + } void TurbojetVisual::SetNodes(int front, int back, int ref) @@ -181,8 +175,10 @@ void TurbojetVisual::UpdateVisuals(RoR::GfxActor* gfx_actor) } else m_flame_scenenode->setVisible(false); + //smoke - if (m_smoke_scenenode) + if (m_smoke_particle && + gfx_actor->GetSimDataBuffer().simbuf_smoke_enabled) { m_smoke_scenenode->setPosition(node_buf[m_node_back].AbsPosition); ParticleEmitter* emit = m_smoke_particle->getEmitter(0); diff --git a/source/main/physics/air/TurboJet.h b/source/main/physics/air/TurboJet.h index 3f0481cc0e..394b38cfb1 100644 --- a/source/main/physics/air/TurboJet.h +++ b/source/main/physics/air/TurboJet.h @@ -30,7 +30,7 @@ class TurbojetVisual { public: ~TurbojetVisual(); - void SetupVisuals(RigDef::Turbojet & def, int num, std::string const& propname, Ogre::Entity* nozzle, Ogre::Entity* afterburner_flame, bool disable_smoke); + void SetupVisuals(RigDef::Turbojet & def, int num, std::string const& propname, Ogre::Entity* nozzle, Ogre::Entity* afterburner_flame); void SetNodes(int front, int back, int ref); void UpdateVisuals(RoR::GfxActor* gfx_actor); void SetVisible(bool visible); From 13c9158b0efe8817d89876254329832f36e63c3e Mon Sep 17 00:00:00 2001 From: tritonas00 Date: Tue, 14 Sep 2021 16:40:29 +0300 Subject: [PATCH 24/24] fixes --- source/main/physics/Actor.cpp | 4 ++-- source/main/physics/ActorSpawner.cpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/main/physics/Actor.cpp b/source/main/physics/Actor.cpp index 1680eb6853..c2b01a1fe4 100644 --- a/source/main/physics/Actor.cpp +++ b/source/main/physics/Actor.cpp @@ -3186,7 +3186,7 @@ void Actor::updateVisual(float dt) // update exhausts // TODO: Move to GfxActor, don't forget dt*m_simulation_speed - if (!m_disable_smoke && ar_engine && exhausts.size() > 0) + if (ar_engine && exhausts.size() > 0) { std::vector::iterator it; for (it = exhausts.begin(); it != exhausts.end(); it++) @@ -3198,7 +3198,7 @@ void Actor::updateVisual(float dt) ParticleEmitter* emit = it->smoker->getEmitter(0); it->smokeNode->setPosition(ar_nodes[it->emitterNode].AbsPosition); emit->setDirection(dir); - if (ar_engine->GetSmoke() != -1.0) + if (!m_disable_smoke && ar_engine->GetSmoke() != -1.0) { emit->setEnabled(true); emit->setColour(ColourValue(0.0, 0.0, 0.0, 0.02 + ar_engine->GetSmoke() * 0.06)); diff --git a/source/main/physics/ActorSpawner.cpp b/source/main/physics/ActorSpawner.cpp index a58a77ae5e..6aaff83bbb 100644 --- a/source/main/physics/ActorSpawner.cpp +++ b/source/main/physics/ActorSpawner.cpp @@ -657,6 +657,10 @@ void ActorSpawner::ProcessTurbojet(RigDef::Turbojet & def) tj->tjet_visual.SetNodes(front, back, ref); tj->tjet_visual.SetupVisuals(def, m_actor->ar_num_aeroengines, propname, nozzle_ent, afterburn_ent); + if (!m_actor->m_disable_smoke) + { + tj->tjet_visual.SetVisible(true); + } m_actor->ar_aeroengines[m_actor->ar_num_aeroengines]=tj; m_actor->ar_driveable=AIRPLANE;