Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualDrSuperSocks

Posted 16 April 2013 - 05:00 PM

Yes, it's a hot joinable game. Currently, each object get's it's own packet in the initial world send, and I mass send all of them at once.

 

Here is the relevant code:

 

void NetworkManager::send(sf::Packet &packet, int connectorID, int excludeID, bool reliable)
{
    sf::Packet finalPacket;
    //finalPacket << sf::Int8(0);
    finalPacket.append(packet.getData(), packet.getDataSize());

    // Create the enet packet
    unsigned int flags = 0;
    if (reliable)
        flags |= ENET_PACKET_FLAG_RELIABLE;

    ENetPacket *enetPacket = enet_packet_create(finalPacket.getData(), finalPacket.getDataSize(), flags);

    if (mType == NetworkType::CLIENT) // Clients send data to server only
    {
        enet_host_broadcast(mHost, 0, enetPacket);
    }
    else if (connectorID > 0) // It's a server and the client is specified. Tell only that client!
    {
        enet_peer_send(findConnector(connectorID)->mPeer, 0, enetPacket);
    }
    else // It's a server and the client is unspecified. Broadcast to everyone
    {
        if (excludeID > 0)
        {
            for (unsigned int i = 0; i < mConnectors.size(); i++)
            {
                if (mConnectors[i]->mID != excludeID && mConnectors[i]->mPeer)
                    enet_peer_send(mConnectors[i]->mPeer, 0, enetPacket);
            }
        }
        else
            enet_host_broadcast(mHost, 0, enetPacket);
    }
}

void NetworkManager::sendSceneCreation(int connectorID, int excludeID, bool reliable)
{
    for (unsigned int i = 0; i < SceneManager::get()->getCurrentScene()->getGameObjects().size(); i++)
    {
        if (SceneManager::get()->getCurrentScene()->getGameObjects()[i]->getSyncNetwork())
            sendGameObject(SceneManager::get()->getCurrentScene()->getGameObjects()[i], connectorID, excludeID, reliable);
    }
}

void NetworkManager::sendGameObject(GameObject *object, int connectorID, int excludeID, bool reliable)
{
    sf::Packet packet;
    packet << PacketType::CREATE_OBJECT;
    object->serialize(packet);

    send(packet, connectorID, excludeID, reliable);
}

 

 

Thanks for the suggestions, I'll cram stuff into bigger packets. Could you recommend a good maximum packet size? I'll make it adjustable and play with it, but I'd like a ball park biggrin.png This networking stuff is all very new to me.

 

And thanks, nfactorial, I've also given sending only immediate surroundings a thought, and that will be very easy since I already have stuff to detect which planet you are currently on (you fight across many 2D planets).

Edit: But also, in that regard, sending only the current surroundings is kind of the scenario at hand, since I only have 2 planets in the game right now. I plan on having around 100 planets in an actual match.


#4DrSuperSocks

Posted 16 April 2013 - 04:50 PM

Yes, it's a hot joinable game. Currently, each object get's it's own packet in the initial world send, and I mass send all of them at once.

 

Here is the relevant code:

 

void NetworkManager::send(sf::Packet &packet, int connectorID, int excludeID, bool reliable)
{
    sf::Packet finalPacket;
    //finalPacket << sf::Int8(0);
    finalPacket.append(packet.getData(), packet.getDataSize());

    // Create the enet packet
    unsigned int flags = 0;
    if (reliable)
        flags |= ENET_PACKET_FLAG_RELIABLE;

    ENetPacket *enetPacket = enet_packet_create(finalPacket.getData(), finalPacket.getDataSize(), flags);

    if (mType == NetworkType::CLIENT) // Clients send data to server only
    {
        enet_host_broadcast(mHost, 0, enetPacket);
    }
    else if (connectorID > 0) // It's a server and the client is specified. Tell only that client!
    {
        enet_peer_send(findConnector(connectorID)->mPeer, 0, enetPacket);
    }
    else // It's a server and the client is unspecified. Broadcast to everyone
    {
        if (excludeID > 0)
        {
            for (unsigned int i = 0; i < mConnectors.size(); i++)
            {
                if (mConnectors[i]->mID != excludeID && mConnectors[i]->mPeer)
                    enet_peer_send(mConnectors[i]->mPeer, 0, enetPacket);
            }
        }
        else
            enet_host_broadcast(mHost, 0, enetPacket);
    }
}

void NetworkManager::sendSceneCreation(int connectorID, int excludeID, bool reliable)
{
    for (unsigned int i = 0; i < SceneManager::get()->getCurrentScene()->getGameObjects().size(); i++)
    {
        if (SceneManager::get()->getCurrentScene()->getGameObjects()[i]->getSyncNetwork())
            sendGameObject(SceneManager::get()->getCurrentScene()->getGameObjects()[i], connectorID, excludeID, reliable);
    }
}

void NetworkManager::sendGameObject(GameObject *object, int connectorID, int excludeID, bool reliable)
{
    sf::Packet packet;
    packet << PacketType::CREATE_OBJECT;
    object->serialize(packet);

    send(packet, connectorID, excludeID, reliable);
}

 

 

Thanks for the suggestions, I'll cram stuff into bigger packets. Could you recommend a good maximum packet size? I'll make it adjustable and play with it, but I'd like a ball park biggrin.png This networking stuff is all very new to me.

 

And thanks, nfactorial, I've also given sending only immediate surroundings a thought, and that will be very easy since I already have stuff to detect which planet you are currently on (you fight across many 2D planets).


#3DrSuperSocks

Posted 16 April 2013 - 04:50 PM

Yes, it's a hot joinable game. Currently, each object get's it's own packet in the initial world send, and I mass send all of them at once.

 

Here is the relevant code:

 

void NetworkManager::send(sf::Packet &packet, int connectorID, int excludeID, bool reliable)
{
    sf::Packet finalPacket;
    //finalPacket << sf::Int8(0);
    finalPacket.append(packet.getData(), packet.getDataSize());

    // Create the enet packet
    unsigned int flags = 0;
    if (reliable)
        flags |= ENET_PACKET_FLAG_RELIABLE;

    ENetPacket *enetPacket = enet_packet_create(finalPacket.getData(), finalPacket.getDataSize(), flags);

    if (mType == NetworkType::CLIENT) // Clients send data to server only
    {
        enet_host_broadcast(mHost, 0, enetPacket);
    }
    else if (connectorID > 0) // It's a server and the client is specified. Tell only that client!
    {
        enet_peer_send(findConnector(connectorID)->mPeer, 0, enetPacket);
    }
    else // It's a server and the client is unspecified. Broadcast to everyone
    {
        if (excludeID > 0)
        {
            for (unsigned int i = 0; i < mConnectors.size(); i++)
            {
                if (mConnectors[i]->mID != excludeID && mConnectors[i]->mPeer)
                    enet_peer_send(mConnectors[i]->mPeer, 0, enetPacket);
            }
        }
        else
            enet_host_broadcast(mHost, 0, enetPacket);
    }
}
void NetworkManager::sendGameObject(GameObject *object, int connectorID, int excludeID, bool reliable)
{
    sf::Packet packet;
    packet << PacketType::CREATE_OBJECT;
    object->serialize(packet);
 
    send(packet, connectorID, excludeID, reliable);
}

void NetworkManager::sendSceneCreation(int connectorID, int excludeID, bool reliable)
{
    for (unsigned int i = 0; i < SceneManager::get()->getCurrentScene()->getGameObjects().size(); i++)
    {
        if (SceneManager::get()->getCurrentScene()->getGameObjects()[i]->getSyncNetwork())
            sendGameObject(SceneManager::get()->getCurrentScene()->getGameObjects()[i], connectorID, excludeID, reliable);
    }
}
 

 

Thanks for the suggestions, I'll cram stuff into bigger packets. Could you recommend a good maximum packet size? I'll make it adjustable and play with it, but I'd like a ball park biggrin.png This networking stuff is all very new to me.

 

And thanks, nfactorial, I've also given sending only immediate surroundings a thought, and that will be very easy since I already have stuff to detect which planet you are currently on (you fight across many 2D planets).


#2DrSuperSocks

Posted 16 April 2013 - 04:49 PM

Yes, it's a hot joinable game. Currently, each object get's it's own packet in the initial world send, and I mass send all of them at once.

 

Here is the relevant code:

 

void NetworkManager::send(sf::Packet &packet, int connectorID, int excludeID, bool reliable)
{
    sf::Packet finalPacket;
    //finalPacket << sf::Int8(0);
    finalPacket.append(packet.getData(), packet.getDataSize());

    // Create the enet packet
    unsigned int flags = 0;
    if (reliable)
        flags |= ENET_PACKET_FLAG_RELIABLE;

    ENetPacket *enetPacket = enet_packet_create(finalPacket.getData(), finalPacket.getDataSize(), flags);

    if (mType == NetworkType::CLIENT) // Clients send data to server only
    {
        enet_host_broadcast(mHost, 0, enetPacket);
    }
    else if (connectorID > 0) // It's a server and the client is specified. Tell only that client!
    {
        enet_peer_send(findConnector(connectorID)->mPeer, 0, enetPacket);
    }
    else // It's a server and the client is unspecified. Broadcast to everyone
    {
        if (excludeID > 0)
        {
            for (unsigned int i = 0; i < mConnectors.size(); i++)
            {
                if (mConnectors[i]->mID != excludeID && mConnectors[i]->mPeer)
                    enet_peer_send(mConnectors[i]->mPeer, 0, enetPacket);
            }
        }
        else
            enet_host_broadcast(mHost, 0, enetPacket);
    }
}

void NetworkManager::sendGameObject(GameObject *object, int connectorID, int excludeID, bool reliable)
{
    sf::Packet packet;
    packet << PacketType::CREATE_OBJECT;
    object->serialize(packet);
 
    send(packet, connectorID, excludeID, reliable);
}
 

void NetworkManager::sendSceneCreation(int connectorID, int excludeID, bool reliable)
{
    for (unsigned int i = 0; i < SceneManager::get()->getCurrentScene()->getGameObjects().size(); i++)
    {
        if (SceneManager::get()->getCurrentScene()->getGameObjects()[i]->getSyncNetwork())
            sendGameObject(SceneManager::get()->getCurrentScene()->getGameObjects()[i], connectorID, excludeID, reliable);
    }
}

 

Thanks for the suggestions, I'll cram stuff into bigger packets. Could you recommend a good maximum packet size? I'll make it adjustable and play with it, but I'd like a ball park biggrin.png This networking stuff is all very new to me.

 

And thanks, nfactorial, I've also given sending only immediate surroundings a thought, and that will be very easy since I already have stuff to detect which planet you are currently on (you fight across many 2D planets).


#1DrSuperSocks

Posted 16 April 2013 - 04:49 PM

Yes, it's a hot joinable game. Currently, each object get's it's own packet in the initial world send, and I mass send all of them at once.

 

Here is the relevant code:

 

void NetworkManager::send(sf::Packet &packet, int connectorID, int excludeID, bool reliable)
{
    sf::Packet finalPacket;
    //finalPacket << sf::Int8(0);
    finalPacket.append(packet.getData(), packet.getDataSize());

    // Create the enet packet
    unsigned int flags = 0;
    if (reliable)
        flags |= ENET_PACKET_FLAG_RELIABLE;

    ENetPacket *enetPacket = enet_packet_create(finalPacket.getData(), finalPacket.getDataSize(), flags);

    if (mType == NetworkType::CLIENT) // Clients send data to server only
    {
        enet_host_broadcast(mHost, 0, enetPacket);
    }
    else if (connectorID > 0) // It's a server and the client is specified. Tell only that client!
    {
        enet_peer_send(findConnector(connectorID)->mPeer, 0, enetPacket);
    }
    else // It's a server and the client is unspecified. Broadcast to everyone
    {
        if (excludeID > 0)
        {
            for (unsigned int i = 0; i < mConnectors.size(); i++)
            {
                if (mConnectors[i]->mID != excludeID && mConnectors[i]->mPeer)
                    enet_peer_send(mConnectors[i]->mPeer, 0, enetPacket);
            }
        }
        else
            enet_host_broadcast(mHost, 0, enetPacket);
    }
}

void NetworkManager::sendGameObject(GameObject *object, int connectorID, int excludeID, bool reliable)
{
    sf::Packet packet;
    packet << PacketType::CREATE_OBJECT;
    object->serialize(packet);
 
    send(packet, connectorID, excludeID, reliable);
}
 

void NetworkManager::sendSceneCreation(int connectorID, int excludeID, bool reliable)
{
    for (unsigned int i = 0; i < SceneManager::get()->getCurrentScene()->getGameObjects().size(); i++)
    {
        if (SceneManager::get()->getCurrentScene()->getGameObjects()[i]->getSyncNetwork())
            sendGameObject(SceneManager::get()->getCurrentScene()->getGameObjects()[i], connectorID, excludeID, reliable);
    }
}

 

Thanks for the suggestions, I'll cram stuff into bigger packets. Could you recommend a good maximum packet size? I'll make it adjustable and play with it, but I'd like a ball park :D This networking stuff is all very new to me.

 

And thanks, nfactorial, I've also given sending only immediate surroundings a thought, and that will be very easy since I already have stuff to detect which planet you are currently on (you fight across many 2D planets).


PARTNERS