Skip to content

Commit

Permalink
🐛 Fixed FlexbodyDebug UI 'hide other' not working for flexbodies.
Browse files Browse the repository at this point in the history
Broken in 9551d05 - since this commit flexbodies got a dynamic visibility control, exactly the same as props. From user (truck fileformat) perspective, it was the same already but the update pattern was different, and this commit unified it. The FlexbodyDebug UI didn't reflect this however.

In addition to fixing the glitch, this commit also unifies code for the visibility handling - same variables, same constants, just different prefixes.

Codechanges:
* GfxData: cosmetic changes to CAMERA_MODE constants - added typedef
* FlexBody: replaced single visibility mode field with _active+_orig fields, same as props have. Also using the same coding style as props do.
* GfxActor: cosmetic change - use the new variables in flexbody.
* ActorSpawner: set flexbody visibility via the new vars.
  • Loading branch information
ohlidalp committed Apr 13, 2024
1 parent 0f6b179 commit c91f285
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
7 changes: 3 additions & 4 deletions source/main/gfx/GfxActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2988,10 +2988,9 @@ void RoR::GfxActor::UpdateFlexbodies()

for (FlexBody* fb: m_flexbodies)
{
// Update visibility
fb->setVisible(
fb->getCameraMode() == CAMERA_MODE_ALWAYS_VISIBLE
|| fb->getCameraMode() == m_simbuf.simbuf_cur_cinecam);
// Update visibility (same logic as props)
const bool visible = (fb->fb_camera_mode_active == CAMERA_MODE_ALWAYS_VISIBLE || fb->fb_camera_mode_active == m_simbuf.simbuf_cur_cinecam);
fb->setVisible(visible);

// Update visible on background thread
if (fb->isVisible())
Expand Down
15 changes: 9 additions & 6 deletions source/main/gfx/GfxData.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ enum class WheelSide: char
};

// Dynamic visibility control (value 0 and higher is cinecam index) - common to 'props' and 'flexbodies'
static const int CAMERA_MODE_ALWAYS_HIDDEN = -3;
static const int CAMERA_MODE_ALWAYS_VISIBLE = -2;
static const int CAMERA_MODE_3RDPERSON_ONLY = -1;
typedef int CameraMode_t;
static CameraMode_t CAMERA_MODE_ALWAYS_HIDDEN = -3;
static CameraMode_t CAMERA_MODE_ALWAYS_VISIBLE = -2;
static CameraMode_t CAMERA_MODE_3RDPERSON_ONLY = -1;

enum ShifterPropAnim
{
Expand Down Expand Up @@ -171,9 +172,11 @@ struct Prop
std::string pp_media[2]; //!< Redundant, for Tuning UI. Media1 = prop mesh name, Media2 = steeringwheel mesh/beaconprop flare mat.
std::vector<PropAnim> pp_animations;

// Visibility control
int pp_camera_mode_active = CAMERA_MODE_ALWAYS_VISIBLE; //!< Dynamic visibility mode {0 and higher = cinecam index}
int pp_camera_mode_orig = CAMERA_MODE_ALWAYS_VISIBLE; //!< Dynamic visibility mode {0 and higher = cinecam index}
/// @name Visibility control (same as flexbody - see file FlexBody.h)
/// @{
CameraMode_t pp_camera_mode_active = CAMERA_MODE_ALWAYS_VISIBLE; //!< Dynamic visibility mode {0 and higher = cinecam index}
CameraMode_t pp_camera_mode_orig = CAMERA_MODE_ALWAYS_VISIBLE; //!< Dynamic visibility mode {0 and higher = cinecam index}
/// @}

// Special prop - steering wheel
MeshObject* pp_wheel_mesh_obj = nullptr;
Expand Down
15 changes: 14 additions & 1 deletion source/main/gui/panels/GUI_FlexbodyDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ void FlexbodyDebug::DrawDebugView(FlexBody* flexbody, Prop* prop, NodeNum_t node

void FlexbodyDebug::UpdateVisibility()
{
// Both flexbodies and props use the same dynamic visibility mode, see `CameraMode_t` typedef and constants in file GfxData.h
// ---------------------------------------------------------------------------------------------------------------------------

ActorPtr actor = App::GetGameContext()->GetPlayerActor();
if (!actor)
{
Expand All @@ -442,13 +445,18 @@ void FlexbodyDebug::UpdateVisibility()
{
prop.pp_camera_mode_active = CAMERA_MODE_ALWAYS_HIDDEN;
}
// Override flexbody dynamic visibility mode
for (FlexBody* flexbody: actor->GetGfxActor()->GetFlexbodies())
{
flexbody->fb_camera_mode_active = CAMERA_MODE_ALWAYS_HIDDEN;
}

// Then re-display what we need manually.
auto& flexbody_vec = actor->GetGfxActor()->GetFlexbodies();
const int combo_flexbody_selection = m_combo_selection;
if (combo_flexbody_selection >= 0 && combo_flexbody_selection < (int)flexbody_vec.size())
{
flexbody_vec[combo_flexbody_selection]->setVisible(true);
flexbody_vec[combo_flexbody_selection]->fb_camera_mode_active = CAMERA_MODE_ALWAYS_VISIBLE;
}

auto& prop_vec = actor->GetGfxActor()->getProps();
Expand All @@ -472,6 +480,11 @@ void FlexbodyDebug::UpdateVisibility()
{
prop.pp_camera_mode_active = prop.pp_camera_mode_orig;
}
// Restore flexbody dynamic visibility mode
for (FlexBody* flexbody: actor->GetGfxActor()->GetFlexbodies())
{
flexbody->fb_camera_mode_active = flexbody->fb_camera_mode_orig;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion source/main/physics/ActorSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,9 @@ void ActorSpawner::ProcessFlexbody(RigDef::Flexbody& def)
if (flexbody == nullptr)
return; // Error already logged

flexbody->setCameraMode(def.camera_settings.mode);
// Dynamic visibility - same as with props
flexbody->fb_camera_mode_orig = def.camera_settings.mode;
flexbody->fb_camera_mode_active = def.camera_settings.mode;

m_actor->m_gfx_actor->m_flexbodies.emplace_back(flexbody);
}
Expand Down
1 change: 1 addition & 0 deletions source/main/physics/flex/FlexBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ bool FlexBody::isVisible() const

void FlexBody::setVisible(bool visible)
{
// Scene node is NULL if disabled via addonpart/tuneup.
if (m_scene_node)
m_scene_node->setVisible(visible);
}
Expand Down
12 changes: 7 additions & 5 deletions source/main/physics/flex/FlexBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Application.h"
#include "Locator_t.h"
#include "SimData.h"
#include "GfxData.h"
#include "RigDef_File.h"
#include "Utils.h"

Expand Down Expand Up @@ -61,18 +62,19 @@ class FlexBody
typedef int FlexBodyPlaceholder_t;
static const FlexBodyPlaceholder_t TUNING_PLACEHOLDER = -11;

/// @name Visibility control (same as prop - see file GfxData.h)
/// @{
CameraMode_t fb_camera_mode_active = CAMERA_MODE_ALWAYS_VISIBLE; //!< Dynamic visibility mode {0 and higher = cinecam index}
CameraMode_t fb_camera_mode_orig = CAMERA_MODE_ALWAYS_VISIBLE; //!< Dynamic visibility mode {0 and higher = cinecam index}
/// @}

FlexBody(FlexBodyPlaceholder_t, FlexbodyID_t id, const std::string& orig_meshname);
~FlexBody();

void reset();
void updateBlend();
void writeBlend();

/// Visibility control
/// @param mode {-2 = always, -1 = 3rdPerson only, 0+ = cinecam index}
void setCameraMode(int mode) { m_camera_mode = mode; };
int getCameraMode() { return m_camera_mode; };

void computeFlexbody(); //!< Updates mesh deformation; works on CPU using local copy of vertex data.
void updateFlexbodyVertexBuffers();

Expand Down

0 comments on commit c91f285

Please sign in to comment.