Ejemplo n.º 1
0
        public override void DoMain()
        {
            m_game.OnStateLog(m_log);

            LSystem.isResume  = false;
            LSystem.isPaused  = false;
            LSystem.isDestroy = false;

            timerContext = new LTimerContext();
            timer        = LSystem.GetSystemTimer();

            if (m_game != null)
            {
                GameType type = m_game.GetGameType();
                if (type != null)
                {
                    Register(type.setting, type.mainType, type.args);
                }
            }

            Printf("doMain");
        }
Ejemplo n.º 2
0
        public override void Draw(GL g)
        {
            this.m_onRunning = false;
            this.m_onPause   = false;
            this.m_onDestroy = false;
            this.m_onResume  = false;

            lock (m_sync)
            {
                m_onRunning = LSystem.isRunning;
                m_onPause   = LSystem.isPaused;
                m_onDestroy = LSystem.isDestroy;
                m_onResume  = LSystem.isResume;

                if (LSystem.isResume)
                {
                    LSystem.isResume = false;
                }

                if (LSystem.isPaused)
                {
                    LSystem.isPaused = false;
                    JavaRuntime.NotifyAll(m_sync);
                }

                if (LSystem.isDestroy)
                {
                    LSystem.isDestroy = false;
                    JavaRuntime.NotifyAll(m_sync);
                }

                if (m_onResume)
                {
                    m_log.I("m_onResume");
                    timer           = LSystem.GetSystemTimer();
                    lastTimeMicros  = timer.GetTimeMicros();
                    elapsedTime     = 0;
                    remainderMicros = 0;
                    m_process.OnResume();
                }


                if (m_onRunning)
                {
                    if (LSystem.isLogo)
                    {
                        if (logoFlag == null)
                        {
                            LSystem.isLogo = false;
                            return;
                        }
                        logoFlag.Draw(m_process.gl);
                        if (logoFlag.finish)
                        {
                            m_process.gl.SetAlpha(1.0f);
                            m_process.gl.DrawClear(LColor.black);
                            LSystem.isLogo = false;
                            logoFlag.Dispose();
                            logoFlag = null;
                            return;
                        }
                        return;
                    }

                    if (!m_process.Next())
                    {
                        return;
                    }

                    m_process.Load();

                    m_process.Calls();

                    goalTimeMicros    = lastTimeMicros + 1000000L / maxFrames;
                    currTimeMicros    = timer.SleepTimeMicros(goalTimeMicros);
                    elapsedTimeMicros = currTimeMicros - lastTimeMicros
                                        + remainderMicros;
                    elapsedTime     = MathUtils.Max(0, (elapsedTimeMicros / 1000));
                    remainderMicros = elapsedTimeMicros - elapsedTime * 1000;
                    lastTimeMicros  = currTimeMicros;
                    timerContext.millisSleepTime     = remainderMicros;
                    timerContext.timeSinceLastUpdate = elapsedTime;

                    ActionControl.Update(elapsedTime);

                    m_process.RunTimer(timerContext);

                    if (LSystem.AUTO_REPAINT)
                    {
                        GLEx gl = m_process.gl;

                        if (gl != null)
                        {
                            if (!m_process.Next())
                            {
                                return;
                            }

                            //设定graphics.PreferredBackBufferWidth和graphics.PreferredBackBufferHeight时WP会自动缩放画面,
                            //此处无需再缩放一次。

                            /*if (LSystem.scaleWidth != 1f || LSystem.scaleHeight != 1f)
                             * {
                             *  gl.Scale(LSystem.scaleWidth,
                             *          LSystem.scaleHeight);
                             * }*/

                            int repaintMode = m_process.GetRepaintMode();

                            switch (repaintMode)
                            {
                            case Screen.SCREEN_BITMAP_REPAINT:
                                gl.Reset(true);
                                if (m_process.GetX() == 0 && m_process.GetY() == 0)
                                {
                                    gl.DrawTexture(m_process.GetBackground(), 0, 0);
                                }
                                else
                                {
                                    gl.DrawTexture(m_process.GetBackground(), m_process.GetX(),
                                                   m_process.GetY());
                                }
                                break;

                            case Screen.SCREEN_COLOR_REPAINT:
                                LColor c = m_process.GetColor();
                                if (c != null)
                                {
                                    gl.DrawClear(c);
                                }
                                break;

                            case Screen.SCREEN_CANVAS_REPAINT:
                                gl.Reset(true);
                                break;

                            case Screen.SCREEN_NOT_REPAINT:
                                gl.Reset(true);
                                break;

                            default:
                                gl.Reset(true);
                                if (m_process.GetX() == 0 && m_process.GetY() == 0)
                                {
                                    gl.DrawTexture(
                                        m_process.GetBackground(),
                                        repaintMode / 2
                                        - LSystem.random.Next(repaintMode),
                                        repaintMode / 2
                                        - LSystem.random.Next(repaintMode));
                                }
                                else
                                {
                                    gl.DrawTexture(m_process.GetBackground(),
                                                   m_process.GetX() + repaintMode / 2
                                                   - LSystem.random.Next(repaintMode),
                                                   m_process.GetY() + repaintMode / 2
                                                   - LSystem.random.Next(repaintMode));
                                }
                                break;
                            }

                            m_process.Draw();

                            m_process.Drawable(elapsedTime);

                            if (isFPS)
                            {
                                this.TickFrames();
                                fpsFont.DrawString(string.Format(numformat, "FPS:{0}", frameRate), 5, 5, 0, LColor.white);
                            }

                            m_process.DrawEmulator();

                            m_process.Unload();

                            gl.Restore();
                        }
                    }
                }
            }
        }