Initialized check + toggle fullscreen fix
This commit is contained in:
parent
cfd50e58f8
commit
4365e8ae26
@ -13,7 +13,7 @@
|
|||||||
File: ZE_ZEngine.h <br>
|
File: ZE_ZEngine.h <br>
|
||||||
Description: Header file for ZEngine class, the core of the ZEngine. <br>
|
Description: Header file for ZEngine class, the core of the ZEngine. <br>
|
||||||
Author(s): James Turk <br>
|
Author(s): James Turk <br>
|
||||||
$Id: ZE_ZEngine.h,v 1.17 2003/01/25 19:55:13 cozman Exp $<br>
|
$Id: ZE_ZEngine.h,v 1.18 2003/01/27 04:33:34 cozman Exp $<br>
|
||||||
|
|
||||||
\file ZE_ZEngine.h
|
\file ZE_ZEngine.h
|
||||||
\brief Definition file for core ZEngine class.
|
\brief Definition file for core ZEngine class.
|
||||||
@ -98,6 +98,8 @@ class ZEngine
|
|||||||
int mBPP;
|
int mBPP;
|
||||||
//! Fullscreen setting of Display
|
//! Fullscreen setting of Display
|
||||||
bool mFullscreen;
|
bool mFullscreen;
|
||||||
|
//! If ZEngine display has been setup.
|
||||||
|
bool mInitialized;
|
||||||
|
|
||||||
#ifdef USE_SDL_MIXER
|
#ifdef USE_SDL_MIXER
|
||||||
//! Sound Bitrate
|
//! Sound Bitrate
|
||||||
@ -163,6 +165,15 @@ class ZEngine
|
|||||||
**/
|
**/
|
||||||
void ToggleFullscreen();
|
void ToggleFullscreen();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Check state of ZEngine.
|
||||||
|
|
||||||
|
Checks if ZEngine display has been properly setup.
|
||||||
|
\since 0.8.2
|
||||||
|
\return Boolean status of ZEngine, true if CreateDisplay has been successfully called, false if ZEngine has no display.
|
||||||
|
**/
|
||||||
|
bool Initialized();
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
//Screen Access//
|
//Screen Access//
|
||||||
/////////////////
|
/////////////////
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
File: ZE_ZEngine.cpp <br>
|
File: ZE_ZEngine.cpp <br>
|
||||||
Description: Implementation source file for ZEngine library main singleton class. <br>
|
Description: Implementation source file for ZEngine library main singleton class. <br>
|
||||||
Author(s): James Turk <br>
|
Author(s): James Turk <br>
|
||||||
$Id: ZE_ZEngine.cpp,v 1.24 2003/01/26 00:55:52 cozman Exp $<br>
|
$Id: ZE_ZEngine.cpp,v 1.25 2003/01/27 04:33:34 cozman Exp $<br>
|
||||||
|
|
||||||
\file ZE_ZEngine.cpp
|
\file ZE_ZEngine.cpp
|
||||||
\brief Central source file for ZEngine.
|
\brief Central source file for ZEngine.
|
||||||
@ -30,6 +30,7 @@ ZEngine *ZEngine::sInstance=NULL;
|
|||||||
|
|
||||||
ZEngine::ZEngine()
|
ZEngine::ZEngine()
|
||||||
{
|
{
|
||||||
|
mInitialized = false;
|
||||||
mWidth = 640;
|
mWidth = 640;
|
||||||
mHeight = 480;
|
mHeight = 480;
|
||||||
mBPP = 16;
|
mBPP = 16;
|
||||||
@ -105,27 +106,34 @@ bool ZEngine::CreateDisplay(string title, string icon)
|
|||||||
{
|
{
|
||||||
Uint32 flags=0;
|
Uint32 flags=0;
|
||||||
SDL_Surface *iconImg;
|
SDL_Surface *iconImg;
|
||||||
bool status=true; //status of setup
|
bool status=true; //status of setup, only true if everything went flawless
|
||||||
int bpp;
|
int bpp;
|
||||||
int rgb_size[3];
|
int rgb_size[3];
|
||||||
|
|
||||||
|
if(!mInitialized)
|
||||||
|
{
|
||||||
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0)
|
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0)
|
||||||
{
|
{
|
||||||
ReportError(ZERR_SDL_INIT,SDL_GetError());
|
ReportError(ZERR_SDL_INIT,SDL_GetError());
|
||||||
return false; //return now, nothing else should be called
|
return false; //return now, nothing else should be called
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_SDL_MIXER
|
#ifdef USE_SDL_MIXER
|
||||||
|
if(!mInitialized)
|
||||||
|
{
|
||||||
if(Mix_OpenAudio(mRate, AUDIO_S16SYS, mStereo?2:1, 4096) < 0) //Open Audio (Stereo?2:1 is conditional for number of channels)
|
if(Mix_OpenAudio(mRate, AUDIO_S16SYS, mStereo?2:1, 4096) < 0) //Open Audio (Stereo?2:1 is conditional for number of channels)
|
||||||
{
|
{
|
||||||
ReportError(ZERR_MIX_INIT,SDL_GetError());
|
ReportError(ZERR_MIX_INIT,SDL_GetError());
|
||||||
status = false; //continue setup without sound
|
status = false; //continue setup without sound
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif //USE_SDL_MIXER
|
#endif //USE_SDL_MIXER
|
||||||
|
|
||||||
//set flags and bpp//
|
//set flags and bpp//
|
||||||
if(mFullscreen)
|
if(mFullscreen)
|
||||||
flags |= SDL_FULLSCREEN;
|
flags |= SDL_FULLSCREEN;
|
||||||
|
|
||||||
if(mBPP != -1 && mBPP != 8 && mBPP != 15 && mBPP != 16 && mBPP != 24 && mBPP !=32)
|
if(mBPP != -1 && mBPP != 8 && mBPP != 15 && mBPP != 16 && mBPP != 24 && mBPP !=32)
|
||||||
{
|
{
|
||||||
ReportError(ZERR_VIDMODE,FormatStr("%d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",mBPP));
|
ReportError(ZERR_VIDMODE,FormatStr("%d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",mBPP));
|
||||||
@ -173,7 +181,7 @@ bool ZEngine::CreateDisplay(string title, string icon)
|
|||||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
|
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
|
||||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, mBPP==32 ? 24 : mBPP);
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, mBPP==32 ? 24 : mBPP); //use 24 if BPP is 32
|
||||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
|
||||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0);
|
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0);
|
||||||
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0);
|
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0);
|
||||||
@ -182,7 +190,9 @@ bool ZEngine::CreateDisplay(string title, string icon)
|
|||||||
|
|
||||||
flags |= SDL_OPENGL;
|
flags |= SDL_OPENGL;
|
||||||
|
|
||||||
//Window Manager settings//
|
if(!mInitialized) //only set these settings the first time
|
||||||
|
{
|
||||||
|
//Default window manager settings//
|
||||||
SDL_EnableKeyRepeat(30,30);
|
SDL_EnableKeyRepeat(30,30);
|
||||||
if(!icon.length())
|
if(!icon.length())
|
||||||
SDL_WM_SetCaption(title.c_str(),NULL);
|
SDL_WM_SetCaption(title.c_str(),NULL);
|
||||||
@ -193,6 +203,7 @@ bool ZEngine::CreateDisplay(string title, string icon)
|
|||||||
SDL_WM_SetIcon(iconImg,NULL);
|
SDL_WM_SetIcon(iconImg,NULL);
|
||||||
FreeImage(iconImg);
|
FreeImage(iconImg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//create SDL screen and update settings based on returned screen//
|
//create SDL screen and update settings based on returned screen//
|
||||||
mScreen = SDL_SetVideoMode(mWidth, mHeight, mBPP, flags);
|
mScreen = SDL_SetVideoMode(mWidth, mHeight, mBPP, flags);
|
||||||
@ -218,21 +229,28 @@ bool ZEngine::CreateDisplay(string title, string icon)
|
|||||||
mKeyIsPressed = SDL_GetKeyState(NULL);
|
mKeyIsPressed = SDL_GetKeyState(NULL);
|
||||||
|
|
||||||
#ifdef USE_SDL_TTF
|
#ifdef USE_SDL_TTF
|
||||||
|
if(!mInitialized)
|
||||||
|
{
|
||||||
if(TTF_Init() < 0)
|
if(TTF_Init() < 0)
|
||||||
{
|
{
|
||||||
ReportError(ZERR_TTF_INIT,TTF_GetError());
|
ReportError(ZERR_TTF_INIT,TTF_GetError());
|
||||||
status = false; //possible to go on without SDL_TTF
|
status = false; //possible to go on without SDL_TTF
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif //USE_SDL_TTF
|
#endif //USE_SDL_TTF
|
||||||
|
|
||||||
|
if(!mInitialized)
|
||||||
mLastTime = mPausedTime = SDL_GetTicks();
|
mLastTime = mPausedTime = SDL_GetTicks();
|
||||||
mActive = true;
|
mActive = true;
|
||||||
|
mInitialized = true; //if it makes it to the end it has been initialized
|
||||||
|
|
||||||
return status; //return true (false will be returned if TTF or Mixer fail)
|
return status; //return true (false will be returned if TTF or Mixer fail)
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZEngine::CloseDisplay()
|
void ZEngine::CloseDisplay()
|
||||||
{
|
{
|
||||||
|
if(mInitialized)
|
||||||
|
{
|
||||||
#ifdef USE_SDL_TTF
|
#ifdef USE_SDL_TTF
|
||||||
TTF_Quit();
|
TTF_Quit();
|
||||||
#endif
|
#endif
|
||||||
@ -249,6 +267,9 @@ void ZEngine::CloseDisplay()
|
|||||||
|
|
||||||
if(mErrlog != stderr && mErrlog != stdin)
|
if(mErrlog != stderr && mErrlog != stdin)
|
||||||
fclose(mErrlog);
|
fclose(mErrlog);
|
||||||
|
|
||||||
|
mInitialized = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZEngine::ToggleFullscreen()
|
void ZEngine::ToggleFullscreen()
|
||||||
@ -259,10 +280,17 @@ void ZEngine::ToggleFullscreen()
|
|||||||
#else
|
#else
|
||||||
SetupDisplay(mWidth,mHeight,mBPP,!mFullscreen);
|
SetupDisplay(mWidth,mHeight,mBPP,!mFullscreen);
|
||||||
SDL_WM_GetCaption(&title,&icon);
|
SDL_WM_GetCaption(&title,&icon);
|
||||||
|
if(icon)
|
||||||
|
CreateDisplay(title,icon);
|
||||||
|
else
|
||||||
CreateDisplay(title);
|
CreateDisplay(title);
|
||||||
#endif
|
#endif
|
||||||
SetReloadNeed(true);
|
SetReloadNeed(true);
|
||||||
mActive = true;
|
}
|
||||||
|
|
||||||
|
bool ZEngine::Initialized()
|
||||||
|
{
|
||||||
|
return mInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *ZEngine::Display()
|
SDL_Surface *ZEngine::Display()
|
||||||
|
Loading…
Reference in New Issue
Block a user