コード例 #1
0
        private RendererUpdateQueue EndOperation()
        {
            RendererUpdateQueue returnValue = currentUpdateQueue;

            currentUpdateQueue = null;
            return(returnValue);
        }
コード例 #2
0
ファイル: Renderer.cs プロジェクト: cfo82/Magmageddon
 public void AddUpdateQueue(RendererUpdateQueue updateQueue)
 {
     lock (updateQueues)
     {
         updateQueues.Add(updateQueue);
     }
 }
コード例 #3
0
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
#if !DEBUG
            try
            {
#endif
#if !XBOX
            Debug.Assert(
                simulationThread.Thread.ThreadState == System.Threading.ThreadState.Stopped ||
                simulationThread.Thread.ThreadState == System.Threading.ThreadState.WaitSleepJoin
                );
#endif

            RendererUpdateQueue q = simulation.Close();
            renderer.AddUpdateQueue(q);
            simulationThread.Abort();

            MediaPlayer.Stop();

            simulationThread.Profiler.Write(device, Window.Title, "profiling_simulation.txt");
            profiler.Write(device, Window.Title, "profiling_renderer.txt");

#if !XBOX
            Debug.Assert(simulationThread.Thread.ThreadState == System.Threading.ThreadState.Stopped);
#endif
#if !DEBUG
        }
        catch (Exception)
        {
        }
#endif
        }
コード例 #4
0
        private void StartOperation()
        {
            if (currentUpdateQueue != null)
            {
                throw new Exception("synchronisation error");
            }

            currentUpdateQueue = new RendererUpdateQueue(simTime.At);
        }
コード例 #5
0
        /// <summary>
        /// initializes a new simulation using the level provided
        /// </summary>
        /// <param name="level"></param>
        public void LoadLevel(
            string simulationLevel,
            string rendererLevel
            )
        {
            if (simulationThread != null)
            {
                if (!paused)
                {
                    simulationThread.Join();
                }
            }

            if (simulationThread == null)
            {
                simulationThread = new SimulationThread();
            }

            // reset old simulation
            if (simulation != null)
            {
                RendererUpdateQueue q1 = simulation.Close();
                renderer.AddUpdateQueue(q1);
            }

            // init simulation
            simulation = new ProjectMagma.Simulation.Simulation();
            RendererUpdateQueue q = simulation.Initialize(ContentManager, simulationLevel, rendererLevel, globalClock.PausableMilliseconds);

            renderer.AddUpdateQueue(q);

#if !XBOX
            Debug.Assert(
                simulationThread == null || simulationThread.Thread == null ||
                simulationThread.Thread.ThreadState == System.Threading.ThreadState.WaitSleepJoin
                );
#endif

            simulationThread.Reinitialize(this.simulation, this.renderer);

            // set camera
            //currentCamera = simulation.EntityManager["camera1"];

            if (!paused)
            {
                simulationThread.Start();
            }
        }
コード例 #6
0
ファイル: Renderer.cs プロジェクト: cfo82/Magmageddon
        private RendererUpdateQueue GetNextUpdateQueue()
        {
            lock (updateQueues)
            {
                if (updateQueues.Count == 0)
                {
                    return(null);
                }

                ValicateUpdateQueueCount();

                RendererUpdateQueue q = updateQueues[0];
                updateQueues.RemoveAt(0);
                return(q);
            }
        }
コード例 #7
0
        private void Run()
        {
#if XBOX
            this.thread.SetProcessorAffinity(ThreadDistribution.SimulationThread);
#endif
            try
            {
                while (true)
                {
                    startEvent.WaitOne();

                    while (!joinRequested)
                    {
                        profiler.BeginFrame();
                        RendererUpdateQueue q = simulation.Update();
                        renderer.AddUpdateQueue(q);

                        Sps    = 1000f / simulation.Time.DtMs;
                        AvgSps = 1000f * simulation.Time.Frame / simulation.Time.At;
                        profiler.EndFrame();
                    }

                    finishedEvent.Set();
                }
            }
#if DEBUG
            catch (ThreadAbortException ex)
            {
                if (!this.aborted)
                {
                    System.Console.WriteLine("unexpected Exception {0}\n{1}\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace);
                    throw ex;
                }
            }
#else
            catch (Exception ex)
            {
                if (!this.aborted)
                {
                    System.Console.WriteLine("unexpected Exception {0}\n{1}\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace);
                    Game.Instance.CrashDebugger.Crash(ex);
                    finishedEvent.Set();
                }
            }
#endif
        }
コード例 #8
0
        public RendererUpdateQueue Update()
        {
            try
            {
                Game.Instance.SimulationThread.Profiler.BeginSection("simulation_update");
                StartOperation();

                // pause simulation if explicitly paused or app changed
                // removed app-changed thing (Game.Instance.IsActive) since this should be already handled
                // by the game class
                if (!paused)
                {
                    // update simulation time
                    simTime.Update();
                    //Console.WriteLine("simulating {0}", simTime.At);

                    if (simTime.DtMs < 15)
                    {
                        System.Threading.Thread.Sleep(15 - (int)simTime.DtMs);
                    }

                    // update all entities
                    foreach (Entity e in entityManager)
                    {
                        e.Update(simTime);
                    }

                    // perform collision detection
                    collisionManager.Update(simTime);

                    // execute deferred add/remove orders on the entityManager
                    entityManager.ExecuteDeferred();

                    if (phase == SimulationPhase.Intro &&
                        playersWaiting == 0)
                    {
                        SetPhase(SimulationPhase.Game, "", null);
                    }

                    //System.Threading.Thread.Sleep(60);
                }
                else
                {
                    // safety measurement:
                    //   - first we should never enter this methode since we pause simulation and simulation thread simultaneously
                    //    => assert if we arrive here
                    //   - second take precautions and pause vor 10 milliseconds if we arrive here in a release build

                    Debug.Assert(false);
                    System.Threading.Thread.Sleep(10);
                }

                RendererUpdateQueue returnValue = EndOperation();
                Game.Instance.SimulationThread.Profiler.EndSection("simulation_update");
                return(returnValue);
            }
            finally
            {
                currentUpdateQueue = null;
            }
        }
コード例 #9
0
ファイル: Renderer.cs プロジェクト: cfo82/Magmageddon
        private void Update()
        {
            if (Camera != null)
            {
                // should only be called if a level has already been loaded
                Camera.Update(this);
                Camera.RecomputeFrame(ref opaqueRenderables);
            }

            RendererUpdateQueue q = GetNextUpdateQueue();

            while (q != null)
            {
                for (int i = 0; i < q.Count; ++i)
                {
                    q[i].Apply(q.Timestamp);
                }

                q = GetNextUpdateQueue();
            }

            foreach (Renderable renderable in updateRenderables)
            {
                renderable.Update(this);
            }

            Game.Instance.Profiler.BeginSection("particle_systems");
            PIXHelper.BeginEvent("Update Particles");

            PIXHelper.BeginEvent("Update lava flames");
            Game.Instance.Profiler.BeginSection("explosion_system");
            if (explosionSystem != null)
            {
                explosionSystem.Update(Time.Last / 1000d, Time.At / 1000d);
            }
            Game.Instance.Profiler.EndSection("explosion_system");
            PIXHelper.EndEvent();

            PIXHelper.BeginEvent("Update snow");
            Game.Instance.Profiler.BeginSection("snow_system");
            if (snowSystem != null)
            {
                snowSystem.Update(Time.Last / 1000d, Time.At / 1000d);
            }
            Game.Instance.Profiler.EndSection("snow_system");
            PIXHelper.EndEvent();

            PIXHelper.BeginEvent("Update ice explosions");
            Game.Instance.Profiler.BeginSection("ice_explosion_system");
            if (iceExplosionSystem != null)
            {
                iceExplosionSystem.Update(Time.PausableLast / 1000d, Time.PausableAt / 1000d);
            }
            Game.Instance.Profiler.EndSection("ice_explosion_system");
            PIXHelper.EndEvent();

            PIXHelper.BeginEvent("Update fire explosions");
            Game.Instance.Profiler.BeginSection("fire_explosion_system");
            if (fireExplosionSystem != null)
            {
                fireExplosionSystem.Update(Time.PausableLast / 1000d, Time.PausableAt / 1000d);
            }
            Game.Instance.Profiler.EndSection("fire_explosion_system");
            PIXHelper.EndEvent();

            PIXHelper.BeginEvent("Update flamethrowers");
            Game.Instance.Profiler.BeginSection("flamethrower_system");
            if (flamethrowerSystem != null)
            {
                flamethrowerSystem.Update(Time.PausableLast / 1000d, Time.PausableAt / 1000d);
            }
            Game.Instance.Profiler.EndSection("flamethrower_system");
            PIXHelper.EndEvent();

            PIXHelper.BeginEvent("Update ice spikes");
            Game.Instance.Profiler.BeginSection("ice_spike_system");
            if (iceSpikeSystem != null)
            {
                iceSpikeSystem.Update(Time.PausableLast / 1000d, Time.PausableAt / 1000d);
            }
            Game.Instance.Profiler.EndSection("ice_spike_system");
            PIXHelper.EndEvent();

            PIXHelper.EndEvent();
            Game.Instance.Profiler.EndSection("particle_systems");
        }
コード例 #10
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (CrashDebugger.Crashed)
            {
                if (!Paused)
                {
                    Pause();
                    RendererUpdateQueue q = simulation.Close();
                    renderer.AddUpdateQueue(q);
                    simulationThread.Abort();
                }

                crashDebugger.Update(GraphicsDevice);

                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    Exit();
                }
                return;
            }

#if XBOX && !DEBUG
            try
            {
#endif
            // get storage device => moved
            if (!Guide.IsVisible && storageSelectionResult == null)
            {
                try
                {
                    storageSelectionResult = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
                }
                catch (GuideAlreadyVisibleException)
                {
                    // FIXME. see also
                    //    http://forums.xna.com/forums/p/19874/103843.aspx
                    //    http://blog.nickgravelyn.com/2009/07/storage-device-management-20/
                }
            }

            // get storage device as soon as selected
            if (storageSelectionResult != null && !storageAvailable && storageSelectionResult.IsCompleted)
            {
                device           = StorageDevice.EndShowSelector(storageSelectionResult);
                storageAvailable = true;
                LoadSettings();
            }

            profiler.TryEndFrame();
            profiler.BeginFrame();

            // wait with normal update until storage available
            if (storageAvailable)
            {
                profiler.BeginSection("update");

                // fullscreen
                if (Keyboard.GetState().IsKeyDown(Keys.Enter) &&
                    Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
                {
                    graphics.IsFullScreen = !this.graphics.IsFullScreen;
                    graphics.ApplyChanges();
                }

                profiler.HandleInput(gameTime);

                //simulationThread.Join();

                // update menu
                menu.Update(gameTime);

                // update all GameComponents registered
                profiler.BeginSection("base_update");
                base.Update(gameTime);
                profiler.EndSection("base_update");

                profiler.EndSection("update");
            }
#if XBOX && !DEBUG
        }

        catch (Exception e)
        {
            crashDebugger.Crash(e);
        }
#endif
        }