Esempio n. 1
0
        /// <summary>
        /// All Components used by this GameState should be Added in the GameState here
        /// This will be called in a multithreaded way !
        /// </summary>
        public virtual void Initialize(DeviceContext context)
        {
            //Call the Initialized from each Registered component, if needed !
            //Will be thread dispatched !
            List <Task> _startedTask = new List <Task>();

            GameComponents.ForEach(gc =>
            {
                if (gc.IsInitialized == false)
                {
                    //Start the Initialize()
                    _startedTask.Add(ThreadsManager.RunAsync(gc.Initialize));
                }
            });

            Task.WaitAll(_startedTask.ToArray());

            //Call the LoadContents from each Registered component, if needed !
            //!! Those methods are not Thread Safe !! => cannot thread dispatch them, can only run once at a time in this thread context
            foreach (var gc in GameComponents.Where(x => x.IsDefferedLoadContent))
            {
                if (gc.IsInitialized == false)
                {
                    gc.LoadContent(context);
                    gc.IsInitialized = true;
                }
            }

            IsDirty = false;
        }