Exemplo n.º 1
0
        private void lifeLoopTask()
        {
            do
            {
                if (NextMode == LMode.AUTO)
                {                                      // if we are not in single step mode
                    nextStep();                        // update a step
                }
                else
                {
                    Thread.Sleep(50);
                }

                if (NextMode == LMode.STEP)
                {                                      // if we are in single step mode
                    _allCellUpdate = true;
                    nextStep();                        // update a tick
                    NextMode = LMode.IDLE;             // clear flag so we only do it once
                }

                if (NextMode != _currentMode)
                {
                    changeMode(NextMode);
                }
            } while (NextMode != LMode.EXIT);         // while is allways true, thread never ends on its own
        }
Exemplo n.º 2
0
        public virtual void UpdateViewSizeData(LMode mode)
        {
            if (zoomWidth <= 0)
            {
                zoomWidth = maxWidth;
            }
            if (zoomHeight <= 0)
            {
                zoomHeight = maxHeight;
            }
            LSystem.SetScaleWidth((float)maxWidth / zoomWidth);
            LSystem.SetScaleHeight((float)maxHeight / zoomHeight);
            LSystem.viewSize.SetSize(zoomWidth, zoomHeight);

            StringBuffer sbr = new StringBuffer();

            sbr.Append("Mode:").Append(mode);
            sbr.Append("\nWidth:").Append(zoomWidth).Append(",Height:" + zoomHeight);
            sbr.Append("\nMaxWidth:").Append(maxWidth).Append(",MaxHeight:" + maxHeight);
            JavaSystem.Out.Println(sbr.ToString());
        }
Exemplo n.º 3
0
        private void changeMode(LMode newMode)
        {
            int       nx;
            const int FIN = _LIFE_SIZE / 50;
            int       index;

            switch (newMode)
            {
            case LMode.CLEAR:   // clear
                Array.Clear(_workMap, 0, _LIFE_SIZE);
                Array.Clear(_lastMap, 0, _LIFE_SIZE);
                _stepsTaken = 0;
                break;

            case LMode.AUTO:
            case LMode.EXIT:
                break;

            case LMode.IDLE:
                Thread.Sleep(50);         // sleep the thread for 50ms (only in manual mode)
                break;

            case LMode.ADD_SMALL:         // S = 7 point starter
                addToMapViewCentered(1, 0);
                addToMapViewCentered(3, 1);
                addToMapViewCentered(0, 2);
                addToMapViewCentered(1, 2);
                addToMapViewCentered(4, 2);
                addToMapViewCentered(5, 2);
                addToMapViewCentered(6, 2);
                NextMode = LMode.IDLE;
                break;

            case LMode.ADD_GLIDER:
                addToMapViewCentered(3, 0);
                addToMapViewCentered(3, 1);
                addToMapViewCentered(3, 2);
                addToMapViewCentered(2, 0);
                addToMapViewCentered(1, 1);
                NextMode = LMode.IDLE;
                break;

            case LMode.ADD_LARGE:          // L point starter
                addToMapViewCentered(0, 0);
                addToMapViewCentered(2, 0);
                addToMapViewCentered(2, 1);
                addToMapViewCentered(4, 2);
                addToMapViewCentered(4, 3);

                addToMapViewCentered(4, 4);
                addToMapViewCentered(6, 3);
                addToMapViewCentered(6, 4);
                addToMapViewCentered(6, 5);
                addToMapViewCentered(7, 4);
                NextMode = LMode.IDLE;
                break;

            case LMode.ADD_RANDOM:        // R = random fill of entire row/col

                for (index = 0; index < FIN; ++index)
                {                                                       // use a for to iterate the randoms
                    nx           = _randomLocation.Next(0, _LIFE_SIZE); // create a new random number winthin the array
                    _lastMap[nx] = 1;                                   //write the array with a 1, add a cell
                    _workMap[nx] = 1;
                }
                NextMode = LMode.IDLE;
                break;
            }
            _currentMode   = newMode;
            _allCellUpdate = true;
        }
Exemplo n.º 4
0
        public void Initialization(bool l,
                bool f, LMode m)
        {
            log.I("GPU surface");

            this.landscape = l;
            this.fullScreen = f;
            this.mode = m;

            if (landscape == false)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH = tmp_height;
                }
            }

            this.CheckDisplayMode();

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = landscape;

            this.maxWidth = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.width = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {

                LSystem.scaleWidth = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;

            }
            else if (mode == LMode.FitFill)
            {

                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                        maxWidth, maxHeight);
                maxWidth = res.width;
                maxHeight = res.height;
                LSystem.scaleWidth = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;

            }
            else if (mode == LMode.Ratio)
            {

                maxWidth = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;

            }
            else if (mode == LMode.MaxRatio)
            {

                maxWidth = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1)
                        || (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;

            }
            else
            {
                LSystem.scaleWidth = 1;
                LSystem.scaleHeight = 1;
            }

            LSystem.screenRect = new RectBox(0, 0, width, height);

            graphics.PreferredBackBufferFormat = displayMode.Format;
            graphics.PreferredBackBufferWidth = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (landscape)
            {
               graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            }
            else
            {
                graphics.SupportedOrientations = DisplayOrientation.Portrait;
            }

            //������Ⱦ����ʾ��ͬ��
            graphics.SynchronizeWithVerticalRetrace = true;
            graphics.PreferMultiSampling = true;

            #if WINDOWS
            graphics.IsFullScreen = false;
            IsMouseVisible = true;
            #elif XBOX || WINDOWS_PHONE
            //ȫ��
            graphics.IsFullScreen = true;
            #endif

            graphics.ApplyChanges();

            base.IsFixedTimeStep = false;

            isFPS = false;

            if (maxFrames <= 0)
            {
                SetFPS(LSystem.DEFAULT_MAX_FPS);
            }

            SetSleepTime(1);

            LSystem.screenActivity = this;
            LSystem.screenProcess = (process = new LProcess(this, width, height));

            StringBuilder sbr = new StringBuilder();
            sbr.Append("Mode:").Append(mode);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Width:").Append(width).Append(",Height:" + height);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("MaxWidth:").Append(maxWidth)
                    .Append(",MaxHeight:" + maxHeight);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Scale:").Append(IsScale());
            log.I(sbr.ToString());
        }
Exemplo n.º 5
0
 public void Initialization(int width, int height,
         bool landscape, LMode mode)
 {
     MaxScreen(width, height);
     Initialization(landscape, mode);
 }
Exemplo n.º 6
0
 public void Initialization(bool landscape, LMode mode)
 {
     Initialization(landscape, true, mode);
 }
Exemplo n.º 7
0
        public void Initialization(bool l,
                                   bool f, LMode m)
        {
            log.I("GPU surface");

            this.landscape  = l;
            this.fullScreen = f;
            this.mode       = m;

            if (landscape == false)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH  = tmp_height;
                }
            }

            this.CheckDisplayMode();

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = landscape;

            this.maxWidth  = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.width  = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width  = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.FitFill)
            {
                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                                                         maxWidth, maxHeight);
                maxWidth            = res.width;
                maxHeight           = res.height;
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.Ratio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.MaxRatio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) ||
                    (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else
            {
                LSystem.scaleWidth  = 1;
                LSystem.scaleHeight = 1;
            }

            LSystem.screenRect = new RectBox(0, 0, width, height);

            graphics.PreferredBackBufferFormat = displayMode.Format;
            graphics.PreferredBackBufferWidth  = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (landscape)
            {
                graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            }
            else
            {
                graphics.SupportedOrientations = DisplayOrientation.Portrait;
            }

            //画面渲染与显示器同步
            graphics.SynchronizeWithVerticalRetrace = true;
            graphics.PreferMultiSampling            = true;


#if WINDOWS
            graphics.IsFullScreen = false;
            IsMouseVisible        = true;
#elif XBOX || WINDOWS_PHONE
            //全屏
            graphics.IsFullScreen = true;
#endif


            graphics.ApplyChanges();

            base.IsFixedTimeStep = false;

            isFPS = false;

            if (maxFrames <= 0)
            {
                SetFPS(LSystem.DEFAULT_MAX_FPS);
            }

            SetSleepTime(1);

            LSystem.screenActivity = this;
            LSystem.screenProcess  = (process = new LProcess(this, width, height));

            StringBuilder sbr = new StringBuilder();
            sbr.Append("Mode:").Append(mode);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Width:").Append(width).Append(",Height:" + height);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("MaxWidth:").Append(maxWidth)
            .Append(",MaxHeight:" + maxHeight);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Scale:").Append(IsScale());
            log.I(sbr.ToString());
        }
Exemplo n.º 8
0
 public void Initialization(int width, int height,
                            bool landscape, LMode mode)
 {
     MaxScreen(width, height);
     Initialization(landscape, mode);
 }
Exemplo n.º 9
0
 public void Initialization(bool landscape, LMode mode)
 {
     Initialization(landscape, true, mode);
 }
Exemplo n.º 10
0
        protected virtual void UpdateViewSize(bool landscape, int width, int height, LMode mode)
        {
            RectBox d = GetScreenDimension();

            this.maxWidth  = MathUtils.Max((int)d.GetWidth(), 1);
            this.maxHeight = MathUtils.Max((int)d.GetHeight(), 1);

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.zoomWidth  = width;
                    this.zoomHeight = height;
                }
                else
                {
                    this.zoomWidth  = height;
                    this.zoomHeight = width;
                }
            }
            else
            {
                if (landscape)
                {
                    this.zoomWidth  = maxWidth >= width ? width : maxWidth;
                    this.zoomHeight = maxHeight >= height ? height : maxHeight;
                }
                else
                {
                    this.zoomWidth  = maxWidth >= height ? height : maxWidth;
                    this.zoomHeight = maxHeight >= width ? width : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {
                LSystem.SetScaleWidth(((float)maxWidth) / zoomWidth);
                LSystem.SetScaleHeight(((float)maxHeight) / zoomHeight);
            }
            else if (mode == LMode.FitFill)
            {
                RectBox res = FitLimitSize(zoomWidth, zoomHeight, maxWidth, maxHeight);
                maxWidth  = res.width;
                maxHeight = res.height;
                LSystem.SetScaleWidth(((float)maxWidth) / zoomWidth);
                LSystem.SetScaleHeight(((float)maxHeight) / zoomHeight);
            }
            else if (mode == LMode.Ratio)
            {
                float userAspect = (float)zoomWidth / (float)zoomHeight;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.SetScaleWidth(((float)maxWidth) / zoomWidth);
                LSystem.SetScaleHeight(((float)maxHeight) / zoomHeight);
            }
            else if (mode == LMode.MaxRatio)
            {
                float userAspect = (float)zoomWidth / (float)zoomHeight;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) || (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)zoomHeight / (float)zoomWidth;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.SetScaleWidth(((float)maxWidth) / zoomWidth);
                LSystem.SetScaleHeight(((float)maxHeight) / zoomHeight);
            }
            else
            {
                LSystem.SetScaleWidth(1f);
                LSystem.SetScaleHeight(1f);
            }
            UpdateViewSizeData(mode);
        }
Exemplo n.º 11
0
        protected override void Initialize()
        {
            LSystem.FreeStaticObject();

            if (_xnalistener != null)
            {
                _xnalistener.Initialize();
            }

            this.OnMain();

            if (_setting == null)
            {
                _setting = new MonoGameSetting();
            }
            LMode mode = _setting.showMode;

            if (mode == default)
            {
                mode = LMode.Fill;
            }

            float width  = _setting.width;
            float height = _setting.height;

            // 是否按比例缩放屏幕
            if (_setting.useRatioScaleFactor)
            {
                float scale = ScaleFactor();
                width  *= scale;
                height *= scale;
                _setting.width_zoom  = (int)width;
                _setting.height_zoom = (int)height;
                _setting.UpdateScale();
                mode = LMode.MaxRatio;
            }
            else if (!(PlatformInfo.MonoGamePlatform == MonoGamePlatform.DesktopGL || PlatformInfo.MonoGamePlatform == MonoGamePlatform.Windows || PlatformInfo.MonoGamePlatform == MonoGamePlatform.WindowsUniversal) && (_setting.width_zoom <= 0 || _setting.height_zoom <= 0))
            {
                UpdateViewSize(_setting.Landscape(), _setting.width, _setting.height, mode);
                width  = this.maxWidth;
                height = this.maxHeight;
                _setting.width_zoom  = this.maxWidth;
                _setting.height_zoom = this.maxHeight;
                _setting.UpdateScale();
                mode = LMode.Fill;
            }
            else
            {
                this.maxWidth   = _setting.width;
                this.maxHeight  = _setting.height;
                this.zoomWidth  = _setting.width_zoom;
                this.zoomHeight = _setting.height_zoom;
                UpdateViewSizeData(mode);
                _setting.UpdateScale();
            }

            Window.AllowUserResizing   = _setting.allowUserResizing;
            Window.Title               = _setting.appName;
            Window.OrientationChanged += OnOrientationChanged;
            Window.ClientSizeChanged  += OnClientSizeChanged;

#if WINDOWS || DEBUG
            IsMouseVisible = _setting.isMouseVisible;
#endif
            IsFixedTimeStep = _setting.isFixedTimeStep;

            _graphics.PreparingDeviceSettings += (object s, PreparingDeviceSettingsEventArgs args) =>
            {
                args.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
            };
            _graphics.DeviceReset += OnGraphicsDeviceReset;
            _graphics.PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8;
            _graphics.PreferredBackBufferFormat   = _displayMode.Format;
            _graphics.PreferredBackBufferWidth    = _setting.Width;
            _graphics.PreferredBackBufferHeight   = _setting.Height;
            _graphics.IsFullScreen = _setting.fullscreen;
            _graphics.SynchronizeWithVerticalRetrace = _setting.synchronizeVerticalRetrace;
            _graphics.PreferMultiSampling            = _setting.preferMultiSampling;

            if (_setting.Landscape())
            {
                _graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            }
            else
            {
                _graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.PortraitDown;
            }

            _graphics.ApplyChanges();

            base.Initialize();

            this.SetFPS(_setting.fps);
            this.InitializeGame();
        }
Exemplo n.º 12
0
        public void Initialization(bool l,
                                   bool f, LMode m)
        {
            log.I("GPU surface");

            this.landscape  = l;
            this.fullScreen = f;
            this.mode       = m;

            if (landscape == false)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH  = tmp_height;
                }
            }

            this.CheckDisplayMode();

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = landscape;

            this.maxWidth  = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.width  = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width  = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.FitFill)
            {
                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                                                         maxWidth, maxHeight);
                maxWidth            = res.width;
                maxHeight           = res.height;
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.Ratio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.MaxRatio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) ||
                    (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else
            {
                LSystem.scaleWidth  = 1;
                LSystem.scaleHeight = 1;
            }

            if (landscape)
            {
                GamePage.Orientation           = Microsoft.Phone.Controls.PageOrientation.Landscape | Microsoft.Phone.Controls.PageOrientation.LandscapeLeft | Microsoft.Phone.Controls.PageOrientation.LandscapeRight;
                GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Landscape;
            }
            else
            {
                GamePage.Orientation           = Microsoft.Phone.Controls.PageOrientation.Portrait | Microsoft.Phone.Controls.PageOrientation.PortraitDown | Microsoft.Phone.Controls.PageOrientation.PortraitUp;
                GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Portrait;
            }

            LSystem.screenRect = new RectBox(0, 0, width, height);

            graphics.PreferredBackBufferFormat = displayMode.Format;
            graphics.PreferredBackBufferWidth  = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (GamePage != null)
            {
                UIElementRenderer = new UIElementRenderer(GamePage, maxWidth, maxHeight);
            }

            //画面渲染与显示器同步
            graphics.SynchronizeWithVerticalRetrace = true;

            graphics.ApplyChanges();

            isFPS = false;

            if (maxFrames <= 0)
            {
                SetFPS(LSystem.DEFAULT_MAX_FPS);
            }

            LSystem.screenActivity = this;
            LSystem.screenProcess  = (process = new LProcess(this, width, height));

            StringBuilder sbr = new StringBuilder();

            sbr.Append("Mode:").Append(mode);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Width:").Append(width).Append(",Height:" + height);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("MaxWidth:").Append(maxWidth)
            .Append(",MaxHeight:" + maxHeight);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Scale:").Append(IsScale());
            log.I(sbr.ToString());

            if (GamePage != null)
            {
                GamePage.Background = null;
                GamePage.Foreground = null;
                GamePage.Style      = null;
                GamePage.AllowDrop  = false;
                GamePage.Visibility = System.Windows.Visibility.Collapsed;

                /*System.Windows.Interop.Settings settings = new System.Windows.Interop.Settings();
                 * settings.EnableFrameRateCounter = true;
                 * settings.EnableCacheVisualization = true;
                 * settings.EnableRedrawRegions = true;
                 * settings.MaxFrameRate = maxFrames;
                 * System.Windows.Media.BitmapCache cache = new System.Windows.Media.BitmapCache();
                 * cache.RenderAtScale = 1;
                 * GamePage.CacheMode = cache;*/
                GamePage.Opacity = 1f;
            }
        }
Exemplo n.º 13
0
        public void Initialization(bool l,
                bool f, LMode m)
        {
            log.I("GPU surface");

            this.landscape = l;
            this.fullScreen = f;
            this.mode = m;

            if (landscape == false)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH = tmp_height;
                }
            }

            this.CheckDisplayMode();

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = landscape;

            this.maxWidth = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.width = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {

                LSystem.scaleWidth = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;

            }
            else if (mode == LMode.FitFill)
            {

                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                        maxWidth, maxHeight);
                maxWidth = res.width;
                maxHeight = res.height;
                LSystem.scaleWidth = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;

            }
            else if (mode == LMode.Ratio)
            {

                maxWidth = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;

            }
            else if (mode == LMode.MaxRatio)
            {

                maxWidth = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1)
                        || (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;

            }
            else
            {
                LSystem.scaleWidth = 1;
                LSystem.scaleHeight = 1;
            }

            if (landscape)
            {
                GamePage.Orientation = Microsoft.Phone.Controls.PageOrientation.Landscape | Microsoft.Phone.Controls.PageOrientation.LandscapeLeft | Microsoft.Phone.Controls.PageOrientation.LandscapeRight;
                GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Landscape;
            }
            else
            {
                GamePage.Orientation = Microsoft.Phone.Controls.PageOrientation.Portrait | Microsoft.Phone.Controls.PageOrientation.PortraitDown | Microsoft.Phone.Controls.PageOrientation.PortraitUp;
                GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Portrait;
            }

            LSystem.screenRect = new RectBox(0, 0, width, height);

            graphics.PreferredBackBufferFormat = displayMode.Format;
            graphics.PreferredBackBufferWidth = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (GamePage != null)
            {
                UIElementRenderer = new UIElementRenderer(GamePage, maxWidth, maxHeight);
            }

            //������Ⱦ����ʾ��ͬ��
            graphics.SynchronizeWithVerticalRetrace = true;

            graphics.ApplyChanges();

            isFPS = false;

            if (maxFrames <= 0)
            {
                SetFPS(LSystem.DEFAULT_MAX_FPS);
            }

            LSystem.screenActivity = this;
            LSystem.screenProcess = (process = new LProcess(this, width, height));

            StringBuilder sbr = new StringBuilder();
            sbr.Append("Mode:").Append(mode);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Width:").Append(width).Append(",Height:" + height);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("MaxWidth:").Append(maxWidth)
                    .Append(",MaxHeight:" + maxHeight);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Scale:").Append(IsScale());
            log.I(sbr.ToString());

            if (GamePage != null)
            {
                GamePage.Background = null;
                GamePage.Foreground = null;
                GamePage.Style = null;
                GamePage.AllowDrop = false;
                GamePage.Visibility = System.Windows.Visibility.Collapsed;
                /*System.Windows.Interop.Settings settings = new System.Windows.Interop.Settings();
                settings.EnableFrameRateCounter = true;
                settings.EnableCacheVisualization = true;
                settings.EnableRedrawRegions = true;
                settings.MaxFrameRate = maxFrames;
                System.Windows.Media.BitmapCache cache = new System.Windows.Media.BitmapCache();
                cache.RenderAtScale = 1;
                GamePage.CacheMode = cache;*/
                GamePage.Opacity = 1f;
            }
        }