473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Timer issue

Hey guys

Here is what i want to do. I have made a multiplayer game that needs to when
more than one player is ready start a countdown that the clients can see,
so players can still join in this time frame and then after the time elapses
the game starts.

I am trying to do it lie this, my server controls all handling of the game
logic, deciding who wins, who is next to play etc. For all the players to
have their timers showing the same times i have created the timer on the
server and this time is then serialised as part of the game object that is
sent to the clients.

The idea being the clients receive that object and they will then continue
to be running the timer their end with it having started at the server
theoretically making the timers go in sync.

My problem is first of all that System.Timers objects cannot be serialised.

My second problem is i think this may be flawed, if it takes longer for data
to reach one client his timer will start slightly late etc.

Anyone have any ideas how i can do this so all players see the same timer??

Thanks
Apr 22 '06 #1
4 1669
Send a TimeSpan (say 30 seconds) to all clients. It is a duration in the
future so it will be relative to any timezone or system time. You can't get
it *exact, but a second or two should not be an issue. If a client comes
in late, then that is just the way the ball bounces. Start your timer on
the server after the last client message is sent so that should give
everyone at least 30 seconds (for example) to connect - the first clients
may wait a tiny bit longer, but that should be ok.

--
William Stacey [MVP]

"Daniel" <Da*****@vestryonline.com> wrote in message
news:ua**************@TK2MSFTNGP03.phx.gbl...
| Hey guys
|
| Here is what i want to do. I have made a multiplayer game that needs to
when
| more than one player is ready start a countdown that the clients can see,
| so players can still join in this time frame and then after the time
elapses
| the game starts.
|
| I am trying to do it lie this, my server controls all handling of the game
| logic, deciding who wins, who is next to play etc. For all the players to
| have their timers showing the same times i have created the timer on the
| server and this time is then serialised as part of the game object that is
| sent to the clients.
|
| The idea being the clients receive that object and they will then continue
| to be running the timer their end with it having started at the server
| theoretically making the timers go in sync.
|
| My problem is first of all that System.Timers objects cannot be
serialised.
|
| My second problem is i think this may be flawed, if it takes longer for
data
| to reach one client his timer will start slightly late etc.
|
| Anyone have any ideas how i can do this so all players see the same
timer??
|
| Thanks
|
|
Apr 22 '06 #2
Hi William,

Ok so step by step your saying:

1) instantiate timer on the server
2) send to each player currently ready (once i have more than 1) a time span
object
3) now start the servers timer
4) clients on receiving the timespan object start their timers
5) anyone new joins in this time they are sent the timespan as it stands on
the server at this stage (so maybe 20seconds left), they then start their
timers from there
6) when server hits 0 send the start game to all clients
Thats sounds like a good method, there is one more problem though. my game
can have 3 or 4 games upto 100 going at once. So each game needs its own
timer tracked independantly.

At first thought a TimerManager class springs to mind where i can have every
game running tracked via a unique id number and on a player joining a game i
check which game he/she has joined and return the time details from the
timemanager class for that game.

My only problem is from a design point of view this could get messy. It
would mean i would have to when i instantiate my games do something liek
this:

GameManager.CreateGame("Game1", 1);
TimerManager.Create(1);

where 1 is the unique id.

Ideally i would want the timermanager done inside the gamemanager class but
that class is serialised and sent to the client on connecting so they can
see all the available games. As a result i cant put the timer manager in
there as it would need to be serialisable and i cant serialise a timer.

Anyway round that? I dont want future coders to forget to create a
timermanager for each game, plus they would have to always stay in sync.

Look forward to your views.

"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:O5**************@TK2MSFTNGP03.phx.gbl...
Send a TimeSpan (say 30 seconds) to all clients. It is a duration in the
future so it will be relative to any timezone or system time. You can't
get
it *exact, but a second or two should not be an issue. If a client comes
in late, then that is just the way the ball bounces. Start your timer on
the server after the last client message is sent so that should give
everyone at least 30 seconds (for example) to connect - the first clients
may wait a tiny bit longer, but that should be ok.

--
William Stacey [MVP]

"Daniel" <Da*****@vestryonline.com> wrote in message
news:ua**************@TK2MSFTNGP03.phx.gbl...
| Hey guys
|
| Here is what i want to do. I have made a multiplayer game that needs to
when
| more than one player is ready start a countdown that the clients can
see,
| so players can still join in this time frame and then after the time
elapses
| the game starts.
|
| I am trying to do it lie this, my server controls all handling of the
game
| logic, deciding who wins, who is next to play etc. For all the players
to
| have their timers showing the same times i have created the timer on the
| server and this time is then serialised as part of the game object that
is
| sent to the clients.
|
| The idea being the clients receive that object and they will then
continue
| to be running the timer their end with it having started at the server
| theoretically making the timers go in sync.
|
| My problem is first of all that System.Timers objects cannot be
serialised.
|
| My second problem is i think this may be flawed, if it takes longer for
data
| to reach one client his timer will start slightly late etc.
|
| Anyone have any ideas how i can do this so all players see the same
timer??
|
| Thanks
|
|

Apr 22 '06 #3
sb
Synchronization is probably the most common concern in all MPOGs. One
approach is to measure & track the time it takes for a packet of data to
complete a round trip (server -> client -> server) for each connected
client. This value can be used by the server to determine when to send
packets to each client as well as when to completely disconnect them...ie
they are responding too slowly.

For example:
Client A has a round-trip time (RTT) of 100 ms or ~50ms one-way
Client B has a round-trip time (RTT) of 200 ms or ~100ms one-way
Client C has a round-trip time (RTT) of 500 ms or ~250ms one-way

Now let's say I have some data that each client needs to see at the same
time...such as a player shooting a bullet. Knowing the information above I
can do the following and be fairly confident that everyone will be in synch:
Send C the data packet...wait 150ms and send client B the data, wait
50ms more and send client A the data.
Of course, this method requires that you frequenty check the latency of
every client because connections vary over time....but this does get you
down to milliseconds in terms of accuracy. Depending on what your game does
and how much timing matters in it, you can take the above scenario and add
many more levels of complexity to measuring the latency more accurately.
Alas, this is just one way to do it that isn't too complicated.

-sb
"Daniel" <Da*****@vestryonline.com> wrote in message
news:ua**************@TK2MSFTNGP03.phx.gbl...
Hey guys

Here is what i want to do. I have made a multiplayer game that needs to
when more than one player is ready start a countdown that the clients can
see, so players can still join in this time frame and then after the time
elapses the game starts.

I am trying to do it lie this, my server controls all handling of the game
logic, deciding who wins, who is next to play etc. For all the players to
have their timers showing the same times i have created the timer on the
server and this time is then serialised as part of the game object that is
sent to the clients.

The idea being the clients receive that object and they will then continue
to be running the timer their end with it having started at the server
theoretically making the timers go in sync.

My problem is first of all that System.Timers objects cannot be
serialised.

My second problem is i think this may be flawed, if it takes longer for
data to reach one client his timer will start slightly late etc.

Anyone have any ideas how i can do this so all players see the same
timer??

Thanks

Apr 22 '06 #4
You can still put the timer logic in the Game class. Just mark the timer
var and [nonserialized] or what ever the attribute is as I can't remember.
If xml, private vars will not be serialized anyway, only public properties
with get and set.
1) Create the game.
2) First client starts the timer (for example)
3) Future clients get a timespan between now and future time.
4) If client get into the game before timer trigger, then good, otherwise
return failure to client.

It probably makes sense to keep the timer logic close to the client connect
logic, where ever that is. If in the game class, great place to put it.
hth

--
William Stacey [MVP]

"Daniel" <Da*****@vestryonline.com> wrote in message
news:uF**************@TK2MSFTNGP05.phx.gbl...
| Hi William,
|
| Ok so step by step your saying:
|
| 1) instantiate timer on the server
| 2) send to each player currently ready (once i have more than 1) a time
span
| object
| 3) now start the servers timer
| 4) clients on receiving the timespan object start their timers
| 5) anyone new joins in this time they are sent the timespan as it stands
on
| the server at this stage (so maybe 20seconds left), they then start their
| timers from there
| 6) when server hits 0 send the start game to all clients
|
|
| Thats sounds like a good method, there is one more problem though. my game
| can have 3 or 4 games upto 100 going at once. So each game needs its own
| timer tracked independantly.
|
| At first thought a TimerManager class springs to mind where i can have
every
| game running tracked via a unique id number and on a player joining a game
i
| check which game he/she has joined and return the time details from the
| timemanager class for that game.
|
| My only problem is from a design point of view this could get messy. It
| would mean i would have to when i instantiate my games do something liek
| this:
|
| GameManager.CreateGame("Game1", 1);
| TimerManager.Create(1);
|
| where 1 is the unique id.
|
| Ideally i would want the timermanager done inside the gamemanager class
but
| that class is serialised and sent to the client on connecting so they can
| see all the available games. As a result i cant put the timer manager in
| there as it would need to be serialisable and i cant serialise a timer.
|
| Anyway round that? I dont want future coders to forget to create a
| timermanager for each game, plus they would have to always stay in sync.
|
| Look forward to your views.
|
| "William Stacey [MVP]" <wi************@gmail.com> wrote in message
| news:O5**************@TK2MSFTNGP03.phx.gbl...
| > Send a TimeSpan (say 30 seconds) to all clients. It is a duration in
the
| > future so it will be relative to any timezone or system time. You can't
| > get
| > it *exact, but a second or two should not be an issue. If a client
comes
| > in late, then that is just the way the ball bounces. Start your timer
on
| > the server after the last client message is sent so that should give
| > everyone at least 30 seconds (for example) to connect - the first
clients
| > may wait a tiny bit longer, but that should be ok.
| >
| > --
| > William Stacey [MVP]
| >
| > "Daniel" <Da*****@vestryonline.com> wrote in message
| > news:ua**************@TK2MSFTNGP03.phx.gbl...
| > | Hey guys
| > |
| > | Here is what i want to do. I have made a multiplayer game that needs
to
| > when
| > | more than one player is ready start a countdown that the clients can
| > see,
| > | so players can still join in this time frame and then after the time
| > elapses
| > | the game starts.
| > |
| > | I am trying to do it lie this, my server controls all handling of the
| > game
| > | logic, deciding who wins, who is next to play etc. For all the players
| > to
| > | have their timers showing the same times i have created the timer on
the
| > | server and this time is then serialised as part of the game object
that
| > is
| > | sent to the clients.
| > |
| > | The idea being the clients receive that object and they will then
| > continue
| > | to be running the timer their end with it having started at the server
| > | theoretically making the timers go in sync.
| > |
| > | My problem is first of all that System.Timers objects cannot be
| > serialised.
| > |
| > | My second problem is i think this may be flawed, if it takes longer
for
| > data
| > | to reach one client his timer will start slightly late etc.
| > |
| > | Anyone have any ideas how i can do this so all players see the same
| > timer??
| > |
| > | Thanks
| > |
| > |
| >
| >
|
|
Apr 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
2
by: Benjamin | last post by:
Hi, I am having a problem enabling a timer in my class. I have attached some sample pseudo code (see "Sample code illustrating issue") so you can see what I am talking about. Whats the issue?...
5
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
10
by: igor | last post by:
I have recently discovered that the system.Timers.Timer from.Net Framework v1.1 is not reliable when used on Windows 2003 server. When incorporated into a Windows Service, the timer_elapsed event...
3
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I am trying to use the timer to make a login form show after a specified interval. However, if the interval is set to a value greater than 5000 nanosecond, then it does not respond. What could be...
8
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.