planning split

This commit is contained in:
James Turk 2004-01-13 23:52:01 +00:00
parent bdb2afe245
commit dcd715832d
33 changed files with 833 additions and 213 deletions

View File

@ -17,8 +17,12 @@
#define ZE_SDL (2) #define ZE_SDL (2)
#define GFX_BACKEND (ZE_OGL) #define GFX_BACKEND (ZE_OGL)
#define ZE_NONE (0)
#define ZE_MIXER (1)
#define ZE_AUDIERE (2)
#define SND_BACKEND (ZE_MIXER)
#define USE_SDL_TTF #define USE_SDL_TTF
#define USE_SDL_IMAGE #define USE_SDL_IMAGE
#define USE_AUDIERE
#endif //__ze_defines_h__ #endif //__ze_defines_h__

View File

@ -23,7 +23,10 @@
#ifdef USE_SDL_TTF #ifdef USE_SDL_TTF
#include "SDL_ttf.h" #include "SDL_ttf.h"
#endif #endif
#ifdef USE_AUDIERE
#if SND_BACKEND == ZE_MIXER
#include "SDL_mixer.h"
#elif SND_BACKEND == ZE_AUDIERE
#include "audiere.h" #include "audiere.h"
#endif #endif

View File

@ -11,6 +11,7 @@
#ifndef __ze_utility_h__ #ifndef __ze_utility_h__
#define __ze_utility_h__ #define __ze_utility_h__
#include "ZE_Defines.h"
#include "ZE_Includes.h" #include "ZE_Includes.h"
namespace ZE namespace ZE
@ -18,6 +19,7 @@ namespace ZE
std::string FormatStr(std::string fmtStr, ...); std::string FormatStr(std::string fmtStr, ...);
int LoadFromZip(std::string zipname, std::string filename, void *&buffer);
SDL_RWops* RWFromZip(std::string zipname, std::string filename); SDL_RWops* RWFromZip(std::string zipname, std::string filename);
#if (GFX_BACKEND == ZE_OGL) #if (GFX_BACKEND == ZE_OGL)
@ -27,6 +29,11 @@ GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord);
void FreeImage(SDL_Surface *&image); void FreeImage(SDL_Surface *&image);
#if SND_BACKEND == ZE_MIXER
void FreeSound(Mix_Chunk *&chunk);
void FreeMusic(Mix_Music *&music);
#endif
#ifdef USE_SDL_TTF #ifdef USE_SDL_TTF
void FreeFont(TTF_Font *&font); void FreeFont(TTF_Font *&font);
#endif #endif

View File

@ -8,33 +8,40 @@
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
#ifndef __ze_zsoundbase_h__ #ifndef __ze_zaudiobase_h__
#define __ze_zsoundbase_h__ #define __ze_zaudiobase_h__
#include "ZE_ZEngine.h" #include "ZE_ZEngine.h"
#ifdef USE_AUDIERE #if SND_BACKEND == ZE_AUDIERE
namespace ZE namespace ZE
{ {
class ZSoundBase class ZAudioBase
{ {
protected: protected:
//ZEngine* rEngine; ZEngine* rEngine;
audiere::AudioDevicePtr rDevice; audiere::AudioDevicePtr rDevice;
audiere::OutputStreamPtr rStream; audiere::OutputStreamPtr rStream;
int rPausePos;
public: public:
ZSoundBase(); ZAudioBase();
virtual ~ZSoundBase(); virtual ~ZAudioBase();
virtual void Open(std::string filename)=0; virtual void Open(std::string filename)=0;
virtual void OpenFromZip(std::string zipname, std::string filename)=0;
virtual void OpenFromZRF(std::string resourceId)=0;
//void Release();
void Play(bool loop=false); void Play(bool loop=false);
void Pause();
void Unpause();
void Rewind();
void Stop(); void Stop();
void SetVolume(float volume); void SetVolume(int volume);
void SetPan(float pan); void SetPan(float pan);
void SetPitch(float pitch); void SetPitch(float pitch);
void SetPosition(int position); void SetPosition(int position);
@ -42,8 +49,9 @@ class ZSoundBase
bool IsLoaded() const; bool IsLoaded() const;
bool IsPlaying() const; bool IsPlaying() const;
bool IsPaused() const;
bool IsSeekable() const; bool IsSeekable() const;
float GetVolume() const; int GetVolume() const;
float GetPan() const; float GetPan() const;
float GetPitch() const; float GetPitch() const;
int GetPosition() const; int GetPosition() const;
@ -52,6 +60,6 @@ class ZSoundBase
} }
#endif //USE_AUDIERE #endif //ZE_AUDIERE
#endif //__ze_zsound_h__ #endif //__ze_zaudiobase_h__

View File

@ -70,9 +70,14 @@ class ZEngine
std::FILE *mErrlog; std::FILE *mErrlog;
ZRandGen mRandGen; ZRandGen mRandGen;
TiXmlDocument rZRF; TiXmlDocument rZRF;
#ifdef USE_AUDIERE #if SND_BACKEND == ZE_MIXER
int mMixerFrequency;
Uint16 mMixerFormat;
int mMixerChannels;
int mMixerChunksize;
#elif SND_BACKEND == ZE_AUDIERE
audiere::AudioDevicePtr mAudiereDevice; audiere::AudioDevicePtr mAudiereDevice;
#endif //USE_AUDIERE #endif
ZEngine(); ZEngine();
@ -83,7 +88,11 @@ class ZEngine
static void ReleaseInstance(); static void ReleaseInstance();
void InitErrorLog(ZErrorLogStyle logStyle=ZLOG_HTML, std::string logFile="errlog.html", ZErrorSeverity severityFilter=ZERR_VERBOSE); void InitErrorLog(ZErrorLogStyle logStyle=ZLOG_HTML, std::string logFile="errlog.html", ZErrorSeverity severityFilter=ZERR_VERBOSE);
bool InitSound(); #if SND_BACKEND == ZE_MIXER
void InitAudio(int frequency=MIX_DEFAULT_FREQUENCY, bool stereo=true, Uint16 format=MIX_DEFAULT_FORMAT, int chunksize=4096);
#elif SND_BACKEND == ZE_AUDIERE
bool InitAudio();
#endif
bool CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title="ZEngine Application", std::string icon=""); bool CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title="ZEngine Application", std::string icon="");
void CloseDisplay(); void CloseDisplay();
void ToggleFullscreen(); void ToggleFullscreen();
@ -144,9 +153,9 @@ class ZEngine
int GetIntResource(std::string type, std::string id, std::string element); int GetIntResource(std::string type, std::string id, std::string element);
double GetDoubleResource(std::string type, std::string id, std::string element); double GetDoubleResource(std::string type, std::string id, std::string element);
#ifdef USE_AUDIERE #if SND_BACKEND == ZE_AUDIERE
audiere::AudioDevicePtr GetSoundDevice(); audiere::AudioDevicePtr GetSoundDevice();
#endif //USE_AUDIERE #endif
SDL_Surface* GetDisplayPointer(); SDL_Surface* GetDisplayPointer();
bool DisplayCreated(); bool DisplayCreated();
int DisplayWidth(); int DisplayWidth();

81
include/ZE_ZSound.h Normal file
View File

@ -0,0 +1,81 @@
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002-2004 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
#ifndef __ze_zsound_h__
#define __ze_zsound_h__
#include "ZE_ZEngine.h"
#include "ZE_ZAudioBase.h"
namespace ZE
{
#if SND_BACKEND == ZE_MIXER
class ZSound
{
protected:
ZEngine* rEngine;
Mix_Chunk* rSound;
int rChannelID;
public:
static const int LoopInfinite;
ZSound();
ZSound(std::string filename);
virtual ~ZSound();
void Open(std::string filename);
void OpenFromZip(std::string zipname, std::string filename);
void OpenFromZRF(std::string resourceId);
void Release();
void Play(int loopNum=0, int fadeTime=0);
void Pause() const;
void Unpause() const;
void Rewind() const;
void Stop(int fadeTime=0) const;
void SetVolume(int volume);
void SetPan(float pan);
//void SetPitch(float pitch);
void SetPosition(int position);
//void SetPosition(float posPercent);
bool IsLoaded() const;
bool IsPlaying() const;
bool IsPaused() const;
bool IsSeekable() const;
int GetVolume() const;
//float GetPan() const;
//float GetPitch() const;
//int GetPosition() const;
//int GetLength() const;
};
#elif SND_BACKEND == ZE_AUDIERE
class ZSound : public ZAudioBase
{
public:
ZSound();
ZSound(std::string filename);
void Open(std::string filename);
void OpenFromZip(std::string zipname, std::string filename);
void OpenFromZRF(std::string resourceId);
};
#endif //SND_BACKEND
}
#endif //__ze_zsound_h__

View File

@ -15,7 +15,7 @@
#ifdef USE_SDL_TTF #ifdef USE_SDL_TTF
#include "ZE_ZFont.h" #include "ZE_ZFont.h"
#endif #endif
#ifdef USE_AUDIERE #if SND_BACKEND != ZE_NONE
#include "ZE_ZSound.h" #include "ZE_ZSound.h"
#include "ZE_ZMusic.h" #include "ZE_ZMusic.h"
#endif #endif

View File

@ -26,23 +26,24 @@ std::string FormatStr(std::string fmtStr, ...)
return buf; return buf;
} }
SDL_RWops* RWFromZip(std::string zipname, std::string filename) int LoadFromZip(std::string zipname, std::string filename, void *&buffer)
{ {
unzFile zip = unzOpen(zipname.c_str()); unzFile zip = unzOpen(zipname.c_str());
unz_file_info info; unz_file_info info;
void *buffer;
buffer = NULL; //start off buffer as NULL
if(!zip) //failed to open zip if(!zip) //failed to open zip
{ {
ZEngine::GetInstance()->ReportError(ZERR_WARNING,"Could not open zipfile %s",zipname.c_str()); ZEngine::GetInstance()->ReportError(ZERR_WARNING,"Could not open zipfile %s",zipname.c_str());
return NULL; return 0;
} }
//locate the file and open it (last param means case sensitive comparison) //locate the file and open it (last param means case sensitive comparison)
unzLocateFile(zip,filename.c_str(),0); unzLocateFile(zip,filename.c_str(),0);
if(unzOpenCurrentFile(zip) != UNZ_OK) //failed to open file within zip if(unzOpenCurrentFile(zip) != UNZ_OK) //failed to open file within zip
{ {
return NULL; //error should reported in calling function return 0; //error should reported in calling function
} }
//find current file info (we are looking for uncompressed file size) //find current file info (we are looking for uncompressed file size)
@ -55,7 +56,7 @@ SDL_RWops* RWFromZip(std::string zipname, std::string filename)
unzCloseCurrentFile(zip); unzCloseCurrentFile(zip);
unzClose(zip); unzClose(zip);
ZEngine::GetInstance()->ReportError(ZERR_ERROR,"RWFromZip failed to allocate enough memory for buffer while loading %s from %s.",filename.c_str(),zipname.c_str()); ZEngine::GetInstance()->ReportError(ZERR_ERROR,"RWFromZip failed to allocate enough memory for buffer while loading %s from %s.",filename.c_str(),zipname.c_str());
return NULL; return 0;
} }
//load into memory //load into memory
@ -65,7 +66,17 @@ SDL_RWops* RWFromZip(std::string zipname, std::string filename)
unzCloseCurrentFile(zip); unzCloseCurrentFile(zip);
unzClose(zip); unzClose(zip);
return SDL_RWFromMem(buffer, info.uncompressed_size); //return buffer in RW form return info.uncompressed_size; //return the buffer size
}
SDL_RWops* RWFromZip(std::string zipname, std::string filename)
{
void *buffer;
int bufSize;
bufSize = LoadFromZip(zipname,filename,buffer);
return SDL_RWFromMem(buffer,bufSize);
} }
#if (GFX_BACKEND == ZE_OGL) #if (GFX_BACKEND == ZE_OGL)
@ -157,6 +168,28 @@ void FreeImage(SDL_Surface *&image)
} }
} }
#if SND_BACKEND == ZE_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 //ZE_MIXER
#ifdef USE_SDL_TTF #ifdef USE_SDL_TTF
void FreeFont(TTF_Font *&font) void FreeFont(TTF_Font *&font)

144
src/ZE_ZAudioBase.cpp Normal file
View File

@ -0,0 +1,144 @@
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002-2004 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
#include "ZE_ZAudioBase.h"
#if SND_BACKEND == ZE_AUDIERE
namespace ZE
{
ZAudioBase::ZAudioBase() :
rEngine(ZEngine::GetInstance()),
rDevice(rEngine->GetSoundDevice()),
rPausePos(0)
{
}
ZAudioBase::~ZAudioBase()
{
}
void ZAudioBase::Play(bool loop)
{
rStream->play();
rStream->setRepeat(loop);
}
void ZAudioBase::Pause()
{
rPausePos = rStream->getPosition();
rStream->stop();
}
void ZAudioBase::Unpause()
{
if(rPausePos)
{
rStream->setPosition(rPausePos);
rPausePos = 0;
}
rStream->play();
}
void ZAudioBase::Rewind()
{
rStream->reset();
rPausePos = 0;
}
void ZAudioBase::Stop()
{
rStream->stop();
rStream->reset();
rPausePos = 0;
}
void ZAudioBase::SetVolume(int volume)
{
if(volume < 0)
volume = 0;
else if(volume > 100)
volume = 100;
rStream->setVolume(volume/100.0f);
}
void ZAudioBase::SetPan(float pan)
{
rStream->setPan(pan);
}
void ZAudioBase::SetPitch(float pitch)
{
rStream->setPitchShift(pitch);
}
void ZAudioBase::SetPosition(int position)
{
rPausePos = 0;
rStream->setPosition(position);
}
void ZAudioBase::SetPosition(float posPercent)
{
rPausePos = 0;
rStream->setPosition(static_cast<int>(posPercent*rStream->getLength()));
}
bool ZAudioBase::IsLoaded() const
{
return (rStream != NULL);
}
bool ZAudioBase::IsPlaying() const
{
return rStream->isPlaying();
}
bool ZAudioBase::IsPaused() const
{
return (rPausePos != 0);
}
bool ZAudioBase::IsSeekable() const
{
return rStream->isSeekable();
}
int ZAudioBase::GetVolume() const
{
//cast here needs to be accurate, adds .5 to get proper rounding
return static_cast<int>((rStream->getVolume()*100)+.5);
}
float ZAudioBase::GetPan() const
{
return rStream->getPan();
}
float ZAudioBase::GetPitch() const
{
return rStream->getPitchShift();
}
int ZAudioBase::GetPosition() const
{
return rStream->getPosition();
}
int ZAudioBase::GetLength() const
{
return rStream->getLength();
}
}
#endif //ZE_AUDIERE

View File

@ -26,6 +26,9 @@ ZEngine::ZEngine() :
mMouseX(0), mMouseY(0), mMouseB(0), mMouseX(0), mMouseY(0), mMouseB(0),
mEventFilter(NULL), mEventFilter(NULL),
mLogStyle(ZLOG_NONE), mMinSeverity(ZERR_NOTE), mErrlog(NULL) mLogStyle(ZLOG_NONE), mMinSeverity(ZERR_NOTE), mErrlog(NULL)
#if SND_BACKEND == ZE_MIXER
,mMixerFrequency(0),mMixerFormat(0),mMixerChannels(0),mMixerChunksize(0)
#endif
{ {
for(int k = 0; k < SDLK_LAST; ++k) for(int k = 0; k < SDLK_LAST; ++k)
mKeyPress[k] = false; mKeyPress[k] = false;
@ -49,9 +52,8 @@ TiXmlElement* ZEngine::FindElement(std::string type, std::string id)
elem = elem->NextSiblingElement(); elem = elem->NextSiblingElement();
} }
//if it gets here, element not found if(!elem)
ReportError(ZERR_WARNING,"No '%s' resource found with id '%s'",type.c_str(),id.c_str()); ReportError(ZERR_WARNING,"No '%s' resource found with id '%s'",type.c_str(),id.c_str());
elem = NULL;
} }
else else
{ {
@ -116,7 +118,16 @@ void ZEngine::InitErrorLog(ZErrorLogStyle logStyle, std::string logFile, ZErrorS
} }
} }
bool ZEngine::InitSound() #if SND_BACKEND == ZE_MIXER
void ZEngine::InitAudio(int frequency, bool stereo, Uint16 format, int chunksize)
{
mMixerFrequency = frequency;
mMixerChannels = stereo ? 2 : 1;
mMixerFormat = format;
mMixerChunksize = chunksize;
}
#elif SND_BACKEND == ZE_AUDIERE
bool ZEngine::InitAudio()
{ {
mAudiereDevice = audiere::OpenDevice(); mAudiereDevice = audiere::OpenDevice();
if(!mAudiereDevice) if(!mAudiereDevice)
@ -125,9 +136,11 @@ bool ZEngine::InitSound()
} }
return (mAudiereDevice != NULL); return (mAudiereDevice != NULL);
} }
#endif //SND_BACKEND
bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title, std::string icon) bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std::string title, std::string icon)
{ {
Uint32 sdlFlags=SDL_INIT_VIDEO|SDL_INIT_TIMER;
Uint32 vidFlags=0; Uint32 vidFlags=0;
SDL_Surface *iconImg; SDL_Surface *iconImg;
bool status=true; //status of setup, only true if everything went flawlessly bool status=true; //status of setup, only true if everything went flawlessly
@ -138,15 +151,31 @@ bool ZEngine::CreateDisplay(int width, int height, int bpp, bool fullscreen, std
mFullscreen = fullscreen; mFullscreen = fullscreen;
#if SND_BACKEND == ZE_MIXER
if(mMixerFrequency && mMixerFormat && mMixerChannels && mMixerChunksize)
sdlFlags |= SDL_INIT_AUDIO;
#endif
if(!mInitialized) if(!mInitialized)
{ {
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0) if(SDL_Init(sdlFlags) < 0)
{ {
ReportError(ZERR_CRITICAL,"Error initializing SDL: %s",SDL_GetError()); ReportError(ZERR_CRITICAL,"Error initializing SDL: %s",SDL_GetError());
return false; //return now, nothing else should be called return false; //return now, nothing else should be called
} }
} }
#if SND_BACKEND == ZE_MIXER
if(!mInitialized && mMixerFrequency && mMixerFormat && mMixerChannels && mMixerChunksize)
{
if(Mix_OpenAudio(mMixerFrequency,mMixerFormat,mMixerChannels,mMixerChunksize) < 0)
{
ReportError(ZERR_ERROR,"Error initializing SDL_mixer: %s",SDL_GetError());
status = false;
}
}
#endif //USE_SDL_MIXER
//set vidFlags and bpp// //set vidFlags and bpp//
if(mFullscreen) if(mFullscreen)
vidFlags |= SDL_FULLSCREEN; vidFlags |= SDL_FULLSCREEN;
@ -698,10 +727,12 @@ double ZEngine::GetDoubleResource(std::string type, std::string id, std::string
return ret; return ret;
} }
#if SND_BACKEND == ZE_AUDIERE
audiere::AudioDevicePtr ZEngine::GetSoundDevice() audiere::AudioDevicePtr ZEngine::GetSoundDevice()
{ {
return mAudiereDevice; return mAudiereDevice;
} }
#endif
SDL_Surface *ZEngine::GetDisplayPointer() SDL_Surface *ZEngine::GetDisplayPointer()
{ {

View File

@ -10,16 +10,182 @@
#include "ZE_ZMusic.h" #include "ZE_ZMusic.h"
#ifdef USE_AUDIERE
namespace ZE namespace ZE
{ {
ZMusic::ZMusic() #if SND_BACKEND == ZE_MIXER
const int ZMusic::LoopInfinite = -1; //constant for infinite, as used by SDL_Mixer
ZMusic::ZMusic() :
rEngine(ZEngine::GetInstance()),
rMusic(NULL)
{ {
} }
ZMusic::ZMusic(std::string filename) : ZSoundBase() ZMusic::ZMusic(std::string filename) :
rEngine(ZEngine::GetInstance()),
rMusic(NULL)
{
Open(filename);
}
ZMusic::~ZMusic()
{
Release();
}
void ZMusic::Open(std::string filename)
{
Release();
rMusic = Mix_LoadMUS(filename.c_str());
if(!rMusic)
rEngine->ReportError(ZERR_WARNING,"Could not load %s",filename.c_str());
}
void ZMusic::OpenFromZRF(std::string resourceId)
{
std::string filename = rEngine->GetStringResource("music",resourceId,"filename");
if(filename.length())
Open(filename);
else
rEngine->ReportError(ZERR_WARNING,"Failed to load music resource '%s'",resourceId.c_str());
}
void ZMusic::Release()
{
Mix_HaltMusic();
FreeMusic(rMusic);
}
void ZMusic::Play(int loopNum, int fadeTime) const
{
if(Mix_PlayingMusic()) //stop currently playing music
Mix_HaltMusic();
if(rMusic)
{
if(fadeTime)
Mix_FadeInMusic(rMusic, loopNum, fadeTime);
else
Mix_PlayMusic(rMusic, loopNum);
}
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Play with no music loaded.");
}
void ZMusic::Pause() const
{
if(rMusic)
Mix_PauseMusic();
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Pause with no music loaded.");
}
void ZMusic::Unpause() const
{
if(rMusic)
Mix_ResumeMusic();
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Unpause with no music loaded.");
}
void ZMusic::Rewind() const
{
if(rMusic)
Mix_RewindMusic();
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Rewind with no music loaded.");
}
void ZMusic::Stop(int fadeTime) const
{
if(rMusic)
{
if(fadeTime)
Mix_FadeOutMusic(fadeTime);
else
Mix_HaltMusic();
}
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::Stop with no music loaded.");
}
void ZMusic::SetVolume(int volume)
{
if(rMusic)
Mix_VolumeMusic(volume);
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::SetVolume with no music loaded.");
}
void ZMusic::SetPosition(int position)
{
if(rMusic)
{
if(!IsSeekable() || Mix_SetMusicPosition(static_cast<double>(position)) == -1)
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::SetPosition on non-seekable file.");
}
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::SetPosition with no music loaded.");
}
bool ZMusic::IsLoaded() const
{
return rMusic != NULL;
}
bool ZMusic::IsPlaying() const
{
if(rMusic)
return Mix_PlayingMusic() > 0;
else
{
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::IsPlaying with no music loaded.");
return false;
}
}
bool ZMusic::IsPaused() const
{
if(rMusic)
return Mix_PausedMusic() > 0;
else
{
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::IsPaused with no music loaded.");
return false;
}
}
bool ZMusic::IsSeekable() const
{
Mix_MusicType type = Mix_GetMusicType(rMusic);
if(type == MUS_MOD || type == MUS_OGG || type == MUS_MP3)
return true;
else
return false;
}
int ZMusic::GetVolume() const
{
if(rMusic)
return Mix_VolumeMusic(-1);
else
{
rEngine->ReportError(ZERR_VERBOSE,"Called ZMusic::GetVolume with no music loaded.");
return false;
}
}
#elif SND_BACKEND == ZE_AUDIERE
ZMusic::ZMusic() : ZAudioBase()
{
}
ZMusic::ZMusic(std::string filename) : ZAudioBase()
{ {
Open(filename); Open(filename);
} }
@ -29,6 +195,24 @@ void ZMusic::Open(std::string filename)
rStream = audiere::OpenSound(rDevice, filename.c_str(), true); rStream = audiere::OpenSound(rDevice, filename.c_str(), true);
} }
void ZMusic::OpenFromZip(std::string zipname, std::string filename)
{
void *buffer;
int bufSize;
bufSize = LoadFromZip(zipname, filename, buffer);
rStream = audiere::OpenSound(rDevice, audiere::hidden::AdrCreateMemoryFile(buffer,bufSize), true);
} }
#endif void ZMusic::OpenFromZRF(std::string resourceId)
{
std::string filename = rEngine->GetStringResource("music",resourceId,"filename");
if(filename.length())
Open(filename);
else
rEngine->ReportError(ZERR_WARNING,"Failed to load music resource '%s'",resourceId.c_str());
}
#endif //SND_BACKEND
}

View File

@ -8,19 +8,202 @@
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
#include "ZE_ZSound.h" //ZSound is almost exactly like ZMusic, when making changes check if that change should
#include "ZE_ZSoundBase.h" //be applied to ZMusic as well, roughly 95% of the time it should be.
#ifdef USE_AUDIERE #include "ZE_ZSound.h"
namespace ZE namespace ZE
{ {
ZSound::ZSound() #if SND_BACKEND == ZE_MIXER
const int ZSound::LoopInfinite = -1;
ZSound::ZSound() :
rEngine(ZEngine::GetInstance()),
rSound(NULL),
rChannelID(-1) //request channel ID
{ {
} }
ZSound::ZSound(std::string filename) : ZSoundBase() ZSound::ZSound(std::string filename) :
rEngine(ZEngine::GetInstance()),
rSound(NULL),
rChannelID(-1) //request channel ID
{
Open(filename);
}
ZSound::~ZSound()
{
Release();
}
void ZSound::Open(std::string filename)
{
Release();
rSound = Mix_LoadWAV(filename.c_str());
if(!rSound)
rEngine->ReportError(ZERR_ERROR,"Could not load %s",filename.c_str());
}
void ZSound::OpenFromZip(std::string zipname, std::string filename)
{
SDL_RWops *rw = RWFromZip(zipname,filename);
if(rw)
{
rSound = Mix_LoadWAV_RW(rw,0);
delete []rw->hidden.mem.base; //must free buffer
SDL_FreeRW(rw);
}
if(!rSound)
rEngine->ReportError(ZERR_WARNING,"Could not load %s from %s",filename.c_str(),zipname.c_str());
}
void ZSound::OpenFromZRF(std::string resourceId)
{
std::string filename = rEngine->GetStringResource("sound",resourceId,"filename");
if(filename.length())
Open(filename);
else
rEngine->ReportError(ZERR_WARNING,"Failed to load sound resource '%s'",resourceId.c_str());
}
void ZSound::Release()
{
if(rChannelID >= 0)
Mix_HaltChannel(rChannelID);
FreeSound(rSound);
}
void ZSound::Play(int loopNum, int fadeTime)
{
if(rChannelID >= 0 && Mix_Playing(rChannelID)) //stop currently playing sound
Mix_HaltChannel(rChannelID);
if(rSound)
{
if(fadeTime)
rChannelID = Mix_FadeInChannel(rChannelID, rSound, loopNum, fadeTime);
else
rChannelID = Mix_PlayChannel(rChannelID, rSound, loopNum);
}
else if(!rSound)
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Play with no sound effect loaded.");
}
void ZSound::Pause() const
{
if(rSound && rChannelID >= 0)
Mix_Pause(rChannelID);
else if(!rSound)
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Pause with no sound effect loaded.");
}
void ZSound::Unpause() const
{
if(rSound && rChannelID >= 0)
Mix_Resume(rChannelID);
else if(!rSound)
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Unpause with no sound effect loaded.");
}
void ZSound::Stop(int fadeTime) const
{
if(rSound && rChannelID >= 0)
{
if(fadeTime)
Mix_FadeOutChannel(rChannelID,fadeTime);
else
Mix_HaltChannel(rChannelID);
}
else if(!rSound)
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::Stop with no sound effect loaded.");
}
void ZSound::SetVolume(int volume)
{
if(rSound)
Mix_VolumeChunk(rSound,volume);
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::SetVolume with no sound effect loaded.");
}
void ZSound::SetPan(float pan)
{
if(rSound)
{
if(pan == 0)
Mix_SetPanning(rChannelID,255,255);
else if(pan < 0)
Mix_SetPanning(rChannelID, static_cast<Uint8>(128+(128*-pan)), 128);
else
Mix_SetPanning(rChannelID, 128, static_cast<Uint8>(128+(128*pan)));
}
else
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::SetPan with no sound effect loaded.");
}
void ZSound::SetPosition(int position)
{
//no-op, non-seekable currently
}
bool ZSound::IsLoaded() const
{
return rSound != NULL;
}
bool ZSound::IsPlaying() const
{
if(rSound && rChannelID >= 0)
return Mix_Playing(rChannelID) > 0;
else
{
if(rChannelID >= 0)
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::IsPlaying with no sound effect loaded.");
return false;
}
}
bool ZSound::IsPaused() const
{
if(rSound && rChannelID >= 0)
return Mix_Paused(rChannelID) > 0;
else
{
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::IsPaused with no sound effect loaded.");
return false;
}
}
bool ZSound::IsSeekable() const
{
return false; //no Mix_Chunks are seekable atm.
}
int ZSound::GetVolume() const
{
if(rSound)
return Mix_VolumeChunk(rSound,-1);
else
{
rEngine->ReportError(ZERR_VERBOSE,"Called ZSound::GetVolume with no sound effect loaded.");
return -1;
}
}
#elif SND_BACKEND == ZE_AUDIERE
ZSound::ZSound() : ZAudioBase()
{
}
ZSound::ZSound(std::string filename) : ZAudioBase()
{ {
Open(filename); Open(filename);
} }
@ -30,6 +213,24 @@ void ZSound::Open(std::string filename)
rStream = audiere::OpenSound(rDevice, filename.c_str(), false); rStream = audiere::OpenSound(rDevice, filename.c_str(), false);
} }
void ZSound::OpenFromZip(std::string zipname, std::string filename)
{
void *buffer;
int bufSize;
bufSize = LoadFromZip(zipname, filename, buffer);
rStream = audiere::OpenSound(rDevice, audiere::hidden::AdrCreateMemoryFile(buffer,bufSize), false);
} }
#endif void ZSound::OpenFromZRF(std::string resourceId)
{
std::string filename = rEngine->GetStringResource("music",resourceId,"filename");
if(filename.length())
Open(filename);
else
rEngine->ReportError(ZERR_WARNING,"Failed to load music resource '%s'",resourceId.c_str());
}
#endif //SND_BACKEND
}

View File

@ -1,106 +0,0 @@
/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002-2004 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
#include "ZE_ZSoundBase.h"
#ifdef USE_AUDIERE
namespace ZE
{
ZSoundBase::ZSoundBase()
{
rDevice = ZEngine::GetInstance()->GetSoundDevice();
}
ZSoundBase::~ZSoundBase()
{
}
void ZSoundBase::Play(bool loop)
{
rStream->play();
rStream->setRepeat(true);
}
void ZSoundBase::Stop()
{
rStream->stop();
}
void ZSoundBase::SetVolume(float volume)
{
rStream->setVolume(volume);
}
void ZSoundBase::SetPan(float pan)
{
rStream->setPan(pan);
}
void ZSoundBase::SetPitch(float pitch)
{
rStream->setPitchShift(pitch);
}
void ZSoundBase::SetPosition(int position)
{
rStream->setPosition(position);
}
void ZSoundBase::SetPosition(float posPercent)
{
rStream->setPosition(static_cast<int>(posPercent*rStream->getLength()));
}
bool ZSoundBase::IsLoaded() const
{
return (rStream != NULL);
}
bool ZSoundBase::IsPlaying() const
{
return rStream->isPlaying();
}
bool ZSoundBase::IsSeekable() const
{
return rStream->isSeekable();
}
float ZSoundBase::GetVolume() const
{
return rStream->getVolume();
}
float ZSoundBase::GetPan() const
{
return rStream->getPan();
}
float ZSoundBase::GetPitch() const
{
return rStream->getPitchShift();
}
int ZSoundBase::GetPosition() const
{
return rStream->getPosition();
}
int ZSoundBase::GetLength() const
{
return rStream->getLength();
}
}
#endif

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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: ZAnimTest.cpp,v 1.2 2003/12/31 12:27:58 cozman Exp $ // $Id: ZAnimTest.cpp,v 1.3 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -30,6 +30,7 @@ bool Initialize()
fs = cfg.GetBool("ZAnimTest","fullscreen",false); fs = cfg.GetBool("ZAnimTest","fullscreen",false);
title = cfg.GetString("ZAnimTest","title","ZAnimation Test"); title = cfg.GetString("ZAnimTest","title","ZAnimation Test");
engine->InitErrorLog();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -72,7 +73,7 @@ void Test()
for(i=0; i < 8; ++i) for(i=0; i < 8; ++i)
tank[i].Update(); tank[i].Update();
engine->Clear(); engine->ClearDisplay();
for(i=0; i < 8; ++i) for(i=0; i < 8; ++i)
tank[i].Draw(200*(i/2),200*(i%2)); tank[i].Draw(200*(i/2),200*(i%2));

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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: ZFontTest.cpp,v 1.20 2003/12/31 12:27:58 cozman Exp $ // $Id: ZFontTest.cpp,v 1.21 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -31,7 +31,7 @@ bool Initialize()
title = cfg.GetString("ZFontTest","title","ZFont Test"); title = cfg.GetString("ZFontTest","title","ZFont Test");
engine->SetResourceFile("resources.zrf"); engine->SetResourceFile("resources.zrf");
engine->InitErrorLog();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -69,7 +69,7 @@ void Test()
engine->RequestQuit(); engine->RequestQuit();
betsy.DrawText(FormatStr("FPS: %.2f",engine->GetFramerate()),text[5]); betsy.DrawText(FormatStr("FPS: %.2f",engine->GetFramerate()),text[5]);
engine->Clear(); //clear screen engine->ClearDisplay(); //clear screen
//draw the images// //draw the images//
for(int i=0; i <= 5; i++) for(int i=0; i <= 5; i++)
text[i].Draw(10*i,50*i); text[i].Draw(10*i,50*i);

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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: ZImageTest.cpp,v 1.30 2003/12/31 12:27:58 cozman Exp $ // $Id: ZImageTest.cpp,v 1.31 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -31,7 +31,7 @@ bool Initialize()
title = cfg.GetString("ZImageTest","title","ZImage Test"); title = cfg.GetString("ZImageTest","title","ZImage Test");
engine->SetResourceFile("resources.zrf"); engine->SetResourceFile("resources.zrf");
engine->InitErrorLog();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -49,7 +49,7 @@ void Test()
font.SetColor(0,255,0); font.SetColor(0,255,0);
font.SetBGColor(0,0,255); font.SetBGColor(0,0,255);
engine->SetErrorLog(ZLOG_HTML,"err.html"); engine->InitErrorLog();
engine->ReportError(ZERR_CRITICAL,"This is a critical test error!!! Something has gone seriously wrong!"); engine->ReportError(ZERR_CRITICAL,"This is a critical test error!!! Something has gone seriously wrong!");
engine->ReportError(ZERR_DEPRECIATED,"This is a test of a depreciated feature."); engine->ReportError(ZERR_DEPRECIATED,"This is a test of a depreciated feature.");
engine->ReportError(ZERR_ERROR,"This is a normal error, but only a test."); engine->ReportError(ZERR_ERROR,"This is a normal error, but only a test.");
@ -88,7 +88,7 @@ void Test()
} }
//movement// //movement//
movDelta = static_cast<float>(engine->GetFrameTime()*30); movDelta = static_cast<float>(engine->GetFrameSpeed()*30);
if(engine->KeyIsPressed(SDLK_LEFT)) if(engine->KeyIsPressed(SDLK_LEFT))
clipRect.MoveRel(-movDelta,0); clipRect.MoveRel(-movDelta,0);
if(engine->KeyIsPressed(SDLK_RIGHT)) if(engine->KeyIsPressed(SDLK_RIGHT))
@ -113,9 +113,9 @@ void Test()
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
engine->Clear(); //clear screen engine->ClearDisplay(); //clear screen
//draw the images// //draw the images//
alpha += static_cast<float>(alphaDelta*engine->GetFrameTime()); alpha += static_cast<float>(alphaDelta*engine->GetFrameSpeed());
if(alpha >= 255 || alpha <= 0) if(alpha >= 255 || alpha <= 0)
alphaDelta *= -1.0f; alphaDelta *= -1.0f;
image1.SetAlpha(static_cast<Uint8>(alpha)); image1.SetAlpha(static_cast<Uint8>(alpha));
@ -123,7 +123,7 @@ void Test()
#if (GFX_BACKEND == ZE_OGL) #if (GFX_BACKEND == ZE_OGL)
image2.DrawRotated(100,0,angle); image2.DrawRotated(100,0,angle);
angle += static_cast<float>(150*engine->GetFrameTime()); angle += static_cast<float>(150*engine->GetFrameSpeed());
if(angle > 360) if(angle > 360)
angle = 0.0f; angle = 0.0f;
#elif (GFX_BACKEND == ZE_SDL) #elif (GFX_BACKEND == ZE_SDL)

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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: ZMouseTest.cpp,v 1.22 2003/12/31 12:27:58 cozman Exp $ // $Id: ZMouseTest.cpp,v 1.23 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -31,7 +31,7 @@ bool Initialize()
title = cfg.GetString("ZMouseTest","title","ZMouse Test"); title = cfg.GetString("ZMouseTest","title","ZMouse Test");
engine->SetResourceFile("resources.zrf"); engine->SetResourceFile("resources.zrf");
engine->InitErrorLog();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -78,7 +78,7 @@ void Test()
font.DrawText(FormatStr("Mouse at %d,%d",engine->MouseX(),engine->MouseY()),text[2]); font.DrawText(FormatStr("Mouse at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
engine->Clear(); //clear screen engine->ClearDisplay(); //clear screen
//draw the images// //draw the images//
text[engine->MouseInRect(textRect)].Draw(100,100); text[engine->MouseInRect(textRect)].Draw(100,100);
text[2].Draw(0,0); text[2].Draw(0,0);

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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: ZMusicTest.cpp,v 1.22 2003/12/31 12:27:58 cozman Exp $ // $Id: ZMusicTest.cpp,v 1.23 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -30,6 +30,7 @@ bool Initialize()
fs = cfg.GetBool("ZMusicTest","fullscreen",false); fs = cfg.GetBool("ZMusicTest","fullscreen",false);
title = cfg.GetString("ZMusicTest","title","ZMusic Test"); title = cfg.GetString("ZMusicTest","title","ZMusic Test");
engine->InitAudio();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -37,15 +38,15 @@ void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZMusic song("data/music.ogg"); ZMusic song("data/sample.ogg");
ZFont font("data/almontew.ttf",48); ZFont font("data/almontew.ttf",48);
ZImage text[4]; ZImage text[4];
if(!song.IsLoaded()) //this executes if there is no music.ogg file if(!song.IsLoaded()) //this executes if there is no music.ogg file
{ {
engine->CreateDisplay(800,70,32,false,"ZMusic Test"); engine->CreateDisplay(800,70,32,false,"ZMusic Test");
engine->Clear(); engine->ClearDisplay();
font.DrawText("Music.ogg does not exist, please read music.txt.",text[0]); font.DrawText("sample.ogg does not exist, please read music.txt.",text[0]);
text[0].Draw(0,0); text[0].Draw(0,0);
engine->Update(); engine->Update();
do do
@ -76,21 +77,24 @@ void Test()
song.Pause(); song.Pause();
if(engine->KeyIsPressed(SDLK_u)) if(engine->KeyIsPressed(SDLK_u))
song.Unpause(); song.Unpause();
#if SND_BACKEND == ZE_MIXER
if(engine->KeyIsPressed(SDLK_f)) if(engine->KeyIsPressed(SDLK_f))
song.Stop(5000); song.Stop(200);
#endif
if(engine->KeyIsPressed(SDLK_h)) if(engine->KeyIsPressed(SDLK_h))
song.Stop(); song.Stop();
if(engine->KeyIsPressed(SDLK_SPACE)) if(engine->KeyIsPressed(SDLK_SPACE))
song.Play(); song.Play();
if(engine->KeyIsPressed(SDLK_UP)) if(engine->KeyIsPressed(SDLK_UP))
song.SetVolume(song.GetVolume()+1); song.SetVolume(song.GetVolume()+1);
if(engine->KeyIsPressed(SDLK_DOWN)) if(engine->KeyIsPressed(SDLK_DOWN) && song.GetVolume() > 0)
song.SetVolume(song.GetVolume()-1); song.SetVolume(song.GetVolume()-1);
if(engine->KeyIsPressed(SDLK_v))
song.SetVolume(100);
font.DrawText(FormatStr("Volume: %d%%",song.GetVolume()),text[3]);
engine->ClearDisplay(); //clear screen
font.DrawText(FormatStr("Volume: %d",song.GetVolume()),text[3]);
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*50);
engine->Update(); //update the screen engine->Update(); //update the screen

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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: ZParticleTest.cpp,v 1.10 2003/12/31 12:27:58 cozman Exp $ // $Id: ZParticleTest.cpp,v 1.11 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -31,7 +31,7 @@ bool Initialize()
title = cfg.GetString("ZParticleTest","title","ZParticle Test"); title = cfg.GetString("ZParticleTest","title","ZParticle Test");
engine->SetResourceFile("resources.zrf"); engine->SetResourceFile("resources.zrf");
engine->InitErrorLog();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -127,9 +127,9 @@ void Test()
engine->RequestQuit(); engine->RequestQuit();
for(i=0; i < 3; ++i) for(i=0; i < 3; ++i)
effect[i].Update(); effect[i].Update();
engine->Clear(); engine->ClearDisplay();
bg.Draw(0,0); bg.Draw(0,0);
for(i=0; i < 3; ++i) for(i=0; i < 3; ++i)

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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: ZRectTest.cpp,v 1.23 2003/12/31 12:27:58 cozman Exp $ // $Id: ZRectTest.cpp,v 1.24 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -29,7 +29,7 @@ bool Initialize()
bpp = cfg.GetInt("ZRectTest","bpp",32); bpp = cfg.GetInt("ZRectTest","bpp",32);
fs = cfg.GetBool("ZRectTest","fullscreen",false); fs = cfg.GetBool("ZRectTest","fullscreen",false);
title = cfg.GetString("ZRectTest","title","ZRect Test"); title = cfg.GetString("ZRectTest","title","ZRect Test");
engine->InitErrorLog();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -49,7 +49,7 @@ void Test()
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
//movement// //movement//
movDelta = static_cast<float>(engine->GetFrameTime()*30); movDelta = static_cast<float>(engine->GetFrameSpeed()*30);
if(engine->KeyIsPressed(SDLK_LEFT)) if(engine->KeyIsPressed(SDLK_LEFT))
moveRect.MoveRel(-movDelta,0); moveRect.MoveRel(-movDelta,0);
if(engine->KeyIsPressed(SDLK_RIGHT)) if(engine->KeyIsPressed(SDLK_RIGHT))
@ -69,7 +69,7 @@ void Test()
moveRect.ResizeRel(-2,-2); moveRect.ResizeRel(-2,-2);
} }
engine->Clear(); engine->ClearDisplay();
moveRect.Draw(255,0,0,128); moveRect.Draw(255,0,0,128);
stillRect.Draw(0,0,255,128); stillRect.Draw(0,0,255,128);
moveRect.Intersection(stillRect).Draw(0,255,0); moveRect.Intersection(stillRect).Draw(0,255,0);

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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: ZSoundTest.cpp,v 1.22 2003/12/31 12:27:58 cozman Exp $ // $Id: ZSoundTest.cpp,v 1.23 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -31,7 +31,8 @@ bool Initialize()
title = cfg.GetString("ZSoundTest","title","ZSound Test"); title = cfg.GetString("ZSoundTest","title","ZSound Test");
engine->SetResourceFile("resources.zrf"); engine->SetResourceFile("resources.zrf");
engine->InitErrorLog();
engine->InitAudio();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -49,7 +50,6 @@ void Test()
sample[i].OpenFromZip("data/data.zip",FormatStr("%s.wav",name[i].c_str())); sample[i].OpenFromZip("data/data.zip",FormatStr("%s.wav",name[i].c_str()));
sample[4].OpenFromZRF("whip"); sample[4].OpenFromZRF("whip");
font.DrawText("(P)ause\t(U)npause",text[0]); font.DrawText("(P)ause\t(U)npause",text[0]);
font.DrawText("(F)ade Out\t(H)alt\t",text[1]); font.DrawText("(F)ade Out\t(H)alt\t",text[1]);
font.DrawText("Space - Play\t Up/Down - Control Volume",text[2]); font.DrawText("Space - Play\t Up/Down - Control Volume",text[2]);
@ -77,21 +77,23 @@ void Test()
sample[sampleNum].Pause(); sample[sampleNum].Pause();
if(engine->KeyIsPressed(SDLK_u)) if(engine->KeyIsPressed(SDLK_u))
sample[sampleNum].Unpause(); sample[sampleNum].Unpause();
#if SND_BACKEND == ZE_MIXER
if(engine->KeyIsPressed(SDLK_f)) if(engine->KeyIsPressed(SDLK_f))
sample[sampleNum].Stop(5000); sample[sampleNum].Stop(200);
#endif
if(engine->KeyIsPressed(SDLK_h)) if(engine->KeyIsPressed(SDLK_h))
sample[sampleNum].Stop(); sample[sampleNum].Stop();
if(engine->KeyIsPressed(SDLK_SPACE)) if(engine->KeyIsPressed(SDLK_SPACE))
sample[sampleNum].Play(); sample[sampleNum].Play();
if(engine->KeyIsPressed(SDLK_UP)) if(engine->KeyIsPressed(SDLK_UP) && sample[sampleNum].GetVolume() < 100)
sample[sampleNum].SetVolume(sample[sampleNum].GetVolume()+1); sample[sampleNum].SetVolume(sample[sampleNum].GetVolume()+1);
if(engine->KeyIsPressed(SDLK_DOWN)) if(engine->KeyIsPressed(SDLK_DOWN) && sample[sampleNum].GetVolume() > 0)
sample[sampleNum].SetVolume(sample[sampleNum].GetVolume()-1); sample[sampleNum].SetVolume(sample[sampleNum].GetVolume()-1);
font.DrawText(FormatStr("Volume: %d",sample[sampleNum].GetVolume()),text[4]); font.DrawText(FormatStr("Volume: %d%%",sample[sampleNum].GetVolume()),text[4]);
font.DrawText(FormatStr("Sample: %s",name[sampleNum].c_str()),text[5]); font.DrawText(FormatStr("Sample: %s",name[sampleNum].c_str()),text[5]);
engine->Clear(); //clear screen engine->ClearDisplay(); //clear screen
for(int i=0; i < 6; i++) for(int i=0; i < 6; i++)
text[i].Draw(0,i*50); text[i].Draw(0,i*50);
engine->Update(); //update the screen engine->Update(); //update the screen

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
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.21 2003/12/31 12:27:58 cozman Exp $ // $Id: ZTimerTest.cpp,v 1.22 2004/01/13 23:56:28 cozman Exp $
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -31,7 +31,7 @@ bool Initialize()
title = cfg.GetString("ZTimerTest","title","ZTimer Test"); title = cfg.GetString("ZTimerTest","title","ZTimer Test");
engine->SetResourceFile("resources.zrf"); engine->SetResourceFile("resources.zrf");
engine->InitErrorLog();
return engine->CreateDisplay(w,h,bpp,fs,title); return engine->CreateDisplay(w,h,bpp,fs,title);
} }
@ -105,7 +105,7 @@ void Test()
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->ClearDisplay(); //clear screen
for(int i=0; i <= 4; i++) for(int i=0; i <= 4; i++)
text[i].Draw(0,i*30); text[i].Draw(0,i*30);

View File

@ -1,4 +0,0 @@
Where have the VC6 project files gone?
Visual C++ 6 is now an outdated program, and I apologize but I can no longer support it. It's STL support as well as it's support of newer features of C++ made compiling ZEngine properly in it an extremely difficult thing for me to officially support. As of 0.8.4 some people could get it to compile, but as far as I know they had to use things like STLPort (http://www.stlport.org) due to the problems in the STL shipped with VC6. If you have the money I'd recommend upgrading to Visual C++ 7 (aka .net) Standard which should cost you less than 100$. If you're short on cash Bloodshed makes their GCC based windows IDE available for free at http://bloodshed.net/dev/devcpp.html. I apologize for the inconvenience but keeping VC6 support is getting increasingly hard as all my VC6 contacts have switched and I have been notified several times that the VC6 project files are becoming more and more broken with every release. Of course if anybody would like to work on a VC6 port of ZEngine I'd be glad to help as much as I can, just contact me (james@conceptofzero.net).

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZAnimTest.exe" OutputFile="../test/bin/ZAnimTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"

View File

@ -64,6 +64,9 @@
<File <File
RelativePath="..\src\ZE_ZAnimation.cpp"> RelativePath="..\src\ZE_ZAnimation.cpp">
</File> </File>
<File
RelativePath="..\src\ZE_ZAudioBase.cpp">
</File>
<File <File
RelativePath="..\src\ZE_ZConfigFile.cpp"> RelativePath="..\src\ZE_ZConfigFile.cpp">
</File> </File>
@ -110,6 +113,9 @@
<File <File
RelativePath="..\include\ZE_ZAnimation.h"> RelativePath="..\include\ZE_ZAnimation.h">
</File> </File>
<File
RelativePath="..\include\ZE_ZAudioBase.h">
</File>
<File <File
RelativePath="..\include\ZE_ZBaseParticleSystem.h"> RelativePath="..\include\ZE_ZBaseParticleSystem.h">
</File> </File>
@ -146,6 +152,9 @@
<File <File
RelativePath="..\include\ZEngine.h"> RelativePath="..\include\ZEngine.h">
</File> </File>
<File
RelativePath="..\..\ZE-deps\include\audiere.h">
</File>
</Filter> </Filter>
<Filter <Filter
Name="Zlib"> Name="Zlib">

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZFontTest.exe" OutputFile="../test/bin/ZFontTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZImageTest.exe" OutputFile="../test/bin/ZImageTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZMouseTest.exe" OutputFile="../test/bin/ZMouseTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZMusicTest.exe" OutputFile="../test/bin/ZMusicTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZParticleTest.exe" OutputFile="../test/bin/ZParticleTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZRectTest.exe" OutputFile="../test/bin/ZRectTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZSoundTest.exe" OutputFile="../test/bin/ZSoundTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"

View File

@ -38,9 +38,10 @@
sdlmain.lib sdlmain.lib
opengl32.lib opengl32.lib
sdl_ttf.lib sdl_ttf.lib
sdl_mixer.lib
sdl_image.lib sdl_image.lib
ZEngineS.lib" ZEngineS.lib
SDL_mixer.lib
audiere.lib"
OutputFile="../test/bin/ZTimerTest.exe" OutputFile="../test/bin/ZTimerTest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../lib" AdditionalLibraryDirectories="../lib"