line endings!

This commit is contained in:
James Turk 2003-11-24 02:17:32 +00:00
parent 6709e83d94
commit fa7c896540
8 changed files with 1070 additions and 1279 deletions

View File

@ -1,127 +0,0 @@
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
/*!
\file ZE_ZError.h
\brief Definition file for ZError.
Definition file for ZError, the Error logging class for ZEngine.
This class should never be used by the average user, it is used by ZEngine to store information on an error.
<br>$Id: ZE_ZError.h,v 1.14 2003/08/31 18:34:38 cozman Exp $<br>
\author James Turk
**/
#ifndef __ze_zerror_h__
#define __ze_zerror_h__
#include "ZE_Utility.h"
#include <string>
namespace ZE
{
/*!
\brief Enumeration of ZEngine error codes.
All the error codes currently possibly by ZEngine, note that ZERR_LAST is not used as an error code, but instead
as a range check on the others.
**/
enum ZErrorCode
{
ZERR_NONE, /*!< No error has occured. */
ZERR_SDL_INTERNAL, /*!< Error internal to SDL has occured, usually more detail is given by SDL. */
ZERR_SDL_INIT, /*!< Error Initializing SDL. */
ZERR_MIX_INIT, /*!< Error Initializing SDL_mixer. */
ZERR_TTF_INIT, /*!< Error Initializing SDL_ttf. */
ZERR_VIDMODE, /*!< Error setting up the display. */
ZERR_LOAD_IMAGE, /*!< Error loading an image. */
ZERR_LOAD_SOUND, /*!< Error loading a sound sample. */
ZERR_LOAD_MUSIC, /*!< Error loading music. */
ZERR_LOAD_FONT, /*!< Error loading a font. */
ZERR_NOIMAGE, /*!< Error trying to use a ZImage without properly loading an image. */
ZERR_NOSOUND, /*!< Error trying to use a ZSound without properly loading a sound. */
ZERR_NOMUSIC, /*!< Error trying to use a ZMusic without properly loading music. */
ZERR_NOFONT, /*!< Error trying to use a ZFont without properly loading a font. */
ZERR_LAST /*!< Value used as range index, not a valid error code. */
};
/*!
\brief ZError class for describing errors.
ZError class for storing and printing information on errors. Inherited from ZObject and tied closely to ZEngine.
\since 0.8.2
**/
class ZError
{
protected:
//! Static Array of Error Identifiers
static std::string sErrorDesc[ZERR_LAST];
//! Error ID.
ZErrorCode rCode;
//! Error Description.
std::string rDescription;
//! File which error occured in.
std::string rFilename;
//! Line which error occured on.
unsigned int rLine;
public:
/*!
\brief Construct string table for error strings.
Constructs a string table for errors, enabling ZEngine to properly delete the table on exit.
**/
static void CreateStringTable();
/*!
\brief Default constructor for ZError.
Make new ZError object, by default set rCode to ZERR_NONE with no description.
\param code ZErrorCode to set object to, defaults to ZERR_NONE.
\param desc Description to use for object, defaults to nothing.
\param file Optional argument specifying the file the error occured in.
\param line Optional argument specifying the line the error occured on.
**/
ZError(ZErrorCode code=ZERR_NONE, std::string desc="", std::string file="", int line=0);
/*!
\brief Set members of error object.
Set new values in ZError object.
\param code ZErrorCode to set object to.
\param desc Description to use for object, defaults to nothing.
\param file Optional argument specifying the file the error occured in.
\param line Optional argument specifying the line the error occured on.
**/
void Create(ZErrorCode code, std::string desc="", std::string file="", int line=0);
/////////////
//Accessors//
/////////////
/*!
\brief Get ZErrorCode of error.
Access ZErrorCode of the ZError object.
\return The error ZErrorCode.
**/
ZErrorCode Code() const;
/*!
\brief Get formatted string for log file.
Return the string to be written to the logfile. Called by ZEngine in LogError.
**/
std::string LogString() const;
};
}
#endif //__ze_zerror_h__

View File

@ -13,7 +13,7 @@
\brief Central source file for ZEngine.
Actual implementation of ZEngine singleton class, the core of ZEngine.
<br>$Id: ZE_ZEngine.cpp,v 1.64 2003/10/24 21:20:09 cozman Exp $<br>
<br>$Id: ZE_ZEngine.cpp,v 1.65 2003/11/24 02:21:20 cozman Exp $<br>
\author James Turk
**/
@ -33,12 +33,26 @@ ZEngine::ZEngine() :
mSecPerFrame(0.0),
mNeedReload(false), mActive(false), mQuit(false), mKeyIsPressed(NULL),
mMouseX(0), mMouseY(0), mMouseB(0),
mLogAllErrors(true), mErrlog(stderr), mEventFilter(NULL)
mErrlog(stderr), mEventFilter(NULL)
{
for(int k = 0; k < SDLK_LAST; ++k)
mKeyPress[k] = false;
ZError::CreateStringTable();
//create error strings
mErrorDesc[ZERR_NONE] = "No Error. [%s]";
mErrorDesc[ZERR_SDL_INTERNAL] = "SDL Error. [%s]";
mErrorDesc[ZERR_SDL_INIT] = "Error Initializing SDL: %s";
mErrorDesc[ZERR_MIX_INIT] = "Error Initializing SDL_mixer: %s";
mErrorDesc[ZERR_TTF_INIT] = "Error Initializing SDL_ttf: %s";
mErrorDesc[ZERR_VIDMODE] = "Error Creating Display: %s";
mErrorDesc[ZERR_LOAD_IMAGE] = "Failed to load Image: %s";
mErrorDesc[ZERR_LOAD_SOUND] = "Failed to load Sound: %s";
mErrorDesc[ZERR_LOAD_MUSIC] = "Failed to load Music: %s";
mErrorDesc[ZERR_LOAD_FONT] = "Failed to load Font: %s";
mErrorDesc[ZERR_NOIMAGE] = "Called ZImage::%s with no Image loaded.";
mErrorDesc[ZERR_NOSOUND] = "Called ZSound::%s with no Sound loaded.";
mErrorDesc[ZERR_NOMUSIC] = "Called ZMusic::%s with no Music loaded.";
mErrorDesc[ZERR_NOFONT] = "Called ZFont::%s with no Font loaded.";
}
ZEngine* ZEngine::GetInstance()
@ -102,7 +116,7 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std
if(bpp != -1 && bpp != 8 && bpp != 15 && bpp != 16 && bpp != 24 && bpp !=32)
{
ReportError(ZERR_VIDMODE,FormatStr("%d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",bpp));
ReportError(ZERR_VIDMODE,"%d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",bpp);
bpp = -1;
}
else //this decides correcr BPP
@ -113,12 +127,12 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std
okBPP = SDL_VideoModeOK(width, height, bpp, vidFlags);
if(!okBPP)
{
ReportError(ZERR_VIDMODE,FormatStr("%dx%d not supported in any depth.",width,height));
ReportError(ZERR_VIDMODE,"%dx%d not supported in any depth.",width,height);
return false; //return now
}
else if(okBPP != bpp)
{
ReportError(ZERR_VIDMODE,FormatStr("%dx%d not supported in %dBPP, trying %dBPP.",width,height,bpp,okBPP));
ReportError(ZERR_VIDMODE,"%dx%d not supported in %dBPP, trying %dBPP.",width,height,bpp,okBPP);
bpp = okBPP;
}
}
@ -178,7 +192,7 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std
if(!mScreen)
{
ReportError(ZERR_VIDMODE,FormatStr("Unknown Error. %dx%d %dBPP (%s)", width, height, bpp, SDL_GetError()));
ReportError(ZERR_VIDMODE,"Unknown Error. %dx%d %dBPP (%s)", width, height, bpp, SDL_GetError());
#ifdef USE_SDL_MIXER
Mix_CloseAudio();
@ -228,7 +242,7 @@ void ZEngine::CloseDisplay()
SDL_Quit();
if(mErrlog != stderr && mErrlog != stdin)
if(mErrlog && mErrlog != stderr && mErrlog != stdin)
fclose(mErrlog);
mInitialized = false;
@ -534,12 +548,11 @@ void ZEngine::SetEventFilter(SDL_EventFilter filter)
mEventFilter = filter;
}
void ZEngine::SetErrorLog(bool logAll, std::string logFile)
void ZEngine::SetErrorLog(std::string logFile)
{
mLogAllErrors = logAll;
if(logFile.length())
{
//stderr & stdout are special cases, and should be directed to their appropriate streams
//stderr & stdout directed to their appropriate streams
if(logFile == "stderr")
mErrlog = stderr;
else if(logFile == "stdout")
@ -549,42 +562,27 @@ void ZEngine::SetErrorLog(bool logAll, std::string logFile)
}
}
void ZEngine::ReportError(ZErrorCode code, std::string desc, std::string file, unsigned int line)
void ZEngine::DisableErrorLog()
{
mCurError.Create(code,desc,file,line);
if(mLogAllErrors)
LogError(mCurError);
else
mErrorQueue.push(mCurError);
mErrlog = NULL;
}
ZErrorCode ZEngine::GetLastError()
void ZEngine::ReportError(ZErrorCode type, std::string desc, ...)
{
ZErrorCode code = mCurError.Code();
mCurError.Create(ZERR_NONE);
return code;
}
char buf[512];
va_list args;
std::string msg;
void ZEngine::WriteLog(std::string str)
{
std::fprintf(mErrlog,str.c_str());
std::fprintf(mErrlog,"\n");
std::fflush(mErrlog);
}
va_start(args,desc);
vsprintf(buf,desc.c_str(),args);
va_end(args);
void ZEngine::LogError(ZError error)
{
std::fprintf(mErrlog,error.LogString().c_str());
std::fflush(mErrlog);
}
msg = desc.length() ? FormatStr(mErrorDesc[type],buf) : mErrorDesc[type];
void ZEngine::FlushErrors()
{
while(!mErrorQueue.empty())
if(mErrlog)
{
LogError(mErrorQueue.front());
mErrorQueue.pop();
std::fprintf(mErrlog,msg.c_str());
std::fflush(mErrlog);
}
}

View File

@ -1,79 +0,0 @@
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
/**
\file ZE_ZError.cpp
\brief Source file for ZError.
Implementation of ZError, the ZEngine internal error information storage class.
<br>$Id: ZE_ZError.cpp,v 1.12 2003/08/31 18:34:38 cozman Exp $<br>
\author James Turk
**/
#include "ZE_ZError.h"
namespace ZE
{
std::string ZError::sErrorDesc[ZERR_LAST];
void ZError::CreateStringTable()
{
//create error strings
sErrorDesc[ZERR_NONE] = "No Error. [%s]";
sErrorDesc[ZERR_SDL_INTERNAL] = "SDL Error. [%s]";
sErrorDesc[ZERR_SDL_INIT] = "Error Initializing SDL: %s";
sErrorDesc[ZERR_MIX_INIT] = "Error Initializing SDL_mixer: %s";
sErrorDesc[ZERR_TTF_INIT] = "Error Initializing SDL_ttf: %s";
sErrorDesc[ZERR_VIDMODE] = "Error Creating Display: %s";
sErrorDesc[ZERR_LOAD_IMAGE] = "Failed to load Image: %s";
sErrorDesc[ZERR_LOAD_SOUND] = "Failed to load Sound: %s";
sErrorDesc[ZERR_LOAD_MUSIC] = "Failed to load Music: %s";
sErrorDesc[ZERR_LOAD_FONT] = "Failed to load Font: %s";
sErrorDesc[ZERR_NOIMAGE] = "Called ZImage::%s with no Image loaded.";
sErrorDesc[ZERR_NOSOUND] = "Called ZSound::%s with no Sound loaded.";
sErrorDesc[ZERR_NOMUSIC] = "Called ZMusic::%s with no Music loaded.";
sErrorDesc[ZERR_NOFONT] = "Called ZFont::%s with no Font loaded.";
}
ZError::ZError(ZErrorCode code, std::string desc, std::string file, int line) :
rCode(code), rDescription(desc), rFilename(file), rLine(line)
{
}
void ZError::Create(ZErrorCode code, std::string desc, std::string file, int line)
{
rCode = code;
rDescription = desc;
rFilename = file;
rLine = line;
}
ZErrorCode ZError::Code() const
{
return rCode;
}
std::string ZError::LogString() const
{
std::string msg;
//if there is a description be sure to integrate it
msg = rDescription.length() ? FormatStr(sErrorDesc[rCode].c_str(),rDescription.c_str()) : sErrorDesc[rCode];
if(rLine != 0) //if there is a line (there is also a filename)
return FormatStr(" -%s(%d): %s\n",rFilename.c_str(),rLine,msg.c_str());
else if(rFilename.length()) //no line, just filename
return FormatStr(" -%s: %s\n",rFilename.c_str(),msg.c_str());
else //just the message
return FormatStr(" -%s\n",msg.c_str());
}
}

View File

@ -1,244 +1,244 @@
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
/**
\file ZE_ZFont.cpp
\brief Source file for ZFont.
Implementation of ZFont, the basic Font class for ZEngine.
<br>$Id: ZE_ZFont.cpp,v 1.15 2003/10/12 04:09:46 cozman Exp $<br>
\author James Turk
**/
#include "ZE_ZFont.h"
#ifdef USE_SDL_TTF
namespace ZE
{
ZFont::ZFont() :
rEngine(ZEngine::GetInstance()),
rFont(NULL)
{
rColor.r = rColor.g = rColor.b = rColor.unused = 255;
rBGColor.r = rBGColor.g = rBGColor.b = rBGColor.unused = 0;
}
ZFont::ZFont(std::string filename, int size) :
rEngine(ZEngine::GetInstance()),
rFont(NULL)
{
rColor.r = rColor.g = rColor.b = rColor.unused = 255;
rBGColor.r = rBGColor.g = rBGColor.b = rBGColor.unused = 0;
Open(filename,size);
}
ZFont::~ZFont()
{
Release();
}
void ZFont::Open(std::string filename, int size)
{
Release();
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
/**
\file ZE_ZFont.cpp
\brief Source file for ZFont.
Implementation of ZFont, the basic Font class for ZEngine.
<br>$Id: ZE_ZFont.cpp,v 1.16 2003/11/24 02:21:20 cozman Exp $<br>
\author James Turk
**/
#include "ZE_ZFont.h"
#ifdef USE_SDL_TTF
namespace ZE
{
ZFont::ZFont() :
rEngine(ZEngine::GetInstance()),
rFont(NULL)
{
rColor.r = rColor.g = rColor.b = rColor.unused = 255;
rBGColor.r = rBGColor.g = rBGColor.b = rBGColor.unused = 0;
}
ZFont::ZFont(std::string filename, int size) :
rEngine(ZEngine::GetInstance()),
rFont(NULL)
{
rColor.r = rColor.g = rColor.b = rColor.unused = 255;
rBGColor.r = rBGColor.g = rBGColor.b = rBGColor.unused = 0;
Open(filename,size);
}
ZFont::~ZFont()
{
Release();
}
void ZFont::Open(std::string filename, int size)
{
Release();
rFilename = filename;
rFont = TTF_OpenFont(filename.c_str(),size);
if(!rFont)
rEngine->ReportError(ZERR_LOAD_FONT,filename);
}
void ZFont::OpenFromZip(std::string zipname, std::string filename, int size)
{
SDL_RWops *rw;
Release();
rZipname = zipname;
rFilename = filename;
rw = RWFromZip(zipname,filename);
if(rw)
rEngine->ReportError(ZERR_LOAD_FONT,filename);
}
void ZFont::OpenFromZip(std::string zipname, std::string filename, int size)
{
SDL_RWops *rw;
Release();
rZipname = zipname;
rFilename = filename;
rw = RWFromZip(zipname,filename);
if(rw)
{
rFont = TTF_OpenFontRW(rw,0,size);
//delete []rw->hidden.mem.base; //must free buffer
//SDL_FreeRW(rw);
}
rFont = TTF_OpenFontRW(rw,0,size);
//delete []rw->hidden.mem.base; //must free buffer
//SDL_FreeRW(rw);
}
if(!rFont)
rEngine->ReportError(ZERR_LOAD_FONT,FormatStr("%s in %s archive",filename.c_str(),zipname.c_str()));
}
void ZFont::Release()
{
FreeFont(rFont);
}
void ZFont::DrawText(std::string text, ZImage &image) const
{
if(rFont)
{
if(text.length() == 0)
text = " ";
image.Attach(TTF_RenderText_Blended(rFont, text.c_str(), rColor));
image.SetAlpha(rColor.unused); //the images alpha comes from the SetColor a parameter
}
}
void ZFont::DrawShadedText(std::string text, ZImage &image) const
{
if(rFont)
{
if(text.length() == 0)
text = " ";
image.Attach(TTF_RenderText_Shaded(rFont, text.c_str(), rColor, rBGColor));
image.SetAlpha(rColor.unused);
}
}
void ZFont::SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
rColor.r = r;
rColor.g = g;
rColor.b = b;
rColor.unused = a; //used in DrawText and DrawBlendedText
}
void ZFont::SetBGColor(Uint8 r, Uint8 g, Uint8 b)
{
rBGColor.r = r;
rBGColor.g = g;
rBGColor.b = b;
}
void ZFont::SetStyle(bool bold, bool italic, bool underline)
{
int flags=0;
if(bold)
flags |= TTF_STYLE_BOLD;
if(italic)
flags |= TTF_STYLE_ITALIC;
if(underline)
flags |= TTF_STYLE_UNDERLINE;
if(!flags)
flags = TTF_STYLE_NORMAL;
if(rFont)
TTF_SetFontStyle(rFont,flags);
else
rEngine->ReportError(ZERR_NOFONT,"SetStyle");
}
void ZFont::Resize(int size)
{
if(rZipname.length())
OpenFromZip(rZipname,rFilename,size);
else
Open(rFilename,size);
}
bool ZFont::IsLoaded() const
{
return rFont != NULL;
}
bool ZFont::IsBold() const
{
if(rFont)
return (TTF_GetFontStyle(rFont) & TTF_STYLE_BOLD) > 0;
else
{
rEngine->ReportError(ZERR_NOFONT, "IsBold");
return false;
}
}
bool ZFont::IsItalic() const
{
if(rFont)
return (TTF_GetFontStyle(rFont) & TTF_STYLE_ITALIC) > 0;
else
{
rEngine->ReportError(ZERR_NOFONT, "IsItalic");
return false;
}
}
bool ZFont::IsUnderlined() const
{
if(rFont)
return (TTF_GetFontStyle(rFont) & TTF_STYLE_UNDERLINE) > 0;
else
{
rEngine->ReportError(ZERR_NOFONT, "IsUnderlined");
return false;
}
}
int ZFont::Height() const
{
if(rFont)
return TTF_FontHeight(rFont);
else
{
rEngine->ReportError(ZERR_NOFONT, "GetHeight");
return 0;
}
}
int ZFont::LineSkip() const
{
if(rFont)
return TTF_FontLineSkip(rFont);
else
{
rEngine->ReportError(ZERR_NOFONT, "GetLineSkip");
return 0;
}
}
int ZFont::StringWidth(std::string text) const
{
int w,h;
if(rFont)
{
TTF_SizeText(rFont,text.c_str(),&w,&h);
return w;
}
else
{
rEngine->ReportError(ZERR_NOFONT, "GetStringWidth");
return 0;
}
}
int ZFont::StringHeight(std::string text) const
{
int w,h;
if(rFont)
{
TTF_SizeText(rFont,text.c_str(),&w,&h);
return h;
}
else
{
rEngine->ReportError(ZERR_NOFONT, "GetStringHeight");
return 0;
}
}
}
#endif //USE_SDL_TTF
rEngine->ReportError(ZERR_LOAD_FONT,"%s in %s archive",filename.c_str(),zipname.c_str());
}
void ZFont::Release()
{
FreeFont(rFont);
}
void ZFont::DrawText(std::string text, ZImage &image) const
{
if(rFont)
{
if(text.length() == 0)
text = " ";
image.Attach(TTF_RenderText_Blended(rFont, text.c_str(), rColor));
image.SetAlpha(rColor.unused); //the images alpha comes from the SetColor a parameter
}
}
void ZFont::DrawShadedText(std::string text, ZImage &image) const
{
if(rFont)
{
if(text.length() == 0)
text = " ";
image.Attach(TTF_RenderText_Shaded(rFont, text.c_str(), rColor, rBGColor));
image.SetAlpha(rColor.unused);
}
}
void ZFont::SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
rColor.r = r;
rColor.g = g;
rColor.b = b;
rColor.unused = a; //used in DrawText and DrawBlendedText
}
void ZFont::SetBGColor(Uint8 r, Uint8 g, Uint8 b)
{
rBGColor.r = r;
rBGColor.g = g;
rBGColor.b = b;
}
void ZFont::SetStyle(bool bold, bool italic, bool underline)
{
int flags=0;
if(bold)
flags |= TTF_STYLE_BOLD;
if(italic)
flags |= TTF_STYLE_ITALIC;
if(underline)
flags |= TTF_STYLE_UNDERLINE;
if(!flags)
flags = TTF_STYLE_NORMAL;
if(rFont)
TTF_SetFontStyle(rFont,flags);
else
rEngine->ReportError(ZERR_NOFONT,"SetStyle");
}
void ZFont::Resize(int size)
{
if(rZipname.length())
OpenFromZip(rZipname,rFilename,size);
else
Open(rFilename,size);
}
bool ZFont::IsLoaded() const
{
return rFont != NULL;
}
bool ZFont::IsBold() const
{
if(rFont)
return (TTF_GetFontStyle(rFont) & TTF_STYLE_BOLD) > 0;
else
{
rEngine->ReportError(ZERR_NOFONT, "IsBold");
return false;
}
}
bool ZFont::IsItalic() const
{
if(rFont)
return (TTF_GetFontStyle(rFont) & TTF_STYLE_ITALIC) > 0;
else
{
rEngine->ReportError(ZERR_NOFONT, "IsItalic");
return false;
}
}
bool ZFont::IsUnderlined() const
{
if(rFont)
return (TTF_GetFontStyle(rFont) & TTF_STYLE_UNDERLINE) > 0;
else
{
rEngine->ReportError(ZERR_NOFONT, "IsUnderlined");
return false;
}
}
int ZFont::Height() const
{
if(rFont)
return TTF_FontHeight(rFont);
else
{
rEngine->ReportError(ZERR_NOFONT, "GetHeight");
return 0;
}
}
int ZFont::LineSkip() const
{
if(rFont)
return TTF_FontLineSkip(rFont);
else
{
rEngine->ReportError(ZERR_NOFONT, "GetLineSkip");
return 0;
}
}
int ZFont::StringWidth(std::string text) const
{
int w,h;
if(rFont)
{
TTF_SizeText(rFont,text.c_str(),&w,&h);
return w;
}
else
{
rEngine->ReportError(ZERR_NOFONT, "GetStringWidth");
return 0;
}
}
int ZFont::StringHeight(std::string text) const
{
int w,h;
if(rFont)
{
TTF_SizeText(rFont,text.c_str(),&w,&h);
return h;
}
else
{
rEngine->ReportError(ZERR_NOFONT, "GetStringHeight");
return 0;
}
}
}
#endif //USE_SDL_TTF

File diff suppressed because it is too large Load Diff

View File

@ -1,165 +1,165 @@
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
/**
\file ZE_ZMusic.cpp
\brief Source file for ZMusic.
Implementation of ZMusic, the basic Music class for ZEngine.
<br>$Id: ZE_ZMusic.cpp,v 1.11 2003/09/24 02:03:18 cozman Exp $<br>
\author James Turk
**/
#include "ZE_ZMusic.h"
#ifdef USE_SDL_MIXER
namespace ZE
{
//ZMusic is a very simple class, each call basically wraps a self-explanatory function of SDL_Mixer
const int ZMusic::LoopInfinite = -1; //constant for infinite, as used by SDL_Mixer
ZMusic::ZMusic() :
rEngine(ZEngine::GetInstance()),
rMusic(NULL)
{
}
ZMusic::ZMusic(std::string filename) :
rEngine(ZEngine::GetInstance()),
rMusic(NULL)
{
Open(filename);
}
ZMusic::~ZMusic()
{
Release();
}
void ZMusic::Open(std::string filename)
{
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
/**
\file ZE_ZMusic.cpp
\brief Source file for ZMusic.
Implementation of ZMusic, the basic Music class for ZEngine.
<br>$Id: ZE_ZMusic.cpp,v 1.12 2003/11/24 02:21:20 cozman Exp $<br>
\author James Turk
**/
#include "ZE_ZMusic.h"
#ifdef USE_SDL_MIXER
namespace ZE
{
//ZMusic is a very simple class, each call basically wraps a self-explanatory function of SDL_Mixer
const int ZMusic::LoopInfinite = -1; //constant for infinite, as used by SDL_Mixer
ZMusic::ZMusic() :
rEngine(ZEngine::GetInstance()),
rMusic(NULL)
{
}
ZMusic::ZMusic(std::string filename) :
rEngine(ZEngine::GetInstance()),
rMusic(NULL)
{
Open(filename);
}
ZMusic::~ZMusic()
{
Release();
}
void ZMusic::Open(std::string filename)
{
Release();
rMusic = Mix_LoadMUS(filename.c_str());
if(!rMusic)
rEngine->ReportError(ZERR_LOAD_MUSIC,filename);
}
void ZMusic::Release()
{
Mix_HaltMusic();
FreeMusic(rMusic);
}
void ZMusic::Play(int loopNum, int fadeTime) const
{
if(Mix_PlayingMusic()) //stop currently playing music
Mix_HaltMusic();
if(rMusic)
{
if(fadeTime)
Mix_FadeInMusic(rMusic, loopNum, fadeTime);
else
Mix_PlayMusic(rMusic, loopNum);
}
else
rEngine->ReportError(ZERR_NOMUSIC, "Play");
}
void ZMusic::Pause() const
{
if(rMusic)
Mix_PauseMusic();
else
rEngine->ReportError(ZERR_NOMUSIC, "Pause");
}
void ZMusic::Unpause() const
{
if(rMusic)
Mix_ResumeMusic();
else
rEngine->ReportError(ZERR_NOMUSIC, "Unpause");
}
void ZMusic::Rewind() const
{
if(rMusic)
Mix_RewindMusic();
else
rEngine->ReportError(ZERR_NOMUSIC, "Rewind");
}
void ZMusic::Stop(int fadeTime) const
{
if(rMusic)
{
if(fadeTime)
Mix_FadeOutMusic(fadeTime);
else
Mix_HaltMusic();
}
else
rEngine->ReportError(ZERR_NOMUSIC, "Stop");
}
void ZMusic::SetVolume(int volume)
{
if(rMusic)
Mix_VolumeMusic(volume);
else
rEngine->ReportError(ZERR_NOMUSIC, "SetVolume");
}
bool ZMusic::IsLoaded() const
{
return rMusic != NULL;
}
bool ZMusic::IsPlaying() const
{
if(rMusic)
return Mix_PlayingMusic() > 0;
else
{
rEngine->ReportError(ZERR_NOMUSIC, "IsPlaying");
return false;
}
}
bool ZMusic::IsPaused() const
{
if(rMusic)
return Mix_PausedMusic() > 0;
else
{
rEngine->ReportError(ZERR_NOMUSIC, "IsPaused");
return false;
}
}
int ZMusic::Volume() const
{
if(rMusic)
return Mix_VolumeMusic(-1);
else
{
rEngine->ReportError(ZERR_NOMUSIC, "GetVolume");
return false;
}
}
}
#endif
rEngine->ReportError(ZERR_LOAD_MUSIC,filename);
}
void ZMusic::Release()
{
Mix_HaltMusic();
FreeMusic(rMusic);
}
void ZMusic::Play(int loopNum, int fadeTime) const
{
if(Mix_PlayingMusic()) //stop currently playing music
Mix_HaltMusic();
if(rMusic)
{
if(fadeTime)
Mix_FadeInMusic(rMusic, loopNum, fadeTime);
else
Mix_PlayMusic(rMusic, loopNum);
}
else
rEngine->ReportError(ZERR_NOMUSIC, "Play");
}
void ZMusic::Pause() const
{
if(rMusic)
Mix_PauseMusic();
else
rEngine->ReportError(ZERR_NOMUSIC, "Pause");
}
void ZMusic::Unpause() const
{
if(rMusic)
Mix_ResumeMusic();
else
rEngine->ReportError(ZERR_NOMUSIC, "Unpause");
}
void ZMusic::Rewind() const
{
if(rMusic)
Mix_RewindMusic();
else
rEngine->ReportError(ZERR_NOMUSIC, "Rewind");
}
void ZMusic::Stop(int fadeTime) const
{
if(rMusic)
{
if(fadeTime)
Mix_FadeOutMusic(fadeTime);
else
Mix_HaltMusic();
}
else
rEngine->ReportError(ZERR_NOMUSIC, "Stop");
}
void ZMusic::SetVolume(int volume)
{
if(rMusic)
Mix_VolumeMusic(volume);
else
rEngine->ReportError(ZERR_NOMUSIC, "SetVolume");
}
bool ZMusic::IsLoaded() const
{
return rMusic != NULL;
}
bool ZMusic::IsPlaying() const
{
if(rMusic)
return Mix_PlayingMusic() > 0;
else
{
rEngine->ReportError(ZERR_NOMUSIC, "IsPlaying");
return false;
}
}
bool ZMusic::IsPaused() const
{
if(rMusic)
return Mix_PausedMusic() > 0;
else
{
rEngine->ReportError(ZERR_NOMUSIC, "IsPaused");
return false;
}
}
int ZMusic::Volume() const
{
if(rMusic)
return Mix_VolumeMusic(-1);
else
{
rEngine->ReportError(ZERR_NOMUSIC, "GetVolume");
return false;
}
}
}
#endif

View File

@ -13,7 +13,7 @@
\brief Source file for ZSound.
Implementation of ZSound, the basic Sound class for ZEngine.
<br>$Id: ZE_ZSound.cpp,v 1.13 2003/11/20 02:23:14 cozman Exp $<br>
<br>$Id: ZE_ZSound.cpp,v 1.14 2003/11/24 02:21:20 cozman Exp $<br>
\author James Turk
**/
@ -69,7 +69,7 @@ void ZSound::OpenFromZip(std::string zipname, std::string filename)
}
if(!rSound)
rEngine->ReportError(ZERR_LOAD_SOUND,FormatStr("%s in %s archive",filename.c_str(),zipname.c_str()));
rEngine->ReportError(ZERR_LOAD_SOUND,"%s in %s archive",filename.c_str(),zipname.c_str());
}
void ZSound::Release()

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
/*$Id: ZTimerTest.cpp,v 1.18 2003/10/21 01:17:35 cozman Exp $*/
/*$Id: ZTimerTest.cpp,v 1.19 2003/11/24 02:17:32 cozman Exp $*/
#include <ZEngine.h>
#include <string>
@ -115,10 +115,10 @@ void Test()
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
}
int main(int argc, char *argv[])
{
if(Initialize())
Test();
ZEngine::ReleaseInstance();
return 0;
int main(int argc, char *argv[])
{
if(Initialize())
Test();
ZEngine::ReleaseInstance();
return 0;
}