Пример #1
0
        public void LoadTGA()
        {
            string file       = "test.tga";
            IntPtr surfacePtr = VideoSetup();
            IntPtr imagePtr   = SdlImage.IMG_LoadTGA_RW(Sdl.SDL_RWFromFile(file, "rb"));

            Assert.IsFalse(imagePtr == IntPtr.Zero);
            Sdl.SDL_Rect rect1  = new Sdl.SDL_Rect(0, 0, 200, 200);
            Sdl.SDL_Rect rect2  = new Sdl.SDL_Rect(0, 0, 200, 200);
            int          result = Sdl.SDL_BlitSurface(imagePtr, ref rect1, surfacePtr, ref rect2);

            Sdl.SDL_UpdateRect(surfacePtr, 0, 0, 200, 200);
            Thread.Sleep(sleepTime);
            Assert.AreEqual(result, 0);
            this.Quit();
        }
 protected override void OnKeyUp(KeyEventArgs e)
 {
     if (!_LockKeyboardInput)
     {
         try
         {
             if (!designMode)
             {
                 Sdl.Event evt = GetKeyEvent((SDLK.Key)Enum.Parse(typeof(SDLK.Key), e.KeyCode.ToString()), (SDLK.ModifierKeys)e.Modifiers, false);
                 Sdl.PushEvent(out evt);
             }
         }
         catch { }
     }
     base.OnKeyUp(e);
 }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        private IntPtr VideoSetup()
        {
            Sdl.SDL_Quit();
            init = Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO);
            IntPtr surfacePtr;

            //Assert.IsNotNull(surfacePtr);
            //Sdl.SDL_FreeSurface(surfacePtr);
            surfacePtr = Sdl.SDL_SetVideoMode(
                width,
                height,
                bpp,
                flags);
            Assert.IsNotNull(surfacePtr);
            return(surfacePtr);
        }
Пример #4
0
    public bool IsKeyPressed(int key)
    {
        bool pressed = false;

        Sdl.SDL_PumpEvents();
        Sdl.SDL_Event evt;
        Sdl.SDL_PollEvent(out evt);
        int numKeys;

        byte[] keys = Sdl.SDL_GetKeyState(out numKeys);
        if (keys[key] == 1)
        {
            pressed = true;
        }
        return(pressed);
    }
Пример #5
0
    public int KeyPressed()
    {
        int pressed = -1;

        Sdl.SDL_PumpEvents();
        Sdl.SDL_Event keyEvent;
        if (Sdl.SDL_PollEvent(out keyEvent) == 1)
        {
            if (keyEvent.type == Sdl.SDL_KEYDOWN)
            {
                pressed = keyEvent.key.keysym.sym;
            }
        }

        return(pressed);
    }
Пример #6
0
        public void zoomSurface()
        {
            this.InitSdl();
            Sdl.SDL_Rect rect1          = new Sdl.SDL_Rect(0, 0, 400, 400);
            Sdl.SDL_Rect rect2          = new Sdl.SDL_Rect(0, 0, 400, 400);
            IntPtr       bmpImagePtr    = Sdl.SDL_LoadBMP("test.bmp");
            IntPtr       zoomSurfacePtr = SdlGfx.zoomSurface(bmpImagePtr, 5, 2, SdlGfx.SMOOTHING_OFF);
            int          result         = Sdl.SDL_BlitSurface(zoomSurfacePtr, ref rect1, surfacePtr, ref rect2);

            Assert.IsNotNull(zoomSurfacePtr);
            Assert.IsFalse(zoomSurfacePtr == IntPtr.Zero);
            Sdl.SDL_UpdateRect(surfacePtr, 0, 0, 400, 400);

            //int results = Sdl.SDL_Flip(surfacePtr);
            Thread.Sleep(sleepTime);
        }
Пример #7
0
 /// <summary>
 /// Initialize timer.
 /// </summary>
 public static bool Initialize()
 {
     if ((Sdl.SDL_WasInit(Sdl.SDL_INIT_TIMER))
         == (int)SdlFlag.FalseValue)
     {
         if (Sdl.SDL_Init(Sdl.SDL_INIT_TIMER) != (int)SdlFlag.Success)
         {
             throw SdlException.Generate();
         }
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #8
0
    public static bool KeyPressed(int c)
    {
        bool pressed = false;

        Sdl.SDL_PumpEvents();
        Sdl.SDL_Event myEvent;
        Sdl.SDL_PollEvent(out myEvent);
        int numkeys;

        byte[] keys = Tao.Sdl.Sdl.SDL_GetKeyState(out numkeys);
        if (keys[c] == 1)
        {
            pressed = true;
        }
        return(pressed);
    }
Пример #9
0
    public static void WriteHiddenText(string txt,
                                       short x, short y, byte r, byte g, byte b, Font f)
    {
        Sdl.SDL_Color color           = new Sdl.SDL_Color(r, g, b);
        IntPtr        textoComoImagen = SdlTtf.TTF_RenderText_Solid(
            f.GetPointer(), txt, color);

        //if (textoComoImagen == IntPtr.Zero)
        //   Environment.Exit(5);

        Sdl.SDL_Rect origen = new Sdl.SDL_Rect(0, 0, width, height);
        Sdl.SDL_Rect dest   = new Sdl.SDL_Rect(x, y, width, height);

        Sdl.SDL_BlitSurface(textoComoImagen, ref origen,
                            hiddenScreen, ref dest);
    }
Пример #10
0
        /// <summary>
        /// Returns an array of events in the event queue.
        /// </summary>
        /// <param name="eventMask">Mask for event that will be removed from queue</param>
        /// <param name="numberOfEvents">Number of events to remove</param>
        public static void Remove(EventMask eventMask, int numberOfEvents)
        {
            Sdl.SDL_Event[] events = new Sdl.SDL_Event[numberOfEvents];
            Sdl.SDL_PumpEvents();
            int result =
                Sdl.SDL_PeepEvents(
                    events,
                    events.Length,
                    Sdl.SDL_GETEVENT,
                    (int)eventMask);

            if (result == (int)SdlFlag.Error)
            {
                throw SdlException.Generate();
            }
        }
Пример #11
0
    /** JoyPulsado: devuelve TRUE si
     *  ha sido pulsado un botón del jostick
     *  (cualquiera, por ahora)
     */
    public static bool JoystickPulsado(int boton)
    {
        if (!existeJoystick)
        {
            return(false);
        }

        if (Sdl.SDL_JoystickGetButton(joystick, boton) > 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #12
0
    // Joystick methods

    /** JoystickPressed: returns TRUE if
     *  a certain button in the joystick/gamepad
     *  has been pressed
     */
    public static bool JoystickPressed(int boton)
    {
        if (!isThereJoystick)
        {
            return(false);
        }

        if (Sdl.SDL_JoystickGetButton(joystick, boton) > 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #13
0
        public static KeyboardState GetState()
        {
            state = new KeyboardState((int)Sdl.SDLK_LAST);
            int numKeys = 0;

            byte[] keys = Sdl.SDL_GetKeyState(out numKeys);
            for (int key = Sdl.SDLK_UNKNOWN; key < Sdl.SDLK_LAST; key++)
            {
                if (keys[key] > 0)
                {
                    state[keyDictionary[key]] = KeyState.Down;
                }
            }

            return(state);
        }
Пример #14
0
        public override void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
        {
            this.screenDeviceName = screenDeviceName;
            OnScreenDeviceNameChanged();

            int flags = Sdl.SDL_OPENGL;

            if (willBeFullScreen)
            {
                flags |= Sdl.SDL_FULLSCREEN;
            }

            int           bitsPerPixel = 0;
            SurfaceFormat format;

            if (game.GraphicsDevice == null)
            {
                // TODO This cast should be tested against MS XNA
                GraphicsDeviceManager graphicsManager = (GraphicsDeviceManager)game.Services.GetService(typeof(IGraphicsDeviceManager));
                format = graphicsManager.PreferredBackBufferFormat;
            }
            else
            {
                format = game.GraphicsDevice.PresentationParameters.BackBufferFormat;
            }

            if (format == SurfaceFormat.Color || format == SurfaceFormat.Bgr32 || format == SurfaceFormat.Rgba32)
            {
                bitsPerPixel = 32;
            }
            // TODO add support for other surface formats

            IntPtr sdlSurfacePtr = Sdl.SDL_SetVideoMode(clientWidth, clientHeight, bitsPerPixel, flags);

            if (sdlSurfacePtr != IntPtr.Zero)
            {
                sdlSurface = (Sdl.SDL_Surface)Marshal.PtrToStructure(sdlSurfacePtr, typeof(Sdl.SDL_Surface));
            }

#warning SDL 1.2 doesn't support getting the window position, only the dimensions
            clientBounds.Width  = clientWidth;
            clientBounds.Height = clientHeight;

            OnClientSizeChanged();

            inTransition = false;
        }
Пример #15
0
        private void setSDLVideo()
        {
            /* To center a non-fullscreen window we need to set an environment
             * variable
             */
            Sdl.SDL_putenv("SDL_VIDEO_CENTERED=center");

            /* the video info structure contains the current video mode. Prior to
             * calling setVideoMode, it contains the best available mode
             * for your system. Post setting the video mode, it contains
             * whatever values you set the video mode with.
             * First we point at the SDL structure, then test to see that the
             * point is right. Then we copy the data from the structure to
             * the safer vidInfo variable.
             */

            /* according to the SDL documentaion, the flags parameter passed to setVideoMode
             * affects only the 2D SDL surface, not the openGL. To set their properties
             * use the syntax below. We enable vsync because we are running the loop
             * unfettered and we don't want the loop redrawing the buffer
             * while it is being written to screen
             */
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_SWAP_CONTROL, 1); //enable vsync
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_RED_SIZE, 8);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_GREEN_SIZE, 8);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_BLUE_SIZE, 8);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DEPTH_SIZE, 16);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_MULTISAMPLEBUFFERS, 1);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_MULTISAMPLESAMPLES, 2);
            Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1);

            /* the setVideoMode function returns the current frame buffer as an
             * SDL_Surface. Again, we grab a pointer to it, then place its
             * content into the non pointery surface variable. I say 'non-pointery',
             * but this SDL variable must have a pointer in it because it can
             * access the current pixels in the framebuffer.
             */
            var ptr = Sdl.SDL_SetVideoMode(w, h, bpp, flags);

            if (ptr == IntPtr.Zero)
            {
                Console.WriteLine("Error qsetting the video mode");
                Sdl.SDL_Quit();
            }
            InitGL();
            ReSizeGLScene(w, h);
        }
Пример #16
0
        internal static void AddDevice(int deviceId)
        {
            var gamepad = new GamePadInfo();

            gamepad.Device       = Sdl.GameController.Open(deviceId);
            gamepad.HapticDevice = Sdl.Haptic.OpenFromJoystick(Sdl.GameController.GetJoystick(gamepad.Device));

            var id = 0;

            while (Gamepads.ContainsKey(id))
            {
                id++;
            }

            Gamepads.Add(id, gamepad);

            if (gamepad.HapticDevice == IntPtr.Zero)
            {
                return;
            }

            try
            {
                if (Sdl.Haptic.EffectSupported(gamepad.HapticDevice, ref _hapticLeftRightEffect) == 1)
                {
                    Sdl.Haptic.NewEffect(gamepad.HapticDevice, ref _hapticLeftRightEffect);
                    gamepad.HapticType = 1;
                }
                else if (Sdl.Haptic.RumbleSupported(gamepad.HapticDevice) == 1)
                {
                    Sdl.Haptic.RumbleInit(gamepad.HapticDevice);
                    gamepad.HapticType = 2;
                }
                else
                {
                    Sdl.Haptic.Close(gamepad.HapticDevice);
                }
            }
            catch
            {
                Sdl.Haptic.Close(gamepad.HapticDevice);
                gamepad.HapticDevice = IntPtr.Zero;
                Sdl.ClearError();
            }

            RefreshTranslationTable();
        }
Пример #17
0
        public void GetVideoInfo()
        {
            IntPtr videoInfoPtr = Sdl.SDL_GetVideoInfo();

            Assert.IsNotNull(videoInfoPtr);

            Sdl.SDL_VideoInfo videoInfo = (Sdl.SDL_VideoInfo)
                                          Marshal.PtrToStructure(videoInfoPtr,
                                                                 typeof(Sdl.SDL_VideoInfo));
            Console.WriteLine(videoInfo.hw_available);
            Console.WriteLine(videoInfo.wm_available);
            Console.WriteLine(videoInfo.video_mem);
            Console.WriteLine(videoInfo.current_h);
            Console.WriteLine(videoInfo.current_w);

            Sdl.SDL_FreeSurface(videoInfoPtr);
        }
Пример #18
0
        static IntPtr veraSmall;                                              //The pointer to the font
        #endregion

        static void Draw()
        {
            Sdl.SDL_FillRect(screen, ref screenArea, 0);                                           //Clear for next draw cycle
            screenData = (Sdl.SDL_Surface)Marshal.PtrToStructure(screen, typeof(Sdl.SDL_Surface)); //Put the screen data in its place

            switch (Adventurer.gameState)
            {
            case GameState.OpeningMenu:
                Draw_Opening();
                break;

            case GameState.NameSelect:
                Draw_Name();
                break;

            case GameState.CreatureSelect:
                Draw_CreatureSel();
                break;

            case GameState.HelpMenu:
                Draw_Help();
                break;

            case GameState.MainGame:
                Draw_Main();
                break;

            case GameState.InventoryMenu:
                Draw_Inventory();
                break;

            case GameState.HealthMenu:
                Draw_Health();
                break;

            case GameState.WaitForPosition:
                Draw_GetPos();
                break;

            case GameState.EscapeMenu:
                Draw_Escape();
                break;
            }

            Sdl.SDL_Flip(screen); //Update screen
        } //Draws things to the screen
Пример #19
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            Sdl.Window.Destroy(_handle);
            _handle = IntPtr.Zero;

            if (_icon != IntPtr.Zero)
            {
                Sdl.FreeSurface(_icon);
            }

            _disposed = true;
        }
Пример #20
0
        /// <summary>
        /// Create a Font from a byte array in memory.
        /// </summary>
        /// <param name="array">A array of byte that should be the font data</param>
        /// <param name="pointSize">Size of font</param>
        public Font(byte[] array, int pointSize)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (!Font.IsFontSystemInitialized)
            {
                Font.InitializeFontSystem();
            }

            this.Handle = SdlTtf.TTF_OpenFontRW(Sdl.SDL_RWFromMem(array, array.Length), 0, pointSize);
            if (this.Handle == IntPtr.Zero)
            {
                throw FontException.Generate();
            }
        }
Пример #21
0
        /// <summary>
        /// Returns the number of seconds before the audio track starts on the cd.
        /// </summary>
        /// <remarks></remarks>
        /// <param name="trackNumber">Track to query</param>
        public int TrackStart(int trackNumber)
        {
            int result = Sdl.CD_INDRIVE((int)this.Status);

            GC.KeepAlive(this);
            if (result == 1)
            {
                Sdl.SDL_CD cd =
                    (Sdl.SDL_CD)Marshal.PtrToStructure(
                        this.Handle, typeof(Sdl.SDL_CD));
                return((int)Timer.FramesToSeconds(cd.track[trackNumber].offset));
            }
            else
            {
                return(0);
            }
        }
Пример #22
0
        public void Update(double elapsedTime)
        {
            _countDown -= elapsedTime;

            if (Sdl.SDL_NumJoysticks() > 0)
            {
                if (_countDown <= 0 || _input.Controller.ButtonA.Pressed)
                {
                    Finish();
                }
            }

            if (_countDown <= 0 || _input.Keyboard.IsKeyPressed(System.Windows.Forms.Keys.Enter))
            {
                Finish();
            }
        }
Пример #23
0
        public SdlGameWindow(Game game)
        {
            _game             = game;
            _screenDeviceName = "";

            Instance = this;

            _winx   = Sdl.Window.PosUndefined;
            _winy   = Sdl.Window.PosUndefined;
            _width  = GraphicsDeviceManager.DefaultBackBufferWidth;
            _height = GraphicsDeviceManager.DefaultBackBufferHeight;

            if (Sdl.Patch >= 4)
            {
                var display = GetMouseDisplay();
                _winx = display.X + display.Width / 2;
                _winy = display.Y + display.Height / 2;
            }

            Sdl.SetHint("SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS", "0");
            Sdl.SetHint("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1");

            using (
                var stream =
                    Assembly.GetEntryAssembly().GetManifestResourceStream(Assembly.GetEntryAssembly().EntryPoint.DeclaringType.Namespace + ".Icon.bmp") ??
                    Assembly.GetEntryAssembly().GetManifestResourceStream("Icon.bmp") ??
                    Assembly.GetExecutingAssembly().GetManifestResourceStream("MonoGame.bmp"))
            {
                if (stream != null)
                {
                    using (var br = new BinaryReader(stream))
                    {
                        try
                        {
                            var src = Sdl.RwFromMem(br.ReadBytes((int)stream.Length), (int)stream.Length);
                            _icon = Sdl.LoadBMP_RW(src, 1);
                        }
                        catch { }
                    }
                }
            }

            _handle = Sdl.Window.Create("", _winx, _winy,
                                        GraphicsDeviceManager.DefaultBackBufferWidth, GraphicsDeviceManager.DefaultBackBufferHeight,
                                        Sdl.Window.State.Hidden);
        }
Пример #24
0
        public void WriteText(string text, short x, short y,
                              Font fontType)
        {
            byte r = 0, g = 255, b = 0;

            Sdl.SDL_Color color       = new Sdl.SDL_Color(r, g, b);
            IntPtr        textAsImage = SdlTtf.TTF_RenderText_Solid(fontType.GetFontType(),
                                                                    text, color);

            if (textAsImage == IntPtr.Zero)
            {
                Environment.Exit(5);
            }
            Sdl.SDL_Rect src          = new Sdl.SDL_Rect(0, 0, screenWidth, screenHeight);
            Sdl.SDL_Rect dest         = new Sdl.SDL_Rect(x, y, screenWidth, screenHeight);
            Sdl.SDL_BlitSurface(textAsImage, ref src, screen, ref dest);
        }
Пример #25
0
        public void EnsureHost()
        {
            int result = Sdl.SDL_Init(Sdl.SDL_INIT_TIMER | Sdl.SDL_INIT_VIDEO | Sdl.SDL_INIT_JOYSTICK);

            if (result == 0)
            {
                System.Diagnostics.Debug.WriteLine("SDL initialized");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Couldn't initialize SDL");
            }

            Il.ilInit();

            window = new SdlGameWindow(game);
        }
Пример #26
0
        public App()
        {
            //SDL is comprised of 8 subsystems. Here we initialize the video
            if (Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO) < 0)
            {
                Console.WriteLine("Error initializing SDL");
                Sdl.SDL_Quit();
                return;
            }

            /* Rather than set the video properties up in the constructor, I set
             * them in setVideo. The reason for this is that 2 pointers are used
             * to interact with SDL structures. Once used they convert their
             * handles into vidInfo and surface tamer variables. That this
             * occurs inside the function means the pointers will release
             * their memory on function exit.
             */
            setSDLVideo();

            /* openGL is not part of SDL, rather it runs in a window handled
             * by SDL. here we set up some openGL state
             */
            //initialize game
            game = new GameClass();

            /* finP is the property get/setter for the boolean fin in the game
             * class. It is held in the game class because the game class handles
             * events. When escape is pressed, fin is set to true and the following
             * loop
             * terminates.
             * The function tick is called every loop. It is passed the time
             * taken for each loop
             */
            while (!game.finP)
            {
                game.pollEvents();
                Tick();           //updates the game object
                Sdl.SDL_Delay(1); //release the thread
            }

            /* When the loop ends the code drops down to here. SDL_Quit shuts
             * down the SDL subsystems initialized by SDL_Init
             */
            Sdl.SDL_Quit();
            return;
        }
Пример #27
0
    /** JoystickMoved: returns TRUE if
     *  the joystick/gamepad has been moved
     *  up to the limit in any direction
     *  Then, int returns the corresponding
     *  X (1=right, -1=left)
     *  and Y (1=down, -1=up)
     */
    public static bool JoystickMoved(out int posX, out int posY)
    {
        posX = 0; posY = 0;
        if (!isThereJoystick)
        {
            return(false);
        }

        posX = Sdl.SDL_JoystickGetAxis(joystick, 0);  // Leo valores (hasta 32768)
        posY = Sdl.SDL_JoystickGetAxis(joystick, 1);
        // Normalizo valores
        if (posX == -32768)
        {
            posX = -1;                  // Normalizo, a -1, +1 o 0
        }
        else if (posX == 32767)
        {
            posX = 1;
        }
        else
        {
            posX = 0;
        }
        if (posY == -32768)
        {
            posY = -1;
        }
        else if (posY == 32767)
        {
            posY = 1;
        }
        else
        {
            posY = 0;
        }

        if ((posX != 0) || (posY != 0))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #28
0
    public static void Init(short w, short h, int colors, bool fullScreen)
    {
        width  = w;
        height = h;

        int flags = Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT;

        if (fullScreen)
        {
            flags |= Sdl.SDL_FULLSCREEN;
        }
        Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
        hiddenScreen = Sdl.SDL_SetVideoMode(
            width,
            height,
            colors,
            flags);

        Sdl.SDL_Rect rect2 =
            new Sdl.SDL_Rect(0, 0, (short)width, (short)height);
        Sdl.SDL_SetClipRect(hiddenScreen, ref rect2);

        SdlTtf.TTF_Init();

        // Joystick initialization
        isThereJoystick = true;
        if (Sdl.SDL_NumJoysticks() < 1)
        {
            isThereJoystick = false;
        }

        if (isThereJoystick)
        {
            joystick = Sdl.SDL_JoystickOpen(0);
            if (joystick == IntPtr.Zero)
            {
                isThereJoystick = false;
            }
        }

        // Time lapse between two consecutive mouse clicks,
        // so that they are not too near
        mouseClickLapse = 10;
        lastMouseClick  = Sdl.SDL_GetTicks();
    }
Пример #29
0
        public void Tick()
        {
            TimeSpan elapsedUpdateTime = TimeSpan.FromMilliseconds(Sdl.SDL_GetTicks() - gameUpdateTime.TotalRealTime.TotalMilliseconds);

            if (isFixedTimeStep)
            {
                while (elapsedUpdateTime < TargetElapsedTime)
                {
#warning To low resolution with ms (10^-3)
                    Thread.Sleep(TargetElapsedTime.Milliseconds - elapsedUpdateTime.Milliseconds);
                    elapsedUpdateTime = TimeSpan.FromMilliseconds(Sdl.SDL_GetTicks() - gameUpdateTime.TotalRealTime.TotalMilliseconds);
                }

                gameUpdateTime.ElapsedGameTime = TargetElapsedTime;
                gameUpdateTime.TotalGameTime   = gameUpdateTime.TotalGameTime.Add(TargetElapsedTime);
            }
            else
            {
                gameUpdateTime.ElapsedGameTime = elapsedUpdateTime;
                gameUpdateTime.TotalGameTime   = gameUpdateTime.TotalGameTime.Add(elapsedUpdateTime);
            }

            gameUpdateTime.ElapsedRealTime = elapsedUpdateTime;
            gameUpdateTime.TotalRealTime   = gameUpdateTime.TotalRealTime.Add(elapsedUpdateTime);

            Update(gameUpdateTime);

            elapsedUpdateTime = TimeSpan.FromMilliseconds(Sdl.SDL_GetTicks() - gameUpdateTime.TotalRealTime.TotalMilliseconds);
            if (isFixedTimeStep && elapsedUpdateTime > TargetElapsedTime)
            {
                gameUpdateTime.IsRunningSlowly = true;
            }
            else
            {
                gameUpdateTime.IsRunningSlowly = false;
            }

            if (!BeginDraw())
            {
                return;
            }

            Draw(gameUpdateTime);
            EndDraw();
        }
Пример #30
0
    /** JoystickMoved: returns TRUE if
     *  the joystick/gamepad has been moved
     *  up to the limit in any direction
     *  Then, int returns the corresponding
     *  X (1=right, -1=left)
     *  and Y (1=down, -1=up)
     */
    public static bool JoystickMoved(out int posX, out int posY)
    {
        posX = 0; posY = 0;
        if (!isThereJoystick)
        {
            return(false);
        }

        posX = Sdl.SDL_JoystickGetAxis(joystick, 0);
        posY = Sdl.SDL_JoystickGetAxis(joystick, 1);

        if (posX == -32768)
        {
            posX = -1;
        }
        else if (posX == 32767)
        {
            posX = 1;
        }
        else
        {
            posX = 0;
        }
        if (posY == -32768)
        {
            posY = -1;
        }
        else if (posY == 32767)
        {
            posY = 1;
        }
        else
        {
            posY = 0;
        }

        if ((posX != 0) || (posY != 0))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #31
0
 public void InitializeSettings(Sdl.Core.Settings.ISettingsBundle settingsBundle, string configurationId)
 {
     //loading of filter settings
 }