Mercurial > projects > mde
diff mde/SDL.d @ 20:838577503598
Reworked much of Init.
Moved mde.Init to mde.scheduler.Init and largely cleaned up the code.
Implemented mde.scheduler.InitStage to reduce dependancies of modules running Init functions.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 22 Mar 2008 16:22:59 +0000 |
parents | 5f90774ea1ef |
children | a60cbb7359dd |
line wrap: on
line diff
--- a/mde/SDL.d Fri Mar 21 12:31:21 2008 +0000 +++ b/mde/SDL.d Sat Mar 22 16:22:59 2008 +0000 @@ -17,48 +17,74 @@ */ module mde.SDL; -import mde.Init; +import mde.scheduler.InitStage; import mde.input.joystick; import tango.util.log.Log : Log, Logger; +import tango.stdc.stringz; import derelict.sdl.sdl; +import derelict.opengl.gl; import derelict.util.exception; Logger logger; static this() { - logger = Log.getLogger ("mde.init.SDL"); + logger = Log.getLogger ("mde.SDL"); - Init.addFunc (&initSDL); + init2.addFunc (&initSdlAndGl); + init4.addFunc (&setupWindow); } -void initSDL() { - - // Inits SDL and related stuff (joystick). +void initSdlAndGl() { // init2 func + // Load SDL and GL dynamic libs try { DerelictSDL.load(); + DerelictGL.load(); } catch (DerelictException de) { logger.fatal ("Loading dynamic library failed:"); logger.fatal (de.msg); - - init.setFailure (); // abort + + init2.setFailure (); return; } - logger.trace ("Derelict: loaded SDL"); - + logger.trace ("Derelict: loaded SDL and OpenGL"); + + // Initialise SDL if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK /+| SDL_INIT_EVENTTHREAD+/)) { logger.fatal ("SDL initialisation failed:"); char* msg = SDL_GetError (); logger.fatal (msg ? fromStringz(msg) : "no reason available"); - - init.setFailure (); // abort + + init2.setFailure (); return; } - - init.addCleanupFct (&cleanupSDL); + + cleanup2.addFunc (&cleanupSDL); logger.trace ("SDL initialised"); - - /+ Load of info-printing stuff + + // Must be called after SDL has been initialised, so cannot be a separate Init function. + openJoysticks (); // after SDL init + cleanup2.addFunc (&closeJoysticks); +} + +void setupWindow() { // init4 func + // Open a window + // FIXME: provide a way to re-set video mode and change settings + if (SDL_SetVideoMode (800, 600, 0, 0) is null) { // Can't open in windows!! + logger.fatal ("Unable to set video mode:"); + char* msg = SDL_GetError (); + logger.fatal (msg ? fromStringz(msg) : "no reason available"); + + init4.setFailure (); + return; + } +} + +void cleanupSDL () { + SDL_Quit(); +} + + /+ Load of info-printing stuff (currently doesn't have a use) // Print a load of info: logger.info ("Available video modes:"); char[128] tmp; @@ -70,34 +96,16 @@ logger.info (logger.format (tmp, "\t{}x{}", modes[i].w, modes[i].h)); } } - + SDL_VideoInfo* vi = SDL_GetVideoInfo (); if (vi !is null) { logger.info ("Video info:"); logger.info ("Hardware surface support: "~ (vi.flags & SDL_HWSURFACE ? "yes" : "no")); logger.info (logger.format (tmp, "Video memory: {}", vi.video_mem)); - + if (vi.vfmt !is null) { logger.info ("Best video mode:"); logger.info (logger.format (tmp, "Bits per pixel: {}", vi.vfmt.BitsPerPixel)); } } +/ - - // FIXME: make this non-fatal and provide a way to re-set video mode - if (SDL_SetVideoMode (800, 600, 0, 0) is null) { // Can't open in windows!! - logger.fatal ("Unable to set video mode:"); - char* msg = SDL_GetError (); - logger.fatal (msg ? fromStringz(msg) : "no reason available"); - - init.setFailure (); - return; - } - - openJoysticks (); // after SDL init - init.addCleanupFct (&closeJoysticks); -} - -void cleanupSDL () { - SDL_Quit(); -}