コード例 #1
0
 public override void Tick(FrameTime ft)
 {
     GameEngine.SetGameLevel(Context.Cast<NativeObjectAdapter>());
     GameEngine.Update(ft.TotalTime, ft.ElapsedTime, false);
     foreach (NativeDesignControl view in Views)
     {                               
         view.Render();
     }
 }                
コード例 #2
0
ファイル: GameEngine.cs プロジェクト: coreafive/XLE
        public void Update(FrameTime ft, UpdateType updateType)
        {
                // There are 3 update types defined by Sony.
                //  Here they are:
            // Editing: in this mode physics and AI 
            // should not be updated.
            // While particle system and other editing related effects
            // should be updated
    
            // GamePlay: update all the subsystems.
            // Some editing related effects shoult not updated.

            // Paused: none of the time based effects are simulated.
            // Delta time should be zero.

            if (updateType != UpdateType.Paused)
                s_underlyingScene.IncrementTime(ft.ElapsedTime);
        }
コード例 #3
0
        /// <summary>
        /// Computes frame time and calls
        /// Tick(FrameTime ft) to advance
        /// update/rendering by on tick.
        /// </summary>
        public void Tick()
        {
            FrameTime ft = GetFrameTime();

            Tick(ft);
        }
コード例 #4
0
 /// <summary>
 /// Advances update/render by the given frame time.</summary>
 /// <param name="ft"></param>
 public abstract void Tick(FrameTime ft);
コード例 #5
0
ファイル: GameEngine.cs プロジェクト: arsaccol/LevelEditor
 private static extern void NativeUpdate(FrameTime* time, UpdateType updateType);
コード例 #6
0
ファイル: GameEngine.cs プロジェクト: arsaccol/LevelEditor
 /// <summary>
 /// Updates game world</summary>
 /// <param name="ft">Frame time</param>
 /// <param name="updateType">Update type</param>        
 public void Update(FrameTime ft, UpdateType updateType)
 {
     NativeUpdate(&ft, updateType);
 }
コード例 #7
0
            // render the scene.
            public override void Render()
            {
                if (GameEngine.IsInError
                    || SurfaceId == 0
                    || Visible == false
                    || Width == 0
                    || Height == 0
                    || Game == null)
                    return;

                
                NativeObjectAdapter gameLevel = GameEngine.GetGameLevel();
                try
                {                    
                    NativeObjectAdapter game = Game.As<NativeObjectAdapter>();
                    GameEngine.SetGameLevel(game);
                    GameEngine.SetRenderState(m_renderState);
                    if (Game.RootGameObjectFolder.GameObjects.Count > 0)
                    {
                        FrameTime fr = new FrameTime(0, 0);
                        GameEngineProxy.WaitForPendingResources();
                        GameEngineProxy.Update(fr, UpdateType.Paused);
                    }

                    if (ResetCamera)
                    {
                        // save view type
                        ViewTypes viewtype = this.ViewType;
                        ViewType = ViewTypes.Perspective;
                        Size sz = ClientSize;
                        float aspect = (float)sz.Width / (float)sz.Height;
                        IBoundable boundable = Game.RootGameObjectFolder.Cast<IBoundable>();
                        Sce.Atf.VectorMath.Sphere3F sphere = boundable.BoundingBox.ToSphere();
                        float nearZ = sphere.Radius * 0.01f;
                        nearZ = Math.Min(0.1f, nearZ);
                        Camera.SetPerspective(
                            (float)Math.PI / 4,
                            aspect,
                            nearZ,
                            sphere.Radius * 10.0f);

                        Vec3F camPos = sphere.Center + new Vec3F(sphere.Radius, sphere.Radius, sphere.Radius) * 1.2f;
                        Camera.Set(camPos, sphere.Center, new Vec3F(0, 1, 0));
                        ViewType = viewtype;
                        ResetCamera = false;
                    }
                                       
                    GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);
                    if(Game.RootGameObjectFolder.GameObjects.Count > 0)
                        GameEngine.RenderGame();                        
                    string str = "View Type: " + ViewType.ToString();
                    GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);
                    GameEngine.End();
                }
                finally
                {
                    GameEngine.SetGameLevel(gameLevel);
                }
            }
コード例 #8
0
        public void Update()
        {
            var context = m_designView.Context;
            if (context == null) return;

            m_gameEngine.SetGameWorld(context.Cast<IGame>());
            double lag = (Timing.GetHiResCurrentTime() - m_lastUpdateTime)
                + m_updateLagRemainder;

            // early return
            if (lag < UpdateStep) return;

            if (UpdateType == UpdateType.Paused)
            {
                m_lastUpdateTime = Timing.GetHiResCurrentTime();
                FrameTime fr = new FrameTime(m_simulationTime, 0.0f);
                m_gameEngine.Update(fr, UpdateType);
                m_updateLagRemainder = 0.0;
            }
            else
            {
                // set upper limit of update calls 
                const int MaxUpdates = 3;
                int updateCount = 0;

                while (lag >= UpdateStep
                    && updateCount < MaxUpdates)
                {
                    m_lastUpdateTime = Timing.GetHiResCurrentTime();
                    FrameTime fr = new FrameTime(m_simulationTime, (float)UpdateStep);
                    m_gameEngine.Update(fr, UpdateType);
                    m_simulationTime += UpdateStep;
                    lag -= UpdateStep;
                    updateCount++;
                }

                m_updateLagRemainder = MathUtil.Clamp(lag, 0, UpdateStep);
                Debug.Assert(updateCount != 0);
            }
        }
コード例 #9
0
        private void GenThumbnail(Uri resourceUri, string thumbnailPath)
        {             
            NativeObjectAdapter gameLevel = GameEngine.GetGameLevel();
            try
            {
                IResource resource = m_resourceService.Load(resourceUri);
                IGameObject gob = m_resourceConverterService.Convert(resource);
                if (gob == null) return;
                
                m_game.RootGameObjectFolder.GameObjects.Add(gob);

                GameEngine.SetRenderState(m_renderState);
                GameEngine.SetGameLevel(m_game.Cast<NativeObjectAdapter>());

                m_gameEngine.WaitForPendingResources();
                FrameTime fr = new FrameTime(0, 0);
                m_gameEngine.Update(fr, UpdateType.Paused);

                IBoundable boundable = gob.Cast<IBoundable>();
                Sphere3F sphere = boundable.BoundingBox.ToSphere();
                
                if (Math.Abs(sphere.Radius) <= float.Epsilon)
                    sphere.Radius = 1.0f;

                m_cam.SetPerspective(
               (float)Math.PI / 4,
               1.0f,
               sphere.Radius * 0.01f,
               sphere.Radius * 4.0f);


                Vec3F camPos = sphere.Center + new Vec3F(sphere.Radius, sphere.Radius, sphere.Radius) * 1.5f;
                m_cam.Set(camPos, sphere.Center, new Vec3F(0, 1, 0));

                GameEngine.Begin(m_renderSurface.InstanceId, m_cam.ViewMatrix, m_cam.ProjectionMatrix);
                GameEngine.RenderGame();
                GameEngine.End();
                GameEngine.SaveRenderSurfaceToFile(m_renderSurface.InstanceId, thumbnailPath);                
                m_game.RootGameObjectFolder.GameObjects.Remove(gob);

                m_resourceService.Unload(resourceUri);
            }
            finally
            {
                GameEngine.SetGameLevel(gameLevel);
            }
             
             
        }
コード例 #10
0
ファイル: DesignView.cs プロジェクト: JanDeHud/LevelEditor
 /// <summary>
 /// Advances update/render by the given frame time.</summary>
 /// <param name="ft"></param>
 public abstract void Tick(FrameTime ft);