new error logging

This commit is contained in:
James Turk 2003-12-31 21:17:11 +00:00
parent fa115cc885
commit 3f311298df
9 changed files with 82 additions and 60 deletions

View File

@ -1,5 +1,5 @@
ZEngine Version Log for Version 0.8.5 ZEngine Version Log for Version 0.8.5
$Id: changelog.txt,v 1.61 2003/12/31 12:59:36 cozman Exp $ $Id: changelog.txt,v 1.62 2003/12/31 21:17:11 cozman Exp $
Changes are marked with symbols that describe them: Changes are marked with symbols that describe them:
! is code that breaks backwards compatibility (used after 0.8.0-rc1, previous versions broke compatibility) ! is code that breaks backwards compatibility (used after 0.8.0-rc1, previous versions broke compatibility)
@ -18,6 +18,7 @@ Changes are marked with symbols that describe them:
! Removed Doxygen documentation comments. ! Removed Doxygen documentation comments.
! Changed several member functions with obsolete names. ! Changed several member functions with obsolete names.
+ Introduced severity option to error reporting for better error logs. + Introduced severity option to error reporting for better error logs.
+ A lot more error logging internally.
+ Added HTML output option to error system. + Added HTML output option to error system.
+ Added XML resource file support via TinyXML (ZEngine::SetResourceFile, ZEngine::GetStringResource, etc) + Added XML resource file support via TinyXML (ZEngine::SetResourceFile, ZEngine::GetStringResource, etc)
+ Added ZAnimation class. + Added ZAnimation class.

View File

@ -130,7 +130,7 @@ class ZEngine
void SetEventFilter(SDL_EventFilter filter); void SetEventFilter(SDL_EventFilter filter);
void SetErrorLog(ZErrorLogStyle logStyle, std::string logFile); void SetErrorLog(ZErrorLogStyle logStyle, std::string logFile);
void ReportError(ZErrorSeverity type, std::string desc="", ...); void ReportError(ZErrorSeverity type, std::string desc, ...);
void WriteLog(std::string str, ...); void WriteLog(std::string str, ...);
void SeedRandGen(unsigned long seed); void SeedRandGen(unsigned long seed);

View File

@ -9,6 +9,7 @@
*******************************************************************************/ *******************************************************************************/
#include "ZE_Utility.h" #include "ZE_Utility.h"
#include "ZE_ZEngine.h" //needed for error log, can't be in ZE_Utility.h (circular dependency)
namespace ZE namespace ZE
{ {
@ -33,7 +34,7 @@ SDL_RWops* RWFromZip(std::string zipname, std::string filename)
if(!zip) //failed to open zip if(!zip) //failed to open zip
{ {
//log error ZEngine::GetInstance()->ReportError(ZERR_WARNING,"Could not open zipfile %s",zipname.c_str());
return NULL; return NULL;
} }
@ -41,7 +42,7 @@ SDL_RWops* RWFromZip(std::string zipname, std::string filename)
unzLocateFile(zip,filename.c_str(),0); unzLocateFile(zip,filename.c_str(),0);
if(unzOpenCurrentFile(zip) != UNZ_OK) //failed to open file within zip if(unzOpenCurrentFile(zip) != UNZ_OK) //failed to open file within zip
{ {
return NULL; return NULL; //error should reported in calling function
} }
//find current file info (we are looking for uncompressed file size) //find current file info (we are looking for uncompressed file size)
@ -53,7 +54,7 @@ SDL_RWops* RWFromZip(std::string zipname, std::string filename)
{ {
unzCloseCurrentFile(zip); unzCloseCurrentFile(zip);
unzClose(zip); unzClose(zip);
//log error (failed to allocate memory?!) ZEngine::GetInstance()->ReportError(ZERR_ERROR,"RWFromZip failed to allocate enough memory for buffer while loading %s from %s.",filename.c_str(),zipname.c_str());
return NULL; return NULL;
} }

View File

@ -34,6 +34,8 @@ ZAnimation::~ZAnimation()
void ZAnimation::Create(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimType type, bool backwards) void ZAnimation::Create(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimType type, bool backwards)
{ {
if(!images)
rEngine->ReportError(ZERR_WARNING,"Called ZAnimation::Create with NULL images parameter.");
rAnimImages = images; rAnimImages = images;
rNumFrames = numFrames; rNumFrames = numFrames;
rFrameDelay = frameDelay; rFrameDelay = frameDelay;
@ -44,6 +46,8 @@ void ZAnimation::Create(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimT
void ZAnimation::SetAnimImages(ZImage *images, int numFrames) void ZAnimation::SetAnimImages(ZImage *images, int numFrames)
{ {
if(!images)
rEngine->ReportError(ZERR_WARNING,"Called ZAnimation::SetAnimImages with NULL images parameter.");
rAnimImages = images; rAnimImages = images;
rNumFrames = numFrames; rNumFrames = numFrames;
} }
@ -67,11 +71,18 @@ void ZAnimation::Reset()
void ZAnimation::Start() void ZAnimation::Start()
{ {
if(rAnimImages)
{
if(rAnimType != ZANIM_NONE) if(rAnimType != ZANIM_NONE)
rFrameStep = rBackwards ? -1 : 1; rFrameStep = rBackwards ? -1 : 1;
else else
rFrameStep = 0; rFrameStep = 0;
rNextFrameTime = rEngine->GetTime()+rFrameDelay; rNextFrameTime = rEngine->GetTime()+rFrameDelay;
}
else
{
rEngine->ReportError(ZERR_WARNING,"Called ZAnimation::Start with no images loaded.");
}
} }
void ZAnimation::Pause() void ZAnimation::Pause()
@ -87,7 +98,7 @@ void ZAnimation::SetFrame(int frame)
SetFrame(rNumFrames+frame); SetFrame(rNumFrames+frame);
else else
{ {
//invalid frame rEngine->ReportError(ZERR_WARNING,"Attempt to set frame to %d in ZAnimation::SetFrame, valid range is %d to %d.",frame,-rNumFrames,rNumFrames-1);
} }
} }
@ -117,7 +128,7 @@ void ZAnimation::Update()
case ZANIM_NONE: case ZANIM_NONE:
default: default:
Reset(); Reset();
//error? rEngine->ReportError(ZERR_ERROR,"Unknown error: Invalid Enum [%d] in ZAnimation::Update",static_cast<int>(rAnimType));
break; break;
} }
} }
@ -129,8 +140,8 @@ void ZAnimation::Draw(float x, float y) const
{ {
if(rAnimImages) if(rAnimImages)
rAnimImages[rCurFrame].Draw(x,y); rAnimImages[rCurFrame].Draw(x,y);
//else else
//error: images not loaded rEngine->ReportError(ZERR_WARNING,"Called ZAnimation::Draw with no images loaded.");
} }
bool ZAnimation::IsRunning() const bool ZAnimation::IsRunning() const

View File

@ -20,9 +20,6 @@ ZEngine *ZEngine::sInstance=NULL;
ZEngine::ZEngine() : ZEngine::ZEngine() :
mScreen(NULL), mFullscreen(true), mInitialized(false), mScreen(NULL), mFullscreen(true), mInitialized(false),
mPaused(false), mUnpauseOnActive(false), mPaused(false), mUnpauseOnActive(false),
#ifdef DEPRECIATED
mDesiredFramerate(0),
#endif DEPRECIATED
mNextUpdate(0), mLastPause(0), mPausedTime(0), mLastTime(0), mNextUpdate(0), mLastPause(0), mPausedTime(0), mLastTime(0),
mSecPerFrame(0.0), mSecPerFrame(0.0),
mNeedReload(false), mActive(false), mQuit(false), mKeyIsPressed(NULL), mNeedReload(false), mActive(false), mQuit(false), mKeyIsPressed(NULL),
@ -31,32 +28,42 @@ ZEngine::ZEngine() :
{ {
for(int k = 0; k < SDLK_LAST; ++k) for(int k = 0; k < SDLK_LAST; ++k)
mKeyPress[k] = false; mKeyPress[k] = false;
atexit(ZEngine::ReleaseInstance);
} }
TiXmlElement* ZEngine::FindElement(std::string type, std::string id) TiXmlElement* ZEngine::FindElement(std::string type, std::string id)
{ {
TiXmlElement *elem=NULL;
if(rZRF.RootElement()) if(rZRF.RootElement())
{ {
TiXmlElement *elem = rZRF.RootElement()->FirstChildElement(); elem = rZRF.RootElement()->FirstChildElement();
//while element exists //while element exists
while(elem) while(elem)
{ {
if(strcmpi(elem->Value(),type.c_str()) == 0 && strcmpi(elem->Attribute("id"),id.c_str()) == 0) if(strcmpi(elem->Value(),type.c_str()) == 0 && strcmpi(elem->Attribute("id"),id.c_str()) == 0)
return elem; break; //found our guy
else else
elem = elem->NextSiblingElement(); elem = elem->NextSiblingElement();
} }
//if it gets here, element not found
ReportError(ZERR_WARNING,"No '%s' resource found with id '%s'",type.c_str(),id.c_str());
elem = NULL;
}
else
{
ReportError(ZERR_WARNING,"No root element in ZRF file.");
} }
return NULL; //if it gets this far, problem return elem;
} }
ZEngine* ZEngine::GetInstance() ZEngine* ZEngine::GetInstance()
{ {
if(!sInstance) //first time through, gets new instance, each time after returns same one if(!sInstance) //first time through, gets new instance, each time after returns same one
sInstance = new ZEngine; sInstance = new ZEngine;
atexit(ZEngine::ReleaseInstance);
return sInstance; return sInstance;
} }
@ -257,7 +264,7 @@ void ZEngine::ToggleFullscreen()
#ifdef linux //SDL_WM_TF only works on Linux #ifdef linux //SDL_WM_TF only works on Linux
SDL_WM_ToggleFullScreen(mScreen); SDL_WM_ToggleFullScreen(mScreen);
#else #else
CreateDisplay(mScreen->w,mScreen->h,mScreen->format->BitsPerPixel,!mFullscreen); CreateDisplay(mScreen->w,mScreen->h,mScreen->format->BitsPerPixel,!mFullscreen); //replacement for WM_TF on Windows
#endif #endif
SetReloadNeed(true); //images need to be reloaded on fullscreen swap SetReloadNeed(true); //images need to be reloaded on fullscreen swap
} }
@ -278,16 +285,6 @@ void ZEngine::Update()
//keeps track of spf// //keeps track of spf//
mSecPerFrame = (GetTime()-mLastTime)/1000.0; mSecPerFrame = (GetTime()-mLastTime)/1000.0;
mLastTime = GetTime(); mLastTime = GetTime();
#ifdef DEPRECIATED
//framerate limiting//
if(mDesiredFramerate)
{
if(mLastTime < mNextUpdate)
SDL_Delay(mNextUpdate-mLastTime);
mNextUpdate = GetTime()+(1000/mDesiredFramerate);
}
#endif //DEPRECIATED
} }
#if (GFX_BACKEND == ZE_OGL) #if (GFX_BACKEND == ZE_OGL)
@ -477,7 +474,9 @@ void ZEngine::CheckEvents()
while(SDL_PollEvent(&event)) while(SDL_PollEvent(&event))
{ {
if(!mEventFilter || mEventFilter(&event)) //if the filter returns 0 it is removing the event, it will not be processed //only process event if filter doesn't exist or if filter returns a nonzero value
//the SDL spec says that filters return 0 when they wish to remove an item from the event queue
if(!mEventFilter || mEventFilter(&event))
{ {
switch(event.type) //only certain events are handled, mEventFilter can handle user requests switch(event.type) //only certain events are handled, mEventFilter can handle user requests
{ {
@ -666,8 +665,8 @@ double ZEngine::RandDouble()
void ZEngine::SetResourceFile(std::string filename) void ZEngine::SetResourceFile(std::string filename)
{ {
rZRF.LoadFile(filename); rZRF.LoadFile(filename);
//if(rZRF.Error()) if(rZRF.Error())
//log an error ReportError(ZERR_ERROR,"Error loading resource file %s.",filename.c_str());
} }
std::string ZEngine::GetStringResource(std::string type, std::string id, std::string element) std::string ZEngine::GetStringResource(std::string type, std::string id, std::string element)
@ -677,7 +676,7 @@ std::string ZEngine::GetStringResource(std::string type, std::string id, std::st
return elem->Attribute(element.c_str()); return elem->Attribute(element.c_str());
else else
{ {
//error ReportError(ZERR_WARNING,"GetStringResource(%s,%s,%s) failed.",type.c_str(),id.c_str(),element.c_str());
return ""; //empty string return ""; //empty string
} }
} }
@ -685,34 +684,35 @@ std::string ZEngine::GetStringResource(std::string type, std::string id, std::st
int ZEngine::GetIntResource(std::string type, std::string id, std::string element) int ZEngine::GetIntResource(std::string type, std::string id, std::string element)
{ {
TiXmlElement *elem = FindElement(type,id); TiXmlElement *elem = FindElement(type,id);
int ret; int ret=0;
if(elem && (elem->QueryIntAttribute(element.c_str(),&ret) == TIXML_SUCCESS)) if(!elem || (elem->QueryIntAttribute(element.c_str(),&ret) != TIXML_SUCCESS))
return ret;
else
{ {
if(!elem) if(!elem)
WriteLog("no elem"); ReportError(ZERR_WARNING,"GetIntResource(%s,%s,%s) failed, no tags of that type.",type.c_str(),id.c_str(),element.c_str());
else if(elem->QueryIntAttribute(element.c_str(),&ret) == TIXML_NO_ATTRIBUTE) else if(elem->QueryIntAttribute(element.c_str(),&ret) == TIXML_NO_ATTRIBUTE)
WriteLog("no attribute"); ReportError(ZERR_WARNING,"GetIntResource(%s,%s,%s) failed, no tag with that ID.",type.c_str(),id.c_str(),element.c_str());
else if(elem->QueryIntAttribute(element.c_str(),&ret) == TIXML_WRONG_TYPE) else if(elem->QueryIntAttribute(element.c_str(),&ret) == TIXML_WRONG_TYPE)
WriteLog("wrong type"); ReportError(ZERR_WARNING,"GetIntResource(%s,%s,%s) failed, not an integer.",type.c_str(),id.c_str(),element.c_str());
return 0;
} }
return ret;
} }
double ZEngine::GetDoubleResource(std::string type, std::string id, std::string element) double ZEngine::GetDoubleResource(std::string type, std::string id, std::string element)
{ {
TiXmlElement *elem = FindElement(type,id); TiXmlElement *elem = FindElement(type,id);
double ret; double ret=0;
if(elem && elem->QueryDoubleAttribute(element.c_str(),&ret) == TIXML_SUCCESS) if(!elem || (elem->QueryDoubleAttribute(element.c_str(),&ret) != TIXML_SUCCESS))
return ret;
else
{ {
//error if(!elem)
return 0; ReportError(ZERR_WARNING,"GetDoubleResource(%s,%s,%s) failed, no tags of that type.",type.c_str(),id.c_str(),element.c_str());
else if(elem->QueryDoubleAttribute(element.c_str(),&ret) == TIXML_NO_ATTRIBUTE)
ReportError(ZERR_WARNING,"GetDoubleResource(%s,%s,%s) failed, no tag with that ID.",type.c_str(),id.c_str(),element.c_str());
else if(elem->QueryDoubleAttribute(element.c_str(),&ret) == TIXML_WRONG_TYPE)
ReportError(ZERR_WARNING,"GetDoubleResource(%s,%s,%s) failed, not a double.",type.c_str(),id.c_str(),element.c_str());
} }
return ret;
} }
bool ZEngine::DisplayCreated() bool ZEngine::DisplayCreated()

View File

@ -78,7 +78,7 @@ void ZFont::OpenFromZRF(std::string resourceId)
if(filename.length() && size) if(filename.length() && size)
Open(filename,size); Open(filename,size);
else else
;//error rEngine->ReportError(ZERR_WARNING,"Failed to load font resource '%s'",resourceId.c_str());
} }
void ZFont::Release() void ZFont::Release()
@ -95,6 +95,8 @@ void ZFont::DrawText(std::string text, ZImage &image) const
image.Attach(TTF_RenderText_Blended(rFont, text.c_str(), rColor)); image.Attach(TTF_RenderText_Blended(rFont, text.c_str(), rColor));
image.SetAlpha(rColor.unused); //the images alpha comes from the SetColor a parameter image.SetAlpha(rColor.unused); //the images alpha comes from the SetColor a parameter
} }
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::DrawText with no font loaded.");
} }
void ZFont::DrawShadedText(std::string text, ZImage &image) const void ZFont::DrawShadedText(std::string text, ZImage &image) const
@ -106,6 +108,8 @@ void ZFont::DrawShadedText(std::string text, ZImage &image) const
image.Attach(TTF_RenderText_Shaded(rFont, text.c_str(), rColor, rBGColor)); image.Attach(TTF_RenderText_Shaded(rFont, text.c_str(), rColor, rBGColor));
image.SetAlpha(rColor.unused); image.SetAlpha(rColor.unused);
} }
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::DrawShadedText with no font loaded.");
} }
void ZFont::SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) void ZFont::SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
@ -144,10 +148,15 @@ void ZFont::SetStyle(bool bold, bool italic, bool underline)
void ZFont::Resize(int size) void ZFont::Resize(int size)
{ {
if(rFilename.length())
{
if(rZipname.length()) if(rZipname.length())
OpenFromZip(rZipname,rFilename,size); OpenFromZip(rZipname,rFilename,size);
else else
Open(rFilename,size); Open(rFilename,size);
}
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::Resize with no font loaded.");
} }
bool ZFont::IsLoaded() const bool ZFont::IsLoaded() const

View File

@ -117,8 +117,8 @@ void ZImage::OpenFromZRF(std::string resourceId)
std::string filename = rEngine->GetStringResource("image",resourceId,"filename"); std::string filename = rEngine->GetStringResource("image",resourceId,"filename");
if(filename.length()) if(filename.length())
Open(filename); Open(filename);
//else else
//error rEngine->ReportError(ZERR_WARNING,"Failed to load image resource '%s'",resourceId.c_str());
} }
void ZImage::OpenFromImage(SDL_Surface *image, Sint16 x, Sint16 y, Sint16 w, Sint16 h) void ZImage::OpenFromImage(SDL_Surface *image, Sint16 x, Sint16 y, Sint16 w, Sint16 h)

View File

@ -51,8 +51,8 @@ void ZMusic::OpenFromZRF(std::string resourceId)
std::string filename = rEngine->GetStringResource("music",resourceId,"filename"); std::string filename = rEngine->GetStringResource("music",resourceId,"filename");
if(filename.length()) if(filename.length())
Open(filename); Open(filename);
//else else
//error rEngine->ReportError(ZERR_WARNING,"Failed to load music resource '%s'",resourceId.c_str());
} }
void ZMusic::Release() void ZMusic::Release()

View File

@ -68,8 +68,8 @@ void ZSound::OpenFromZRF(std::string resourceId)
std::string filename = rEngine->GetStringResource("sound",resourceId,"filename"); std::string filename = rEngine->GetStringResource("sound",resourceId,"filename");
if(filename.length()) if(filename.length())
Open(filename); Open(filename);
//else else
//error rEngine->ReportError(ZERR_WARNING,"Failed to load sound resource '%s'",resourceId.c_str());
} }
void ZSound::Release() void ZSound::Release()