Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Multiplayer improvements #2760

Merged
merged 24 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
009bcf6
added hide/unhide/remove buttons in mp actor list
tritonas00 Jun 10, 2021
6f01450
use eject button
tritonas00 Jun 11, 2021
a6a5b0e
:triangular_ruler: Reorganized actor state enum + variable.
ohlidalp Sep 13, 2021
65e3c3a
:wrench: when hiding remote vehicle, also hide seated character.
ohlidalp Sep 13, 2021
fd13413
Fixed character appearing even if vehicle has no driverseat!
ohlidalp Jun 12, 2021
81cb689
use X for remove button, mute/unmute sounds, alligned buttons
tritonas00 Jun 12, 2021
e925527
hide lights
tritonas00 Jun 15, 2021
f6604af
fixed remote actor not unregistering when hidden
tritonas00 Jun 15, 2021
8187fed
hide wings
tritonas00 Jun 15, 2021
7dcdb9a
hide airbrakes
tritonas00 Jun 15, 2021
1911bc0
:label: MP labels are now drawn by DearIMGUI (prototype).
ohlidalp Jun 27, 2021
448aae7
:triangular_ruler: (minor) Rem. redundant namespace qualifier
ohlidalp Jun 28, 2021
b322a87
:label: Character net labels also drawn by DearIMGUI
ohlidalp Jun 28, 2021
b9c0320
:label: Net. labels now colored and highlighted.
ohlidalp Jun 28, 2021
f54ab47
use AddRectFilled, rounded corners
tritonas00 Jun 29, 2021
04a2edf
:label: DearIMGUI net labels - corrected centering.
ohlidalp Aug 23, 2021
b8ad1b8
:wastebasket: Rem. unused MovableText - now using DearIMGUI.
ohlidalp Aug 23, 2021
e8b71d7
:wastebasket: Rem. unused MovableText from Actor - using imgui.
ohlidalp Aug 23, 2021
cde43f8
Removed dupli. code - SetAllMeshesVisible() handles that.
ohlidalp Aug 28, 2021
39274ee
Code cleanup - do more in SetAllMeshesVisible()
ohlidalp Aug 28, 2021
86ecc5b
:triangular_ruler: Big re-format of GfxActor.h, grouped functions.
ohlidalp Aug 28, 2021
1d188f2
:wrench: Ability to hide aeroengines
ohlidalp Aug 28, 2021
1194484
Actor: added `get/setSmokeEnabled()` for ad-hoc use.
ohlidalp Sep 13, 2021
13c9158
fixes
tritonas00 Sep 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions source/main/GameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
Expand Down
72 changes: 24 additions & 48 deletions source/main/gameplay/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand All @@ -612,34 +607,40 @@ 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();
}
}

// Position + Orientation
Ogre::Entity* entity = static_cast<Ogre::Entity*>(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(gfx_actor->HasDriverSeatProp());
break;
default:
break; // no change.
}

// 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);
Expand All @@ -657,7 +658,6 @@ void RoR::GfxCharacter::UpdateCharacterInScene()
}

// Animation
Ogre::Entity* entity = static_cast<Ogre::Entity*>(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
Expand Down Expand Up @@ -690,14 +690,6 @@ void RoR::GfxCharacter::UpdateCharacterInScene()
#ifdef USE_SOCKETW
if (App::mp_state->getEnum<MpState>() == 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;

Expand All @@ -708,32 +700,16 @@ 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);

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
Expand Down
1 change: 0 additions & 1 deletion source/main/gameplay/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions source/main/gameplay/RecoveryMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void RecoveryMode::UpdateInputEvents(float dt)
{
if (App::sim_state->getEnum<SimState>() != 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;
}
Expand Down
8 changes: 4 additions & 4 deletions source/main/gameplay/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion source/main/gameplay/SceneMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, Real> pair = mouseRay.intersects(actor->ar_bounding_box);
Expand Down
85 changes: 46 additions & 39 deletions source/main/gfx/GfxActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -48,6 +49,8 @@
#include "TurboProp.h"
#include "Utils.h"

#include "imgui_internal.h"

#include <Ogre.h>

RoR::GfxActor::GfxActor(Actor* actor, ActorSpawner* spawner, std::string ogre_resource_group,
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -1726,8 +1720,6 @@ 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_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();
Expand All @@ -1749,7 +1741,12 @@ 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_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;
m_simbuf.simbuf_physics_paused = m_actor->ar_physics_paused;

// nodes
const int num_nodes = m_actor->ar_num_nodes;
Expand Down Expand Up @@ -1875,7 +1872,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()
Expand Down Expand Up @@ -1953,7 +1950,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<int>(m_actor->ar_sim_state); }
int RoR::GfxActor::GetActorState () const { return static_cast<int>(m_actor->ar_state); }

ActorType RoR::GfxActor::GetActorDriveable() const
{
Expand Down Expand Up @@ -2050,39 +2047,22 @@ 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)
{
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;
}

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));
App::GetGfxScene()->DrawNetLabel(scene_pos, vlen, m_simbuf.simbuf_net_username, m_simbuf.simbuf_net_colornum);

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)");
}
else if (vlen > 20) // 20 ... vlen ... 1000
{
m_actor->m_net_label_mt->setCaption(
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);
}
m_actor->m_net_label_mt->setVisible(true);
}
}

void RoR::GfxActor::CalculateDriverPos(Ogre::Vector3& out_pos, Ogre::Quaternion& out_rot)
Expand Down Expand Up @@ -2372,6 +2352,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)
Expand Down Expand Up @@ -3306,6 +3297,22 @@ void RoR::GfxActor::SetAllMeshesVisible(bool visible)
this->SetWheelsVisible(visible);
this->SetPropsVisible(visible);
this->SetFlexbodyVisible(visible);
this->SetWingsVisible(visible);
this->SetRodsVisible(visible);
this->SetAeroEnginesVisible(visible);
}

void RoR::GfxActor::SetWingsVisible(bool visible)
{
for (int i = 0; i < m_actor->ar_num_wings; ++i)
{
m_actor->ar_wings[i].cnode->setVisible(visible);
}

for (size_t i=0; i< m_actor->ar_airbrakes.size(); ++i)
{
m_gfx_airbrakes[i].abx_scenenode->setVisible(visible);
}
}

void RoR::GfxActor::UpdateWingMeshes()
Expand Down
Loading