コード例 #1
0
        public void Update(float deltaTime)
        {
            // Receive all network input
            // TODO: This needs to be limited.
            while (networkClient.ReceiveOne())
            {
            }

            if (Connected)
            {
                Context.Render();
                Context.Simulate();
                Context.Send();
            }
        }
コード例 #2
0
        public override void Start()
        {
            log.Info("Starting server on *:{0}", ServerConfiguration.Port);

            // Start server listener
            NetworkServer.Listen();

            // Start time manager
            Context.Time.Start();

            // Start the event timer
            startTimer();

            // Setup event array
            AutoResetEvent[] resetEvents = new AutoResetEvent[2];
            resetEvents[0] = timerEvent;
            resetEvents[1] = NetworkPeer.MessageReceivedEvent;

            // Send buffer timer
            long lastSendTime  = 0;
            long sendBuffering = Math.Min(ServerConfiguration.SendBuffering, ServerConfiguration.SimulationAccuracy / 2L);

            while (true)
            {
                // Wait for any event
                switch (WaitHandle.WaitAny(resetEvents))
                {
                case 0:

                    Context.Time.Update();
                    Context.Scheduler.RunExpired();

                    goto case 1;

                case 1:

                    // Reset send time
                    lastSendTime = Context.Time.ElapsedMilliseconds;

                    // Try fixed update
                    Context.Simulate();

                    // Receive client input
                    while (NetworkServer.ReceiveOne())
                    {
                        // Try fixed update
                        Context.Simulate();

                        // Check if we should send
                        if (Context.Time.ElapsedMilliseconds - lastSendTime > sendBuffering)
                        {
                            if (Context.Send())
                            {
                                lastSendTime = Context.Time.ElapsedMilliseconds;
                            }
                        }
                    }

                    // Send data
                    Context.Send();
                    break;
                }
            }
        }