public ParallelInvoker(Game game, ParallelInvokerTarget <T> function, bool multiThreaded)
        {
            Function = function;

            if (multiThreaded)
            {
#if XBOX
                // ThreadPoolComponent always uses 3 threads on XBox 360.
                ThreadCount = 3;
#else
                // Try to pick a good number of threads based on the current CPU count.
                // Too many and we'll get bogged down in scheduling overhead. Too few and we won't benefit from parallelism.
                ThreadCount = Math.Max(2, Math.Min(8, Environment.ProcessorCount));
#endif
            }
            else
            {
                ThreadCount = 1;
            }

            UserData = new T();

            Delegates = new InvokerFunction[ThreadCount];
            for (int i = 0; i < ThreadCount; i++)
            {
                int j = i;
                Delegates[i] =
                    () => InvokeInternal(j);
            }

#if XBOX
            Signals = new AutoResetEvent[ThreadCount];
            for (int i = 0; i < ThreadCount; i++)
            {
                Signals[i] = new AutoResetEvent(false);
            }

            foreach (var component in game.Components)
            {
                ThreadPool = component as ThreadPoolComponent;
                if (ThreadPool != null)
                {
                    break;
                }
            }

            if (ThreadPool == null)
            {
                throw new InvalidOperationException("You must have a ThreadPoolComponent to use a ParallelInvoker");
            }
#endif
        }
Ejemplo n.º 2
0
    public XnaGame()
    {
        Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

        Instance              = this;
        _graphics             = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";

        IsFixedTimeStep = true;
        IsMouseVisible  = false;

        #if WINDOWS
        _graphics.PreferredBackBufferWidth  = 960;
        _graphics.PreferredBackBufferHeight = 640;

        _mousepointer = true;
        #elif XBOX360
        _graphics.PreferredBackBufferWidth  = 1280;
        _graphics.PreferredBackBufferHeight = 720;

        _mousepointer = true;
        #elif WINDOWS_PHONE
        _graphics.PreferredBackBufferFormat = SurfaceFormat.Color;
        _mousepointer = false;
        #endif

        //Make 30 FPS or put a key limiter on KeyDown!
        TargetElapsedTime = TimeSpan.FromSeconds(1 / 60.0f);

        StorageManager = new StorageManager("EndingXNA");
        StorageManager.ShowStorageGuide();
        StorageManager.StorageDeviceAction += (sender, e) => {
            if (e.DialogAction == DialogAction.Select)
            {
                Game.LoadFromUserStorage(e.StorageContainer);
            }
        };


        FlashRenderer = new FlashRenderer();

        //Post processing effects for bloom, fisheye and scanlines...
        PostProcess = new PostProcess(this, null);
        #if WINDOWS || XBOX360
        PostProcess.AddProcessor(new BloomProcessor(this)
        {
            Active = true, Settings = BloomProcessor.BloomSettings.PresetSettings[7]
        });
        PostProcess.AddProcessor(new BarrelDistortionProcessor(this)
        {
            Active = false
        });
        PostProcess.AddProcessor(new ScanlinesProcessor(this)
        {
            Active = false, ScanlinesValue = 0.25f
        });

        Components.Add(new GamerServicesComponent(this));
        Components.Add(ThreadPoolComponent = new ThreadPoolComponent(this));
        #endif
    }