static void RunServer() { try { TimeStat timeAll = new TimeStat(); LockTimer perfUpdateTimer = new LockTimer(60 * 1000); perfUpdateTimer.Trigger(); while (true) { timeAll.Start(); GameTime.Update(); OnTick?.Invoke(); GameTime.Update(); GUCTimer.Update(GameTime.Ticks); // move to new thread? //Run the dispatcher GUCDispatcher.Execute(); GameTime.Update(); GameServer.Update(); //process received packets GameTime.Update(); WorldObjects.World.ForEach(w => w.OnTick(GameTime.Ticks)); long elapsed = timeAll.Stop(); if (perfUpdateTimer.IsReady) { Logger.Log("Performance: {0:0}ms avg, {1:0}ms max. RAM: {2:0.0}MB", timeAll.Average, timeAll.Maximum, Process.GetCurrentProcess().PrivateMemorySize64 / 1000000d); timeAll.Reset(); } long diff = (updateRate - elapsed) / TimeSpan.TicksPerMillisecond; if (diff > 0) { Thread.Sleep((int)diff); } } } catch (Exception e) { Logger.LogError(e.Source + "<br>" + e.Message + "<br>" + e.StackTrace); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { LockTimer.RefreshTiles(); if (!ApplicationData.Current.LocalSettings.Values.ContainsKey(Init)) { BadgeGlyphTypes.Attention.GetBadge().Set(); ApplicationData.Current.LocalSettings.Values[Init] = true; } Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); // Set the default language rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); }
public void Lock() { LockTimer.Dispose(); }