Surface Loss Protection

This commit is contained in:
James Turk 2002-12-27 03:15:33 +00:00
parent 6fc9a96ad1
commit 7d30f555c5
5 changed files with 66 additions and 16 deletions

View File

@ -1,11 +1,15 @@
ZEngine Version Log for Version 0.8.0-rc4
$Id: changelog.txt,v 1.16 2002/12/22 06:07:56 cozman Exp $
$Id: changelog.txt,v 1.17 2002/12/27 03:15:33 cozman Exp $
0.8.0
-Added Surface Loss Protection.
-Utilized Surface Loss Protection in ZImageTest for a demo.
0.8.0-rc4 (AKA "what rc3 should have been")
-Fixed ZImage::SetColorKey for new Attach behavior.
-Fixed ZMusicTest GL screen error if music fails to open.
-Fixed VC7 "Release" Project files.
-Removed switch option from tests.
-Removed switch option from tests due to surface loss.
0.8.0-rc3
-Fixed MAJOR memory leak when using ZImage::Attach, and in ZFont.

View File

@ -13,7 +13,7 @@
File: ZE_ZEngine.h <br>
Description: Header file for ZEngine class, the core of the ZEngine. <br>
Author(s): James Turk <br>
$Id: ZE_ZEngine.h,v 1.6 2002/12/12 02:50:35 cozman Exp $<br>
$Id: ZE_ZEngine.h,v 1.7 2002/12/27 03:15:33 cozman Exp $<br>
\file ZE_ZEngine.h
\brief Definition file for core ZEngine class.
@ -268,8 +268,9 @@ class ZEngine
////////////////////////////
//Event and Input Handling//
////////////////////////////
private:
//! bool which is only set to true if the engine thinks the images need to be reloaded (loss of focus in fullscreen).
bool mNeedReload;
//! bool describing Active or Inactive State of Game
bool mActive;
//! bool for checking if a Quit event has been detected
@ -310,6 +311,21 @@ class ZEngine
\return bool telling if quit has been requested.
**/
bool QuitRequested();
/*!
\brief Set State of ImagesNeedReload.
\param state False if images need to be reloaded, True if images have been reloaded.
**/
void SetReloadNeed(bool state);
/*!
\brief Find out if images should be reloaded.
Function that is good to call every frame to check if images should be reloaded, usually only caused by loss of focus in
fullscreen.
\return bool, True if images should be reloaded, false otherwise.
**/
bool ImagesNeedReload();
/*!
\brief Set Key repeat rate.

View File

@ -3,7 +3,7 @@
File: ZEngine.h <br>
Description: Public Header File for ZEngine. <br>
Author(s): James Turk <br>
$Id: ZEngine.h,v 1.10 2002/12/12 04:33:18 cozman Exp $<br>
$Id: ZEngine.h,v 1.11 2002/12/27 03:15:33 cozman Exp $<br>
\file ZEngine.h
\brief Header file for ZEngine.
@ -16,8 +16,8 @@ $Id: ZEngine.h,v 1.10 2002/12/12 04:33:18 cozman Exp $<br>
\mainpage ZEngine Documentation
\author James Turk
\version 0.8.0-rc2
\date December 12, 2002
\version 0.8.0-rc4
\date December 26, 2002
\section ZEngine About ZEngine
<br>

View File

@ -13,7 +13,7 @@
File: ZE_ZEngine.cpp <br>
Description: Implementation source file for ZEngine library main singleton class. <br>
Author(s): James Turk <br>
$Id: ZE_ZEngine.cpp,v 1.7 2002/12/12 02:50:35 cozman Exp $<br>
$Id: ZE_ZEngine.cpp,v 1.8 2002/12/27 03:15:33 cozman Exp $<br>
\file ZE_ZEngine.cpp
\brief Central source file for ZEngine.
@ -39,6 +39,7 @@ ZEngine::ZEngine()
mRate = 22050;
mStereo = false;
#endif
mNeedReload = false;
mScreen = NULL;
@ -298,6 +299,16 @@ bool ZEngine::QuitRequested()
return mQuit;
}
void ZEngine::SetReloadNeed(bool state)
{
mNeedReload = state;
}
bool ZEngine::ImagesNeedReload()
{
return mNeedReload;
}
void ZEngine::SetKeyRepeatRate(int rate)
{
SDL_EnableKeyRepeat(rate,rate);
@ -368,6 +379,8 @@ void ZEngine::CheckEvents()
mActive = true;
if(mUnpauseOnActive)
UnpauseTimer();
if(mFullscreen)
mNeedReload = true;
}
else
{

View File

@ -24,7 +24,7 @@ void Initialize()
w = cfg.GetInt("ZImageTest","width",800);
h = cfg.GetInt("ZImageTest","height",600);
bpp = cfg.GetInt("ZImageTest","bpp",32);
fs = cfg.GetBool("ZImageTest","fullscreen",false);
fs = cfg.GetBool("ZImageTest","fullscreen",true);
title = cfg.GetString("ZImageTest","title","ZImage Test");
engine->SetupDisplay(w,h,bpp,fs);
@ -38,22 +38,39 @@ void Test()
//Open and Setup all the Images//
SDL_Surface *temp;
ZImage image1, image2("data/test01.bmp"), image3(image2.Surface(),5,5,20,20), textImage;
ZImage image1, image2, image3, textImage;
ZFont font("data/almontew.ttf",30);
temp = SDL_LoadBMP("data/test02.bmp"); //this is a separate surface
image1.Attach(temp); //this attaches the surface into itself
temp = NULL; //and temp will now be controlled and freed by image1
image1.SetColorKey(255,0,255);
image2.SetColorKey(255,0,255);
engine->SetReloadNeed(true); //start off needing the reload
font.SetColor(0,255,0);
font.SetBGColor(0,0,255);
font.DrawShadedText("ZImage Test.",textImage);
do
{
//In the active loop, check events first//
engine->CheckEvents();
if(engine->ImagesNeedReload())
{
temp = SDL_LoadBMP("data/test02.bmp"); //this is a separate surface
image1.Attach(temp); //this attaches the surface into itself
image2.Open("data/test01.bmp");
image3.OpenFromImage(image2.Surface(),5,5,20,20);
temp = NULL; //and temp will now be controlled and freed by image1
image1.SetColorKey(255,0,255);
image2.SetColorKey(255,0,255);
font.DrawShadedText("ZImage Test.",textImage);
engine->SetReloadNeed(false); //very important for speed, without this you'd be reloading every frame
}
if(engine->KeyIsPressed(SDLK_s))
{
//code to toggle screen//
engine->SetupDisplay(engine->Width(),engine->Height(),engine->BPP(),!engine->IsFullscreen());
engine->CreateDisplay("ZImage Test");
engine->SetReloadNeed(true);
}
if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit();