Schedule Reliability and Server Simulation

edited April 2010 in Photon Server
Hello,

I have been experimenting with Photon for about one week with the free license (Yay! :D)
I have used the LiteLobby as a sample of how to program the server taking Lite as a base, and have created a somewhat equivalent of a GameInstanceRoom.

Since I am making an authoritative server, I am creating a small simulation for object positioning and manipulation in the server code,simple things (hopefully) like ball movement and such. The client, which is in Unity3D, only asks for Updates in this simulation, and makes requests for movement at the press of a button. He only asks for permission, he does not send any other type of data, when the server grants its permission, the object will start to move in the simulator, and the client will receive that feedback via updating the Simulator. For this I am creating a "Schedule", using RoomMessages that runs every 100 milliseconds, and publishes an unreliable event to all actors (for each room there is a maximum of 6 players for now) to send all the current game data.

So, my questions are:

1. How reliable is Schedule? How precise it is? Would be a good idea to actually create some sort of "DeltaTime", so I can handle my simulation without any dependence to the Schedule precision? Should I use another method?

2. How logical is the idea to create a simulation to each instance created, which handles all the current game status, and sends to all the player every 100 milliseconds? I can not find any "lighter" solution, without giving the client any info that can be hacked. (I believe that I should not give any info to the client, since he/she can just hack it and ruin the game experience). Does it make any sense?

PD: Oh I have an extra question.. how can I handle the timeout of the server? Ive noticed that If i "disconnect" on purpose the client (by not issuing a Disconnect() function, like closing unexpectedly the app for example",the timeout response in order to "eliminate and disconnect, therefore eliminating the GameinstanceRoom" that player can be very long. Where I can find that information or how can I modify that? Or how can I detect that disconnection cannot be recovered?

Thanks a lot,
Italo F. Capasso B.
AKA "Edwood Grant"

Comments

  • BorisBoris ✭✭
    Hi,

    1) The Schedule and ScheduleOnInterval methods use the System.Threading.Timer; the precision is usually about 10-20ms.
    If you need a greater precision you would have to use your own timers such as the windows multimedia timer defined in the winmm.dll.
    But if you do this make sure to use the enqueue method when the timer elapses or you will have threading issues with your game.
    Callbacks of the existing schedule method are already executed in the right thread.
    Well, because of other tasks blocking the game thread your callbacks might always be a bit off until they are executed... you can try to work against such issues and use the System.Diagonostics.Stopwatch for measurement and modify the next schedule call accordingly.

    2) It sounds like every game needs to have its own simulation state anyway... what problems do you anticipate in having one simulation per game instance?

    3) [Disconnect] in short: you can't. Photon thinks there is a connection problem and disconnects after all resend tries have failed.
    We might add the possibility to configure a resend timeout in the future, but right now it has low priority for us.
    To work around this issue you could add your own timers and expect your client to call a certain operation every few seconds. If this operations does not arrive in time you know the client is probably disconnected and you can remove him from the game.

    Boris
  • Thanks a lot for your answers, the helped a lot,

    I am more of a newbie in all of this network systems, and my head keeps spinning whenever I try to understand whats going on, but at least I have a simple bouncing ball simulated from the server, sent every 100 ms to its players. It is local, though.. I don't know how it will work with latency.. I suppose I have to find a way to predict locally the whole simulation...

    As for the second question, well I was only thinking of scalability... when I will have like 1000 game instance, each one with its own simulation, I wonder if that its not too heavy.. but as you say, in the end its impossible to handle something in the client and end up simulating the whole system remotely... and I guess this kind of systems are designed to be scalable in that way

    BTW I wanted to make one last question... Is there a way to simulate latency in photon? I am using Unity3D as a client. That would be extemely useful...

    Oh well, I'll keep working on it, specially how to make some kind of client prediction, thanks a lot..

    Italo F. Capasso B.
    AKA "Edwood Grant"
  • BorisBoris ✭✭
    Is there a way to simulate latency in photon? I am using Unity3D as a client. That would be extemely useful...
    Unfortunately not (yet) on the networking level.
    You could fake it by delaying whatever you send in your business logic, or delay the event dispatch on the client side, or just call service() less often (service() leads to EventAction(), calling service() less often will delay the event dispatch).
Sign In or Register to comment.