| 34 | } |
| 35 | |
| 36 | void SendPacketToPeer(ENetPeer* peer, const NetworkChannelType channelType, const NetworkMessage& message) |
| 37 | { |
| 38 | // Covert our channel type to the internal ENet packet flags |
| 39 | const ENetPacketFlag flag = ChannelTypeToPacketFlag(channelType); |
| 40 | |
| 41 | // This will copy the data into the packet when ENET_PACKET_FLAG_NO_ALLOCATE is not set. |
| 42 | // Tho, we cannot use it, because we're releasing the message right after the send - and the packet might not |
| 43 | // be sent, yet. To avoid data corruption, we're just using the copy method. We might fix that later, but I'll take |
| 44 | // the smaller risk. |
| 45 | ENetPacket* packet = enet_packet_create(message.Buffer, message.Length, flag); |
| 46 | |
| 47 | // And send it! |
| 48 | enet_peer_send(peer, 0, packet); |
| 49 | |
| 50 | // TODO: To reduce latency, we can use `enet_host_flush` to flush all packets. Maybe some API, like NetworkManager::FlushQueues()? |
| 51 | } |
| 52 | |
| 53 | ENetDriver::ENetDriver(const SpawnParams& params) |
| 54 | : ScriptingObject(params) |
no test coverage detected