SDL 0.6.2 → 0.6.3
raw patch · 12 files changed
+72/−49 lines, 12 filessetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Graphics.UI.SDL.Video: glAccumAlphaSize :: GLAttr
- Graphics.UI.SDL.Video: glAccumBlueSize :: GLAttr
- Graphics.UI.SDL.Video: glAccumGreenSize :: GLAttr
- Graphics.UI.SDL.Video: glAccumRedSize :: GLAttr
- Graphics.UI.SDL.Video: glAlphaSize :: GLAttr
- Graphics.UI.SDL.Video: glBlueSize :: GLAttr
- Graphics.UI.SDL.Video: glBufferSize :: GLAttr
- Graphics.UI.SDL.Video: glDepthSize :: GLAttr
- Graphics.UI.SDL.Video: glDoubleBuffer :: GLAttr
- Graphics.UI.SDL.Video: glGreenSize :: GLAttr
- Graphics.UI.SDL.Video: glMultiSampleBuffers :: GLAttr
- Graphics.UI.SDL.Video: glMultiSampleSamples :: GLAttr
- Graphics.UI.SDL.Video: glRedSize :: GLAttr
- Graphics.UI.SDL.Video: glStencilSize :: GLAttr
- Graphics.UI.SDL.Video: glStereo :: GLAttr
+ Graphics.UI.SDL.Video: glAccumAlphaSize, glMultiSampleSamples, glMultiSampleBuffers, glStereo :: GLAttr
+ Graphics.UI.SDL.Video: glDepthSize, glAccumBlueSize, glAccumGreenSize, glAccumRedSize, glStencilSize :: GLAttr
+ Graphics.UI.SDL.Video: glRedSize, glDoubleBuffer, glBufferSize, glAlphaSize, glBlueSize, glGreenSize :: GLAttr
- Graphics.UI.SDL.Video: toToggle :: Num a => a -> Toggle
+ Graphics.UI.SDL.Video: toToggle :: (Eq a, Num a) => a -> Toggle
Files
- Examples/MacOSX/MainWrapper.hs +4/−0
- Examples/MacOSX/Makefile +10/−8
- Examples/MacOSX/SDLWrapper.hs +0/−4
- Examples/MacOSX/mainc.c +44/−0
- Examples/MacOSX/wrapper.c +0/−25
- Graphics/UI/SDL/Events.hsc +2/−1
- Graphics/UI/SDL/Joystick.hsc +2/−1
- Graphics/UI/SDL/Types.hsc +2/−1
- Graphics/UI/SDL/Video.hsc +2/−2
- MACOSX +2/−3
- SDL.cabal +3/−3
- Setup.lhs +1/−1
+ Examples/MacOSX/MainWrapper.hs view
@@ -0,0 +1,4 @@+{-# LANGUAGE ForeignFunctionInterface #-}+module MainWrapper where+import Main (main)+foreign export ccall "haskell_main" main :: IO ()
Examples/MacOSX/Makefile view
@@ -1,10 +1,12 @@-test: wrapper.o SDLWrapper.hs- ghc -no-hs-main --make wrapper.o SDLWrapper.hs -o test-SDLWrapper_stub.h: SDLWrapper.hs- ghc -no-hs-main --make SDLWrapper.hs -c-wrapper.o: SDLWrapper_stub.h- ghc -no-hs-main `sdl-config --cflags` -Wall wrapper.c -c+# build with sdl wrapper for mac osx (see mainc.c or hssdl/Examples/MacOSX)+PROGNAME=main+$(PROGNAME): mainc.o MainWrapper.hs Main.hs+ ghc -no-hs-main --make mainc.o MainWrapper.hs -o $@+mainc.o: mainc.c MainWrapper_stub.h+ ghc -no-hs-main `sdl-config --cflags` -Wall $*.c -c+MainWrapper_stub.h: MainWrapper.hs+ ghc -no-hs-main --make $< -c clean:- rm -f *.hi *.o *_stub.c *_stub.h test+ rm -f *.hi *.o *_stub.c *_stub.h $(PROGNAME) .PHONY: clean-+#
− Examples/MacOSX/SDLWrapper.hs
@@ -1,4 +0,0 @@-{-# LANGUAGE ForeignFunctionInterface #-}-module SDLWrapper where-import Main-foreign export ccall "haskell_main" main :: IO ()
+ Examples/MacOSX/mainc.c view
@@ -0,0 +1,44 @@+/*+A C wrapper to get proper SDL initialisation on mac. From MACOSX in the+SDL haskell package:++ SDL uses Objective-C and Cocoa to open a UI window; this means that+ Cocoa must be initialized, and in particular, an NSAutoReleasePool be in+ place. This initialization is done in libSDLmain. For+ C/C++/Objective-C programs, libSDLmain #defines the developer's main to+ be SDL_main and piggy backs SDL_main onto it's own Cocoa main, using the+ C preprocessor and abusing the linker. Of course, this technique will+ never work for Haskell: there is no clean entry point to a Haskell+ runtime in this fashion.+ ...+ MainWrapper.hs imports Main.hs and foreign-exports main as haskell_main.+ mainc.c includes SDL.h and contains a main function to make the+ preprocessor magic of SDL happen; it also initializes the GHC runtime+ system and calls haskell_main. Some makefile rules link our objects with+ the GHC RTS and SDL.++See also+http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#using-own-main++*/++#include <SDL.h>+#include <HsFFI.h>+#ifdef __GLASGOW_HASKELL__+#include "MainWrapper_stub.h"+#endif++#ifdef __GLASGOW_HASKELL__+extern void __stginit_MainWrapper (void);+#endif++int main(int argc, char *argv[])+{+ hs_init(&argc, &argv);+#ifdef __GLASGOW_HASKELL__+ hs_add_root(__stginit_MainWrapper);+#endif+ haskell_main();+ hs_exit();+ return 0;+}
− Examples/MacOSX/wrapper.c
@@ -1,25 +0,0 @@-//for explanations see http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#using-own-main--#include <SDL.h>-#include <HsFFI.h>--#ifdef __GLASGOW_HASKELL__-#include "SDLWrapper_stub.h"-#endif--#ifdef __GLASGOW_HASKELL__-extern void __stginit_SDLWrapper ( void );-#endif--int main(int argc, char *argv[])-{- hs_init(&argc, &argv);-#ifdef __GLASGOW_HASKELL__- hs_add_root(__stginit_SDLWrapper);-#endif-- haskell_main();-- hs_exit();- return 0;-}
Graphics/UI/SDL/Events.hsc view
@@ -44,8 +44,9 @@ import Foreign (Int16, Word8, Word16, Word32, Ptr, Storable(poke, sizeOf, alignment, peekByteOff, pokeByteOff, peek),- unsafePerformIO, toBool, new, alloca)+ toBool, new, alloca) import Foreign.C (peekCString, CString, CInt)+import System.IO.Unsafe (unsafePerformIO) import Data.Bits (Bits((.&.), shiftL)) import Control.Concurrent (threadDelay) import Prelude hiding (Enum(..))
Graphics/UI/SDL/Joystick.hsc view
@@ -33,9 +33,10 @@ , close ) where -import Foreign (Int16, Word8, Ptr, FunPtr, Storable(peek), unsafePerformIO,+import Foreign (Int16, Word8, Ptr, FunPtr, Storable(peek), finalizeForeignPtr, toBool, maybePeek, alloca, withForeignPtr, newForeignPtr) import Foreign.C (peekCString, CString)+import System.IO.Unsafe (unsafePerformIO) import Graphics.UI.SDL.General (unwrapMaybe) import Graphics.UI.SDL.Utilities (fromBitmask)
Graphics/UI/SDL/Types.hsc view
@@ -43,7 +43,8 @@ import Foreign.C (CInt) import Foreign (Word8, Word16, Word32, Ptr, Storable(peekByteOff),- unsafePerformIO, newForeignPtr_, ForeignPtr, withForeignPtr)+ newForeignPtr_, ForeignPtr, withForeignPtr)+import System.IO.Unsafe (unsafePerformIO) import Graphics.UI.SDL.Utilities (Enum(..), fromBitmask) import Graphics.UI.SDL.Color (Pixel(..))
Graphics/UI/SDL/Video.hsc view
@@ -83,7 +83,7 @@ import Foreign (Ptr, FunPtr, Storable(peek), castPtr, plusPtr, nullPtr, newForeignPtr_, finalizeForeignPtr, alloca, withForeignPtr, newForeignPtr)-import Foreign.C (peekCString, CString, CInt)+import Foreign.C (peekCString, CString, CInt()) import Foreign.Marshal.Array (withArrayLen, peekArray0, peekArray, allocaArray) import Foreign.Marshal.Utils (with, toBool, maybeWith, maybePeek, fromBool) import Control.Exception (bracket)@@ -130,7 +130,7 @@ data Toggle = Disable | Enable | Query deriving (Eq, Ord, Show) -toToggle :: (Num a) => a -> Toggle+toToggle :: (Eq a, Num a) => a -> Toggle toToggle (#{const SDL_DISABLE}) = Disable toToggle (#{const SDL_ENABLE}) = Enable toToggle (#{const SDL_QUERY}) = Query
MACOSX view
@@ -54,10 +54,9 @@ All our troubles stem from SDL's startup procedure on Mac OS X. The fundamental problem is that SDL uses Objective-C and Cocoa to open a UI window; this means that Cocoa must be initialized, and in particular, an NSAutoReleasePool be in place. This initialization is done in libSDLmain. For C/C++/Objective-C programs, libSDLmain #defines the developer's main to be SDL_main and piggy backs SDL_main onto it's own Cocoa main, using the C preprocessor and abusing the linker. Of course, this technique will never work for Haskell: there is no clean entry point to a Haskell runtime in this fashion. -But we can fake it. In Examples/MacOSX, there is an example program using SDL in Main.hs. It doesn't need to be modified to make it work on OS X. Instead we put two helper files in the same directory and compile them along with it: SDLWrapper.hs imports Main and foreign-exports Main.main as haskell_main to be able to call it from C. wrapper.c includes SDL.h and contains a main function to make the preprocessor magic of SDL happen. The C main function initializes the GHC RTS and calls haskell_main from SDLWrapper.hs which is Main.main in disguise.-The Makefile then uses ghc --make to link our objects with the GHC RTS and SDL.+But we can fake it. In Examples/MacOSX, there is an example program using SDL in Main.hs. It doesn't need to be modified to make it work on OS X. Instead we put two helper files in the same directory and compile them along with it: MainWrapper.hs imports Main.hs and foreign-exports main as haskell_main. mainc.c includes SDL.h and contains a main function to make the preprocessor magic of SDL happen; it also initializes the GHC runtime system and calls haskell_main. Some makefile rules link our objects with the GHC RTS and SDL. -For your own projects just copy the two helper files and make your build system produce the final result like the example Makefile does.+For your own projects, copy the two helper files mainc.c and MainWrapper.hs and copy/mimic the build rules from the example Makefile, optionally changing PROGNAME. GHCi and hsSDL on Mac OS X --------------------------
SDL.cabal view
@@ -1,6 +1,6 @@ Cabal-Version: >= 1.6 Name: SDL-Version: 0.6.2+Version: 0.6.3 Maintainer: Lemmih (lemmih@gmail.com) Author: Lemmih (lemmih@gmail.com) Copyright: 2004-2010, Lemmih@@ -20,8 +20,8 @@ Data-files: README, MACOSX, WIN32, Examples/MacOSX/Main.hs, Examples/MacOSX/Makefile,- Examples/MacOSX/SDLWrapper.hs,- Examples/MacOSX/wrapper.c+ Examples/MacOSX/MainWrapper.hs,+ Examples/MacOSX/mainc.c Extra-Source-files: configure, configure.ac, SDL.buildinfo.in, config.mk.in, includes/HsSDLConfig.h.in Library
Setup.lhs view
@@ -2,4 +2,4 @@ > module Main where > import Distribution.Simple > main :: IO ()-> main = defaultMainWithHooks defaultUserHooks+> main = defaultMainWithHooks autoconfUserHooks