line endings!
This commit is contained in:
parent
6709e83d94
commit
fa7c896540
@ -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__
|
|
@ -13,7 +13,7 @@
|
|||||||
\brief Central source file for ZEngine.
|
\brief Central source file for ZEngine.
|
||||||
|
|
||||||
Actual implementation of ZEngine singleton class, the core of 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
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -33,12 +33,26 @@ ZEngine::ZEngine() :
|
|||||||
mSecPerFrame(0.0),
|
mSecPerFrame(0.0),
|
||||||
mNeedReload(false), mActive(false), mQuit(false), mKeyIsPressed(NULL),
|
mNeedReload(false), mActive(false), mQuit(false), mKeyIsPressed(NULL),
|
||||||
mMouseX(0), mMouseY(0), mMouseB(0),
|
mMouseX(0), mMouseY(0), mMouseB(0),
|
||||||
mLogAllErrors(true), mErrlog(stderr), mEventFilter(NULL)
|
mErrlog(stderr), mEventFilter(NULL)
|
||||||
{
|
{
|
||||||
for(int k = 0; k < SDLK_LAST; ++k)
|
for(int k = 0; k < SDLK_LAST; ++k)
|
||||||
mKeyPress[k] = false;
|
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()
|
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)
|
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;
|
bpp = -1;
|
||||||
}
|
}
|
||||||
else //this decides correcr BPP
|
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);
|
okBPP = SDL_VideoModeOK(width, height, bpp, vidFlags);
|
||||||
if(!okBPP)
|
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
|
return false; //return now
|
||||||
}
|
}
|
||||||
else if(okBPP != bpp)
|
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;
|
bpp = okBPP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +192,7 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std
|
|||||||
|
|
||||||
if(!mScreen)
|
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
|
#ifdef USE_SDL_MIXER
|
||||||
Mix_CloseAudio();
|
Mix_CloseAudio();
|
||||||
@ -228,7 +242,7 @@ void ZEngine::CloseDisplay()
|
|||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
if(mErrlog != stderr && mErrlog != stdin)
|
if(mErrlog && mErrlog != stderr && mErrlog != stdin)
|
||||||
fclose(mErrlog);
|
fclose(mErrlog);
|
||||||
|
|
||||||
mInitialized = false;
|
mInitialized = false;
|
||||||
@ -534,12 +548,11 @@ void ZEngine::SetEventFilter(SDL_EventFilter filter)
|
|||||||
mEventFilter = filter;
|
mEventFilter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZEngine::SetErrorLog(bool logAll, std::string logFile)
|
void ZEngine::SetErrorLog(std::string logFile)
|
||||||
{
|
{
|
||||||
mLogAllErrors = logAll;
|
|
||||||
if(logFile.length())
|
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")
|
if(logFile == "stderr")
|
||||||
mErrlog = stderr;
|
mErrlog = stderr;
|
||||||
else if(logFile == "stdout")
|
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);
|
mErrlog = NULL;
|
||||||
|
|
||||||
if(mLogAllErrors)
|
|
||||||
LogError(mCurError);
|
|
||||||
else
|
|
||||||
mErrorQueue.push(mCurError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZErrorCode ZEngine::GetLastError()
|
void ZEngine::ReportError(ZErrorCode type, std::string desc, ...)
|
||||||
{
|
{
|
||||||
ZErrorCode code = mCurError.Code();
|
char buf[512];
|
||||||
mCurError.Create(ZERR_NONE);
|
va_list args;
|
||||||
return code;
|
std::string msg;
|
||||||
}
|
|
||||||
|
|
||||||
void ZEngine::WriteLog(std::string str)
|
va_start(args,desc);
|
||||||
{
|
vsprintf(buf,desc.c_str(),args);
|
||||||
std::fprintf(mErrlog,str.c_str());
|
va_end(args);
|
||||||
std::fprintf(mErrlog,"\n");
|
|
||||||
std::fflush(mErrlog);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZEngine::LogError(ZError error)
|
msg = desc.length() ? FormatStr(mErrorDesc[type],buf) : mErrorDesc[type];
|
||||||
{
|
|
||||||
std::fprintf(mErrlog,error.LogString().c_str());
|
|
||||||
std::fflush(mErrlog);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZEngine::FlushErrors()
|
if(mErrlog)
|
||||||
{
|
|
||||||
while(!mErrorQueue.empty())
|
|
||||||
{
|
{
|
||||||
LogError(mErrorQueue.front());
|
std::fprintf(mErrlog,msg.c_str());
|
||||||
mErrorQueue.pop();
|
std::fflush(mErrlog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZFont.
|
\brief Source file for ZFont.
|
||||||
|
|
||||||
Implementation of ZFont, the basic Font class for ZEngine.
|
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>
|
<br>$Id: ZE_ZFont.cpp,v 1.16 2003/11/24 02:21:20 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ void ZFont::OpenFromZip(std::string zipname, std::string filename, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!rFont)
|
if(!rFont)
|
||||||
rEngine->ReportError(ZERR_LOAD_FONT,FormatStr("%s in %s archive",filename.c_str(),zipname.c_str()));
|
rEngine->ReportError(ZERR_LOAD_FONT,"%s in %s archive",filename.c_str(),zipname.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZFont::Release()
|
void ZFont::Release()
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZImage.
|
\brief Source file for ZImage.
|
||||||
|
|
||||||
Implementation of ZImage, the Image class for ZEngine.
|
Implementation of ZImage, the Image class for ZEngine.
|
||||||
<br>$Id: ZE_ZImage.cpp,v 1.51 2003/11/14 02:11:50 cozman Exp $<br>
|
<br>$Id: ZE_ZImage.cpp,v 1.52 2003/11/24 02:21:20 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -193,20 +193,16 @@ void ZImage::OpenFromZip(std::string zipname, std::string filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!image)
|
if(!image)
|
||||||
rEngine->ReportError(ZERR_LOAD_IMAGE,FormatStr("%s in %s archive",filename.c_str(),zipname.c_str()));
|
rEngine->ReportError(ZERR_LOAD_IMAGE,"%s in %s archive",filename.c_str(),zipname.c_str());
|
||||||
else
|
else
|
||||||
Attach(image);
|
Attach(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
SDL_Surface *screen = rEngine->Display();
|
|
||||||
SDL_Surface *cutImg = NULL;
|
SDL_Surface *cutImg = NULL;
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
SDL_VideoInfo *videoInfo;
|
Uint8 oldAlpha;
|
||||||
|
|
||||||
//either set hardware or software surface//
|
|
||||||
videoInfo = const_cast<SDL_VideoInfo*>(SDL_GetVideoInfo());
|
|
||||||
|
|
||||||
rect.x = x;
|
rect.x = x;
|
||||||
rect.y = y;
|
rect.y = y;
|
||||||
@ -216,13 +212,16 @@ void ZImage::OpenFromImage(SDL_Surface *image, Sint16 x, Sint16 y, Sint16 w, Sin
|
|||||||
if(!image)
|
if(!image)
|
||||||
rEngine->ReportError(ZERR_NOIMAGE,"OpenFromImage");
|
rEngine->ReportError(ZERR_NOIMAGE,"OpenFromImage");
|
||||||
|
|
||||||
cutImg = SDL_CreateRGBSurface(0, rect.w, rect.h, rEngine->DisplayDepth(),
|
cutImg = SDL_CreateRGBSurface(0, rect.w, rect.h, image->format->BitsPerPixel,
|
||||||
screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
|
image->format->Rmask, image->format->Gmask, image->format->Bmask, image->format->Amask);
|
||||||
|
|
||||||
if(!cutImg)
|
if(!cutImg)
|
||||||
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_CreateRGBSurface failed in ZImage::OpenFromImage: %s.",SDL_GetError()));
|
rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_CreateRGBSurface failed in ZImage::OpenFromImage: %s.",SDL_GetError());
|
||||||
|
|
||||||
|
oldAlpha = image->format->alpha; //store alpha
|
||||||
|
SDL_SetAlpha(image,0,SDL_ALPHA_OPAQUE); //turn off alpha for RGBA->RGBA copy
|
||||||
SDL_BlitSurface(image,&rect,cutImg,NULL);
|
SDL_BlitSurface(image,&rect,cutImg,NULL);
|
||||||
|
SDL_SetAlpha(image,oldAlpha == SDL_ALPHA_OPAQUE ? 0 : SDL_SRCALPHA, oldAlpha); //turn alpha back on iff alpha was not opaque to start
|
||||||
Attach(cutImg);
|
Attach(cutImg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +249,7 @@ void ZImage::Attach(SDL_Surface *surface)
|
|||||||
}
|
}
|
||||||
else //can't convert, leave surface as is
|
else //can't convert, leave surface as is
|
||||||
{
|
{
|
||||||
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError()));
|
rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
rWidth = static_cast<float>(surface->w);
|
rWidth = static_cast<float>(surface->w);
|
||||||
@ -298,7 +297,7 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
|
|||||||
{
|
{
|
||||||
color = SDL_MapRGB(rImage->format,red,green,blue);
|
color = SDL_MapRGB(rImage->format,red,green,blue);
|
||||||
if(SDL_SetColorKey(rImage, SDL_SRCCOLORKEY, color) < 0)
|
if(SDL_SetColorKey(rImage, SDL_SRCCOLORKEY, color) < 0)
|
||||||
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError()));
|
rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError());
|
||||||
else
|
else
|
||||||
Reload(); //do the reattach hack, this gets a new OpenGL surface for the same image
|
Reload(); //do the reattach hack, this gets a new OpenGL surface for the same image
|
||||||
}
|
}
|
||||||
@ -318,7 +317,7 @@ void ZImage::DrawClipped(int x, int y, ZRect clipRect) const
|
|||||||
|
|
||||||
void ZImage::Draw(float x, float y) const
|
void ZImage::Draw(float x, float y) const
|
||||||
{
|
{
|
||||||
glColor4ub(255,255,255,rAlpha); //sets the color correctly
|
//glColor4ub(255,255,255,rAlpha); //sets the color correctly
|
||||||
Bind();
|
Bind();
|
||||||
glBegin(GL_TRIANGLE_STRIP); //triangle strips, speedier?
|
glBegin(GL_TRIANGLE_STRIP); //triangle strips, speedier?
|
||||||
glTexCoord2f(rTexMinX,rTexMinY); glVertex2f(x,y);
|
glTexCoord2f(rTexMinX,rTexMinY); glVertex2f(x,y);
|
||||||
@ -524,7 +523,7 @@ void ZImage::Attach(SDL_Surface *surface)
|
|||||||
}
|
}
|
||||||
else //can't convert, leave surface as is
|
else //can't convert, leave surface as is
|
||||||
{
|
{
|
||||||
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError()));
|
rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
rImage = surface;
|
rImage = surface;
|
||||||
@ -548,8 +547,8 @@ void ZImage::SetAlpha(Uint8 alpha)
|
|||||||
rAlpha = alpha;
|
rAlpha = alpha;
|
||||||
if(rImage)
|
if(rImage)
|
||||||
{
|
{
|
||||||
if(SDL_SetAlpha(rImage, SDL_SRCALPHA, alpha) < 0)
|
if(SDL_SetAlpha(rImage, rAlpha == SDL_ALPHA_OPAQUE ? 0 : SDL_SRCALPHA, alpha) < 0)
|
||||||
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetAlpha failed in ZImage::SetAlpha: %s",SDL_GetError()));
|
rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_SetAlpha failed in ZImage::SetAlpha: %s",SDL_GetError()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rEngine->ReportError(ZERR_NOIMAGE,"SetAlpha");
|
rEngine->ReportError(ZERR_NOIMAGE,"SetAlpha");
|
||||||
@ -563,7 +562,7 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
|
|||||||
{
|
{
|
||||||
color = SDL_MapRGBA(rImage->format,red,green,blue,255);
|
color = SDL_MapRGBA(rImage->format,red,green,blue,255);
|
||||||
if(SDL_SetColorKey(rImage, SDL_RLEACCEL|SDL_SRCCOLORKEY, color) < 0)
|
if(SDL_SetColorKey(rImage, SDL_RLEACCEL|SDL_SRCCOLORKEY, color) < 0)
|
||||||
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError()));
|
rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError()));
|
||||||
//surface conversion//
|
//surface conversion//
|
||||||
SDL_Surface *temp = rImage;
|
SDL_Surface *temp = rImage;
|
||||||
rImage = SDL_DisplayFormatAlpha(temp); //TTF_RenderTextBlended relys on this
|
rImage = SDL_DisplayFormatAlpha(temp); //TTF_RenderTextBlended relys on this
|
||||||
@ -573,7 +572,7 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
|
|||||||
}
|
}
|
||||||
else //can't convert
|
else //can't convert
|
||||||
{
|
{
|
||||||
rEngine->ReportError(ZERR_SDL_INTERNAL,FormatStr("SDL_DisplayFormatAlpha failed in ZImage::SetColorKey: %s",SDL_GetError()));
|
rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_DisplayFormatAlpha failed in ZImage::SetColorKey: %s",SDL_GetError()));
|
||||||
rImage = temp;
|
rImage = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZMusic.
|
\brief Source file for ZMusic.
|
||||||
|
|
||||||
Implementation of ZMusic, the basic Music class for ZEngine.
|
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>
|
<br>$Id: ZE_ZMusic.cpp,v 1.12 2003/11/24 02:21:20 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZSound.
|
\brief Source file for ZSound.
|
||||||
|
|
||||||
Implementation of ZSound, the basic Sound class for ZEngine.
|
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
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ void ZSound::OpenFromZip(std::string zipname, std::string filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!rSound)
|
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()
|
void ZSound::Release()
|
||||||
|
@ -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
|
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 <ZEngine.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
Loading…
Reference in New Issue
Block a user