From 718423e506da5e08384770ea06634f34c9e0657f Mon Sep 17 00:00:00 2001 From: B3n30 Date: Wed, 26 Jul 2017 21:06:40 +0200 Subject: Network: Moved NintendoOUI initalization to RoomMember constructor --- src/network/room.cpp | 5 +++-- src/network/room.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/network') diff --git a/src/network/room.cpp b/src/network/room.cpp index 8b7915bb7..fbbaf8b93 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp @@ -19,7 +19,7 @@ static constexpr u32 MaxConcurrentConnections = 10; class Room::RoomImpl { public: // This MAC address is used to generate a 'Nintendo' like Mac address. - const MacAddress NintendoOUI = {0x00, 0x1F, 0x32, 0x00, 0x00, 0x00}; + const MacAddress NintendoOUI; std::mt19937 random_gen; ///< Random number generator. Used for GenerateMacAddress ENetHost* server = nullptr; ///< Network interface. @@ -36,7 +36,8 @@ public: using MemberList = std::vector; MemberList members; ///< Information about the members of this room. - RoomImpl() : random_gen(std::random_device()()) {} + RoomImpl() + : random_gen(std::random_device()()), NintendoOUI{0x00, 0x1F, 0x32, 0x00, 0x00, 0x00} {} /// Thread that receives and dispatches network packets std::unique_ptr room_thread; diff --git a/src/network/room.h b/src/network/room.h index 54cccf0ae..65b0d008a 100644 --- a/src/network/room.h +++ b/src/network/room.h @@ -24,7 +24,7 @@ struct RoomInformation { using MacAddress = std::array; /// A special MAC address that tells the room we're joining to assign us a MAC address /// automatically. -const MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +constexpr MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // 802.11 broadcast MAC address constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; -- cgit v1.2.3 From 5d0a1e7efddf234234d54fe97395f6975f8d1a28 Mon Sep 17 00:00:00 2001 From: B3n30 Date: Sat, 19 Aug 2017 19:14:33 +0200 Subject: Added missing parts in libnetwork (#2838) * Network: Set and send the game information over enet Added Callbacks for RoomMember and GetMemberList to Room in preparation for web_services. --- src/core/CMakeLists.txt | 2 +- src/core/core.cpp | 5 ++ src/core/loader/ncch.cpp | 8 +++ src/network/packet.cpp | 38 +++++++++++++ src/network/packet.h | 4 ++ src/network/room.cpp | 84 +++++++++++++++++++++-------- src/network/room.h | 19 ++++++- src/network/room_member.cpp | 128 ++++++++++++++++++++++++++++++++++++++++---- src/network/room_member.h | 59 ++++++++++++++++++-- 9 files changed, 310 insertions(+), 37 deletions(-) (limited to 'src/network') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 360f407f3..0a6f97e4b 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -388,7 +388,7 @@ set(HEADERS create_directory_groups(${SRCS} ${HEADERS}) add_library(core STATIC ${SRCS} ${HEADERS}) -target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) +target_link_libraries(core PUBLIC common PRIVATE audio_core network video_core) target_link_libraries(core PUBLIC Boost::boost PRIVATE cryptopp dynarmic fmt) if (ENABLE_WEB_SERVICE) target_link_libraries(core PUBLIC json-headers web_service) diff --git a/src/core/core.cpp b/src/core/core.cpp index d08f18623..5332318cf 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -19,6 +19,7 @@ #include "core/loader/loader.h" #include "core/memory_setup.h" #include "core/settings.h" +#include "network/network.h" #include "video_core/video_core.h" namespace Core { @@ -188,6 +189,10 @@ void System::Shutdown() { cpu_core = nullptr; app_loader = nullptr; telemetry_session = nullptr; + if (auto room_member = Network::GetRoomMember().lock()) { + Network::GameInfo game_info{}; + room_member->SendGameInfo(game_info); + } LOG_DEBUG(Core, "Shutdown OK"); } diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index c007069a9..7aff7f29b 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -20,6 +20,7 @@ #include "core/loader/ncch.h" #include "core/loader/smdh.h" #include "core/memory.h" +#include "network/network.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // Loader namespace @@ -350,6 +351,13 @@ ResultStatus AppLoader_NCCH::Load() { Core::Telemetry().AddField(Telemetry::FieldType::Session, "ProgramId", program_id); + if (auto room_member = Network::GetRoomMember().lock()) { + Network::GameInfo game_info; + ReadTitle(game_info.name); + game_info.id = ncch_header.program_id; + room_member->SendGameInfo(game_info); + } + is_loaded = true; // Set state to loaded result = LoadExec(); // Load the executable into memory for booting diff --git a/src/network/packet.cpp b/src/network/packet.cpp index 660e92c0d..cc60f2fbc 100644 --- a/src/network/packet.cpp +++ b/src/network/packet.cpp @@ -13,6 +13,18 @@ namespace Network { +#ifndef htonll +u64 htonll(u64 x) { + return ((1 == htonl(1)) ? (x) : ((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32)); +} +#endif + +#ifndef ntohll +u64 ntohll(u64 x) { + return ((1 == ntohl(1)) ? (x) : ((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32)); +} +#endif + void Packet::Append(const void* in_data, std::size_t size_in_bytes) { if (in_data && (size_in_bytes > 0)) { std::size_t start = data.size(); @@ -100,6 +112,20 @@ Packet& Packet::operator>>(u32& out_data) { return *this; } +Packet& Packet::operator>>(s64& out_data) { + s64 value; + Read(&value, sizeof(value)); + out_data = ntohll(value); + return *this; +} + +Packet& Packet::operator>>(u64& out_data) { + u64 value; + Read(&value, sizeof(value)); + out_data = ntohll(value); + return *this; +} + Packet& Packet::operator>>(float& out_data) { Read(&out_data, sizeof(out_data)); return *this; @@ -183,6 +209,18 @@ Packet& Packet::operator<<(u32 in_data) { return *this; } +Packet& Packet::operator<<(s64 in_data) { + s64 toWrite = htonll(in_data); + Append(&toWrite, sizeof(toWrite)); + return *this; +} + +Packet& Packet::operator<<(u64 in_data) { + u64 toWrite = htonll(in_data); + Append(&toWrite, sizeof(toWrite)); + return *this; +} + Packet& Packet::operator<<(float in_data) { Append(&in_data, sizeof(in_data)); return *this; diff --git a/src/network/packet.h b/src/network/packet.h index 94b351ab1..5a2e58dc2 100644 --- a/src/network/packet.h +++ b/src/network/packet.h @@ -72,6 +72,8 @@ public: Packet& operator>>(u16& out_data); Packet& operator>>(s32& out_data); Packet& operator>>(u32& out_data); + Packet& operator>>(s64& out_data); + Packet& operator>>(u64& out_data); Packet& operator>>(float& out_data); Packet& operator>>(double& out_data); Packet& operator>>(char* out_data); @@ -89,6 +91,8 @@ public: Packet& operator<<(u16 in_data); Packet& operator<<(s32 in_data); Packet& operator<<(u32 in_data); + Packet& operator<<(s64 in_data); + Packet& operator<<(u64 in_data); Packet& operator<<(float in_data); Packet& operator<<(double in_data); Packet& operator<<(const char* in_data); diff --git a/src/network/room.cpp b/src/network/room.cpp index fbbaf8b93..261049ab0 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp @@ -4,9 +4,9 @@ #include #include +#include #include #include -#include #include "enet/enet.h" #include "network/packet.h" #include "network/room.h" @@ -29,12 +29,14 @@ public: struct Member { std::string nickname; ///< The nickname of the member. - std::string game_name; ///< The current game of the member + GameInfo game_info; ///< The current game of the member MacAddress mac_address; ///< The assigned mac address of the member. ENetPeer* peer; ///< The remote peer. }; using MemberList = std::vector; - MemberList members; ///< Information about the members of this room. + MemberList members; ///< Information about the members of this room + mutable std::mutex member_mutex; ///< Mutex for locking the members list + /// This should be a std::shared_mutex as soon as C++17 is supported RoomImpl() : random_gen(std::random_device()()), NintendoOUI{0x00, 0x1F, 0x32, 0x00, 0x00, 0x00} {} @@ -147,7 +149,7 @@ void Room::RoomImpl::ServerLoop() { case IdJoinRequest: HandleJoinRequest(&event); break; - case IdSetGameName: + case IdSetGameInfo: HandleGameNamePacket(&event); break; case IdWifiPacket: @@ -213,7 +215,10 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) { member.nickname = nickname; member.peer = event->peer; - members.push_back(std::move(member)); + { + std::lock_guard lock(member_mutex); + members.push_back(std::move(member)); + } // Notify everyone that the room information has changed. BroadcastRoomInformation(); @@ -223,12 +228,14 @@ void Room::RoomImpl::HandleJoinRequest(const ENetEvent* event) { bool Room::RoomImpl::IsValidNickname(const std::string& nickname) const { // A nickname is valid if it is not already taken by anybody else in the room. // TODO(B3N30): Check for empty names, spaces, etc. + std::lock_guard lock(member_mutex); return std::all_of(members.begin(), members.end(), [&nickname](const auto& member) { return member.nickname != nickname; }); } bool Room::RoomImpl::IsValidMacAddress(const MacAddress& address) const { // A MAC address is valid if it is not already taken by anybody else in the room. + std::lock_guard lock(member_mutex); return std::all_of(members.begin(), members.end(), [&address](const auto& member) { return member.mac_address != address; }); } @@ -279,6 +286,7 @@ void Room::RoomImpl::SendCloseMessage() { packet << static_cast(IdCloseRoom); ENetPacket* enet_packet = enet_packet_create(packet.GetData(), packet.GetDataSize(), ENET_PACKET_FLAG_RELIABLE); + std::lock_guard lock(member_mutex); for (auto& member : members) { enet_peer_send(member.peer, 0, enet_packet); } @@ -295,10 +303,14 @@ void Room::RoomImpl::BroadcastRoomInformation() { packet << room_information.member_slots; packet << static_cast(members.size()); - for (const auto& member : members) { - packet << member.nickname; - packet << member.mac_address; - packet << member.game_name; + { + std::lock_guard lock(member_mutex); + for (const auto& member : members) { + packet << member.nickname; + packet << member.mac_address; + packet << member.game_info.name; + packet << member.game_info.id; + } } ENetPacket* enet_packet = @@ -335,11 +347,13 @@ void Room::RoomImpl::HandleWifiPacket(const ENetEvent* event) { ENET_PACKET_FLAG_RELIABLE); if (destination_address == BroadcastMac) { // Send the data to everyone except the sender + std::lock_guard lock(member_mutex); for (const auto& member : members) { if (member.peer != event->peer) enet_peer_send(member.peer, 0, enet_packet); } } else { // Send the data only to the destination client + std::lock_guard lock(member_mutex); auto member = std::find_if(members.begin(), members.end(), [destination_address](const Member& member) -> bool { return member.mac_address == destination_address; @@ -361,6 +375,8 @@ void Room::RoomImpl::HandleChatPacket(const ENetEvent* event) { auto CompareNetworkAddress = [event](const Member member) -> bool { return member.peer == event->peer; }; + + std::lock_guard lock(member_mutex); const auto sending_member = std::find_if(members.begin(), members.end(), CompareNetworkAddress); if (sending_member == members.end()) { return; // Received a chat message from a unknown sender @@ -385,22 +401,32 @@ void Room::RoomImpl::HandleGameNamePacket(const ENetEvent* event) { in_packet.Append(event->packet->data, event->packet->dataLength); in_packet.IgnoreBytes(sizeof(u8)); // Igonore the message type - std::string game_name; - in_packet >> game_name; - auto member = - std::find_if(members.begin(), members.end(), - [event](const Member& member) -> bool { return member.peer == event->peer; }); - if (member != members.end()) { - member->game_name = game_name; - BroadcastRoomInformation(); + GameInfo game_info; + in_packet >> game_info.name; + in_packet >> game_info.id; + + { + std::lock_guard lock(member_mutex); + auto member = + std::find_if(members.begin(), members.end(), [event](const Member& member) -> bool { + return member.peer == event->peer; + }); + if (member != members.end()) { + member->game_info = game_info; + } } + BroadcastRoomInformation(); } void Room::RoomImpl::HandleClientDisconnection(ENetPeer* client) { // Remove the client from the members list. - members.erase(std::remove_if(members.begin(), members.end(), - [client](const Member& member) { return member.peer == client; }), - members.end()); + { + std::lock_guard lock(member_mutex); + members.erase( + std::remove_if(members.begin(), members.end(), + [client](const Member& member) { return member.peer == client; }), + members.end()); + } // Announce the change to all clients. enet_peer_disconnect(client, 0); @@ -437,6 +463,19 @@ const RoomInformation& Room::GetRoomInformation() const { return room_impl->room_information; } +std::vector Room::GetRoomMemberList() const { + std::vector member_list; + std::lock_guard lock(room_impl->member_mutex); + for (const auto& member_impl : room_impl->members) { + Member member; + member.nickname = member_impl.nickname; + member.mac_address = member_impl.mac_address; + member.game_info = member_impl.game_info; + member_list.push_back(member); + } + return member_list; +}; + void Room::Destroy() { room_impl->state = State::Closed; room_impl->room_thread->join(); @@ -447,7 +486,10 @@ void Room::Destroy() { } room_impl->room_information = {}; room_impl->server = nullptr; - room_impl->members.clear(); + { + std::lock_guard lock(room_impl->member_mutex); + room_impl->members.clear(); + } room_impl->room_information.member_slots = 0; room_impl->room_information.name.clear(); } diff --git a/src/network/room.h b/src/network/room.h index 65b0d008a..8285a4d0c 100644 --- a/src/network/room.h +++ b/src/network/room.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "common/common_types.h" namespace Network { @@ -21,6 +22,11 @@ struct RoomInformation { u32 member_slots; ///< Maximum number of members in this room }; +struct GameInfo { + std::string name{""}; + u64 id{0}; +}; + using MacAddress = std::array; /// A special MAC address that tells the room we're joining to assign us a MAC address /// automatically. @@ -34,7 +40,7 @@ enum RoomMessageTypes : u8 { IdJoinRequest = 1, IdJoinSuccess, IdRoomInformation, - IdSetGameName, + IdSetGameInfo, IdWifiPacket, IdChatMessage, IdNameCollision, @@ -51,6 +57,12 @@ public: Closed, ///< The room is not opened and can not accept connections. }; + struct Member { + std::string nickname; ///< The nickname of the member. + GameInfo game_info; ///< The current game of the member + MacAddress mac_address; ///< The assigned mac address of the member. + }; + Room(); ~Room(); @@ -64,6 +76,11 @@ public: */ const RoomInformation& GetRoomInformation() const; + /** + * Gets a list of the mbmers connected to the room. + */ + std::vector GetRoomMemberList() const; + /** * Creates the socket for this room. Will bind to default address if * server is empty string. diff --git a/src/network/room_member.cpp b/src/network/room_member.cpp index dac9bacae..f229ec6fd 100644 --- a/src/network/room_member.cpp +++ b/src/network/room_member.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "common/assert.h" #include "enet/enet.h" @@ -25,6 +26,9 @@ public: /// Information about the room we're connected to. RoomInformation room_information; + /// The current game name, id and version + GameInfo current_game_info; + std::atomic state{State::Idle}; ///< Current state of the RoomMember. void SetState(const State new_state); bool IsConnected() const; @@ -37,6 +41,24 @@ public: std::unique_ptr loop_thread; std::mutex send_list_mutex; ///< Mutex that controls access to the `send_list` variable. std::list send_list; ///< A list that stores all packets to send the async + + template + using CallbackSet = std::set>; + std::mutex callback_mutex; ///< The mutex used for handling callbacks + + class Callbacks { + public: + template + CallbackSet& Get(); + + private: + CallbackSet callback_set_wifi_packet; + CallbackSet callback_set_chat_messages; + CallbackSet callback_set_room_information; + CallbackSet callback_set_state; + }; + Callbacks callbacks; ///< All CallbackSets to all events + void MemberLoop(); void StartLoop(); @@ -84,12 +106,20 @@ public: * Disconnects the RoomMember from the Room */ void Disconnect(); + + template + void Invoke(const T& data); + + template + CallbackHandle Bind(std::function callback); }; // RoomMemberImpl void RoomMember::RoomMemberImpl::SetState(const State new_state) { - state = new_state; - // TODO(B3N30): Invoke the callback functions + if (state != new_state) { + state = new_state; + Invoke(state); + } } bool RoomMember::RoomMemberImpl::IsConnected() const { @@ -195,9 +225,10 @@ void RoomMember::RoomMemberImpl::HandleRoomInformationPacket(const ENetEvent* ev for (auto& member : member_information) { packet >> member.nickname; packet >> member.mac_address; - packet >> member.game_name; + packet >> member.game_info.name; + packet >> member.game_info.id; } - // TODO(B3N30): Invoke callbacks + Invoke(room_information); } void RoomMember::RoomMemberImpl::HandleJoinPacket(const ENetEvent* event) { @@ -209,7 +240,7 @@ void RoomMember::RoomMemberImpl::HandleJoinPacket(const ENetEvent* event) { // Parse the MAC Address from the packet packet >> mac_address; - // TODO(B3N30): Invoke callbacks + SetState(State::Joined); } void RoomMember::RoomMemberImpl::HandleWifiPackets(const ENetEvent* event) { @@ -235,7 +266,7 @@ void RoomMember::RoomMemberImpl::HandleWifiPackets(const ENetEvent* event) { packet >> wifi_packet.data; - // TODO(B3N30): Invoke callbacks + Invoke(wifi_packet); } void RoomMember::RoomMemberImpl::HandleChatPacket(const ENetEvent* event) { @@ -248,7 +279,7 @@ void RoomMember::RoomMemberImpl::HandleChatPacket(const ENetEvent* event) { ChatEntry chat_entry{}; packet >> chat_entry.nickname; packet >> chat_entry.message; - // TODO(B3N30): Invoke callbacks + Invoke(chat_entry); } void RoomMember::RoomMemberImpl::Disconnect() { @@ -276,6 +307,46 @@ void RoomMember::RoomMemberImpl::Disconnect() { server = nullptr; } +template <> +RoomMember::RoomMemberImpl::CallbackSet& RoomMember::RoomMemberImpl::Callbacks::Get() { + return callback_set_wifi_packet; +} + +template <> +RoomMember::RoomMemberImpl::CallbackSet& +RoomMember::RoomMemberImpl::Callbacks::Get() { + return callback_set_state; +} + +template <> +RoomMember::RoomMemberImpl::CallbackSet& +RoomMember::RoomMemberImpl::Callbacks::Get() { + return callback_set_room_information; +} + +template <> +RoomMember::RoomMemberImpl::CallbackSet& RoomMember::RoomMemberImpl::Callbacks::Get() { + return callback_set_chat_messages; +} + +template +void RoomMember::RoomMemberImpl::Invoke(const T& data) { + std::lock_guard lock(callback_mutex); + CallbackSet callback_set = callbacks.Get(); + for (auto const& callback : callback_set) + (*callback)(data); +} + +template +RoomMember::CallbackHandle RoomMember::RoomMemberImpl::Bind( + std::function callback) { + std::lock_guard lock(callback_mutex); + CallbackHandle handle; + handle = std::make_shared>(callback); + callbacks.Get().insert(handle); + return handle; +} + // RoomMember RoomMember::RoomMember() : room_member_impl{std::make_unique()} { room_member_impl->client = enet_host_create(nullptr, 1, NumChannels, 0, 0); @@ -339,6 +410,7 @@ void RoomMember::Join(const std::string& nick, const char* server_addr, u16 serv room_member_impl->SetState(State::Joining); room_member_impl->StartLoop(); room_member_impl->SendJoinRequest(nick, preferred_mac); + SendGameInfo(room_member_impl->current_game_info); } else { room_member_impl->SetState(State::CouldNotConnect); } @@ -366,17 +438,53 @@ void RoomMember::SendChatMessage(const std::string& message) { room_member_impl->Send(std::move(packet)); } -void RoomMember::SendGameName(const std::string& game_name) { +void RoomMember::SendGameInfo(const GameInfo& game_info) { + room_member_impl->current_game_info = game_info; + if (!IsConnected()) + return; + Packet packet; - packet << static_cast(IdSetGameName); - packet << game_name; + packet << static_cast(IdSetGameInfo); + packet << game_info.name; + packet << game_info.id; room_member_impl->Send(std::move(packet)); } +RoomMember::CallbackHandle RoomMember::BindOnStateChanged( + std::function callback) { + return room_member_impl->Bind(callback); +} + +RoomMember::CallbackHandle RoomMember::BindOnWifiPacketReceived( + std::function callback) { + return room_member_impl->Bind(callback); +} + +RoomMember::CallbackHandle RoomMember::BindOnRoomInformationChanged( + std::function callback) { + return room_member_impl->Bind(callback); +} + +RoomMember::CallbackHandle RoomMember::BindOnChatMessageRecieved( + std::function callback) { + return room_member_impl->Bind(callback); +} + +template +void RoomMember::Unbind(CallbackHandle handle) { + std::lock_guard lock(room_member_impl->callback_mutex); + room_member_impl->callbacks.Get().erase(handle); +} + void RoomMember::Leave() { room_member_impl->SetState(State::Idle); room_member_impl->loop_thread->join(); room_member_impl->loop_thread.reset(); } +template void RoomMember::Unbind(CallbackHandle); +template void RoomMember::Unbind(CallbackHandle); +template void RoomMember::Unbind(CallbackHandle); +template void RoomMember::Unbind(CallbackHandle); + } // namespace Network diff --git a/src/network/room_member.h b/src/network/room_member.h index bc1af3a7e..98770a234 100644 --- a/src/network/room_member.h +++ b/src/network/room_member.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -53,12 +54,23 @@ public: struct MemberInformation { std::string nickname; ///< Nickname of the member. - std::string game_name; ///< Name of the game they're currently playing, or empty if they're + GameInfo game_info; ///< Name of the game they're currently playing, or empty if they're /// not playing anything. MacAddress mac_address; ///< MAC address associated with this member. }; using MemberList = std::vector; + // The handle for the callback functions + template + using CallbackHandle = std::shared_ptr>; + + /** + * Unbinds a callback function from the events. + * @param handle The connection handle to disconnect + */ + template + void Unbind(CallbackHandle handle); + RoomMember(); ~RoomMember(); @@ -113,10 +125,49 @@ public: void SendChatMessage(const std::string& message); /** - * Sends the current game name to the room. - * @param game_name The game name. + * Sends the current game info to the room. + * @param game_info The game information. + */ + void SendGameInfo(const GameInfo& game_info); + + /** + * Binds a function to an event that will be triggered every time the State of the member + * changed. The function wil be called every time the event is triggered. The callback function + * must not bind or unbind a function. Doing so will cause a deadlock + * @param callback The function to call + * @return A handle used for removing the function from the registered list + */ + CallbackHandle BindOnStateChanged(std::function callback); + + /** + * Binds a function to an event that will be triggered every time a WifiPacket is received. + * The function wil be called everytime the event is triggered. + * The callback function must not bind or unbind a function. Doing so will cause a deadlock + * @param callback The function to call + * @return A handle used for removing the function from the registered list + */ + CallbackHandle BindOnWifiPacketReceived( + std::function callback); + + /** + * Binds a function to an event that will be triggered every time the RoomInformation changes. + * The function wil be called every time the event is triggered. + * The callback function must not bind or unbind a function. Doing so will cause a deadlock + * @param callback The function to call + * @return A handle used for removing the function from the registered list + */ + CallbackHandle BindOnRoomInformationChanged( + std::function callback); + + /** + * Binds a function to an event that will be triggered every time a ChatMessage is received. + * The function wil be called every time the event is triggered. + * The callback function must not bind or unbind a function. Doing so will cause a deadlock + * @param callback The function to call + * @return A handle used for removing the function from the registered list */ - void SendGameName(const std::string& game_name); + CallbackHandle BindOnChatMessageRecieved( + std::function callback); /** * Leaves the current room. -- cgit v1.2.3 From a13ab958cbba75bc9abd1ca50f3030a10a75784e Mon Sep 17 00:00:00 2001 From: Huw Pascoe Date: Wed, 27 Sep 2017 00:26:09 +0100 Subject: Fixed type conversion ambiguity --- src/audio_core/hle/source.cpp | 2 +- .../debugger/graphics/graphics_cmdlists.cpp | 4 +-- .../debugger/graphics/graphics_surface.cpp | 3 +- src/common/string_util.cpp | 2 +- src/common/string_util.h | 2 +- src/common/vector_math.h | 12 ++------ src/core/gdbstub/gdbstub.cpp | 4 +-- src/core/hle/ipc.h | 8 ++--- src/core/hle/ipc_helpers.h | 12 ++++---- src/core/hle/kernel/hle_ipc.cpp | 2 +- src/core/hle/kernel/mutex.cpp | 2 +- src/core/hle/kernel/resource_limit.cpp | 2 +- src/core/hle/kernel/resource_limit.h | 2 +- src/core/hle/kernel/shared_memory.cpp | 3 +- src/core/hle/kernel/shared_memory.h | 2 +- src/core/hle/kernel/thread.cpp | 18 +++++------ src/core/hle/kernel/thread.h | 14 ++++----- src/core/hle/kernel/wait_object.cpp | 2 +- src/core/hle/service/apt/apt.cpp | 4 +-- src/core/hle/service/cam/cam.cpp | 2 +- src/core/hle/service/cfg/cfg.cpp | 2 +- src/core/hle/service/fs/archive.cpp | 2 +- src/core/hle/service/hid/hid.cpp | 2 +- src/core/hle/service/ldr_ro/cro_helper.h | 6 ++-- src/core/hle/service/nwm/nwm_uds.cpp | 10 +++--- src/core/hle/service/nwm/uds_beacon.cpp | 4 +-- src/core/hle/service/nwm/uds_data.cpp | 8 ++--- src/core/hle/svc.cpp | 8 ++--- src/core/memory.cpp | 36 +++++++++++++--------- src/network/packet.cpp | 2 +- src/video_core/geometry_pipeline.cpp | 2 +- src/video_core/renderer_opengl/gl_state.cpp | 4 +-- 32 files changed, 97 insertions(+), 91 deletions(-) (limited to 'src/network') diff --git a/src/audio_core/hle/source.cpp b/src/audio_core/hle/source.cpp index de4e88cae..c12287700 100644 --- a/src/audio_core/hle/source.cpp +++ b/src/audio_core/hle/source.cpp @@ -264,7 +264,7 @@ void Source::GenerateFrame() { break; } } - state.next_sample_number += frame_position; + state.next_sample_number += static_cast(frame_position); state.filters.ProcessFrame(current_frame); } diff --git a/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp index 7d06ec28a..ce2b9fa50 100644 --- a/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp @@ -26,8 +26,8 @@ namespace { QImage LoadTexture(const u8* src, const Pica::Texture::TextureInfo& info) { QImage decoded_image(info.width, info.height, QImage::Format_ARGB32); - for (int y = 0; y < info.height; ++y) { - for (int x = 0; x < info.width; ++x) { + for (u32 y = 0; y < info.height; ++y) { + for (u32 x = 0; x < info.width; ++x) { Math::Vec4 color = Pica::Texture::LookupTexture(src, x, y, info, true); decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); } diff --git a/src/citra_qt/debugger/graphics/graphics_surface.cpp b/src/citra_qt/debugger/graphics/graphics_surface.cpp index 47d9924e1..c974545ef 100644 --- a/src/citra_qt/debugger/graphics/graphics_surface.cpp +++ b/src/citra_qt/debugger/graphics/graphics_surface.cpp @@ -273,7 +273,8 @@ void GraphicsSurfaceWidget::Pick(int x, int y) { surface_picker_x_control->setValue(x); surface_picker_y_control->setValue(y); - if (x < 0 || x >= surface_width || y < 0 || y >= surface_height) { + if (x < 0 || x >= static_cast(surface_width) || y < 0 || + y >= static_cast(surface_height)) { surface_info_label->setText(tr("Pixel out of bounds")); surface_info_label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); return; diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index bad311793..6959915fa 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -117,7 +117,7 @@ std::string StringFromFormat(const char* format, ...) { } // For Debugging. Read out an u8 array. -std::string ArrayToString(const u8* data, u32 size, int line_len, bool spaces) { +std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { std::ostringstream oss; oss << std::setfill('0') << std::hex; diff --git a/src/common/string_util.h b/src/common/string_util.h index 075bf4ecb..259360aec 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -33,7 +33,7 @@ inline void CharArrayFromFormat(char (&out)[Count], const char* format, ...) { } // Good -std::string ArrayToString(const u8* data, u32 size, int line_len = 20, bool spaces = true); +std::string ArrayToString(const u8* data, size_t size, int line_len = 20, bool spaces = true); std::string StripSpaces(const std::string& s); std::string StripQuotes(const std::string& s); diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 2b05f66ee..3f0057d9e 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -104,8 +104,7 @@ public: } template void operator*=(const V& f) { - x *= f; - y *= f; + *this = *this * f; } template Vec2 operator/(const V& f) const { @@ -262,9 +261,7 @@ public: } template void operator*=(const V& f) { - x *= f; - y *= f; - z *= f; + *this = *this * f; } template Vec3 operator/(const V& f) const { @@ -478,10 +475,7 @@ public: } template void operator*=(const V& f) { - x *= f; - y *= f; - z *= f; - w *= f; + *this = *this * f; } template Vec4 operator/(const V& f) const { diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 123fe7cd4..be2b2e25f 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -946,7 +946,7 @@ static void Init(u16 port) { WSAStartup(MAKEWORD(2, 2), &InitData); #endif - int tmpsock = socket(PF_INET, SOCK_STREAM, 0); + int tmpsock = static_cast(socket(PF_INET, SOCK_STREAM, 0)); if (tmpsock == -1) { LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket"); } @@ -973,7 +973,7 @@ static void Init(u16 port) { sockaddr_in saddr_client; sockaddr* client_addr = reinterpret_cast(&saddr_client); socklen_t client_addrlen = sizeof(saddr_client); - gdbserver_socket = accept(tmpsock, client_addr, &client_addrlen); + gdbserver_socket = static_cast(accept(tmpsock, client_addr, &client_addrlen)); if (gdbserver_socket < 0) { // In the case that we couldn't start the server for whatever reason, just start CPU // execution like normal. diff --git a/src/core/hle/ipc.h b/src/core/hle/ipc.h index f7f96125a..87ed85df6 100644 --- a/src/core/hle/ipc.h +++ b/src/core/hle/ipc.h @@ -122,11 +122,11 @@ union StaticBufferDescInfo { BitField<14, 18, u32> size; }; -inline u32 StaticBufferDesc(u32 size, u8 buffer_id) { +inline u32 StaticBufferDesc(size_t size, u8 buffer_id) { StaticBufferDescInfo info{}; info.descriptor_type.Assign(StaticBuffer); info.buffer_id.Assign(buffer_id); - info.size.Assign(size); + info.size.Assign(static_cast(size)); return info.raw; } @@ -160,11 +160,11 @@ union MappedBufferDescInfo { BitField<4, 28, u32> size; }; -inline u32 MappedBufferDesc(u32 size, MappedBufferPermissions perms) { +inline u32 MappedBufferDesc(size_t size, MappedBufferPermissions perms) { MappedBufferDescInfo info{}; info.flags.Assign(MappedBuffer); info.perms.Assign(perms); - info.size.Assign(size); + info.size.Assign(static_cast(size)); return info.raw; } diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index f0d89cffe..7cb95cbac 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -117,9 +117,9 @@ public: void PushCurrentPIDHandle(); - void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id); + void PushStaticBuffer(VAddr buffer_vaddr, size_t size, u8 buffer_id); - void PushMappedBuffer(VAddr buffer_vaddr, u32 size, MappedBufferPermissions perms); + void PushMappedBuffer(VAddr buffer_vaddr, size_t size, MappedBufferPermissions perms); }; /// Push /// @@ -190,12 +190,12 @@ inline void RequestBuilder::PushCurrentPIDHandle() { Push(u32(0)); } -inline void RequestBuilder::PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { +inline void RequestBuilder::PushStaticBuffer(VAddr buffer_vaddr, size_t size, u8 buffer_id) { Push(StaticBufferDesc(size, buffer_id)); Push(buffer_vaddr); } -inline void RequestBuilder::PushMappedBuffer(VAddr buffer_vaddr, u32 size, +inline void RequestBuilder::PushMappedBuffer(VAddr buffer_vaddr, size_t size, MappedBufferPermissions perms) { Push(MappedBufferDesc(size, perms)); Push(buffer_vaddr); @@ -227,8 +227,8 @@ public: bool validateHeader = true) { if (validateHeader) ValidateHeader(); - Header builderHeader{ - MakeHeader(header.command_id, normal_params_size, translate_params_size)}; + Header builderHeader{MakeHeader(static_cast(header.command_id), normal_params_size, + translate_params_size)}; if (context != nullptr) return {*context, builderHeader}; else diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 5ebe2eca4..6020e9764 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -37,7 +37,7 @@ SharedPtr HLERequestContext::GetIncomingHandle(u32 id_from_cmdbuf) const u32 HLERequestContext::AddOutgoingHandle(SharedPtr object) { request_handles.push_back(std::move(object)); - return request_handles.size() - 1; + return static_cast(request_handles.size() - 1); } void HLERequestContext::ClearIncomingObjects() { diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index cef961289..2cbca5e5b 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp @@ -90,7 +90,7 @@ void Mutex::UpdatePriority() { if (!holding_thread) return; - s32 best_priority = THREADPRIO_LOWEST; + u32 best_priority = THREADPRIO_LOWEST; for (auto& waiter : GetWaitingThreads()) { if (waiter->current_priority < best_priority) best_priority = waiter->current_priority; diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp index a8f10a3ee..517dc47a8 100644 --- a/src/core/hle/kernel/resource_limit.cpp +++ b/src/core/hle/kernel/resource_limit.cpp @@ -61,7 +61,7 @@ s32 ResourceLimit::GetCurrentResourceValue(u32 resource) const { } } -s32 ResourceLimit::GetMaxResourceValue(u32 resource) const { +u32 ResourceLimit::GetMaxResourceValue(u32 resource) const { switch (resource) { case PRIORITY: return max_priority; diff --git a/src/core/hle/kernel/resource_limit.h b/src/core/hle/kernel/resource_limit.h index 6cdfbcf8d..42874eb8d 100644 --- a/src/core/hle/kernel/resource_limit.h +++ b/src/core/hle/kernel/resource_limit.h @@ -67,7 +67,7 @@ public: * @param resource Requested resource type * @returns The max value of the resource type */ - s32 GetMaxResourceValue(u32 resource) const; + u32 GetMaxResourceValue(u32 resource) const; /// Name of resource limit object. std::string name; diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index a7b66142f..02d5a7a36 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -42,7 +42,8 @@ SharedPtr SharedMemory::Create(SharedPtr owner_process, u memory_region->used += size; shared_memory->linear_heap_phys_address = - Memory::FCRAM_PADDR + memory_region->base + shared_memory->backing_block_offset; + Memory::FCRAM_PADDR + memory_region->base + + static_cast(shared_memory->backing_block_offset); // Increase the amount of used linear heap memory for the owner process. if (shared_memory->owner_process != nullptr) { diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h index 94b335ed1..93a6f2182 100644 --- a/src/core/hle/kernel/shared_memory.h +++ b/src/core/hle/kernel/shared_memory.h @@ -114,7 +114,7 @@ public: /// Backing memory for this shared memory block. std::shared_ptr> backing_block; /// Offset into the backing block for this shared memory. - u32 backing_block_offset; + size_t backing_block_offset; /// Size of the memory block. Page-aligned. u32 size; /// Permission restrictions applied to the process which created the block. diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 1033f8552..11f7d2127 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -111,7 +111,7 @@ void Thread::Stop() { Thread* ArbitrateHighestPriorityThread(u32 address) { Thread* highest_priority_thread = nullptr; - s32 priority = THREADPRIO_LOWEST; + u32 priority = THREADPRIO_LOWEST; // Iterate through threads, find highest priority thread that is waiting to be arbitrated... for (auto& thread : thread_list) { @@ -311,7 +311,7 @@ static void DebugThreadQueue() { } for (auto& t : thread_list) { - s32 priority = ready_queue.contains(t.get()); + u32 priority = ready_queue.contains(t.get()); if (priority != -1) { LOG_DEBUG(Kernel, "0x%02X %u", priority, t->GetObjectId()); } @@ -422,7 +422,7 @@ ResultVal> Thread::Create(std::string name, VAddr entry_point, return ERR_OUT_OF_MEMORY; } - u32 offset = linheap_memory->size(); + size_t offset = linheap_memory->size(); // Allocate some memory from the end of the linear heap for this region. linheap_memory->insert(linheap_memory->end(), Memory::PAGE_SIZE, 0); @@ -430,7 +430,7 @@ ResultVal> Thread::Create(std::string name, VAddr entry_point, owner_process->linear_heap_used += Memory::PAGE_SIZE; tls_slots.emplace_back(0); // The page is completely available at the start - available_page = tls_slots.size() - 1; + available_page = static_cast(tls_slots.size() - 1); available_slot = 0; // Use the first slot in the new page auto& vm_manager = owner_process->vm_manager; @@ -457,7 +457,7 @@ ResultVal> Thread::Create(std::string name, VAddr entry_point, return MakeResult>(std::move(thread)); } -void Thread::SetPriority(s32 priority) { +void Thread::SetPriority(u32 priority) { ASSERT_MSG(priority <= THREADPRIO_LOWEST && priority >= THREADPRIO_HIGHEST, "Invalid priority value."); // If thread was ready, adjust queues @@ -470,7 +470,7 @@ void Thread::SetPriority(s32 priority) { } void Thread::UpdatePriority() { - s32 best_priority = nominal_priority; + u32 best_priority = nominal_priority; for (auto& mutex : held_mutexes) { if (mutex->priority < best_priority) best_priority = mutex->priority; @@ -478,7 +478,7 @@ void Thread::UpdatePriority() { BoostPriority(best_priority); } -void Thread::BoostPriority(s32 priority) { +void Thread::BoostPriority(u32 priority) { // If thread was ready, adjust queues if (status == THREADSTATUS_READY) ready_queue.move(this, current_priority, priority); @@ -487,7 +487,7 @@ void Thread::BoostPriority(s32 priority) { current_priority = priority; } -SharedPtr SetupMainThread(u32 entry_point, s32 priority, SharedPtr owner_process) { +SharedPtr SetupMainThread(u32 entry_point, u32 priority, SharedPtr owner_process) { // Initialize new "main" thread auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0, Memory::HEAP_VADDR_END, owner_process); @@ -531,7 +531,7 @@ void Thread::SetWaitSynchronizationOutput(s32 output) { s32 Thread::GetWaitObjectIndex(WaitObject* object) const { ASSERT_MSG(!wait_objects.empty(), "Thread is not waiting for anything"); auto match = std::find(wait_objects.rbegin(), wait_objects.rend(), object); - return std::distance(match, wait_objects.rend()) - 1; + return static_cast(std::distance(match, wait_objects.rend()) - 1); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index ddc0d15c5..f02e1d43a 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -15,7 +15,7 @@ #include "core/hle/kernel/wait_object.h" #include "core/hle/result.h" -enum ThreadPriority : s32 { +enum ThreadPriority : u32 { THREADPRIO_HIGHEST = 0, ///< Highest thread priority THREADPRIO_USERLAND_MAX = 24, ///< Highest thread priority for userland apps THREADPRIO_DEFAULT = 48, ///< Default thread priority for userland apps @@ -82,7 +82,7 @@ public: * Gets the thread's current priority * @return The current thread's priority */ - s32 GetPriority() const { + u32 GetPriority() const { return current_priority; } @@ -90,7 +90,7 @@ public: * Sets the thread's current priority * @param priority The new priority */ - void SetPriority(s32 priority); + void SetPriority(u32 priority); /** * Boost's a thread's priority to the best priority among the thread's held mutexes. @@ -102,7 +102,7 @@ public: * Temporarily boosts the thread's priority until the next time it is scheduled * @param priority The new priority */ - void BoostPriority(s32 priority); + void BoostPriority(u32 priority); /** * Gets the thread's thread ID @@ -176,8 +176,8 @@ public: u32 entry_point; u32 stack_top; - s32 nominal_priority; ///< Nominal thread priority, as set by the emulated application - s32 current_priority; ///< Current thread priority, can be temporarily changed + u32 nominal_priority; ///< Nominal thread priority, as set by the emulated application + u32 current_priority; ///< Current thread priority, can be temporarily changed u64 last_running_ticks; ///< CPU tick when thread was last running @@ -219,7 +219,7 @@ private: * @param owner_process The parent process for the main thread * @return A shared pointer to the main thread */ -SharedPtr SetupMainThread(u32 entry_point, s32 priority, SharedPtr owner_process); +SharedPtr SetupMainThread(u32 entry_point, u32 priority, SharedPtr owner_process); /** * Returns whether there are any threads that are ready to run. diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index f245eda6c..56fdd977f 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp @@ -34,7 +34,7 @@ void WaitObject::RemoveWaitingThread(Thread* thread) { SharedPtr WaitObject::GetHighestPriorityReadyThread() { Thread* candidate = nullptr; - s32 candidate_priority = THREADPRIO_LOWEST + 1; + u32 candidate_priority = THREADPRIO_LOWEST + 1; for (const auto& thread : waiting_threads) { // The list of waiting threads must not contain threads that are not waiting to be awakened. diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 8c0ba73f2..4c6156345 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -561,7 +561,7 @@ void ReceiveParameter(Service::Interface* self) { ? Kernel::g_handle_table.Create(next_parameter->object).Unwrap() : 0); - rb.PushStaticBuffer(buffer, static_cast(next_parameter->buffer.size()), 0); + rb.PushStaticBuffer(buffer, next_parameter->buffer.size(), 0); Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); @@ -609,7 +609,7 @@ void GlanceParameter(Service::Interface* self) { ? Kernel::g_handle_table.Create(next_parameter->object).Unwrap() : 0); - rb.PushStaticBuffer(buffer, static_cast(next_parameter->buffer.size()), 0); + rb.PushStaticBuffer(buffer, next_parameter->buffer.size(), 0); Memory::WriteBlock(buffer, next_parameter->buffer.data(), next_parameter->buffer.size()); diff --git a/src/core/hle/service/cam/cam.cpp b/src/core/hle/service/cam/cam.cpp index c9f9e9d95..8172edae8 100644 --- a/src/core/hle/service/cam/cam.cpp +++ b/src/core/hle/service/cam/cam.cpp @@ -177,7 +177,7 @@ void CompletionEventCallBack(u64 port_id, int) { LOG_ERROR(Service_CAM, "The destination size (%u) doesn't match the source (%zu)!", port.dest_size, buffer_size); } - Memory::WriteBlock(port.dest, buffer.data(), std::min(port.dest_size, buffer_size)); + Memory::WriteBlock(port.dest, buffer.data(), std::min(port.dest_size, buffer_size)); } port.is_receiving = false; diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index f26a1f65f..f78c25fb2 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -141,7 +141,7 @@ void GetCountryCodeString(Service::Interface* self) { void GetCountryCodeID(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); - u16 country_code = cmd_buff[1]; + u16 country_code = static_cast(cmd_buff[1]); u16 country_code_id = 0; // The following algorithm will fail if the first country code isn't 0. diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 4ccb3cd32..4ee7df73c 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -217,7 +217,7 @@ void Directory::HandleSyncRequest(Kernel::SharedPtr serve LOG_TRACE(Service_FS, "Read %s: count=%d", GetName().c_str(), count); // Number of entries actually read - u32 read = backend->Read(entries.size(), entries.data()); + u32 read = backend->Read(static_cast(entries.size()), entries.data()); cmd_buff[2] = read; Memory::WriteBlock(address, entries.data(), read * sizeof(FileSys::Entry)); break; diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index aa5d821f9..379fbd71c 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -251,7 +251,7 @@ static void UpdateGyroscopeCallback(u64 userdata, int cycles_late) { Math::Vec3 gyro; std::tie(std::ignore, gyro) = motion_device->GetStatus(); double stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale(); - gyro *= gyroscope_coef * stretch; + gyro *= gyroscope_coef * static_cast(stretch); gyroscope_entry.x = static_cast(gyro.x); gyroscope_entry.y = static_cast(gyro.y); gyroscope_entry.z = static_cast(gyro.z); diff --git a/src/core/hle/service/ldr_ro/cro_helper.h b/src/core/hle/service/ldr_ro/cro_helper.h index 3bc10dbdc..57b4fb6df 100644 --- a/src/core/hle/service/ldr_ro/cro_helper.h +++ b/src/core/hle/service/ldr_ro/cro_helper.h @@ -413,7 +413,8 @@ private: */ template void GetEntry(std::size_t index, T& data) const { - Memory::ReadBlock(GetField(T::TABLE_OFFSET_FIELD) + index * sizeof(T), &data, sizeof(T)); + Memory::ReadBlock(GetField(T::TABLE_OFFSET_FIELD) + static_cast(index * sizeof(T)), + &data, sizeof(T)); } /** @@ -425,7 +426,8 @@ private: */ template void SetEntry(std::size_t index, const T& data) { - Memory::WriteBlock(GetField(T::TABLE_OFFSET_FIELD) + index * sizeof(T), &data, sizeof(T)); + Memory::WriteBlock(GetField(T::TABLE_OFFSET_FIELD) + static_cast(index * sizeof(T)), + &data, sizeof(T)); } /** diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 4e2af9ae6..8ef0cda09 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -316,7 +316,7 @@ static void RecvBeaconBroadcastData(Interface* self) { auto beacons = GetReceivedBeacons(mac_address); BeaconDataReplyHeader data_reply_header{}; - data_reply_header.total_entries = beacons.size(); + data_reply_header.total_entries = static_cast(beacons.size()); data_reply_header.max_output_size = out_buffer_size; Memory::WriteBlock(current_buffer_pos, &data_reply_header, sizeof(BeaconDataReplyHeader)); @@ -326,8 +326,8 @@ static void RecvBeaconBroadcastData(Interface* self) { for (const auto& beacon : beacons) { BeaconEntryHeader entry{}; // TODO(Subv): Figure out what this size is used for. - entry.unk_size = sizeof(BeaconEntryHeader) + beacon.data.size(); - entry.total_size = sizeof(BeaconEntryHeader) + beacon.data.size(); + entry.unk_size = static_cast(sizeof(BeaconEntryHeader) + beacon.data.size()); + entry.total_size = static_cast(sizeof(BeaconEntryHeader) + beacon.data.size()); entry.wifi_channel = beacon.channel; entry.header_size = sizeof(BeaconEntryHeader); entry.mac_address = beacon.transmitter_address; @@ -338,9 +338,9 @@ static void RecvBeaconBroadcastData(Interface* self) { current_buffer_pos += sizeof(BeaconEntryHeader); Memory::WriteBlock(current_buffer_pos, beacon.data.data(), beacon.data.size()); - current_buffer_pos += beacon.data.size(); + current_buffer_pos += static_cast(beacon.data.size()); - total_size += sizeof(BeaconEntryHeader) + beacon.data.size(); + total_size += static_cast(sizeof(BeaconEntryHeader) + beacon.data.size()); } // Update the total size in the structure and write it to the buffer again. diff --git a/src/core/hle/service/nwm/uds_beacon.cpp b/src/core/hle/service/nwm/uds_beacon.cpp index 552eaf65e..73a80d940 100644 --- a/src/core/hle/service/nwm/uds_beacon.cpp +++ b/src/core/hle/service/nwm/uds_beacon.cpp @@ -243,7 +243,7 @@ std::vector GenerateNintendoFirstEncryptedDataTag(const NetworkInfo& network EncryptedDataTag tag{}; tag.header.tag_id = static_cast(TagId::VendorSpecific); - tag.header.length = sizeof(tag) - sizeof(TagHeader) + payload_size; + tag.header.length = static_cast(sizeof(tag) - sizeof(TagHeader) + payload_size); tag.oui_type = static_cast(NintendoTagId::EncryptedData0); tag.oui = NintendoOUI; @@ -279,7 +279,7 @@ std::vector GenerateNintendoSecondEncryptedDataTag(const NetworkInfo& networ EncryptedDataTag tag{}; tag.header.tag_id = static_cast(TagId::VendorSpecific); - tag.header.length = tag_length; + tag.header.length = static_cast(tag_length); tag.oui_type = static_cast(NintendoTagId::EncryptedData1); tag.oui = NintendoOUI; diff --git a/src/core/hle/service/nwm/uds_data.cpp b/src/core/hle/service/nwm/uds_data.cpp index 0fd9b8b8c..3ef2a84b6 100644 --- a/src/core/hle/service/nwm/uds_data.cpp +++ b/src/core/hle/service/nwm/uds_data.cpp @@ -197,7 +197,7 @@ static std::vector DecryptDataFrame(const std::vector& encrypted_payload df.ChannelMessageEnd(CryptoPP::DEFAULT_CHANNEL); df.SetRetrievalChannel(CryptoPP::DEFAULT_CHANNEL); - int size = df.MaxRetrievable(); + size_t size = df.MaxRetrievable(); std::vector pdata(size); df.Get(pdata.data(), size); @@ -251,7 +251,7 @@ static std::vector EncryptDataFrame(const std::vector& payload, df.SetRetrievalChannel(CryptoPP::DEFAULT_CHANNEL); - int size = df.MaxRetrievable(); + size_t size = df.MaxRetrievable(); std::vector cipher(size); df.Get(cipher.data(), size); @@ -266,8 +266,8 @@ static std::vector EncryptDataFrame(const std::vector& payload, std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 dest_node, u16 src_node, u16 sequence_number) { std::vector buffer = GenerateLLCHeader(EtherType::SecureData); - std::vector securedata_header = - GenerateSecureDataHeader(data.size(), channel, dest_node, src_node, sequence_number); + std::vector securedata_header = GenerateSecureDataHeader( + static_cast(data.size()), channel, dest_node, src_node, sequence_number); buffer.insert(buffer.end(), securedata_header.begin(), securedata_header.end()); buffer.insert(buffer.end(), data.begin(), data.end()); diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 05c6897bf..41c82c922 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -361,7 +361,7 @@ static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 ha // We found a ready object, acquire it and set the result value Kernel::WaitObject* object = itr->get(); object->Acquire(thread); - *out = std::distance(objects.begin(), itr); + *out = static_cast(std::distance(objects.begin(), itr)); return RESULT_SUCCESS; } @@ -469,7 +469,7 @@ static ResultCode ReplyAndReceive(s32* index, Kernel::Handle* handles, s32 handl // We found a ready object, acquire it and set the result value Kernel::WaitObject* object = itr->get(); object->Acquire(thread); - *index = std::distance(objects.begin(), itr); + *index = static_cast(std::distance(objects.begin(), itr)); if (object->GetHandleType() == Kernel::HandleType::ServerSession) { auto server_session = static_cast(object); @@ -683,7 +683,7 @@ static void ExitThread() { } /// Gets the priority for the specified thread -static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) { +static ResultCode GetThreadPriority(u32* priority, Kernel::Handle handle) { const SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -693,7 +693,7 @@ static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) { } /// Sets the priority for the specified thread -static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { +static ResultCode SetThreadPriority(Kernel::Handle handle, u32 priority) { if (priority > THREADPRIO_LOWEST) { return Kernel::ERR_OUT_OF_RANGE; } diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 5ea0694a9..847e69710 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -477,7 +477,7 @@ void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) { while (remaining_size > 0) { const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size); - const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset; + const VAddr current_vaddr = static_cast((page_index << PAGE_BITS) + page_offset); switch (current_page_table->attributes[page_index]) { case PageType::Unmapped: { @@ -500,13 +500,15 @@ void ReadBlock(const VAddr src_addr, void* dest_buffer, const size_t size) { break; } case PageType::RasterizerCachedMemory: { - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush); + RasterizerFlushVirtualRegion(current_vaddr, static_cast(copy_amount), + FlushMode::Flush); std::memcpy(dest_buffer, GetPointerFromVMA(current_vaddr), copy_amount); break; } case PageType::RasterizerCachedSpecial: { DEBUG_ASSERT(GetMMIOHandler(current_vaddr)); - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush); + RasterizerFlushVirtualRegion(current_vaddr, static_cast(copy_amount), + FlushMode::Flush); GetMMIOHandler(current_vaddr)->ReadBlock(current_vaddr, dest_buffer, copy_amount); break; } @@ -544,7 +546,7 @@ void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size while (remaining_size > 0) { const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size); - const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset; + const VAddr current_vaddr = static_cast((page_index << PAGE_BITS) + page_offset); switch (current_page_table->attributes[page_index]) { case PageType::Unmapped: { @@ -567,13 +569,15 @@ void WriteBlock(const VAddr dest_addr, const void* src_buffer, const size_t size break; } case PageType::RasterizerCachedMemory: { - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate); + RasterizerFlushVirtualRegion(current_vaddr, static_cast(copy_amount), + FlushMode::FlushAndInvalidate); std::memcpy(GetPointerFromVMA(current_vaddr), src_buffer, copy_amount); break; } case PageType::RasterizerCachedSpecial: { DEBUG_ASSERT(GetMMIOHandler(current_vaddr)); - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate); + RasterizerFlushVirtualRegion(current_vaddr, static_cast(copy_amount), + FlushMode::FlushAndInvalidate); GetMMIOHandler(current_vaddr)->WriteBlock(current_vaddr, src_buffer, copy_amount); break; } @@ -597,7 +601,7 @@ void ZeroBlock(const VAddr dest_addr, const size_t size) { while (remaining_size > 0) { const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size); - const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset; + const VAddr current_vaddr = static_cast((page_index << PAGE_BITS) + page_offset); switch (current_page_table->attributes[page_index]) { case PageType::Unmapped: { @@ -619,13 +623,15 @@ void ZeroBlock(const VAddr dest_addr, const size_t size) { break; } case PageType::RasterizerCachedMemory: { - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate); + RasterizerFlushVirtualRegion(current_vaddr, static_cast(copy_amount), + FlushMode::FlushAndInvalidate); std::memset(GetPointerFromVMA(current_vaddr), 0, copy_amount); break; } case PageType::RasterizerCachedSpecial: { DEBUG_ASSERT(GetMMIOHandler(current_vaddr)); - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::FlushAndInvalidate); + RasterizerFlushVirtualRegion(current_vaddr, static_cast(copy_amount), + FlushMode::FlushAndInvalidate); GetMMIOHandler(current_vaddr)->WriteBlock(current_vaddr, zeros.data(), copy_amount); break; } @@ -646,7 +652,7 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { while (remaining_size > 0) { const size_t copy_amount = std::min(PAGE_SIZE - page_offset, remaining_size); - const VAddr current_vaddr = (page_index << PAGE_BITS) + page_offset; + const VAddr current_vaddr = static_cast((page_index << PAGE_BITS) + page_offset); switch (current_page_table->attributes[page_index]) { case PageType::Unmapped: { @@ -670,13 +676,15 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { break; } case PageType::RasterizerCachedMemory: { - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush); + RasterizerFlushVirtualRegion(current_vaddr, static_cast(copy_amount), + FlushMode::Flush); WriteBlock(dest_addr, GetPointerFromVMA(current_vaddr), copy_amount); break; } case PageType::RasterizerCachedSpecial: { DEBUG_ASSERT(GetMMIOHandler(current_vaddr)); - RasterizerFlushVirtualRegion(current_vaddr, copy_amount, FlushMode::Flush); + RasterizerFlushVirtualRegion(current_vaddr, static_cast(copy_amount), + FlushMode::Flush); std::vector buffer(copy_amount); GetMMIOHandler(current_vaddr)->ReadBlock(current_vaddr, buffer.data(), buffer.size()); @@ -689,8 +697,8 @@ void CopyBlock(VAddr dest_addr, VAddr src_addr, const size_t size) { page_index++; page_offset = 0; - dest_addr += copy_amount; - src_addr += copy_amount; + dest_addr += static_cast(copy_amount); + src_addr += static_cast(copy_amount); remaining_size -= copy_amount; } } diff --git a/src/network/packet.cpp b/src/network/packet.cpp index cc60f2fbc..7e1a812f3 100644 --- a/src/network/packet.cpp +++ b/src/network/packet.cpp @@ -233,7 +233,7 @@ Packet& Packet::operator<<(double in_data) { Packet& Packet::operator<<(const char* in_data) { // First insert string length - u32 length = std::strlen(in_data); + u32 length = static_cast(std::strlen(in_data)); *this << length; // Then insert characters diff --git a/src/video_core/geometry_pipeline.cpp b/src/video_core/geometry_pipeline.cpp index b146e2ecb..98ff2ccd3 100644 --- a/src/video_core/geometry_pipeline.cpp +++ b/src/video_core/geometry_pipeline.cpp @@ -105,7 +105,7 @@ public: DEBUG_ASSERT(need_index); // The number of vertex input is put to the uniform register - float24 vertex_num = float24::FromFloat32(val); + float24 vertex_num = float24::FromFloat32(static_cast(val)); setup.uniforms.f[0] = Math::MakeVec(vertex_num, vertex_num, vertex_num, vertex_num); // The second uniform register and so on are used for receiving input vertices diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 06a905766..5770ae08f 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -267,9 +267,9 @@ void OpenGLState::Apply() const { for (size_t i = 0; i < clip_distance.size(); ++i) { if (clip_distance[i] != cur_state.clip_distance[i]) { if (clip_distance[i]) { - glEnable(GL_CLIP_DISTANCE0 + i); + glEnable(GL_CLIP_DISTANCE0 + static_cast(i)); } else { - glDisable(GL_CLIP_DISTANCE0 + i); + glDisable(GL_CLIP_DISTANCE0 + static_cast(i)); } } } -- cgit v1.2.3