Move menu_number_bias_wrapper bias into type signature

This commit is contained in:
Kp 2017-09-26 04:15:50 +00:00
parent 1641c87765
commit bba7e3a153
3 changed files with 25 additions and 20 deletions

View file

@ -537,12 +537,14 @@ public:
{
return get_mask() & get_bit();
}
menu_bit_wrapper_t &operator=(bool n)
menu_bit_wrapper_t &operator=(const bool n)
{
auto &m = get_mask();
const auto b = get_bit();
if (n)
get_mask() |= get_bit();
m |= b;
else
get_mask() &= ~get_bit();
m &= ~b;
return *this;
}
};
@ -553,31 +555,34 @@ static constexpr menu_bit_wrapper_t<T, B> menu_bit_wrapper(T &t, B b)
return {t, b};
}
template <typename T, typename B>
template <unsigned B, typename T>
class menu_number_bias_wrapper_t
{
T &m_value;
B m_bias;
std::tuple<T &, std::integral_constant<unsigned, B>> m_data;
#define m_value std::get<0>(m_data)
#define m_bias std::get<1>(m_data)
public:
constexpr menu_number_bias_wrapper_t(T &t, B bias) :
m_value(t), m_bias(bias)
constexpr menu_number_bias_wrapper_t(T &t) :
m_data(t, {})
{
}
constexpr operator T() const
{
return m_value + m_bias;
}
menu_number_bias_wrapper_t &operator=(T n)
menu_number_bias_wrapper_t &operator=(const T n)
{
m_value = n - m_bias;
return *this;
}
#undef m_bias
#undef m_value
};
template <typename T, typename B>
static constexpr menu_number_bias_wrapper_t<T, B> menu_number_bias_wrapper(T &t, B b)
template <unsigned B, typename T>
static constexpr menu_number_bias_wrapper_t<B, T> menu_number_bias_wrapper(T &t)
{
return {t, b};
return t;
}
#endif

View file

@ -1736,15 +1736,15 @@ public:
class cheat_menu_bit_invulnerability :
std::reference_wrapper<player_info>,
public menu_bit_wrapper_t<player_flags, PLAYER_FLAG>
public menu_bit_wrapper_t<player_flags, std::integral_constant<PLAYER_FLAG, PLAYER_FLAGS_INVULNERABLE>>
{
public:
cheat_menu_bit_invulnerability(player &plr) :
reference_wrapper(vmobjptr(plr.objnum)->ctype.player_info),
menu_bit_wrapper_t(get().powerup_flags, PLAYER_FLAGS_INVULNERABLE)
menu_bit_wrapper_t(get().powerup_flags, {})
{
}
cheat_menu_bit_invulnerability &operator=(uint32_t n)
cheat_menu_bit_invulnerability &operator=(const uint32_t n)
{
this->menu_bit_wrapper_t::operator=(n);
if (n)
@ -1759,15 +1759,15 @@ public:
class cheat_menu_bit_cloak :
std::reference_wrapper<player_info>,
public menu_bit_wrapper_t<player_flags, PLAYER_FLAG>
public menu_bit_wrapper_t<player_flags, std::integral_constant<PLAYER_FLAG, PLAYER_FLAGS_CLOAKED>>
{
public:
cheat_menu_bit_cloak(player &plr) :
reference_wrapper(vmobjptr(plr.objnum)->ctype.player_info),
menu_bit_wrapper_t(get().powerup_flags, PLAYER_FLAGS_CLOAKED)
menu_bit_wrapper_t(get().powerup_flags, {})
{
}
cheat_menu_bit_cloak &operator=(uint32_t n)
cheat_menu_bit_cloak &operator=(const uint32_t n)
{
this->menu_bit_wrapper_t::operator=(n);
if (n)
@ -1805,7 +1805,7 @@ public:
DXX_MENUITEM(VERB, NUMBER, "Shields", opt_shields, menu_fix_wrapper(plrobj.shields), 0, 200) \
DXX_MENUITEM(VERB, TEXT, TXT_SCORE, opt_txt_score) \
DXX_MENUITEM(VERB, INPUT, score_text, opt_score) \
DXX_MENUITEM(VERB, NUMBER, "Laser Level", opt_laser_level, menu_number_bias_wrapper(plr_laser_level, 1), LASER_LEVEL_1 + 1, DXX_MAXIMUM_LASER_LEVEL + 1) \
DXX_MENUITEM(VERB, NUMBER, "Laser Level", opt_laser_level, menu_number_bias_wrapper<1>(plr_laser_level), LASER_LEVEL_1 + 1, DXX_MAXIMUM_LASER_LEVEL + 1) \
DXX_MENUITEM(VERB, NUMBER, "Concussion", opt_concussion, plrobj.ctype.player_info.secondary_ammo[CONCUSSION_INDEX], 0, 200) \
static void do_cheat_menu()

View file

@ -3337,7 +3337,7 @@ static void net_udp_set_power (void)
#endif
#define DXX_GRANT_POWERUP_MENU(VERB) \
DXX_MENUITEM(VERB, NUMBER, "Laser level", opt_laser_level, menu_number_bias_wrapper(laser_level, 1), LASER_LEVEL_1 + 1, DXX_MAXIMUM_LASER_LEVEL + 1) \
DXX_MENUITEM(VERB, NUMBER, "Laser level", opt_laser_level, menu_number_bias_wrapper<1>(laser_level), LASER_LEVEL_1 + 1, DXX_MAXIMUM_LASER_LEVEL + 1) \
DXX_MENUITEM(VERB, CHECK, NETFLAG_LABEL_QUAD, opt_quad_lasers, menu_bit_wrapper(flags, NETGRANT_QUAD)) \
DXX_MENUITEM(VERB, CHECK, NETFLAG_LABEL_VULCAN, opt_vulcan, menu_bit_wrapper(flags, NETGRANT_VULCAN)) \
DXX_MENUITEM(VERB, CHECK, NETFLAG_LABEL_SPREAD, opt_spreadfire, menu_bit_wrapper(flags, NETGRANT_SPREAD)) \