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

Added hydro flag j, restored bug with i for backw. compat. #2933

Merged
merged 1 commit into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 2 additions & 9 deletions source/main/physics/ActorSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3590,12 +3590,7 @@ void ActorSpawner::ProcessHydro(RigDef::Hydro & def)
bool invisible = false;
unsigned int hydro_flags = 0;

if (def.options == 0)
{
invisible = false;
hydro_flags |= HYDRO_FLAG_DIR;
}
if (BITMASK_IS_1(def.options, RigDef::Hydro::OPTION_i_INVISIBLE))
if (BITMASK_IS_1(def.options, RigDef::Hydro::OPTION_j_INVISIBLE))
{
invisible = true;
}
Expand Down Expand Up @@ -3639,9 +3634,7 @@ void ActorSpawner::ProcessHydro(RigDef::Hydro & def)
{
hydro_flags |= (HYDRO_FLAG_REV_ELEVATOR | HYDRO_FLAG_RUDDER);
}

// if you use the 'INVISIBLE' flag on its own, add the direction to it
if (invisible && !hydro_flags)
if (BITMASK_IS_1(def.options, RigDef::Hydro::OPTION_n_INPUT_NORMAL))
{
hydro_flags |= HYDRO_FLAG_DIR;
}
Expand Down
9 changes: 6 additions & 3 deletions source/main/resources/rig_def_fileformat/RigDef_File.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ enum class BeamOption: char

enum class HydroOption: char
{
n_DUMMY = 'n',
i_INVISIBLE = 'i',
n_INPUT_NORMAL = 'n',
j_INVISIBLE = 'j',
i_INVISIBLE_INPUT_NORMAL = 'i', //!< For backwards compatibility; combines flags 'j' and 'n'.
// Useful for trucks
s_DISABLE_ON_HIGH_SPEED = 's',
// Useful for planes: These can be used to control flight surfaces, or to create a thrust vectoring system.
Expand Down Expand Up @@ -950,7 +951,7 @@ struct Hook

struct Hydro
{
static const BitMask_t OPTION_i_INVISIBLE = BITMASK(1);
static const BitMask_t OPTION_j_INVISIBLE = BITMASK(1);
// Useful for trucks:
static const BitMask_t OPTION_s_DISABLE_ON_HIGH_SPEED = BITMASK(2);
// Useful for planes: These can be used to control flight surfaces, or to create a thrust vectoring system.
Expand All @@ -963,6 +964,8 @@ struct Hydro
static const BitMask_t OPTION_y_INPUT_InvAILERON_RUDDER = BITMASK(9);
static const BitMask_t OPTION_g_INPUT_ELEVATOR_RUDDER = BITMASK(10);
static const BitMask_t OPTION_h_INPUT_InvELEVATOR_RUDDER = BITMASK(11);
// Generic steering input
static const BitMask_t OPTION_n_INPUT_NORMAL = BITMASK(12);

Node::Ref nodes[2];
float lenghtening_factor = 0.f;
Expand Down
19 changes: 17 additions & 2 deletions source/main/resources/rig_def_fileformat/RigDef_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,11 @@ void Parser::ParseHydros()
hydro.lenghtening_factor = this->GetArgFloat (2);

if (m_num_args > 3) { hydro.options = this->GetArgHydroOptions(3); }

if (!hydro.options)
{
hydro.options |= Hydro::OPTION_n_INPUT_NORMAL;
}

this->ParseOptionalInertia(hydro.inertia, 4);

Expand Down Expand Up @@ -3111,7 +3116,7 @@ BitMask_t Parser::GetArgHydroOptions (int index)
{
switch (c)
{
case (char)HydroOption::i_INVISIBLE : ret |= Hydro::OPTION_i_INVISIBLE ; break;
case (char)HydroOption::j_INVISIBLE : ret |= Hydro::OPTION_j_INVISIBLE ; break;
case (char)HydroOption::s_DISABLE_ON_HIGH_SPEED : ret |= Hydro::OPTION_s_DISABLE_ON_HIGH_SPEED ; break;
case (char)HydroOption::a_INPUT_AILERON : ret |= Hydro::OPTION_a_INPUT_AILERON ; break;
case (char)HydroOption::r_INPUT_RUDDER : ret |= Hydro::OPTION_r_INPUT_RUDDER ; break;
Expand All @@ -3122,14 +3127,24 @@ BitMask_t Parser::GetArgHydroOptions (int index)
case (char)HydroOption::y_INPUT_InvAILERON_RUDDER : ret |= Hydro::OPTION_y_INPUT_InvAILERON_RUDDER ; break;
case (char)HydroOption::g_INPUT_ELEVATOR_RUDDER : ret |= Hydro::OPTION_g_INPUT_ELEVATOR_RUDDER ; break;
case (char)HydroOption::h_INPUT_InvELEVATOR_RUDDER : ret |= Hydro::OPTION_h_INPUT_InvELEVATOR_RUDDER ; break;
case (char)HydroOption::n_INPUT_NORMAL : ret |= Hydro::OPTION_n_INPUT_NORMAL ; break;

case (char)HydroOption::n_DUMMY: break;
case (char)HydroOption::i_INVISIBLE_INPUT_NORMAL:
if (ret == 0)
{
// Original intent: when using 'i' flag alone, also force 'n' (steering input).
// For backward compatibility, do it every time 'i' comes first, even if not alone.
ret |= Hydro::OPTION_n_INPUT_NORMAL;
}
ret |= Hydro::OPTION_j_INVISIBLE;
break;

default:
this->LogMessage(Console::CONSOLE_SYSTEM_WARNING,
fmt::format("ignoring invalid option '{}'", c));
}
}

return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ void Serializer::ProcessHydro(Hydro & def)
m_stream << std::setw(m_float_width) << def.lenghtening_factor << ", ";

// Options
if (BITMASK_IS_1(def.options, Hydro::OPTION_i_INVISIBLE )) m_stream << (char)HydroOption::i_INVISIBLE ;
if (BITMASK_IS_1(def.options, Hydro::OPTION_j_INVISIBLE )) m_stream << (char)HydroOption::j_INVISIBLE ;
if (BITMASK_IS_1(def.options, Hydro::OPTION_s_DISABLE_ON_HIGH_SPEED )) m_stream << (char)HydroOption::s_DISABLE_ON_HIGH_SPEED ;
if (BITMASK_IS_1(def.options, Hydro::OPTION_a_INPUT_AILERON )) m_stream << (char)HydroOption::a_INPUT_AILERON ;
if (BITMASK_IS_1(def.options, Hydro::OPTION_r_INPUT_RUDDER )) m_stream << (char)HydroOption::r_INPUT_RUDDER ;
Expand All @@ -2107,7 +2107,8 @@ void Serializer::ProcessHydro(Hydro & def)
if (BITMASK_IS_1(def.options, Hydro::OPTION_y_INPUT_InvAILERON_RUDDER )) m_stream << (char)HydroOption::y_INPUT_InvAILERON_RUDDER ;
if (BITMASK_IS_1(def.options, Hydro::OPTION_g_INPUT_ELEVATOR_RUDDER )) m_stream << (char)HydroOption::g_INPUT_ELEVATOR_RUDDER ;
if (BITMASK_IS_1(def.options, Hydro::OPTION_h_INPUT_InvELEVATOR_RUDDER )) m_stream << (char)HydroOption::h_INPUT_InvELEVATOR_RUDDER ;
if (def.options == 0) m_stream << (char)HydroOption::n_DUMMY;
if (BITMASK_IS_1(def.options, Hydro::OPTION_n_INPUT_NORMAL )) m_stream << (char)HydroOption::n_INPUT_NORMAL;
if (def.options == 0) m_stream << (char)HydroOption::n_INPUT_NORMAL;
m_stream << ", ";

// Inertia
Expand Down