Code Restructuring to make mega-glest more standard

This commit is contained in:
Mark Vejvoda
2010-03-12 05:20:53 +00:00
parent 7cb4f99ec4
commit 43c3f2457e
399 changed files with 0 additions and 73357 deletions

View File

@@ -1,31 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_SOUND_SOUNDFACTORYDS8_H_
#define _SHARED_SOUND_SOUNDFACTORYDS8_H_
#include "sound_factory.h"
#include "sound_player_ds8.h"
namespace Shared{ namespace Sound{ namespace Ds8{
// =====================================================
// class SoundFactoryDs8
// =====================================================
class SoundFactoryDs8: public SoundFactory{
public:
virtual SoundPlayer *newSoundPlayer() {return new SoundPlayerDs8();}
};
}}}//end namespace
#endif

View File

@@ -1,135 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_SOUND_SOUNDPLAYERDS8_H_
#define _SHARED_SOUND_SOUNDPLAYERDS8_H_
#include "sound_player.h"
#include "platform_util.h"
#include <dsound.h>
#include <vector>
using std::vector;
namespace Shared{ namespace Sound{ namespace Ds8{
// =====================================================
// class SoundBuffer
// =====================================================
class SoundBuffer{
protected:
IDirectSoundBuffer8 *dsBuffer;
Sound *sound;
DWORD size;
public:
SoundBuffer();
virtual ~SoundBuffer(){};
virtual void end()=0;
IDirectSoundBuffer8 *getDsBuffer() const {return dsBuffer;}
Sound *getSound() const {return sound;}
void setDsBuffer(IDirectSoundBuffer8 *dsBuffer) {this->dsBuffer= dsBuffer;}
void setSound(IDirectSound8 *dsObject, Sound *sound) {this->sound= sound;}
bool isFree();
bool isReady();
protected:
void createDsBuffer(IDirectSound8 *dsObject);
};
// =====================================================
// class StaticSoundBuffer
// =====================================================
class StaticSoundBuffer: public SoundBuffer{
public:
StaticSound *getStaticSound() const {return static_cast<StaticSound*>(sound);}
void init(IDirectSound8 *dsObject, Sound *sound);
void end();
void play();
private:
void fillDsBuffer();
};
// =====================================================
// class StrSoundBuffer
// =====================================================
class StrSoundBuffer: public SoundBuffer{
private:
enum State{sFree, sFadingOn, sPlaying, sFadingOff, sStopped};
private:
DWORD lastPlayCursor;
State state;
Chrono chrono; //delay-fade chrono
int64 fade; //fade on fade off delay
public:
StrSoundBuffer();
StrSound *getStrSound() const {return static_cast<StrSound*>(sound);}
void init(IDirectSound8 *dsObject, Sound *sound, uint32 strBufferSize);
void end();
void play(int64 fadeOn);
void update();
void stop(int64 fadeOff);
private:
void fillDsBuffer();
void refreshDsBuffer();
void readChunk(void *writePointer, uint32 size);
};
// =====================================================
// class SoundPlayerDs8
//
/// SoundPlayer implementation using Direct Sound 8
// =====================================================
class SoundPlayerDs8: public SoundPlayer{
private:
IDirectSound8 *dsObject;
vector<StaticSoundBuffer> staticSoundBuffers;
vector<StrSoundBuffer> strSoundBuffers;
SoundPlayerParams params;
public:
SoundPlayerDs8();
virtual void init(const SoundPlayerParams *params);
virtual void end();
virtual void play(StaticSound *staticSound);
virtual void play(StrSound *strSound, int64 fadeOn=0);
virtual void stop(StrSound *strSound, int64 fadeOff=0);
virtual void stopAllSounds();
virtual void updateStreams(); //updates str buffers if needed
private:
bool findStaticBuffer(Sound *sound, int *bufferIndex);
bool findStrBuffer(Sound *sound, int *bufferIndex);
};
// =====================================================
// Misc
// =====================================================
long dsVolume(float floatVolume);
}}}//end namespace
#endif

View File

@@ -1,28 +0,0 @@
//This file is part of Glest Shared Library (www.glest.org)
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//You can redistribute this code and/or modify it under
//the terms of the GNU General Public License as published by the Free Software
//Foundation; either version 2 of the License, or (at your option) any later
//version.
#ifndef _SHARED_SOUND_SOUNDFACTORYSDL_H_
#define _SHARED_SOUND_SOUNDFACTORYSDL_H_
#include "sound_factory.h"
#include "sound_player_openal.h"
namespace Shared{ namespace Sound{ namespace OpenAL{
// ===============================
// class SoundFactoryOpenAL
// ===============================
class SoundFactoryOpenAL : public SoundFactory{
public:
virtual SoundPlayer* newSoundPlayer() {return new SoundPlayerOpenAL();}
};
}}}//end namespace
#endif

View File

@@ -1,125 +0,0 @@
//This file is part of Glest Shared Library (www.glest.org)
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
//You can redistribute this code and/or modify it under
//the terms of the GNU General Public License as published by the Free Software
//Foundation; either version 2 of the License, or (at your option) any later
//version.
#ifndef _SHARED_SOUND_SOUNDPLAYEROPENAL_H_
#define _SHARED_SOUND_SOUNDPLAYEROPENAL_H_
#include "sound_player.h"
#include "platform_util.h"
#include <SDL.h>
#include <AL/alc.h>
#include <AL/al.h>
#include <vector>
using std::vector;
namespace Shared{ namespace Sound{ namespace OpenAL{
class SoundSource {
public:
SoundSource();
virtual ~SoundSource();
bool playing();
void stop();
protected:
friend class SoundPlayerOpenAL;
ALenum getFormat(Sound* sound);
ALuint source;
};
class StaticSoundSource : public SoundSource {
public:
StaticSoundSource();
virtual ~StaticSoundSource();
void play(StaticSound* sound);
protected:
friend class SoundPlayerOpenAL;
bool bufferAllocated;
ALuint buffer;
};
class StreamSoundSource : public SoundSource {
public:
StreamSoundSource();
virtual ~StreamSoundSource();
void play(StrSound* sound, int64 fade);
void update();
void stop();
void stop(int64 fade);
protected:
friend class SoundPlayerOpenAL;
static const size_t STREAMBUFFERSIZE = 1024 * 500;
static const size_t STREAMFRAGMENTS = 5;
static const size_t STREAMFRAGMENTSIZE
= STREAMBUFFERSIZE / STREAMFRAGMENTS;
bool fillBufferAndQueue(ALuint buffer);
StrSound* sound;
ALuint buffers[STREAMFRAGMENTS];
ALenum format;
enum FadeState { NoFading, FadingOn, FadingOff };
FadeState fadeState;
Chrono chrono; // delay-fade chrono
int64 fade;
};
// ==============================================================
// class SoundPlayerSDL
//
/// SoundPlayer implementation using SDL_mixer
// ==============================================================
class SoundPlayerOpenAL : public SoundPlayer {
public:
SoundPlayerOpenAL();
virtual ~SoundPlayerOpenAL();
virtual void init(const SoundPlayerParams *params);
virtual void end();
virtual void play(StaticSound *staticSound);
virtual void play(StrSound *strSound, int64 fadeOn=0);
virtual void stop(StrSound *strSound, int64 fadeOff=0);
virtual void stopAllSounds();
virtual void updateStreams(); //updates str buffers if needed
private:
friend class SoundSource;
friend class StaticSoundSource;
friend class StreamSoundSource;
void printOpenALInfo();
StaticSoundSource* findStaticSoundSource();
StreamSoundSource* findStreamSoundSource();
void checkAlcError(const char* message);
static void checkAlError(const char* message);
ALCdevice* device;
ALCcontext* context;
typedef std::vector<StaticSoundSource*> StaticSoundSources;
StaticSoundSources staticSources;
typedef std::vector<StreamSoundSource*> StreamSoundSources;
StreamSoundSources streamSources;
SoundPlayerParams params;
};
}}}//end namespace
#endif

View File

@@ -1,109 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_SOUND_SOUND_H_
#define _SHARED_SOUND_SOUND_H_
#include <string>
#include "sound_file_loader.h"
using namespace std;
using namespace Shared::Platform;
namespace Shared{ namespace Sound{
// =====================================================
// class SoundInfo
// =====================================================
class SoundInfo{
private:
uint32 channels;
uint32 samplesPerSecond;
uint32 bitsPerSample;
uint32 size;
public:
SoundInfo();
virtual ~SoundInfo(){};
uint32 getChannels() const {return channels;}
uint32 getSamplesPerSecond() const {return samplesPerSecond;}
uint32 getBitsPerSample() const {return bitsPerSample;}
uint32 getSize() const {return size;}
void setChannels(uint32 channels) {this->channels= channels;}
void setsamplesPerSecond(uint32 samplesPerSecond) {this->samplesPerSecond= samplesPerSecond;}
void setBitsPerSample(uint32 bitsPerSample) {this->bitsPerSample= bitsPerSample;}
void setSize(uint32 size) {this->size= size;}
};
// =====================================================
// class Sound
// =====================================================
class Sound{
protected:
SoundFileLoader *soundFileLoader;
SoundInfo info;
float volume;
public:
Sound();
virtual ~Sound(){};
const SoundInfo *getInfo() const {return &info;}
float getVolume() const {return volume;}
void setVolume(float volume) {this->volume= volume;}
};
// =====================================================
// class StaticSound
// =====================================================
class StaticSound: public Sound{
private:
int8 * samples;
public:
StaticSound();
virtual ~StaticSound();
int8 *getSamples() const {return samples;}
void load(const string &path);
};
// =====================================================
// class StrSound
// =====================================================
class StrSound: public Sound{
private:
StrSound *next;
public:
StrSound();
virtual ~StrSound();
StrSound *getNext() const {return next;}
void setNext(StrSound *next) {this->next= next;}
void open(const string &path);
uint32 read(int8 *samples, uint32 size);
void close();
void restart();
};
}}//end namespace
#endif

View File

@@ -1,31 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_SOUND_SOUNDFACTORY_H_
#define _SHARED_SOUND_SOUNDFACTORY_H_
#include "sound_player.h"
namespace Shared{ namespace Sound{
// =====================================================
// class SoundFactory
// =====================================================
class SoundFactory{
public:
virtual ~SoundFactory(){}
virtual SoundPlayer *newSoundPlayer() {return NULL;}
};
}}//end namespace
#endif

View File

@@ -1,104 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_SOUND_SOUNDFILELOADER_H_
#define _SHARED_SOUND_SOUNDFILELOADER_H_
#include <string>
#include <fstream>
#include "types.h"
#include "factory.h"
struct OggVorbis_File;
using std::string;
using std::ifstream;
namespace Shared{ namespace Sound{
using Platform::uint32;
using Platform::int8;
using Util::MultiFactory;
class SoundInfo;
// =====================================================
// class SoundFileLoader
//
/// Interface that all SoundFileLoaders will implement
// =====================================================
class SoundFileLoader{
public:
virtual ~SoundFileLoader(){}
virtual void open(const string &path, SoundInfo *soundInfo)= 0;
virtual uint32 read(int8 *samples, uint32 size)= 0;
virtual void close()= 0;
virtual void restart()= 0;
};
// =====================================================
// class WavSoundFileLoader
//
/// Wave file loader
// =====================================================
class WavSoundFileLoader: public SoundFileLoader{
private:
static const int maxDataRetryCount= 10;
private:
uint32 dataOffset;
uint32 dataSize;
uint32 bytesPerSecond;
ifstream f;
public:
virtual void open(const string &path, SoundInfo *soundInfo);
virtual uint32 read(int8 *samples, uint32 size);
virtual void close();
virtual void restart();
};
// =====================================================
// class OggSoundFileLoader
//
/// OGG sound file loader, uses ogg-vorbis library
// =====================================================
class OggSoundFileLoader: public SoundFileLoader{
private:
OggVorbis_File *vf;
FILE *f;
public:
virtual void open(const string &path, SoundInfo *soundInfo);
virtual uint32 read(int8 *samples, uint32 size);
virtual void close();
virtual void restart();
};
// =====================================================
// class SoundFileLoaderFactory
// =====================================================
class SoundFileLoaderFactory: public MultiFactory<SoundFileLoader>{
private:
SoundFileLoaderFactory();
public:
static SoundFileLoaderFactory * getInstance();
};
}}//end namespace
#endif

View File

@@ -1,42 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_SOUND_SOUNDINTERFACE_H_
#define _SHARED_SOUND_SOUNDINTERFACE_H_
#include "sound_factory.h"
namespace Shared{ namespace Sound{
// =====================================================
// class SoundInterface
// =====================================================
class SoundInterface{
private:
SoundFactory *soundFactory;
private:
SoundInterface(){}
SoundInterface(SoundInterface &);
void operator=(SoundInterface &);
public:
static SoundInterface &getInstance();
void setFactory(SoundFactory *soundFactory);
SoundPlayer *newSoundPlayer();
};
}}//end namespace
#endif

View File

@@ -1,55 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_SOUND_SOUNDPLAYER_H_
#define _SHARED_SOUND_SOUNDPLAYER_H_
#include "sound.h"
#include "types.h"
using Shared::Platform::uint32;
namespace Shared{ namespace Sound{
// =====================================================
// class SoundPlayerParams
// =====================================================
class SoundPlayerParams{
public:
uint32 strBufferSize;
uint32 strBufferCount;
uint32 staticBufferCount;
SoundPlayerParams();
};
// =====================================================
// class SoundPlayer
//
// Interface that every SoundPlayer will implement
// =====================================================
class SoundPlayer{
public:
virtual ~SoundPlayer(){};
virtual void init(const SoundPlayerParams *params)= 0;
virtual void end()= 0;
virtual void play(StaticSound *staticSound)= 0;
virtual void play(StrSound *strSound, int64 fadeOn=0)= 0; //delay and fade in miliseconds
virtual void stop(StrSound *strSound, int64 fadeOff=0)= 0;
virtual void stopAllSounds()= 0;
virtual void updateStreams()= 0;
};
}}//end namespace
#endif