Beispiel #1
0
 private static void QuitSDL2()
 {
     SDL_ttf.TTF_Quit();
     SDL_image.IMG_Quit();
     SDL_mixer.Mix_Quit();
     SDL.SDL_Quit();
 }
        public void Dispose()
        {
            foreach (var disposable in _disposables)
            {
                disposable.Dispose();
            }

            if (HasRender)
            {
                SDL.SDL_DestroyRenderer(_renderer);
            }

            if (HasWindow)
            {
                SDL.SDL_DestroyWindow(_window);
            }

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

            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #3
0
        private static void Close()
        {
            //Free loaded images
            _PromptTexture.Free();

            //Free the sound effects
            SDL_mixer.Mix_FreeChunk(_Scratch);
            SDL_mixer.Mix_FreeChunk(_High);
            SDL_mixer.Mix_FreeChunk(_Medium);
            SDL_mixer.Mix_FreeChunk(_Low);
            _Scratch = IntPtr.Zero;
            _High    = IntPtr.Zero;
            _Medium  = IntPtr.Zero;
            _Low     = IntPtr.Zero;

            //Free the music
            SDL_mixer.Mix_FreeMusic(_Music);
            _Music = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(Renderer);
            SDL.SDL_DestroyWindow(_Window);
            _Window  = IntPtr.Zero;
            Renderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_mixer.Mix_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #4
0
        private static void close()
        {
            //Open data for writing
            //Create file for writing
            using (var bw = new BinaryWriter(File.OpenWrite("nums.bin"), Encoding.Default))
            {
                //Initialize data
                for (int i = 0; i < TOTAL_DATA; ++i)
                {
                    bw.Write(gData[i]);
                }
            }

            //Free loaded images
            gPromptTextTexture.free();
            for (int i = 0; i < TOTAL_DATA; ++i)
            {
                gDataTextures[i].free();
            }

            //Free global font
            SDL_ttf.TTF_CloseFont(gFont);
            gFont = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(gRenderer);
            SDL.SDL_DestroyWindow(gWindow);
            gWindow   = IntPtr.Zero;
            gRenderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_ttf.TTF_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
        private bool ReleaseAndQuit(IntPtr window, IntPtr renderer, IntPtr background, IntPtr image)
        {
            if (window != IntPtr.Zero)
            {
                SDL.SDL_DestroyWindow(window);
            }

            if (renderer != IntPtr.Zero)
            {
                SDL.SDL_DestroyRenderer(renderer);
            }

            if (background != IntPtr.Zero)
            {
                SDL.SDL_DestroyTexture(background);
            }

            if (image != IntPtr.Zero)
            {
                SDL.SDL_DestroyTexture(image);
            }

            SDL_image.IMG_Quit();
            SDL.SDL_Quit();

            return(false);
        }
Beispiel #6
0
 internal static void deinitialiser_2d()
 {
     foreach (var image in images)
     {
         SDL.SDL_DestroyTexture(image.Value);
     }
     images.Clear();
     SDL_image.IMG_Quit();
     for (int i = 0; i < 73; i++)
     {
         if (police[i] != IntPtr.Zero)
         {
             SDL_ttf.TTF_CloseFont(police[i]);
             police[i] = IntPtr.Zero;
         }
     }
     SDL_ttf.TTF_Quit();
     if (rendu != IntPtr.Zero)
     {
         SDL.SDL_DestroyRenderer(rendu);
         rendu = IntPtr.Zero;
     }
     if (fenetre != IntPtr.Zero)
     {
         SDL.SDL_DestroyWindow(fenetre);
         fenetre = IntPtr.Zero;
     }
 }
        private bool ReleaseAndQuit(IntPtr window, IntPtr renderer, IntPtr font, IntPtr image)
        {
            if (window != IntPtr.Zero)
            {
                SDL.SDL_DestroyWindow(window);
            }

            if (renderer != IntPtr.Zero)
            {
                SDL.SDL_DestroyRenderer(renderer);
            }

            if (font != IntPtr.Zero)
            {
                SDL_ttf.TTF_CloseFont(font);
            }

            if (image != IntPtr.Zero)
            {
                SDL.SDL_DestroyTexture(image);
            }

            SDL_image.IMG_Quit();
            SDL.SDL_Quit();

            return(false);
        }
Beispiel #8
0
 public void Dispose()
 {
     sceneRenderer.Dispose();
     Screen.Dispose();
     SDL_mixer.Mix_CloseAudio();
     SDL_mixer.Mix_Quit();
     SDL_ttf.TTF_Quit();
     SDL_image.IMG_Quit();
     SDL_Quit();
 }
Beispiel #9
0
        /// <summary>
        /// De-initialize SDL, SDL_image and SDL_ttf
        /// </summary>
        public static void QuitGraphics()
        {
            // Quit SDL
            SDL.SDL_Quit();

            // Quit SDL_image
            SDL_image.IMG_Quit();

            // Quit SDL_ttf
            SDL_ttf.TTF_Quit();
        }
Beispiel #10
0
        private static void Main(string[] args)
        {
            SDL.SDL_Init(SDL.SDL_INIT_EVERYTHING);
            SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG);

            var gameWindow = new GameWindow();

            gameWindow.Initialize();
            gameWindow.FrameLoop();

            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #11
0
        public void OpenImage()
        {
            var initResult = SDL_image.IMG_Init((int)SDL_image.IMG_InitFlags.IMG_INIT_PNG);
            var image      = SDL_image.IMG_Load("./Hi.png");

            Assert.NotEqual(IntPtr.Zero, image);

            var imageSurface = Marshal.PtrToStructure <SDL_surface.SDL_Surface>(image);

            Assert.Equal(400, imageSurface.w);
            Assert.Equal(400, imageSurface.h);

            SDL_image.IMG_Quit();
        }
Beispiel #12
0
        private static void Close()
        {
            //Free loaded image
            SDL.SDL_FreeSurface(_PngSurface);
            _PngSurface = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyWindow(_Window);
            _Window = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #13
0
        private static void close()
        {
            //Free loaded images
            gSceneTexture.free();

            //Destroy window
            SDL.SDL_DestroyRenderer(gRenderer);
            gWindow.free();
            gRenderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #14
0
        private static void Close()
        {
            //Free loaded images
            _SpriteSheetTexture.Free();

            //Destroy window
            SDL.SDL_DestroyRenderer(Renderer);
            SDL.SDL_DestroyWindow(_Window);
            _Window  = IntPtr.Zero;
            Renderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #15
0
        private static void Close()
        {
            //Free loaded image
            SDL.SDL_DestroyTexture(_Texture);
            _Texture = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(_Renderer);
            SDL.SDL_DestroyWindow(_Window);
            _Window   = IntPtr.Zero;
            _Renderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #16
0
        protected virtual void Dispose(bool disposing)
        {
            if (Window != null)
            {
                Window.Dispose();
            }

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

            SDL_ttf.TTF_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
            RaiseEvent(Disposed, EventArgs.Empty);
        }
Beispiel #17
0
        private static void DestroySDL(ref IntPtr win, ref IntPtr ren)
        {
            scene.Dispose();

            if (ren != IntPtr.Zero)
            {
                SDL.SDL_DestroyRenderer(ren);
                ren = IntPtr.Zero;
            }

            if (win != IntPtr.Zero)
            {
                SDL.SDL_DestroyWindow(win);
                win = IntPtr.Zero;
            }
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #18
0
        private static void Close()
        {
            //Free loaded images
            _SplashTexture.Free();

            //Close game controller
            SDL.SDL_JoystickClose(_GameController);
            _GameController = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(Renderer);
            SDL.SDL_DestroyWindow(_Window);
            _Window  = IntPtr.Zero;
            Renderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #19
0
        private static void Close()
        {
            //Free loaded images
            _PressTexture.Free();
            _UpTexture.Free();
            _DownTexture.Free();
            _LeftTexture.Free();
            _RightTexture.Free();

            //Destroy window
            SDL.SDL_DestroyRenderer(Renderer);
            SDL.SDL_DestroyWindow(_Window);
            _Window  = IntPtr.Zero;
            Renderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #20
0
        private static void Close()
        {
            //Free loaded images
            _TextTexture.Free();

            //Free global font
            SDL_ttf.TTF_CloseFont(Font);
            Font = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(Renderer);
            SDL.SDL_DestroyWindow(_Window);
            _Window  = IntPtr.Zero;
            Renderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_ttf.TTF_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #21
0
        private static void close()
        {
            //Free loaded images
            gFPSTextTexture.free();

            //Free global font
            SDL_ttf.TTF_CloseFont(gFont);
            gFont = IntPtr.Zero;

            //Destroy window
            SDL.SDL_DestroyRenderer(gRenderer);
            SDL.SDL_DestroyWindow(gWindow);
            gWindow   = IntPtr.Zero;
            gRenderer = IntPtr.Zero;

            //Quit SDL subsystems
            SDL_ttf.TTF_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #22
0
        void GEALOSprog()
        {
            init();

            while (running)
            {
                time.update();

                while (SDL.SDL_PollEvent(out SDL.SDL_Event e) == 1)
                {
                    switch (e.type)
                    {
                    case SDL.SDL_EventType.SDL_QUIT:
                        running = false;
                        break;

                    case SDL.SDL_EventType.SDL_KEYDOWN:
                        input.setPress(e.key.keysym.sym, true);
                        break;

                    case SDL.SDL_EventType.SDL_KEYUP:
                        if (e.key.repeat == 0)
                        {
                            input.setPress(e.key.keysym.sym, false);
                        }
                        break;
                    }
                }

                update();
            }

            SDL_mixer.Mix_Quit();
            SDL_ttf.TTF_Quit();
            SDL_image.IMG_Quit();
            SDL.SDL_Quit();
        }
Beispiel #23
0
        internal static int initialiser_2d()
        {
            fenetre = SDL.SDL_CreateWindow("TNTMan", SDL.SDL_WINDOWPOS_UNDEFINED, SDL.SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);
            if (fenetre == IntPtr.Zero)
            {
                Program.MessageErr("SDL_CreateWindow: ERREUR ({0})\n", SDL.SDL_GetError());
                SDL.SDL_Quit();
                return(2);
            }

            rendu = SDL.SDL_CreateRenderer(fenetre, -1, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);
            if (rendu == IntPtr.Zero)
            {
                Program.MessageErr("SDL_CreateRenderer: ERREUR ({0})\n", SDL.SDL_GetError());
                SDL.SDL_DestroyWindow(fenetre);
                SDL.SDL_Quit();
                return(3);
            }

            if (SDL_ttf.TTF_Init() == -1)
            {
                Program.MessageErr("TTF_Init: ERREUR ({0})", SDL.SDL_GetError());
                SDL.SDL_DestroyRenderer(rendu);
                SDL.SDL_DestroyWindow(fenetre);
                SDL.SDL_Quit();
                return(4);
            }

            police = new IntPtr[73];
            for (int i = 1; i < 73; i++)
            {
                police[i] = SDL_ttf.TTF_OpenFont("res/font.ttf", i);
                if (police[i] == IntPtr.Zero)
                {
                    Program.MessageErr("TTF_OpenFont: TAILLE ({0}), ERREUR ({1})", i, SDL.SDL_GetError());
                    SDL_ttf.TTF_Quit();
                    SDL.SDL_DestroyRenderer(rendu);
                    SDL.SDL_DestroyWindow(fenetre);
                    SDL.SDL_Quit();
                    return(5);
                }
            }

            if (SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG) == -1)
            {
                Program.MessageErr("IMG_Init: ERREUR ({0})\n", SDL.SDL_GetError());
                SDL.SDL_DestroyRenderer(rendu);
                SDL.SDL_DestroyWindow(fenetre);
                SDL.SDL_Quit();
                return(4);
            }

            if (prechargerImages() > 0)
            {
                Program.MessageErr("prechargerImages: ERREUR ({0})\n", SDL.SDL_GetError());
                SDL_image.IMG_Quit();
                SDL.SDL_DestroyRenderer(rendu);
                SDL.SDL_DestroyWindow(fenetre);
                SDL.SDL_Quit();
                return(5);
            }

            changerEcran(new Ecran_Titre());

            return(0);
        }
Beispiel #24
0
 public override void Cleanup()
 {
     SDL_ttf.TTF_Quit();
     SDL_image.IMG_Quit();
     SDL2.SDL.SDL_Quit();
 }
Beispiel #25
0
 /// <summary>
 /// Destroys the memory objects related to this element.
 /// </summary>
 public void Shutdown()
 {
     SDL_image.IMG_Quit();
 }
Beispiel #26
0
        public static void Run <TGame>(GameInfo info, string[] args) where TGame : IGame, new()
        {
            bool sdlInitialised        = false;
            bool sdlImageInitialised   = false;
            bool steamworksInitialised = false;

            try
            {
                // Store info
                Info = info;

                // Get commandline arguments
                Arguments = new ProgramArguments(args);

                // Determine platform
                string platformString = SDL.SDL_GetPlatform();
                switch (platformString)
                {
                case "Windows":
                {
                    Platform = Platform.Windows;
                    break;
                }

                case "Mac OS X":
                {
                    Platform = Platform.OSX;
                    break;
                }

                case "Linux":
                {
                    Platform = Platform.Linux;
                    break;
                }

                default:
                {
                    Platform = Platform.Unknown;
                    break;
                }
                }

                // Print App Info
                if (App.Debug && App.Steam)
                {
                    Log("{0} {1} (Steam Debug build)", Info.Title, Info.Version);
                }
                else if (App.Debug)
                {
                    Log("{0} {1} (Debug build)", Info.Title, Info.Version);
                }
                else if (App.Steam)
                {
                    Log("{0} {1} (Steam build)", Info.Title, Info.Version);
                }
                else
                {
                    Log("{0} {1}", Info.Title, Info.Version);
                }
                if (!Arguments.IsEmpty)
                {
                    Log("Command Line Arguments: {0}", Arguments);
                }
                Log("Developed by {0} ({1})", Info.DeveloperName, Info.DeveloperEmail);
                Log("Platform: {0} ({1})", Platform, platformString);

                // Setup Steamworks
                if (App.Steam)
                {
                    // Relaunch game under Steam if launched externally
                    if (!App.Debug)
                    {
                        if (File.Exists("steam_appid.txt"))
                        {
                            File.Delete("steam_appid.txt");
                        }

                        AppId_t appID = (Info.SteamAppID > 0) ? new AppId_t(Info.SteamAppID) : AppId_t.Invalid;
                        if (SteamAPI.RestartAppIfNecessary(appID))
                        {
                            Log("Relaunching game in Steam");
                            return;
                        }
                    }

                    // Initialise Steamworks
                    if (!SteamAPI.Init())
                    {
                        throw new SteamworksException("SteamAPI_Init", "If you have just installed " + App.Info.Title + " for the first time, try restarting Steam");
                    }
                    Log("Steamworks initialised");
                    steamworksInitialised = true;
                }

                // Print SDL version
                SDL.SDL_version version;
                SDL.SDL_GetVersion(out version);
                Log("SDL version: {0}.{1}.{2}", version.major, version.minor, version.patch);

                // Setup SDL
                SDL.SDL_SetHint(SDL.SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, "1");
                SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
                CheckSDLResult("SDL_Init", SDL.SDL_Init(
                                   SDL.SDL_INIT_VIDEO |
                                   SDL.SDL_INIT_AUDIO |
                                   SDL.SDL_INIT_GAMECONTROLLER |
                                   SDL.SDL_INIT_JOYSTICK |
                                   SDL.SDL_INIT_HAPTIC
                                   ));
                Log("SDL2 Initialised");
                sdlInitialised = true;

                CheckSDLResult("IMG_Init", SDL_image.IMG_Init(
                                   SDL_image.IMG_InitFlags.IMG_INIT_PNG
                                   ));
                sdlImageInitialised = true;
                Log("SDL2_Image initialised");

                // Determine save path
                InitSavePath();
                StartLogging();

                // Determine asset directory
                if (App.Debug)
                {
                    AssetPath = "../../assets";
                }
                else
                {
                    if (App.Platform == Platform.OSX)
                    {
                        AssetPath = "assets";
                    }
                    else
                    {
                        string basePath = SDL.SDL_GetBasePath();
                        AssetPath = Path.Combine(basePath, "assets");
                    }
                }
                if (!Directory.Exists(AssetPath))
                {
                    throw new IOException
                          (
                              "Could not locate assets directory (" + AssetPath + ")" + Environment.NewLine +
                              "This must be provided from a legal copy of " + App.Info.Title + ". Visit " + App.Info.Website + " for more info."
                          );
                }

                // Register asset types
                RegisterAssetTypes();

                // Load controller database
                var gameControllerDBPath = Path.Combine(AssetPath, "gamecontrollerdb.txt");
                if (File.Exists(gameControllerDBPath))
                {
                    try
                    {
                        CheckSDLResult("SDL_GameControllerAddMappingsFromFile", SDL.SDL_GameControllerAddMappingsFromFile(gameControllerDBPath));
                        App.Log("Loaded gamepad mappings from gamecontrollerdb.txt");
                    }
                    catch (SDLException)
                    {
                        App.Log("Error: Failed to load gamepad mappings from gamecontrollerdb.txt");
                    }
                }
                else
                {
                    App.Log("Error: gamecontrollerdb.txt not found");
                }

                // Create game
                using (var game = new Game.Game.Game())
                {
                    App.CheckOpenGLError();

                    // Main loop
                    uint lastFrameStart = SDL.SDL_GetTicks();
                    while (!game.Over)
                    {
                        // Get time
                        uint frameStart = SDL.SDL_GetTicks();
                        uint delta      = frameStart - lastFrameStart;
                        FPS = 0.8f * FPS + 0.2f * ((delta > 0) ? (1000.0f / (float)delta) : 1000.0f);
                        float dt = Math.Max((float)delta / 1000.0f, 0.0f);

                        // Handle SDL events
                        SDL.SDL_Event e;
                        while (!game.Over && SDL.SDL_PollEvent(out e) != 0)
                        {
                            // Pass event to game
                            game.HandleEvent(ref e);
                        }

                        // Handle Steamworks events
                        if (!game.Over && App.Steam)
                        {
                            SteamAPI.RunCallbacks();
                        }

                        // Update game
                        if (!game.Over)
                        {
                            game.Update(dt);
                        }

                        // Render game
                        if (!game.Over)
                        {
                            game.Render();
                            App.CheckOpenGLError();
                            RenderStats.EndFrame();
                        }

                        // Sleep if necessary
                        if (!game.Over)
                        {
                            uint minFrameTime = 1000 / MAX_FPS;
                            uint frameTime    = (SDL.SDL_GetTicks() - frameStart);
                            if (frameTime < minFrameTime)
                            {
                                // SDL.SDL_Delay(minFrameTime - frameTime);
                            }
                        }

                        // Update timer for next frame
                        lastFrameStart = frameStart;
                    }
                }
            }
#if !DEBUG
            catch (Exception e)
            {
                // Log error to console
                string message = string.Format("Game crashed with {0}: {1}", e.GetType().FullName, e.Message);
                Log(message);
                Log(e.StackTrace);
                while ((e = e.InnerException) != null)
                {
                    Log("Caused by {0}: {1}", e.GetType().FullName, e.Message);
                    Log(e.StackTrace);
                }

                // Open an emergency log file if necessary
                if (LogFile == null)
                {
                    try
                    {
                        LogFilePath = "log.txt";
                        Log("Logging to " + LogFilePath);
                        LogFile = new StreamWriter("log.txt");
                        for (int i = 0; i < EarlyLogText.Count; ++i)
                        {
                            LogFile.WriteLine(EarlyLogText[i]);
                        }
                        EarlyLogText.Clear();
                        LogFile.Flush();
                    }
                    catch (IOException)
                    {
                        Log("Failed to open log file");
                        LogFilePath = null;
                    }
                }

                // Pop up the message box
                //if( sdlInitialised ) // The docs say SDL doesn't need to be inited to call ShowSimpleMessageBox
                {
                    try
                    {
                        if (LogFilePath != null)
                        {
                            message += Environment.NewLine;
                            message += Environment.NewLine;
                            message += "Callstack written to " + LogFilePath;
                        }

                        CheckSDLResult("SDL_ShowSimpleMessageBox", SDL.SDL_ShowSimpleMessageBox(
                                           SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
                                           Info.Title + " " + Info.Version,
                                           message,
                                           IntPtr.Zero
                                           ));
                    }
                    catch (SDLException e2)
                    {
                        Log(e2.Message);
                    }
                }
            }
#endif
            finally
            {
                // Shutdown SDL
                if (sdlImageInitialised)
                {
                    SDL_image.IMG_Quit();
                    Log("SDL2_Image shut down");
                }
                if (sdlInitialised)
                {
                    SDL.SDL_Quit();
                    Log("SDL2 shut down");
                }

                // Shutdown Steamworks
                if (steamworksInitialised)
                {
                    SteamAPI.Shutdown();
                    Log("Steamworks shut down");
                }

                // Close the log file
                if (LogFile != null)
                {
                    Log("Closing log file");
                    LogFile.Dispose();
                    LogFile = null;
                    Log("Log file closed");
                }

                // Quit
                Log("Quitting");
            }
        }
Beispiel #27
0
 /// <summary>Override to dispose of any custom objects that you've instantiated. Always call
 /// base.Dispose() so that the base class objects are disposed as well.
 /// </summary>
 /// <param name="disposing"></param>
 private void Dispose(bool disposing)
 {
     SDL_ttf.TTF_Quit();
     SDL_image.IMG_Quit();
     SDL.SDL_Quit();
 }