Exemple #1
0
        protected override void Render()
        {
            Display.context.ClearDepthStencilView(Display.depthStencil, DepthStencilClearFlags.Depth, 1.0f, 0);
            Display.context.ClearRenderTargetView(Display.renderTarget, Color.Black);

            DebugPerfMonitor.BeginMark(0, "Render", Color.Blue);
            ScreenManager.Draw();
            DebugPerfMonitor.EndMark(0, "Render");


            GameConsole.Draw();
            DebugPerfMonitor.Draw(new Vector2(50, Display.Height - 100), Display.Width - 100);

            ScreenshotManager.Render();
        }
Exemple #2
0
        void UpdateThread()
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();
            double accumulatedTime = 0, lastTime = 0;

            while (Global.IsRunning)
            {
                double time = timer.Elapsed.TotalSeconds;
                accumulatedTime += (time - lastTime);
                lastTime         = time;

                const double frameTime = 0.10; // frames per second
                while (accumulatedTime > frameTime)
                {
                    accumulatedTime -= frameTime;
                    //world.Step((float)frameTime);

                    lock (Display.device) {
                        BackgroundGame.GameTick++;

                        DebugPerfMonitor.BeginMark(0, "Update", Color.White);

                        /*NetOutgoingMessage om = Main.network.CreateMessage(NetworkDataType.SyncUpdate);
                         * om.Write((Int32)(BackgroundGame.GameTick + 2));
                         * om.Write((Int32)1);
                         * foreach (byte[] order in BackgroundGame.OrderListToSend) {
                         *  byte[] data = order;
                         *  om.Write((byte)data.Length);
                         *  om.Write(data);
                         * }
                         * Main.network.SendSyncMessage(om);*/

                        foreach (byte[] o in BackgroundGame.OrderListToSend)
                        {
                            Order.DecodeAndExecute(0, o, 0, o.Length);
                        }
                        BackgroundGame.OrderListToSend.Clear();

                        for (int i = BackgroundGame.IntObjs.Count - 1; i >= 0; i--)
                        {
                            BackgroundGame.IntObjs[i].Update();
                        }
                        for (int i = BackgroundGame.IntObjs.Count - 1; i >= 0; i--)
                        {
                            BackgroundGame.IntObjs[i].Prepare();
                        }

                        DebugPerfMonitor.EndMark(0, "Update");

                        BackgroundGame.TimeInterpolateDelta = timer.Elapsed.TotalSeconds - BackgroundGame.TimeInterpolateLast;
                        BackgroundGame.TimeInterpolateLast  = timer.Elapsed.TotalSeconds;
                        ForegroundGame.timer.Restart();
                    }
                }
            }


            /*//if (float.IsNaN(minGameSpeed) || minGameSpeed < 100) minGameSpeed = 100;
             * if (BackgroundGame.GameTick > BackgroundGame.GameTick_Last) continue;
             * if (BackgroundGame.updateTimer.ElapsedMilliseconds < BackgroundGame.timeMax) continue;
             *
             * BackgroundGame.updateTimer.Restart();
             *
             * //BackgroundGame.timeMax = (int)BackgroundGame.updateTimer.ElapsedMilliseconds;
             * ForegroundGame.timeInterpolateFull = ForegroundGame.timeInterpolate+1;
             * ForegroundGame.timeInterpolate = 0;
             *
             * lock (Global.device) {
             *  BackgroundGame.GameTick++;
             *
             *  SyncBucket timeBucket;
             *  if (Main.network.ticks.TryGetValue(BackgroundGame.GameTick, out timeBucket)) {
             *      foreach (SyncData sdata in timeBucket.rawdata) {
             *          int i = 0;
             *          int length;
             *          byte[] rdata = sdata.data;
             *          while (i < rdata.Length) {
             *              length = (int)rdata[i++];
             *              Order.DecodeAndExecute(sdata.playerId, rdata, i, length);
             *              i += length;
             *              if (length == 0) break;
             *          }
             *      }
             *  }
             *
             *  NetOutgoingMessage om = Main.network.CreateMessage(NetworkDataType.SyncUpdate);
             *  om.Write((Int32)(BackgroundGame.GameTick + 2));
             *  om.Write((Int32)1);
             *  foreach (byte[] order in BackgroundGame.OrderList) {
             *      byte[] data = order;
             *      om.Write((byte)data.Length);
             *      om.Write(data);
             *  }
             *  Main.network.SendSyncMessage(om);
             *  BackgroundGame.OrderList.Clear();
             *
             *  DebugPerfMonitor.BeginMark(1, "Update", Color.White);
             *
             *  BackgroundGame.Map_Space.Update();
             *
             *  DebugPerfMonitor.BeginMark(1, "Interactive Objects Update", Color.Orange);
             *  for (int i = BackgroundGame.IObjs.Count - 1; i >= 0; i--) BackgroundGame.IObjs[i].Update();
             *  DebugPerfMonitor.EndMark(1, "Interactive Objects Update");
             *
             *  DebugPerfMonitor.BeginMark(1, "Intel Update", Color.Blue);
             *  BackgroundGame.intelManager.Update();
             *  DebugPerfMonitor.EndMark(1, "Intel Update");
             *
             *  DebugPerfMonitor.BeginMark(1, "Resources Update", Color.Green);
             *  for (int i = BackgroundGame.ResObjs.Count - 1; i >= 0; i--) BackgroundGame.ResObjs[i].Update();
             *  DebugPerfMonitor.EndMark(1, "Resources Update");
             *
             *  DebugPerfMonitor.BeginMark(1, "Projectiles Update", Color.Red);
             *  for (int i = BackgroundGame.Projectiles.Count - 1; i >= 0; i--) {
             *      if (BackgroundGame.Projectiles[i].Update()) BackgroundGame.Projectiles.RemoveAt(i);
             *  }
             *  DebugPerfMonitor.EndMark(1, "Projectiles Update");
             *
             *  if (BackgroundGame.async_IObjs.Count != 0) {
             *      for (int i = BackgroundGame.async_IObjs.Count; i > 0; i--) {
             *          InteractiveObject obj = BackgroundGame.async_IObjs.Pop();
             *          if (obj == null) continue;
             *          if (!obj.Initialized)
             *              BackgroundGame.IObjs.Remove(obj);
             *          else
             *              BackgroundGame.IObjs.Add(obj);
             *      }
             *  }
             *
             *  DebugPerfMonitor.EndMark(1, "Update");
             * }
             *
             * BackgroundGame.GameSpeed = BackgroundGame.GameSpeed_To; // Change it next turn
             */
        }