Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / DarkNet UDP Receive

Author
Message
Scab
22
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 21st May 2010 21:37
Isn't there a way to send UDP position info from server to client without looping through all possible clients?

e.g. from Cube World:



If you have a maximum of 500 clients, it's going to have to do a UDP check for each of them.

Also, with the line: UDPPackets = mn Recv UDP(0,RecvPacket,PlayerA,0)

Is PlayerA the Player that the packet is about?

How do I even send all of my enemy positions from server to client?
What do I use for PlayerA? It's not info about a player.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 21st May 2010 22:14
I use PER CLIENT PER OPERATION mode for this, although for the moment I'm only using 1 operation there is possibility for expansion.

DO NOT USE OPERATION 0. Start with Operation 1. Operation 0 seems to lump everyone's data into one packet space instead of keeping them separated. I discovered this when there were 5 players on the server and only one of them was moving. When I changed to operation 1 everything worked fine.

Here is an example of how I'm doing it. Let's take your 500 clients to check.

- Set up a variable to count your loops up to 25, then reset to 0.
- Every 5th loop count the first 100.
- Every 10th loop count 101 to 200.
- 15th loop, 201 to 300.
- etc..


This is a very simplified example, but it does at least 2 things.

1. It checks all your players in a very short amount of time.
2. It saves CPU cycles, thus not killing your framerate.

You can apply this same concept to several other things that don't necessarily need to happen EVERY game loop, and your game's performance will improve dramatically.

Scab
22
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 24th May 2010 05:50
Thanks KISTech.

So this can help with the problem of having to loop through all clients to see if there is any UDP infor about them.

But how do I send enemy info? Should I just make enemies start at 500 and send them as clients?
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 24th May 2010 18:27
Enemies / AI is a difficult one, however you are sort of on the right track. You don't want to extend the top number out to far, or it will be a much longer time before it gets around to the 1st player again, and you'll get jerky movements.

I would run the enemies through the same routine, but use a different operation ID. If you are using Operation ID 1 for player movements, then use 2 for AI. When you receive the packet you can then determine if it's a player or an AI by the operation id and update them accordingly. You can still use the Player IDs when sending updates for AI, because you know that it's actually AI data instead of player data.

It's up to you to figure out how many can be processed at a time. You might have to process fewer in a given loop (say 50 players and 50 AI) so the checks don't take to long, but then you might have to check every 4th or 3rd loop instead of every 5th so the time between the first and last player/AI isn't to long.

Your movement code and the data you send will play the biggest part in making sure that the player and AI movements are smooth between updates.

Login to post a reply

Server time is: 2026-07-25 08:30:00
Your offset time is: 2026-07-25 08:30:00