| 1 |
#include "oodle.h" |
| 2 |
|
| 3 |
CSDLGame::CSDLGame(int screenX, int screenY, int bitDepth, bool fullscreen, const string &title) |
| 4 |
: screen(NULL) |
| 5 |
{ |
| 6 |
LOG("-------------\nPowered by Oodle v1.0\n-------------", 1, LOG_INFO); |
| 7 |
|
| 8 |
LOG("Initializing SDL library", 6, LOG_INFO); |
| 9 |
// initialize SDL |
| 10 |
if (SDL_Init( SDL_INIT_VIDEO ) < 0) { |
| 11 |
// clean up SDL |
| 12 |
SDL_Quit( ); |
| 13 |
// throw exception |
| 14 |
_THROWEX(ex_sdlInitFailed, "SDL Initilization Failed", "CSDLGame", "CSDLGame", |
| 15 |
"screenX = " << screenX << ", screenY = " << screenY << ", bitDepth = " << bitDepth); |
| 16 |
} |
| 17 |
SDL_WM_SetCaption(title.c_str(), NULL); |
| 18 |
|
| 19 |
resize(screenX, screenY, bitDepth, fullscreen); |
| 20 |
} |
| 21 |
|
| 22 |
CSDLGame::~CSDLGame() |
| 23 |
{ |
| 24 |
delete screen; |
| 25 |
|
| 26 |
LOG("Shutting down SDL library", 6, LOG_INFO); |
| 27 |
SDL_Quit(); |
| 28 |
} |
| 29 |
|
| 30 |
void CSDLGame::resize(int screenX, int screenY, int bitDepth, bool fullscreen) |
| 31 |
{ |
| 32 |
delete screen; |
| 33 |
|
| 34 |
int fs = 0; |
| 35 |
if (fullscreen) fs = SDL_FULLSCREEN; |
| 36 |
|
| 37 |
LOG("Changing to resolution " + stringify(screenX) + "x" + stringify(screenY), 1, LOG_INFO); |
| 38 |
|
| 39 |
SDL_Surface* surf; |
| 40 |
|
| 41 |
// set display resolution and bit depth |
| 42 |
surf = SDL_SetVideoMode(screenX, screenY, bitDepth, |
| 43 |
SDL_HWSURFACE | // create surface in video ram |
| 44 |
SDL_DOUBLEBUF | fs // create surface with dbl buffering |
| 45 |
); // surface is full-screen |
| 46 |
/*LOG("Got surface with: [Hardware=" << ((surf->flags & SDL_HWSURFACE) == SDL_HWSURFACE) << |
| 47 |
", DblBuf=" << ((surf->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) << |
| 48 |
", Fullscreen=" << ((surf->flags & fs) == fs) << "]", 1, LOG_INFO);*/ |
| 49 |
|
| 50 |
if (!surf) { |
| 51 |
LOG("Creating hardware surface failed, falling back to software surface", 1, LOG_ERROR); |
| 52 |
// there was some problem creating surface |
| 53 |
// first try to create it in SW mode |
| 54 |
surf = SDL_SetVideoMode(screenX, screenY, bitDepth, |
| 55 |
SDL_SWSURFACE | // create surface in system ram |
| 56 |
SDL_DOUBLEBUF | // create surface with dbl buffering |
| 57 |
fs); // surface is full-screen |
| 58 |
if (!surf) { |
| 59 |
LOG("Creating software surface failed", 2, LOG_ERROR); |
| 60 |
// software surface failed too, just quit |
| 61 |
// clean up SDL |
| 62 |
SDL_Quit(); |
| 63 |
// throw exception |
| 64 |
_THROWEX(ex_sdlSurfaceCreationFailed, "SDL Surface Creation Failed", "CSDLGame", "CSDLGame", |
| 65 |
"screenX = " << screenX << ", screenY = " << screenY << ", bitDepth = " << bitDepth); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
// try |
| 70 |
// { |
| 71 |
screen = new CSurface(surf); |
| 72 |
// } |
| 73 |
// background = CImgLoader::loadImage("castlebg.bmp"); |
| 74 |
// started = time(NULL); |
| 75 |
} |
| 76 |
|
| 77 |
void CSDLGame::start() |
| 78 |
{ |
| 79 |
//try |
| 80 |
//{ |
| 81 |
while(!gameLoop()); |
| 82 |
//} |
| 83 |
//catch (ex_Generic e) |
| 84 |
//{ |
| 85 |
// _ADDTRACEINFO(e, "CSDLGame", "start", ""); |
| 86 |
// throw e; |
| 87 |
//} |
| 88 |
} |
| 89 |
|
| 90 |
/*void CSDLGame::start(int time) |
| 91 |
{ |
| 92 |
runtime = time; |
| 93 |
} |
| 94 |
*/ |