Move std::tie out of headers

This commit is contained in:
DS 2024-09-14 12:10:11 +02:00 committed by GitHub
parent a6219ab955
commit c54f5a2137
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 41 deletions

View File

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "util/serialize.h"
#include <sstream>
#include <tuple>
static const video::SColor NULL_BGCOLOR{0, 1, 1, 1};
@ -85,6 +86,27 @@ std::string ObjectProperties::dump() const
return os.str();
}
static auto tie(const ObjectProperties &o)
{
// Make sure to add new members to this list!
return std::tie(
o.textures, o.colors, o.collisionbox, o.selectionbox, o.visual, o.mesh,
o.damage_texture_modifier, o.nametag, o.infotext, o.wield_item, o.visual_size,
o.nametag_color, o.nametag_bgcolor, o.spritediv, o.initial_sprite_basepos,
o.stepheight, o.automatic_rotate, o.automatic_face_movement_dir_offset,
o.automatic_face_movement_max_rotation_per_sec, o.eye_height, o.zoom_fov,
o.hp_max, o.breath_max, o.glow, o.pointable, o.physical, o.collideWithObjects,
o.rotate_selectionbox, o.is_visible, o.makes_footstep_sound,
o.automatic_face_movement_dir, o.backface_culling, o.static_save, o.use_texture_alpha,
o.shaded, o.show_on_minimap
);
}
bool ObjectProperties::operator==(const ObjectProperties &other) const
{
return tie(*this) == tie(other);
}
bool ObjectProperties::validate()
{
const char *func = "ObjectProperties::validate(): ";

View File

@ -20,11 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include <optional>
#include <tuple>
#include <string>
#include "irrlichttypes_bloated.h"
#include <iostream>
#include <map>
#include <vector>
#include "util/pointabilities.h"
@ -77,28 +75,10 @@ struct ObjectProperties
std::string dump() const;
private:
auto tie() const {
// Make sure to add new members to this list!
return std::tie(
textures, colors, collisionbox, selectionbox, visual, mesh, damage_texture_modifier,
nametag, infotext, wield_item, visual_size, nametag_color, nametag_bgcolor,
spritediv, initial_sprite_basepos, stepheight, automatic_rotate,
automatic_face_movement_dir_offset, automatic_face_movement_max_rotation_per_sec,
eye_height, zoom_fov, hp_max, breath_max, glow, pointable, physical,
collideWithObjects, rotate_selectionbox, is_visible, makes_footstep_sound,
automatic_face_movement_dir, backface_culling, static_save, use_texture_alpha,
shaded, show_on_minimap
);
}
public:
bool operator==(const ObjectProperties &other) const {
return tie() == other.tie();
};
bool operator==(const ObjectProperties &other) const;
bool operator!=(const ObjectProperties &other) const {
return tie() != other.tie();
};
return !(*this == other);
}
/**
* Check limits of some important properties that'd cause exceptions later on.

View File

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "log.h"
#include "porting.h" // strlcpy
#include <tuple>
bool is_valid_player_name(std::string_view name) {
@ -229,3 +230,19 @@ void PlayerControl::unpackKeysPressed(u32 keypress_bits)
place = keypress_bits & (1 << 8);
zoom = keypress_bits & (1 << 9);
}
static auto tie(const PlayerPhysicsOverride &o)
{
// Make sure to add new members to this list!
return std::tie(
o.speed, o.jump, o.gravity, o.sneak, o.sneak_glitch, o.new_move, o.speed_climb,
o.speed_crouch, o.liquid_fluidity, o.liquid_fluidity_smooth, o.liquid_sink,
o.acceleration_default, o.acceleration_air, o.speed_fast, o.acceleration_fast,
o.speed_walk
);
}
bool PlayerPhysicsOverride::operator==(const PlayerPhysicsOverride &other) const
{
return tie(*this) == tie(other);
}

View File

@ -24,10 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h"
#include "util/basic_macros.h"
#include "util/string.h"
#include <list>
#include <mutex>
#include <functional>
#include <tuple>
#include <string>
#define PLAYERNAME_SIZE 20
@ -133,23 +131,10 @@ struct PlayerPhysicsOverride
float acceleration_fast = 1.f;
float speed_walk = 1.f;
private:
auto tie() const {
// Make sure to add new members to this list!
return std::tie(
speed, jump, gravity, sneak, sneak_glitch, new_move, speed_climb, speed_crouch,
liquid_fluidity, liquid_fluidity_smooth, liquid_sink, acceleration_default,
acceleration_air, speed_fast, acceleration_fast, speed_walk
);
}
public:
bool operator==(const PlayerPhysicsOverride &other) const {
return tie() == other.tie();
};
bool operator==(const PlayerPhysicsOverride &other) const;
bool operator!=(const PlayerPhysicsOverride &other) const {
return tie() != other.tie();
};
return !(*this == other);
}
};
class Map;