Пример #1
0
 /// <summary>
 /// callback that this component is added to entity
 /// </summary>
 /// <param name="entity">onwer entity</param>
 /// <remarks>
 /// If you override this methods, you must call this version too.
 /// </remarks>
 virtual public void OnAddToEntity(GameEntity entity)
 {
     m_entity = entity;
     if (m_updateLine != UpdateLines.Invalid)
     {
         var entitySys = EntitySystem.GetInstance();
         entitySys.GetComponentLine(m_updateLine).AddComponent(this);
     }
 }
Пример #2
0
 /// <summary>
 /// callback that this component is removed from entity
 /// </summary>
 /// <param name="entity">owner entity</param>
 /// <remarks>
 /// If you override this methods, you must call this version too.
 /// </remarks>
 virtual public void OnRemoveFromEntity(GameEntity entity)
 {
     Debug.Assert(entity == m_entity, "invalid entity");
     m_entity = null;
     if (m_updateLine != UpdateLines.Invalid)
     {
         var entitySys = EntitySystem.GetInstance();
         entitySys.GetComponentLine(m_updateLine).RemoveComponent(this);
     }
 }
Пример #3
0
        public PlayerEntity()
            : base("player")
        {
            var entitySys = EntitySystem.GetInstance();
            var mapSys    = MapSystem.GetInstance();

            //var path = "Chr/c9000/test.blend";
            //var searchPath = "Chr/c9000";
            var path       = "Chr/c9100/c9100.blend";
            var searchPath = "Chr/c9100";
            var scene      = BlenderScene.FromFile(path);

            if (scene != null)
            {
                var drawModel = DrawModel.FromScene(path + "/draw", scene, searchPath);
                var animRes   = AnimResource.FromBlenderScene(path + "/anim", scene);
                //var debugModel = DrawModel.CreateTangentFrame(path + "/debug", scene);

                if (drawModel.BoneArray.Length != 0)
                {
                    var skeletonC = new SkeletonComponent(drawModel.BoneArray);
                    AddComponent(skeletonC);
                }

                var layoutC = new LayoutComponent();
                layoutC.Transform = Matrix.Identity;
                AddComponent(layoutC);

                //var markerC = new ModelMarkerComponent(scene);
                //AddComponent(markerC);

                var modelC = new ModelComponent(GameEntityComponent.UpdateLines.Draw);
                modelC.ModelContext.EnableCastShadow = true;
                modelC.ModelContext.DrawModel        = drawModel;
                //modelC.ModelContext.DebugModel = debugModel;
                AddComponent(modelC);

                var animC = new AnimComponent(animRes);
                AddComponent(animC);

                var behaviorC = new ChrBehaviorComponent();
                AddComponent(behaviorC);

                var minimapC = new MinimapComponent();
                AddComponent(minimapC);

                MapLocation startLocation = mapSys.GetStartInfo();
                //var inputC = new GodViewInputComponent();
                var inputC = new FpsInputComponent(startLocation);
                AddComponent(inputC);
            }
        }
Пример #4
0
        private void _RegisterDebugEntity()
        {
            var entitySys = EntitySystem.GetInstance();

            var entity = new GameEntity("frustum");

            var layoutC = new LayoutComponent();

            layoutC.Transform = Matrix.Identity;
            entity.AddComponent(layoutC);

            var drawC = new EasyDrawComponent((IDrawContext context, Matrix layout, DrawModel lastDrawModel) =>
            {
                if (lastDrawModel != null)
                {
                    lastDrawModel.Dispose();
                }

                var cameraSys = CameraSystem.GetInstance();
                if (cameraSys.IngameCamera != cameraSys.ActiveCamera)
                {
                    // frustum is visible in editor mode
                    var drawModel = DrawModel.CreateFrustum("frustum", _GetFrustumMatrix(), Color.Cyan);
                    foreach (var node in drawModel.NodeList)
                    {
                        context.DrawDebugModel(layout, node.Mesh, DrawSystem.RenderMode.Transparency);
                    }

                    return(drawModel);
                }
                else
                {
                    return(null);
                }
            });

            entity.AddComponent(drawC);

            m_dbgModelEntity = entity;
        }
Пример #5
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();
        }