Esempio n. 1
0
        public void RenderFrame()
        {
            double dt = m_fps.GetDeltaTime();

            var drawSys    = DrawSystem.GetInstance();
            var cameraSys  = CameraSystem.GetInstance();
            var inputSys   = InputSystem.GetInstance();
            var entitySys  = EntitySystem.GetInstance();
            var mapSys     = MapSystem.GetInstance();
            var cullingSys = CullingSystem.GetInstance();

            // update fps
            {
                double avgDT = m_fps.GetAverageDeltaTime();
                string text  = String.Format("FPS:{0:f2}, DeltaTime:{1:f2}ms", 1.0 / avgDT, avgDT * 1000.0f);
                m_numberEntity.SetNumber(1.0f / (float)avgDT);
            }

            if (m_multiThreadCount > 1)
            {
                Task.WaitAll(m_taskList.ToArray());
                var tmpTaskResult = new List <CommandList>(m_taskResultList);

                inputSys.Update(dt);
                entitySys.UpdateComponents(GameEntityComponent.UpdateLines.Input, dt);
                entitySys.UpdateComponents(GameEntityComponent.UpdateLines.Behavior, dt);
                cameraSys.Update(dt);
                entitySys.UpdateComponents(GameEntityComponent.UpdateLines.PostBehavior, dt);

                DrawSystem.WorldData worldData;
                worldData.AmbientColor     = new Color3(0.4f, 0.45f, 0.55f);
                worldData.FogColor         = new Color3(0.3f, 0.5f, 0.8f);
                worldData.NearClip         = 0.01f;
                worldData.FarClip          = 100.0f;
                worldData.DirectionalLight = new DrawSystem.DirectionalLightData()
                {
                    Direction = new Vector3(0.3f, -0.2f, 0.4f),
                    Color     = new Color3(0.6f, 0.6f, 0.5f),
                };
                worldData.Camera = cameraSys.GetCameraData();

                drawSys.BeginScene(worldData);
                var context = drawSys.GetDrawContext();


                entitySys.UpdateComponents(GameEntityComponent.UpdateLines.Posing, dt);
                mapSys.Update(dt, context);
                cullingSys.UpdateFrustum();
                entitySys.UpdateComponents(GameEntityComponent.UpdateLines.PreDraw, dt);
                drawSys.GetDrawBuffer().Process(drawSys.GetDrawContext());
                entitySys.UpdateComponents(GameEntityComponent.UpdateLines.Draw, dt);

                // start command list generation for the next frame
                m_taskList.Clear();
                m_taskResultList.Clear();
                m_taskResultList.AddRange(Enumerable.Repeat <CommandList>(null, m_multiThreadCount));
                m_accTime += dt;
                for (int threadIndex = 0; threadIndex < m_multiThreadCount; ++threadIndex)
                {
                    int resultIndex = threadIndex;

                    var subThreadContext = drawSys.GetSubThreadContext(threadIndex);
                    m_taskList.Add(Task.Run(() =>
                    {
                        // todo : do sub-thread task
                        m_taskResultList[resultIndex] = subThreadContext.FinishCommandList();
                    }));
                }

                foreach (var result in tmpTaskResult)
                {
                    context.ExecuteCommandList(result);
                }

                m_numberEntity.SetPose(ChrSystem.GetInstance().Player.FindComponent <LayoutComponent>().Transform);
                m_numberEntity.Draw(context);
                drawSys.EndScene();
            }
            else
            {
                // not supported
            }

            m_fps.EndFrame();
            m_fps.BeginFrame();
        }