示例#1
0
        internal CCApplication(CCGame game, bool isFullScreen             = true, CCSize?mainWindowSizeInPixels = null,
                               CCDisplayOrientation supportedOrientations = CCDisplayOrientation.Default)
            : base(game)
        {
            GameTime = new CCGameTime();
            xnaGame  = game;

            Scheduler     = new CCScheduler();
            ActionManager = new CCActionManager();
            Scheduler.Schedule(ActionManager, CCSchedulePriority.System, false);

            priorGamePadState = new Dictionary <PlayerIndex, GamePadState>();
            gamePadConnection = new CCEventGamePadConnection();
            gamePadButton     = new CCEventGamePadButton();
            gamePadDPad       = new CCEventGamePadDPad();
            gamePadStick      = new CCEventGamePadStick();
            gamePadTrigger    = new CCEventGamePadTrigger();

            IGraphicsDeviceService service = (IGraphicsDeviceService)Game.Services.GetService(typeof(IGraphicsDeviceService));

            if (service == null)
            {
                service = new GraphicsDeviceManager(game);

                // if we still do not have a service after creating the GraphicsDeviceManager
                // we need to stop somewhere and issue a warning.
                if (Game.Services.GetService(typeof(IGraphicsDeviceService)) == null)
                {
                    Game.Services.AddService(typeof(IGraphicsDeviceService), service);
                }
            }

            xnaDeviceManager = (GraphicsDeviceManager)service;

            Content = game.Content;
            HandleMediaStateAutomatically = true;

            game.IsFixedTimeStep = true;

            TouchPanel.EnabledGestures = GestureType.Tap;

            game.Activated   += GameActivated;
            game.Deactivated += GameDeactivated;
            game.Exiting     += GameExiting;
            game.Window.OrientationChanged += OrientationChanged;

            game.Components.Add(this);

            gameWindows = new List <CCWindow>();

            InitializeMainWindow((mainWindowSizeInPixels.HasValue) ? mainWindowSizeInPixels.Value : CCSize.Zero,
                                 isFullScreen, supportedOrientations);
        }
示例#2
0
 public CCTimer(CCScheduler scheduler, ICCUpdatable target, Action <float> selector, float seconds,
                uint repeat, float delay)
 {
     this.Scheduler        = scheduler;
     this.target           = target;
     this.Selector         = selector;
     this.elapsed          = -1;
     this.OriginalInterval = seconds;
     this.Interval         = seconds;
     this.delay            = delay;
     this.useDelay         = delay > 0f;
     this.repeat           = repeat;
     this.runForever       = repeat == uint.MaxValue;
 }
示例#3
0
        public CCTimer(CCScheduler scheduler, ICCUpdatable target, Action<float> selector, float seconds,
                       uint repeat, float delay)
        {
			this.Scheduler = scheduler;
			this.target = target;
			this.Selector = selector;
			this.elapsed = -1;
			this.OriginalInterval = seconds;
			this.Interval = seconds;
			this.delay = delay;
			this.useDelay = delay > 0f;
			this.repeat = repeat;
			this.runForever = repeat == uint.MaxValue;
        }
        CCParticleSystemCache(CCScheduler scheduler)
        {
            Scheduler = scheduler;

            configs = new Dictionary <string, CCParticleSystemConfig>();

            ProcessingAction = new Action(
                () =>
            {
                while (true)
                {
                    AsyncStruct psConfig;

                    lock (asyncLoadedConfigs)
                    {
                        if (asyncLoadedConfigs.Count == 0)
                        {
                            Task = null;
                            return;
                        }
                        psConfig = asyncLoadedConfigs[0];
                        asyncLoadedConfigs.RemoveAt(0);
                    }

                    try
                    {
                        var config = AddParticleSystem(psConfig.FileName, psConfig.DirectoryName, true);
                        CCLog.Log("Loaded particle system: {0}", psConfig.FileName);
                        if (psConfig.OnLoad != null)
                        {
                            Scheduler.Schedule(
                                f => psConfig.OnLoad(config, psConfig.Action), this, 0, 0, 0, false
                                );
                        }
                    }
                    catch (Exception ex)
                    {
                        CCLog.Log("Failed to load particle system {0}", psConfig.FileName);
                        CCLog.Log(ex.ToString());
                    }
                }
            }
                );
        }
示例#5
0
        public static object RunAsync(CCScheduler scheduler, Action action, Action <object> taskCompleted = null)
        {
#if WINDOWS_PHONE
            var worker = new BackgroundWorker();

            worker.DoWork +=
                (sender, args) =>
            {
                action();
            };

            if (taskCompleted != null)
            {
                worker.RunWorkerCompleted +=
                    (sender, args) =>
                {
                    //var scheduler = CCApplication.SharedApplication.Scheduler;
                    scheduler.Schedule(f => taskCompleted(worker), taskSelector, 0, 0, 0, false);
                };
            }

            worker.RunWorkerAsync();

            return(worker);
#else
            var task = new Task(
                () =>
            {
                action();

                if (taskCompleted != null)
                {
                    scheduler.Schedule(f => taskCompleted(null), taskSelector, 0, 0, 0, false);
                }
            }
                );

            task.Start();

            return(task);
#endif
        }
示例#6
0
        public static object RunAsync(CCScheduler scheduler, Action action, Action<object> taskCompleted = null)
        {
#if WINDOWS_PHONE
            var worker = new BackgroundWorker();
            
            worker.DoWork +=
                (sender, args) =>
                {
                    action();
                };

            if (taskCompleted != null)
            {
                worker.RunWorkerCompleted +=
                    (sender, args) =>
                    {
                        //var scheduler = CCApplication.SharedApplication.Scheduler;
                        scheduler.Schedule (f => taskCompleted(worker), taskSelector, 0, 0, 0, false);
                    };
            }

            worker.RunWorkerAsync();

            return worker;
#else
            var task = new Task(
                () =>
                {
                    action();

                    if (taskCompleted != null)
                    {
                        scheduler.Schedule (f => taskCompleted(null), taskSelector, 0, 0, 0, false);
                    }
                }
                );
                    
            task.Start();

            return task;
#endif
        }
示例#7
0
        void Initialise()
        {
            if (viewInitialised)
            {
                return;
            }

            PlatformInitialise();

            ActionManager   = new CCActionManager();
            Director        = new CCDirector();
            EventDispatcher = new CCEventDispatcher(this);
            AudioEngine     = new CCAudioEngine();
            Scheduler       = new CCScheduler();

            // Latest instance of game view should be setting shared resources
            // Ideally, we should move towards removing these singletons altogetehr
            CCAudioEngine.SharedEngine  = AudioEngine;
            CCScheduler.SharedScheduler = Scheduler;

            Stats = new CCStats();

            InitialiseGraphicsDevice();

            InitialiseResourceCaches();

            InitialiseRunLoop();

            InitialiseInputHandling();

            Stats.Initialise();

            viewInitialised = true;

            currentViewInstance = new WeakReference(this);
        }
示例#8
0
 public CCTimer(CCScheduler scheduler, ICCUpdatable target, Action <float> selector, float seconds)
     : this(scheduler, target, selector, seconds, 0, 0)
 {
 }
示例#9
0
        CCTextureCache(CCScheduler scheduler)
        {
            Scheduler = scheduler;

            ProcessingAction = new Action(
                () =>
            {
                while (true)
                {
                    AsyncStruct image;

                    lock (asyncLoadedImages)
                    {
                        if (asyncLoadedImages.Count == 0)
                        {
                            Task = null;
                            return;
                        }
                        image = asyncLoadedImages[0];
                        asyncLoadedImages.RemoveAt(0);
                    }

                    try
                    {
                        var texture = AddImage(image.FileName);
                        CCLog.Log("Loaded texture: {0}", image.FileName);
                        if (image.Action != null)
                        {
                            scheduler.Schedule(
                                f => image.Action(texture), this, 0, 0, 0, false
                                );
                        }
                    }
                    catch (Exception ex)
                    {
                        CCLog.Log("Failed to load image {0}", image.FileName);
                        CCLog.Log(ex.ToString());
                    }
                }
            }
                );
            ProcessingDataAction = new Action(
                () =>
            {
                while (true)
                {
                    DataAsyncStruct imageData;

                    lock (dataAsyncLoadedImages)
                    {
                        if (dataAsyncLoadedImages.Count == 0)
                        {
                            Task = null;
                            return;
                        }
                        imageData = dataAsyncLoadedImages[0];
                        dataAsyncLoadedImages.RemoveAt(0);
                    }

                    try
                    {
                        var texture = AddImage(imageData.Data, imageData.AssetName, imageData.Format);
                        CCLog.Log("Loaded texture: {0}", imageData.AssetName);
                        if (imageData.Action != null)
                        {
                            scheduler.Schedule(
                                f => imageData.Action(texture), this, 0, 0, 0, false
                                );
                        }
                    }
                    catch (Exception ex)
                    {
                        CCLog.Log("Failed to load image {0}", imageData.AssetName);
                        CCLog.Log(ex.ToString());
                    }
                }
            }
                );
        }
示例#10
0
 public CCTimer(CCScheduler scheduler, ICCUpdatable target, Action<float> selector, float seconds)
     : this(scheduler, target, selector, seconds, 0, 0)
 {
 }
示例#11
0
        internal CCApplication(CCGame game, bool isFullScreen = true, CCSize? mainWindowSizeInPixels = null)
            : base(game)
        {
            GameTime = new CCGameTime();
            xnaGame = game;

            Scheduler = new CCScheduler();
            ActionManager = new CCActionManager();
            Scheduler.Schedule(ActionManager, CCSchedulePriority.System, false);

            priorGamePadState = new Dictionary<PlayerIndex, GamePadState>();
            gamePadConnection = new CCEventGamePadConnection();
            gamePadButton = new CCEventGamePadButton();
            gamePadDPad = new CCEventGamePadDPad();
            gamePadStick = new CCEventGamePadStick();
            gamePadTrigger = new CCEventGamePadTrigger();

            IGraphicsDeviceService service = (IGraphicsDeviceService)Game.Services.GetService(typeof(IGraphicsDeviceService));

            if (service == null)
            {
                service = new GraphicsDeviceManager(game);

                // if we still do not have a service after creating the GraphicsDeviceManager
                // we need to stop somewhere and issue a warning.
                if (Game.Services.GetService(typeof(IGraphicsDeviceService)) == null)
                {
                    Game.Services.AddService(typeof(IGraphicsDeviceService), service);
                }
            }

            xnaDeviceManager = (GraphicsDeviceManager)service;

            Content = game.Content;
            HandleMediaStateAutomatically = true;

            game.IsFixedTimeStep = true;

            TouchPanel.EnabledGestures = GestureType.Tap;

            game.Activated += GameActivated;
            game.Deactivated += GameDeactivated;
            game.Exiting += GameExiting;
            game.Window.OrientationChanged += OrientationChanged;

            game.Components.Add(this);

            gameWindows = new List<CCWindow>();

            // Setting up the window correctly requires knowledge of the phone app page which needs to be set first
            #if !WINDOWS_PHONE
            InitializeMainWindow((mainWindowSizeInPixels.HasValue) ? mainWindowSizeInPixels.Value : new CCSize(800,480), isFullScreen);
            #endif
        }
示例#12
0
		CCApplication(CCGame game, bool isFullScreen = true, CCSize? mainWindowSizeInPixels = null,
			CCDisplayOrientation supportedOrientations = CCDisplayOrientation.Default)
			: base(game)
		{
			GameTime = new CCGameTime();
			xnaGame = game;

			Scheduler = new CCScheduler();
			ActionManager = new CCActionManager();
			Scheduler.Schedule(ActionManager, CCSchedulePriority.System, false);

			priorGamePadState = new Dictionary<PlayerIndex, GamePadState>();
			gamePadConnection = new CCEventGamePadConnection();
			gamePadButton = new CCEventGamePadButton();
			gamePadDPad = new CCEventGamePadDPad();
			gamePadStick = new CCEventGamePadStick();
			gamePadTrigger = new CCEventGamePadTrigger();

			IGraphicsDeviceService service = (IGraphicsDeviceService)Game.Services.GetService(typeof(IGraphicsDeviceService));

			if (service == null)
			{
				service = new GraphicsDeviceManager(game);

				// if we still do not have a service after creating the GraphicsDeviceManager
				// we need to stop somewhere and issue a warning.
				if (Game.Services.GetService(typeof(IGraphicsDeviceService)) == null)
				{
					Game.Services.AddService(typeof(IGraphicsDeviceService), service);
				}
			}

			xnaDeviceManager = (GraphicsDeviceManager)service;

			Content = game.Content;
			HandleMediaStateAutomatically = true;

			game.IsFixedTimeStep = true;

			TouchPanel.EnabledGestures = GestureType.Tap;

			game.Activated += GameActivated;
			game.Deactivated += GameDeactivated;
			game.Exiting += GameExiting;
			game.Window.OrientationChanged += OrientationChanged;

			game.Components.Add(this);

			gameWindows = new List<CCWindow>();

			InitializeMainWindow((mainWindowSizeInPixels.HasValue) ? mainWindowSizeInPixels.Value : CCSize.Zero,
				isFullScreen, supportedOrientations);
		}
示例#13
0
		CCParticleSystemCache(CCScheduler scheduler)
		{
			Scheduler = scheduler;

			configs = new Dictionary<string, CCParticleSystemConfig>();

			ProcessingAction = new Action(
				() =>
				{
					while (true)
					{
						AsyncStruct psConfig;

						lock (asyncLoadedConfigs)
						{
							if (asyncLoadedConfigs.Count == 0)
							{
								Task = null;
								return;
							}
							psConfig = asyncLoadedConfigs[0];
							asyncLoadedConfigs.RemoveAt(0);
						}

						try
						{
							var config = AddParticleSystem(psConfig.FileName, psConfig.DirectoryName, true);
							CCLog.Log("Loaded particle system: {0}", psConfig.FileName);
							if (psConfig.OnLoad != null)
							{
								Scheduler.Schedule(
									f => psConfig.OnLoad(config, psConfig.Action), this, 0, 0, 0, false
								);
							}
						}
						catch (Exception ex)
						{
							CCLog.Log("Failed to load particle system {0}", psConfig.FileName);
							CCLog.Log(ex.ToString());
						}
					}
				}
			);
		}