diff --git a/include/VersionInfo.h b/include/VersionInfo.h
index 9494d62..418f120 100755
--- a/include/VersionInfo.h
+++ b/include/VersionInfo.h
@@ -1,90 +1,91 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- Licensed under a BSD-style license.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/*!
- \file 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.3 2003/06/11 00:15:24 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.
-**/
-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.
- **/
- 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;
-};
-
-#endif //__versioninfo_h__
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ Licensed under a BSD-style license.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/*!
+ \file 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.
+ **/
+ 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;
+};
+
+#endif //__versioninfo_h__
diff --git a/include/ZE_Includes.h b/include/ZE_Includes.h
index 9477ada..34ee62b 100644
--- a/include/ZE_Includes.h
+++ b/include/ZE_Includes.h
@@ -1,52 +1,53 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- Licensed under a BSD-style license.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/*!
- \file ZE_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.8 2003/04/27 22:05:25 cozman Exp $
- \author James Turk
-**/
-
-#ifndef __ze_includes_h__
-#define __ze_includes_h__
-
-#include "ZE_Defines.h"
-
-#include "SDL.h"
-#include "SDL_opengl.h"
-#include "external/SDLGL_Util.h"
-#ifdef USE_SDL_IMAGE
-#include "SDL_image.h"
-#endif
-#ifdef USE_SDL_TTF
-#include "SDL_ttf.h"
-#endif
-#ifdef USE_SDL_MIXER
-#include "SDL_mixer.h"
-#endif
-#ifdef USE_SDL_NET
-#include "SDL_net.h"
-#endif
-#ifdef USE_PHYSFS
-#include "physfs.h"
-#include "external/physfsrwops.h"
-#endif
-
-#include //used frequently
-#include //used by ZEngine for ZErrors
-#include //used by ZConfigFile
-#include //used by ZConfigFile
-#include //used in parsing
-
-#endif //__ze_includes_h__
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ Licensed under a BSD-style license.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/*!
+ \file ZE_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.8 2003/04/27 22:05:25 cozman Exp $
+ \author James Turk
+**/
+
+#ifndef __ze_includes_h__
+#define __ze_includes_h__
+
+#include "ZE_Defines.h"
+
+#include "SDL.h"
+#include "SDL_opengl.h"
+#include "external/SDLGL_Util.h"
+#ifdef USE_SDL_IMAGE
+#include "SDL_image.h"
+#endif
+#ifdef USE_SDL_TTF
+#include "SDL_ttf.h"
+#endif
+#ifdef USE_SDL_MIXER
+#include "SDL_mixer.h"
+#endif
+#ifdef USE_SDL_NET
+#include "SDL_net.h"
+#endif
+#ifdef USE_PHYSFS
+#include "physfs.h"
+#include "external/physfsrwops.h"
+#endif
+
+#include //used frequently
+#include //used by ZEngine for ZErrors
+#include //used by ZConfigFile
+#include //used by ZConfigFile
+#include //used in parsing
+#include //used in FormatStr
+
+#endif //__ze_includes_h__
diff --git a/include/ZE_ZBaseParticleSystem.h b/include/ZE_ZBaseParticleSystem.h
index 7fa9dda..c3d892e 100755
--- a/include/ZE_ZBaseParticleSystem.h
+++ b/include/ZE_ZBaseParticleSystem.h
@@ -1,351 +1,351 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- Licensed under a BSD-style license.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/*!
- \file ZE_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.4 2003/07/11 20:51:44 cozman Exp $
- \author James Turk
-**/
-
-#ifndef __ze_zbaseparticlesystem_h__
-#define __ze_zbaseparticlesystem_h__
-
-#include "ZEngine.h"
-
-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.
- **/
- 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.
- **/
- 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(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 SetRate(int rate);
-};
-
-//implementation//
-
-template
-void ZBaseParticleSystem::AddParticle()
-{
- //empty space is always at end, function is private so no checking is needed (Emit does that)
- rParticles[rCurParticles] = NewParticle();
- ++rCurParticles;
-}
-
-template
-ZBaseParticleSystem::ZBaseParticleSystem()
-{
- rEngine = ZEngine::GetInstance();
- rParticles = NULL;
- rMaxParticles = rCurParticles = rNumParticlesPerSec = 0;
- rLastUpdate = rEngine->GetTime();
- rPaused = false;
-}
-
-template
-ZBaseParticleSystem::~ZBaseParticleSystem()
-{
- if(rParticles)
- delete []rParticles;
-}
-
-template
-void ZBaseParticleSystem::Emit(int numParticles)
-{
- while(numParticles > 0 && rCurParticles < rMaxParticles)
- {
- AddParticle();
- --numParticles;
- }
-}
-
-template
-void ZBaseParticleSystem::Update()
-{
- float elapsed = (rEngine->GetTime()-rLastUpdate)/1000.0f;
- double emitAmount;
- static double overflow=0;
-
- if(!rPaused)
- {
- //update every particle and remove dead particles
- for(unsigned int i=0; i < rCurParticles; ++i)
- {
- UpdateParticle(i,elapsed);
- if(rParticles[i].xPos < 0 || rParticles[i].xPos > rEngine->DisplayWidth()
- || rParticles[i].yPos < 0 || rParticles[i].yPos > rEngine->DisplayHeight() || rParticles[i].energy <= 0)
- {
- rParticles[i] = rParticles[--rCurParticles];
- --i; //go back one to process that particle
- }
- }
-
- emitAmount = elapsed*rNumParticlesPerSec;
- overflow += emitAmount - static_cast(emitAmount); //only floating point portion of emitAmount
- Emit(static_cast(emitAmount));
- if(overflow >= .95) //a little lower than one, for tolerance
- {
- Emit(1);
- overflow = 0; //dump & clear overflow
- }
- }
-
- rLastUpdate = rEngine->GetTime();
-}
-
-
-template
-void ZBaseParticleSystem::Clear()
-{
- rCurParticles = 0;
-}
-
-template
-void ZBaseParticleSystem::Pause()
-{
- rPaused = true;
-}
-
-template
-void ZBaseParticleSystem::Unpause()
-{
- rPaused = false;
-}
-
-template
-void ZBaseParticleSystem::Stop()
-{
- Clear();
- Pause();
-}
-
-template
-bool ZBaseParticleSystem::Paused()
-{
- return rPaused;
-}
-
-template
-void ZBaseParticleSystem::SetMaxParticles(int max)
-{
- particleType *temp;
- unsigned int i;
-
- if(max)
- {
- if(max != rMaxParticles) //only do this if size changed
- {
- if(rCurParticles)
- {
- rCurParticles %= max;
- //copy current particles to temp
- temp = new particleType[rCurParticles];
- for(i=0; i < rCurParticles; ++i)
- temp[i] = rParticles[i];
- }
-
- //change size of rParticles
- if(rParticles)
- delete []rParticles;
- rParticles = new particleType[max];
- rMaxParticles = max;
-
- if(rCurParticles)
- {
- //copy particles from temp back to rParticles
- for(i=0; i < rCurParticles; ++i)
- rParticles[i] = temp[i];
-
- delete []temp;
- }
- }
- }
- else
- {
- rMaxParticles = rCurParticles = 0;
- if(rParticles)
- delete []rParticles;
- }
-}
-
-template
-void ZBaseParticleSystem::SetRate(int rate)
-{
- rNumParticlesPerSec = rate;
-}
-
-} //namespace ZE
-
-#endif //__ze_zbaseparticlesystem_h__
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ Licensed under a BSD-style license.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/*!
+ \file ZE_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__
+
+#include "ZEngine.h"
+
+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.
+ **/
+ 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.
+ **/
+ 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 SetRate(unsigned int rate);
+};
+
+//implementation//
+
+template
+void ZBaseParticleSystem::AddParticle()
+{
+ //empty space is always at end, function is private so no checking is needed (Emit does that)
+ rParticles[rCurParticles] = NewParticle();
+ ++rCurParticles;
+}
+
+template
+ZBaseParticleSystem::ZBaseParticleSystem()
+{
+ rEngine = ZEngine::GetInstance();
+ rParticles = NULL;
+ rMaxParticles = rCurParticles = rNumParticlesPerSec = 0;
+ rLastUpdate = rEngine->GetTime();
+ rPaused = false;
+}
+
+template
+ZBaseParticleSystem::~ZBaseParticleSystem()
+{
+ if(rParticles)
+ delete []rParticles;
+}
+
+template
+void ZBaseParticleSystem::Emit(int numParticles)
+{
+ while(numParticles > 0 && rCurParticles < rMaxParticles)
+ {
+ AddParticle();
+ --numParticles;
+ }
+}
+
+template
+void ZBaseParticleSystem::Update()
+{
+ float elapsed = (rEngine->GetTime()-rLastUpdate)/1000.0f;
+ double emitAmount;
+ static double overflow=0;
+
+ if(!rPaused)
+ {
+ //update every particle and remove dead particles
+ for(unsigned int i=0; i < rCurParticles; ++i)
+ {
+ UpdateParticle(i,elapsed);
+ if(rParticles[i].xPos < 0 || rParticles[i].xPos > rEngine->DisplayWidth()
+ || rParticles[i].yPos < 0 || rParticles[i].yPos > rEngine->DisplayHeight() || rParticles[i].energy <= 0)
+ {
+ rParticles[i] = rParticles[--rCurParticles];
+ --i; //go back one to process that particle
+ }
+ }
+
+ emitAmount = elapsed*rNumParticlesPerSec;
+ overflow += emitAmount - static_cast(emitAmount); //only floating point portion of emitAmount
+ Emit(static_cast(emitAmount));
+ if(overflow >= .95) //a little lower than one, for tolerance
+ {
+ Emit(1);
+ overflow = 0; //dump & clear overflow
+ }
+ }
+
+ rLastUpdate = rEngine->GetTime();
+}
+
+
+template
+void ZBaseParticleSystem::Clear()
+{
+ rCurParticles = 0;
+}
+
+template
+void ZBaseParticleSystem::Pause()
+{
+ rPaused = true;
+}
+
+template
+void ZBaseParticleSystem::Unpause()
+{
+ rPaused = false;
+}
+
+template
+void ZBaseParticleSystem::Stop()
+{
+ Clear();
+ Pause();
+}
+
+template
+bool ZBaseParticleSystem::Paused()
+{
+ return rPaused;
+}
+
+template
+void ZBaseParticleSystem::SetMaxParticles(unsigned int max)
+{
+ particleType *temp;
+ unsigned int i;
+
+ if(max)
+ {
+ if(max != rMaxParticles) //only do this if size changed
+ {
+ if(rCurParticles)
+ {
+ rCurParticles %= max;
+ //copy current particles to temp
+ temp = new particleType[rCurParticles];
+ for(i=0; i < rCurParticles; ++i)
+ temp[i] = rParticles[i];
+ }
+
+ //change size of rParticles
+ if(rParticles)
+ delete []rParticles;
+ rParticles = new particleType[max];
+ rMaxParticles = max;
+
+ if(rCurParticles)
+ {
+ //copy particles from temp back to rParticles
+ for(i=0; i < rCurParticles; ++i)
+ rParticles[i] = temp[i];
+
+ delete []temp;
+ }
+ }
+ }
+ else
+ {
+ rMaxParticles = rCurParticles = 0;
+ if(rParticles)
+ delete []rParticles;
+ }
+}
+
+template
+void ZBaseParticleSystem::SetRate(unsigned int rate)
+{
+ rNumParticlesPerSec = rate;
+}
+
+} //namespace ZE
+
+#endif //__ze_zbaseparticlesystem_h__
diff --git a/include/ZE_ZEngine.h b/include/ZE_ZEngine.h
index 7415afc..2e1a3f4 100644
--- a/include/ZE_ZEngine.h
+++ b/include/ZE_ZEngine.h
@@ -1,756 +1,754 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- Licensed under a BSD-style license.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/*!
- \file ZE_ZEngine.h
- \brief Definition file for core ZEngine class.
-
- ZEngine Game Engine core Engine definition.
-
$Id: ZE_ZEngine.h,v 1.43 2003/07/11 20:51:44 cozman Exp $
- \author James Turk
-**/
-
-//revision on this is so high.. can this be lowered?
-
-#ifndef __ze_zengine_h__
-#define __ze_zengine_h__
-
-#include "ZE_Defines.h"
-#include "ZE_Utility.h"
-#include "ZE_Includes.h"
-#include "ZE_ZError.h"
-#include "ZE_ZRandGen.h"
-#include "VersionInfo.h"
-
-/*!
- \brief ZEngine Namespace.
-
- Namespace for ZEngine classes and utility functions.
-**/
-namespace ZE
-{
-
-/*!
- \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;
- //! Width of Display
- int mWidth;
- //! Height of Display
- int mHeight;
- //! BPP Setting of Display
- int mBPP;
- //! Fullscreen setting of Display
- bool mFullscreen;
- //! If ZEngine display has been setup.
- bool mInitialized;
- //! Pointer to Display
- SDL_Surface *mScreen;
- //! Keep track of paused state of game.
- bool mPaused;
- //! Keep track of if ZEngine should unpause on active event.
- bool mUnpauseOnActive;
- //! Value framerate strives to be at, set by SetDesiredFramerate.
- Uint8 mDesiredFramerate;
- //! 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.
- double mSecPerFrame;
- //! bool which is only set to true if the 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;
- //! Stack of Errors which have occured.
- std::queue mErrorQueue;
- //! Current error.
- ZError mCurError;
- //! Option controlling how logfile is used.
- bool mLogAllErrors;
- //! 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;
-
-#ifdef USE_SDL_MIXER
- //! Sound Bitrate
- int mRate;
- //! Stereo setting of Sound Subsystem
- bool mStereo;
-#endif
-
- /////////////////////////////////
- //Singleton + Memory Management//
- /////////////////////////////////
-
- private:
- /*!
- \brief Constructor for ZEngine.
-
- Initialize ZEngine values to defaults. (Private so that only one instance may be created.)
- **/
- ZEngine();
-
- 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 Setup Display for SDL.
-
- Sets display parameters to specified parameters. (called before CreateDisplay)
-
- \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.
- **/
- void SetupDisplay(int width, int height, int bpp, bool fullscreen);
-
-#ifdef USE_SDL_MIXER
- /*!
- \brief Initialize Sound for SDL.
-
- Set sound settings to specified parameters. (If not called before CreateDisplay rate will default to 22050+mono)
-
- \param rate Desired sound bitrate.
- \param stereo A bool for stereo setting.
- **/
- void SetupSound(int rate, bool stereo);
-#endif
-
- /*!
- \brief Create Display with predefined settings.
-
- SetupDisplay and SetupSound should be called prior to this to change settings, settings from those do not go into effect
- until this function is called. Specify no icon file to use default icon for OS. Returns result of setting up ZEngine, and logs
- error if false is returned (Trys not to fail + returns bool in versions >= 0.8.2).
-
- \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(std::string title, 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.
- **/
- 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.0-1.0) of new color.
- \param green Green component (0.0-1.0) of new color.
- \param blue Blue component (0.0-1.0) of new color.
- \param alpha Alpha component (0.0-1.0) of new color.
- **/
- void Clear(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=1.0f);
-
- /////////////////////////////
- //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.
- **/
- void SetGL2D();
-
- ////////////////////////////////////////////
- //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();
-
- /*!
- \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();
-
- /*!
- \brief Set Desired Framerate.
-
- Sets desired framerate, if engine gets ahead of desired rate during a frame it will stall in Update until
- current framerate is closer to that desired. Acceptable values are 1-255, setting this value to 0 will disable this
- feature. (Desired framerate is disabled upon initialization of ZEngine.)
- \since 0.8.2
- \param rate Desired framerate 1-255, or 0 to disable.
- **/
- void SetDesiredFramerate(Uint8 rate);
-
- /*!
- \brief Get Desired Framerate.
-
- Get desired framerate set by SetDesiredFramerate.
- \since 0.8.2
- \return Current setting for desired framerate.
- **/
- Uint8 GetDesiredFramerate();
-
- /*!
- \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.
-
- 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.
- \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.
- \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 Check if mouse is in given rectangle.
-
- Return status of mouse in current rectangle (used for buttons)
- \param rect Rectangle to check if mouse is in.
- \return true if mouse is in rectangle, false otherwise
- **/
- bool MouseInRect(SDL_Rect *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.
- **/
- 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);
-
-#ifdef USE_PHYSFS
- ////////////////////
- //Physfs Utilities//
- ////////////////////
- /*!
- \brief Initialize PhysicsFS
-
- Sets up PhysicsFS, must be called when application is started.
- \param argv argv[0] from application's main.
- **/
- void InitPhysFS(std::string argv);
-
- /*!
- \brief Add Directory to PhysFS Search Path.
-
- Add Directory to PhysicsFS search path, the path it looks in for files when attempting to load.
- \param dir Directory to add to search path.
- **/
- void AddPhysFSDir(std::string dir);
-
-#endif //USE_PHYSFS
-
- /////////////////
- //Error Logging//
- /////////////////
- private:
- /*!
- \brief Writes an error to file.
-
- Writes error to current error file.
- \since 0.8.2
- \param error ZError to write to file.
- **/
- void LogError(ZError error);
-
- 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.2
- \param logAll If set to true every error will be written to file instead of stored in the logfile.
- \param logFile Name of file to use as log, passing in stderr or stdio will set the log to the C streams.
- Passing in nothing will not change the current error log file, which defaults to stderr.
- **/
- void SetErrorLog(bool logAll, std::string logFile="");
-
- /*!
- \brief Report an error.
-
- Adds the error to the the error queue, and sets the current error to this error.
- \since 0.8.2
- \param code ZErrorCode of error.
- \param desc Optional std::string describing error.
- \param file Optional argument specifying the file the error occured in.
- \param line Optional argument specifying the line the error occured on.
- **/
- void ReportError(ZErrorCode code, std::string desc="", std::string file="", unsigned int line=0);
-
- /*!
- \brief Get the last error.
-
- Get the last error reported.
- \since 0.8.2
- \return ZErrorCode of last error reported.
- **/
- ZErrorCode GetLastError();
-
- /*!
- \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 WriteLog(std::string str);
-
- /*!
- \brief Flush Stack of Errors to file.
-
- Write the error stack to the error log.
- \since 0.8.2
- **/
- void FlushErrors();
-
- ////////////////////////////
- //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 RandDouble();
-
- ////////////////////////////
- //Data Loading + Unloading//
- ////////////////////////////
- /*!
- \brief Load an Image.
-
- Loads an Image to an ImageData class which keeps vital information on the Image.
- \param filename path to file to load.
- \return A SDL_Surface pointer to data.
- **/
- SDL_Surface* LoadImage(std::string filename);
-
-#ifdef USE_SDL_MIXER
- /*!
- \brief Load a Sound
-
- Loads a Sound to a SoundData class which keeps vital information on the Sound
- \param filename path to file to load.
- \return A Mix_Chunk pointer to data.
- **/
- Mix_Chunk* LoadSound(std::string filename);
-
- /*!
- \brief Load a Music File
-
- Loads a Music Clip to a MusicData class which keeps vital information on the Music Data
- \param filename path to file to load.
- \return A Mix_Music pointer to data.
- **/
- Mix_Music* LoadMusic(std::string filename);
-#endif
-
-#ifdef USE_SDL_TTF
- /*!
- \brief Load a Font.
-
- Loads a Font to a FontData class which keeps vital information on the Font
- \param filename path to file to load.
- \param size point size of font
- \return A TTF_Font pointer to data.
- **/
- TTF_Font* LoadFont(std::string filename, int size);
-#endif
-
- /////////////
- //Accessors//
- /////////////
-
- /*!
- \brief Get Current Display Width.
-
- Get Width of Window or Fullscreen mode.
- \return Width of Display.
- **/
- int DisplayWidth();
-
- /*!
- \brief Get Current Display Height.
-
- Get Height of Window or Fullscreen mode.
- \return Height of Display.
- **/
- int DisplayHeight();
-
- /*!
- \brief Get Current Display BPP.
-
- Get color depth of Window or Fullscreen mode. BPP means bits per pixel.
- \return BPP or depth of Display.
- **/
- int DisplayDepth();
-
-#ifdef DEPRECIATED
- /*!
- \brief Get Current Display Width.
-
- Get Width of Window or Fullscreen mode.
- \return Width of Display.
- **/
- int Width();
-
- /*!
- \brief Get Current Display Height.
-
- Get Height of Window or Fullscreen mode.
- \return Height of Display.
- **/
- int Height();
-
- /*!
- \brief Get Current Display BPP.
-
- Get BPP of Window or Fullscreen mode.
- \return BPP of Display.
- **/
- int BPP();
-#endif //DEPRECIATED
-
- /*!
- \brief Get Fullscreen setting.
-
- Get Fullscreen setting of Display.
- \return True if Fullscreen, False if Windowed
- **/
- bool IsFullscreen();
-};
-
-}
-
-#endif //__ze_zengine_h__
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ Licensed under a BSD-style license.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/*!
+ \file ZE_ZEngine.h
+ \brief Definition file for core ZEngine class.
+
+ ZEngine Game Engine core Engine definition.
+
$Id: ZE_ZEngine.h,v 1.44 2003/07/12 01:25:42 cozman Exp $
+ \author James Turk
+**/
+
+#ifndef __ze_zengine_h__
+#define __ze_zengine_h__
+
+#include "ZE_Defines.h"
+#include "ZE_Utility.h"
+#include "ZE_Includes.h"
+#include "ZE_ZError.h"
+#include "ZE_ZRandGen.h"
+#include "VersionInfo.h"
+
+/*!
+ \brief ZEngine Namespace.
+
+ Namespace for ZEngine classes and utility functions.
+**/
+namespace ZE
+{
+
+/*!
+ \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;
+ //! Width of Display
+ int mWidth;
+ //! Height of Display
+ int mHeight;
+ //! BPP Setting of Display
+ int mBPP;
+ //! Fullscreen setting of Display
+ bool mFullscreen;
+ //! If ZEngine display has been setup.
+ bool mInitialized;
+ //! Pointer to Display
+ SDL_Surface *mScreen;
+ //! Keep track of paused state of game.
+ bool mPaused;
+ //! Keep track of if ZEngine should unpause on active event.
+ bool mUnpauseOnActive;
+ //! Value framerate strives to be at, set by SetDesiredFramerate.
+ Uint8 mDesiredFramerate;
+ //! 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.
+ double mSecPerFrame;
+ //! bool which is only set to true if the 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;
+ //! Stack of Errors which have occured.
+ std::queue mErrorQueue;
+ //! Current error.
+ ZError mCurError;
+ //! Option controlling how logfile is used.
+ bool mLogAllErrors;
+ //! 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;
+
+#ifdef USE_SDL_MIXER
+ //! Sound Bitrate
+ int mRate;
+ //! Stereo setting of Sound Subsystem
+ bool mStereo;
+#endif
+
+ /////////////////////////////////
+ //Singleton + Memory Management//
+ /////////////////////////////////
+
+ private:
+ /*!
+ \brief Constructor for ZEngine.
+
+ Initialize ZEngine values to defaults. (Private so that only one instance may be created.)
+ **/
+ ZEngine();
+
+ 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 Setup Display for SDL.
+
+ Sets display parameters to specified parameters. (called before CreateDisplay)
+
+ \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.
+ **/
+ void SetupDisplay(int width, int height, int bpp, bool fullscreen);
+
+#ifdef USE_SDL_MIXER
+ /*!
+ \brief Initialize Sound for SDL.
+
+ Set sound settings to specified parameters. (If not called before CreateDisplay rate will default to 22050+mono)
+
+ \param rate Desired sound bitrate.
+ \param stereo A bool for stereo setting.
+ **/
+ void SetupSound(int rate, bool stereo);
+#endif
+
+ /*!
+ \brief Create Display with predefined settings.
+
+ SetupDisplay and SetupSound should be called prior to this to change settings, settings from those do not go into effect
+ until this function is called. Specify no icon file to use default icon for OS. Returns result of setting up ZEngine, and logs
+ error if false is returned (Trys not to fail + returns bool in versions >= 0.8.2).
+
+ \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(std::string title, 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.
+ **/
+ 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.0-1.0) of new color.
+ \param green Green component (0.0-1.0) of new color.
+ \param blue Blue component (0.0-1.0) of new color.
+ \param alpha Alpha component (0.0-1.0) of new color.
+ **/
+ void Clear(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=1.0f);
+
+ /////////////////////////////
+ //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.
+ **/
+ void SetGL2D();
+
+ ////////////////////////////////////////////
+ //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();
+
+ /*!
+ \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();
+
+ /*!
+ \brief Set Desired Framerate.
+
+ Sets desired framerate, if engine gets ahead of desired rate during a frame it will stall in Update until
+ current framerate is closer to that desired. Acceptable values are 1-255, setting this value to 0 will disable this
+ feature. (Desired framerate is disabled upon initialization of ZEngine.)
+ \since 0.8.2
+ \param rate Desired framerate 1-255, or 0 to disable.
+ **/
+ void SetDesiredFramerate(Uint8 rate);
+
+ /*!
+ \brief Get Desired Framerate.
+
+ Get desired framerate set by SetDesiredFramerate.
+ \since 0.8.2
+ \return Current setting for desired framerate.
+ **/
+ Uint8 GetDesiredFramerate();
+
+ /*!
+ \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.
+
+ 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.
+ \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.
+ \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 Check if mouse is in given rectangle.
+
+ Return status of mouse in current rectangle (used for buttons)
+ \param rect Rectangle to check if mouse is in.
+ \return true if mouse is in rectangle, false otherwise
+ **/
+ bool MouseInRect(SDL_Rect *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.
+ **/
+ 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);
+
+#ifdef USE_PHYSFS
+ ////////////////////
+ //Physfs Utilities//
+ ////////////////////
+ /*!
+ \brief Initialize PhysicsFS
+
+ Sets up PhysicsFS, must be called when application is started.
+ \param argv argv[0] from application's main.
+ **/
+ void InitPhysFS(std::string argv);
+
+ /*!
+ \brief Add Directory to PhysFS Search Path.
+
+ Add Directory to PhysicsFS search path, the path it looks in for files when attempting to load.
+ \param dir Directory to add to search path.
+ **/
+ void AddPhysFSDir(std::string dir);
+
+#endif //USE_PHYSFS
+
+ /////////////////
+ //Error Logging//
+ /////////////////
+ private:
+ /*!
+ \brief Writes an error to file.
+
+ Writes error to current error file.
+ \since 0.8.2
+ \param error ZError to write to file.
+ **/
+ void LogError(ZError error);
+
+ 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.2
+ \param logAll If set to true every error will be written to file instead of stored in the logfile.
+ \param logFile Name of file to use as log, passing in stderr or stdio will set the log to the C streams.
+ Passing in nothing will not change the current error log file, which defaults to stderr.
+ **/
+ void SetErrorLog(bool logAll, std::string logFile="");
+
+ /*!
+ \brief Report an error.
+
+ Adds the error to the the error queue, and sets the current error to this error.
+ \since 0.8.2
+ \param code ZErrorCode of error.
+ \param desc Optional std::string describing error.
+ \param file Optional argument specifying the file the error occured in.
+ \param line Optional argument specifying the line the error occured on.
+ **/
+ void ReportError(ZErrorCode code, std::string desc="", std::string file="", unsigned int line=0);
+
+ /*!
+ \brief Get the last error.
+
+ Get the last error reported.
+ \since 0.8.2
+ \return ZErrorCode of last error reported.
+ **/
+ ZErrorCode GetLastError();
+
+ /*!
+ \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 WriteLog(std::string str);
+
+ /*!
+ \brief Flush Stack of Errors to file.
+
+ Write the error stack to the error log.
+ \since 0.8.2
+ **/
+ void FlushErrors();
+
+ ////////////////////////////
+ //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 RandDouble();
+
+ ////////////////////////////
+ //Data Loading + Unloading//
+ ////////////////////////////
+ /*!
+ \brief Load an Image.
+
+ Loads an Image to an ImageData class which keeps vital information on the Image.
+ \param filename path to file to load.
+ \return A SDL_Surface pointer to data.
+ **/
+ SDL_Surface* LoadImage(std::string filename);
+
+#ifdef USE_SDL_MIXER
+ /*!
+ \brief Load a Sound
+
+ Loads a Sound to a SoundData class which keeps vital information on the Sound
+ \param filename path to file to load.
+ \return A Mix_Chunk pointer to data.
+ **/
+ Mix_Chunk* LoadSound(std::string filename);
+
+ /*!
+ \brief Load a Music File
+
+ Loads a Music Clip to a MusicData class which keeps vital information on the Music Data
+ \param filename path to file to load.
+ \return A Mix_Music pointer to data.
+ **/
+ Mix_Music* LoadMusic(std::string filename);
+#endif
+
+#ifdef USE_SDL_TTF
+ /*!
+ \brief Load a Font.
+
+ Loads a Font to a FontData class which keeps vital information on the Font
+ \param filename path to file to load.
+ \param size point size of font
+ \return A TTF_Font pointer to data.
+ **/
+ TTF_Font* LoadFont(std::string filename, int size);
+#endif
+
+ /////////////
+ //Accessors//
+ /////////////
+
+ /*!
+ \brief Get Current Display Width.
+
+ Get Width of Window or Fullscreen mode.
+ \return Width of Display.
+ **/
+ int DisplayWidth();
+
+ /*!
+ \brief Get Current Display Height.
+
+ Get Height of Window or Fullscreen mode.
+ \return Height of Display.
+ **/
+ int DisplayHeight();
+
+ /*!
+ \brief Get Current Display BPP.
+
+ Get color depth of Window or Fullscreen mode. BPP means bits per pixel.
+ \return BPP or depth of Display.
+ **/
+ int DisplayDepth();
+
+#ifdef DEPRECIATED
+ /*!
+ \brief Get Current Display Width.
+
+ Get Width of Window or Fullscreen mode.
+ \return Width of Display.
+ **/
+ int Width();
+
+ /*!
+ \brief Get Current Display Height.
+
+ Get Height of Window or Fullscreen mode.
+ \return Height of Display.
+ **/
+ int Height();
+
+ /*!
+ \brief Get Current Display BPP.
+
+ Get BPP of Window or Fullscreen mode.
+ \return BPP of Display.
+ **/
+ int BPP();
+#endif //DEPRECIATED
+
+ /*!
+ \brief Get Fullscreen setting.
+
+ Get Fullscreen setting of Display.
+ \return True if Fullscreen, False if Windowed
+ **/
+ bool IsFullscreen();
+};
+
+}
+
+#endif //__ze_zengine_h__
diff --git a/include/ZE_ZRandGen.h b/include/ZE_ZRandGen.h
index 063c53c..9800414 100755
--- a/include/ZE_ZRandGen.h
+++ b/include/ZE_ZRandGen.h
@@ -1,162 +1,163 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- Licensed under a BSD-style license.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/*!
- \file ZE_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.1 2003/07/05 01:05:47 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.
- int 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();
-};
-
-}
-
-#endif //__ze_zrandgen_h__
\ No newline at end of file
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ Licensed under a BSD-style license.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/*!
+ \file ZE_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();
+};
+
+}
+
+#endif //__ze_zrandgen_h__
+
diff --git a/src/VersionInfo.cpp b/src/VersionInfo.cpp
index a2cff27..95c7d8f 100755
--- a/src/VersionInfo.cpp
+++ b/src/VersionInfo.cpp
@@ -1,57 +1,57 @@
-#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.4 2003/06/11 05:51:15 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)
-{
-}
-
-
+#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.5 2003/07/12 01:25:42 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
{
- if(extra.length())
- return ZE::FormatStr("%d.%d.%d [%s]",major,minor,release,extra.c_str());
+ if(Extra.length())
+ return ZE::FormatStr("%d.%d.%d [%s]",Major,Minor,Release,Extra.c_str());
else
- return ZE::FormatStr("%d.%d.%d",major,minor,release);
-}
-
-bool VersionInfo::operator<(const VersionInfo &rhs) const
-{
- //chained compares, compare numbers in order of importance
- if(this->major < rhs.major)
- return true;
- else if(this->major == rhs.major)
- {
- if(this->minor < rhs.minor)
- return true;
- else if(this->minor == rhs.minor)
- {
- if(this->release < rhs.release)
- return true;
- else if(this->release == rhs.release)
- {
- return this->extra < rhs.extra; //just compare the strings at the end
- }
- }
- }
- return false; //if it reaches this point rhs is >=
-}
-
-bool VersionInfo::operator==(const VersionInfo &rhs) const
-{
- return this->GetString() == rhs.GetString(); //only equal data produces equal strings
-}
-
-bool VersionInfo::operator>(const VersionInfo &rhs) const
-{
- return !((*this) < rhs || (*this) == rhs); //if not < and not ==, must be >
-}
+ return ZE::FormatStr("%d.%d.%d",Major,Minor,Release);
+}
+
+bool VersionInfo::operator<(const VersionInfo &rhs) const
+{
+ //chained compares, compare numbers in order of importance
+ if(this->Major < rhs.Major)
+ return true;
+ else if(this->Major == rhs.Major)
+ {
+ if(this->Minor < rhs.Minor)
+ return true;
+ else if(this->Minor == rhs.Minor)
+ {
+ if(this->Release < rhs.Release)
+ return true;
+ else if(this->Release == rhs.Release)
+ {
+ return this->Extra < rhs.Extra; //just compare the strings at the end
+ }
+ }
+ }
+ return false; //if it reaches this point rhs is >=
+}
+
+bool VersionInfo::operator==(const VersionInfo &rhs) const
+{
+ return this->GetString() == rhs.GetString(); //only equal data produces equal strings
+}
+
+bool VersionInfo::operator>(const VersionInfo &rhs) const
+{
+ return !((*this) < rhs || (*this) == rhs); //if not < and not ==, must be >
+}
diff --git a/src/ZE_Utility.cpp b/src/ZE_Utility.cpp
index 1d1ec10..5ca6b46 100755
--- a/src/ZE_Utility.cpp
+++ b/src/ZE_Utility.cpp
@@ -1,82 +1,82 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- Licensed under a BSD-style license.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/**
- \file ZE_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.9 2003/06/11 05:51:15 cozman Exp $
- \author James Turk
-**/
-
-#include "ZE_Utility.h"
-
-namespace ZE
-{
-
-std::string FormatStr(const char *fmtstr, ...)
-{
- char buf[512];
- va_list args;
- //simply puts args into the buffer using standard parsing rules
- va_start(args,fmtstr);
- vsprintf(buf, fmtstr, args);
- va_end(args);
- return buf;
-}
-
-//Each of the Free*s safely frees & NULLs the pointer
-void FreeImage(SDL_Surface *&image)
-{
- if(image)
- {
- SDL_FreeSurface(image);
- image = NULL;
- }
-}
-
-#ifdef USE_SDL_MIXER
-
-void FreeSound(Mix_Chunk *&chunk)
-{
- if(chunk)
- {
- Mix_FreeChunk(chunk);
- chunk = NULL;
- }
-}
-
-void FreeMusic(Mix_Music *&music)
-{
- if(music)
- {
- Mix_FreeMusic(music);
- music = NULL;
- }
-}
-
-#endif
-
-#ifdef USE_SDL_TTF
-
-void FreeFont(TTF_Font *&font)
-{
- if(font)
- {
- TTF_CloseFont(font);
- font = NULL;
- }
-}
-
-#endif
-
-}
-
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ Licensed under a BSD-style license.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/**
+ \file ZE_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.10 2003/07/12 01:25:42 cozman Exp $
+ \author James Turk
+**/
+
+#include "ZE_Utility.h"
+
+namespace ZE
+{
+
+std::string FormatStr(const char *fmtstr, ...)
+{
+ char buf[512];
+ va_list args;
+ //simply puts args into the buffer using standard parsing rules
+ va_start(args,fmtstr);
+ vsprintf(buf, fmtstr, args);
+ va_end(args);
+ return buf;
+}
+
+//Each of the Free*s safely frees & NULLs the pointer
+void FreeImage(SDL_Surface *&image)
+{
+ if(image)
+ {
+ SDL_FreeSurface(image);
+ image = NULL;
+ }
+}
+
+#ifdef USE_SDL_MIXER
+
+void FreeSound(Mix_Chunk *&chunk)
+{
+ if(chunk)
+ {
+ Mix_FreeChunk(chunk);
+ chunk = NULL;
+ }
+}
+
+void FreeMusic(Mix_Music *&music)
+{
+ if(music)
+ {
+ Mix_FreeMusic(music);
+ music = NULL;
+ }
+}
+
+#endif
+
+#ifdef USE_SDL_TTF
+
+void FreeFont(TTF_Font *&font)
+{
+ if(font)
+ {
+ TTF_CloseFont(font);
+ font = NULL;
+ }
+}
+
+#endif
+
+}
+
diff --git a/src/ZE_ZEngine.cpp b/src/ZE_ZEngine.cpp
index cf1fa21..1caf998 100644
--- a/src/ZE_ZEngine.cpp
+++ b/src/ZE_ZEngine.cpp
@@ -13,7 +13,7 @@
\brief Central source file for ZEngine.
Actual implementation of ZEngine singleton class, the core of ZEngine.
-
$Id: ZE_ZEngine.cpp,v 1.51 2003/07/11 20:51:44 cozman Exp $
+
$Id: ZE_ZEngine.cpp,v 1.52 2003/07/12 01:25:42 cozman Exp $
\author James Turk
**/
@@ -25,18 +25,18 @@ namespace ZE
VersionInfo ZEngine::Version(0,8,4);
ZEngine *ZEngine::sInstance=NULL;
-ZEngine::ZEngine() :
- mInitialized(false), mWidth(800), mHeight(600), mBPP(-1), mFullscreen(true),
-#ifdef USE_SDL_MIXER
- mRate(22050), mStereo(false),
-#endif
- mNeedReload(false),mScreen(NULL),
- mEventFilter(NULL), mActive(false), mQuit(false), mKeyIsPressed(NULL),
- mMouseX(0), mMouseY(0), mMouseB(0),
- mUnpauseOnActive(false), mPaused(false),
+ZEngine::ZEngine() :
+ mWidth(800), mHeight(600), mBPP(-1), mFullscreen(true), mInitialized(false),
+ mScreen(NULL),
+ mPaused(false), mUnpauseOnActive(false),
mDesiredFramerate(0), mNextUpdate(0), mLastPause(0), mPausedTime(0), mLastTime(0),
mSecPerFrame(0.0),
- mLogAllErrors(true), mErrlog(stderr)
+ mNeedReload(false), mActive(false), mQuit(false), mKeyIsPressed(NULL),
+ mMouseX(0), mMouseY(0), mMouseB(0),
+ mLogAllErrors(true), mErrlog(stderr), mEventFilter(NULL)
+#ifdef USE_SDL_MIXER
+ , mRate(22050), mStereo(false)
+#endif
{
for(int k = 0; k < SDLK_LAST; ++k)
mKeyPress[k] = false;
@@ -273,15 +273,15 @@ void ZEngine::ToggleFullscreen()
SDL_WM_ToggleFullScreen(mScreen);
#else
char *title,*icon;
-
- SetupDisplay(mWidth,mHeight,mBPP,!mFullscreen);
-
- SDL_WM_GetCaption(&title,&icon);
- if(icon)
- CreateDisplay(title,icon);
- else
- CreateDisplay(title);
-#endif
+
+ SetupDisplay(mWidth,mHeight,mBPP,!mFullscreen);
+
+ SDL_WM_GetCaption(&title,&icon);
+ if(icon)
+ CreateDisplay(title,icon);
+ else
+ CreateDisplay(title);
+#endif
SetReloadNeed(true); //images need to be reloaded on fullscreen swap
}
diff --git a/src/ZE_ZRandGen.cpp b/src/ZE_ZRandGen.cpp
index 06b92a6..28baba0 100755
--- a/src/ZE_ZRandGen.cpp
+++ b/src/ZE_ZRandGen.cpp
@@ -1,139 +1,139 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- Licensed under a BSD-style license.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/**
- \file ZE_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.1 2003/07/05 00:58:08 cozman Exp $
- \author James Turk, some code from Mersenne Twister.
-**/
-
-#include "ZE_ZRandGen.h"
-
-namespace ZE
-{
-
-/*
- The source in this file is based on MT19937, with much of the source
- replicated from mt19937ar.c, because of this the original license
- for that file is below.
- -James
-
-
- A C-program for MT19937, with initialization improved 2002/1/26.
- Coded by Takuji Nishimura and Makoto Matsumoto.
-
- Before using, initialize the state by using init_genrand(seed)
- or init_by_array(init_key, key_length).
-
- Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. The names of its contributors may not be used to endorse or promote
- products derived from this software without specific prior written
- permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
- Any feedback is very welcome.
- http://www.math.keio.ac.jp/matumoto/emt.html
- email: matumoto@math.keio.ac.jp
-*/
-
-//adapted directly from mt19937ar : unsigned long genrand_int32(void)
-unsigned long ZRandGen::genrand_int32()
-{
- unsigned long y;
- static unsigned long mag01[2]={0x0UL, MATRIX_A};
- /* mag01[x] = x * MATRIX_A for x=0,1 */
-
- if (rStateVectorIndex >= N) { /* generate N words at one time */
- int kk;
-
- //removed uninitialized check, class initializes in constructor
-
- for (kk=0;kk> 1) ^ mag01[y & 0x1UL];
- }
- for (;kk> 1) ^ mag01[y & 0x1UL];
- }
- y = (rStateVector[N-1]&UPPER_MASK)|(rStateVector[0]&LOWER_MASK);
- rStateVector[N-1] = rStateVector[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
-
- rStateVectorIndex = 0;
- }
-
- y = rStateVector[rStateVectorIndex++];
-
- /* Tempering */
- y ^= (y >> 11);
- y ^= (y << 7) & 0x9d2c5680UL;
- y ^= (y << 15) & 0xefc60000UL;
- y ^= (y >> 18);
-
- return y;
-}
-
-ZRandGen::ZRandGen()
-{
- Seed(static_cast(std::time(NULL)));
-}
-
-ZRandGen::ZRandGen(unsigned long seed)
-{
- Seed(seed);
-}
-
-//adapted directly from mt19937ar : void init_genrand(unsigned long s)
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ Licensed under a BSD-style license.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/**
+ \file ZE_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
+{
+
+/*
+ The source in this file is based on MT19937, with much of the source
+ replicated from mt19937ar.c, because of this the original license
+ for that file is below.
+ -James
+
+
+ A C-program for MT19937, with initialization improved 2002/1/26.
+ Coded by Takuji Nishimura and Makoto Matsumoto.
+
+ Before using, initialize the state by using init_genrand(seed)
+ or init_by_array(init_key, key_length).
+
+ Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. The names of its contributors may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+ Any feedback is very welcome.
+ http://www.math.keio.ac.jp/matumoto/emt.html
+ email: matumoto@math.keio.ac.jp
+*/
+
+//adapted directly from mt19937ar : unsigned long genrand_int32(void)
+unsigned long ZRandGen::genrand_int32()
+{
+ unsigned long y;
+ static unsigned long mag01[2]={0x0UL, MATRIX_A};
+ /* mag01[x] = x * MATRIX_A for x=0,1 */
+
+ if (rStateVectorIndex >= N) { /* generate N words at one time */
+ unsigned int kk;
+
+ //removed uninitialized check, class initializes in constructor
+
+ for (kk=0;kk> 1) ^ mag01[y & 0x1UL];
+ }
+ for (;kk> 1) ^ mag01[y & 0x1UL];
+ }
+ y = (rStateVector[N-1]&UPPER_MASK)|(rStateVector[0]&LOWER_MASK);
+ rStateVector[N-1] = rStateVector[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
+
+ rStateVectorIndex = 0;
+ }
+
+ y = rStateVector[rStateVectorIndex++];
+
+ /* Tempering */
+ y ^= (y >> 11);
+ y ^= (y << 7) & 0x9d2c5680UL;
+ y ^= (y << 15) & 0xefc60000UL;
+ y ^= (y >> 18);
+
+ return y;
+}
+
+ZRandGen::ZRandGen()
+{
+ Seed(static_cast(std::time(NULL)));
+}
+
+ZRandGen::ZRandGen(unsigned long seed)
+{
+ Seed(seed);
+}
+
+//adapted directly from mt19937ar : void init_genrand(unsigned long s)
void ZRandGen::Seed(unsigned long s)
{
- rStateVector[0]= s & 0xffffffffUL;
- for(rStateVectorIndex=1; rStateVectorIndex> 30)) + rStateVectorIndex);
- /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
- /* In the previous versions, MSBs of the seed affect */
- /* only MSBs of the array rStateVector[]. */
- /* 2002/01/09 modified by Makoto Matsumoto */
- rStateVector[rStateVectorIndex] &= 0xffffffffUL;
- /* for >32 bit machines */
+ rStateVector[0]= s & 0xffffffffUL;
+ for(rStateVectorIndex=1; rStateVectorIndex> 30)) + rStateVectorIndex);
+ /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
+ /* In the previous versions, MSBs of the seed affect */
+ /* only MSBs of the array rStateVector[]. */
+ /* 2002/01/09 modified by Makoto Matsumoto */
+ rStateVector[rStateVectorIndex] &= 0xffffffffUL;
+ /* for >32 bit machines */
}
}
diff --git a/src/ZE_ZTimer.cpp b/src/ZE_ZTimer.cpp
index 6f28d8c..5ba4d44 100644
--- a/src/ZE_ZTimer.cpp
+++ b/src/ZE_ZTimer.cpp
@@ -1,83 +1,82 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- Licensed under a BSD-style license.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/**
- \file ZE_ZTimer.cpp
- \brief Source file for ZTimer.
-
- Implementation of ZTimer, the basic Timer class for ZEngine.
-
$Id: ZE_ZTimer.cpp,v 1.9 2003/06/11 05:51:16 cozman Exp $
- \author James Turk
-**/
-
-#include "ZE_ZTimer.h"
-
-namespace ZE
-{
-
-Uint32 ZTimer::GetParentTime() const
-{
- if(rUseZEngine)
- return rEngine->GetTime();
- else
- return SDL_GetTicks();
-}
-
-ZTimer::ZTimer(bool useZEngine) :
- rEngine(ZEngine::GetInstance()),
- rUseZEngine(useZEngine),
- rPaused(false)
-{
- Reset();
-}
-
-ZTimer::~ZTimer()
-{
-}
-
-void ZTimer::Reset()
-{
- rLastPause = rPausedTime = GetParentTime();
- rPaused = false;
-}
-
-void ZTimer::Pause()
-{
- if(!rPaused)
- {
- rLastPause = GetParentTime();
- rPaused = true;
- }
-}
-
-void ZTimer::Unpause()
-{
- if(rPaused)
- {
- //when unpausing update the total paused time by that pause
- rPausedTime += (GetParentTime()-rLastPause);
- rPaused = false;
- }
-}
-
-Uint32 ZTimer::GetTime() const
-{
- if(rPaused) //when paused timer adjusted to subtract currently paused time
- return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause));
- else
- return GetParentTime() - rPausedTime; //paused time is the cotal amt of time the program has been paused
-}
-
-bool ZTimer::IsPaused() const
-{
- return rPaused;
-}
-
-}
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ Licensed under a BSD-style license.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/**
+ \file ZE_ZTimer.cpp
+ \brief Source file for ZTimer.
+
+ Implementation of ZTimer, the basic Timer class for ZEngine.
+
$Id: ZE_ZTimer.cpp,v 1.10 2003/07/12 01:25:42 cozman Exp $
+ \author James Turk
+**/
+
+#include "ZE_ZTimer.h"
+
+namespace ZE
+{
+
+Uint32 ZTimer::GetParentTime() const
+{
+ if(rUseZEngine)
+ return rEngine->GetTime();
+ else
+ return SDL_GetTicks();
+}
+
+ZTimer::ZTimer(bool useZEngine) :
+ rEngine(ZEngine::GetInstance()),
+ rUseZEngine(useZEngine)
+{
+ Reset(); //initializes other members
+}
+
+ZTimer::~ZTimer()
+{
+}
+
+void ZTimer::Reset()
+{
+ rLastPause = rPausedTime = GetParentTime();
+ rPaused = false;
+}
+
+void ZTimer::Pause()
+{
+ if(!rPaused)
+ {
+ rLastPause = GetParentTime();
+ rPaused = true;
+ }
+}
+
+void ZTimer::Unpause()
+{
+ if(rPaused)
+ {
+ //when unpausing update the total paused time by that pause
+ rPausedTime += (GetParentTime()-rLastPause);
+ rPaused = false;
+ }
+}
+
+Uint32 ZTimer::GetTime() const
+{
+ if(rPaused) //when paused timer adjusted to subtract currently paused time
+ return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause));
+ else
+ return GetParentTime() - rPausedTime; //paused time is the cotal amt of time the program has been paused
+}
+
+bool ZTimer::IsPaused() const
+{
+ return rPaused;
+}
+
+}
diff --git a/test/ZTimerTest.cpp b/test/ZTimerTest.cpp
index 77bb687..78808d4 100644
--- a/test/ZTimerTest.cpp
+++ b/test/ZTimerTest.cpp
@@ -1,132 +1,132 @@
-/*******************************************************************************
- This file is Part of the ZEngine Library for 2D game development.
- Copyright (C) 2002, 2003 James Turk
-
- ZEngine is Licensed under a BSD-style license.
-This example file is in the public domain, it may be used with no restrictions.
-
- The maintainer of this library is James Turk (james@conceptofzero.net)
- and the home of this Library is http://www.zengine.sourceforge.net
-*******************************************************************************/
-
-/*$Id: ZTimerTest.cpp,v 1.14 2003/07/10 20:45:39 cozman Exp $*/
-
-#include
-#include
-using namespace std;
-using namespace ZE;
-
-bool Initialize()
-{
- ZEngine *engine = ZEngine::GetInstance();
- ZConfigFile cfg("tests.zcf");
- int w,h,bpp,rate;
- bool fs;
- std::string title;
-
- w = cfg.GetInt("ZTimerTest","width",800);
- h = cfg.GetInt("ZTimerTest","height",600);
- bpp = cfg.GetInt("ZTimerTest","bpp",32);
- fs = cfg.GetBool("ZTimerTest","fullscreen",false);
- title = cfg.GetString("ZTimerTest","title","ZTimer Test");
- rate = cfg.GetInt("ZTimerTest","framerate",60);
-
- engine->SetupDisplay(w,h,bpp,fs);
- engine->SetDesiredFramerate(rate);
- return engine->CreateDisplay(title);
-}
-
-void Test()
-{
- ZEngine *engine = ZEngine::GetInstance();
-
- std::string TimerName[3] = {"ZEngine Timer", "ZEngine Hooked Timer", "SDL Hooked Timer"};
- int curTimer = 0;
-
- //Open and Setup Font and Create Images and Timers//
- ZImage text[5];
- ZFont font("data/almontew.ttf",48);
- ZTimer TimerOne, TimerTwo(false); //Timer Two is on the SDL Timer.
-
- //do this only once//
- font.DrawText("(T)oggle | (P)ause | (U)npause",text[4]);
-
- do
- {
- //In the active loop, check events first//
- engine->CheckEvents();
-
- if(engine->IsActive())
- {
- if(engine->KeyIsPressed(SDLK_ESCAPE))
- engine->RequestQuit();
- //pause current timer//
- if(engine->KeyIsPressed(SDLK_p))
- {
- switch(curTimer)
- {
- case 0:
- engine->PauseTimer();
- break;
- case 1:
- TimerOne.Pause();
- break;
- case 2:
- TimerTwo.Pause();
- break;
- }
- }
- //unpause current timer//
- if(engine->KeyIsPressed(SDLK_u))
- {
- switch(curTimer)
- {
- case 0:
- engine->UnpauseTimer();
- break;
- case 1:
- TimerOne.Unpause();
- break;
- case 2:
- TimerTwo.Unpause();
- break;
- }
- }
- //switch//
- if(engine->KeyIsPressed(SDLK_t))
- {
- if(++curTimer > 2)
- curTimer = 0;
- engine->Delay(200);
- }
-
- //Render all the fonts//
- font.DrawText(FormatStr("Current Timer: %s",TimerName[curTimer].c_str()),text[0]);
- font.DrawText(FormatStr("%s Time: %d",TimerName[0].c_str(),engine->GetTime()),text[1]);
- font.DrawText(FormatStr("%s Time: %d",TimerName[1].c_str(),TimerOne.GetTime()),text[2]);
- font.DrawText(FormatStr("%s Time: %d",TimerName[2].c_str(),TimerTwo.GetTime()),text[3]);
-
- engine->Clear(); //clear screen
-
- for(int i=0; i <= 4; i++)
- text[i].Draw(0,i*50);
-
- engine->Update(); //update the screen
- }
-
- } while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
-}
-
-int main(int argc, char *argv[])
-{
- ZEngine *engine = ZEngine::GetInstance();
-
- if(Initialize())
- {
- //engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available
- Test();
- }
-
- ZEngine::ReleaseInstance(); //release engine instance
- return 0;
-}
+/*******************************************************************************
+ This file is Part of the ZEngine Library for 2D game development.
+ Copyright (C) 2002, 2003 James Turk
+
+ ZEngine is Licensed under a BSD-style license.
+This example file is in the public domain, it may be used with no restrictions.
+
+ The maintainer of this library is James Turk (james@conceptofzero.net)
+ and the home of this Library is http://www.zengine.sourceforge.net
+*******************************************************************************/
+
+/*$Id: ZTimerTest.cpp,v 1.15 2003/07/12 01:25:42 cozman Exp $*/
+
+#include
+#include
+using namespace std;
+using namespace ZE;
+
+bool Initialize()
+{
+ ZEngine *engine = ZEngine::GetInstance();
+ ZConfigFile cfg("tests.zcf");
+ int w,h,bpp,rate;
+ bool fs;
+ std::string title;
+
+ w = cfg.GetInt("ZTimerTest","width",800);
+ h = cfg.GetInt("ZTimerTest","height",600);
+ bpp = cfg.GetInt("ZTimerTest","bpp",32);
+ fs = cfg.GetBool("ZTimerTest","fullscreen",false);
+ title = cfg.GetString("ZTimerTest","title","ZTimer Test");
+ rate = cfg.GetInt("ZTimerTest","framerate",60);
+
+ engine->SetupDisplay(w,h,bpp,fs);
+ engine->SetDesiredFramerate(rate);
+ return engine->CreateDisplay(title);
+}
+
+void Test()
+{
+ ZEngine *engine = ZEngine::GetInstance();
+
+ std::string TimerName[3] = {"ZEngine Timer", "ZEngine Hooked Timer", "SDL Hooked Timer"};
+ int curTimer = 0;
+
+ //Open and Setup Font and Create Images and Timers//
+ ZImage text[5];
+ ZFont font("data/almontew.ttf",24);
+ ZTimer TimerOne, TimerTwo(false); //Timer Two is on the SDL Timer.
+
+ //do this only once//
+ font.DrawText("(T)oggle | (P)ause | (U)npause",text[4]);
+
+ do
+ {
+ //In the active loop, check events first//
+ engine->CheckEvents();
+
+ if(engine->IsActive())
+ {
+ if(engine->KeyIsPressed(SDLK_ESCAPE))
+ engine->RequestQuit();
+ //pause current timer//
+ if(engine->KeyIsPressed(SDLK_p))
+ {
+ switch(curTimer)
+ {
+ case 0:
+ engine->PauseTimer();
+ break;
+ case 1:
+ TimerOne.Pause();
+ break;
+ case 2:
+ TimerTwo.Pause();
+ break;
+ }
+ }
+ //unpause current timer//
+ if(engine->KeyIsPressed(SDLK_u))
+ {
+ switch(curTimer)
+ {
+ case 0:
+ engine->UnpauseTimer();
+ break;
+ case 1:
+ TimerOne.Unpause();
+ break;
+ case 2:
+ TimerTwo.Unpause();
+ break;
+ }
+ }
+ //switch//
+ if(engine->KeyIsPressed(SDLK_t))
+ {
+ if(++curTimer > 2)
+ curTimer = 0;
+ engine->Delay(200);
+ }
+
+ //Render all the fonts//
+ font.DrawText(FormatStr("Current Timer: %s",TimerName[curTimer].c_str()),text[0]);
+ font.DrawText(FormatStr("%s Time: %d",TimerName[0].c_str(),engine->GetTime()),text[1]);
+ font.DrawText(FormatStr("%s Time: %d",TimerName[1].c_str(),TimerOne.GetTime()),text[2]);
+ font.DrawText(FormatStr("%s Time: %d",TimerName[2].c_str(),TimerTwo.GetTime()),text[3]);
+
+ engine->Clear(); //clear screen
+
+ for(int i=0; i <= 4; i++)
+ text[i].Draw(0,i*30);
+
+ engine->Update(); //update the screen
+ }
+
+ } while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
+}
+
+int main(int argc, char *argv[])
+{
+ ZEngine *engine = ZEngine::GetInstance();
+
+ if(Initialize())
+ {
+ //engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available
+ Test();
+ }
+
+ ZEngine::ReleaseInstance(); //release engine instance
+ return 0;
+}