示例#1
0
文件: Actor.cs 项目: lujiawen/OpenRA
 public SyncHash(ISync trait)
 {
     Trait = trait; hashFunction = Sync.GetHashFunction(trait);
 }
示例#2
0
        static void InnerLogicTick(OrderManager orderManager)
        {
            var tick = RunTime;

            var world = orderManager.World;

            var uiTickDelta = tick - Ui.LastTickTime;

            if (uiTickDelta >= Timestep)
            {
                // Explained below for the world tick calculation
                var integralTickTimestep = (uiTickDelta / Timestep) * Timestep;
                Ui.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : Timestep;

                Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, Ui.Tick);
                Cursor.Tick();
            }

            var worldTimestep  = world == null ? Timestep : world.IsLoadingGameSave ? 1 : world.Timestep;
            var worldTickDelta = tick - orderManager.LastTickTime;

            if (worldTimestep != 0 && worldTickDelta >= worldTimestep)
            {
                using (new PerfSample("tick_time"))
                {
                    // Tick the world to advance the world time to match real time:
                    //    If dt < TickJankThreshold then we should try and catch up by repeatedly ticking
                    //    If dt >= TickJankThreshold then we should accept the jank and progress at the normal rate
                    // dt is rounded down to an integer tick count in order to preserve fractional tick components.
                    var integralTickTimestep = (worldTickDelta / worldTimestep) * worldTimestep;
                    orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep;

                    Sound.Tick();

                    if (world == null)
                    {
                        orderManager.TickPreGame();
                        return;
                    }

                    // Collect orders first, we will dispatch them if we can this frame
                    Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () =>
                    {
                        world.OrderGenerator.Tick(world);
                    });

                    if (orderManager.TryTick())
                    {
                        Log.Write("debug", "--Tick: {0} ({1})", LocalTick, orderManager.IsNetTick ? "net" : "local");

                        world.Tick();

                        PerfHistory.Tick();
                    }
                    else if (orderManager.NetFrameNumber == 0)
                    {
                        orderManager.LastTickTime = RunTime;
                    }

                    // Wait until we have done our first world Tick before TickRendering
                    if (orderManager.LocalFrameNumber > 0)
                    {
                        Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () => world.TickRender(worldRenderer));
                    }
                }

                if (benchmark != null)
                {
                    benchmark.Tick(LocalTick);
                }
            }
        }
示例#3
0
 public void OnMouseInput(MouseInput input)
 {
     Sync.RunUnsynced(world, () => Ui.HandleInput(input));
 }
示例#4
0
文件: Game.cs 项目: zidonuke/OpenRA
        static void InnerLogicTick(OrderManager orderManager)
        {
            var tick = RunTime;

            var world = orderManager.World;

            var uiTickDelta = tick - Ui.LastTickTime;

            if (uiTickDelta >= Timestep)
            {
                // Explained below for the world tick calculation
                var integralTickTimestep = (uiTickDelta / Timestep) * Timestep;
                Ui.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : Timestep;

                Viewport.TicksSinceLastMove += uiTickDelta / Timestep;

                Sync.CheckSyncUnchanged(world, Ui.Tick);
                Cursor.Tick();
            }

            var worldTimestep  = world == null ? Timestep : world.Timestep;
            var worldTickDelta = tick - orderManager.LastTickTime;

            if (worldTimestep != 0 && worldTickDelta >= worldTimestep)
            {
                using (new PerfSample("tick_time"))
                {
                    // Tick the world to advance the world time to match real time:
                    //    If dt < TickJankThreshold then we should try and catch up by repeatedly ticking
                    //    If dt >= TickJankThreshold then we should accept the jank and progress at the normal rate
                    // dt is rounded down to an integer tick count in order to preserve fractional tick components.
                    var integralTickTimestep = (worldTickDelta / worldTimestep) * worldTimestep;
                    orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep;

                    Sound.Tick();
                    Sync.CheckSyncUnchanged(world, orderManager.TickImmediate);

                    if (world == null)
                    {
                        return;
                    }

                    // Don't tick when the shellmap is disabled
                    if (world.ShouldTick)
                    {
                        var isNetTick = LocalTick % NetTickScale == 0;

                        if (!isNetTick || orderManager.IsReadyForNextFrame)
                        {
                            ++orderManager.LocalFrameNumber;

                            Log.Write("debug", "--Tick: {0} ({1})", LocalTick, isNetTick ? "net" : "local");

                            if (BenchmarkMode)
                            {
                                Log.Write("cpu", "{0};{1}".F(LocalTick, PerfHistory.Items["tick_time"].LastValue));
                            }

                            if (isNetTick)
                            {
                                orderManager.Tick();
                            }

                            Sync.CheckSyncUnchanged(world, () =>
                            {
                                world.OrderGenerator.Tick(world);
                                world.Selection.Tick(world);
                            });

                            world.Tick();

                            PerfHistory.Tick();
                        }
                        else if (orderManager.NetFrameNumber == 0)
                        {
                            orderManager.LastTickTime = RunTime;
                        }

                        Sync.CheckSyncUnchanged(world, () => world.TickRender(worldRenderer));
                    }
                    else
                    {
                        PerfHistory.Tick();
                    }
                }
            }
        }
示例#5
0
 public void OnKeyInput(KeyInput input)
 {
     Sync.RunUnsynced(world, () => Ui.HandleKeyPress(input));
 }
示例#6
0
 public void OnTextInput(string text)
 {
     Sync.RunUnsynced(world, () => Ui.HandleTextInput(text));
 }
示例#7
0
 public void OnKeyInput(KeyInput input)
 {
     Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleKeyPress(input));
 }
示例#8
0
 public void OnMouseInput(MouseInput input)
 {
     Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleInput(input));
 }
示例#9
0
 public void OnMouseInput(MouseInput input)
 {
     Sync.CheckSyncUnchanged(world, () => Ui.HandleInput(input));
 }
示例#10
0
 public void OnTextInput(string text)
 {
     Sync.CheckSyncUnchanged(world, () => Ui.HandleTextInput(text));
 }
示例#11
0
 public void OnKeyInput(KeyInput input)
 {
     Sync.CheckSyncUnchanged(world, () => Ui.HandleKeyPress(input));
 }
示例#12
0
        static void InnerLogicTick(OrderManager orderManager)
        {
            var tick = RunTime;

            var world = orderManager.World;

            var uiTickDelta = tick - Ui.LastTickTime;

            if (uiTickDelta >= Ui.Timestep)
            {
                // Explained below for the world tick calculation
                var integralTickTimestep = (uiTickDelta / Ui.Timestep) * Ui.Timestep;
                Ui.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : Ui.Timestep;

                Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, Ui.Tick);
                Cursor.Tick();
            }

            var worldTimestep = world == null ? Ui.Timestep :
                                world.IsLoadingGameSave ? 1 :
                                world.IsReplay ? world.ReplayTimestep :
                                world.Timestep;

            var worldTickDelta = tick - orderManager.LastTickTime;

            if (worldTimestep != 0 && worldTickDelta >= worldTimestep)
            {
                using (new PerfSample("tick_time"))
                {
                    // Tick the world to advance the world time to match real time:
                    //    If dt < TickJankThreshold then we should try and catch up by repeatedly ticking
                    //    If dt >= TickJankThreshold then we should accept the jank and progress at the normal rate
                    // dt is rounded down to an integer tick count in order to preserve fractional tick components.
                    var integralTickTimestep = (worldTickDelta / worldTimestep) * worldTimestep;
                    orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep;

                    Sound.Tick();
                    Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, orderManager.TickImmediate);

                    if (world == null)
                    {
                        return;
                    }

                    var isNetTick = LocalTick % NetTickScale == 0;

                    if (!isNetTick || orderManager.IsReadyForNextFrame)
                    {
                        ++orderManager.LocalFrameNumber;

                        if (isNetTick)
                        {
                            orderManager.Tick();
                        }

                        Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () =>
                        {
                            world.OrderGenerator.Tick(world);
                        });

                        world.Tick();

                        PerfHistory.Tick();
                    }
                    else if (orderManager.NetFrameNumber == 0)
                    {
                        orderManager.LastTickTime = RunTime;
                    }

                    // Wait until we have done our first world Tick before TickRendering
                    if (orderManager.LocalFrameNumber > 0)
                    {
                        Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () => world.TickRender(worldRenderer));
                    }
                }

                benchmark?.Tick(LocalTick);
            }
        }
示例#13
0
 public void OnTextInput(string text)
 {
     Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleTextInput(text));
 }