示例#1
0
        public GameBuilder Build(int stateKey = 0)
        {
            if (!Engine.HasState(stateKey))
            {
                Engine.AddNewState(stateKey);
            }

            Engine.SetView(stateKey, view);

            Frame.Start();
            Engine.DrawEnd(stateKey) += Frame.DrawHandle;

            Engine.SetLocation(stateKey, location);

            foreach (Controller controller in controllers)
            {
                Engine.AddController(stateKey, controller);

                Frame.Window.Hook(controller);
            }

            Stopwatch swTick = new Stopwatch();

            Engine.TickStart(stateKey) += (e, o) => swTick.Restart();
            Engine.TickEnd(stateKey)   += (e, o) => { swTick.Stop();; tickTime = swTick.ElapsedTicks; };

            Stopwatch swDraw = new Stopwatch();

            Engine.DrawStart(stateKey) += (e, o) => swDraw.Restart();
            Engine.DrawEnd(stateKey)   += (e, o) => { swDraw.Stop(); drawTime = swDraw.ElapsedTicks; };

            int       ticks    = 0;
            Stopwatch tpsWatch = Stopwatch.StartNew();

            Engine.TickStart(stateKey) += (e, o) => ticks++;
            Engine.TickEnd(stateKey)   += (e, o) =>
            {
                if (tpsWatch.ElapsedMilliseconds >= 1000)
                {
                    tpsWatch.Restart();
                    tps   = ticks;
                    ticks = 0;
                }
            };

            return(this);
        }