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.
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.
<br>$Id: VersionInfo.h,v 1.3 2003/06/11 00:15:24 cozman Exp $<br>
\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.
<br>$Id: VersionInfo.h,v 1.4 2003/07/12 01:25:42 cozman Exp $<br>
\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__

View File

@ -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 $<br>
\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 <string> //used frequently
#include <queue> //used by ZEngine for ZErrors
#include <list> //used by ZConfigFile
#include <fstream> //used by ZConfigFile
#include <cctype> //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 $<br>
\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 <string> //used frequently
#include <queue> //used by ZEngine for ZErrors
#include <list> //used by ZConfigFile
#include <fstream> //used by ZConfigFile
#include <cctype> //used in parsing
#include <cstdarg> //used in FormatStr
#endif //__ze_includes_h__

View File

@ -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.
<br>$Id: ZE_ZBaseParticleSystem.h,v 1.4 2003/07/11 20:51:44 cozman Exp $<br>
\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 particleType>
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 <class particleType>
void ZBaseParticleSystem<particleType>::AddParticle()
{
//empty space is always at end, function is private so no checking is needed (Emit does that)
rParticles[rCurParticles] = NewParticle();
++rCurParticles;
}
template <class particleType>
ZBaseParticleSystem<particleType>::ZBaseParticleSystem()
{
rEngine = ZEngine::GetInstance();
rParticles = NULL;
rMaxParticles = rCurParticles = rNumParticlesPerSec = 0;
rLastUpdate = rEngine->GetTime();
rPaused = false;
}
template <class particleType>
ZBaseParticleSystem<particleType>::~ZBaseParticleSystem()
{
if(rParticles)
delete []rParticles;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Emit(int numParticles)
{
while(numParticles > 0 && rCurParticles < rMaxParticles)
{
AddParticle();
--numParticles;
}
}
template <class particleType>
void ZBaseParticleSystem<particleType>::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<int>(emitAmount); //only floating point portion of emitAmount
Emit(static_cast<int>(emitAmount));
if(overflow >= .95) //a little lower than one, for tolerance
{
Emit(1);
overflow = 0; //dump & clear overflow
}
}
rLastUpdate = rEngine->GetTime();
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Clear()
{
rCurParticles = 0;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Pause()
{
rPaused = true;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Unpause()
{
rPaused = false;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Stop()
{
Clear();
Pause();
}
template <class particleType>
bool ZBaseParticleSystem<particleType>::Paused()
{
return rPaused;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::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 <class particleType>
void ZBaseParticleSystem<particleType>::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.
<br>$Id: ZE_ZBaseParticleSystem.h,v 1.5 2003/07/12 01:25:42 cozman Exp $<br>
\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 particleType>
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 <class particleType>
void ZBaseParticleSystem<particleType>::AddParticle()
{
//empty space is always at end, function is private so no checking is needed (Emit does that)
rParticles[rCurParticles] = NewParticle();
++rCurParticles;
}
template <class particleType>
ZBaseParticleSystem<particleType>::ZBaseParticleSystem()
{
rEngine = ZEngine::GetInstance();
rParticles = NULL;
rMaxParticles = rCurParticles = rNumParticlesPerSec = 0;
rLastUpdate = rEngine->GetTime();
rPaused = false;
}
template <class particleType>
ZBaseParticleSystem<particleType>::~ZBaseParticleSystem()
{
if(rParticles)
delete []rParticles;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Emit(int numParticles)
{
while(numParticles > 0 && rCurParticles < rMaxParticles)
{
AddParticle();
--numParticles;
}
}
template <class particleType>
void ZBaseParticleSystem<particleType>::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<int>(emitAmount); //only floating point portion of emitAmount
Emit(static_cast<int>(emitAmount));
if(overflow >= .95) //a little lower than one, for tolerance
{
Emit(1);
overflow = 0; //dump & clear overflow
}
}
rLastUpdate = rEngine->GetTime();
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Clear()
{
rCurParticles = 0;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Pause()
{
rPaused = true;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Unpause()
{
rPaused = false;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::Stop()
{
Clear();
Pause();
}
template <class particleType>
bool ZBaseParticleSystem<particleType>::Paused()
{
return rPaused;
}
template <class particleType>
void ZBaseParticleSystem<particleType>::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 <class particleType>
void ZBaseParticleSystem<particleType>::SetRate(unsigned int rate)
{
rNumParticlesPerSec = rate;
}
} //namespace ZE
#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.
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.
<br>$Id: ZE_ZRandGen.h,v 1.1 2003/07/05 01:05:47 cozman Exp $<br>
\author James Turk
**/
#ifndef __ze_zrandgen_h__
#define __ze_zrandgen_h__
#include "ZE_Utility.h"
#include <ctime>
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__
/*******************************************************************************
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.
<br>$Id: ZE_ZRandGen.h,v 1.2 2003/07/12 01:25:42 cozman Exp $<br>
\author James Turk
**/
#ifndef __ze_zrandgen_h__
#define __ze_zrandgen_h__
#include "ZE_Utility.h"
#include <ctime>
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__

View File

@ -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.
<br>$Id: VersionInfo.cpp,v 1.4 2003/06/11 05:51:15 cozman Exp $<br>
\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.
<br>$Id: VersionInfo.cpp,v 1.5 2003/07/12 01:25:42 cozman Exp $<br>
\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 >
}

View File

@ -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.
<br>$Id: ZE_Utility.cpp,v 1.9 2003/06/11 05:51:15 cozman Exp $<br>
\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.
<br>$Id: ZE_Utility.cpp,v 1.10 2003/07/12 01:25:42 cozman Exp $<br>
\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
}

View File

@ -13,7 +13,7 @@
\brief Central source file for 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
**/
@ -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
}

View File

@ -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.
<br>$Id: ZE_ZRandGen.cpp,v 1.1 2003/07/05 00:58:08 cozman Exp $<br>
\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<N-M;++kk) {
y = (rStateVector[kk]&UPPER_MASK)|(rStateVector[kk+1]&LOWER_MASK);
rStateVector[kk] = rStateVector[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
for (;kk<N-1;++kk) {
y = (rStateVector[kk]&UPPER_MASK)|(rStateVector[kk+1]&LOWER_MASK);
rStateVector[kk] = rStateVector[kk+(M-N)] ^ (y >> 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<unsigned long>(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.
<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.
**/
#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<N-M;++kk) {
y = (rStateVector[kk]&UPPER_MASK)|(rStateVector[kk+1]&LOWER_MASK);
rStateVector[kk] = rStateVector[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
}
for (;kk<N-1;++kk) {
y = (rStateVector[kk]&UPPER_MASK)|(rStateVector[kk+1]&LOWER_MASK);
rStateVector[kk] = rStateVector[kk+(M-N)] ^ (y >> 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<unsigned long>(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<N; ++rStateVectorIndex)
{
rStateVector[rStateVectorIndex] =
(1812433253UL * (rStateVector[rStateVectorIndex-1] ^ (rStateVector[rStateVectorIndex-1] >> 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<N; ++rStateVectorIndex)
{
rStateVector[rStateVectorIndex] =
(1812433253UL * (rStateVector[rStateVectorIndex-1] ^ (rStateVector[rStateVectorIndex-1] >> 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 */
}
}

View File

@ -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.
<br>$Id: ZE_ZTimer.cpp,v 1.9 2003/06/11 05:51:16 cozman Exp $<br>
\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.
<br>$Id: ZE_ZTimer.cpp,v 1.10 2003/07/12 01:25:42 cozman Exp $<br>
\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;
}
}

View File

@ -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 <ZEngine.h>
#include <string>
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 <ZEngine.h>
#include <string>
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;
}