diff --git a/include/VersionInfo.h b/include/VersionInfo.h index 418f120..9a7fc2a 100755 --- a/include/VersionInfo.h +++ b/include/VersionInfo.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,83 +8,24 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file VersionInfo.h - \brief Definition file for VersionInfo class. - - Definition file for VersinInfo class, simple class for containing and comparing - version numbers. -
$Id: VersionInfo.h,v 1.4 2003/07/12 01:25:42 cozman Exp $
- \author James Turk -**/ - #ifndef __versioninfo_h__ #define __versioninfo_h__ #include "ZE_Utility.h" -/*! - \brief Class for holding version information. - Class for holding version information on a library. (Members capitalized because - g++ has issues with members named major and minor.) -**/ class VersionInfo { public: - //! Major version number. unsigned int Major; - //! Minor version number, changes upon signifigant releases. (Often upon compatibility breaks.) unsigned int Minor; - //! Version release number, changes on every release. unsigned int Release; - //! String Description of release. (Often blank.) std::string Extra; - /*! - \brief Constructor for VersionInfo. - - Simple constructor for version info, with a parameter for each member. - \param maj Major version number. - \param min Minor version number. - \param rel Version release number. - \param ext Extra info std::string, optional (defaults to empty std::string). - **/ VersionInfo(unsigned int maj, unsigned int min, unsigned int rel, std::string ext=""); - - /*! - \brief Get std::string representing version number. - - Get dotted version number major.minor.release [extra]. - \return Formatted version std::string. - **/ - std::string GetString() const; - - /*! - \brief Less than operator overload for comparing VersionInfo. - - Overload of the less than (<) operator for two VersionInfos. - \param rhs Right hand side of comparison. - \return true if less than, false if greater than or equal to. - **/ + char* GetString() const; bool operator<(const VersionInfo &rhs) const; - - /*! - \brief Equals to operator overload for comparing VersionInfo. - - Overload of the equals to (==) operator for two VersionInfos. - \param rhs Right hand side of comparison. - \return true if equal to, false if not equals to. - **/ bool operator==(const VersionInfo &rhs) const; - - /*! - \brief Greater than operator overload for comparing VersionInfo. - - Overload of the greater than (>) operator for two VersionInfos. - \param rhs Right hand side of comparison. - \return true if greater than, false if less than or equal to. - **/ bool operator>(const VersionInfo &rhs) const; }; diff --git a/include/ZE_Defines.h b/include/ZE_Defines.h index bededf9..147f829 100644 --- a/include/ZE_Defines.h +++ b/include/ZE_Defines.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,34 +8,17 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_Defines.h - \brief Define file for ZEngine where all #define statements to control compilation options are placed. - - Definition file, holds #define statements describing optional features of ZEngine. -
$Id: ZE_Defines.h,v 1.25 2003/11/23 19:31:24 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_defines_h__ #define __ze_defines_h__ //Defines- undefine any of these if you dont have the indicated SDL extension// -//! OpenGL 2D Rendering Target. #define ZE_OGL (1) -//! SDL Rendering Target. #define ZE_SDL (2) -//! Define the graphics backend for ZEngine to use. (Options are ZE_OGL,ZE_SDL,ZE_D3D) #define GFX_BACKEND (ZE_OGL) -//! Define to include font support. #define USE_SDL_TTF -//! Define to include non-bmp image file support. #define USE_SDL_IMAGE -//! Define to include sound support. #define USE_SDL_MIXER -//! Define to use depreciated code that has not been entirely removed. -//#define DEPRECIATED #endif //__ze_defines_h__ diff --git a/include/ZE_Includes.h b/include/ZE_Includes.h index bc3cae5..1163041 100644 --- a/include/ZE_Includes.h +++ b/include/ZE_Includes.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,16 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_Includes.h - \brief Include file for SDL and C++ Includes that many ZEngine files need. - - 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.21 2003/12/24 04:46:48 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_includes_h__ #define __ze_includes_h__ @@ -45,6 +35,7 @@ #include //used by ZConfigFile #include //used by ZConfigFile #include //used in parsing +#include //used in Randgen #include //used in FormatStr #endif //__ze_includes_h__ diff --git a/include/ZE_Utility.h b/include/ZE_Utility.h index 56810ff..716f860 100755 --- a/include/ZE_Utility.h +++ b/include/ZE_Utility.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,17 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_Utility.h - \brief Definition file for ZEngine Utilities. - - Definition file for ZEngine Utilities which are used throughout the engine and can be used in - conjunction with ZEngine. -
$Id: ZE_Utility.h,v 1.10 2003/11/24 02:02:25 cozman Exp $
- \author James Turk -**/ - - #ifndef __ze_utility_h__ #define __ze_utility_h__ @@ -27,65 +16,23 @@ namespace ZE { -/*! - \brief Parses a std::string and interprets variable arguments, similar to sprintf. +std::string FormatStr(std::string fmtStr, ...); - Takes % identifiers out of fmtstr and parses them, replacing them with cooresponding values - in the variable arguments list. For more detail view stdarg documentation. - \param fmtstr defines format of resulting std::string - \param ... variable number of arguments after fmtstr - \return std::string of parsed and combined std::string -**/ -std::string FormatStr(const std::string fmtstr, ...); - -/*! - \brief Extracts a SDL_RWops memory structure from a zip archive. - - Attempts to open a file from within a zipfile and return a SDL_RWops which can be used - to load a resource from memory. - Used internally, generally shouldn't be called by users. - \param zipname Name of zip-format archive to open. - \param filename Name of file within archive to access. - \return On success, pointer to SDL_RWops, on failure, NULL. - \since 0.8.5 -**/ SDL_RWops* RWFromZip(std::string zipname, std::string filename); -/*! - \brief Properly free SDL_Surface. - - Safely free an SDL_Surface* and set it to NULL. - \param image Image to free and set to NULL. -**/ +#if (GFX_BACKEND == ZE_OGL) +int PowerOfTwo(int num); +GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord); +#endif //GFX_BACKEND + void FreeImage(SDL_Surface *&image); #ifdef USE_SDL_MIXER - -/*! - \brief Properly free Mix_Chunk. - - Safely free a Mix_Chunk* and set it to NULL. - \param chunk Chunk to free and set to NULL. -**/ void FreeSound(Mix_Chunk *&chunk); - -/*! - \brief Properly free Mix_Music. - - Safely free a Mix_Music* and set it to NULL. - \param music Music to free and set to NULL. -**/ void FreeMusic(Mix_Music *&music); - #endif #ifdef USE_SDL_TTF -/*! - \brief Properly free TTF_Font. - - Safely free a TTF_Font* and set it to NULL. - \param font Font to free and set to NULL. -**/ void FreeFont(TTF_Font *&font); #endif diff --git a/include/ZE_ZAnimation.h b/include/ZE_ZAnimation.h index 7863f64..0ab814e 100644 --- a/include/ZE_ZAnimation.h +++ b/include/ZE_ZAnimation.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZAnimation.h - \brief Definition file for ZAnimation. - - Definition file for ZAnimation, a class for animations using ZImage. -
$Id: ZE_ZAnimation.h,v 1.2 2003/12/24 04:46:48 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zanimation_h__ #define __ze_zanimation_h__ @@ -38,138 +29,35 @@ enum ZAnimType class ZAnimation { protected: - //! Pointer to ZEngine object. ZEngine *rEngine; - //! Pointer to dynamic array of images. ZImage *rAnimImages; - //! 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; - //! 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(); - - /*! - \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); + virtual ~ZAnimation(); - /*! - \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); - - /*! - \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(); - - /*! - \brief Pauses animation. - - Halts animation at current frame. - **/ void Pause(); - - /*! - \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); - /*! - \brief Updates animation. - - 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; + bool IsRunning() const; }; } diff --git a/include/ZE_ZBaseParticleSystem.h b/include/ZE_ZBaseParticleSystem.h index c3d892e..f65837b 100755 --- a/include/ZE_ZBaseParticleSystem.h +++ b/include/ZE_ZBaseParticleSystem.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,16 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZBaseParticleSystem.h - \brief Definition and implementation file for the base of the ZEngine Particle System. - - Definition and implementation file for ZEngine particle system class ZBaseParticleSystem. - Due to problems with template classes the template implementation needs to be in the same file as the declaration. -
$Id: ZE_ZBaseParticleSystem.h,v 1.5 2003/07/12 01:25:42 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zbaseparticlesystem_h__ #define __ze_zbaseparticlesystem_h__ @@ -26,172 +16,50 @@ namespace ZE { -/*! - \brief Basic particle class for ZEngine particle systems. - - Basic particle class, all particles used should derive from this class so that needed members are available. - (No default constructor is needed because NewParticle should initialize members.) -**/ class ZBaseParticle { - public: - /*! - \brief Virtual destructor. - - Empty virtual destructor to make inheritance safe. - **/ + public: virtual ~ZBaseParticle() {} // empty definition here, since ZBaseParticleSystem has no cpp file and this would be all that would be in it - //! X Position of particle. float xPos; - //! Y Position of particle. float yPos; - //! Energy of particle (particles die if energy is 0). float energy; }; -/*! - \brief Base particle system, a virtual class defining an outline for a fully functional particle system. - - Virtual class providing outline of basic particle system, designed so that a working particle system can be - derived with minimal waste. Uses templated system to allow particle systems to work with their own types of - particles, the particleType template parameter must be a type that has the members of ZBaseParticle. - (Note: If you need a very specific particle system it's probably best to write your own fit to your needs.) -**/ template class ZBaseParticleSystem { protected: - //! Pointer to ZEngine singleton. ZEngine *rEngine; - //! Pointer to array of particles. particleType *rParticles; - //! Maximum number of particles, and size of rParticles array. unsigned int rMaxParticles; - //! Current number of particles. unsigned int rCurParticles; - //! Number of particles to release per second. unsigned int rNumParticlesPerSec; - //! Millisecond format time of last update. Uint32 rLastUpdate; - //! Boolean value indicating if system is paused. bool rPaused; - /*! - \brief Adds a new particle. - - Finds room in array with dead particle, and adds new particle using NewParticle, called by Emit. - **/ void AddParticle(); - - /*! - \brief Pure virtual function to initialize and return a new particle. - - Pure virtual function, overload should set up a new particle with desired traits, called by AddParticle. - **/ virtual particleType NewParticle()=0; - - /*! - \brief Pure virtual function to update a particle. - - Pure virtual function, overload should update the particle `rParticles[index]`, called by Update. - \param index Index of particle in rParticles array to update. - \param elapsedTime Decimal portion of a second since last call. - **/ virtual void UpdateParticle(int index, float elapsedTime)=0; public: - /*! - \brief Basic constructor for ZBaseParticleSystem. - - Basic constructor for ZBaseParticle system, initializes all values to 0. - **/ ZBaseParticleSystem(); - - /*! - \brief Virtual destructor for ZBaseParticleSystem. - - Virtual destructor for ZBaseParticleSystem, destroys all particles, virtual to make class inheritance-safe. - **/ virtual ~ZBaseParticleSystem(); - /*! - \brief Pure virtual function, renders the particles. - - Pure virtual so that each particle system can render it's member particles in it's own way. - **/ virtual void Render()=0; - - /*! - \brief Emit a given number of particles. - - Emits a given number of particles, will not emit particles if system is full. - \param numParticles Number of particles to emit. - **/ - void Emit(int numParticles); - - /*! - \brief Updates status of particle system. - - Updates entire particle system, calling update on every particle, emitting necessary new - particles, removing particles which have an energy <= 0 or are off the screen. Virtual for - special cases, but generally should not be overridden. - **/ + void Emit(int numParticles); virtual void Update(); - /*! - \brief Empties particle system of all particles. - - Empties particle system of all particles, does not alter paused state. - **/ void Clear(); - - /*! - \brief Pauses particle system. - - Pauses particle system, particles may still be drawn but particles are not updated. - **/ void Pause(); - - /*! - \brief Unpauses particle system. - - Returns particle system to active state, system starts unpaused. - **/ void Unpause(); - - /*! - \brief Clears system and pauses it. - - Same as calling Clear() and then Pause(), use unpause to restart system. - **/ void Stop(); - /*! - \brief Detect if particle system is currently paused. - - Returns bool indicating if the particle system is currently paused. - \return true if paused, false if active - **/ - bool Paused(); - - /*! - \brief Sets max particles allowed in system. - - Set maximum number of particles allowed in system, particles are not emitted when system is full. - When this resizes the array contents are moved to the new array, if it shrinks the array particles may be lost. - \param max Maximum number of particles for system. - **/ - void SetMaxParticles(unsigned int max); - - /*! - \brief Sets release rate of particles. - - Set number of particles to release per second. - \param rate Number of particles to release over the duration of one second. - **/ + void SetMaxParticles(unsigned int max); void SetRate(unsigned int rate); + + bool IsPaused(); }; //implementation// @@ -292,7 +160,7 @@ void ZBaseParticleSystem::Stop() } template -bool ZBaseParticleSystem::Paused() +bool ZBaseParticleSystem::IsPaused() { return rPaused; } diff --git a/include/ZE_ZConfigFile.h b/include/ZE_ZConfigFile.h index 8489a89..20a313e 100644 --- a/include/ZE_ZConfigFile.h +++ b/include/ZE_ZConfigFile.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,16 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZConfigFile.h - \brief Definition file for ZConfigFile. - - Definition file for ZConfigFile, an INI-style config file format.
- $ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $ - \author James Turk -**/ - - #ifndef __ze_zconfigfile_h__ #define __ze_zconfigfile_h__ @@ -26,239 +16,52 @@ namespace ZE { -/*! - \brief ZConfigFile Class for use in ZEngine. - - ZConfigFile class for INI-style configuration files for games or applications. - ZConfigFile can have comments using the semicolon (;) or octothorpe (#) characters. - Sections are delimited by [section-name], and variables must start with a letter - and should be in the format variable = data. -**/ class ZConfigFile { private: - //Private Types// - - /*! - \brief ZConfigFile Variable class. - - ZConfigFile class for mapping a variable name to it's value, stored in std::string form (later converted to - bool or int if needed). - **/ class ZCF_Variable { public: - //! Variable name. std::string var; - //! Value associated with variable. std::string val; }; - - /*! - \brief ZConfigFile Section class. - - ZConfigFile class for mapping a section name to a list of variables in that section. - **/ + class ZCF_Section { public: - //! Section name. std::string section; - //! STL list of variables. std::list varList; }; protected: - //! List of sections of internal type. std::list rFileLayout; - //! Filename of file currently open. std::string rFilename; - - /*! - \brief Reformat a std::string in a form more suitable to parsing. - - Removes whitespace from a std::string and makes all characters lowercase. - \param str The std::string to get a clean version of. - \return Cleaned std::string. - **/ - std::string CleanString(std::string str) const; - - /*! - \brief Check if a section exists. - - Find out if a section currently exists. - \param sec Section to check for. - \return bool, true if section exists in file. - **/ + + std::string CleanString(std::string str) const; bool Exists(std::string sec) const; - - /*! - \brief Check if a variable exists. - - Find out if a variable currently exists. - \param sec Section to check in. - \param var Variable to check for. - \return bool, true if section exists in file. - **/ bool Exists(std::string sec, std::string var) const; - - /*! - \brief Internal function to set variables. - - Set variable to value, called internally only. - \param sec Section for variable. - \param var Variable to set. - \param val Value to set variable to. - **/ void SetVariable(std::string sec, std::string var, std::string val); - - /*! - \brief Internal function to get value of a variable. - - Get value of variable, called internally only. - \param sec Section for variable. - \param var Variable to get. - \param defVal Value to return if variable doesnt exist. - \return Value of variable. - **/ std::string GetVariable(std::string sec, std::string var, std::string defVal) const; - public: - - /*! - \brief Default constructor. - - A no-op default constructor. - **/ + public: ZConfigFile(); - - /*! - \brief Constructor which takes filename. - - Constructor takes filename, and calls process on it. - \param filename File to load as ZConfigFile. - **/ ZConfigFile(std::string filename); - - /*! - \brief Destructor, flushes file. - - Flushes the file, ensures a flush if the file is left open. - **/ virtual ~ZConfigFile(); - /*! - \brief Parse a file. - - Parses the file, reading the contents into the fileLayout map. - \param filename File to parse and attach this ZDataFile to. - **/ void Process(std::string filename); - /*! - \brief Get value in floating point format from file. - - Get the current value of a variable in the file, or defVal if not found in file. - \since 0.8.3 - \param section Name of section to seek variable under. - \param var Name of variable to seek value for. - \param defVal Value to return if var does not exist within section. - \return Contents of the variable in floating point format. - **/ float GetFloat(std::string section, std::string var, float defVal) const; - - /*! - \brief Get value in integer format from file. - - Get the current value of a variable in the file, or defVal if not found in file. - \param section Name of section to seek variable under. - \param var Name of variable to seek value for. - \param defVal Value to return if var does not exist within section. - \return Contents of the variable in integer format. - **/ int GetInt(std::string section, std::string var, int defVal) const; - - /*! - \brief Get value in boolean format from file. - - Get the current value of a variable in the file, or defVal if not found in file. - (Valid values are "0","1","true" and "false") - \param section Name of section to seek variable under. - \param var Name of variable to seek value for. - \param defVal Value to return if var does not exist within section. - \return Contents of the variable in boolean format. - **/ bool GetBool(std::string section, std::string var, bool defVal) const; - - /*! - \brief Get value in std::string format from file. - - Get the current value of a variable in the file, or defVal if not found in file. - \param section Name of section to seek variable under. - \param var Name of variable to seek value for. - \param defVal Value to return if var does not exist within section. - \return Contents of the variable in std::string format. - **/ std::string GetString(std::string section, std::string var, std::string defVal) const; - - /*! - \brief Set value in floating point format in file. - - Set the new value of a variable in the file to val, creating the section and variable - if not already found in file. - \since 0.8.3 - \param section Name of section to edit variable under. - \param var Name of variable to set value for. - \param val Floating point value to set variable to in file. - **/ + void SetFloat(std::string section, std::string var, float val); - - /*! - \brief Set value in integer format in file. - - Set the new value of a variable in the file to val, creating the section and variable - if not already found in file. - \param section Name of section to edit variable under. - \param var Name of variable to set value for. - \param val Integer value to set variable to in file. - **/ void SetInt(std::string section, std::string var, int val); - - /*! - \brief Set value in boolean format in file. - - Set the new value of a variable in the file to val, creating the section and variable - if not already found in file. - \param section Name of section to edit variable under. - \param var Name of variable to set value for. - \param val Boolean value to set variable to in file. - **/ void SetBool(std::string section, std::string var, bool val); - - /*! - \brief Set value in std::string format in file. - - Set the new value of a variable in the file to val, creating the section and variable - if not already found in file. - \param section Name of section to edit variable under. - \param var Name of variable to set value for. - \param val String value to set variable to in file. - **/ void SetString(std::string section, std::string var, std::string val); - /*! - \brief Write all values to file - - Writes all values and sections to file. - **/ void Flush(); - - /*! - \brief Close the file. - - Flush the file and clear the filename. - **/ void Close(); }; diff --git a/include/ZE_ZEngine.h b/include/ZE_ZEngine.h index 7adb3aa..67fca88 100644 --- a/include/ZE_ZEngine.h +++ b/include/ZE_ZEngine.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZEngine.h - \brief Definition file for core ZEngine class. - - ZEngine Game Engine core Engine definition. -
$Id: ZE_ZEngine.h,v 1.57 2003/12/24 04:46:48 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zengine_h__ #define __ze_zengine_h__ @@ -26,11 +17,6 @@ #include "ZE_ZRandGen.h" #include "VersionInfo.h" -/*! - \brief ZEngine Namespace. - - Namespace for ZEngine classes and utility functions. -**/ namespace ZE { @@ -53,630 +39,118 @@ enum ZErrorLogStyle ZLOG_HTML }; - -/*! - \brief Main ZEngine Singleton Class - - ZEngine Singleton Class, accessible from anywhere in a ZEngine-based program by nature. Controls core elements of program and does - majority of SDL and OpenGL wrapping. -**/ class ZEngine { public: - //! Static version information. static VersionInfo Version; private: - //! Static Pointer to Instance of ZEngine for Singleton. static ZEngine *sInstance; - //! Pointer to Display SDL_Surface *mScreen; - //! Fullscreen setting of Display bool mFullscreen; - //! If ZEngine display has been setup. bool mInitialized; - //! Keep track of paused state of game. bool mPaused; - //! Keep track of if ZEngine should unpause on active event. bool mUnpauseOnActive; - -#ifdef DEPRECIATED - Uint8 mDesiredFramerate; -#endif //DEPRECIATED - - //! Time scheduled for next update (used for framerate locked movement). Uint32 mNextUpdate; - //! Keep track of time game was last paused. Uint32 mLastPause; - //! Keep track of total globally paused time. Uint32 mPausedTime; - //! Keep track of last screen update time. Uint32 mLastTime; - //! Seconds per frame. (1/FPS) double mSecPerFrame; - //! Keeps track of when engine thinks the images need to be reloaded (loss of focus in fullscreen). bool mNeedReload; - //! bool describing Active or Inactive State of Game bool mActive; - //! bool for checking if a Quit event has been detected bool mQuit; - //! Pointer to array of Keys Uint8 *mKeyIsPressed; - //! Array of keys, used by KeyPress bool mKeyPress[SDLK_LAST]; - //! X Position of Mouse int mMouseX; - //! Y Position of Mouse int mMouseY; - //! Mouse Button Information Uint8 mMouseB; - //! Error log style. ZErrorLogStyle mLogStyle; - //! C-style FILE* for error logging. std::FILE *mErrlog; - //! 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 bool mSoundInitialized; - //! Sound Bitrate int mSoundRate; - //! Stereo setting of Sound Subsystem bool mStereo; #endif - ///////////////////////////////// - //Singleton + Memory Management// - ///////////////////////////////// - - /*! - \brief Constructor for ZEngine. - - Initialize ZEngine values to defaults. (Private so that only one instance may be created.) - **/ ZEngine(); - ////////////////////// - //Resource Internals// - ////////////////////// - TiXmlElement* FindElement(std::string type, std::string id); public: - - /*! - \brief Get Instance. - - Static function, returns pointer to instance of ZEngine, creating an instance if none exist. - \return Instance to the ZEngine. - **/ static ZEngine* GetInstance(); - - /*! - \brief Release Instance. - - Release memory held by instance of engine and closes window. - **/ static void ReleaseInstance(); - ////////////////// - //Initialization// - ////////////////// - - /*! - \brief Create Display (window or fullscreen). - - Create a window or fullscreen display given the screen options, a title, icon, - - \param width Desired width of screen or window. - \param height Desired height of screen or window. - \param bpp Desired BPP for screen, generally use 8,16 or 32, pass -1 if you want ZEngine to guess the best choice. - \param fullscreen A bool for fullscreen setting. - \param soundRate Desired sound bitrate. - \param stereo A bool for stereo setting. - \param title Window Title. - \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="ZEngine Application", int soundRate=22050, bool stereo=false, std::string icon=""); - - /*! - \brief Quit SDL and any Subsystems. - - Shut down SDL (and SDL_ttf,SDL_mixer if necessary) You shouldn't ever have to call this, ReleaseInstance calls this for you. - **/ void CloseDisplay(); - - /*! - \brief Toggle fullscreen/windowed mode. - - Safely toggles fullscreen/windowed mode, generally toggling modes will bring the need to reload images so it will - set the ImagesNeedReload state to true. - \since 0.8.2 - **/ void ToggleFullscreen(); - /*! - \brief Check state of ZEngine. - - Checks if ZEngine display has been properly setup. - \since 0.8.2 - \return Boolean status of ZEngine, true if CreateDisplay has been successfully called, false if ZEngine has no display. - **/ - bool Initialized(); - - ///////////////// - //Screen Access// - ///////////////// - - /*! - \brief Allow access to Screen Surface. - - Get pointer to screen SDL_Surface, allowing direct screen manipulation using SDL. - \return Pointer to Display Surface. - **/ - SDL_Surface *Display(); - - /*! - \brief Update display contents. - - Swap OpenGL buffers, and update screen, if a desired framerate is set it will delay to stay under that rate. - Must be called every frame. - **/ + SDL_Surface* Display(); void Update(); - - /*! - \brief Clear screen to a certain color (Black by default). - - Clears a rectangle on screen to a color, defaults to solid black. - \param red Red component (0-255) of new color. - \param green Green component (0-255) of new color. - \param blue Blue component (0-255) of new color. - \param alpha Alpha component (0-255) of new color. - **/ void Clear(Uint8 red=0, Uint8 green=0, Uint8 blue=0, Uint8 alpha=255); -#if (GFX_BACKEND == ZE_OGL) - ///////////////////////////// - //OpenGL Specific Functions// - ///////////////////////////// - - /*! - \brief Setup OpenGL ortho mode. - - Sets the OpenGL scaled orthographic mode, called once at beginning, no need to call - unless you change the OpenGL mode manually. - **/ +#if (GFX_BACKEND == ZE_OGL) void SetGL2D(); #endif //GFX_BACKEND - //////////////////////////////////////////// - //Timer and Framerate Independent Movement// - //////////////////////////////////////////// - - /*! - \brief Sleep for a certain amount of time. - - Freeze everything for given number of milliseconds. - \param milliseconds Number of milliseconds to freeze. - **/ void Delay(Uint32 milliseconds); - - /*! - \brief Get Global ZEngine time. - - Get active time since ZEngine initialization in milliseconds, paused time doesn't count. - \return Number of active milliseconds since initialization. - **/ Uint32 GetTime(); - - /*! - \brief Pause ZEngine. - - Pause ZEngine timer and all ZTimer objects that rely on ZEngine. - **/ void PauseTimer(); - - /*! - \brief Unpause ZEngine. - - Unpause ZEngine timer and all ZTimer objects that rely on ZEngine. - **/ void UnpauseTimer(); + bool TimerIsPaused(); - /*! - \brief Get Seconds Per Frame. - - Get double that describes the time passed between screen updates. (should be used for Framerate Independant Movement) - \return Time between screen updates. - **/ double GetFrameTime(); - - /*! - \brief Get Frames Per Second. - - Get double representing current (approximate) FPS. This value is always the same as 1/GetFrameTime(). - \since 0.8.2 - \return Current Framerate. - **/ double GetFramerate(); - -#ifdef DEPRECIATED - void SetDesiredFramerate(Uint8 rate); - Uint8 GetDesiredFramerate(); -#endif //DEPRECIATED - - /*! - \brief Check Engine Paused State. - - Find out if engine timer is paused. - \return Paused State of engine. - **/ - bool IsPaused(); - - //////////////////////////// - //Event and Input Handling// - //////////////////////////// - - /*! - \brief Find out if application is active. - - Function to find out if application currently has focus. - \return bool telling active/inactive state of application. - **/ + bool IsActive(); - /*! - \brief Request A Quit. - - Tell the engine that it should behave as if a Quit was requested, does not call - any shutdown functions. - **/ void RequestQuit(); - - /*! - \brief Find out if user has requested to quit. - - Function to find out if user or operating system has requested program cease execution, can be - set by Alt-F4, SDL_Quit event or ZEngine::RequestQuit(). - \return bool telling if quit has been requested. - **/ bool QuitRequested(); - - /*! - \brief Set State of ImagesNeedReload. - \param state False if images need to be reloaded, True if images have been reloaded. - **/ - void SetReloadNeed(bool state); - - /*! - \brief Find out if images should be reloaded. - - Function that is good to call every frame to check if images should be reloaded, usually only caused by loss of focus in - fullscreen. - \return bool, True if images should be reloaded, false otherwise. - **/ - bool ImagesNeedReload(); - /*! - \brief Set Key repeat rate. + void SetReloadNeed(bool state); + bool ImagesNeedReload(); - Calls SDL_EnableKeyRepeat(rate,rate) because usually this is the desired movement style for games. 0 to disable. - If 2 different values are needed SDL_EnableKeyRepeat can be called separately: http://sdldoc.csn.ul.ie/sdlenablekeyrepeat.php. - - \param rate Desired key repeat rate. - **/ void SetKeyRepeatRate(int rate); - - /*! - \brief Find the state of a key. - - Function returns true/false based on if key is currently pressed or not. - This is used when using keys as buttons, and you need to check if the button/key - is currently pressed (ex. arrow keys). - \param key Code of key to find status of. - \return State of requested key. - **/ bool KeyIsPressed(SDLKey key); - - /*! - \brief Find if key has been pressed since last check. - - Function returns true/false based on if key has been pressed since last check. - This is what is good to use if you are trying to get user input where a key is only - counted once per press. (ex. typing in a name for a high scores list) - \param key Code of key to find status of. - \return State of requested key. - **/ bool KeyPress(SDLKey key); - - /*! - \brief Hide mouse cursor. - - Hide the system mouse cursor. - **/ void HideCursor(); - - /*! - \brief Show mouse cursor. - - Show the system mouse cursor. - **/ void ShowCursor(); - - /*! - \brief Get X Position of Mouse. - - Find X Position of Mouse on screen. - \return X Position of Mouse. - **/ int MouseX(); - - /*! - \brief Get Y Position of Mouse. - - Find Y Position of Mouse on screen. - \return Y Position of Mouse. - **/ int MouseY(); - - /*! - \brief Get Status of Left Button. - - Get pressed status of left button of mouse. - \return true if left button is pressed, false otherwise. - **/ bool LButtonPressed(); - - /*! - \brief Get Status of Right Button. - - Get pressed status of right button of mouse. - \return true if right button is pressed, false otherwise. - **/ bool RButtonPressed(); - - /*! - \brief Get status of Middle Button. - - Get pressed status of middle button if available. - \return true if middle button is pressed, false if it is not or if it does not exist. - \since 0.8.5 - **/ bool MButtonPressed(); - - /*! - \brief Check if mouse is in given rectangle. - - Return status of mouse in current rectangle (eg. GUI buttons). - \param rect Rectangle to check if mouse is in. - \return true if mouse is in rectangle, false otherwise - **/ bool MouseInRect(const SDL_Rect &rect); - - /*! - \brief Check if mouse is in given rectangle. - - Return status of mouse in current rectangle (eg. GUI buttons). - \param rect Rectangle to check if mouse is in. - \return true if mouse is in rectangle, false otherwise - **/ - bool MouseInRect(ZRect rect); - - /*! - \brief Check for Activation, Window Manager, and Quit Events. - - Cycle through event queue, processing events, updating all Event Related variables, should be called once per frame. - **/ + bool MouseInRect(const ZRect &rect); void CheckEvents(); - - /*! - \brief Add a SDL Event Filter for user processing of events. - - This is only needed when you need tight control with ZEngine. The parameter processed as if it were passed to - SDL_SetEventFilter, generally only those with a good amount of SDL experience should use this function or - ZEngine's internal message state could be corrupted. For more information on SDL_SetEventFilter see - http://sdldoc.csn.ul.ie/sdlseteventfilter.php. (FYI: The parameter is now actually processed in check events, - not passed to the SDL function, this is done because of problems with singletons and event threading.) - \since 0.8.2 - \param filter An SDL_EventFilter (A function that takes a const SDL_Event* and returns 0 if the event should be removed from - the event queue and 1 otherwise.) - **/ void SetEventFilter(SDL_EventFilter filter); - - ///////////////// - //Error Logging// - ///////////////// - - public: - /*! - \brief Modify Error Logging. - - Change the way errors are logged and the file they are logged to, before calling this errors are logged to stderr. - (SDL may define stderr.txt on some platforms.) - \since 0.8.6 - \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(ZErrorLogStyle logStyle, std::string logFile); - - void DisableErrorLog(); - - - /*! - \brief Report an error. - - Adds the error to the the error queue, and sets the current error to this error. - \since 0.8.2 - **/ - void ReportError(ZErrorSeverity type, std::string desc="", ...); - - /*! - \brief Write to the log. - - Write a std::string to the log, allowing special usage of the error log. - \since 0.8.2 - \param str String to write to log file. - **/ + void ReportError(ZErrorSeverity type, std::string desc="", ...); void WriteLog(std::string str, ...); - //////////////////////////// - //Random Number Generation// - //////////////////////////// - /*! - \brief Seed random number generator. - - Reseed Mersenne Twister random number generator. NOTE: Generator is initialized upon creation of object using time. - \param seed Seed for random sequence. - **/ void SeedRandGen(unsigned long seed); - - /*! - \brief Obtain random integer [0,max). - - Obtain random int l where 0 <= l < max. - \param max Limit for random number. - \return Random unsigned int. - **/ unsigned int Rand(unsigned int max); - - /*! - \brief Obtain random integer [0,max). - - Obtain random long l where 0 <= l < max. - \param max Limit for random number. - \return Random unsigned long. - **/ unsigned long Rand(unsigned long max); - - /*! - \brief Obtain random integer [min,max]. - - Obtain random int l where min <= l <= max. - \param min Lower limit for random number. - \param max Upper limit for random number. - \return Random int. - **/ int Rand(int min, int max); - - /*! - \brief Obtain random integer [min,max]. - - Obtain random long l where min <= l <= max. - \param min Lower limit for random number. - \param max Upper limit for random number. - \return Random long. - **/ long Rand(long min, long max); - - /*! - \brief Obtain random integer [min,max]. - - Obtain random float l where min <= l <= max. - \param min Lower limit for random number. - \param max Upper limit for random number. - \return Random float. - **/ float Rand(float min, float max); - - /*! - \brief Obtain random integer [min,max]. - - Obtain random double l where min <= l <= max. - \param min Lower limit for random number. - \param max Upper limit for random number. - \return Random double. - **/ - double Rand(double min, double max); - - /*! - \brief Obtain random double [0,1). - - Obtain random double d where 0 <= d < 1. - \return Random double [0,1). - **/ + double Rand(double min, double max); 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. - **/ + int GetIntResource(std::string type, std::string id, std::string element); double GetDoubleResource(std::string type, std::string id, std::string element); - - ///////////// - //Accessors// - ///////////// - - /*! - \brief Get current display width. - - Get Width of Window or Fullscreen mode. - \return Width of display. - **/ + bool DisplayCreated(); int DisplayWidth(); - - /*! - \brief Get current display height. - - Get height of window or fullscreen mode. - \return Height of display. - **/ int DisplayHeight(); - - /*! - \brief Get current display depth. - - Get color depth of window or fullscreen mode. - \return Color depth (bpp) of display. - **/ int DisplayDepth(); - -#ifdef DEPRECIATED - int Width(); - int Height(); - int BPP(); -#endif //DEPRECIATED - - /*! - \brief Get Fullscreen setting. - - Get Fullscreen setting of Display. - \return True if Fullscreen, False if Windowed - **/ bool IsFullscreen(); }; diff --git a/include/ZE_ZFont.h b/include/ZE_ZFont.h index f6fbc05..b58099e 100644 --- a/include/ZE_ZFont.h +++ b/include/ZE_ZFont.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZFont.h - \brief Definition file for ZFont. - - Definition file for ZFont, the basic Font class for ZEngine. -
$Id: ZE_ZFont.h,v 1.17 2003/12/24 04:46:48 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zfont_h__ #define __ze_zfont_h__ @@ -28,219 +19,42 @@ namespace ZE { -/*! - \brief ZFont class for basic Font use. - - ZFont font container class, class wraps common features of SDL_TTF. -**/ class ZFont { protected: - //! Pointer to ZEngine Object ZEngine* rEngine; - //! Pointer to font data. TTF_Font *rFont; - //! Filename, for resizing. std::string rFilename; - //! Zip filename, for resizing when file was from archive. std::string rZipname; - //! SDL_Color for current text color. SDL_Color rColor; - //! SDL_Color for background color to be used in shaded draws. SDL_Color rBGColor; public: - - /////////////////////// - //Opening and Closing// - /////////////////////// - - /*! - \brief Default Constructor. - - Default Constructor, does nothing. - **/ ZFont(); - - /*! - \brief Constructor that opens a font with a certain size. - - Constructor simply calls ZFont::Open() with same parameters. - \param filename Font to open. - \param size Size to use for font. - **/ ZFont(std::string filename, int size); - - /*! - \brief Destructor, frees memory. - - Destructor calls ZFont::Release(). - **/ virtual ~ZFont(); - /*! - \brief Opens a font with a certain size. - - Opens a font given a filename and a point size. - \param filename Font to open. - \param size Size to use for font. - **/ void Open(std::string filename, int size); - - /*! - \brief Opens a font from within a zip archive. - - Open a font from within a zip archive using zlib and SDL_RWops. - \param zipname Zip file to open image from. - \param filename File to open as new image. - \param size Size to use for font. - **/ 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. - - Release memory held by font. (Called by destructor). - **/ void Release(); - //////////////////////// - //Settings and Drawing// - //////////////////////// - - /*! - \brief Draws a std::string in a color to a ZImage. - - Draw to a surface in specified color and associate that surface with a ZImage. - \param text String to write. - \param image ZImage to draw to. - **/ void DrawText(std::string text, ZImage &image) const; - - /*! - \brief Draws a std::string with a colored background to a ZImage. - - Draw to a surface a std::string with a background of rBGColor and lettering in the normal color and associate that surface with a ZImage. - \param text String to write. - \param image ZImage to draw to. - **/ void DrawShadedText(std::string text, ZImage &image) const; - - /*! - \brief Set Text rColor. - - Set rColor of Text Output. - \param r Red component of color (0-255). - \param g Green component of color (0-255). - \param b Blue component of color (0-255). - \param a Alpha component of drawn font, including background if present. (0-255) (Optional, defaults to 255.) - **/ void SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a=255); - - /*! - \brief Set Background rColor. - - Set rColor of Background for Shaded Draw. - \param r Red component of color (0-255). - \param g Green component of color (0-255). - \param b Blue component of color (0-255). - **/ void SetBGColor(Uint8 r, Uint8 g, Uint8 b); - - /*! - \brief Set display format. - - Set display format (bold, italic, underline). - \param bold Decides bold setting of font. - \param italic Decides italic setting of font. - \param underline Decides underline setting of font. - **/ - void SetStyle(bool bold, bool italic, bool underline); - - /*! - \brief Resize Font. - - Release and Reopen font in new size. - \param size New size for font. - **/ + void SetStyle(bool bold, bool italic, bool underline); void Resize(int size); - ///////////// - //Accessors// - ///////////// - - /*! - \brief Check if file is loaded. - - Check if file is loaded and pointer to data is non-NULL. - \return Loaded or Unloaded state of data. - **/ bool IsLoaded() const; - - /*! - \brief Get Bold Setting. - - Check if font output is currently bold. - \return True or False state of bold. - **/ bool IsBold() const; - - /*! - \brief Get Italic Setting. - - Check if font output is currently italic. - \return True or False state of italic. - **/ bool IsItalic() const; - - /*! - \brief Get Underlined Setting. - - Check if font output is currently underline. - \return True or False state of underline. - **/ bool IsUnderlined() const; - - /*! - \brief Get Height of Font. - - Check font height as reported by SDL_ttf. - \return Height of font. - **/ - int Height() const; - - /*! - \brief Get Line Skip for Font. - - Check font line skip as reported by SDL_ttf. - \return Recommended Line Skip of font. - **/ - int LineSkip() const; - - /*! - \brief Get String Width. - - Get Width of String in Current Font in Pixels. - \param text String to get width of. - \return Width of String in Current font. - **/ - int StringWidth(std::string text) const; - - /*! - \brief Get String Height. - - Get Height of String in Current Font in Pixels. - \param text String to get height of. - \return Height of String in Current font. - **/ - int StringHeight(std::string text) const; + int GetHeight() const; + int GetLineSkip() const; + int CalcStringWidth(std::string text) const; + int CalcStringHeight(std::string text) const; }; } diff --git a/include/ZE_ZImage.h b/include/ZE_ZImage.h index 0d84c17..d3ab506 100644 --- a/include/ZE_ZImage.h +++ b/include/ZE_ZImage.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZImage.h - \brief Definition file for ZImage. - - Definition file for ZImage, the ZImage class for ZEngine. -
$Id: ZE_ZImage.h,v 1.30 2003/12/24 04:46:48 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zimage_h__ #define __ze_zimage_h__ @@ -26,435 +17,71 @@ namespace ZE { -/*! - \brief ZImage class for basic Image use. - - ZImage image drawing class, class wraps 2d textures under OpenGL or SDL_Surface under SDL. -**/ class ZImage { protected: - //! Pointer to ZEngine Object ZEngine* rEngine; - //! Stored texture. SDL_Surface *rImage; - //! Stored alpha value for drawing texture. Uint8 rAlpha; #if (GFX_BACKEND == ZE_OGL) - //! Texture lower X, used internally for flip. GLfloat rTexMinX; - //! Texture lower Y, used internally for flip GLfloat rTexMinY; - //! Texture X width ratio, used internally by OpenGL. GLfloat rTexMaxX; - //! Texture Y width ratio, used internally by OpenGL. GLfloat rTexMaxY; - //! Texture ID for OpenGL. unsigned int rTexID; - //! Current draw width of Texture. GLfloat rWidth; - //! Current draw height of Texture. GLfloat rHeight; - - /*! - \brief Rounds a number up to the nearest power of two. - - Rounds a number up to the next highest power of two, used for OpenGL textures. (From testgl.c) - Used internally, generally shouldn't be called by users. - \param in Number to round up. - \return num rounded up to closest power of two. - \since 0.8.6 - **/ - int PowerOfTwo(int num) const; - - /*! - \brief Converts an SDL_Surface to an OpenGL texture ID. - - Given an SDL_Surface returns a texture ID representing the OpenGL - texture assigned to that surface. Also returns texture coordinates - via texcoord parameter. (From SDL_GL_LoadTexture in testgl.c) - Used internally, generally shouldn't be called by users. - \param surface SDL_Surface to assign an OpenGL ID, returns unmodified. - \param texcoord Should be an array of 4 GLfloat, assigned texture coordinates for OpenGL use. - \return OpenGL texture ID for SDL_Surface, 0 if an error occurs. - \since 0.8.6 - **/ - GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord) const; #endif //GFX_BACKEND == OGL public: - - /*! - \brief Default Constructor. - - Default Constructor, initializes variables. - **/ ZImage(); - - /*! - \brief Copy constructor for ZImage. - - Creates one ZImage using another. - \param rhs A previously created ZImage to copy. - **/ ZImage(const ZImage &rhs); - - /*! - \brief Constructor to Construct from File. - - Constructor is same as calling ZImage::Open() on passed filename. - \param filename File to open as rImage. - **/ ZImage(std::string filename); - - /*! - \brief Constructor to Construct from part of an SDL_Surface*. - - Constructor is same as calling ZImage::OpenFromImage with an SDL_Surface*. - - \param img Image to take new image from. - \param x X Coordinate in source of top left corner. - \param y Y Coordinate in source of top left corner. - \param w Width of new image. - \param h Height of new image. - **/ ZImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); - - /*! - \brief Constructor to Construct from part of another ZImage. - - Constructor is same as calling ZImage::OpenFromImage with a ZImage. - - \param img Image to take new image from. - \param x X Coordinate in source of top left corner. - \param y Y Coordinate in source of top left corner. - \param w Width of new image. - \param h Height of new image. - **/ 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. - - Destructor calls ZImage::Release(). - **/ virtual ~ZImage(); - /////////////////////// - //Opening and Closing// - /////////////////////// - - /*! - \brief Opens a file. - - Open an image file using ZEngine. - \param filename File to open as new image. - **/ void Open(std::string filename); - - /*! - \brief Opens an image file from within a zip archive. - - Open an image file from within a zip archive using zlib and SDL_RWops. - \param zipname Zip file to open image from. - \param filename File to open as new image. - **/ 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. - - Cut part of an SDL_Surface to create a new Image. - - \param img SDL_Surface* to take new image from. - \param x X Coordinate in source of top left corner. - \param y Y Coordinate in source of top left corner. - \param w Width of new image. - \param h Height of new image. - **/ void OpenFromImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); - - /*! - \brief Cuts part of an existing ZImage to create a new image. - - Cut part of another ZImage to create a new Image. - - \param img ZImage to take new image from. - \param x X Coordinate in source of top left corner. - \param y Y Coordinate in source of top left corner. - \param w Width of new image. - \param h Height of new image. - **/ void OpenFromImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); - /*! - \brief Attach an existing surface to class. - - Attach a pointer to instance of ZImage. (NOTE: Should not be used on a surface that is owned elsewhere.) - \param surface SDL_Surface* to use as rImage. - **/ void Attach(SDL_Surface *surface); - - /*! - \brief Reattach a preloaded texture that has been lost. - - Attach loaded textures which have been lost due to loss of focus, should be called when ZEngine::ImagesNeedReload is true. - **/ void Reload(); - - /*! - \brief Releases image. - - Frees memory for the image. (Called by destructor). - **/ void Release(); - //////////// - //Graphics// - //////////// - - /*! - \brief Set alpha value (translucency) of image. - - Set translucency value 0-255 (0 is transparent, 255 = opaque). - \since 0.8.2 - \param alpha Number 0-255 setting translucency for image. - **/ void SetAlpha(Uint8 alpha); - - /*! - \brief Set Color Key (transparent color) of image. - - Set color which will not be drawn in image. - \param red Red component of colorkey (0-255). - \param green Green component of colorkey (0-255). - \param blue Blue component of colorkey (0-255). - **/ void SetColorKey(Uint8 red, Uint8 green, Uint8 blue); - - /*! - \brief Draw Image to Screen. - - Draw Image to screen at specified location. - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - **/ void Draw(int x, int y) const; - - /*! - \brief Draw Image, clipped within a given rectangle to the screen. - - Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle - can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a - map on a HUD. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param clipRect Rectangle to clip within. - **/ void DrawClipped(int x, int y, ZRect clipRect) const; #if (GFX_BACKEND == ZE_OGL) - /*! - \brief Draw Image to Screen. - - Draw Image to screen at specified location. - \since 0.8.3 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - **/ void Draw(float x, float y) const; - - /*! - \brief Draw Image to screen with shaded/colored vertices. - - Draw Image to screen using OpenGL to shade and color vertices. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. - Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) - of top left corner (after top-left corner goes around clockwise). - **/ void Draw(float x, float y, Uint8 vc[]) const; - - /*! - \brief Draw Image rotated to screen. - - Image is rotated about it's own center by specified angle, then drawn to screen. - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param angle Angle in degrees to rotate image. - **/ void DrawRotated(int x, int y, float angle) const; - - /*! - \brief Draw Image rotated to screen. - - Image is rotated about it's own center by specified angle, then drawn to screen. - \since 0.8.3 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param angle Angle in degrees to rotate image. - **/ void DrawRotated(float x, float y, float angle) const; - - /*! - \brief Draw Image rotated to screen with shaded/colored vertices. - - Image is rotated about it's own center by specified angle, then drawn to screen with shaded or colored vertices. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param angle Angle in degrees to rotate image. - \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. - Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) - of top left corner (after top-left corner goes around clockwise). - **/ void DrawRotated(float x, float y, float angle, Uint8 vc[]) const; - - /*! - \brief Draw Image, clipped within a given rectangle to the screen. - - Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle - can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a - map on a HUD. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param clipRect Rectangle to clip within. - **/ void DrawClipped(float x, float y, ZRect clipRect) const; - - /*! - \brief Draw Image, clipped within a given rectangle to the screen with colored/shaded vertices. - - Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle - can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a - map on a HUD. Image is drawn with colored/shaded vertices. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param clipRect Rectangle to clip within. - \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. - Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) - of top left corner (after top-left corner goes around clockwise). - **/ void DrawClipped(float x, float y, ZRect clipRect, Uint8 vc[]) const; - - /*! - \brief Flip image over one or both axes. - - Flip image vertical and/or horizontal. - \param horizontal Boolean, true will flip image horizontally. - \param vertical Boolean, true will flip image vertically. - **/ void Flip(bool horizontal, bool vertical); - - /*! - \brief Stretch the image by a certain X and Y factor. - - Stretch image using a factor to multiply width and height by. - \param xFactor Stretch factor for width. [newWidth = oldWidth * xStretch] - \param yFactor Stretch factor for height. [newHeight = oldHeight * yStretch] - **/ void Stretch(float xFactor, float yFactor); - - /*! - \brief Resizes an image, stretching to new size. - - Stretch image to new width and height. - \param width New width to stretch image to. - \param height New height to stretch image to. - **/ void Resize(float width, float height); - - /*! - \brief OpenGL related bind call. - - OpenGL related bind call, only available in case you want to bind image in 3D. - Draw uses this but the average user should never need to call this. - **/ void Bind() const; #endif //GFX_BACKEND == OGL - ///////////// - //Accessors// - ///////////// - - /*! - \brief Check if file is loaded. - - Check if surface is a valid GL texture. (does not detect surface loss) - \return Loaded or Unloaded state of data. - **/ bool IsLoaded() const; - - /*! - \brief Get SDL_Surface. - Get SDL_Surface pointer to actual image data. - \return SDL_Surface* of rImage. - **/ SDL_Surface *Surface() const; #if (GFX_BACKEND == ZE_OGL) - - /*! - \brief Get Width. - - Get Current Width of Image. - \return Image Width. - **/ float Width() const; - - /*! - \brief Get Height. - - Get Current Height of Image. - \return Image Height. - **/ float Height() const; - #elif (GFX_BACKEND == ZE_SDL) - /*! - \brief Get Width. - - Get Current Width of Image. - \return Image Width. - **/ int Width() const; - - /*! - \brief Get Height. - - Get Current Height of Image. - \return Image Height. - **/ int Height() const; #endif //GFX_BACKEND - /*! - \brief Get Alpha component. - - Get current alpha value of image. - \since 0.8.2 - \return Image Alpha. - **/ Uint8 Alpha() const; }; diff --git a/include/ZE_ZMusic.h b/include/ZE_ZMusic.h index ffe3f20..8223652 100644 --- a/include/ZE_ZMusic.h +++ b/include/ZE_ZMusic.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZMusic.h - \brief Definition file for ZMusic. - - Definition file for ZMusic, the Music file wrapper for ZEngine. -
$Id: ZE_ZMusic.h,v 1.11 2003/12/24 04:46:48 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zmusic_h__ #define __ze_zmusic_h__ @@ -26,161 +17,35 @@ namespace ZE { - -/*! - \brief ZMusic class for playing full length music (eg. ogg or wav). - - ZMusic music class, class wraps common features for SDL_Mixer's Mix_Music. Inherited from ZObject. -**/ class ZMusic { protected: - //! Pointer to ZEngine Object ZEngine* rEngine; - //! Pointer to music data. Mix_Music *rMusic; - public: - //! Static Variable For Infinite loop of sound. (Defined as -1) static const int LoopInfinite; - - /////////////////////// - //Opening and Closing// - /////////////////////// - - /*! - \brief Default Constructor. - - Default Constructor, does nothing. - **/ + ZMusic(); - - /*! - \brief Constructor that opens a music file. - - Constructor simply calls ZMusic::Open() with same filename. (WAV,MOD,MID,OGG) - \param filename Music to open. - **/ ZMusic(std::string filename); - - /*! - \brief Destructor, frees memory. - - Destructor calls ZMusic::Release(). - **/ virtual ~ZMusic(); - - /*! - \brief Opens a music file. - - Open a music file to be used. - \param filename Music to open. - **/ + 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. - - Release memory held by music data. - **/ + void Release(); - - ///////////////// - //Play Controls// - ///////////////// - - /*! - \brief Play currently loaded music. - - Play music currently loaded in ZMusic, looping loopNum times. (use ZMusic::LoopInfinite to loop forever.) - If fade is not zero (which it defaults to) music will fade in over specified number of milliseconds. - \param loopNum Number of times to loop song, defaults to zero. - \param fadeTime Milliseconds to fade to full volume, defaults to zero for no fade. - **/ void Play(int loopNum=0, int fadeTime=0) const; - - /*! - \brief Pause music. - - Pause currently playing music. - **/ void Pause() const; - - /*! - \brief Unpause music. - - Unpause currently paused music. - **/ void Unpause() const; - - /*! - \brief Rewind music. - - Rewind music to beginning. - **/ void Rewind() const; - - /*! - \brief Stop music. - - Stop currently playing music, if fadeTime is not zero, fade out over specified time. - \param fadeTime Milliseconds to fade out over, defaults to zero for immediate stop. - **/ void Stop(int fadeTime=0) const; - - /*! - \brief Change Volume. - - Change volume of currently playing music. - \param volume Volume to change to, can be in a range from 0 to 128 - **/ void SetVolume(int volume); - ///////////// - //Accessors// - ///////////// - - /*! - \brief Check if file is loaded. - - Check if file is loaded and pointer to data is non-NULL. - \return Loaded or Unloaded state of data. - **/ bool IsLoaded() const; - - /*! - \brief Check if music is Playing. - - Check if music is playing, specifically if it is not stopped. (Paused state should be checked for by IsPaused) - \return Playing / Not Playing State of Music. - **/ bool IsPlaying() const; - - /*! - \brief Check if music is Paused. - - Check if music is "playing" but currently paused. - \return Paused / Not Paused State of Music. - **/ bool IsPaused() const; - - /*! - \brief Find Current Volume of Music. - - Get current volume of music represented as a value from 0-128. - \return Volume of music, 0-128. - **/ - int Volume() const; + int GetVolume() const; }; - } #endif //USE_SDL_MIXER diff --git a/include/ZE_ZRandGen.h b/include/ZE_ZRandGen.h index 9800414..d21ff92 100755 --- a/include/ZE_ZRandGen.h +++ b/include/ZE_ZRandGen.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,152 +8,40 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZRandGen.h - \brief Definition file for ZRandGen. - - Definition file for ZRandGen, an OO encapsulated version of the Mersenne Twister. - This class usually isn't needed by the average user, ZEngine contains an instance which - should suffice unless you want objects to have their ownrandom streams. This - implementation is derived from the original mt19937ar.c source from - http://www.math.keio.ac.jp/matumoto/emt.html. See source of ZE_ZRandGen.cpp for license. -
$Id: ZE_ZRandGen.h,v 1.2 2003/07/12 01:25:42 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zrandgen_h__ #define __ze_zrandgen_h__ #include "ZE_Utility.h" -#include namespace ZE { -/*! - \brief ZRandGen class for OO encapsulation of superb random generator "Mersenne Twister." - - This class usually isn't needed by the average user, ZEngine contains an instance which - should suffice unless you want objects to have their ownrandom streams. This - implementation is derived from the original mt19937ar.c source from - http://www.math.keio.ac.jp/matumoto/emt.html. See source of ZE_ZRandGen.cpp for license. - \since 0.8.4 -**/ class ZRandGen { protected: - //! Number of random numbers to generate at once. static const unsigned long N = 624; - //! A constant used internally by Mersenne Twister. static const unsigned long M = 397; - //! Constant vector A, used internally by Mersenne Twister. static const unsigned long MATRIX_A = 0x9908b0dfUL; - //! Most signifigan w-r bits, used internally by Mersenne Twister. static const unsigned long UPPER_MASK = 0x80000000UL; - //! Least signifigant r bits, used internally by Mersenne Twister. static const unsigned long LOWER_MASK = 0x7fffffffUL; - //! Each instance of the algorithm requires a state vector. unsigned long rStateVector[N]; - //! Used internally to traversing the rStateVector. unsigned long rStateVectorIndex; - /*! - \brief Workhorse of random generator, only used internally. - - Generates N random numbers and then serves them up, all Rand functions rely - on this. - \return A random unsigned long. - **/ unsigned long genrand_int32(); public: - /*! - \brief Constructor which does an initial seeding using time. - - Creates internal vector and calls Seed(time(NULL)) to initialize the MT state. - **/ ZRandGen(); - - /*! - \brief Constructor which does an initial seeding. - - Creates internal vector and calls seed to initialize the MT state. - **/ ZRandGen(unsigned long seed); - /*! - \brief Seed random number generator. - - Reseed Mersenne Twister random number generator. NOTE: Generator is initialized upon creation of object using time. - \param seed Seed for random sequence. - **/ void Seed(unsigned long seed); - /*! - \brief Obtain random integer [0,max). - - Obtain random int l where 0 <= l < max. - \param max Limit for random number. - \return Random unsigned int. - **/ unsigned int Rand(unsigned int max); - - /*! - \brief Obtain random integer [0,max). - - Obtain random long l where 0 <= l < max. - \param max Limit for random number. - \return Random unsigned long. - **/ unsigned long Rand(unsigned long max); - - /*! - \brief Obtain random integer [min,max]. - - Obtain random int l where min <= l <= max. - \param min Lower limit for random number. - \param max Upper limit for random number. - \return Random int. - **/ int Rand(int min, int max); - - /*! - \brief Obtain random integer [min,max]. - - Obtain random long l where min <= l <= max. - \param min Lower limit for random number. - \param max Upper limit for random number. - \return Random long. - **/ long Rand(long min, long max); - - /*! - \brief Obtain random integer [min,max]. - - Obtain random float l where min <= l <= max. - \param min Lower limit for random number. - \param max Upper limit for random number. - \return Random float. - **/ float Rand(float min, float max); - - /*! - \brief Obtain random integer [min,max]. - - Obtain random double l where min <= l <= max. - \param min Lower limit for random number. - \param max Upper limit for random number. - \return Random double. - **/ double Rand(double min, double max); - - /*! - \brief Obtain random double [0,1). - - Obtain random double d where 0 <= d < 1. - \return Random double [0,1). - **/ double RandDouble(); }; diff --git a/include/ZE_ZRect.h b/include/ZE_ZRect.h index eca16db..92f0b97 100644 --- a/include/ZE_ZRect.h +++ b/include/ZE_ZRect.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZRect.h - \brief Definition file for ZRect. - - Definition file for ZRect, the Rectangle class for ZEngine. -
$Id: ZE_ZRect.h,v 1.14 2003/11/24 22:22:07 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zrect_h__ #define __ze_zrect_h__ @@ -25,241 +16,44 @@ namespace ZE { -/*! - \brief ZEngine class for simplified rectangle use. - - ZRect Rectangle class, used to define a rectangular area or perform operations on the defined area. -**/ class ZRect { protected: - //! Pointer to ZEngine Object ZEngine* rEngine; - //! X Position of top left corner of rectangle. float rX; - //! Y Position of top left corner of rectangle. float rY; - //! Width of Rectangle. float rWidth; - //! Height of Rectangle. float rHeight; public: - /*! - \brief Default constructor for ZRect. - - Default constructor, initializes all values to zero. - **/ ZRect(); - - /*! - \brief Constructor for ZRect that takes inital values. - - Constructor for ZRect that takes inital values for all four members. - \param x Value for x position. - \param y Value for y position. - \param width Value for width. - \param height Value for height. - **/ ZRect(float x, float y, float width, float height); - - /*! - \brief Constructor for ZRect that uses an SDL_Rect. - - Constructor for ZRect that initializes from an SDL_Rect. - \param rect SDL_Rect to intialize from. - **/ ZRect(const SDL_Rect &rect); - - /*! - \brief Copy constructor for ZRect. - - Takes a ZRect and constructs a new identical rectangle. - \param rhs Rectangle to construct from. - **/ ZRect(const ZRect &rhs); - - /*! - \brief Virtual Destructor. - - Virtual destructor making future inheritance safe. - **/ virtual ~ZRect(); - /*! - \brief Overload for = operator with ZRect. - - Copies all values from one ZRect into another. - \param rhs Rectangle to copy values from. - \return New value of the ZRect. - **/ const ZRect& operator=(const ZRect &rhs); - - /*! - \brief Overload for < operator with ZRect, based upon location then size. - - Rectangles are sorted by y value, followed by x value, if they start at the same place, - the smaller of the two is deemed less than the other. - \param rhs Rectangle to compare. - \return True if this rectangle is smaller than the rhs rectangle, false otherwise. - **/ bool operator<(const ZRect &rhs) const; - /*! - \brief Draw rectangle. (filled) - - Draw the ZRect, this function is mainly provided for testing purposes. - \param red Red component of color (0-255). - \param green Green component of color (0-255). - \param blue Blue component of color (0-255). - \param alpha Alpha component of color (0-255). - **/ void Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha=255) const; - - /*! - \brief Changes the location of the rectangle. - - Changes the current x,y position of the rectangle. - \param x New x position for rectangle. - \param y New y position for rectangle. - **/ void Move(float x, float y); - - /*! - \brief Changes the location of the rectangle based upon the current location. - - Changes the current x,y position of the rectangle relative to the current location. - \param xMove Offset for new x position from current. - \param yMove Offset for new y position from current. - **/ void MoveRel(float xMove, float yMove); - - /*! - \brief Resize rectangle. - - Changes the current width and height of the rectangle. - \param width New width for rectangle. - \param height New height for rectangle. - **/ void Resize(float width, float height); - - /*! - \brief Grows or shrinks current rectangle. - - Changes the current width and height of the rectangle based upon current values. - \param widthChange Amount to add or subtract from width. - \param heightChange Amount to add or subtract from height. - **/ void ResizeRel(float widthChange, float heightChange); - /*! - \brief Check if one ZRect intersects another. - - Checks for overlap and returns boolean value based on if overlap exists. - \param rect Rectangle to check for intersection with. - \return True if intersection occured, false otherwise. - **/ bool Intersects(const ZRect &rect) const; - - /*! - \brief Check if a rectangle contains a given point. - - Checks point against boundaries of rectangle and returns result. - \param x X value of point to check. - \param y Y value of poitn to check. - \return Boolean variable, true if point is inside rectangle, false otherwise. - **/ bool Contains(float x, float y) const; - - /*! - \brief Check if a rectangle contains a given point. - - Checks point against boundaries of rectangle and returns result. - \param rect Rectangle to check for point. - \return Boolean variable, true if point is inside rectangle, false otherwise. - **/ bool Contains(const ZRect &rect) const; - - /*! - \brief Finds intersection of two rectangles. - - Checks for intersection, and returns rectangle where the two rectangles intersect. - \param rect Rectangle to check intersection with. - \return ZRect describing intersection area. - **/ ZRect Intersection(const ZRect &rect) const; - - /*! - \brief Returns an SDL_Rect representing the rectangle. - - Makes a SDL_Rect representing the rectangle, for use where functions require an SDL_Rect. - \return SDL_Rect representing the ZRect. - **/ SDL_Rect SDLrect() const; - - /*! - \brief Returns X Location. - - Access private X location member. - \return Value of mX. - **/ float X() const; - - /*! - \brief Returns Y Location. - - Access private Y location member. - \return Value of mY. - **/ float Y() const; - - /*! - \brief Return position of left side. - - Find X position of left side of rectangle. - \return X position of left side. - **/ float Left() const; - - /*! - \brief Return position of right side. - - Find X position of right side of rectangle. - \return X position of right side. - **/ float Right() const; - - /*! - \brief Return position of top side. - - Find Y position of top side of rectangle. - \return Y position of top side. - **/ float Top() const; - - /*! - \brief Return position of bottom side. - - Find Y position of left side of rectangle. - \return Y position of bottom side. - **/ float Bottom() const; - - /*! - \brief Returns Width. - - Access private width member. - \return Value of mWidth. - **/ float Width() const; - - /*! - \brief Returns Height. - - Access private height member. - \return Value of mHeight. - **/ float Height() const; }; diff --git a/include/ZE_ZSimpleParticleSystem.h b/include/ZE_ZSimpleParticleSystem.h index 397885e..d592e6b 100755 --- a/include/ZE_ZSimpleParticleSystem.h +++ b/include/ZE_ZSimpleParticleSystem.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,16 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZSimpleParticleSystem.h - \brief Definition and implementation file for a simple particle system for ZEngine. - - Definition and implementation file for ZEngine simple particle system, ZSimpleParticleSystem based on ZBaseParticleSystem. - Due to problems with template classes the template implementation needs to be in the same file as the declaration. -
$Id: ZE_ZSimpleParticleSystem.h,v 1.5 2003/11/24 22:22:07 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zsimpleparticlesystem_h__ #define __ze_zsimpleparticlesystem_h__ @@ -26,222 +16,74 @@ namespace ZE { -/*! - \brief Simple particle class for ZSimpleParticleSystem. - - General purpose particle, contains needed variables for a functional particle system. -**/ class ZSimpleParticle : public ZBaseParticle { public: - //! Previous X position of particle. float xPrev; - //! Previous Y position of particle. float yPrev; - //! X Velocity of particle per second. float xVel; - //! Y Velocity of particle per second. float yVel; - //! Energy change per second. float energyDelta; - //! Size of particle. float size; - //! Size change per second. float sizeDelta; - //! Red component of particle color. Uint8 r; - //! Green component of particle color. Uint8 g; - //! Blue component of particle color. Uint8 b; - //! Alpha component of particle color. Uint8 a; }; -/*! - \brief Possible draw styles for ZSimpleParticleSystem. - - Possible draw styles for ZSimpleParticleSystem, each specifies different code with which the particles will be drawn. -**/ enum ParticleDrawStyle { - DS_POINT, /*!< Draw particles as simple points. */ - DS_LINE, /*!< Draw particles as lines between the current position and the last. */ - DS_IMAGE /*!< Draw particles as an image. */ + DS_POINT, + DS_LINE, + DS_IMAGE }; -/*! - \brief ZSimpleParticleSystem class, a simple particle system provided originally as an example. - - ZSimpleParticleSystem class, example of implementation of a particle system on top of ZBaseParticleSystem base, - designed for flexibility and ease of use over speed. More specific, therefore even less optimized for specific - circumstances. Should be concidered usable but not optimal. (Although it is a great source of code for your - own implementations.) -**/ template class ZSimpleParticleSystem : public ZBaseParticleSystem { protected: - //! Draw style, one of the three enumerated values specifying how particles will be drawn. ParticleDrawStyle rStyle; - //! Image to draw (only used if rStyle is DS_IMAGE). ZImage rImage; - //! Minimum X value for starting position. float rMinX; - //! Maximum X value for starting position. float rMaxX; - //! Minimum Y value for starting position. float rMinY; - //! Maximum Y value for starting position. float rMaxY; - //! Minimum X velocity, particle moves it's velocity every second. float rMinXVel; - //! Maximum X velocity, particle moves it's velocity every second. float rMaxXVel; - //! Minimum Y velocity, particle moves it's velocity every second. - float rMinYVel; - //! Maximum Y velocity, particle moves it's velocity every second. + float rMinYVel; float rMaxYVel; - //! Minimum starting energy. (Remember particles with energy values <= 0 are removed.) float rMinEnergy; - //! Maximum starting energy. float rMaxEnergy; - //! Minimum energy change per second. float rMinEnergyDelta; - //! Maximum energy change per second. float rMaxEnergyDelta; - //! Minimum starting size. float rMinSize; - //! Maximum starting size. float rMaxSize; - //! Minimum size change per second. float rMinSizeDelta; - //! Maximum size change per second. float rMaxSizeDelta; - //! Minimum red component of color, 0-255. Uint8 rMinRed; - //! Maximum red component of color, 0-255. Uint8 rMaxRed; - //! Minimum green component of color, 0-255. Uint8 rMinGreen; - //! Maximum green component of color, 0-255. Uint8 rMaxGreen; - //! Minimum blue component of color, 0-255. Uint8 rMinBlue; - //! Maximum blue component of color, 0-255. Uint8 rMaxBlue; - //! Minimum alpha of particle, 0-255. Uint8 rMinAlpha; - //! Maximum alpha of particle, 0-255. Uint8 rMaxAlpha; - - /*! - \brief Function which creates a new particle. - - Implementation of pure virtual NewParticle from ZBaseParticleSystem, creates a new particle with - it's members set to values between their min and max value as set by the system. - **/ + virtual particleType NewParticle(); - - /*! - \brief Updates a given particle given it's index and the elapsedTime. - - Implementation of pure virtual UpdateParticle from ZBaseParticleSystem, updates a given particle - relative to the elapsed time. - \param index Index of particle in rParticles array to update. - \param elapsedTime Decimal portion of a second since last call. - **/ virtual void UpdateParticle(int index, float elapsedTime); public: - /*! - \brief Draws all particles. - - Implementation of pure virtual Render from ZBaseParticleSystem, draws all particles in specified - ParticleDrawStyle. - **/ virtual void Render(); - /*! - \brief Reload image. - - Reload image if mode is DS_IMAGE, usage is same as ZImage::Reload. - **/ void ReloadImage(); - /*! - \brief Sets ParticleDrawStyle for this system. - - Sets the method of drawing particles, point, line, or image particles. - \param style ParticleDrawStyle for this particle system to use. - **/ void SetDrawStyle(ParticleDrawStyle style); - - /*! - \brief Sets image for particle system. - - Sets image for particle system to use, assuming the drawing style is DS_IMAGE. - \brief filename Filename of image to load for the system. - **/ void SetImage(std::string filename); - - /*! - \brief Sets the range of initial positions. - - Sets the range of initial positions for a new particle. - \param minX Minimum X coordinate for new particles. - \param minY Minimum Y coordinate for new particles. - \param maxX Maximum X coordinate for new particles. - \param maxY Maximum Y coordinate for new particles. - **/ void SetPosRange(float minX, float minY, float maxX, float maxY); - - /*! - \brief Sets range of velocities for particles. - - Sets range from which a new particle obtains it's random velocity, - \param minXVel Minimum X velocity of a particle. - \param minYVel Minimum Y velocity of a particle. - \param maxXVel Maximum X velocity of a particle. - \param maxYVel Maximum Y velocity of a particle. - **/ void SetVelocityRange(float minXVel, float minYVel, float maxXVel, float maxYVel); - - /*! - \brief Sets range of initial energy and energyDelta. - - Sets the possible ranges for a particles starting energy and it's energyDelta. Particles with - energy less than or equal to 0 are deleted by ZBaseParticleSystem::Update. - \param minEnergy Minimum initial energy. - \param maxEnergy Maximum initial energy. - \param minEnergyDelta Minimum energy delta. - \param maxEnergyDelta Maximum energy delta. - **/ void SetEnergyRange(float minEnergy, float maxEnergy, float minEnergyDelta=0, float maxEnergyDelta=0); - - /*! - \brief Sets range of initial size and sizeDelta. - Sets the possible ranges for a particles starting size and it's sizeDelta. - \param minSize Minimum initial size. - \param maxSize Maximum initial size. - \param minSizeDelta Minimum size delta. - \param maxSizeDelta Maximum size delta. - **/ void SetSizeRange(float minSize, float maxSize, float minSizeDelta=0, float maxSizeDelta=0); - - /*! - \brief Set range of color for a new particle. - - Sets range of possible colors, by component, for a new particle. - \param minRed Minimum value of red component (0-255). - \param maxRed Minimum value of red component (0-255). - \param minGreen Minimum value of green component (0-255). - \param maxGreen Minimum value of green component (0-255). - \param minBlue Minimum value of blue component (0-255). - \param maxBlue Minimum value of blue component (0-255). - \param minAlpha Minimum value of alpha value (0-255). - \param maxAlpha Minimum value of alpha value (0-255). - **/ void SetColorRange(Uint8 minRed, Uint8 maxRed, Uint8 minGreen, Uint8 maxGreen, Uint8 minBlue, Uint8 maxBlue, Uint8 minAlpha, Uint8 maxAlpha); }; diff --git a/include/ZE_ZSound.h b/include/ZE_ZSound.h index 8b8a112..fab1dda 100644 --- a/include/ZE_ZSound.h +++ b/include/ZE_ZSound.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZSound.h - \brief Definition file for ZSound. - - Definition file for ZSound, the Sound Effect wrapper for ZEngine. -
$Id: ZE_ZSound.h,v 1.12 2003/12/24 04:46:48 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_zsound_h__ #define __ze_zsound_h__ @@ -27,164 +18,37 @@ namespace ZE { -/*! - \brief ZSound class for playing sound effects. (WAV) - - ZSound music class, class wraps common features for SDL_Mixer's Mix_Chunk. Inherited from ZObject. -**/ class ZSound { protected: - //! Pointer to ZEngine Object ZEngine* rEngine; - //! Pointer to music data. Mix_Chunk* rSound; - //! Channel ID Number from SDL_Mixer. int rChannelID; public: - //! Static Variable For Infinite loop of sound. (Defined as -1) static const int LoopInfinite; - /////////////////////// - //Opening and Closing// - /////////////////////// - - /*! - \brief Default Constructor. - - Default Constructor, does nothing. - **/ ZSound(); - - /*! - \brief Constructor that opens a sound effect file. - - Constructor simply calls ZSound::Open() with same filename. (WAV,MOD,MID,OGG) - \param filename Sound effect to open. - **/ ZSound(std::string filename); - - /*! - \brief Destructor, frees memory. - - Destructor calls ZSound::Release(). - **/ virtual ~ZSound(); - /*! - \brief Opens a sound effect file. - - Open a music file to be used. - \param filename Music to open. - **/ void Open(std::string filename); - - /*! - \brief Opens a sound effect file from within a zip archive. - - Open a sound effect file from within a zip archive using zlib and SDL_RWops. - \param zipname Zip file to open sound effect from. - \param filename File to open as new sound effect. - **/ 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. - - Release memory held by sample data. - **/ void Release(); - ///////////////// - //Play Controls// - ///////////////// - - /*! - \brief Play currently loaded sound effect. - - Play sound effect, looping loopNum times. (use ZSound::LoopInfinite to loop forever.) - If fade is not zero (which it defaults to) music will fade in over specified number of milliseconds. - \param loopNum Number of times to loop song, defaults to zero. - \param fadeTime Milliseconds to fade to full volume, defaults to zero for no fade. - **/ void Play(int loopNum=0, int fadeTime=0); - - /*! - \brief Pause sound. - - Pause currently playing sound. - **/ void Pause() const; - - /*! - \brief Unpause sound. - - Unpause currently playing sound. - **/ void Unpause() const; - - /*! - \brief Stop sound. - - Stop currently playing sound, if fadeTime is not zero, fade out over specified time. - \param fadeTime Milliseconds to fade out over, defaults to zero for immediate stop. - **/ void Stop(int fadeTime=0) const; - - /*! - \brief Change Volume. - - Change volume of currently playing sample. - \param volume Volume to change to, can be in a range from 0 to 128. - **/ void SetVolume(int volume); - ///////////// - //Accessors// - ///////////// - - /*! - \brief Check if file is loaded. - - Check if file is loaded and pointer to data is non-NULL. - \return Loaded or Unloaded state of data. - **/ bool IsLoaded() const; - - /*! - \brief Check if sound is Playing. - - Check if sound is playing, specifically if it is not stopped. (Paused state should be checked for by IsPaused) - \return Playing / Not Playing State of sound. - **/ bool IsPlaying() const; - - /*! - \brief Check if sound is Paused. - - Check if sound is "playing" but currently paused. - \return Paused / Not Paused State of Sound. - **/ bool IsPaused() const; - - /*! - \brief Find Current Volume of Sound Channel. - - Get current volume of sound channel represented as a value from 0-128. - \return Volume of sound channel, 0-128. - **/ - int Volume() const; + int GetVolume() const; }; - } #endif //USE_SDL_MIXER diff --git a/include/ZE_ZTimer.h b/include/ZE_ZTimer.h index 67c9875..663beac 100644 --- a/include/ZE_ZTimer.h +++ b/include/ZE_ZTimer.h @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/*! - \file ZE_ZTimer.h - \brief Definition file for ZTimer. - - Definition file for ZTimer, the Timer class for ZEngine. -
$Id: ZE_ZTimer.h,v 1.10 2003/11/24 22:24:33 cozman Exp $
- \author James Turk -**/ - #ifndef __ze_ztimer_h__ #define __ze_ztimer_h__ @@ -25,85 +16,26 @@ namespace ZE { -/*! - \brief ZTimer class for Timer use. - - ZTimer timing class, class wraps common features of SDL timer. Inherited from ZObject and tied to ZEngine main timer. -**/ class ZTimer { protected: - //! Pointer to ZEngine Object ZEngine* rEngine; - //! Paused / Unpaused state of Timer bool rPaused; - //! Using ZEngine timer or SDL global timer. bool rUseZEngine; - //! Total time this timer has been paused. Uint32 rPausedTime; - //! Time this Timer was paused. Uint32 rLastPause; - /*! - \brief Get time from parent timer. - - Protected method to get time from whichever timer is parent. - \return Time on parent timer. - **/ Uint32 GetParentTime() const; public: - - /*! - \brief Constructs a new Timer. - - Sets TimePaused to current ZEngine time if useZEngine is true, otherwise uses SDL timer. - \param useZEngine Tells if timer should use ZEngine or SDL. - **/ ZTimer(bool useZEngine=true); - - /*! - \brief Virtual Destructor. - - Virtual destructor making future inheritance safe. - **/ virtual ~ZTimer(); - /*! - \brief Reset Timer. - - Set Timer back to Zero, will also unpause timer if it was paused. - **/ void Reset(); - - /*! - \brief Pause Timer. - - Pause the timer if it is unpaused. - **/ void Pause(); - - /*! - \brief Unpause Timer. - - Unpause the timer if it is paused. - **/ void Unpause(); - /*! - \brief Get Time of Timer. - - Get current time accounting for time paused. - \return Current Timer Time. - **/ Uint32 GetTime() const; - - /*! - \brief Get paused state. - - Find out paused state of timer. - \return Paused state for timer. - **/ bool IsPaused() const; }; diff --git a/include/ZEngine.h b/include/ZEngine.h index 79bbd80..0da6f3d 100644 --- a/include/ZEngine.h +++ b/include/ZEngine.h @@ -1,53 +1,3 @@ -/*! - \file ZEngine.h - \brief Header file for ZEngine. - - Public header file for ZEngine, this is the file that programs that wish to utilize ZEngine should include. -
$Id: ZEngine.h,v 1.38 2003/11/25 01:02:17 cozman Exp $
- \author James Turk -**/ - -/*! - \mainpage ZEngine Documentation - - \author James Turk - \version 0.8.5 - \date October 5th, 2003 - - \section ZEngine About ZEngine -
-     -ZEngine is designed to provide a powerful yet easy to use 2D game engine in a well designed - Object Oriented manner, and uses cross platform libraries such as SDL and OpenGL. (ZEngine can use SDL_ttf,SDL_image, - and SDL_mixer all of which are cross platform as well as Open Source.)
-     -It is licensed under a BSD-style license, and anyone is free to suggest or implement changes - to be added to the Engine, as well as modify the engine to their own needs or use it however they like.
-     -ZEngine now uses OpenGL rather than SDL to do 2D drawing, thus increasing the uses of the engine - and making the engine much faster in all test cases, and the engine was tested for memory leaks with MSVC and is known - to have no leaks.
-     -ZEngine homepage : http://zengine.sourceforge.net/.
-     -ZEngine tutorials : http://zengine.sourceforge.net/tutorials/.
-     -ZEngine forums : http://sourceforge.net/forum/?group_id=62098.
- - \section Licensing Licensing -
-
        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://zengine.sourceforge.net
-    
- \section Authors Contributing Authors -
- James Turk james@conceptofzero.net - Core Engine, Design, Docs, and Classes
- Gamer Tazar tazar@conceptofzero.net - OpenGL assistance
- Sean sean@conceptofzero.net - MSVC++6 Project Files
- Kevin Watters kwatters@adelphia.net - Fix to ZImage::SetColorKey
- Atani atani@atani-software.net - Revised Linux Build System
- Stinus Petersen bison@flytlet.dk - Fix for ZImage::OpenFromImage with alpha images
-**/ - #ifndef __zengine_h__ #define __zengine_h__ diff --git a/src/VersionInfo.cpp b/src/VersionInfo.cpp index 00415e5..999c1e8 100755 --- a/src/VersionInfo.cpp +++ b/src/VersionInfo.cpp @@ -1,26 +1,30 @@ +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002-2004 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 +*******************************************************************************/ + #include "VersionInfo.h" -/*! - \file VersionInfo.cpp - \brief Implementation file for VersionInfo class. - - Implementation file for VersinInfo class, simple class for containing and comparing - version numbers. -
$Id: VersionInfo.cpp,v 1.6 2003/07/12 09:22:13 cozman Exp $
- \author James Turk -**/ - VersionInfo::VersionInfo(unsigned int maj, unsigned int min, unsigned int rel, std::string ext) : Major(maj), Minor(min), Release(rel), Extra(ext) { } -std::string VersionInfo::GetString() const +char* VersionInfo::GetString() const { + static char verStr[100]; + if(Extra.length()) - return ZE::FormatStr("%d.%d.%d [%s]",Major,Minor,Release,Extra.c_str()); + sprintf(verStr,"%d.%d.%d [%s]",Major,Minor,Release,Extra.c_str()); else - return ZE::FormatStr("%d.%d.%d",Major,Minor,Release); + sprintf(verStr,"%d.%d.%d",Major,Minor,Release); + + return verStr; } bool VersionInfo::operator<(const VersionInfo &rhs) const diff --git a/src/ZE_Utility.cpp b/src/ZE_Utility.cpp index 8908430..58ecc41 100755 --- a/src/ZE_Utility.cpp +++ b/src/ZE_Utility.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,27 +8,18 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_Utility.cpp - \brief Source file for ZEngine utility functions. - - Source file containing open utilities for use inside and alongside ZEngine. -
$Id: ZE_Utility.cpp,v 1.14 2003/11/24 02:07:03 cozman Exp $
- \author James Turk -**/ - #include "ZE_Utility.h" namespace ZE { -std::string FormatStr(const std::string fmtstr, ...) +std::string FormatStr(std::string fmtStr, ...) { - char buf[512]; - va_list args; - //simply puts args into the buffer using standard parsing rules - va_start(args,fmtstr); - vsprintf(buf, fmtstr.c_str(), args); + std::va_list args; + char buf[1024]; + + va_start(args,fmtStr); + std::vsprintf(buf,fmtStr.c_str(),args); va_end(args); return buf; @@ -76,6 +67,85 @@ SDL_RWops* RWFromZip(std::string zipname, std::string filename) return SDL_RWFromMem(buffer, info.uncompressed_size); //return buffer in RW form } +#if (GFX_BACKEND == ZE_OGL) + +//from SDL's testgl.c power_of_two +int PowerOfTwo(int num) +{ + int value = 1; + + while(value < num) //texture coord must be >= input + value <<= 1; //value <<= 1 is the same as value *= 2 + return value; +} + +//from SDL's testgl.c SDL_GL_LoadTexture +GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord) +{ + GLuint texture; + int w, h; + SDL_Surface *temp; + SDL_Rect area; + Uint32 saved_flags; + Uint8 saved_alpha; + + //expand width and height to nearest powers of 2 + w = PowerOfTwo(surface->w); + h = PowerOfTwo(surface->h); + texcoord[0] = 0.0f; //min X + texcoord[1] = 0.0f; //min Y + texcoord[2] = (GLfloat)surface->w / w; //max X + texcoord[3] = (GLfloat)surface->h / h; //max Y + + temp = SDL_CreateRGBSurface( + SDL_SWSURFACE, + w, h, + 32, +#if SDL_BYTEORDER == SDL_LIL_ENDIAN //endian specific color masks + 0x000000FF, + 0x0000FF00, + 0x00FF0000, + 0xFF000000 +#else + 0xFF000000, + 0x00FF0000, + 0x0000FF00, + 0x000000FF +#endif + ); + if(!temp) //failure in CreateRGBSurface + return 0; + + //save alpha + saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); + saved_alpha = surface->format->alpha; + if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) + SDL_SetAlpha(surface, 0, 0); + + //copy surface (do not alter passed surface to allow this function to be used in special situations) + area.x = 0; + area.y = 0; + area.w = static_cast(surface->w); + area.h = static_cast(surface->h); + SDL_BlitSurface(surface, &area, temp, &area); + + //restore saved alpha + if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) + SDL_SetAlpha(surface, saved_flags, saved_alpha); + + //create the OpenGL texture + glGenTextures(1, &texture); + //setup texture parmaters + glBindTexture(GL_TEXTURE_2D, texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp->pixels); + SDL_FreeSurface(temp); //temp surface no longer needed + + return texture; +} +#endif //GFX_BACKEND == ZE_OGL + //Each of the Free*s safely frees & NULLs the pointer void FreeImage(SDL_Surface *&image) { diff --git a/src/ZE_ZAnimation.cpp b/src/ZE_ZAnimation.cpp index 111736c..dbf6443 100644 --- a/src/ZE_ZAnimation.cpp +++ b/src/ZE_ZAnimation.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_ZAnimation.cpp - \brief Source file for ZAnimation. - - Implementation of ZAnimation, ZEngine's class for ZImage based animations. -
$Id: ZE_ZAnimation.cpp,v 1.2 2003/12/24 04:44:41 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZAnimation.h" namespace ZE @@ -37,6 +28,10 @@ ZAnimation::ZAnimation(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimTy Create(images,numFrames,frameDelay,type,backwards); } +ZAnimation::~ZAnimation() +{ +} + void ZAnimation::Create(ZImage *images, int numFrames, Uint32 frameDelay, ZAnimType type, bool backwards) { rAnimImages = images; @@ -138,7 +133,7 @@ void ZAnimation::Draw(float x, float y) const //error: images not loaded } -bool ZAnimation::Running() const +bool ZAnimation::IsRunning() const { return rFrameStep != 0; } diff --git a/src/ZE_ZConfigFile.cpp b/src/ZE_ZConfigFile.cpp index 891a5aa..54455d4 100644 --- a/src/ZE_ZConfigFile.cpp +++ b/src/ZE_ZConfigFile.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_ZConfigFile.cpp - \brief Source file for ZConfigFile. - - Implementation of ZConfigFile, the ZEngine INI-Style Config File. -
$Id: ZE_ZConfigFile.cpp,v 1.15 2003/11/24 22:20:49 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZConfigFile.h" namespace ZE @@ -177,11 +168,12 @@ ZConfigFile::~ZConfigFile() void ZConfigFile::Process(std::string filename) { rFilename = filename; - int commentNum=0; - int newlineNum=0; - - std::ifstream cfile(rFilename.c_str()); + int commentNum,newlineNum; + char commentStr[15],newlineStr[15]; std::string section, str, var, tmp; + std::ifstream cfile(rFilename.c_str()); + + commentNum = newlineNum = 0; //comment/newline support is a bit of a hack rFileLayout.clear(); //layout must be cleared, in case variable is being used multiple times @@ -200,12 +192,14 @@ void ZConfigFile::Process(std::string filename) } else if(tmp[0] == '#' || tmp[0] == ';') //acceptable comment characters { - SetVariable(section,FormatStr("__comment%d",commentNum),str); + sprintf(commentStr,"__comment%d",commentNum); + SetVariable(section,commentStr,str); ++commentNum; } - else if(tmp.length() == 0 && !cfile.eof()) //prevent writing a new newline with every write to disk + else if(tmp.length() == 0 && !cfile.eof()) //avoid adding a line to end of file each time { - SetVariable(section,FormatStr("__newline%d",newlineNum),""); + sprintf(newlineStr,"__newline%d",newlineNum); + SetVariable(section,newlineStr,str); ++newlineNum; } diff --git a/src/ZE_ZEngine.cpp b/src/ZE_ZEngine.cpp index 043c393..b0e1d14 100644 --- a/src/ZE_ZEngine.cpp +++ b/src/ZE_ZEngine.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_ZEngine.cpp - \brief Central source file for ZEngine. - - Actual implementation of ZEngine singleton class, the core of ZEngine. -
$Id: ZE_ZEngine.cpp,v 1.67 2003/12/24 04:43:36 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZEngine.h" #include "ZE_ZRect.h" @@ -65,7 +56,7 @@ ZEngine* ZEngine::GetInstance() { if(!sInstance) //first time through, gets new instance, each time after returns same one sInstance = new ZEngine; - + atexit(ZEngine::ReleaseInstance); return sInstance; } @@ -73,7 +64,13 @@ void ZEngine::ReleaseInstance() { if(sInstance) { - sInstance->CloseDisplay(); + if(sInstance->mErrlog && sInstance->mLogStyle == ZLOG_HTML) + { + fprintf(sInstance->mErrlog,"\n"); + fclose(sInstance->mErrlog); + } + + sInstance->CloseDisplay(); delete sInstance; } sInstance = NULL; @@ -265,11 +262,6 @@ void ZEngine::ToggleFullscreen() SetReloadNeed(true); //images need to be reloaded on fullscreen swap } -bool ZEngine::Initialized() -{ - return mInitialized; -} - SDL_Surface *ZEngine::Display() { return mScreen; @@ -375,6 +367,11 @@ void ZEngine::UnpauseTimer() } } +bool ZEngine::TimerIsPaused() +{ + return mPaused; +} + double ZEngine::GetFrameTime() { return mSecPerFrame; @@ -385,25 +382,6 @@ double ZEngine::GetFramerate() return mSecPerFrame ? 1/mSecPerFrame : 0; //avoid /0 } -#ifdef DEPRECIATED - -void ZEngine::SetDesiredFramerate(Uint8 rate) -{ - mDesiredFramerate = rate; -} - -Uint8 ZEngine::GetDesiredFramerate() -{ - return mDesiredFramerate; -} - -#endif //DEPRECIATED - -bool ZEngine::IsPaused() -{ - return mPaused; -} - bool ZEngine::IsActive() { return mActive; @@ -488,7 +466,7 @@ bool ZEngine::MouseInRect(const SDL_Rect &rect) mMouseY >= rect.y && mMouseY <= rect.y+rect.h); } -bool ZEngine::MouseInRect(ZRect rect) +bool ZEngine::MouseInRect(const ZRect &rect) { return rect.Contains(static_cast(mMouseX),static_cast(mMouseY)); } @@ -562,6 +540,8 @@ void ZEngine::SetEventFilter(SDL_EventFilter filter) void ZEngine::SetErrorLog(ZErrorLogStyle logStyle, std::string logFile) { + mLogStyle = logStyle; + if(logStyle != ZLOG_NONE && logFile.length()) { //stderr & stdout directed to their appropriate streams @@ -575,24 +555,20 @@ void ZEngine::SetErrorLog(ZErrorLogStyle logStyle, std::string logFile) if(logStyle == ZLOG_HTML) { fprintf(mErrlog, - "ZEngine Error Log\n\n\n\n"); fflush(mErrlog); } } } -void ZEngine::DisableErrorLog() -{ - mErrlog = NULL; -} - void ZEngine::ReportError(ZErrorSeverity severity, std::string desc, ...) { static std::string prefix[] = { @@ -616,11 +592,10 @@ void ZEngine::ReportError(ZErrorSeverity severity, std::string desc, ...) if(mLogStyle != ZLOG_NONE) { char buf[1024]; - va_list args; - std::string msg; + std::va_list args; va_start(args,desc); - vsprintf(buf,desc.c_str(),args); + std::vsprintf(buf,desc.c_str(),args); va_end(args); if(mLogStyle == ZLOG_TEXT) @@ -629,7 +604,7 @@ void ZEngine::ReportError(ZErrorSeverity severity, std::string desc, ...) } else if(mLogStyle == ZLOG_HTML) { - fprintf(mErrlog,"

%s%s

\n",style[static_cast(severity)].c_str(),prefix[static_cast(severity)].c_str(),buf); + fprintf(mErrlog,"

%s%s

\n",style[static_cast(severity)].c_str(),prefix[static_cast(severity)].c_str(),buf); } std::fflush(mErrlog); @@ -638,17 +613,14 @@ void ZEngine::ReportError(ZErrorSeverity severity, std::string desc, ...) void ZEngine::WriteLog(std::string str, ...) { - if(mLogStyle != ZLOG_NONE) - { - char buf[1024]; - va_list args; + std::va_list args; + char buf[1024]; - va_start(args,str); - vsprintf(buf,str.c_str(),args); - va_end(args); + va_start(args,str); + std::vsprintf(buf,str.c_str(),args); + va_end(args); - - } + ReportError(ZERR_NOTE, buf); } void ZEngine::SeedRandGen(unsigned long seed) @@ -743,6 +715,11 @@ double ZEngine::GetDoubleResource(std::string type, std::string id, std::string } } +bool ZEngine::DisplayCreated() +{ + return mInitialized; +} + int ZEngine::DisplayWidth() { return mScreen->w; @@ -758,25 +735,6 @@ int ZEngine::DisplayDepth() return mScreen->format->BitsPerPixel; } -#ifdef DEPRECIATED - -int ZEngine::Width() -{ - return mScreen->w; -} - -int ZEngine::Height() -{ - return mScreen->h; -} - -int ZEngine::BPP() -{ - return mScreen->format->BitsPerPixel; -} - -#endif //DEPRECIATED - bool ZEngine::IsFullscreen() { return mFullscreen; diff --git a/src/ZE_ZFont.cpp b/src/ZE_ZFont.cpp index 9fe1261..1ed2ed9 100644 --- a/src/ZE_ZFont.cpp +++ b/src/ZE_ZFont.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ 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. -
$Id: ZE_ZFont.cpp,v 1.17 2003/12/24 04:43:36 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZFont.h" #ifdef USE_SDL_TTF @@ -197,7 +188,7 @@ bool ZFont::IsUnderlined() const } } -int ZFont::Height() const +int ZFont::GetHeight() const { if(rFont) return TTF_FontHeight(rFont); @@ -208,7 +199,7 @@ int ZFont::Height() const } } -int ZFont::LineSkip() const +int ZFont::GetLineSkip() const { if(rFont) return TTF_FontLineSkip(rFont); @@ -219,7 +210,7 @@ int ZFont::LineSkip() const } } -int ZFont::StringWidth(std::string text) const +int ZFont::CalcStringWidth(std::string text) const { int w,h; @@ -235,7 +226,7 @@ int ZFont::StringWidth(std::string text) const } } -int ZFont::StringHeight(std::string text) const +int ZFont::CalcStringHeight(std::string text) const { int w,h; diff --git a/src/ZE_ZImage.cpp b/src/ZE_ZImage.cpp index f67ed92..813ab3d 100644 --- a/src/ZE_ZImage.cpp +++ b/src/ZE_ZImage.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,98 +8,12 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_ZImage.cpp - \brief Source file for ZImage. - - Implementation of ZImage, the Image class for ZEngine. -
$Id: ZE_ZImage.cpp,v 1.54 2003/12/24 04:43:36 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZImage.h" namespace ZE { -#if (GFX_BACKEND == ZE_OGL) -//from SDL's testgl.c power_of_two -int ZImage::PowerOfTwo(int num) const -{ - int value = 1; - - while(value < num) //texture coord must be >= input - value <<= 1; //value <<= 1 is the same as value *= 2 - return value; -} - -//from SDL's testgl.c SDL_GL_LoadTexture -GLuint ZImage::SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord) const -{ - GLuint texture; - int w, h; - SDL_Surface *temp; - SDL_Rect area; - Uint32 saved_flags; - Uint8 saved_alpha; - - //expand width and height to nearest powers of 2 - w = PowerOfTwo(surface->w); - h = PowerOfTwo(surface->h); - texcoord[0] = 0.0f; //min X - texcoord[1] = 0.0f; //min Y - texcoord[2] = (GLfloat)surface->w / w; //max X - texcoord[3] = (GLfloat)surface->h / h; //max Y - - temp = SDL_CreateRGBSurface( - SDL_SWSURFACE, - w, h, - 32, -#if SDL_BYTEORDER == SDL_LIL_ENDIAN //endian specific color masks - 0x000000FF, - 0x0000FF00, - 0x00FF0000, - 0xFF000000 -#else - 0xFF000000, - 0x00FF0000, - 0x0000FF00, - 0x000000FF -#endif - ); - if(!temp) //failure in CreateRGBSurface - return 0; - - //save alpha - saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); - saved_alpha = surface->format->alpha; - if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) - SDL_SetAlpha(surface, 0, 0); - - //copy surface (do not alter passed surface to allow this function to be used in special situations) - area.x = 0; - area.y = 0; - area.w = static_cast(surface->w); - area.h = static_cast(surface->h); - SDL_BlitSurface(surface, &area, temp, &area); - - //restore saved alpha - if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) - SDL_SetAlpha(surface, saved_flags, saved_alpha); - - //create the OpenGL texture - glGenTextures(1, &texture); - //setup texture parmaters - glBindTexture(GL_TEXTURE_2D, texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp->pixels); - SDL_FreeSurface(temp); //temp surface no longer needed - - return texture; -} -#endif //GFX_BACKEND == ZE_OGL ZImage::ZImage() : rEngine(ZEngine::GetInstance()), diff --git a/src/ZE_ZMusic.cpp b/src/ZE_ZMusic.cpp index bd721c9..e2e8ee7 100644 --- a/src/ZE_ZMusic.cpp +++ b/src/ZE_ZMusic.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ 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. -
$Id: ZE_ZMusic.cpp,v 1.13 2003/12/24 04:43:36 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZMusic.h" #ifdef USE_SDL_MIXER @@ -158,7 +149,7 @@ bool ZMusic::IsPaused() const } } -int ZMusic::Volume() const +int ZMusic::GetVolume() const { if(rMusic) return Mix_VolumeMusic(-1); diff --git a/src/ZE_ZRandGen.cpp b/src/ZE_ZRandGen.cpp index 28baba0..66cd49d 100755 --- a/src/ZE_ZRandGen.cpp +++ b/src/ZE_ZRandGen.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,17 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_ZRandGen.cpp - \brief Source file for ZRandGen. - - Implementation file for ZRandGen, an OO encapsulated version of the Mersenne Twister. - This implementation is derived from the original mt19937ar.c source from - http://www.math.keio.ac.jp/matumoto/emt.html. See source for MT license. -
$Id: ZE_ZRandGen.cpp,v 1.2 2003/07/12 01:25:42 cozman Exp $
- \author James Turk, some code from Mersenne Twister. -**/ - #include "ZE_ZRandGen.h" namespace ZE diff --git a/src/ZE_ZRect.cpp b/src/ZE_ZRect.cpp index dbb6140..a439008 100644 --- a/src/ZE_ZRect.cpp +++ b/src/ZE_ZRect.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_ZRect.cpp - \brief Source file for ZRect. - - Implementation of ZRect, the Rectangle class for ZEngine. -
$Id: ZE_ZRect.cpp,v 1.15 2003/11/24 22:20:49 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZRect.h" namespace ZE diff --git a/src/ZE_ZSound.cpp b/src/ZE_ZSound.cpp index 6b8b2ad..aca86de 100644 --- a/src/ZE_ZSound.cpp +++ b/src/ZE_ZSound.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_ZSound.cpp - \brief Source file for ZSound. - - Implementation of ZSound, the basic Sound class for ZEngine. -
$Id: ZE_ZSound.cpp,v 1.15 2003/12/24 04:43:36 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZSound.h" #ifdef USE_SDL_MIXER @@ -170,7 +161,7 @@ bool ZSound::IsPaused() const } } -int ZSound::Volume() const +int ZSound::GetVolume() const { if(rSound) return Mix_VolumeChunk(rSound,-1); diff --git a/src/ZE_ZTimer.cpp b/src/ZE_ZTimer.cpp index 9b5456f..f00a40f 100644 --- a/src/ZE_ZTimer.cpp +++ b/src/ZE_ZTimer.cpp @@ -1,6 +1,6 @@ /******************************************************************************* This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk + Copyright (C) 2002-2004 James Turk Licensed under a BSD-style license. @@ -8,15 +8,6 @@ and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ -/** - \file ZE_ZTimer.cpp - \brief Source file for ZTimer. - - Implementation of ZTimer, the basic Timer class for ZEngine. -
$Id: ZE_ZTimer.cpp,v 1.12 2003/11/24 22:20:49 cozman Exp $
- \author James Turk -**/ - #include "ZE_ZTimer.h" namespace ZE