Add simple SendMessage with single target

This commit is contained in:
Damian Korczowski
2021-04-16 22:08:59 +02:00
parent ed82787093
commit e7f899309c
5 changed files with 28 additions and 2 deletions

View File

@@ -205,13 +205,24 @@ void ENetDriver::SendMessage(const NetworkChannelType channelType, const Network
SendPacketToPeer((ENetPeer*)_peer, channelType, message); SendPacketToPeer((ENetPeer*)_peer, channelType, message);
} }
void ENetDriver::SendMessage(NetworkChannelType channelType, const NetworkMessage& message, NetworkConnection target)
{
ASSERT(IsServer());
ENetPeer* peer = *(ENetPeer**)_peerMap.TryGet(target.ConnectionId);
ASSERT(peer != nullptr);
ASSERT(peer->state == ENET_PEER_STATE_CONNECTED);
SendPacketToPeer(peer, channelType, message);
}
void ENetDriver::SendMessage(const NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection, HeapAllocation> targets) void ENetDriver::SendMessage(const NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection, HeapAllocation> targets)
{ {
ASSERT(IsServer()); ASSERT(IsServer());
for(NetworkConnection connection : targets) for(NetworkConnection target : targets)
{ {
ENetPeer* peer = *(ENetPeer**)_peerMap.TryGet(connection.ConnectionId); ENetPeer* peer = *(ENetPeer**)_peerMap.TryGet(target.ConnectionId);
ASSERT(peer != nullptr); ASSERT(peer != nullptr);
ASSERT(peer->state == ENET_PEER_STATE_CONNECTED); ASSERT(peer->state == ENET_PEER_STATE_CONNECTED);

View File

@@ -25,6 +25,7 @@ public:
bool PopEvent(NetworkEvent* eventPtr) override; bool PopEvent(NetworkEvent* eventPtr) override;
void SendMessage(NetworkChannelType channelType, const NetworkMessage& message) override; void SendMessage(NetworkChannelType channelType, const NetworkMessage& message) override;
void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, NetworkConnection target) override;
void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection, HeapAllocation> targets) override; void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection, HeapAllocation> targets) override;
private: private:

View File

@@ -19,6 +19,7 @@ public:
virtual bool PopEvent(NetworkEvent* eventPtr) = 0; virtual bool PopEvent(NetworkEvent* eventPtr) = 0;
virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message) = 0; virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message) = 0;
virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, NetworkConnection target) = 0;
virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection, HeapAllocation> targets) = 0; virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection, HeapAllocation> targets) = 0;
// TODO: Stats API // TODO: Stats API

View File

@@ -137,6 +137,18 @@ bool NetworkManager::EndSendMessage(const int hostId, const NetworkChannelType c
return false; return false;
} }
bool NetworkManager::EndSendMessage(const int hostId, const NetworkChannelType channelType, const NetworkMessage& message, const NetworkConnection& target)
{
ASSERT(Hosts[hostId].IsValid());
NetworkHost& host = Hosts[hostId];
ASSERT(message.IsValid());
host.NetworkDriver->SendMessage(channelType, message, target);
RecycleMessage(hostId, message);
return false;
}
bool NetworkManager::EndSendMessage(const int hostId, const NetworkChannelType channelType, const NetworkMessage& message, const Array<NetworkConnection> targets) bool NetworkManager::EndSendMessage(const int hostId, const NetworkChannelType channelType, const NetworkMessage& message, const Array<NetworkConnection> targets)
{ {
ASSERT(Hosts[hostId].IsValid()); ASSERT(Hosts[hostId].IsValid());

View File

@@ -26,6 +26,7 @@ public:
API_FUNCTION() static NetworkMessage BeginSendMessage(int hostId); API_FUNCTION() static NetworkMessage BeginSendMessage(int hostId);
API_FUNCTION() static void AbortSendMessage(int hostId, const NetworkMessage& message); API_FUNCTION() static void AbortSendMessage(int hostId, const NetworkMessage& message);
API_FUNCTION() static bool EndSendMessage(int hostId, NetworkChannelType channelType, const NetworkMessage& message); API_FUNCTION() static bool EndSendMessage(int hostId, NetworkChannelType channelType, const NetworkMessage& message);
API_FUNCTION() static bool EndSendMessage(int hostId, NetworkChannelType channelType, const NetworkMessage& message, const NetworkConnection& target);
API_FUNCTION() static bool EndSendMessage(int hostId, NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection, HeapAllocation> targets); API_FUNCTION() static bool EndSendMessage(int hostId, NetworkChannelType channelType, const NetworkMessage& message, Array<NetworkConnection, HeapAllocation> targets);
// TODO: Stats API // TODO: Stats API