From 2a4c8ed515bad24a3eb171a8cc054fb1a7da2e61 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 24 Dec 2003 04:43:36 +0000 Subject: [PATCH] new Error system, ZRF added --- include/ZE_Includes.h | 3 +- include/ZE_ZAnimation.h | 136 ++++++++++++++++++++++++---- include/ZE_ZEngine.h | 167 +++++++++++++++------------------- include/ZE_ZFont.h | 9 +- include/ZE_ZImage.h | 29 +++--- include/ZE_ZMusic.h | 9 +- include/ZE_ZSound.h | 9 +- src/ZE_ZEngine.cpp | 192 +++++++++++++++++++++++++++++++--------- src/ZE_ZFont.cpp | 34 ++++--- src/ZE_ZImage.cpp | 47 ++++++---- src/ZE_ZMusic.cpp | 31 ++++--- src/ZE_ZSound.cpp | 31 ++++--- 12 files changed, 477 insertions(+), 220 deletions(-) diff --git a/include/ZE_Includes.h b/include/ZE_Includes.h index 5b3b74a..bc3cae5 100644 --- a/include/ZE_Includes.h +++ b/include/ZE_Includes.h @@ -14,7 +14,7 @@ ZE_*.h files should only include this file and any other ZE_*.h files that they need, External Library or C/C++ Standard Library files should be included from within this file. - $Id: ZE_Includes.h,v 1.20 2003/10/13 21:40:05 cozman Exp $
+ $Id: ZE_Includes.h,v 1.21 2003/12/24 04:46:48 cozman Exp $
\author James Turk **/ @@ -38,6 +38,7 @@ #endif #include "zlib/unzip.h" +#include "tinyxml/tinyxml.h" #include //used frequently #include //used by ZEngine for ZErrors diff --git a/include/ZE_ZAnimation.h b/include/ZE_ZAnimation.h index 807369b..7863f64 100644 --- a/include/ZE_ZAnimation.h +++ b/include/ZE_ZAnimation.h @@ -13,7 +13,7 @@ \brief Definition file for ZAnimation. Definition file for ZAnimation, a class for animations using ZImage. -
$Id: ZE_ZAnimation.h,v 1.1 2003/11/25 01:31:36 cozman Exp $
+
$Id: ZE_ZAnimation.h,v 1.2 2003/12/24 04:46:48 cozman Exp $
\author James Turk **/ @@ -26,48 +26,150 @@ namespace ZE { -enum ZAnimationType +enum ZAnimType { + ZANIM_NONE, ZANIM_ONCE, ZANIM_LOOP, - ZANIM_REV_ONCE, - ZANIM_REV_LOOP + ZANIM_REVERSE }; + class ZAnimation { protected: + //! Pointer to ZEngine object. ZEngine *rEngine; + //! Pointer to dynamic array of images. ZImage *rAnimImages; - float rAnimWidth; - float rAnimHeight; + //! Current frame. int rCurFrame; + //! Number of frames in animation. int rNumFrames; + //! Frame increment, will always be -1,0, or 1. int rFrameStep; + //! Delay between frames in ms. Uint32 rFrameDelay; + //! Time of next step. Uint32 rNextFrameTime; - bool rLoop; + //! Behavior of animation. + ZAnimType rAnimType; + //! Boolean, true if image is to be run backwards, false otherwise. bool rBackwards; + public: + /*! + \brief Default constructor for ZAnimation. + + Sets all members to default values. + **/ ZAnimation(); - ZAnimation(ZImage *images, int numFrames, Uint32 frameDelay, bool loop=false, bool backwards=false, float width=0, float height=0); - void Create(ZImage *images, int numFrames, Uint32 frameDelay, bool loop=false, bool backwards=false, float width=0, float height=0); + /*! + \brief Complete constructor for ZAnimation. + + Assigns values of members to given arguments via call to Create. + \param images Array of images for animation. (Note: array is not copied) + \param numFrames Number of images in array pointed to by 'images' + \param frameDelay Delay (in milliseconds) between frames. + \param type One of the ZAnimType enums that control what animation does after last frame is reached. + \param backwards Boolean, true if image is to be run backwards, false otherwise (defaults to false). + **/ + ZAnimation(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimType type, bool backwards=false); + + /*! + \brief All-at-once function for setting up ZAnimation. + + Calls SetAnimImages,SetFrameDelay,SetAnimType and SetAnimSize with passed parameters. + \param images Array of images for animation. (Note: array is not copied) + \param numFrames Number of images in array pointed to by 'images' + \param frameDelay Delay (in milliseconds) between frames. + \param type One of the ZAnimType enums that control what animation does after last frame is reached. + \param backwards Boolean, true if image is to be run backwards, false otherwise (defaults to false). + **/ + void Create(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimType type, bool backwards=false); + + /*! + \brief Sets images for animation. + + Sets images for animation to use, should be array of images + \param images Array of images for animation. (Note: array is not copied) + \param numFrames Number of images in array pointed to by 'images' + **/ void SetAnimImages(ZImage *images, int numFrames); - void SetFrameDelay(Uint32 frameDelay); - void SetAnimType(bool loop, bool backwards); - void SetAnimSize(float width, float height); + /*! + \brief Sets frame delay between images. + + Set delay between images in milliseconds. + \param frameDelay Delay (in milliseconds) between frames. + **/ + void SetFrameDelay(Uint32 frameDelay); + + /*! + \brief Sets behavior of animation after last frame is reached and direction of animation. + + Sets behavior of animation after last frame as well as the initial direction of the animation. + \param type One of the ZAnimType enums that control what animation does after last frame is reached. + \param backwards Boolean, true if image is to be run backwards, false otherwise (defaults to false). + **/ + void SetAnimType(ZAnimType type, bool backwards=false); + + /*! + \brief Resets animation. + + Sets frame to first frame and pauses animation. + **/ + void Reset(); + + /*! + \brief Starts animation. + + Starts animation, this must once be called to begin animation. + **/ void Start(); - void Stop(); + + /*! + \brief Pauses animation. + + Halts animation at current frame. + **/ void Pause(); - void Unpause(); + + /*! + \brief Sets displayed frame manually. + + Sets displayed frame, uses bounds checking, also accepts negative indices. + \param frame Frame to display. In an animation with N frames, valid frames are 0 to N-1, and also -1 to -N + where negative indices work so that -1 is the last frame, -2 is the second to last, and so on. + **/ void SetFrame(int frame); - void Update(); - void Draw(float x, float y); + /*! + \brief Updates animation. - bool Stopped(); + Updates the animation, changing the frame if needed. This function should be called every frame + so that the frame may be changed. + **/ + void Update(); + + /*! + \brief Draws current frame to screen. + + Draws current frame to screen at given position, should be called every frame that animation is to be drawn. + If stopped, draws first frame, if paused draws frame paused on. + \param x X position for animation to be drawn at. + \param y Y position for animation to be drawn at. + **/ + void Draw(float x, float y) const; + + /*! + \brief Gets running status of animation. + + Returns status of animation, running or halted. + \return True if animation is running, false if it is paused or stopped. + **/ + bool Running() const; }; } diff --git a/include/ZE_ZEngine.h b/include/ZE_ZEngine.h index 77f8f6a..7adb3aa 100644 --- a/include/ZE_ZEngine.h +++ b/include/ZE_ZEngine.h @@ -13,7 +13,7 @@ \brief Definition file for core ZEngine class. ZEngine Game Engine core Engine definition. -
$Id: ZE_ZEngine.h,v 1.56 2003/12/14 22:36:09 cozman Exp $
+
$Id: ZE_ZEngine.h,v 1.57 2003/12/24 04:46:48 cozman Exp $
\author James Turk **/ @@ -36,31 +36,24 @@ namespace ZE class ZRect; -/*! - \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 +enum ZErrorSeverity { - 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. */ + ZERR_NOTE, + ZERR_VERBOSE, + ZERR_DEPRECIATED, + ZERR_WARNING, + ZERR_ERROR, + ZERR_CRITICAL }; +enum ZErrorLogStyle +{ + ZLOG_NONE, + ZLOG_TEXT, + ZLOG_HTML +}; + + /*! \brief Main ZEngine Singleton Class @@ -88,7 +81,6 @@ class ZEngine bool mUnpauseOnActive; #ifdef DEPRECIATED - //! Value framerate strives to be at, set by SetDesiredFramerate. Uint8 mDesiredFramerate; #endif //DEPRECIATED @@ -118,14 +110,16 @@ class ZEngine int mMouseY; //! Mouse Button Information Uint8 mMouseB; + //! Error log style. + ZErrorLogStyle mLogStyle; //! C-style FILE* for error logging. std::FILE *mErrlog; - //! Static Array of Error Identifiers - std::string mErrorDesc[ZERR_LAST]; //! Event filter, for users who need to process their own events. SDL_EventFilter mEventFilter; //! Random Generator for general use. ZRandGen mRandGen; + //! TinyXML XML Document for ZRF (ZEngine Resource File). + TiXmlDocument rZRF; #ifdef USE_SDL_MIXER //! Sound Initialized @@ -140,7 +134,6 @@ class ZEngine //Singleton + Memory Management// ///////////////////////////////// - private: /*! \brief Constructor for ZEngine. @@ -148,6 +141,12 @@ class ZEngine **/ ZEngine(); + ////////////////////// + //Resource Internals// + ////////////////////// + + TiXmlElement* FindElement(std::string type, std::string id); + public: /*! @@ -184,7 +183,7 @@ class ZEngine \param icon Path to Icon File. \return result of setting up the display, true if everything went ok, false if any setup failed (check GetLastError). **/ - bool CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title, + bool CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title="ZEngine Application", int soundRate=22050, bool stereo=false, std::string icon=""); /*! @@ -309,24 +308,7 @@ class ZEngine double GetFramerate(); #ifdef DEPRECIATED - /*! - \brief Set Desired Framerate. - - Sets desired framerate, if engine gets ahead of desired rate during a frame it will stall in Update until - current framerate is closer to that desired. Acceptable values are 1-255, setting this value to 0 will disable this - feature. (Desired framerate is disabled upon initialization of ZEngine.) - \since 0.8.2 - \param rate Desired framerate 1-255, or 0 to disable. - **/ void SetDesiredFramerate(Uint8 rate); - - /*! - \brief Get Desired Framerate. - - Get desired framerate set by SetDesiredFramerate. - \since 0.8.2 - \return Current setting for desired framerate. - **/ Uint8 GetDesiredFramerate(); #endif //DEPRECIATED @@ -476,7 +458,7 @@ class ZEngine \param rect Rectangle to check if mouse is in. \return true if mouse is in rectangle, false otherwise **/ - bool MouseInRect(SDL_Rect *rect); + bool MouseInRect(const SDL_Rect &rect); /*! \brief Check if mouse is in given rectangle. @@ -522,7 +504,7 @@ class ZEngine \param logFile Name of file to use as log, passing in stderr or stdio will set the log to the respective C stream. Passing in nothing will not change the current error log file, which defaults to stderr. **/ - void SetErrorLog(std::string logFile); + void SetErrorLog(ZErrorLogStyle logStyle, std::string logFile); void DisableErrorLog(); @@ -533,16 +515,7 @@ class ZEngine Adds the error to the the error queue, and sets the current error to this error. \since 0.8.2 **/ - void ReportError(ZErrorCode type, std::string desc="", ...); - - /*! - \brief Get the last error. - - Get the last error reported. - \since 0.8.2 - \return ZErrorCode of last error reported. - **/ - ZErrorCode GetLastError(); + void ReportError(ZErrorSeverity type, std::string desc="", ...); /*! \brief Write to the log. @@ -551,15 +524,7 @@ class ZEngine \since 0.8.2 \param str String to write to log file. **/ - void WriteLog(std::string str); - - /*! - \brief Flush Stack of Errors to file. - - Write the error stack to the error log. - \since 0.8.2 - **/ - void FlushErrors(); + void WriteLog(std::string str, ...); //////////////////////////// //Random Number Generation// @@ -638,57 +603,71 @@ class ZEngine **/ double RandDouble(); + ////////////////// + //Resource Files// + ////////////////// + + /*! + \brief Set resource file. + + Set active XML ZEngine Resource File (ZRF). + \param filename Filename of XML format resource file. + **/ + void SetResourceFile(std::string filename); + + /*! + \brief Get string data from resource file. + + Get string data from active ZRF resource file set in SetResourceFile. + **/ + std::string GetStringResource(std::string type, std::string id, std::string element); + + /*! + \brief Get numeric data from resource file. + + Get numeric data from active ZRF resource file set in SetResourceFile, in integer format. + **/ + int GetIntResource(std::string type, std::string id, std::string element); + + /*! + \brief Get numeric data from resource file. + + Get numeric data from active ZRF resource file set in SetResourceFile, in double format. + **/ + double GetDoubleResource(std::string type, std::string id, std::string element); + + ///////////// //Accessors// ///////////// /*! - \brief Get Current Display Width. + \brief Get current display width. Get Width of Window or Fullscreen mode. - \return Width of Display. + \return Width of display. **/ int DisplayWidth(); /*! - \brief Get Current Display Height. + \brief Get current display height. - Get Height of Window or Fullscreen mode. - \return Height of Display. + Get height of window or fullscreen mode. + \return Height of display. **/ int DisplayHeight(); /*! - \brief Get Current Display BPP. + \brief Get current display depth. - Get color depth of Window or Fullscreen mode. BPP means bits per pixel. - \return BPP or depth of Display. + Get color depth of window or fullscreen mode. + \return Color depth (bpp) of display. **/ int DisplayDepth(); #ifdef DEPRECIATED - /*! - \brief Get Current Display Width. - - Get Width of Window or Fullscreen mode. - \return Width of Display. - **/ int Width(); - - /*! - \brief Get Current Display Height. - - Get Height of Window or Fullscreen mode. - \return Height of Display. - **/ int Height(); - - /*! - \brief Get Current Display BPP. - - Get BPP of Window or Fullscreen mode. - \return BPP of Display. - **/ int BPP(); #endif //DEPRECIATED diff --git a/include/ZE_ZFont.h b/include/ZE_ZFont.h index 98383f9..f6fbc05 100644 --- a/include/ZE_ZFont.h +++ b/include/ZE_ZFont.h @@ -13,7 +13,7 @@ \brief Definition file for ZFont. Definition file for ZFont, the basic Font class for ZEngine. -
$Id: ZE_ZFont.h,v 1.16 2003/11/24 22:22:07 cozman Exp $
+
$Id: ZE_ZFont.h,v 1.17 2003/12/24 04:46:48 cozman Exp $
\author James Turk **/ @@ -97,6 +97,13 @@ class ZFont **/ void OpenFromZip(std::string zipname, std::string filename, int size); + /*! + \brief Opens a font file from the current ZEngine Resource File. + + Open font file from the current ZEngine Resource File, the XML resource file set via ZEngine::SetResourceFile. + **/ + void OpenFromZRF(std::string resourceId); + /*! \brief Release font. diff --git a/include/ZE_ZImage.h b/include/ZE_ZImage.h index f141771..0d84c17 100644 --- a/include/ZE_ZImage.h +++ b/include/ZE_ZImage.h @@ -13,7 +13,7 @@ \brief Definition file for ZImage. Definition file for ZImage, the ZImage class for ZEngine. -
$Id: ZE_ZImage.h,v 1.29 2003/11/24 22:22:07 cozman Exp $
+
$Id: ZE_ZImage.h,v 1.30 2003/12/24 04:46:48 cozman Exp $
\author James Turk **/ @@ -65,7 +65,7 @@ class ZImage \return num rounded up to closest power of two. \since 0.8.6 **/ - int PowerOfTwo(int num); + int PowerOfTwo(int num) const; /*! \brief Converts an SDL_Surface to an OpenGL texture ID. @@ -79,7 +79,7 @@ class ZImage \return OpenGL texture ID for SDL_Surface, 0 if an error occurs. \since 0.8.6 **/ - GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord); + GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord) const; #endif //GFX_BACKEND == OGL public: @@ -107,14 +107,6 @@ class ZImage **/ ZImage(std::string filename); - /*! - \brief Constructor to Construct from SDL_Surface*. - - Constructor is same as calling ZImage::Attach() on passed SDL_Surface*. - \param surface SDL_Surface* to use as rImage. - **/ - ZImage(SDL_Surface *surface); - /*! \brief Constructor to Construct from part of an SDL_Surface*. @@ -141,6 +133,14 @@ class ZImage **/ ZImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); + /*! + \brief Constructor to Construct from SDL_Surface*. + + Constructor is same as calling ZImage::Attach() on passed SDL_Surface*. + \param surface SDL_Surface* to use as rImage. + **/ + ZImage(SDL_Surface *surface); + /*! \brief Destructor, frees memory. @@ -169,6 +169,13 @@ class ZImage **/ void OpenFromZip(std::string zipname, std::string filename); + /*! + \brief Opens an image file from the current ZEngine Resource File. + + Open image file from the current ZEngine Resource File, the XML resource file set via ZEngine::SetResourceFile. + **/ + void OpenFromZRF(std::string resourceId); + /*! \brief Cuts part of an existing image to create a new image. diff --git a/include/ZE_ZMusic.h b/include/ZE_ZMusic.h index e89b176..ffe3f20 100644 --- a/include/ZE_ZMusic.h +++ b/include/ZE_ZMusic.h @@ -13,7 +13,7 @@ \brief Definition file for ZMusic. Definition file for ZMusic, the Music file wrapper for ZEngine. -
$Id: ZE_ZMusic.h,v 1.10 2003/11/24 22:22:07 cozman Exp $
+
$Id: ZE_ZMusic.h,v 1.11 2003/12/24 04:46:48 cozman Exp $
\author James Turk **/ @@ -78,6 +78,13 @@ class ZMusic **/ void Open(std::string filename); + /*! + \brief Opens a music file from the current ZEngine Resource File. + + Open music file from the current ZEngine Resource File, the XML resource file set via ZEngine::SetResourceFile. + **/ + void OpenFromZRF(std::string resourceId); + /*! \brief Release music. diff --git a/include/ZE_ZSound.h b/include/ZE_ZSound.h index 8c3c965..8b8a112 100644 --- a/include/ZE_ZSound.h +++ b/include/ZE_ZSound.h @@ -13,7 +13,7 @@ \brief Definition file for ZSound. Definition file for ZSound, the Sound Effect wrapper for ZEngine. -
$Id: ZE_ZSound.h,v 1.11 2003/11/23 19:27:41 cozman Exp $
+
$Id: ZE_ZSound.h,v 1.12 2003/12/24 04:46:48 cozman Exp $
\author James Turk **/ @@ -89,6 +89,13 @@ class ZSound **/ void OpenFromZip(std::string zipname, std::string filename); + /*! + \brief Opens a sound effect file from the current ZEngine Resource File. + + Open sound effect file from the current ZEngine Resource File, the XML resource file set via ZEngine::SetResourceFile. + **/ + void OpenFromZRF(std::string resourceId); + /*! \brief Release sound effect. diff --git a/src/ZE_ZEngine.cpp b/src/ZE_ZEngine.cpp index d4ed030..043c393 100644 --- a/src/ZE_ZEngine.cpp +++ b/src/ZE_ZEngine.cpp @@ -13,7 +13,7 @@ \brief Central source file for ZEngine. Actual implementation of ZEngine singleton class, the core of ZEngine. -
$Id: ZE_ZEngine.cpp,v 1.66 2003/12/14 22:36:50 cozman Exp $
+
$Id: ZE_ZEngine.cpp,v 1.67 2003/12/24 04:43:36 cozman Exp $
\author James Turk **/ @@ -36,26 +36,29 @@ ZEngine::ZEngine() : mSecPerFrame(0.0), mNeedReload(false), mActive(false), mQuit(false), mKeyIsPressed(NULL), mMouseX(0), mMouseY(0), mMouseB(0), - mErrlog(stderr), mEventFilter(NULL) + mLogStyle(ZLOG_TEXT), mErrlog(stderr), mEventFilter(NULL) { for(int k = 0; k < SDLK_LAST; ++k) mKeyPress[k] = false; - - //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."; +} + +TiXmlElement* ZEngine::FindElement(std::string type, std::string id) +{ + if(rZRF.RootElement()) + { + TiXmlElement *elem = rZRF.RootElement()->FirstChildElement(); + + //while element exists + while(elem) + { + if(strcmpi(elem->Value(),type.c_str()) == 0 && strcmpi(elem->Attribute("id"),id.c_str()) == 0) + return elem; + else + elem = elem->NextSiblingElement(); + } + } + + return NULL; //if it gets this far, problem } ZEngine* ZEngine::GetInstance() @@ -97,7 +100,7 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std sdlFlags |= SDL_INIT_AUDIO; if(SDL_Init(sdlFlags) < 0) { - ReportError(ZERR_SDL_INIT,SDL_GetError()); + ReportError(ZERR_CRITICAL,"Error initializing SDL: %s",SDL_GetError()); return false; //return now, nothing else should be called } } @@ -107,7 +110,7 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std { if(Mix_OpenAudio(soundRate, AUDIO_S16SYS, stereo?2:1, 4096) < 0) //Open Audio (Stereo?2:1 is conditional for number of channels) { - ReportError(ZERR_MIX_INIT,SDL_GetError()); + ReportError(ZERR_ERROR,"Error initializing SDL_mixer: %s",SDL_GetError()); status = false; } } @@ -119,7 +122,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,"%d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",bpp); + ReportError(ZERR_WARNING,"Error creating display: %d is invalid BPP, must be 8,15,16,24 or 32, trying best BPP.",bpp); bpp = -1; } else //this decides correcr BPP @@ -130,12 +133,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,"%dx%d not supported in any depth.",width,height); + ReportError(ZERR_ERROR,"Error creating display: %dx%d not supported in any depth.",width,height); return false; //return now } else if(okBPP != bpp) { - ReportError(ZERR_VIDMODE,"%dx%d not supported in %dBPP, trying %dBPP.",width,height,bpp,okBPP); + ReportError(ZERR_WARNING,"Error creating display: %dx%d not supported in %dBPP, trying %dBPP.",width,height,bpp,okBPP); bpp = okBPP; } } @@ -195,7 +198,7 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std if(!mScreen) { - ReportError(ZERR_VIDMODE,"Unknown Error. %dx%d %dBPP (%s)", width, height, bpp, SDL_GetError()); + ReportError(ZERR_CRITICAL,"Error creating display: Unknown Error. %dx%d %dBPP (%s)", width, height, bpp, SDL_GetError()); #ifdef USE_SDL_MIXER Mix_CloseAudio(); @@ -216,7 +219,7 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std { if(TTF_Init() < 0) { - ReportError(ZERR_TTF_INIT,TTF_GetError()); + ReportError(ZERR_ERROR,"Error initializing SDL_ttf: %s",TTF_GetError()); status = false; //possible to go on without SDL_TTF } } @@ -257,7 +260,7 @@ void ZEngine::ToggleFullscreen() #ifdef linux //SDL_WM_TF only works on Linux SDL_WM_ToggleFullScreen(mScreen); #else - CreateDisplay(mScreen->w,mScreen->h,mScreen->format->BitsPerPixel,!mFullscreen,""); //title, soundRate, stereo, and icon not used + CreateDisplay(mScreen->w,mScreen->h,mScreen->format->BitsPerPixel,!mFullscreen); #endif SetReloadNeed(true); //images need to be reloaded on fullscreen swap } @@ -478,11 +481,11 @@ bool ZEngine::MButtonPressed() return (mMouseB & SDL_BUTTON_MMASK) > 0; } -bool ZEngine::MouseInRect(SDL_Rect *rect) +bool ZEngine::MouseInRect(const SDL_Rect &rect) { //useful function, needed so much it made it into ZEngine - return (mMouseX >= rect->x && mMouseX <= rect->x+rect->w && - mMouseY >= rect->y && mMouseY <= rect->y+rect->h); + return (mMouseX >= rect.x && mMouseX <= rect.x+rect.w && + mMouseY >= rect.y && mMouseY <= rect.y+rect.h); } bool ZEngine::MouseInRect(ZRect rect) @@ -557,9 +560,9 @@ void ZEngine::SetEventFilter(SDL_EventFilter filter) mEventFilter = filter; } -void ZEngine::SetErrorLog(std::string logFile) +void ZEngine::SetErrorLog(ZErrorLogStyle logStyle, std::string logFile) { - if(logFile.length()) + if(logStyle != ZLOG_NONE && logFile.length()) { //stderr & stdout directed to their appropriate streams if(logFile == "stderr") @@ -568,6 +571,20 @@ void ZEngine::SetErrorLog(std::string logFile) mErrlog = stdout; else mErrlog = std::fopen(logFile.c_str(),"w"); + + if(logStyle == ZLOG_HTML) + { + fprintf(mErrlog, + "ZEngine Error Log\n\n\n\n"); + fflush(mErrlog); + } } } @@ -576,25 +593,64 @@ void ZEngine::DisableErrorLog() mErrlog = NULL; } -void ZEngine::ReportError(ZErrorCode type, std::string desc, ...) +void ZEngine::ReportError(ZErrorSeverity severity, std::string desc, ...) { - char buf[512]; - va_list args; - std::string msg; + static std::string prefix[] = { + " ", + "VERBOSE: ", + "DEPRECIATED: ", + "WARNING: ", + "ERROR: ", + "CRITICAL: " + }; - va_start(args,desc); - vsprintf(buf,desc.c_str(),args); - va_end(args); + static std::string style[] = { + "note", + "verbose", + "depr", + "warning", + "error", + "critical" + }; - msg = desc.length() ? FormatStr(mErrorDesc[type],buf) : mErrorDesc[type]; - - if(mErrlog) + if(mLogStyle != ZLOG_NONE) { - std::fprintf(mErrlog,msg.c_str()); + char buf[1024]; + va_list args; + std::string msg; + + va_start(args,desc); + vsprintf(buf,desc.c_str(),args); + va_end(args); + + if(mLogStyle == ZLOG_TEXT) + { + fprintf(mErrlog,"%s%s\n",prefix[static_cast(severity)].c_str(),buf); + } + else if(mLogStyle == ZLOG_HTML) + { + fprintf(mErrlog,"

%s%s

\n",style[static_cast(severity)].c_str(),prefix[static_cast(severity)].c_str(),buf); + } + std::fflush(mErrlog); } } +void ZEngine::WriteLog(std::string str, ...) +{ + if(mLogStyle != ZLOG_NONE) + { + char buf[1024]; + va_list args; + + va_start(args,str); + vsprintf(buf,str.c_str(),args); + va_end(args); + + + } +} + void ZEngine::SeedRandGen(unsigned long seed) { mRandGen.Seed(seed); @@ -635,6 +691,58 @@ double ZEngine::RandDouble() return mRandGen.RandDouble(); } +void ZEngine::SetResourceFile(std::string filename) +{ + rZRF.LoadFile(filename); + //if(rZRF.Error()) + //log an error +} + +std::string ZEngine::GetStringResource(std::string type, std::string id, std::string element) +{ + TiXmlElement *elem = FindElement(type,id); + if(elem) + return elem->Attribute(element.c_str()); + else + { + //error + return ""; //empty string + } +} + +int ZEngine::GetIntResource(std::string type, std::string id, std::string element) +{ + TiXmlElement *elem = FindElement(type,id); + int ret; + + if(elem && (elem->QueryIntAttribute(element.c_str(),&ret) == TIXML_SUCCESS)) + return ret; + else + { + if(!elem) + WriteLog("no elem"); + else if(elem->QueryIntAttribute(element.c_str(),&ret) == TIXML_NO_ATTRIBUTE) + WriteLog("no attribute"); + else if(elem->QueryIntAttribute(element.c_str(),&ret) == TIXML_WRONG_TYPE) + WriteLog("wrong type"); + return 0; + } +} + +double ZEngine::GetDoubleResource(std::string type, std::string id, std::string element) +{ + TiXmlElement *elem = FindElement(type,id); + double ret; + + if(elem && elem->QueryDoubleAttribute(element.c_str(),&ret) == TIXML_SUCCESS) + return ret; + else + { + //error + return 0; + } +} + int ZEngine::DisplayWidth() { return mScreen->w; diff --git a/src/ZE_ZFont.cpp b/src/ZE_ZFont.cpp index d61e7ee..9fe1261 100644 --- a/src/ZE_ZFont.cpp +++ b/src/ZE_ZFont.cpp @@ -13,7 +13,7 @@ \brief Source file for ZFont. Implementation of ZFont, the basic Font class for ZEngine. -
$Id: ZE_ZFont.cpp,v 1.16 2003/11/24 02:21:20 cozman Exp $
+
$Id: ZE_ZFont.cpp,v 1.17 2003/12/24 04:43:36 cozman Exp $
\author James Turk **/ @@ -54,7 +54,7 @@ void ZFont::Open(std::string filename, int size) rFont = TTF_OpenFont(filename.c_str(),size); if(!rFont) - rEngine->ReportError(ZERR_LOAD_FONT,filename); + rEngine->ReportError(ZERR_WARNING,"Could not load %s",filename.c_str()); } void ZFont::OpenFromZip(std::string zipname, std::string filename, int size) @@ -70,12 +70,24 @@ void ZFont::OpenFromZip(std::string zipname, std::string filename, int size) if(rw) { rFont = TTF_OpenFontRW(rw,0,size); + //dont free buffer on ZFont? //delete []rw->hidden.mem.base; //must free buffer //SDL_FreeRW(rw); } if(!rFont) - rEngine->ReportError(ZERR_LOAD_FONT,"%s in %s archive",filename.c_str(),zipname.c_str()); + rEngine->ReportError(ZERR_WARNING,"Could not load %s from %s",filename.c_str(),zipname.c_str()); +} + +void ZFont::OpenFromZRF(std::string resourceId) +{ + std::string filename = rEngine->GetStringResource("font",resourceId,"filename"); + int size = rEngine->GetIntResource("font",resourceId,"size"); + + if(filename.length() && size) + Open(filename,size); + else + ;//error } void ZFont::Release() @@ -136,7 +148,7 @@ void ZFont::SetStyle(bool bold, bool italic, bool underline) if(rFont) TTF_SetFontStyle(rFont,flags); else - rEngine->ReportError(ZERR_NOFONT,"SetStyle"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::SetStyle with no font loaded."); } void ZFont::Resize(int size) @@ -158,7 +170,7 @@ bool ZFont::IsBold() const return (TTF_GetFontStyle(rFont) & TTF_STYLE_BOLD) > 0; else { - rEngine->ReportError(ZERR_NOFONT, "IsBold"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::IsBold with no font loaded."); return false; } } @@ -169,7 +181,7 @@ bool ZFont::IsItalic() const return (TTF_GetFontStyle(rFont) & TTF_STYLE_ITALIC) > 0; else { - rEngine->ReportError(ZERR_NOFONT, "IsItalic"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::IsItalic with no font loaded."); return false; } } @@ -180,7 +192,7 @@ bool ZFont::IsUnderlined() const return (TTF_GetFontStyle(rFont) & TTF_STYLE_UNDERLINE) > 0; else { - rEngine->ReportError(ZERR_NOFONT, "IsUnderlined"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::IsUnderlined with no font loaded."); return false; } } @@ -191,7 +203,7 @@ int ZFont::Height() const return TTF_FontHeight(rFont); else { - rEngine->ReportError(ZERR_NOFONT, "GetHeight"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::Height with no font loaded."); return 0; } } @@ -202,7 +214,7 @@ int ZFont::LineSkip() const return TTF_FontLineSkip(rFont); else { - rEngine->ReportError(ZERR_NOFONT, "GetLineSkip"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::LineSkip with no font loaded."); return 0; } } @@ -218,7 +230,7 @@ int ZFont::StringWidth(std::string text) const } else { - rEngine->ReportError(ZERR_NOFONT, "GetStringWidth"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::StringWidth with no font loaded."); return 0; } } @@ -234,7 +246,7 @@ int ZFont::StringHeight(std::string text) const } else { - rEngine->ReportError(ZERR_NOFONT, "GetStringHeight"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZFont::StringHeight with no font loaded."); return 0; } } diff --git a/src/ZE_ZImage.cpp b/src/ZE_ZImage.cpp index 2ace89b..f67ed92 100644 --- a/src/ZE_ZImage.cpp +++ b/src/ZE_ZImage.cpp @@ -13,7 +13,7 @@ \brief Source file for ZImage. Implementation of ZImage, the Image class for ZEngine. -
$Id: ZE_ZImage.cpp,v 1.53 2003/12/14 22:40:00 cozman Exp $
+
$Id: ZE_ZImage.cpp,v 1.54 2003/12/24 04:43:36 cozman Exp $
\author James Turk **/ @@ -25,7 +25,7 @@ namespace ZE #if (GFX_BACKEND == ZE_OGL) //from SDL's testgl.c power_of_two -int ZImage::PowerOfTwo(int num) +int ZImage::PowerOfTwo(int num) const { int value = 1; @@ -35,7 +35,7 @@ int ZImage::PowerOfTwo(int num) } //from SDL's testgl.c SDL_GL_LoadTexture -GLuint ZImage::SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord) +GLuint ZImage::SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord) const { GLuint texture; int w, h; @@ -169,7 +169,7 @@ void ZImage::Open(std::string filename) #endif //USE_SDL_IMAGE if(!image) - rEngine->ReportError(ZERR_LOAD_IMAGE,filename); + rEngine->ReportError(ZERR_WARNING,"Could not load %s",filename.c_str()); else Attach(image); } @@ -193,11 +193,20 @@ void ZImage::OpenFromZip(std::string zipname, std::string filename) } if(!image) - rEngine->ReportError(ZERR_LOAD_IMAGE,"%s in %s archive",filename.c_str(),zipname.c_str()); + rEngine->ReportError(ZERR_WARNING,"Could not load %s from %s",filename.c_str(),zipname.c_str()); else Attach(image); } +void ZImage::OpenFromZRF(std::string resourceId) +{ + std::string filename = rEngine->GetStringResource("image",resourceId,"filename"); + if(filename.length()) + Open(filename); + //else + //error +} + void ZImage::OpenFromImage(SDL_Surface *image, Sint16 x, Sint16 y, Sint16 w, Sint16 h) { SDL_Surface *cutImg = NULL; @@ -210,13 +219,13 @@ void ZImage::OpenFromImage(SDL_Surface *image, Sint16 x, Sint16 y, Sint16 w, Sin rect.h = h; if(!image) - rEngine->ReportError(ZERR_NOIMAGE,"OpenFromImage"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZImage::OpenFromImage with no image loaded."); cutImg = SDL_CreateRGBSurface(0, rect.w, rect.h, image->format->BitsPerPixel, image->format->Rmask, image->format->Gmask, image->format->Bmask, image->format->Amask); if(!cutImg) - rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_CreateRGBSurface failed in ZImage::OpenFromImage: %s.",SDL_GetError()); + rEngine->ReportError(ZERR_CRITICAL,"SDL internal error: 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 @@ -249,7 +258,7 @@ void ZImage::Attach(SDL_Surface *surface) } else //can't convert, leave surface as is { - rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError()); + rEngine->ReportError(ZERR_CRITICAL,"SDL internal error: SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError()); } rWidth = static_cast(surface->w); @@ -262,7 +271,7 @@ void ZImage::Attach(SDL_Surface *surface) rImage = surface; } else - rEngine->ReportError(ZERR_NOIMAGE,"Attach"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZImage::Attach with no image loaded."); } void ZImage::Reload() @@ -297,12 +306,12 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) { color = SDL_MapRGB(rImage->format,red,green,blue); if(SDL_SetColorKey(rImage, SDL_SRCCOLORKEY, color) < 0) - rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError()); + rEngine->ReportError(ZERR_CRITICAL,"SDL internal error: SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError()); else Reload(); //do the reattach hack, this gets a new OpenGL surface for the same image } else - rEngine->ReportError(ZERR_NOIMAGE,"SetColorKey"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZImage::SetColorKey with no image loaded."); } void ZImage::Draw(int x, int y) const @@ -498,7 +507,7 @@ void ZImage::Bind() const if(rTexID) glBindTexture(GL_TEXTURE_2D, rTexID); else - rEngine->ReportError(ZERR_NOIMAGE,"Bind"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZImage::Bind with no image loaded."); } @@ -523,13 +532,13 @@ void ZImage::Attach(SDL_Surface *surface) } else //can't convert, leave surface as is { - rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError())); + rEngine->ReportError("SDL internal error: SDL_DisplayFormatAlpha failed in ZImage::Attach: %s",SDL_GetError())); } rImage = surface; } else - rEngine->ReportError(ZERR_NOIMAGE,"Attach"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZImage::Attach NULL parameter."); } void ZImage::Reload() @@ -548,10 +557,10 @@ void ZImage::SetAlpha(Uint8 alpha) if(rImage) { if(SDL_SetAlpha(rImage, rAlpha == SDL_ALPHA_OPAQUE ? 0 : SDL_SRCALPHA, alpha) < 0) - rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_SetAlpha failed in ZImage::SetAlpha: %s",SDL_GetError())); + rEngine->ReportError("SDL internal error: SDL_SetAlpha failed in ZImage::SetAlpha: %s",SDL_GetError())); } else - rEngine->ReportError(ZERR_NOIMAGE,"SetAlpha"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZImage::SetAlpha with no image loaded."); } void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) @@ -562,7 +571,7 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) { color = SDL_MapRGBA(rImage->format,red,green,blue,255); if(SDL_SetColorKey(rImage, SDL_RLEACCEL|SDL_SRCCOLORKEY, color) < 0) - rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError())); + rEngine->ReportError("SDL internal error: SDL_SetColorKey failed in ZImage::SetColorKey: %s",SDL_GetError())); //surface conversion// SDL_Surface *temp = rImage; rImage = SDL_DisplayFormatAlpha(temp); //TTF_RenderTextBlended relys on this @@ -572,12 +581,12 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue) } else //can't convert { - rEngine->ReportError(ZERR_SDL_INTERNAL,"SDL_DisplayFormatAlpha failed in ZImage::SetColorKey: %s",SDL_GetError())); + rEngine->ReportError("SDL internal error: SDL_DisplayFormatAlpha failed in ZImage::SetColorKey: %s",SDL_GetError())); rImage = temp; } } else - rEngine->ReportError(ZERR_NOIMAGE,"SetColorKey"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZImage::SetColorKey with no image loaded."); } void ZImage::Draw(int x, int y) const diff --git a/src/ZE_ZMusic.cpp b/src/ZE_ZMusic.cpp index db5329a..bd721c9 100644 --- a/src/ZE_ZMusic.cpp +++ b/src/ZE_ZMusic.cpp @@ -13,7 +13,7 @@ \brief Source file for ZMusic. Implementation of ZMusic, the basic Music class for ZEngine. -
$Id: ZE_ZMusic.cpp,v 1.12 2003/11/24 02:21:20 cozman Exp $
+
$Id: ZE_ZMusic.cpp,v 1.13 2003/12/24 04:43:36 cozman Exp $
\author James Turk **/ @@ -52,7 +52,16 @@ void ZMusic::Open(std::string filename) rMusic = Mix_LoadMUS(filename.c_str()); if(!rMusic) - rEngine->ReportError(ZERR_LOAD_MUSIC,filename); + rEngine->ReportError(ZERR_WARNING,"Could not load %s",filename.c_str()); +} + +void ZMusic::OpenFromZRF(std::string resourceId) +{ + std::string filename = rEngine->GetStringResource("music",resourceId,"filename"); + if(filename.length()) + Open(filename); + //else + //error } void ZMusic::Release() @@ -74,7 +83,7 @@ void ZMusic::Play(int loopNum, int fadeTime) const Mix_PlayMusic(rMusic, loopNum); } else - rEngine->ReportError(ZERR_NOMUSIC, "Play"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Play with no music loaded."); } void ZMusic::Pause() const @@ -82,7 +91,7 @@ void ZMusic::Pause() const if(rMusic) Mix_PauseMusic(); else - rEngine->ReportError(ZERR_NOMUSIC, "Pause"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Pause with no music loaded."); } void ZMusic::Unpause() const @@ -90,7 +99,7 @@ void ZMusic::Unpause() const if(rMusic) Mix_ResumeMusic(); else - rEngine->ReportError(ZERR_NOMUSIC, "Unpause"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Unpause with no music loaded."); } void ZMusic::Rewind() const @@ -98,7 +107,7 @@ void ZMusic::Rewind() const if(rMusic) Mix_RewindMusic(); else - rEngine->ReportError(ZERR_NOMUSIC, "Rewind"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Rewind with no music loaded."); } void ZMusic::Stop(int fadeTime) const @@ -111,7 +120,7 @@ void ZMusic::Stop(int fadeTime) const Mix_HaltMusic(); } else - rEngine->ReportError(ZERR_NOMUSIC, "Stop"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Stop with no music loaded."); } void ZMusic::SetVolume(int volume) @@ -119,7 +128,7 @@ void ZMusic::SetVolume(int volume) if(rMusic) Mix_VolumeMusic(volume); else - rEngine->ReportError(ZERR_NOMUSIC, "SetVolume"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::SetVolume with no music loaded."); } bool ZMusic::IsLoaded() const @@ -133,7 +142,7 @@ bool ZMusic::IsPlaying() const return Mix_PlayingMusic() > 0; else { - rEngine->ReportError(ZERR_NOMUSIC, "IsPlaying"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::IsPlaying with no music loaded."); return false; } } @@ -144,7 +153,7 @@ bool ZMusic::IsPaused() const return Mix_PausedMusic() > 0; else { - rEngine->ReportError(ZERR_NOMUSIC, "IsPaused"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::IsPaused with no music loaded."); return false; } } @@ -155,7 +164,7 @@ int ZMusic::Volume() const return Mix_VolumeMusic(-1); else { - rEngine->ReportError(ZERR_NOMUSIC, "GetVolume"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::GetVolume with no music loaded."); return false; } } diff --git a/src/ZE_ZSound.cpp b/src/ZE_ZSound.cpp index 2aeddbd..6b8b2ad 100644 --- a/src/ZE_ZSound.cpp +++ b/src/ZE_ZSound.cpp @@ -13,7 +13,7 @@ \brief Source file for ZSound. Implementation of ZSound, the basic Sound class for ZEngine. -
$Id: ZE_ZSound.cpp,v 1.14 2003/11/24 02:21:20 cozman Exp $
+
$Id: ZE_ZSound.cpp,v 1.15 2003/12/24 04:43:36 cozman Exp $
\author James Turk **/ @@ -55,7 +55,7 @@ void ZSound::Open(std::string filename) rSound = Mix_LoadWAV(filename.c_str()); if(!rSound) - rEngine->ReportError(ZERR_LOAD_SOUND,filename); + rEngine->ReportError(ZERR_ERROR,"Could not load %s",filename.c_str()); } void ZSound::OpenFromZip(std::string zipname, std::string filename) @@ -69,7 +69,16 @@ void ZSound::OpenFromZip(std::string zipname, std::string filename) } if(!rSound) - rEngine->ReportError(ZERR_LOAD_SOUND,"%s in %s archive",filename.c_str(),zipname.c_str()); + rEngine->ReportError(ZERR_WARNING,"Could not load %s from %s",filename.c_str(),zipname.c_str()); +} + +void ZSound::OpenFromZRF(std::string resourceId) +{ + std::string filename = rEngine->GetStringResource("sound",resourceId,"filename"); + if(filename.length()) + Open(filename); + //else + //error } void ZSound::Release() @@ -92,7 +101,7 @@ void ZSound::Play(int loopNum, int fadeTime) rChannelID = Mix_PlayChannel(rChannelID, rSound, loopNum); } else if(!rSound) - rEngine->ReportError(ZERR_NOSOUND, "Play"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Play with no sound effect loaded."); } void ZSound::Pause() const @@ -100,7 +109,7 @@ void ZSound::Pause() const if(rSound && rChannelID >= 0) Mix_Pause(rChannelID); else if(!rSound) - rEngine->ReportError(ZERR_NOSOUND, "Pause"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Pause with no sound effect loaded."); } void ZSound::Unpause() const @@ -108,7 +117,7 @@ void ZSound::Unpause() const if(rSound && rChannelID >= 0) Mix_Resume(rChannelID); else if(!rSound) - rEngine->ReportError(ZERR_NOSOUND, "Unpause"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Unpause with no sound effect loaded."); } @@ -122,7 +131,7 @@ void ZSound::Stop(int fadeTime) const Mix_HaltChannel(rChannelID); } else if(!rSound) - rEngine->ReportError(ZERR_NOSOUND, "Stop"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Stop with no sound effect loaded."); } void ZSound::SetVolume(int volume) @@ -130,7 +139,7 @@ void ZSound::SetVolume(int volume) if(rSound) Mix_VolumeChunk(rSound,volume); else - rEngine->ReportError(ZERR_NOSOUND, "SetVolume"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::SetVolume with no sound effect loaded."); } bool ZSound::IsLoaded() const @@ -145,7 +154,7 @@ bool ZSound::IsPlaying() const else { if(rChannelID >= 0) - rEngine->ReportError(ZERR_NOSOUND, "IsPlaying"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::IsPlaying with no sound effect loaded."); return false; } } @@ -156,7 +165,7 @@ bool ZSound::IsPaused() const return Mix_Paused(rChannelID) > 0; else { - rEngine->ReportError(ZERR_NOSOUND, "IsPaused"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::IsPaused with no sound effect loaded."); return false; } } @@ -167,7 +176,7 @@ int ZSound::Volume() const return Mix_VolumeChunk(rSound,-1); else { - rEngine->ReportError(ZERR_NOSOUND, "GetVolume"); + rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::GetVolume with no sound effect loaded."); return -1; } }