/// <summary> /// Initializes & executes the server runtime loop /// </summary> public void Go() { float MAX_UPDATE = 1.0f / 60.0f; Mogre.Timer frameTimer = new Timer(); frameTimer.Reset(); SafeTimer timer = new SafeTimer(); while (true) { System.Threading.Thread.Sleep(10); eventMgr.Update(); IPAddress ip = null; while ((ip = netServer.GetDisconnectedIP()) != null) { netServer.RemovePlayer(ip); } if (netServer.NumPlayers == 0) break; //world update float diff = (float)timer.Diff / 1000.0f; while (diff > MAX_UPDATE) { this.world.update(MAX_UPDATE); diff -= MAX_UPDATE; } if (diff > 0) { this.world.update(diff); } frameTimer.Reset(); mode.ProcessState(); serverShipMgr.sendShipStateStatus(); } }
/// <summary> /// execute the render loop, which /// is actually pretty simple at this point /// </summary> public void Go() { frameTimer.Reset(); float frameTime; uint frameTimeMod50 = 0; SafeTimer timer = new SafeTimer(); Console.Out.WriteLine(timer.Diff / 1000.0f); float MAX_UPDATE = 1.0f / 60.0f; //float MAX_SPEED = 30.0f; // RenderOneFrame returns false when we Ogre // is done. Alternatively, we can not have // the loop and merely call root.StartRendering while (true) { frameTime = frameTimer.Milliseconds / 1000.0f; //update input inputMgr.PollInputs(); if (input.IsDown(Key.Escape)) { break; } // grab events GrabEvents((uint)timer.Time, null); // grab a ship, if there are any ICollection <ClientShip> ships = shipMgr.Ships; if (ships.Count > 0) { IEnumerator <ClientShip> e = ships.GetEnumerator(); e.MoveNext(); if (input.IsPressed(Key.Return)) { Util.Log("Current State:" + e.Current.SceneNode.Position); } } frameTimeMod50 += frameTimer.Milliseconds; frameTimer.Reset(); if (frameTimeMod50 > 50) { eventMgr.Update(); frameTimeMod50 -= 50; } //world update float diff = (float)timer.Diff / 1000.0f; while (diff > MAX_UPDATE) { this.world.update(MAX_UPDATE); diff -= MAX_UPDATE; } if (diff > 0) { this.world.update(diff); } // score update TextRenderer.UpdateTextBox("frameCtr", "FPS: " + (int)(1 / (frameTime))); shipCam.Update(); if (!root.RenderOneFrame()) { break; } } }
/// <summary> /// execute the render loop, which /// is actually pretty simple at this point /// </summary> public void Go() { frameTimer.Reset(); float frameTime; uint frameTimeMod50 = 0; SafeTimer timer = new SafeTimer(); Console.Out.WriteLine(timer.Diff/1000.0f); float MAX_UPDATE = 1.0f / 60.0f; //float MAX_SPEED = 30.0f; // RenderOneFrame returns false when we Ogre // is done. Alternatively, we can not have // the loop and merely call root.StartRendering while (true) { frameTime = frameTimer.Milliseconds / 1000.0f; //update input inputMgr.PollInputs(); if (input.IsDown(Key.Escape)) break; // grab events GrabEvents((uint)timer.Time, null); // grab a ship, if there are any ICollection<ClientShip> ships = shipMgr.Ships; if (ships.Count > 0) { IEnumerator<ClientShip> e = ships.GetEnumerator(); e.MoveNext(); if (input.IsPressed(Key.Return)) Util.Log("Current State:" + e.Current.SceneNode.Position); } frameTimeMod50 += frameTimer.Milliseconds; frameTimer.Reset(); if (frameTimeMod50 > 50) { eventMgr.Update(); frameTimeMod50 -= 50; } //world update float diff = (float)timer.Diff / 1000.0f ; while (diff > MAX_UPDATE) { this.world.update(MAX_UPDATE); diff -= MAX_UPDATE; } if (diff > 0) { this.world.update(diff); } // score update TextRenderer.UpdateTextBox("frameCtr","FPS: " +(int)(1 / (frameTime)) ); shipCam.Update(); if (!root.RenderOneFrame()) break; } }