Exemplo n.º 1
0
        public static DialogResult Show(string text)
        {
            if (!Disable)
            {
                var gameRunner = GameRunner.Singleton;
                var activity   = gameRunner.Activity;
                if (gameRunner.InModal || activity == null ||
                    android.os.Looper.getMainLooper().getThread()
                    == java.lang.Thread.currentThread())
                {
                    GameRunner.Log(text);
                }
                else
                {
                    gameRunner.PauseGame(true);

                    var waitObj = new android.os.ConditionVariable();
                    Show(activity, text, (_) => waitObj.open());
                    waitObj.block();

                    gameRunner.ResumeGame(true);
                }
            }
            return(DialogResult.OK);
        }
Exemplo n.º 2
0
        //
        // CanResume
        //

        public static bool CanResume(android.app.Activity activity)
        {
            foreach (var renderer in GetRenderersForActivity(activity))
            {
                if (renderer.paused.get() != 0)
                {
                    // we cannot use waitObject for resuming, because the surface
                    // may have been destroyed between pause and resume, in which
                    // case onDrawFrame would not get called.

                    var cond = new android.os.ConditionVariable();
                    renderer.surface.queueEvent(((java.lang.Runnable.Delegate)(
                                                     () => cond.open())).AsInterface());

                    renderer.surface.onResume();
                    if (!cond.block(2000))
                    {
                        // something is wrong if the queued event did not run
                        return(false);
                    }

                    if (!renderer.paused.compareAndSet(1, 0))
                    {
                        // cannot resume because we lost the GL context,
                        // see also PauseRenderers and onSurfaceCreated
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        //
        // constructor
        //

        private Renderer(android.app.Activity activity, Action onChanged,
                         int redSize, int greenSize, int blueSize,
                         int alphaSize, int depthSize, int stencilSize,
                         int swapInterval, bool checkErrors)
        {
            waitObject        = new android.os.ConditionVariable();
            paused            = new java.util.concurrent.atomic.AtomicInteger();
            actionOnChanged   = onChanged;
            this.swapInterval = swapInterval;
            this.checkErrors  = checkErrors;

            activity.runOnUiThread(((java.lang.Runnable.Delegate)(() =>
            {
                surface = new android.opengl.GLSurfaceView(activity);
                surface.setEGLContextClientVersion(3); // OpenGL ES 3.0
                surface.setEGLConfigChooser(redSize, greenSize, blueSize,
                                            alphaSize, depthSize, stencilSize);
                surface.setPreserveEGLContextOnPause(true);
                surface.setRenderer(this);
                surface.setRenderMode(android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY);
                activity.setContentView(surface);
            })).AsInterface());

            // wait for one onDrawFrame callback, which tells us that
            // GLSurfaceView finished initializing the GL context
            if (!waitObject.block(8000))
            {
                throw new NoSuitableGraphicsDeviceException("cannot create GLSurfaceView");
            }

            var clientBounds = GameRunner.Singleton.ClientBounds;

            if (SurfaceWidth != clientBounds.Width || SurfaceHeight != clientBounds.Height)
            {
                // while not common, it is possible for the screen to rotate,
                // between the time the Window/GameRunner is created, and the
                // time the renderer is created.  we want to identify this.
                if (actionOnChanged != null)
                {
                    actionOnChanged();
                }
            }
        }
Exemplo n.º 4
0
        //
        // constructor
        //

        public GameRunner(Activity activity)
        {
            this.activity = activity;

            // in Bluebonnet, the following method is used to specify the
            // size that Marshal.SizeOf should return for non-primitive types.
            // this is used to enable Texture2D.GetData/SetData to accept
            // Color[] arrays.  see also SetTextureData in FNA3D_Tex
            System.Runtime.InteropServices.Marshal.SetComObjectData(
                typeof(System.Runtime.InteropServices.Marshal),
                typeof(Color), -1);

            UpdateConfiguration();

            inModal       = new java.util.concurrent.atomic.AtomicInteger();
            shouldPause   = new java.util.concurrent.atomic.AtomicInteger();
            shouldResume  = new java.util.concurrent.atomic.AtomicInteger();
            shouldExit    = new java.util.concurrent.atomic.AtomicInteger();
            shouldEvents  = new java.util.concurrent.atomic.AtomicInteger();
            waitForPause  = new android.os.ConditionVariable();
            waitForResume = new android.os.ConditionVariable();
        }