g++ fixes

This commit is contained in:
James Turk 2003-07-12 01:25:42 +00:00
parent 454dda1a02
commit 5c4b2c0ea9
11 changed files with 1916 additions and 1916 deletions

View File

@ -1,90 +1,91 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license. Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*! /*!
\file VersionInfo.h \file VersionInfo.h
\brief Definition file for VersionInfo class. \brief Definition file for VersionInfo class.
Definition file for VersinInfo class, simple class for containing and comparing Definition file for VersinInfo class, simple class for containing and comparing
version numbers. version numbers.
<br>$Id: VersionInfo.h,v 1.3 2003/06/11 00:15:24 cozman Exp $<br> <br>$Id: VersionInfo.h,v 1.4 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
#ifndef __versioninfo_h__ #ifndef __versioninfo_h__
#define __versioninfo_h__ #define __versioninfo_h__
#include "ZE_Utility.h" #include "ZE_Utility.h"
/*! /*!
\brief Class for holding version information. \brief Class for holding version information.
Class for holding version information on a library. Class for holding version information on a library. (Members capitalized because
**/ g++ has issues with members named major and minor.)
class VersionInfo **/
{ class VersionInfo
public: {
//! Major version number. public:
unsigned int major; //! Major version number.
//! Minor version number, changes upon signifigant releases. (Often upon compatibility breaks.) unsigned int Major;
unsigned int minor; //! Minor version number, changes upon signifigant releases. (Often upon compatibility breaks.)
//! Version release number, changes on every release. unsigned int Minor;
unsigned int release; //! Version release number, changes on every release.
//! String Description of release. (Often blank.) unsigned int Release;
std::string extra; //! String Description of release. (Often blank.)
std::string Extra;
/*!
\brief Constructor for VersionInfo. /*!
\brief Constructor for VersionInfo.
Simple constructor for version info, with a parameter for each member.
\param maj Major version number. Simple constructor for version info, with a parameter for each member.
\param min Minor version number. \param maj Major version number.
\param rel Version release number. \param min Minor version number.
\param ext Extra info std::string, optional (defaults to empty std::string). \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=""); **/
VersionInfo(unsigned int maj, unsigned int min, unsigned int rel, std::string ext="");
/*!
\brief Get std::string representing version number. /*!
\brief Get std::string representing version number.
Get dotted version number major.minor.release [extra].
\return Formatted version std::string. Get dotted version number major.minor.release [extra].
**/ \return Formatted version std::string.
std::string GetString() const; **/
std::string GetString() const;
/*!
\brief Less than operator overload for comparing VersionInfo. /*!
\brief Less than operator overload for comparing VersionInfo.
Overload of the less than (<) operator for two VersionInfos.
\param rhs Right hand side of comparison. Overload of the less than (<) operator for two VersionInfos.
\return true if less than, false if greater than or equal to. \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; **/
bool operator<(const VersionInfo &rhs) const;
/*!
\brief Equals to operator overload for comparing VersionInfo. /*!
\brief Equals to operator overload for comparing VersionInfo.
Overload of the equals to (==) operator for two VersionInfos.
\param rhs Right hand side of comparison. Overload of the equals to (==) operator for two VersionInfos.
\return true if equal to, false if not equals to. \param rhs Right hand side of comparison.
**/ \return true if equal to, false if not equals to.
bool operator==(const VersionInfo &rhs) const; **/
bool operator==(const VersionInfo &rhs) const;
/*!
\brief Greater than operator overload for comparing VersionInfo. /*!
\brief Greater than operator overload for comparing VersionInfo.
Overload of the greater than (>) operator for two VersionInfos.
\param rhs Right hand side of comparison. Overload of the greater than (>) operator for two VersionInfos.
\return true if greater than, false if less than or equal to. \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; **/
}; bool operator>(const VersionInfo &rhs) const;
};
#endif //__versioninfo_h__
#endif //__versioninfo_h__

View File

@ -1,52 +1,53 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license. Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*! /*!
\file ZE_Includes.h \file ZE_Includes.h
\brief Include file for SDL and C++ Includes that many ZEngine files need. \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 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. files should be included from within this file.
$ id: ZE_Includes.h,v 1.8 2003/04/27 22:05:25 cozman Exp $<br> $ id: ZE_Includes.h,v 1.8 2003/04/27 22:05:25 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
#ifndef __ze_includes_h__ #ifndef __ze_includes_h__
#define __ze_includes_h__ #define __ze_includes_h__
#include "ZE_Defines.h" #include "ZE_Defines.h"
#include "SDL.h" #include "SDL.h"
#include "SDL_opengl.h" #include "SDL_opengl.h"
#include "external/SDLGL_Util.h" #include "external/SDLGL_Util.h"
#ifdef USE_SDL_IMAGE #ifdef USE_SDL_IMAGE
#include "SDL_image.h" #include "SDL_image.h"
#endif #endif
#ifdef USE_SDL_TTF #ifdef USE_SDL_TTF
#include "SDL_ttf.h" #include "SDL_ttf.h"
#endif #endif
#ifdef USE_SDL_MIXER #ifdef USE_SDL_MIXER
#include "SDL_mixer.h" #include "SDL_mixer.h"
#endif #endif
#ifdef USE_SDL_NET #ifdef USE_SDL_NET
#include "SDL_net.h" #include "SDL_net.h"
#endif #endif
#ifdef USE_PHYSFS #ifdef USE_PHYSFS
#include "physfs.h" #include "physfs.h"
#include "external/physfsrwops.h" #include "external/physfsrwops.h"
#endif #endif
#include <string> //used frequently #include <string> //used frequently
#include <queue> //used by ZEngine for ZErrors #include <queue> //used by ZEngine for ZErrors
#include <list> //used by ZConfigFile #include <list> //used by ZConfigFile
#include <fstream> //used by ZConfigFile #include <fstream> //used by ZConfigFile
#include <cctype> //used in parsing #include <cctype> //used in parsing
#include <cstdarg> //used in FormatStr
#endif //__ze_includes_h__
#endif //__ze_includes_h__

View File

@ -1,351 +1,351 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license. Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*! /*!
\file ZE_ZBaseParticleSystem.h \file ZE_ZBaseParticleSystem.h
\brief Definition and implementation file for the base of the ZEngine Particle System. \brief Definition and implementation file for the base of the ZEngine Particle System.
Definition and implementation file for ZEngine particle system class ZBaseParticleSystem. 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. Due to problems with template classes the template implementation needs to be in the same file as the declaration.
<br>$Id: ZE_ZBaseParticleSystem.h,v 1.4 2003/07/11 20:51:44 cozman Exp $<br> <br>$Id: ZE_ZBaseParticleSystem.h,v 1.5 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
#ifndef __ze_zbaseparticlesystem_h__ #ifndef __ze_zbaseparticlesystem_h__
#define __ze_zbaseparticlesystem_h__ #define __ze_zbaseparticlesystem_h__
#include "ZEngine.h" #include "ZEngine.h"
namespace ZE namespace ZE
{ {
/*! /*!
\brief Basic particle class for ZEngine particle systems. \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. 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.) (No default constructor is needed because NewParticle should initialize members.)
**/ **/
class ZBaseParticle class ZBaseParticle
{ {
public: public:
/*! /*!
\brief Virtual destructor. \brief Virtual destructor.
Empty virtual destructor to make inheritance safe. Empty virtual destructor to make inheritance safe.
**/ **/
virtual ~ZBaseParticle() virtual ~ZBaseParticle()
{} // empty definition here, since ZBaseParticleSystem has no cpp file and this would be all that would be in it {} // empty definition here, since ZBaseParticleSystem has no cpp file and this would be all that would be in it
//! X Position of particle. //! X Position of particle.
float xPos; float xPos;
//! Y Position of particle. //! Y Position of particle.
float yPos; float yPos;
//! Energy of particle (particles die if energy is 0). //! Energy of particle (particles die if energy is 0).
float energy; float energy;
}; };
/*! /*!
\brief Base particle system, a virtual class defining an outline for a fully functional particle system. \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 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 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. 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.) (Note: If you need a very specific particle system it's probably best to write your own fit to your needs.)
**/ **/
template <class particleType> template <class particleType>
class ZBaseParticleSystem class ZBaseParticleSystem
{ {
protected: protected:
//! Pointer to ZEngine singleton. //! Pointer to ZEngine singleton.
ZEngine *rEngine; ZEngine *rEngine;
//! Pointer to array of particles. //! Pointer to array of particles.
particleType *rParticles; particleType *rParticles;
//! Maximum number of particles, and size of rParticles array. //! Maximum number of particles, and size of rParticles array.
unsigned int rMaxParticles; unsigned int rMaxParticles;
//! Current number of particles. //! Current number of particles.
unsigned int rCurParticles; unsigned int rCurParticles;
//! Number of particles to release per second. //! Number of particles to release per second.
unsigned int rNumParticlesPerSec; unsigned int rNumParticlesPerSec;
//! Millisecond format time of last update. //! Millisecond format time of last update.
Uint32 rLastUpdate; Uint32 rLastUpdate;
//! Boolean value indicating if system is paused. //! Boolean value indicating if system is paused.
bool rPaused; bool rPaused;
/*! /*!
\brief Adds a new particle. \brief Adds a new particle.
Finds room in array with dead particle, and adds new particle using NewParticle, called by Emit. Finds room in array with dead particle, and adds new particle using NewParticle, called by Emit.
**/ **/
void AddParticle(); void AddParticle();
/*! /*!
\brief Pure virtual function to initialize and return a new particle. \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. Pure virtual function, overload should set up a new particle with desired traits, called by AddParticle.
**/ **/
virtual particleType NewParticle()=0; virtual particleType NewParticle()=0;
/*! /*!
\brief Pure virtual function to update a particle. \brief Pure virtual function to update a particle.
Pure virtual function, overload should update the particle `rParticles[index]`, called by Update. Pure virtual function, overload should update the particle `rParticles[index]`, called by Update.
\param index Index of particle in rParticles array to update. \param index Index of particle in rParticles array to update.
\param elapsedTime Decimal portion of a second since last call. \param elapsedTime Decimal portion of a second since last call.
**/ **/
virtual void UpdateParticle(int index, float elapsedTime)=0; virtual void UpdateParticle(int index, float elapsedTime)=0;
public: public:
/*! /*!
\brief Basic constructor for ZBaseParticleSystem. \brief Basic constructor for ZBaseParticleSystem.
Basic constructor for ZBaseParticle system, initializes all values to 0. Basic constructor for ZBaseParticle system, initializes all values to 0.
**/ **/
ZBaseParticleSystem(); ZBaseParticleSystem();
/*! /*!
\brief Virtual destructor for ZBaseParticleSystem. \brief Virtual destructor for ZBaseParticleSystem.
Virtual destructor for ZBaseParticleSystem, destroys all particles, virtual to make class inheritance-safe. Virtual destructor for ZBaseParticleSystem, destroys all particles, virtual to make class inheritance-safe.
**/ **/
virtual ~ZBaseParticleSystem(); virtual ~ZBaseParticleSystem();
/*! /*!
\brief Pure virtual function, renders the particles. \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. Pure virtual so that each particle system can render it's member particles in it's own way.
**/ **/
virtual void Render()=0; virtual void Render()=0;
/*! /*!
\brief Emit a given number of particles. \brief Emit a given number of particles.
Emits a given number of particles, will not emit particles if system is full. Emits a given number of particles, will not emit particles if system is full.
\param numParticles Number of particles to emit. \param numParticles Number of particles to emit.
**/ **/
void Emit(int numParticles); void Emit(int numParticles);
/*! /*!
\brief Updates status of particle system. \brief Updates status of particle system.
Updates entire particle system, calling update on every particle, emitting necessary new 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 particles, removing particles which have an energy <= 0 or are off the screen. Virtual for
special cases, but generally should not be overridden. special cases, but generally should not be overridden.
**/ **/
virtual void Update(); virtual void Update();
/*! /*!
\brief Empties particle system of all particles. \brief Empties particle system of all particles.
Empties particle system of all particles, does not alter paused state. Empties particle system of all particles, does not alter paused state.
**/ **/
void Clear(); void Clear();
/*! /*!
\brief Pauses particle system. \brief Pauses particle system.
Pauses particle system, particles may still be drawn but particles are not updated. Pauses particle system, particles may still be drawn but particles are not updated.
**/ **/
void Pause(); void Pause();
/*! /*!
\brief Unpauses particle system. \brief Unpauses particle system.
Returns particle system to active state, system starts unpaused. Returns particle system to active state, system starts unpaused.
**/ **/
void Unpause(); void Unpause();
/*! /*!
\brief Clears system and pauses it. \brief Clears system and pauses it.
Same as calling Clear() and then Pause(), use unpause to restart system. Same as calling Clear() and then Pause(), use unpause to restart system.
**/ **/
void Stop(); void Stop();
/*! /*!
\brief Detect if particle system is currently paused. \brief Detect if particle system is currently paused.
Returns bool indicating if the particle system is currently paused. Returns bool indicating if the particle system is currently paused.
\return true if paused, false if active \return true if paused, false if active
**/ **/
bool Paused(); bool Paused();
/*! /*!
\brief Sets max particles allowed in system. \brief Sets max particles allowed in system.
Set maximum number of particles allowed in system, particles are not emitted when system is full. 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. 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. \param max Maximum number of particles for system.
**/ **/
void SetMaxParticles(int max); void SetMaxParticles(unsigned int max);
/*! /*!
\brief Sets release rate of particles. \brief Sets release rate of particles.
Set number of particles to release per second. Set number of particles to release per second.
\param rate Number of particles to release over the duration of one second. \param rate Number of particles to release over the duration of one second.
**/ **/
void SetRate(int rate); void SetRate(unsigned int rate);
}; };
//implementation// //implementation//
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::AddParticle() void ZBaseParticleSystem<particleType>::AddParticle()
{ {
//empty space is always at end, function is private so no checking is needed (Emit does that) //empty space is always at end, function is private so no checking is needed (Emit does that)
rParticles[rCurParticles] = NewParticle(); rParticles[rCurParticles] = NewParticle();
++rCurParticles; ++rCurParticles;
} }
template <class particleType> template <class particleType>
ZBaseParticleSystem<particleType>::ZBaseParticleSystem() ZBaseParticleSystem<particleType>::ZBaseParticleSystem()
{ {
rEngine = ZEngine::GetInstance(); rEngine = ZEngine::GetInstance();
rParticles = NULL; rParticles = NULL;
rMaxParticles = rCurParticles = rNumParticlesPerSec = 0; rMaxParticles = rCurParticles = rNumParticlesPerSec = 0;
rLastUpdate = rEngine->GetTime(); rLastUpdate = rEngine->GetTime();
rPaused = false; rPaused = false;
} }
template <class particleType> template <class particleType>
ZBaseParticleSystem<particleType>::~ZBaseParticleSystem() ZBaseParticleSystem<particleType>::~ZBaseParticleSystem()
{ {
if(rParticles) if(rParticles)
delete []rParticles; delete []rParticles;
} }
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::Emit(int numParticles) void ZBaseParticleSystem<particleType>::Emit(int numParticles)
{ {
while(numParticles > 0 && rCurParticles < rMaxParticles) while(numParticles > 0 && rCurParticles < rMaxParticles)
{ {
AddParticle(); AddParticle();
--numParticles; --numParticles;
} }
} }
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::Update() void ZBaseParticleSystem<particleType>::Update()
{ {
float elapsed = (rEngine->GetTime()-rLastUpdate)/1000.0f; float elapsed = (rEngine->GetTime()-rLastUpdate)/1000.0f;
double emitAmount; double emitAmount;
static double overflow=0; static double overflow=0;
if(!rPaused) if(!rPaused)
{ {
//update every particle and remove dead particles //update every particle and remove dead particles
for(unsigned int i=0; i < rCurParticles; ++i) for(unsigned int i=0; i < rCurParticles; ++i)
{ {
UpdateParticle(i,elapsed); UpdateParticle(i,elapsed);
if(rParticles[i].xPos < 0 || rParticles[i].xPos > rEngine->DisplayWidth() 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].yPos < 0 || rParticles[i].yPos > rEngine->DisplayHeight() || rParticles[i].energy <= 0)
{ {
rParticles[i] = rParticles[--rCurParticles]; rParticles[i] = rParticles[--rCurParticles];
--i; //go back one to process that particle --i; //go back one to process that particle
} }
} }
emitAmount = elapsed*rNumParticlesPerSec; emitAmount = elapsed*rNumParticlesPerSec;
overflow += emitAmount - static_cast<int>(emitAmount); //only floating point portion of emitAmount overflow += emitAmount - static_cast<int>(emitAmount); //only floating point portion of emitAmount
Emit(static_cast<int>(emitAmount)); Emit(static_cast<int>(emitAmount));
if(overflow >= .95) //a little lower than one, for tolerance if(overflow >= .95) //a little lower than one, for tolerance
{ {
Emit(1); Emit(1);
overflow = 0; //dump & clear overflow overflow = 0; //dump & clear overflow
} }
} }
rLastUpdate = rEngine->GetTime(); rLastUpdate = rEngine->GetTime();
} }
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::Clear() void ZBaseParticleSystem<particleType>::Clear()
{ {
rCurParticles = 0; rCurParticles = 0;
} }
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::Pause() void ZBaseParticleSystem<particleType>::Pause()
{ {
rPaused = true; rPaused = true;
} }
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::Unpause() void ZBaseParticleSystem<particleType>::Unpause()
{ {
rPaused = false; rPaused = false;
} }
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::Stop() void ZBaseParticleSystem<particleType>::Stop()
{ {
Clear(); Clear();
Pause(); Pause();
} }
template <class particleType> template <class particleType>
bool ZBaseParticleSystem<particleType>::Paused() bool ZBaseParticleSystem<particleType>::Paused()
{ {
return rPaused; return rPaused;
} }
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::SetMaxParticles(int max) void ZBaseParticleSystem<particleType>::SetMaxParticles(unsigned int max)
{ {
particleType *temp; particleType *temp;
unsigned int i; unsigned int i;
if(max) if(max)
{ {
if(max != rMaxParticles) //only do this if size changed if(max != rMaxParticles) //only do this if size changed
{ {
if(rCurParticles) if(rCurParticles)
{ {
rCurParticles %= max; rCurParticles %= max;
//copy current particles to temp //copy current particles to temp
temp = new particleType[rCurParticles]; temp = new particleType[rCurParticles];
for(i=0; i < rCurParticles; ++i) for(i=0; i < rCurParticles; ++i)
temp[i] = rParticles[i]; temp[i] = rParticles[i];
} }
//change size of rParticles //change size of rParticles
if(rParticles) if(rParticles)
delete []rParticles; delete []rParticles;
rParticles = new particleType[max]; rParticles = new particleType[max];
rMaxParticles = max; rMaxParticles = max;
if(rCurParticles) if(rCurParticles)
{ {
//copy particles from temp back to rParticles //copy particles from temp back to rParticles
for(i=0; i < rCurParticles; ++i) for(i=0; i < rCurParticles; ++i)
rParticles[i] = temp[i]; rParticles[i] = temp[i];
delete []temp; delete []temp;
} }
} }
} }
else else
{ {
rMaxParticles = rCurParticles = 0; rMaxParticles = rCurParticles = 0;
if(rParticles) if(rParticles)
delete []rParticles; delete []rParticles;
} }
} }
template <class particleType> template <class particleType>
void ZBaseParticleSystem<particleType>::SetRate(int rate) void ZBaseParticleSystem<particleType>::SetRate(unsigned int rate)
{ {
rNumParticlesPerSec = rate; rNumParticlesPerSec = rate;
} }
} //namespace ZE } //namespace ZE
#endif //__ze_zbaseparticlesystem_h__ #endif //__ze_zbaseparticlesystem_h__

File diff suppressed because it is too large Load Diff

View File

@ -1,162 +1,163 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license. Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*! /*!
\file ZE_ZRandGen.h \file ZE_ZRandGen.h
\brief Definition file for ZRandGen. \brief Definition file for ZRandGen.
Definition file for ZRandGen, an OO encapsulated version of the Mersenne Twister. 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 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 should suffice unless you want objects to have their ownrandom streams. This
implementation is derived from the original mt19937ar.c source from 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. http://www.math.keio.ac.jp/matumoto/emt.html. See source of ZE_ZRandGen.cpp for license.
<br>$Id: ZE_ZRandGen.h,v 1.1 2003/07/05 01:05:47 cozman Exp $<br> <br>$Id: ZE_ZRandGen.h,v 1.2 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
#ifndef __ze_zrandgen_h__ #ifndef __ze_zrandgen_h__
#define __ze_zrandgen_h__ #define __ze_zrandgen_h__
#include "ZE_Utility.h" #include "ZE_Utility.h"
#include <ctime> #include <ctime>
namespace ZE namespace ZE
{ {
/*! /*!
\brief ZRandGen class for OO encapsulation of superb random generator "Mersenne Twister." \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 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 should suffice unless you want objects to have their ownrandom streams. This
implementation is derived from the original mt19937ar.c source from 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. http://www.math.keio.ac.jp/matumoto/emt.html. See source of ZE_ZRandGen.cpp for license.
\since 0.8.4 \since 0.8.4
**/ **/
class ZRandGen class ZRandGen
{ {
protected: protected:
//! Number of random numbers to generate at once. //! Number of random numbers to generate at once.
static const unsigned long N = 624; static const unsigned long N = 624;
//! A constant used internally by Mersenne Twister. //! A constant used internally by Mersenne Twister.
static const unsigned long M = 397; static const unsigned long M = 397;
//! Constant vector A, used internally by Mersenne Twister. //! Constant vector A, used internally by Mersenne Twister.
static const unsigned long MATRIX_A = 0x9908b0dfUL; static const unsigned long MATRIX_A = 0x9908b0dfUL;
//! Most signifigan w-r bits, used internally by Mersenne Twister. //! Most signifigan w-r bits, used internally by Mersenne Twister.
static const unsigned long UPPER_MASK = 0x80000000UL; static const unsigned long UPPER_MASK = 0x80000000UL;
//! Least signifigant r bits, used internally by Mersenne Twister. //! Least signifigant r bits, used internally by Mersenne Twister.
static const unsigned long LOWER_MASK = 0x7fffffffUL; static const unsigned long LOWER_MASK = 0x7fffffffUL;
//! Each instance of the algorithm requires a state vector. //! Each instance of the algorithm requires a state vector.
unsigned long rStateVector[N]; unsigned long rStateVector[N];
//! Used internally to traversing the rStateVector. //! Used internally to traversing the rStateVector.
int rStateVectorIndex; unsigned long rStateVectorIndex;
/*! /*!
\brief Workhorse of random generator, only used internally. \brief Workhorse of random generator, only used internally.
Generates N random numbers and then serves them up, all Rand functions rely Generates N random numbers and then serves them up, all Rand functions rely
on this. on this.
\return A random unsigned long. \return A random unsigned long.
**/ **/
unsigned long genrand_int32(); unsigned long genrand_int32();
public: public:
/*! /*!
\brief Constructor which does an initial seeding using time. \brief Constructor which does an initial seeding using time.
Creates internal vector and calls Seed(time(NULL)) to initialize the MT state. Creates internal vector and calls Seed(time(NULL)) to initialize the MT state.
**/ **/
ZRandGen(); ZRandGen();
/*! /*!
\brief Constructor which does an initial seeding. \brief Constructor which does an initial seeding.
Creates internal vector and calls seed to initialize the MT state. Creates internal vector and calls seed to initialize the MT state.
**/ **/
ZRandGen(unsigned long seed); ZRandGen(unsigned long seed);
/*! /*!
\brief Seed random number generator. \brief Seed random number generator.
Reseed Mersenne Twister random number generator. NOTE: Generator is initialized upon creation of object using time. Reseed Mersenne Twister random number generator. NOTE: Generator is initialized upon creation of object using time.
\param seed Seed for random sequence. \param seed Seed for random sequence.
**/ **/
void Seed(unsigned long seed); void Seed(unsigned long seed);
/*! /*!
\brief Obtain random integer [0,max). \brief Obtain random integer [0,max).
Obtain random int l where 0 <= l < max. Obtain random int l where 0 <= l < max.
\param max Limit for random number. \param max Limit for random number.
\return Random unsigned int. \return Random unsigned int.
**/ **/
unsigned int Rand(unsigned int max); unsigned int Rand(unsigned int max);
/*! /*!
\brief Obtain random integer [0,max). \brief Obtain random integer [0,max).
Obtain random long l where 0 <= l < max. Obtain random long l where 0 <= l < max.
\param max Limit for random number. \param max Limit for random number.
\return Random unsigned long. \return Random unsigned long.
**/ **/
unsigned long Rand(unsigned long max); unsigned long Rand(unsigned long max);
/*! /*!
\brief Obtain random integer [min,max]. \brief Obtain random integer [min,max].
Obtain random int l where min <= l <= max. Obtain random int l where min <= l <= max.
\param min Lower limit for random number. \param min Lower limit for random number.
\param max Upper limit for random number. \param max Upper limit for random number.
\return Random int. \return Random int.
**/ **/
int Rand(int min, int max); int Rand(int min, int max);
/*! /*!
\brief Obtain random integer [min,max]. \brief Obtain random integer [min,max].
Obtain random long l where min <= l <= max. Obtain random long l where min <= l <= max.
\param min Lower limit for random number. \param min Lower limit for random number.
\param max Upper limit for random number. \param max Upper limit for random number.
\return Random long. \return Random long.
**/ **/
long Rand(long min, long max); long Rand(long min, long max);
/*! /*!
\brief Obtain random integer [min,max]. \brief Obtain random integer [min,max].
Obtain random float l where min <= l <= max. Obtain random float l where min <= l <= max.
\param min Lower limit for random number. \param min Lower limit for random number.
\param max Upper limit for random number. \param max Upper limit for random number.
\return Random float. \return Random float.
**/ **/
float Rand(float min, float max); float Rand(float min, float max);
/*! /*!
\brief Obtain random integer [min,max]. \brief Obtain random integer [min,max].
Obtain random double l where min <= l <= max. Obtain random double l where min <= l <= max.
\param min Lower limit for random number. \param min Lower limit for random number.
\param max Upper limit for random number. \param max Upper limit for random number.
\return Random double. \return Random double.
**/ **/
double Rand(double min, double max); double Rand(double min, double max);
/*! /*!
\brief Obtain random double [0,1). \brief Obtain random double [0,1).
Obtain random double d where 0 <= d < 1. Obtain random double d where 0 <= d < 1.
\return Random double [0,1). \return Random double [0,1).
**/ **/
double RandDouble(); double RandDouble();
}; };
} }
#endif //__ze_zrandgen_h__ #endif //__ze_zrandgen_h__

View File

@ -1,57 +1,57 @@
#include "VersionInfo.h" #include "VersionInfo.h"
/*! /*!
\file VersionInfo.cpp \file VersionInfo.cpp
\brief Implementation file for VersionInfo class. \brief Implementation file for VersionInfo class.
Implementation file for VersinInfo class, simple class for containing and comparing Implementation file for VersinInfo class, simple class for containing and comparing
version numbers. version numbers.
<br>$Id: VersionInfo.cpp,v 1.4 2003/06/11 05:51:15 cozman Exp $<br> <br>$Id: VersionInfo.cpp,v 1.5 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
VersionInfo::VersionInfo(unsigned int maj, unsigned int min, unsigned int rel, std::string ext) : VersionInfo::VersionInfo(unsigned int maj, unsigned int min, unsigned int rel, std::string ext) :
major(maj), minor(min), release(rel), extra(ext) Major(maj), Minor(min), Release(rel), Extra(ext)
{ {
} }
std::string VersionInfo::GetString() const std::string VersionInfo::GetString() const
{ {
if(extra.length()) if(Extra.length())
return ZE::FormatStr("%d.%d.%d [%s]",major,minor,release,extra.c_str()); return ZE::FormatStr("%d.%d.%d [%s]",Major,Minor,Release,Extra.c_str());
else else
return ZE::FormatStr("%d.%d.%d",major,minor,release); return ZE::FormatStr("%d.%d.%d",Major,Minor,Release);
} }
bool VersionInfo::operator<(const VersionInfo &rhs) const bool VersionInfo::operator<(const VersionInfo &rhs) const
{ {
//chained compares, compare numbers in order of importance //chained compares, compare numbers in order of importance
if(this->major < rhs.major) if(this->Major < rhs.Major)
return true; return true;
else if(this->major == rhs.major) else if(this->Major == rhs.Major)
{ {
if(this->minor < rhs.minor) if(this->Minor < rhs.Minor)
return true; return true;
else if(this->minor == rhs.minor) else if(this->Minor == rhs.Minor)
{ {
if(this->release < rhs.release) if(this->Release < rhs.Release)
return true; return true;
else if(this->release == rhs.release) else if(this->Release == rhs.Release)
{ {
return this->extra < rhs.extra; //just compare the strings at the end return this->Extra < rhs.Extra; //just compare the strings at the end
} }
} }
} }
return false; //if it reaches this point rhs is >= return false; //if it reaches this point rhs is >=
} }
bool VersionInfo::operator==(const VersionInfo &rhs) const bool VersionInfo::operator==(const VersionInfo &rhs) const
{ {
return this->GetString() == rhs.GetString(); //only equal data produces equal strings return this->GetString() == rhs.GetString(); //only equal data produces equal strings
} }
bool VersionInfo::operator>(const VersionInfo &rhs) const bool VersionInfo::operator>(const VersionInfo &rhs) const
{ {
return !((*this) < rhs || (*this) == rhs); //if not < and not ==, must be > return !((*this) < rhs || (*this) == rhs); //if not < and not ==, must be >
} }

View File

@ -1,82 +1,82 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license. Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/** /**
\file ZE_Utility.cpp \file ZE_Utility.cpp
\brief Source file for ZEngine utility functions. \brief Source file for ZEngine utility functions.
Source file containing open utilities for use inside and alongside ZEngine. Source file containing open utilities for use inside and alongside ZEngine.
<br>$Id: ZE_Utility.cpp,v 1.9 2003/06/11 05:51:15 cozman Exp $<br> <br>$Id: ZE_Utility.cpp,v 1.10 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
#include "ZE_Utility.h" #include "ZE_Utility.h"
namespace ZE namespace ZE
{ {
std::string FormatStr(const char *fmtstr, ...) std::string FormatStr(const char *fmtstr, ...)
{ {
char buf[512]; char buf[512];
va_list args; va_list args;
//simply puts args into the buffer using standard parsing rules //simply puts args into the buffer using standard parsing rules
va_start(args,fmtstr); va_start(args,fmtstr);
vsprintf(buf, fmtstr, args); vsprintf(buf, fmtstr, args);
va_end(args); va_end(args);
return buf; return buf;
} }
//Each of the Free*s safely frees & NULLs the pointer //Each of the Free*s safely frees & NULLs the pointer
void FreeImage(SDL_Surface *&image) void FreeImage(SDL_Surface *&image)
{ {
if(image) if(image)
{ {
SDL_FreeSurface(image); SDL_FreeSurface(image);
image = NULL; image = NULL;
} }
} }
#ifdef USE_SDL_MIXER #ifdef USE_SDL_MIXER
void FreeSound(Mix_Chunk *&chunk) void FreeSound(Mix_Chunk *&chunk)
{ {
if(chunk) if(chunk)
{ {
Mix_FreeChunk(chunk); Mix_FreeChunk(chunk);
chunk = NULL; chunk = NULL;
} }
} }
void FreeMusic(Mix_Music *&music) void FreeMusic(Mix_Music *&music)
{ {
if(music) if(music)
{ {
Mix_FreeMusic(music); Mix_FreeMusic(music);
music = NULL; music = NULL;
} }
} }
#endif #endif
#ifdef USE_SDL_TTF #ifdef USE_SDL_TTF
void FreeFont(TTF_Font *&font) void FreeFont(TTF_Font *&font)
{ {
if(font) if(font)
{ {
TTF_CloseFont(font); TTF_CloseFont(font);
font = NULL; font = NULL;
} }
} }
#endif #endif
} }

View File

@ -13,7 +13,7 @@
\brief Central source file for ZEngine. \brief Central source file for ZEngine.
Actual implementation of ZEngine singleton class, the core of ZEngine. Actual implementation of ZEngine singleton class, the core of ZEngine.
<br>$Id: ZE_ZEngine.cpp,v 1.51 2003/07/11 20:51:44 cozman Exp $<br> <br>$Id: ZE_ZEngine.cpp,v 1.52 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -25,18 +25,18 @@ namespace ZE
VersionInfo ZEngine::Version(0,8,4); VersionInfo ZEngine::Version(0,8,4);
ZEngine *ZEngine::sInstance=NULL; ZEngine *ZEngine::sInstance=NULL;
ZEngine::ZEngine() : ZEngine::ZEngine() :
mInitialized(false), mWidth(800), mHeight(600), mBPP(-1), mFullscreen(true), mWidth(800), mHeight(600), mBPP(-1), mFullscreen(true), mInitialized(false),
#ifdef USE_SDL_MIXER mScreen(NULL),
mRate(22050), mStereo(false), mPaused(false), mUnpauseOnActive(false),
#endif
mNeedReload(false),mScreen(NULL),
mEventFilter(NULL), mActive(false), mQuit(false), mKeyIsPressed(NULL),
mMouseX(0), mMouseY(0), mMouseB(0),
mUnpauseOnActive(false), mPaused(false),
mDesiredFramerate(0), mNextUpdate(0), mLastPause(0), mPausedTime(0), mLastTime(0), mDesiredFramerate(0), mNextUpdate(0), mLastPause(0), mPausedTime(0), mLastTime(0),
mSecPerFrame(0.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) for(int k = 0; k < SDLK_LAST; ++k)
mKeyPress[k] = false; mKeyPress[k] = false;
@ -273,15 +273,15 @@ void ZEngine::ToggleFullscreen()
SDL_WM_ToggleFullScreen(mScreen); SDL_WM_ToggleFullScreen(mScreen);
#else #else
char *title,*icon; char *title,*icon;
SetupDisplay(mWidth,mHeight,mBPP,!mFullscreen); SetupDisplay(mWidth,mHeight,mBPP,!mFullscreen);
SDL_WM_GetCaption(&title,&icon); SDL_WM_GetCaption(&title,&icon);
if(icon) if(icon)
CreateDisplay(title,icon); CreateDisplay(title,icon);
else else
CreateDisplay(title); CreateDisplay(title);
#endif #endif
SetReloadNeed(true); //images need to be reloaded on fullscreen swap SetReloadNeed(true); //images need to be reloaded on fullscreen swap
} }

View File

@ -1,139 +1,139 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license. Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/** /**
\file ZE_ZRandGen.cpp \file ZE_ZRandGen.cpp
\brief Source file for ZRandGen. \brief Source file for ZRandGen.
Implementation file for ZRandGen, an OO encapsulated version of the Mersenne Twister. Implementation file for ZRandGen, an OO encapsulated version of the Mersenne Twister.
This implementation is derived from the original mt19937ar.c source from 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. http://www.math.keio.ac.jp/matumoto/emt.html. See source for MT license.
<br>$Id: ZE_ZRandGen.cpp,v 1.1 2003/07/05 00:58:08 cozman Exp $<br> <br>$Id: ZE_ZRandGen.cpp,v 1.2 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk, some code from Mersenne Twister. \author James Turk, some code from Mersenne Twister.
**/ **/
#include "ZE_ZRandGen.h" #include "ZE_ZRandGen.h"
namespace ZE namespace ZE
{ {
/* /*
The source in this file is based on MT19937, with much of the source The source in this file is based on MT19937, with much of the source
replicated from mt19937ar.c, because of this the original license replicated from mt19937ar.c, because of this the original license
for that file is below. for that file is below.
-James -James
A C-program for MT19937, with initialization improved 2002/1/26. A C-program for MT19937, with initialization improved 2002/1/26.
Coded by Takuji Nishimura and Makoto Matsumoto. Coded by Takuji Nishimura and Makoto Matsumoto.
Before using, initialize the state by using init_genrand(seed) Before using, initialize the state by using init_genrand(seed)
or init_by_array(init_key, key_length). or init_by_array(init_key, key_length).
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote 3. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written products derived from this software without specific prior written
permission. permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Any feedback is very welcome. Any feedback is very welcome.
http://www.math.keio.ac.jp/matumoto/emt.html http://www.math.keio.ac.jp/matumoto/emt.html
email: matumoto@math.keio.ac.jp email: matumoto@math.keio.ac.jp
*/ */
//adapted directly from mt19937ar : unsigned long genrand_int32(void) //adapted directly from mt19937ar : unsigned long genrand_int32(void)
unsigned long ZRandGen::genrand_int32() unsigned long ZRandGen::genrand_int32()
{ {
unsigned long y; unsigned long y;
static unsigned long mag01[2]={0x0UL, MATRIX_A}; static unsigned long mag01[2]={0x0UL, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */ /* mag01[x] = x * MATRIX_A for x=0,1 */
if (rStateVectorIndex >= N) { /* generate N words at one time */ if (rStateVectorIndex >= N) { /* generate N words at one time */
int kk; unsigned int kk;
//removed uninitialized check, class initializes in constructor //removed uninitialized check, class initializes in constructor
for (kk=0;kk<N-M;++kk) { for (kk=0;kk<N-M;++kk) {
y = (rStateVector[kk]&UPPER_MASK)|(rStateVector[kk+1]&LOWER_MASK); y = (rStateVector[kk]&UPPER_MASK)|(rStateVector[kk+1]&LOWER_MASK);
rStateVector[kk] = rStateVector[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL]; rStateVector[kk] = rStateVector[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
} }
for (;kk<N-1;++kk) { for (;kk<N-1;++kk) {
y = (rStateVector[kk]&UPPER_MASK)|(rStateVector[kk+1]&LOWER_MASK); y = (rStateVector[kk]&UPPER_MASK)|(rStateVector[kk+1]&LOWER_MASK);
rStateVector[kk] = rStateVector[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL]; rStateVector[kk] = rStateVector[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
} }
y = (rStateVector[N-1]&UPPER_MASK)|(rStateVector[0]&LOWER_MASK); y = (rStateVector[N-1]&UPPER_MASK)|(rStateVector[0]&LOWER_MASK);
rStateVector[N-1] = rStateVector[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; rStateVector[N-1] = rStateVector[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
rStateVectorIndex = 0; rStateVectorIndex = 0;
} }
y = rStateVector[rStateVectorIndex++]; y = rStateVector[rStateVectorIndex++];
/* Tempering */ /* Tempering */
y ^= (y >> 11); y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL; y ^= (y << 7) & 0x9d2c5680UL;
y ^= (y << 15) & 0xefc60000UL; y ^= (y << 15) & 0xefc60000UL;
y ^= (y >> 18); y ^= (y >> 18);
return y; return y;
} }
ZRandGen::ZRandGen() ZRandGen::ZRandGen()
{ {
Seed(static_cast<unsigned long>(std::time(NULL))); Seed(static_cast<unsigned long>(std::time(NULL)));
} }
ZRandGen::ZRandGen(unsigned long seed) ZRandGen::ZRandGen(unsigned long seed)
{ {
Seed(seed); Seed(seed);
} }
//adapted directly from mt19937ar : void init_genrand(unsigned long s) //adapted directly from mt19937ar : void init_genrand(unsigned long s)
void ZRandGen::Seed(unsigned long s) void ZRandGen::Seed(unsigned long s)
{ {
rStateVector[0]= s & 0xffffffffUL; rStateVector[0]= s & 0xffffffffUL;
for(rStateVectorIndex=1; rStateVectorIndex<N; ++rStateVectorIndex) for(rStateVectorIndex=1; rStateVectorIndex<N; ++rStateVectorIndex)
{ {
rStateVector[rStateVectorIndex] = rStateVector[rStateVectorIndex] =
(1812433253UL * (rStateVector[rStateVectorIndex-1] ^ (rStateVector[rStateVectorIndex-1] >> 30)) + rStateVectorIndex); (1812433253UL * (rStateVector[rStateVectorIndex-1] ^ (rStateVector[rStateVectorIndex-1] >> 30)) + rStateVectorIndex);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */ /* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array rStateVector[]. */ /* only MSBs of the array rStateVector[]. */
/* 2002/01/09 modified by Makoto Matsumoto */ /* 2002/01/09 modified by Makoto Matsumoto */
rStateVector[rStateVectorIndex] &= 0xffffffffUL; rStateVector[rStateVectorIndex] &= 0xffffffffUL;
/* for >32 bit machines */ /* for >32 bit machines */
} }
} }

View File

@ -1,83 +1,82 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license. Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/** /**
\file ZE_ZTimer.cpp \file ZE_ZTimer.cpp
\brief Source file for ZTimer. \brief Source file for ZTimer.
Implementation of ZTimer, the basic Timer class for ZEngine. Implementation of ZTimer, the basic Timer class for ZEngine.
<br>$Id: ZE_ZTimer.cpp,v 1.9 2003/06/11 05:51:16 cozman Exp $<br> <br>$Id: ZE_ZTimer.cpp,v 1.10 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
#include "ZE_ZTimer.h" #include "ZE_ZTimer.h"
namespace ZE namespace ZE
{ {
Uint32 ZTimer::GetParentTime() const Uint32 ZTimer::GetParentTime() const
{ {
if(rUseZEngine) if(rUseZEngine)
return rEngine->GetTime(); return rEngine->GetTime();
else else
return SDL_GetTicks(); return SDL_GetTicks();
} }
ZTimer::ZTimer(bool useZEngine) : ZTimer::ZTimer(bool useZEngine) :
rEngine(ZEngine::GetInstance()), rEngine(ZEngine::GetInstance()),
rUseZEngine(useZEngine), rUseZEngine(useZEngine)
rPaused(false) {
{ Reset(); //initializes other members
Reset(); }
}
ZTimer::~ZTimer()
ZTimer::~ZTimer() {
{ }
}
void ZTimer::Reset()
void ZTimer::Reset() {
{ rLastPause = rPausedTime = GetParentTime();
rLastPause = rPausedTime = GetParentTime(); rPaused = false;
rPaused = false; }
}
void ZTimer::Pause()
void ZTimer::Pause() {
{ if(!rPaused)
if(!rPaused) {
{ rLastPause = GetParentTime();
rLastPause = GetParentTime(); rPaused = true;
rPaused = true; }
} }
}
void ZTimer::Unpause()
void ZTimer::Unpause() {
{ if(rPaused)
if(rPaused) {
{ //when unpausing update the total paused time by that pause
//when unpausing update the total paused time by that pause rPausedTime += (GetParentTime()-rLastPause);
rPausedTime += (GetParentTime()-rLastPause); rPaused = false;
rPaused = false; }
} }
}
Uint32 ZTimer::GetTime() const
Uint32 ZTimer::GetTime() const {
{ if(rPaused) //when paused timer adjusted to subtract currently paused time
if(rPaused) //when paused timer adjusted to subtract currently paused time return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause));
return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause)); else
else return GetParentTime() - rPausedTime; //paused time is the cotal amt of time the program has been paused
return GetParentTime() - rPausedTime; //paused time is the cotal amt of time the program has been paused }
}
bool ZTimer::IsPaused() const
bool ZTimer::IsPaused() const {
{ return rPaused;
return rPaused; }
}
}
}

View File

@ -1,132 +1,132 @@
/******************************************************************************* /*******************************************************************************
This file is Part of the ZEngine Library for 2D game development. This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk Copyright (C) 2002, 2003 James Turk
ZEngine is Licensed under a BSD-style license. ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions. 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) The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZTimerTest.cpp,v 1.14 2003/07/10 20:45:39 cozman Exp $*/ /*$Id: ZTimerTest.cpp,v 1.15 2003/07/12 01:25:42 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
using namespace std; using namespace std;
using namespace ZE; using namespace ZE;
bool Initialize() bool Initialize()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf"); ZConfigFile cfg("tests.zcf");
int w,h,bpp,rate; int w,h,bpp,rate;
bool fs; bool fs;
std::string title; std::string title;
w = cfg.GetInt("ZTimerTest","width",800); w = cfg.GetInt("ZTimerTest","width",800);
h = cfg.GetInt("ZTimerTest","height",600); h = cfg.GetInt("ZTimerTest","height",600);
bpp = cfg.GetInt("ZTimerTest","bpp",32); bpp = cfg.GetInt("ZTimerTest","bpp",32);
fs = cfg.GetBool("ZTimerTest","fullscreen",false); fs = cfg.GetBool("ZTimerTest","fullscreen",false);
title = cfg.GetString("ZTimerTest","title","ZTimer Test"); title = cfg.GetString("ZTimerTest","title","ZTimer Test");
rate = cfg.GetInt("ZTimerTest","framerate",60); rate = cfg.GetInt("ZTimerTest","framerate",60);
engine->SetupDisplay(w,h,bpp,fs); engine->SetupDisplay(w,h,bpp,fs);
engine->SetDesiredFramerate(rate); engine->SetDesiredFramerate(rate);
return engine->CreateDisplay(title); return engine->CreateDisplay(title);
} }
void Test() void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
std::string TimerName[3] = {"ZEngine Timer", "ZEngine Hooked Timer", "SDL Hooked Timer"}; std::string TimerName[3] = {"ZEngine Timer", "ZEngine Hooked Timer", "SDL Hooked Timer"};
int curTimer = 0; int curTimer = 0;
//Open and Setup Font and Create Images and Timers// //Open and Setup Font and Create Images and Timers//
ZImage text[5]; ZImage text[5];
ZFont font("data/almontew.ttf",48); ZFont font("data/almontew.ttf",24);
ZTimer TimerOne, TimerTwo(false); //Timer Two is on the SDL Timer. ZTimer TimerOne, TimerTwo(false); //Timer Two is on the SDL Timer.
//do this only once// //do this only once//
font.DrawText("(T)oggle | (P)ause | (U)npause",text[4]); font.DrawText("(T)oggle | (P)ause | (U)npause",text[4]);
do do
{ {
//In the active loop, check events first// //In the active loop, check events first//
engine->CheckEvents(); engine->CheckEvents();
if(engine->IsActive()) if(engine->IsActive())
{ {
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
//pause current timer// //pause current timer//
if(engine->KeyIsPressed(SDLK_p)) if(engine->KeyIsPressed(SDLK_p))
{ {
switch(curTimer) switch(curTimer)
{ {
case 0: case 0:
engine->PauseTimer(); engine->PauseTimer();
break; break;
case 1: case 1:
TimerOne.Pause(); TimerOne.Pause();
break; break;
case 2: case 2:
TimerTwo.Pause(); TimerTwo.Pause();
break; break;
} }
} }
//unpause current timer// //unpause current timer//
if(engine->KeyIsPressed(SDLK_u)) if(engine->KeyIsPressed(SDLK_u))
{ {
switch(curTimer) switch(curTimer)
{ {
case 0: case 0:
engine->UnpauseTimer(); engine->UnpauseTimer();
break; break;
case 1: case 1:
TimerOne.Unpause(); TimerOne.Unpause();
break; break;
case 2: case 2:
TimerTwo.Unpause(); TimerTwo.Unpause();
break; break;
} }
} }
//switch// //switch//
if(engine->KeyIsPressed(SDLK_t)) if(engine->KeyIsPressed(SDLK_t))
{ {
if(++curTimer > 2) if(++curTimer > 2)
curTimer = 0; curTimer = 0;
engine->Delay(200); engine->Delay(200);
} }
//Render all the fonts// //Render all the fonts//
font.DrawText(FormatStr("Current Timer: %s",TimerName[curTimer].c_str()),text[0]); 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[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[1].c_str(),TimerOne.GetTime()),text[2]);
font.DrawText(FormatStr("%s Time: %d",TimerName[2].c_str(),TimerTwo.GetTime()),text[3]); font.DrawText(FormatStr("%s Time: %d",TimerName[2].c_str(),TimerTwo.GetTime()),text[3]);
engine->Clear(); //clear screen engine->Clear(); //clear screen
for(int i=0; i <= 4; i++) for(int i=0; i <= 4; i++)
text[i].Draw(0,i*50); text[i].Draw(0,i*30);
engine->Update(); //update the screen engine->Update(); //update the screen
} }
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request } while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
if(Initialize()) if(Initialize())
{ {
//engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available //engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available
Test(); Test();
} }
ZEngine::ReleaseInstance(); //release engine instance ZEngine::ReleaseInstance(); //release engine instance
return 0; return 0;
} }