Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sending/Receiving the Game World


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 tedsta   Members   -  Reputation: 258

Like
0Likes
Like

Posted 15 April 2013 - 11:27 PM

Hi all, I've been working on a sort of side-scrolling, shoot em up, RTS game for the past few weeks and am now confronting the issue of sending the game world to the client when it logs in. Right now, when the player logs in, the entire game world is sent all at once (each object gets it's own packet) over reliable UDP (I'm using enet). Originally, I had the game world all in one packet, but the packet was too big to send in just one packet (it's like 50kb). Right now, it works fine if you have fast internet, but with slow internet (50 kilobytes per second) the client will hang there for a very long time receiving only a few game objects a second and never really receives the entire game world.

 

Any suggestions? I'm about to implement a system where it spreads the packets out over a few seconds, is that a good fix? Or are there fancy ways that would be better?


Current Project

World Storm

 

out our Android app! (My roommate and I)

https://play.google.com/store/apps/details?id=com.drsupersocks.ninja


Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 15737

Like
1Likes
Like

Posted 16 April 2013 - 02:28 AM

How are you sending the data? And how do you go about receiving it? Transmitting 50KB of data even over a slow connection (barring dialup) should take less than a second.

#3 nfactorial   Members   -  Reputation: 729

Like
2Likes
Like

Posted 16 April 2013 - 06:48 AM

You don't need to send the whole world, just the area around the players location. Generally, an RTS game has both players starting together so there's no need to send any data initially. If you have a hot joinable game, then sending only the players immediate surroundings will help improve bandwidth. You should generally be sending delta's after the clients are synchronised. Perhaps expand on your requirements if that doesn't help?

 

But, as Apoch says, 50k should transfer pretty quickly.

 

n!


Edited by nfactorial, 16 April 2013 - 06:48 AM.


#4 hplus0603   Moderators   -  Reputation: 5309

Like
1Likes
Like

Posted 16 April 2013 - 11:48 AM

If the problem is that Enet limits the number of packets per second (with a small send window, say) then you should cram as much as you can into each packet. Let's say Enet allows up to 1300 bytes per packet, then you should cram as many entity updates as you can into that one packet. 39 packets later, you will have sent everything.<br />
enum Bool { True, False, FileNotFound };

#5 tedsta   Members   -  Reputation: 258

Like
0Likes
Like

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::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.


Edited by DrSuperSocks, 16 April 2013 - 05:00 PM.

Current Project

World Storm

 

out our Android app! (My roommate and I)

https://play.google.com/store/apps/details?id=com.drsupersocks.ninja


#6 hplus0603   Moderators   -  Reputation: 5309

Like
2Likes
Like

Posted 17 April 2013 - 07:07 PM

A good ball park number for maximum payload size is 1300 bytes. This works well with the vast majority of networks out there, and is big enough that the per-packet overhead won't be more than a few percent.
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS