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 / DarkBasic Pro Multiplayer question

Author
Message
Gaia
12
Years of Service
User Offline
Joined: 9th Jul 2013
Location: Netherlands
Posted: 9th Jul 2013 23:40
Dear forum members,

I have a problem with my multiplayer game and since people on these forums seem to know everything, I decided to try my luck here, and hope someone can help me with it.

I'm trying to create a simple 2p multiplayer RTS game using DarkBasic Pro.
The code works as follows: first a pier to pier connection is set up between the two computers, then 2 objects per person are drawn to the screen, the X,Y,Z and a health stat of these objects are known to both computers. You can move the objects with the mouse, if your object gets close enough to enemy objects, they start to damage each other.
When an ojbects health gets below (or at) 0 the program will remove the object.
Simplified version of the main loop of the code here:


This code works fine, if an object is moved on one screen, it will also move on the other screen, until one of the health stats gets below(or at) 0. If it happens, the object should be deleted at both computers at the same time, however this doesn't happen, and the result is the computer waiting for information it will never recieve and thus a deadlock occurs.
If anybody knows what exactly the problem is (it appears the healthstats of both computers is not completely in sync), or knows how to fix it, any help is much appreciated.

Gaia
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 10th Jul 2013 07:23
Addressing your immediate problem:
It looks like you are deleting "the object" when health reaches 0. Then after you go to transmit location and status info, but only if "the object" exists. Your problem is that you are using 'object exists' for things that should instead use a health variable.

Taking a step back to see the bigger picture:
You are synchronizing at too low of a level. Instead of synchronizing in terms of objects, store the players health, x, y, z, etc. in variables that are named in an organized manner. Then just synchronize that data and let each computer do the heavy lifting making sure objects are where they should be.

I am worried about going into too much detail since it might discourage you. But using a UDT (user defined type) would alow you to visually organize player related variables better. Also network efficiency is a good idea, where you are only sending data when it is needed. For example if a player stops moving, there's no need to keep transmitting his location.

Gaia
12
Years of Service
User Offline
Joined: 9th Jul 2013
Location: Netherlands
Posted: 10th Jul 2013 15:20
Thanks a lot for your reaction. I am busy storing everything in variables, and using UDT's seems useful, I will look into it. Network efficiency is indeed a good idea, but first I'll try to make this work. Anyway thanks again and I'll see if I can make it work.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 11th Jul 2013 14:40 Edited at: 11th Jul 2013 15:06
Here is another way to solve problems with networking. This is used in almost all good network gaming.

http://en.wikipedia.org/wiki/Pathfinding

Once you understand this concept, you can do more with your networking because it doesn't have to report every single plot or movement position. So its less stress on your server / client.

https://soundcloud.com/toraktu
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 11th Jul 2013 15:41
I'm working on a multi-player RTS game as well (see: my signature), and RTS games use a technique known as lock-stepping.

Basically, you shouldn't be updating model positions/projectiles/effects every loop like you do in FPS or RPG games.

All you do in RTS games is transmit where each user has clicked on the screen at what time, and let the client handle the rest. You can get away with this because RTS games can easily have a latency of up to 500ms without players noticing lag.

I suggest you read this for more information: http://www.gamasutra.com/view/feature/3094/1500_archers_on_a_288_network_.php

TheComet

Gaia
12
Years of Service
User Offline
Joined: 9th Jul 2013
Location: Netherlands
Posted: 11th Jul 2013 15:55
Even though I will not be using that fully, you did give me a good (and very simple) idea that will make my program better. If simply the waypoint, and not the position would be send, then it has to send a whole lot less information indeed. On the other hand, that would mean that I would have to rewrite my program (which isn't a problem) and it has to send an extra message to tell what the content of the next message is I guess.
Though the question that is still on my mind is: if in the sync subroutine, the health stat of an object is send and recieved, and next checked if it is below 0, then why does only one of the 2 computers actually delete the object (in my code snippet)? It seems as if the healthstats aren't in sync at all. Though rewriting my program would solve this, I still wonder.
But thanks for your message anyway.
Gaia
12
Years of Service
User Offline
Joined: 9th Jul 2013
Location: Netherlands
Posted: 11th Jul 2013 16:02
And TheComet, very interesting page, and again that same idea as I just got, but thanks because it's probably going to help me.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 11th Jul 2013 16:10 Edited at: 11th Jul 2013 16:25
Lock-Steping is actually very similar to pathfinding. With Pathfinding the server only needs input based on when it is open to the client's needs at that specific time. Games like Second Life and Minecraft as well as WURM Online use pathfinding and it is very prominent in their engine. These are all using the FPS Style.

What this means is the client tells the server, ok I am on this trajectory, and until I tell you otherwise, it will constantly be heading that way. Well the server can do other things while it waits. Once it gets a key stroke or signal from the client, whether its moving the player, or no key is pressed to show movement, it then changes the trajectory or motion of the player on the server and re-sends this info to all clients that might be near by. Then the server continues on its way until another client sends info. This keeps the bandwidth down as well for both client and server. And with multithreading, servers and clients can be even more efficient. Also, if the server misses the signal about the client sending a key stroke, you can have the server do a catch buffer. If the buffer gets full, you would eliminate part of that buffer over time until it is empty again. But the server doesn't have to respond to everything in the buffer. It can choose to wait for another signal again from the client. Time stamping each stroke can come into play here. This way it empties out the buffer. Although, in reality, it may never be totally empty.

Keep in mind, this is all about illusion. There is always waste and always lag. It's how you code the client that can compensate for this.

Here is a video on how the algorithm of pathfinding works : http://www.youtube.com/watch?v=KNXfSOx4eEE

Pathfinding video for a RTS : http://www.youtube.com/watch?v=bkCLqPpopvE

Point of this is, that pathfinding is an algorithm that can be used in many many ways.

https://soundcloud.com/toraktu
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 11th Jul 2013 17:25 Edited at: 11th Jul 2013 17:29
I think you're getting pathfinding mixed up with interpolation.

https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

Pathfinding is what it means: Find a path from point A to point B.

FPS games don't use that, they use interpolation and a small buffer with old positions of players in order to guess where they will be, before they actually arrive. The server can then make corrections to clients who are guessing out of a certain tolerance.

RTS games never guess where the units will be (that would be disastrous). They only progress to the next loop when every connected player has the required amount of data, so there is no such thing as future guessing in RTS games.

Lock-stepping is an entirely different thing to path finding and interpolation. Lock-stepping is the technique used to synchronize multithreaded systems in such a way that each thread is as fast as the slowest. This is what RTS games do.

TheComet

JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 12th Jul 2013 00:16
Your right. I did have it backwards. Thanks for the clarification.

https://soundcloud.com/toraktu
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 12th Jul 2013 05:35
It's so called path prediction.

Login to post a reply

Server time is: 2026-07-07 02:39:57
Your offset time is: 2026-07-07 02:39:57