- moved sound system debug into a new debugSound property to lessen the impact of regular debug logging since sound processing is now threaded and therefore logging sound system items may slow down performance

- added texture caching for faction preview textures
This commit is contained in:
Mark Vejvoda 2011-01-26 09:09:59 +00:00
parent 16836c758e
commit d10054f1c3
19 changed files with 141 additions and 175 deletions

View File

@ -44,27 +44,6 @@ Logger::Logger() {
}
Logger::~Logger() {
cleanupLoadingTexture();
}
void Logger::cleanupLoadingTexture() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(loadingTexture!=NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//Renderer &renderer= Renderer::getInstance();
//renderer.endTexture(rsGlobal,loadingTexture);
loadingTexture->end();
delete loadingTexture;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//delete loadingTexture;
loadingTexture=NULL;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
Logger & Logger::getInstance() {
@ -102,8 +81,6 @@ void Logger::loadLoadingScreen(string filepath) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
cleanupLoadingTexture();
if(filepath=="")
{
loadingTexture=NULL;
@ -111,18 +88,7 @@ void Logger::loadLoadingScreen(string filepath) {
else
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] filepath = [%s]\n",__FILE__,__FUNCTION__,__LINE__,filepath.c_str());
loadingTexture=GraphicsInterface::getInstance().getFactory()->newTexture2D();
//loadingTexture = renderer.newTexture2D(rsGlobal);
loadingTexture->setMipmap(true);
//loadingTexture->getPixmap()->load(filepath);
loadingTexture->load(filepath);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance();
renderer.initTexture(rsGlobal,loadingTexture);
loadingTexture = Renderer::findFactionLogoTexture(filepath);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
}
@ -137,7 +103,7 @@ void Logger::renderLoadingScreen() {
renderer.reset2d();
renderer.clearBuffers();
if(loadingTexture==NULL){
if(loadingTexture == NULL) {
renderer.renderBackground(CoreData::getInstance().getBackgroundTexture());
}
else{

View File

@ -50,8 +50,6 @@ private:
Logger();
~Logger();
void cleanupLoadingTexture();
public:
static Logger & getInstance();

View File

@ -176,6 +176,18 @@ int Game::ErrorDisplayMessage(const char *msg, bool exitApp) {
return 0;
}
Texture2D * Game::findFactionLogoTexture(const GameSettings *settings, Logger *logger,string factionLogoFilter, bool useTechDefaultIfFilterNotFound) {
Texture2D *result = NULL;
string logoFilename = Game::findFactionLogoFile(settings, logger,factionLogoFilter);
if(logoFilename == "" && factionLogoFilter != "" && useTechDefaultIfFilterNotFound == true) {
logoFilename = Game::findFactionLogoFile(settings, logger);
}
result = Renderer::findFactionLogoTexture(logoFilename);
return result;
}
string Game::findFactionLogoFile(const GameSettings *settings, Logger *logger,string factionLogoFilter) {
string result = "";
if(settings == NULL) {

View File

@ -167,6 +167,7 @@ public:
void endPerformanceTimer();
Vec2i getPerformanceTimerResults();
static Texture2D * findFactionLogoTexture(const GameSettings *settings, Logger *logger,string factionLogoFilter="loading_screen.*", bool useTechDefaultIfFilterNotFound=true);
static string findFactionLogoFile(const GameSettings *settings, Logger *logger, string factionLogoFilter="loading_screen.*");
bool getGameOver() { return gameOver; }

View File

@ -114,6 +114,7 @@ public:
static const char *RANDOMFACTION_SLOTNAME;
static const char *playerTextureCacheLookupKey;
static const char *factionPreviewTextureCacheLookupKey;
static const char *pathCacheLookupKey;
static const char *path_data_CacheLookupKey;
static const char *path_ini_CacheLookupKey;

View File

@ -50,7 +50,8 @@ const char *GameConstants::folder_path_screenshots = "screens/";
const char *GameConstants::OBSERVER_SLOTNAME = "*Observer*";
const char *GameConstants::RANDOMFACTION_SLOTNAME = "*Random*";
const char *GameConstants::playerTextureCacheLookupKey = "playerTextureCache";
const char *GameConstants::playerTextureCacheLookupKey = "playerTextureCache";
const char *GameConstants::factionPreviewTextureCacheLookupKey = "factionPreviewTextureCache";
const char *GameConstants::application_name = "MegaGlest";
const char *GameConstants::pathCacheLookupKey = "pathCache_";

View File

@ -416,6 +416,9 @@ void Renderer::reset3dMenu() {
// ==================== end ====================
void Renderer::end() {
std::map<string,Texture2D *> &crcFactionPreviewTextureCache = CacheManager::getCachedItem< std::map<string,Texture2D *> >(GameConstants::factionPreviewTextureCacheLookupKey);
crcFactionPreviewTextureCache.clear();
//delete resources
modelManager[rsGlobal]->end();
textureManager[rsGlobal]->end();
@ -4798,4 +4801,32 @@ uint64 Renderer::getCurrentPixelByteCount(ResourceScope rs) const {
return result;
}
Texture2D * Renderer::findFactionLogoTexture(string logoFilename) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] logoFilename [%s]\n",__FILE__,__FUNCTION__,__LINE__,logoFilename.c_str());
Texture2D *result = NULL;
if(logoFilename != "") {
// Cache faction preview textures
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
std::map<string,Texture2D *> &crcFactionPreviewTextureCache = CacheManager::getCachedItem< std::map<string,Texture2D *> >(GameConstants::factionPreviewTextureCacheLookupKey);
if(crcFactionPreviewTextureCache.find(logoFilename) != crcFactionPreviewTextureCache.end()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] logoFilename [%s]\n",__FILE__,__FUNCTION__,__LINE__,logoFilename.c_str());
result = crcFactionPreviewTextureCache[logoFilename];
}
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] logoFilename [%s]\n",__FILE__,__FUNCTION__,__LINE__,logoFilename.c_str());
Renderer &renderer= Renderer::getInstance();
result = renderer.newTexture2D(rsGlobal);
result->setMipmap(true);
result->load(logoFilename);
renderer.initTexture(rsGlobal,result);
crcFactionPreviewTextureCache[logoFilename] = result;
}
}
return result;
}
}}//end namespace

View File

@ -422,6 +422,8 @@ public:
void renderProgressBar(int size, int x, int y, Font2D *font,int customWidth=-1, string prefixLabel="");
static Texture2D * findFactionLogoTexture(string logoFilename);
private:
//private misc
float computeSunAngle(float time);

View File

@ -917,6 +917,7 @@ void setupLogging(Config &config, bool haveSpecialOutputCommandLineOption) {
SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled = config.getBool("DebugUnitCommands","false");
SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled = config.getBool("DebugPathFinder","false");
SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled = config.getBool("DebugLUA","false");
SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled = config.getBool("DebugSound","false");
SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled = config.getBool("DebugError","true");
string debugLogFile = config.getString("DebugLogFile","");
@ -971,6 +972,14 @@ void setupLogging(Config &config, bool haveSpecialOutputCommandLineOption) {
debugLUALogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugLUALogFile;
}
string debugSoundLogFile = config.getString("DebugLogFileSound","");
if(debugSoundLogFile == "") {
debugSoundLogFile = debugLogFile;
}
else {
debugSoundLogFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + debugSoundLogFile;
}
string debugErrorLogFile = config.getString("DebugLogFileError","");
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).debugLogFileName = debugLogFile;
@ -980,10 +989,11 @@ void setupLogging(Config &config, bool haveSpecialOutputCommandLineOption) {
SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).debugLogFileName = debugUnitCommandsLogFile;
SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).debugLogFileName = debugPathFinderLogFile;
SystemFlags::getSystemSettingType(SystemFlags::debugLUA).debugLogFileName = debugLUALogFile;
SystemFlags::getSystemSettingType(SystemFlags::debugSound).debugLogFileName = debugSoundLogFile;
SystemFlags::getSystemSettingType(SystemFlags::debugError).debugLogFileName = debugErrorLogFile;
if(haveSpecialOutputCommandLineOption == false) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Startup settings are: debugSystem [%d], debugNetwork [%d], debugPerformance [%d], debugWorldSynch [%d], debugUnitCommands[%d], debugPathFinder[%d], debugLUA [%d], debugError [%d]\n",
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Startup settings are: debugSystem [%d], debugNetwork [%d], debugPerformance [%d], debugWorldSynch [%d], debugUnitCommands[%d], debugPathFinder[%d], debugLUA [%d], debugSound [%d], debugError [%d]\n",
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled,
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled,
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled,
@ -991,6 +1001,7 @@ void setupLogging(Config &config, bool haveSpecialOutputCommandLineOption) {
SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled,
SystemFlags::getSystemSettingType(SystemFlags::debugPathFinder).enabled,
SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled,
SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled,
SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled);
}
}

View File

@ -420,8 +420,6 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM
}
MenuStateConnectedGame::~MenuStateConnectedGame() {
cleanupFactionTexture();
if(ftpClientThread != NULL) {
ftpClientThread->setCallBackObject(NULL);
if(ftpClientThread->shutdownAndWait() == true) {
@ -1662,49 +1660,18 @@ void MenuStateConnectedGame::loadFactionTexture(string filepath) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
cleanupFactionTexture();
if(enableFactionTexturePreview == true) {
if(filepath == "") {
factionTexture=NULL;
}
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] filepath = [%s]\n",__FILE__,__FUNCTION__,__LINE__,filepath.c_str());
factionTexture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
//loadingTexture = renderer.newTexture2D(rsGlobal);
factionTexture->setMipmap(true);
//loadingTexture->getPixmap()->load(filepath);
factionTexture->load(filepath);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance();
renderer.initTexture(rsGlobal,factionTexture);
factionTexture = Renderer::findFactionLogoTexture(filepath);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
}
}
void MenuStateConnectedGame::cleanupFactionTexture() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(factionTexture!=NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
factionTexture->end();
delete factionTexture;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//delete loadingTexture;
factionTexture=NULL;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
bool MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo, bool loadMapPreview) {
struct MapFileHeader{

View File

@ -180,7 +180,6 @@ private:
string getHumanPlayerName();
void setActiveInputLabel(GraphicLabel *newLable);
void cleanupFactionTexture();
void loadFactionTexture(string filepath);
bool loadMapInfo(string file, MapInfo *mapInfo, bool loadMapPreview);
void showMessageBox(const string &text, const string &header, bool toggle);

View File

@ -547,7 +547,6 @@ void MenuStateCustomGame::cleanup() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
cleanupFactionTexture();
cleanupMapPreviewTexture();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -2854,49 +2853,18 @@ void MenuStateCustomGame::loadFactionTexture(string filepath) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
cleanupFactionTexture();
if(enableFactionTexturePreview == true) {
if(filepath == "") {
factionTexture=NULL;
factionTexture = NULL;
}
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] filepath = [%s]\n",__FILE__,__FUNCTION__,__LINE__,filepath.c_str());
factionTexture = GraphicsInterface::getInstance().getFactory()->newTexture2D();
//loadingTexture = renderer.newTexture2D(rsGlobal);
factionTexture->setMipmap(true);
//loadingTexture->getPixmap()->load(filepath);
factionTexture->load(filepath);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Renderer &renderer= Renderer::getInstance();
renderer.initTexture(rsGlobal,factionTexture);
factionTexture = Renderer::findFactionLogoTexture(filepath);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
}
}
void MenuStateCustomGame::cleanupFactionTexture() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(factionTexture!=NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
factionTexture->end();
delete factionTexture;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//delete loadingTexture;
factionTexture=NULL;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void MenuStateCustomGame::cleanupMapPreviewTexture() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -184,7 +184,6 @@ private:
void setActiveInputLabel(GraphicLabel *newLable);
string getHumanPlayerName(int index=-1);
void cleanupFactionTexture();
void loadFactionTexture(string filepath);
void RestoreLastGameSettings();

View File

@ -843,7 +843,7 @@ void MenuStateMasterserver::rebuildServerLines(const string &serverInfo) {
Tokenize(server,serverEntities,"|");
const int MIN_FIELDS_EXPECTED = 14;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("--------------> server [%s] serverEntities.size() = %d MIN_FIELDS_EXPECTED = %d\n",server.c_str(),serverEntities.size(),MIN_FIELDS_EXPECTED);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("--------------> server [%s] serverEntities.size() = %lu MIN_FIELDS_EXPECTED = %d\n",server.c_str(),serverEntities.size(),MIN_FIELDS_EXPECTED);
if(serverEntities.size() >= MIN_FIELDS_EXPECTED) {
labelTitle.setText(lang.get("AvailableServers"));

View File

@ -68,8 +68,8 @@ public:
protected:
friend class SoundPlayerOpenAL;
static const size_t STREAMBUFFERSIZE = 1024 * 500;
static const size_t STREAMFRAGMENTS = 5;
static const size_t STREAMBUFFERSIZE = 4096 * 500;
static const size_t STREAMFRAGMENTS = 10;
static const size_t STREAMFRAGMENTSIZE
= STREAMBUFFERSIZE / STREAMFRAGMENTS;

View File

@ -44,6 +44,7 @@ public:
debugUnitCommands,
debugPathFinder,
debugLUA,
debugSound,
debugError
};

View File

@ -22,22 +22,22 @@ using namespace Util;
SoundSource::SoundSource()
{
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
alGenSources(1, &source);
SoundPlayerOpenAL::checkAlError("Couldn't create audio source: ");
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
SoundSource::~SoundSource()
{
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
stop();
alDeleteSources(1, &source);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
bool SoundSource::playing()
@ -59,13 +59,13 @@ void SoundSource::unQueueBuffers() {
void SoundSource::stop()
{
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
alSourceStop(source);
SoundPlayerOpenAL::checkAlError("Problem stopping audio source: ");
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
unQueueBuffers();
@ -73,29 +73,36 @@ void SoundSource::stop()
alSourcei(source, AL_BUFFER, AL_NONE);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SoundPlayerOpenAL::checkAlError("Problem stopping audio source: ");
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
ALenum SoundSource::getFormat(Sound* sound)
{
if(sound->getInfo()->getChannels() == 2) {
if(sound->getInfo()->getBitsPerSample() == 16)
if(sound->getInfo()->getBitsPerSample() == 16) {
return AL_FORMAT_STEREO16;
else if(sound->getInfo()->getBitsPerSample() == 8)
}
else if(sound->getInfo()->getBitsPerSample() == 8) {
return AL_FORMAT_STEREO8;
else
}
else {
throw std::runtime_error("[1] Sample format not supported in file: " + sound->getFileName());
} else if(sound->getInfo()->getChannels() == 1) {
if(sound->getInfo()->getBitsPerSample() == 16)
}
}
else if(sound->getInfo()->getChannels() == 1) {
if(sound->getInfo()->getBitsPerSample() == 16) {
return AL_FORMAT_MONO16;
else if(sound->getInfo()->getBitsPerSample() == 8)
}
else if(sound->getInfo()->getBitsPerSample() == 8) {
return AL_FORMAT_MONO8;
else
}
else {
throw std::runtime_error("[2] Sample format not supported in file: " + sound->getFileName());
}
}
throw std::runtime_error("[3] Sample format not supported in file: " + sound->getFileName());
@ -114,8 +121,9 @@ StaticSoundSource::~StaticSoundSource() {
}
}
void StaticSoundSource::play(StaticSound* sound)
{
void StaticSoundSource::play(StaticSound* sound) {
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(bufferAllocated) {
stop();
alDeleteBuffers(1, &buffer);
@ -125,14 +133,18 @@ void StaticSoundSource::play(StaticSound* sound)
alGenBuffers(1, &buffer);
SoundPlayerOpenAL::checkAlError("Couldn't create audio buffer: ");
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d] filename [%s] format = %d, sound->getSamples() = %d, sound->getInfo()->getSize() = %d, sound->getInfo()->getSamplesPerSecond() = %d\n",__FILE__,__FUNCTION__,__LINE__,sound->getFileName().c_str(),format,sound->getSamples(),sound->getInfo()->getSize(),sound->getInfo()->getSamplesPerSecond());
bufferAllocated = true;
alBufferData(buffer, format, sound->getSamples(),
static_cast<ALsizei> (sound->getInfo()->getSize()),
static_cast<ALsizei> (sound->getInfo()->getSamplesPerSecond()));
SoundPlayerOpenAL::checkAlError("Couldn't fill audio buffer: ");
alSourcei(source, AL_BUFFER, buffer);
alSourcef(source, AL_GAIN, sound->getVolume());
alSourcePlay(source);
SoundPlayerOpenAL::checkAlError("Couldn't start audio source: ");
}
@ -192,14 +204,14 @@ void StreamSoundSource::play(StrSound* sound, int64 fadeon)
void StreamSoundSource::update()
{
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(sound == 0) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
return;
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(fadeState == NoFading){
alSourcef(source, AL_GAIN, sound->getVolume());
}
@ -217,18 +229,18 @@ void StreamSoundSource::update()
break;
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
// we might have to restart the source if we had a buffer underrun
if(!playing()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] Restarting audio source because of buffer underrun.\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d] Restarting audio source because of buffer underrun.\n",__FILE__,__FUNCTION__,__LINE__);
std::cerr << "Restarting audio source because of buffer underrun.\n";
alSourcePlay(source);
SoundPlayerOpenAL::checkAlError("Couldn't restart audio source: ");
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
// handle fading
switch(fadeState) {
@ -253,7 +265,7 @@ void StreamSoundSource::update()
break;
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
bool StreamSoundSource::fillBufferAndQueue(ALuint buffer)
@ -289,21 +301,21 @@ bool StreamSoundSource::fillBufferAndQueue(ALuint buffer)
// ================================
SoundPlayerOpenAL::SoundPlayerOpenAL() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
device = 0;
initOk = false;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
SoundPlayerOpenAL::~SoundPlayerOpenAL() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
end();
initOk = false;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void SoundPlayerOpenAL::printOpenALInfo()
@ -315,7 +327,7 @@ void SoundPlayerOpenAL::printOpenALInfo()
}
bool SoundPlayerOpenAL::init(const SoundPlayerParams* params) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
initOk = false;
@ -341,11 +353,11 @@ bool SoundPlayerOpenAL::init(const SoundPlayerParams* params) {
checkAlError("Audio error after init: ");
initOk = true;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d] error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
printOpenALInfo();
//throw std::runtime_error(ex.what());
}
@ -355,7 +367,7 @@ bool SoundPlayerOpenAL::init(const SoundPlayerParams* params) {
void SoundPlayerOpenAL::end() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(StaticSoundSources::iterator i = staticSources.begin();
@ -364,7 +376,7 @@ void SoundPlayerOpenAL::end() {
src->stop();
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(StreamSoundSources::iterator i = streamSources.begin();
i != streamSources.end(); ++i) {
@ -372,32 +384,32 @@ void SoundPlayerOpenAL::end() {
src->stop();
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(StaticSoundSources::iterator i = staticSources.begin();
i != staticSources.end(); ++i) {
delete *i;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(StreamSoundSources::iterator i = streamSources.begin();
i != streamSources.end(); ++i) {
delete *i;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
alcMakeContextCurrent( NULL );
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(context != 0) {
alcDestroyContext(context);
context = 0;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(device != 0) {
alcCloseDevice(device);
@ -405,7 +417,7 @@ void SoundPlayerOpenAL::end() {
initOk = false;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void SoundPlayerOpenAL::play(StaticSound* staticSound) {
@ -415,13 +427,15 @@ void SoundPlayerOpenAL::play(StaticSound* staticSound) {
try {
StaticSoundSource* source = findStaticSoundSource();
if(source == 0)
if(source == 0) {
return;
}
source->play(staticSound);
}
catch(std::exception& e) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
std::cerr << "Couldn't play static sound: " << e.what() << "\n";
std::cerr << "Couldn't play static sound: [" << e.what() << "]\n";
}
}
@ -481,7 +495,7 @@ void SoundPlayerOpenAL::updateStreams() {
source->update();
}
catch(std::exception& e) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
std::cerr << "Error while updating sound stream: "<< e.what() << "\n";
@ -491,13 +505,13 @@ void SoundPlayerOpenAL::updateStreams() {
checkAlcError("Error while processing audio context: ");
}
catch(exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
printOpenALInfo();
throw runtime_error(ex.what());
}
catch(...) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] UNKNOWN Error\n",__FILE__,__FUNCTION__,__LINE__);
printOpenALInfo();
throw;
@ -521,12 +535,12 @@ StaticSoundSource* SoundPlayerOpenAL::findStaticSoundSource() {
return 0;
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
StaticSoundSource* source = new StaticSoundSource();
staticSources.push_back(source);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return source;
}
@ -548,12 +562,12 @@ StreamSoundSource* SoundPlayerOpenAL::findStreamSoundSource() {
throw std::runtime_error("Too many stream sounds played at once");
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
StreamSoundSource* source = new StreamSoundSource();
streamSources.push_back(source);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
return source;
}

View File

@ -159,30 +159,24 @@ void OggSoundFileLoader::open(const string &path, SoundInfo *soundInfo){
throw runtime_error("Can't read ogg header info for file: "+path);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] vi->version = %d, vi->channels = %d, vi->rate = %ld, vi->bitrate_upper = %ld, vi->bitrate_nominal = %ld, vi->bitrate_lower = %ld, vi->bitrate_window = %ld\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),vi->version,vi->channels,vi->rate,vi->bitrate_upper,vi->bitrate_nominal,vi->bitrate_lower,vi->bitrate_window);
uint32 samples = static_cast<uint32>(ov_pcm_total(vf, -1));
SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s Line: %d] path = [%s] vi->version = %d, vi->channels = %d, vi->rate = %ld, vi->bitrate_upper = %ld, vi->bitrate_nominal = %ld, vi->bitrate_lower = %ld, vi->bitrate_window = %ld, samples = %lu\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),vi->version,vi->channels,vi->rate,vi->bitrate_upper,vi->bitrate_nominal,vi->bitrate_lower,vi->bitrate_window,samples);
soundInfo->setChannels(vi->channels);
soundInfo->setsamplesPerSecond(vi->rate);
soundInfo->setBitsPerSample(16);
uint32 samples = static_cast<uint32>(ov_pcm_total(vf, -1));
//if(vi->channels == 1) {
soundInfo->setSize(samples * 2);
//}
//else {
// soundInfo->setSize(samples * 4);
//}
soundInfo->setSize(samples * 2);
}
uint32 OggSoundFileLoader::read(int8 *samples, uint32 size){
int section;
int totalBytesRead= 0;
while(size>0){
while(size>0) {
int bytesRead= ov_read(vf, reinterpret_cast<char*> (samples), size,
0, 2, 1, &section);
if(bytesRead==0){
if(bytesRead==0) {
break;
}
size-= bytesRead;

View File

@ -186,13 +186,14 @@ void SystemFlags::init(bool haveSpecialOutputCommandLineOption) {
if(SystemFlags::debugLogFileList == NULL) {
SystemFlags::debugLogFileList = new std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType>();
(*SystemFlags::debugLogFileList)[SystemFlags::debugSystem] = SystemFlags::SystemFlagsType(SystemFlags::debugSystem);
(*SystemFlags::debugLogFileList)[SystemFlags::debugSystem] = SystemFlags::SystemFlagsType(SystemFlags::debugSystem);
(*SystemFlags::debugLogFileList)[SystemFlags::debugNetwork] = SystemFlags::SystemFlagsType(SystemFlags::debugNetwork);
(*SystemFlags::debugLogFileList)[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance);
(*SystemFlags::debugLogFileList)[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch);
(*SystemFlags::debugLogFileList)[SystemFlags::debugUnitCommands] = SystemFlags::SystemFlagsType(SystemFlags::debugUnitCommands);
(*SystemFlags::debugLogFileList)[SystemFlags::debugLUA] = SystemFlags::SystemFlagsType(SystemFlags::debugLUA);
(*SystemFlags::debugLogFileList)[SystemFlags::debugError] = SystemFlags::SystemFlagsType(SystemFlags::debugError);
(*SystemFlags::debugLogFileList)[SystemFlags::debugSound] = SystemFlags::SystemFlagsType(SystemFlags::debugSound);
(*SystemFlags::debugLogFileList)[SystemFlags::debugError] = SystemFlags::SystemFlagsType(SystemFlags::debugError);
}
if(threadLogger == NULL) {