Пример #1
0
        public virtual async System.Threading.Tasks.Task <bool> InitGame(IntPtr WinHandle, UInt32 width, UInt32 height, EngineNS.GamePlay.GGameInstanceDesc desc, EngineNS.Graphics.CGfxCamera camera)
        {
            var rc = EngineNS.CEngine.Instance.RenderContext;

            if (camera == null)
            {
                camera = new EngineNS.Graphics.CGfxCamera();
                camera.Init(rc, false);
            }

            CEngine.Instance.TickManager.AddTickInfo(this);

            await BuildAutoMembers();

            WindowHandle = WinHandle;
            WindowWidth  = width;
            WindowHeight = height;
            mDesc        = desc;
            mWorld       = new GWorld();
            GameCamera   = camera;

            if (false == mWorld.Init())
            {
                return(false);
            }

            var scene = await LoadScene(rc, desc.SceneName, true);

            if (scene == null)
            {
                return(false);
            }

            mWorld.AddScene(desc.SceneName, scene);
            mWorld.SetDefaultScene(scene.SceneId);

            foreach (var i in AutoMembers)
            {
                await i.Key.OnGameInit(i.Value, width, height);
            }

            Vector3 Eye = new Vector3();

            Eye.SetValue(0.0f, 1.0f, -3.0f);
            Vector3 At = new Vector3();

            At.SetValue(0.0f, 1.0f, 0.0f);
            Vector3 Up = new Vector3();

            Up.SetValue(0.0f, 1.0f, 0.0f);
            camera.LookAtLH(Eye, At, Up);
            camera.PerspectiveFovLH(camera.mDefaultFoV, (float)width, (float)height, 0.1f, 1000.0f);

            var mRP_GameMobile = new EngineNS.Graphics.RenderPolicy.CGfxRP_GameMobile();
            await mRP_GameMobile.Init(rc, width, height, camera, WinHandle);

            this.SetGameRenderPolicy(mRP_GameMobile);

            return(true);
        }
Пример #2
0
 public virtual void FinalGame()
 {
     if (mWorld != null)
     {
         mWorld.Cleanup();
         mWorld = null;
     }
     foreach (var i in AutoMembers)
     {
         i.Key.Cleanup(i.Value);
     }
 }
Пример #3
0
        public static async System.Threading.Tasks.Task <SceneGraph.GSceneGraph> LoadScene(CRenderContext rc, GWorld world, RName name)
        {
            var xnd = await IO.XndHolder.LoadXND(name.Address + "/scene.map");

            if (xnd == null)
            {
                var st = await GamePlay.SceneGraph.GSceneGraph.CreateSceneGraph(world, typeof(GamePlay.SceneGraph.GSceneGraph), new SceneGraph.GSceneGraphDesc());

                return(st);
            }
            else
            {
                var type = Rtti.RttiHelper.GetTypeFromSaveString(xnd.Node.GetName());
                if (type == null)
                {
                    return(null);
                }
                var st = await GamePlay.SceneGraph.GSceneGraph.CreateSceneGraph(world, type, null);

                st.Name = name.Name;
                if (false == await st.LoadXnd(rc, xnd.Node, name))
                {
                    return(null);
                }

                if (st != null)
                {
                    world.AddScene(name, st);
                    world.SetDefaultScene(st.SceneId);
                }

                if (st.McSceneGetter != null && st.McSceneGetter.Get(false) != null)
                {
                    await st.McSceneGetter.Get(false).OnSceneLoaded(st);

                    st.McSceneGetter.Get(false).OnRegisterInput();
                }
                return(st);
            }
        }