예제 #1
0
파일: Sync.cs 프로젝트: watsoncui/OpenRA
        public static T CheckSyncUnchanged <T>(World world, Func <T> fn)
        {
            if (world == null)
            {
                return(fn());
            }
            var  shouldCheckSync    = Game.Settings.Debug.SanityCheckUnsyncedCode;
            int  sync               = shouldCheckSync ? world.SyncHash() : 0;
            bool prevInUnsyncedCode = inUnsyncedCode;

            inUnsyncedCode = true;

            try
            {
                return(fn());
            }
            finally
            {
                inUnsyncedCode = prevInUnsyncedCode;
                if (shouldCheckSync && sync != world.SyncHash())
                {
                    throw new InvalidOperationException("CheckSyncUnchanged: sync-changing code may not run here");
                }
            }
        }
예제 #2
0
        public static T RunUnsynced <T>(bool checkSyncHash, World world, Func <T> fn)
        {
            // PERF: Detect sync changes in top level entry point only. Do not recalculate sync hash during reentry.
            if (inUnsyncedCode || world == null)
            {
                return(fn());
            }

            var sync = checkSyncHash ? world.SyncHash() : 0;

            inUnsyncedCode = true;

            // Running this inside a try with a finally statement means isUnsyncedCode is set to false again as soon as fn completes
            try
            {
                return(fn());
            }
            finally
            {
                inUnsyncedCode = false;

                // When the world is disposing all actors and effects have been removed
                // So do not check the hash for a disposing world since it definitively has changed
                if (checkSyncHash && !world.Disposing && sync != world.SyncHash())
                {
                    throw new InvalidOperationException("RunUnsynced: sync-changing code may not run here");
                }
            }
        }
예제 #3
0
파일: Sync.cs 프로젝트: reaperrr/OpenRA
        public static T RunUnsynced <T>(bool checkSyncHash, World world, Func <T> fn)
        {
            if (world == null)
            {
                return(fn());
            }

            var sync = checkSyncHash ? world.SyncHash() : 0;
            var prevInUnsyncedCode = inUnsyncedCode;

            inUnsyncedCode = true;

            try
            {
                return(fn());
            }
            finally
            {
                inUnsyncedCode = prevInUnsyncedCode;
                if (checkSyncHash && sync != world.SyncHash())
                {
                    throw new InvalidOperationException("RunUnsynced: sync-changing code may not run here");
                }
            }
        }
예제 #4
0
        public static T RunUnsynced <T>(bool checkSyncHash, World world, Func <T> fn)
        {
            // PERF: Detect sync changes in top level entry point only. Do not recalculate sync hash during reentry.
            if (inUnsyncedCode || world == null)
            {
                return(fn());
            }

            var sync = checkSyncHash ? world.SyncHash() : 0;

            inUnsyncedCode = true;

            try
            {
                return(fn());
            }
            finally
            {
                inUnsyncedCode = false;
                if (checkSyncHash && sync != world.SyncHash())
                {
                    throw new InvalidOperationException("RunUnsynced: sync-changing code may not run here");
                }
            }
        }