Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10118 from lioncash/messageid
NetPlayProto: Remove lots of casts to MessageId when inserting enum values into packets
  • Loading branch information
leoetlino committed Oct 13, 2021
2 parents 13b84c9 + 3840b55 commit f19da1c
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 310 deletions.
29 changes: 24 additions & 5 deletions Source/Core/Common/SFMLHelper.h
Expand Up @@ -3,18 +3,37 @@

#pragma once

#include <type_traits>

#include <SFML/Network/Packet.hpp>

#include "Common/CommonTypes.h"
#include "Common/Swap.h"

namespace sf
{
class Packet;
}

sf::Packet& operator>>(sf::Packet& packet, Common::BigEndianValue<u16>& data);
sf::Packet& operator>>(sf::Packet& packet, Common::BigEndianValue<u32>& data);
sf::Packet& operator>>(sf::Packet& packet, Common::BigEndianValue<u64>& data);

template <typename Enum, std::enable_if_t<std::is_enum_v<Enum>>* = nullptr>
sf::Packet& operator<<(sf::Packet& packet, Enum e)
{
using Underlying = std::underlying_type_t<Enum>;
packet << static_cast<Underlying>(e);
return packet;
}

template <typename Enum, std::enable_if_t<std::is_enum_v<Enum>>* = nullptr>
sf::Packet& operator>>(sf::Packet& packet, Enum& e)
{
using Underlying = std::underlying_type_t<Enum>;

Underlying value{};
packet >> value;

e = static_cast<Enum>(value);
return packet;
}

namespace Common
{
u64 PacketReadU64(sf::Packet& packet);
Expand Down

0 comments on commit f19da1c

Please sign in to comment.