Skip to content

Commit

Permalink
🎮 Display all 10 user flares in multiplayer.
Browse files Browse the repository at this point in the history
The 'u' flares code was simplified and made similar to code for other flare types.

Control numbers clamped to range 1-10, see short explanation #2551 (comment) or detailed explanation: #2664 (comment)

CODECHANGES:
* m_custom_light_toggle_countdown removed, using classic `getEventBoolValueBounce()` - same effect, same delay
* disabled `controltoggle_status` in individual flares - replaced by `m_custom_lights`

fixes #2664
see also #32
  • Loading branch information
ohlidalp authored and Petr Ohlídal committed Apr 7, 2021
1 parent 7890fdf commit da21a24
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 37 deletions.
9 changes: 9 additions & 0 deletions source/main/GameContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@ void GameContext::UpdateSkyInputEvents(float dt)

void GameContext::UpdateCommonInputEvents(float dt)
{
ROR_ASSERT(m_player_actor);

// reload current truck
if (App::GetInputEngine()->getEventBoolValueBounce(EV_TRUCKEDIT_RELOAD, 0.5f))
{
Expand All @@ -1034,6 +1036,13 @@ void GameContext::UpdateCommonInputEvents(float dt)
if (App::GetInputEngine()->getEventBoolValueBounce(EV_TRUCK_BLINK_WARN))
m_player_actor->toggleBlinkType(BLINK_WARN);

// custom lights
for (int i = 0; i < MAX_CLIGHTS; i++)
{
if (App::GetInputEngine()->getEventBoolValueBounce(EV_TRUCK_LIGHTTOGGLE01 + i))
m_player_actor->setCustomLightVisible(i, !m_player_actor->getCustomLightVisible(i));
}

if (App::GetInputEngine()->getEventBoolValueBounce(EV_COMMON_TRUCK_REMOVE))
{
App::GetGameContext()->PushMessage(Message(MSG_SIM_DELETE_ACTOR_REQUESTED, (void*)m_player_actor));
Expand Down
27 changes: 4 additions & 23 deletions source/main/physics/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2986,15 +2986,11 @@ void Actor::ToggleLights()

void Actor::UpdateFlareStates(float dt)
{
if (m_custom_light_toggle_countdown > -1)
m_custom_light_toggle_countdown -= dt;

if (m_flares_mode == GfxFlaresMode::NONE) { return; }

// NOTE: Beacon flares are now updated in GfxActor::UpdateBeaconFlares()

//the flares
bool keysleep = false;
for (size_t i = 0; i < this->ar_flares.size(); i++)
{
// let the light blink
Expand Down Expand Up @@ -3032,18 +3028,9 @@ void Actor::UpdateFlareStates(float dt)
else
isvisible = false;
}
else if (ar_flares[i].fl_type == FlareType::USER && ar_flares[i].controlnumber != -1) // controlnumber = read only attribute
else if (ar_flares[i].fl_type == FlareType::USER)
{
if (ar_sim_state == Actor::SimState::LOCAL_SIMULATED && this == App::GetGameContext()->GetPlayerActor()) // no network!!
{
// networked customs are set directly, so skip this
if (RoR::App::GetInputEngine()->getEventBoolValue(EV_TRUCK_LIGHTTOGGLE01 + (ar_flares[i].controlnumber - 1)) && m_custom_light_toggle_countdown <= 0)
{
ar_flares[i].controltoggle_status = ! ar_flares[i].controltoggle_status;
keysleep = true;
}
}
isvisible = ar_flares[i].controltoggle_status;
isvisible = this->getCustomLightVisible(ar_flares[i].controlnumber);
}
else if (ar_flares[i].fl_type == FlareType::BLINKER_LEFT)
{
Expand Down Expand Up @@ -3080,8 +3067,6 @@ void Actor::UpdateFlareStates(float dt)

ar_flares[i].isVisible = isvisible; // 3D engine objects are updated in GfxActor
}
if (keysleep)
m_custom_light_toggle_countdown = 0.2;
}

void Actor::toggleBlinkType(BlinkType blink)
Expand Down Expand Up @@ -4421,7 +4406,6 @@ Actor::Actor(
, ar_net_source_id(0)
, m_spawn_rotation(0.0)
, ar_net_stream_id(0)
, m_custom_light_toggle_countdown(0)
, m_min_camera_radius(0.0f)
, m_mouse_grab_move_force(0.0f)
, m_mouse_grab_node(-1)
Expand Down Expand Up @@ -4531,7 +4515,7 @@ bool Actor::getCustomLightVisible(int number)
return false;
}

return m_net_custom_lights[number] < ar_flares.size() && ar_flares[m_net_custom_lights[number]].controltoggle_status;
return m_custom_lights[number];
}

void Actor::setCustomLightVisible(int number, bool visible)
Expand All @@ -4542,10 +4526,7 @@ void Actor::setCustomLightVisible(int number, bool visible)
return;
}

if (m_net_custom_lights[number] !=-1 && ar_flares[m_net_custom_lights[number]].snode)
{
ar_flares[m_net_custom_lights[number]].controltoggle_status = visible;
}
m_custom_lights[number] = visible;
}

bool Actor::getBeaconMode() // Angelscript export
Expand Down
4 changes: 1 addition & 3 deletions source/main/physics/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ class Actor : public ZeroedMemoryAllocator
Ogre::SceneNode* m_net_label_node;
Ogre::UTFString m_net_username;
Ogre::Timer m_reset_timer;
float m_custom_light_toggle_countdown; //!< Input system helper status
Ogre::Vector3 m_rotation_request_center;
float m_rotation_request; //!< Accumulator
int m_anglesnap_request; //!< Accumulator
Expand Down Expand Up @@ -491,8 +490,7 @@ class Actor : public ZeroedMemoryAllocator
float m_load_mass; //!< Physics attr; predefined load mass in Kg
int m_masscount; //!< Physics attr; Number of nodes loaded with l option
float m_dry_mass; //!< Physics attr;
int m_net_custom_lights[MAX_CLIGHTS]; //!< Sim state
unsigned char m_net_custom_light_count;//!< Sim attr
bool m_custom_lights[MAX_CLIGHTS] = {false}; //!< 'u' flares control number on/off states.
GfxFlaresMode m_flares_mode; //!< Gfx attr, clone of GVar -- TODO: remove
std::unique_ptr<Buoyance> m_buoyance; //!< Physics
CacheEntry* m_used_skin_entry; //!< Graphics
Expand Down
28 changes: 19 additions & 9 deletions source/main/physics/ActorSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include <OgreParticleSystem.h>
#include <OgreEntity.h>
#include <climits>
#include <fmt/format.h>

const char* ACTOR_ID_TOKEN = "@Actor_"; // Appended to material name, followed by actor ID (aka 'trucknum')

Expand Down Expand Up @@ -278,8 +279,6 @@ void ActorSpawner::InitializeRig()
m_actor->ar_cinecam_node[0]=-1;
m_actor->ar_num_cinecams=0;
m_actor->m_deletion_scene_nodes.clear();
for (int i=0; i<MAX_CLIGHTS; ++i) { m_actor->m_net_custom_lights[i] = -1; }
m_actor->m_net_custom_light_count = 0;

m_actor->ar_sim_state = Actor::SimState::LOCAL_SLEEPING;
m_actor->m_fusealge_airfoil = nullptr;
Expand Down Expand Up @@ -2030,8 +2029,7 @@ void ActorSpawner::ProcessFlare2(RigDef::Flare2 & def)

flare_t flare;
flare.fl_type = static_cast<FlareType>(def.type);
flare.controlnumber = def.control_number;
flare.controltoggle_status = false;
flare.controlnumber = -1;
flare.blinkdelay = (blink_delay == -1) ? 0.5f : blink_delay / 1000.f;
flare.blinkdelay_curr = 0.f;
flare.blinkdelay_state = false;
Expand Down Expand Up @@ -2129,19 +2127,31 @@ void ActorSpawner::ProcessFlare2(RigDef::Flare2 & def)
flare.light->setSpecularColour( Ogre::ColourValue(1, 1, 0));
flare.light->setAttenuation(10.0, 1, 1, 0);
}
//else if ((type == 'u') && flaresMode >= 4 && size > 0.001)
else if (def.type == RigDef::Flare2::TYPE_u_USER)
{
/* user light always white (TODO: improve this) */
flare.light=App::GetGfxScene()->GetSceneManager()->createLight(flare_name);
flare.light->setDiffuseColour( Ogre::ColourValue(1, 1, 1));
flare.light->setSpecularColour( Ogre::ColourValue(1, 1, 1));
flare.light->setAttenuation(50.0, 1.0, 1, 0.2);

if (m_actor->m_net_custom_light_count < MAX_CLIGHTS)
// control number: convert from 1-10 to 0-9
if (def.control_number < 1)
{
m_actor->m_net_custom_lights[m_actor->m_net_custom_light_count] = static_cast<int>(m_actor->ar_flares.size());
m_actor->m_net_custom_light_count++;
this->AddMessage(Message::TYPE_WARNING,
fmt::format("Bad flare control num {}, must be 1-{}, using 1.",
def.control_number, MAX_CLIGHTS));
flare.controlnumber = 0;
}
else if (def.control_number > MAX_CLIGHTS)
{
this->AddMessage(Message::TYPE_WARNING,
fmt::format("Bad flare control num {}, must be 1-{}, using {}.",
def.control_number, MAX_CLIGHTS, MAX_CLIGHTS));
flare.controlnumber = MAX_CLIGHTS-1;
}
else
{
flare.controlnumber = def.control_number - 1;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/main/physics/SimData.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ struct flare_t
Ogre::BillboardSet *bbs;
Ogre::Light *light;
FlareType fl_type;
int controlnumber;
bool controltoggle_status;
int controlnumber; //!< Only 'u' type flares, valid values 0-9, maps to EV_TRUCK_LIGHTTOGGLE01 to 10.
bool controltoggle_status; // UNUSED - TO BE REMOVED
float blinkdelay;
float blinkdelay_curr;
bool blinkdelay_state;
Expand Down

0 comments on commit da21a24

Please # to comment.