示例#1
0
        public SDL2_GamePlatform(Game game) : base(game)
        {
            // Set and initialize the SDL2 window
            INTERNAL_window      = new SDL2_GameWindow();
            INTERNAL_window.Game = game;
            this.Window          = INTERNAL_window;

            // Get our OpenALSoundController to handle the SoundBuffer pools
            soundControllerInstance = OpenALSoundController.GetInstance;
        }
示例#2
0
        public SDL2_GamePlatform(Game game) : base(game)
        {
            // Assign the OSVersion string
            OSVersion = SDL.SDL_GetPlatform();

            // Set and initialize the SDL2 window
            INTERNAL_window = new SDL2_GameWindow(game, this);
            this.Window     = INTERNAL_window;

            // Create the OpenAL device
            new OpenALDevice();
        }
示例#3
0
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (INTERNAL_window != null)
                {
                    INTERNAL_window.INTERNAL_Destroy();
                    INTERNAL_window = null;
                }

                if (OpenALDevice.Instance != null)
                {
                    OpenALDevice.Instance.Dispose();
                }
            }

            base.Dispose(disposing);
        }
示例#4
0
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
                if (INTERNAL_window != null)
                {
                    INTERNAL_window.INTERNAL_Destroy();
                    INTERNAL_window = null;
                }

                if (soundControllerInstance != null)
                {
                    soundControllerInstance.Dispose();
                    soundControllerInstance = null;
                }
            }

            base.Dispose(disposing);
        }
示例#5
0
		public SDL2_GamePlatform(Game game) : base(game, SDL.SDL_GetPlatform())
		{
			/* SDL2 might complain if an OS that uses SDL_main has not actually
			 * used SDL_main by the time you initialize SDL2.
			 * The only platform that is affected is Windows, but we can skip
			 * their WinMain. This was only added to prevent iOS from exploding.
			 * -flibit
			 */
			SDL.SDL_SetMainReady();

			// This _should_ be the first real SDL call we make...
			SDL.SDL_Init(
				SDL.SDL_INIT_VIDEO |
				SDL.SDL_INIT_JOYSTICK |
				SDL.SDL_INIT_GAMECONTROLLER |
				SDL.SDL_INIT_HAPTIC
			);

			// Set any hints to match XNA4 behavior...
			string hint = SDL.SDL_GetHint(SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);
			if (String.IsNullOrEmpty(hint))
			{
				SDL.SDL_SetHint(
					SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
					"1"
				);
			}

			// If available, load the SDL_GameControllerDB
			string mappingsDB = Path.Combine(
				TitleContainer.Location,
				"gamecontrollerdb.txt"
			);
			if (File.Exists(mappingsDB))
			{
				SDL.SDL_GameControllerAddMappingsFromFile(
					mappingsDB
				);
			}

			// Set and initialize the SDL2 window
			bool forceES2 = Environment.GetEnvironmentVariable(
				"FNA_OPENGL_FORCE_ES2"
			) == "1";
            bool forceES3 = Environment.GetEnvironmentVariable(
				"FNA_OPENGL_FORCE_ES3"
			) == "1";
			bool forceCoreProfile = Environment.GetEnvironmentVariable(
				"FNA_OPENGL_FORCE_CORE_PROFILE"
			) == "1";
			Window = new SDL2_GameWindow(
				!forceES3 && (forceES2 ||
				OSVersion.Equals("Emscripten") ||
				OSVersion.Equals("Android") ||
				OSVersion.Equals("iOS")),
                forceES3,
				forceCoreProfile
			);

			// Create the DisplayMode list
			displayIndex = SDL.SDL_GetWindowDisplayIndex(
				Window.Handle
			);
			INTERNAL_GenerateDisplayModes();

			// Disable the screensaver.
			SDL.SDL_DisableScreenSaver();

			// We hide the mouse cursor by default.
			if (IsMouseVisible)
			{
				IsMouseVisible = false;
			}
			else
			{
				/* Since IsMouseVisible is already false, OnMouseVisibleChanged
				 * will NOT be called! So we get to do it ourselves.
				 * -flibit
				 */
				SDL.SDL_ShowCursor(0);
			}

			// OSX has some fancy fullscreen features, let's use them!
			if (OSVersion.Equals("Mac OS X"))
			{
				hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
				INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
			}
			else
			{
				INTERNAL_useFullscreenSpaces = false;
			}

			// Initialize Active Key List
			keys = new List<Keys>();

			// Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
			INTERNAL_TextInputControlDown = new bool[4];
			INTERNAL_TextInputControlRepeat = new int[4];

			// Assume we will have focus.
			IsActive = true;

			// Ready to run the loop!
			INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
			wiiuStream = DRC.drc_new_streamer();
			if (wiiuStream == IntPtr.Zero)
			{
				System.Console.WriteLine("Failed to alloc GamePad stream!");
				return;
			}
			if (DRC.drc_start_streamer(wiiuStream) < 1) // ???
			{
				System.Console.WriteLine("Failed to start GamePad stream!");
				DRC.drc_delete_streamer(wiiuStream);
				wiiuStream = IntPtr.Zero;
				return;
			}
			DRC.drc_enable_system_input_feeder(wiiuStream);
			Rectangle bounds = Window.ClientBounds;
			wiiuPixelData = new byte[bounds.Width * bounds.Height * 4];
#endif
		}
示例#6
0
        public SDL2_GamePlatform(Game game) : base(game, SDL.SDL_GetPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set and initialize the SDL2 window
            Window = new SDL2_GameWindow();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                string hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Create OpenGL context
            INTERNAL_GLContext = SDL.SDL_GL_CreateContext(Window.Handle);
            OpenTK.Graphics.GraphicsContext.CurrentContext = INTERNAL_GLContext;

#if THREADED_GL
            // Create a background context
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
            Threading.WindowInfo        = Window.Handle;
            Threading.BackgroundContext = new GL_ContextHandle()
            {
                context = SDL.SDL_GL_CreateContext(Window.Handle)
            };

            // Make the foreground context current.
            SDL.SDL_GL_MakeCurrent(Window.Handle, INTERNAL_GLContext);
#endif

            // Set up the OpenGL Device. Loads entry points.
            OpenGLDevice.Initialize();

            // Create the OpenAL device
            OpenALDevice.Initialize();

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            wiiuPixelData = new byte[
                OpenGLDevice.Instance.Backbuffer.Width *
                OpenGLDevice.Instance.Backbuffer.Height *
                4
                            ];
#endif
        }
示例#7
0
        public SDL2_GamePlatform(Game game)
            : base(game, SDL.SDL_GetPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
            );

            // Set and initialize the SDL2 window
            Window = new SDL2_GameWindow();

            // Create the DisplayMode list
            displayIndex = SDL.SDL_GetWindowDisplayIndex(
                Window.Handle
            );
            INTERNAL_GenerateDisplayModes();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                string hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Create the OpenAL device
            OpenALDevice.Initialize();

            // Initialize Active Key List
            keys = new List<Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

            #if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1) // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            Rectangle bounds = Window.ClientBounds;
            wiiuPixelData = new byte[bounds.Width * bounds.Height * 4];
            #endif
        }
示例#8
0
		public static GameWindow CreateWindow()
		{
			// GLContext environment variables
			bool forceES2 = Environment.GetEnvironmentVariable(
				"FNA_OPENGL_FORCE_ES2"
			) == "1";
			bool forceCoreProfile = Environment.GetEnvironmentVariable(
				"FNA_OPENGL_FORCE_CORE_PROFILE"
			) == "1";

			// Set and initialize the SDL2 window
			GameWindow result = new SDL2_GameWindow(
				forceES2 ||
				OSVersion.Equals("Emscripten") ||
				OSVersion.Equals("Android") ||
				OSVersion.Equals("iOS"),
				forceCoreProfile
			);

			// Disable the screensaver.
			SDL.SDL_DisableScreenSaver();

			// We hide the mouse cursor by default.
			SDL.SDL_ShowCursor(0);

			return result;
		}
示例#9
0
        public SDL2_GamePlatform(Game game) : base(game, SDL.SDL_GetPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set any hints to match XNA4 behavior...
            string hint = SDL.SDL_GetHint(SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS);

            if (String.IsNullOrEmpty(hint))
            {
                SDL.SDL_SetHint(
                    SDL.SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
                    "1"
                    );
            }

            // If available, load the SDL_GameControllerDB
            string mappingsDB = Path.Combine(
                TitleContainer.Location,
                "gamecontrollerdb.txt"
                );

            if (File.Exists(mappingsDB))
            {
                SDL.SDL_GameControllerAddMappingsFromFile(
                    mappingsDB
                    );
            }

            // Set and initialize the SDL2 window
            bool forceES2 = Environment.GetEnvironmentVariable(
                "FNA_OPENGL_FORCE_ES2"
                ) == "1";

            Window = new SDL2_GameWindow(
                forceES2 ||
                OSVersion.Equals("Emscripten") ||
                OSVersion.Equals("Android") ||
                OSVersion.Equals("iOS")
                );

            // Create the DisplayMode list
            displayIndex = SDL.SDL_GetWindowDisplayIndex(
                Window.Handle
                );
            INTERNAL_GenerateDisplayModes();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            Rectangle bounds = Window.ClientBounds;
            wiiuPixelData = new byte[bounds.Width * bounds.Height * 4];
#endif
        }
示例#10
0
        public SDL2_GamePlatform(Game game) : base(game, Fna.FnaPlatform.Platform.GetSDLPlatform())
        {
            /* SDL2 might complain if an OS that uses SDL_main has not actually
             * used SDL_main by the time you initialize SDL2.
             * The only platform that is affected is Windows, but we can skip
             * their WinMain. This was only added to prevent iOS from exploding.
             * -flibit
             */
            SDL.SDL_SetMainReady();

            // This _should_ be the first real SDL call we make...
            SDL.SDL_Init(
                SDL.SDL_INIT_VIDEO |
                SDL.SDL_INIT_JOYSTICK |
                SDL.SDL_INIT_GAMECONTROLLER |
                SDL.SDL_INIT_HAPTIC
                );

            // Set and initialize the SDL2 window
            Window = new SDL2_GameWindow();

            // Create the DisplayMode list
            displayIndex = SDL.SDL_GetWindowDisplayIndex(
                Window.Handle
                );
            INTERNAL_GenerateDisplayModes();

            // Disable the screensaver.
            SDL.SDL_DisableScreenSaver();

            // We hide the mouse cursor by default.
            if (IsMouseVisible)
            {
                IsMouseVisible = false;
            }
            else
            {
                /* Since IsMouseVisible is already false, OnMouseVisibleChanged
                 * will NOT be called! So we get to do it ourselves.
                 * -flibit
                 */
                SDL.SDL_ShowCursor(0);
            }

            // OSX has some fancy fullscreen features, let's use them!
            if (OSVersion.Equals("Mac OS X"))
            {
                string hint = SDL.SDL_GetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES);
                INTERNAL_useFullscreenSpaces = (String.IsNullOrEmpty(hint) || hint.Equals("1"));
            }
            else
            {
                INTERNAL_useFullscreenSpaces = false;
            }

            // Create the OpenAL device
            OpenALDevice.Initialize();

            // Initialize Active Key List
            keys = new List <Keys>();

            // Setup Text Input Control Character Arrays (Only 4 control keys supported at this time)
            INTERNAL_TextInputControlDown   = new bool[4];
            INTERNAL_TextInputControlRepeat = new int[4];

            // Assume we will have focus.
            IsActive = true;

            // Ready to run the loop!
            INTERNAL_runApplication = true;

#if WIIU_GAMEPAD
            wiiuStream = DRC.drc_new_streamer();
            if (wiiuStream == IntPtr.Zero)
            {
                System.Console.WriteLine("Failed to alloc GamePad stream!");
                return;
            }
            if (DRC.drc_start_streamer(wiiuStream) < 1)             // ???
            {
                System.Console.WriteLine("Failed to start GamePad stream!");
                DRC.drc_delete_streamer(wiiuStream);
                wiiuStream = IntPtr.Zero;
                return;
            }
            DRC.drc_enable_system_input_feeder(wiiuStream);
            Rectangle bounds = Window.ClientBounds;
            wiiuPixelData = new byte[bounds.Width * bounds.Height * 4];
#endif
        }