Question about a different way to use Enet.
First of all thanks for the nice free lib and sorry about my english. I work on a little vehicle physics multiplayer project: https://www.youtube.com/watch?v=5PR0mDOe_Hk
My question is about how enet working, Normally I have a host and clients. The client send the packet to the host and the host resent all packets to all clients and the sender client is included too. This method is fine with many game types but with my vehicle project the main idea is to have the real vehicle physics representation for all clients. On this way all clients have a real vehicle physics simulated from the client app and not from the host. The client send the real vehicle physics info to the host and the other clients recreate a quick simple representation of this informations.
My question, Is it possible for a client to send the packet to the host but make the host avoid to resend the packet to this sender client. Currently i'm able to avoid the packet in the onreceive of all clients with a check id but the host send it back anyway.
Is it possible to avoid the host to send back the packet for this sender client ? Currently It work pretty good but if I avoid the sender packet from the host directly, I think I can gain some more bandwidth.
If it is not possible to do with enet lib, Do you have any suggestions about how I can do this behaviour with the lib.
In host.c enet_host_broadcast function I have try to use something like this but it don't work good. if (currentPeer->incomingPeerID != currentPeer->outgoingPeerID) enet_peer_send(currentPeer, channelID, packet);
If it is possible I don't see how I can do it. I have see this post, It look similar to what I need : https://github.com/lsalzman/enet/issues/35 But I don't see how to make it work, I only need to avoid the sender peer I don't need to avoid multiple peers.
Thanks.
enet_host_create will assign a sequential ID, starting at 0, to every ENetPeer in the ENetHost.peers array (which contains peerCount peers). These IDs do not change and are stored in ENetPeer.incomingPeerID.
When you receive the ENetEvent from enet_host_service(), it will contain both the ENetPeer and the ENetPacket. You'd have to write your own version of enet_host_broadcast which takes an additional parameter, enet_uint16 incomingPeerID, which you would get from ENetEvent.peer.incomingPeerID, then broadcast the packet to every peer except that one.
The custom broadcast function would look something like this:
void
enet_host_broadcast_except_sender (ENetHost * host, enet_uint8 channelID, ENetPacket * packet, enet_uint16 incomingPeerID)
{
ENetPeer * currentPeer;
for (currentPeer = host -> peers;
currentPeer < & host -> peers [host -> peerCount];
++ currentPeer)
{
if (currentPeer -> state != ENET_PEER_STATE_CONNECTED || currentPeer -> incomingPeerID == incomingPeerID)
continue;
enet_peer_send (currentPeer, channelID, packet);
}
if (packet -> referenceCount == 0)
enet_packet_destroy (packet);
}
Disclaimer: Code not tested. For illustrative purposes only.