Example #1
0
        internal static int initialiser_son()
        {
            if (SDL_mixer.Mix_OpenAudio(44100, SDL_mixer.MIX_DEFAULT_FORMAT, SDL_mixer.MIX_DEFAULT_CHANNELS, 1024) < 0)
            {
                Program.MessageErr("Mix_OpenAudio: ERREUR ({0})\n", SDL.SDL_GetError());
                SDL.SDL_Quit();
                return(1);
            }

            if (prechargerSons() > 0)
            {
                Program.MessageErr("prechargerSons: ERREUR ({0})\n", SDL.SDL_GetError());
                SDL_mixer.Mix_CloseAudio();
                SDL.SDL_Quit();
                return(2);
            }

            if (prechargerMusiques() > 0)
            {
                Program.MessageErr("prechargerMusiques: ERREUR ({0})\n", SDL.SDL_GetError());
                SDL_mixer.Mix_CloseAudio();
                SDL.SDL_Quit();
                return(3);
            }

            SDL_mixer.Mix_AllocateChannels(sons.Count);
            ArreterJouerSons();
            ReglerVolumeSons(50);
            ReglerVolumeMusique(50);

            return(0);
        }
Example #2
0
 internal static void closeMixer()
 {
     if (initialized)
     {
         SDL_mixer.Mix_CloseAudio();
         initialized = false;
     }
 }
Example #3
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();
 }
Example #4
0
 internal static void deinitialiser_son()
 {
     foreach (var musique in musiques)
     {
         SDL_mixer.Mix_FreeMusic(musique.Value);
     }
     musiques.Clear();
     foreach (var son in sons)
     {
         SDL_mixer.Mix_FreeChunk(son.Value);
     }
     sons.Clear();
     SDL_mixer.Mix_CloseAudio();
 }
    public static void Main()
    {
        int    audio_rate     = 44100;
        ushort audio_format   = SDL.AUDIO_S16SYS;
        int    audio_channels = 2;
        int    audio_buffers  = 4096;
        int    audio_volume   = SDL_mixer.MIX_MAX_VOLUME;
        int    timeleft       = 50;

        SDL.SDL_Init(SDL.SDL_INIT_AUDIO);
        if (SDL_mixer.Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0)
        {
            return;
        }
        else
        {
            SDL_mixer.Mix_QuerySpec(out audio_rate, out audio_format, out audio_channels);
        }
        SDL_mixer.Mix_AllocateChannels(32);
        SDL_mixer.Mix_VolumeMusic(audio_volume / 3);

        System.IntPtr music = SDL_mixer.Mix_LoadMUS("Tetris_theme.ogg");
        System.IntPtr wave  = SDL_mixer.Mix_LoadWAV("Meow.ogg");
        SDL_mixer.Mix_FadeInMusic(music, 1, 2000);
        while (SDL_mixer.Mix_PlayingMusic() != 0)
        {
            SDL.SDL_Delay(100);
            timeleft--;
            if (timeleft == 0)
            {
                break;
            }
            if (timeleft == 25)
            {
                SDL_mixer.Mix_PlayChannel(-1, wave, 0);
            }
        }
        SDL_mixer.Mix_FadeOutMusic(2000);
        SDL_mixer.Mix_FreeMusic(music);
        SDL_mixer.Mix_FreeChunk(wave);
        SDL.SDL_Delay(500);
        SDL_mixer.Mix_CloseAudio();
        SDL.SDL_Quit();
    }
Example #6
0
        /**
         * Used to cleanup after the SDL resources.
         */
        public void Dispose()
        {
            if (_renderer != IntPtr.Zero)
            {
                SDL.SDL_DestroyRenderer(_renderer);
            }

            if (_window != IntPtr.Zero)
            {
                SDL.SDL_DestroyWindow(_window);
            }

            if (soundEffects != null)
            {
                foreach (var entry in soundEffects)
                {
                    var pointer = entry.Value;
                    SDL_mixer.Mix_FreeChunk(pointer);
                }

                SDL_mixer.Mix_CloseAudio();
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_AUDIO) < 0)
            {
                Console.WriteLine("Error initializing SDL");
                SDL.SDL_Quit();
                return;
            }

            // LUNA: Initialize with OpenGL 3.2, so we can debug graphics with RenderDoc
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 3);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 2);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);

            var window = SDL.SDL_CreateWindow(
                "Disaster Engine Again",
                SDL.SDL_WINDOWPOS_UNDEFINED,
                SDL.SDL_WINDOWPOS_UNDEFINED,
                ScreenController.windowWidth, ScreenController.windowHeight,
                SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL
                );

            if (window == IntPtr.Zero)
            {
                Console.WriteLine($"There was an issue creating the window. {SDL.SDL_GetError()}");
            }

            var renderer = SDL.SDL_CreateRenderer(
                window,
                -1,
                SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED |
                SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC
                );

            if (renderer == IntPtr.Zero)
            {
                Console.WriteLine($"There was an issue creating the renderer. {SDL.SDL_GetError()}");
            }

            SDL.SDL_SetHint(SDL.SDL_HINT_RENDER_SCALE_QUALITY, "0");

            Console.WriteLine($"Welcome to disaster engine");

            var frameStart = DateTime.UtcNow.Ticks;

            // software renderer initialisation
            SoftwareCanvas.InitTexture(renderer, 320, 240);
            LoadConfig();
            SoftwareCanvas.LoadFont(Assets.LoadPath("fontsmall.png"));

            screen = new ScreenController(window);
            LoadingMessage("disaster engine 5.0");
            LoadingMessage("(c) jazz mickle ultramegacorp 2021");
            LoadingMessage("initialised screen");
            var js = new JS();

            double ms    = 0;
            int    frame = 0;

            LoadingMessage("building input collection");
            DisasterAPI.Input.keyState = new System.Collections.Generic.Dictionary <SDL.SDL_Keycode, (bool down, bool held, bool up)>();

            LoadingMessage("opening audio");
            SDL_mixer.Mix_OpenAudio(44100, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 1024);

            LoadingMessage("complete");

            System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.LowLatency;

            long ticks;
            long t;

            Debug.enabled = false;

            while (running)
            {
                frame += 1;

                Debug.FrameStart();

                ticks      = DateTime.UtcNow.Ticks;
                t          = ticks - frameStart;
                ms         = t / 10000.0;
                frameStart = ticks;

                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:
                        DisasterAPI.Input.keyState[e.key.keysym.sym] = (true, true, DisasterAPI.Input.GetKeyUp(e.key.keysym.sym));
                        break;

                    case SDL.SDL_EventType.SDL_KEYUP:
                        DisasterAPI.Input.keyState[e.key.keysym.sym] = (DisasterAPI.Input.GetKeyDown(e.key.keysym.sym), false, true);
                        break;
                    }
                }

                Debug.Label("sdl events");

                double delta = ms * .001 * timescale;
                js.Update(delta);

                Debug.Label("js update");
                Debug.DrawGraph();
                screen.Update();

                Debug.Label("render update");

                DisasterAPI.Input.Clear();

                SDL.SDL_SetWindowTitle(window, $"DISASTER ENGINE 5 -- MS: {Math.Floor(ms)}");

                if (ms > 20)
                {
                    //Console.WriteLine("HElo");
                    System.Diagnostics.Debugger.Log(0, "hitch", $"took {ms} this frame\n");
                }
                //if (frame % 30 == 0)

                if (GC.GetTotalMemory(false) > 10000000)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }

                Debug.Label("gc");

                Debug.FrameEnd();
                Debug.GetFrameMSData();
            }

            screen.Done();

            // Clean up the resources that were created.
            Assets.Dispose();

            SDL_mixer.Mix_CloseAudio();
            SDL.SDL_DestroyRenderer(renderer);
            SDL.SDL_DestroyTexture(SoftwareCanvas.drawTexture);
            SDL.SDL_DestroyWindow(window);
            SDL.SDL_Quit();
        }
Example #8
0
 public void Dispose()
 {
     SDL_mixer.Mix_CloseAudio();
 }
 public void Dispose()
 {
     StopSong();
     SDL_mixer.Mix_CloseAudio();
 }