- removed directsound related references as it has been deprecated since 3.6.0.1

- coverity related fixes
This commit is contained in:
SoftCoder 2013-12-25 11:42:00 -08:00
parent a6b02a598b
commit 3bb9da6cdf
20 changed files with 45 additions and 752 deletions

View File

@ -68,7 +68,7 @@ namespace Glest { namespace Game {
string getGameReadWritePath(string lookupKey) {
string path = "";
if(path == "" && getenv("GLESTHOME") != NULL) {
path = getenv("GLESTHOME");
path = safeCharPtrCopy(getenv("GLESTHOME"),8096);
if(path != "" && EndsWith(path, "/") == false && EndsWith(path, "\\") == false) {
path += "/";
}

View File

@ -166,7 +166,6 @@ IF(BUILD_MEGAGLEST)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/posix)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/sound/ds8)
INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl )
ELSE()
INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl )

View File

@ -4739,7 +4739,7 @@ int glestMain(int argc, char** argv) {
string newMaxSeconds = paramPartTokens2[0];
time_t newTimeMaxSeconds = strToInt(newMaxSeconds);
AutoTest::setMaxGameTime(newTimeMaxSeconds);
printf("Forcing maximum game time to [%ld] seconds (%.2f minutes)\n",newTimeMaxSeconds,((double)newTimeMaxSeconds / 60.0));
printf("Forcing maximum game time to [%ld] seconds (%.2f minutes)\n",(long int)newTimeMaxSeconds,((double)newTimeMaxSeconds / 60.0));
}
if(paramPartTokens2.size() >= 3 && paramPartTokens2[2].length() > 0) {
string autoTestCmd = paramPartTokens2[2];

View File

@ -393,10 +393,6 @@ void MenuStateOptionsGraphics::reloadUI() {
std::vector<string> listboxData;
listboxData.push_back("None");
listboxData.push_back("OpenAL");
// deprecated as of 3.6.1
//#ifdef WIN32
// listboxData.push_back("DirectSound8");
//#endif
labelScreenModes.setText(lang.getString("Resolution"));

View File

@ -257,11 +257,6 @@ void MenuStateOptionsNetwork::reloadUI() {
std::vector<string> listboxData;
listboxData.push_back("None");
listboxData.push_back("OpenAL");
// deprecated as of 3.6.1
//#ifdef WIN32
// listboxData.push_back("DirectSound8");
//#endif
listboxData.clear();
listboxData.push_back("Bilinear");

View File

@ -109,10 +109,6 @@ MenuStateOptionsSound::MenuStateOptionsSound(Program *program, MainMenu *mainMen
listBoxSoundFactory.init(currentColumnStart, currentLine, 100);
listBoxSoundFactory.pushBackItem("None");
listBoxSoundFactory.pushBackItem("OpenAL");
// deprecated as of 3.6.1
//#ifdef WIN32
//listBoxSoundFactory.pushBackItem("DirectSound8");
//#endif
listBoxSoundFactory.setSelectedItem(config.getString("FactorySound"));
currentLine-=lineOffset;
@ -207,10 +203,6 @@ void MenuStateOptionsSound::reloadUI() {
std::vector<string> listboxData;
listboxData.push_back("None");
listboxData.push_back("OpenAL");
// deprecated as of 3.6.1
//#ifdef WIN32
// listboxData.push_back("DirectSound8");
//#endif
listBoxSoundFactory.setItems(listboxData);

View File

@ -2260,9 +2260,9 @@ bool NetworkMessageSynchNetworkGameDataStatus::receive(Socket* socket) {
fromEndianHeader();
// Here we loop possibly multiple times
uint32 packetLoopCount = 1;
if(data.header.techCRCFileCount > (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount) {
packetLoopCount = (data.header.techCRCFileCount / (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount);
if(data.header.techCRCFileCount % (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount > 0) {
if(data.header.techCRCFileCount > NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount) {
packetLoopCount = (data.header.techCRCFileCount / NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount);
if(data.header.techCRCFileCount % NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount > 0) {
packetLoopCount++;
}
}
@ -2271,8 +2271,8 @@ bool NetworkMessageSynchNetworkGameDataStatus::receive(Socket* socket) {
for(uint32 iPacketLoop = 0; iPacketLoop < packetLoopCount; ++iPacketLoop) {
uint32 packetIndex = iPacketLoop * (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount;
uint32 maxFileCountPerPacket = (uint32)maxFileCRCPacketCount;
uint32 packetIndex = iPacketLoop * NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount;
uint32 maxFileCountPerPacket = maxFileCRCPacketCount;
uint32 packetFileCount = min((uint32)maxFileCountPerPacket,data.header.techCRCFileCount - packetIndex);
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] iPacketLoop = %u, packetIndex = %u, packetFileCount = %u\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,iPacketLoop,packetIndex,packetFileCount);
@ -2305,7 +2305,7 @@ void NetworkMessageSynchNetworkGameDataStatus::send(Socket* socket) {
if(totalFileCount > 0) {
// Here we loop possibly multiple times
int packetLoopCount = 1;
if(totalFileCount > (uint32)NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount) {
if(totalFileCount > NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount) {
packetLoopCount = (totalFileCount / NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount);
if(totalFileCount % NetworkMessageSynchNetworkGameDataStatus::maxFileCRCPacketCount > 0) {
packetLoopCount++;

View File

@ -601,7 +601,7 @@ private:
static const int maxStringSize= 255;
static const int maxFileCRCCount= 1500;
static const int maxFileCRCPacketCount= 25;
static const uint32 maxFileCRCPacketCount= 25;
private:

View File

@ -353,7 +353,6 @@ option(ENABLE_FRIBIDI "Enable FriBIDi support" ON)
SET(DIRS_WITH_SRC ${DIRS_WITH_SRC} platform/macosx)
ELSEIF(WIN32)
SET(DIRS_WITH_SRC ${DIRS_WITH_SRC} platform/win32)
SET(DIRS_WITH_SRC ${DIRS_WITH_SRC} sound/ds8)
SET(DIRS_WITH_SRC ${DIRS_WITH_SRC} ${PROJECT_SOURCE_DIR}/source/win32_deps/src)
ELSE()
SET(DIRS_WITH_SRC ${DIRS_WITH_SRC} platform/sdl)

View File

@ -123,7 +123,7 @@ private:
Uint32 lastStartCount;
Uint32 lastTickCount;
int64 lastResult;
int32 lastMultiplier;
int64 lastMultiplier;
bool lastStopped;
public:
@ -140,7 +140,7 @@ public:
static int64 getCurMillis();
private:
int64 queryCounter(int32 multiplier);
int64 queryCounter(int64 multiplier);
};
// =====================================================

View File

@ -1,31 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martiñ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,136 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martiñ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 <mmsystem.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 bool 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(int64 fadeOff=0);
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

@ -297,6 +297,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
myAddr.sin_family = AF_INET;
myAddr.sin_addr.s_addr = INADDR_ANY;
myAddr.sin_port = htons(20);
myAddr.sin_zero[0] = 0;
if(bind(dataSocket, (struct sockaddr *)&myAddr, sizeof(myAddr)))
{
if(VERBOSE_MODE_ENABLED) printf("In ftpEstablishDataConnection #2 about to Close socket = %d, for sessionId = %d\n",dataSocket, sessionId);

View File

@ -189,7 +189,7 @@ int64 Chrono::getSeconds() {
return queryCounter(1);
}
int64 Chrono::queryCounter(int32 multiplier) {
int64 Chrono::queryCounter(int64 multiplier) {
if( multiplier == lastMultiplier &&
stopped == lastStopped &&

View File

@ -546,14 +546,21 @@ string getNetworkInterfaceBroadcastAddress(string ipAddress)
// Adapted from example code at http://msdn2.microsoft.com/en-us/library/aa365917.aspx
// Now get Windows' IPv4 addresses table. Once again, we gotta call GetIpAddrTable()
// multiple times in order to deal with potential race conditions properly.
MIB_IPADDRTABLE * ipTable = NULL;
PMIB_IPADDRTABLE * ipTable = NULL;
// Before calling AddIPAddress we use GetIpAddrTable to get
// an adapter to which we can add the IP.
ipTable = (MIB_IPADDRTABLE *) MALLOC(sizeof (MIB_IPADDRTABLE));
ipTable->dwNumEntries = 0;
{
ULONG bufLen = 0;
for (int i = 0; i < 5; i++) {
DWORD ipRet = GetIpAddrTable(ipTable, &bufLen, false);
if (ipRet == ERROR_INSUFFICIENT_BUFFER) {
free(ipTable); // in case we had previously allocated it
ipTable = (MIB_IPADDRTABLE *) malloc(bufLen);
ipTable->dwNumEntries = 0;
}
else if(ipRet == NO_ERROR) {
break;
@ -635,8 +642,8 @@ string getNetworkInterfaceBroadcastAddress(string ipAddress)
}
}
free(pAdapterInfo);
free(ipTable);
if(AdapterInfo) free(pAdapterInfo);
if(ipTable) free(ipTable);
}
#else
// Dunno what we're running on here!
@ -2150,7 +2157,7 @@ void BroadCastClientSocketThread::execute() {
if(bcfd >= 0) ::close(bcfd);
bcfd = -1;
#else
if(bcfd >= 0) ::closesocket(bcfd);
if(bcfd != INVALID_SOCKET) ::closesocket(bcfd);
bcfd = INVALID_SOCKET;
#endif

View File

@ -33,10 +33,6 @@ GraphicsFactory *FactoryRepository::getGraphicsFactory(const string &name){
}
SoundFactory *FactoryRepository::getSoundFactory(const string &name){
// deprecated as of 3.6.1
//if(name == "DirectSound8"){
// return &soundFactoryDs8;
//}
if(name == "OpenAL") {
return &soundFactoryOpenAL;
}

View File

@ -1,528 +0,0 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Martiñ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
// ==============================================================
#include "sound_player_ds8.h"
#include <cassert>
#include "math_wrapper.h"
#include "util.h"
#include "leak_dumper.h"
namespace Shared{ namespace Sound{ namespace Ds8{
using namespace Util;
// =====================================================
// class SoundBuffer
// =====================================================
// ===================== PUBLIC ========================
SoundBuffer::SoundBuffer(){
dsBuffer= NULL;
sound= NULL;
}
bool SoundBuffer::isFree(){
if(dsBuffer==NULL){
return true;
}
DWORD status;
dsBuffer->GetStatus(&status);
if(status & DSBSTATUS_BUFFERLOST){
end();
return true;
}
return false;
}
bool SoundBuffer::isReady(){
DWORD status;
dsBuffer->GetStatus(&status);
if ((status & DSBSTATUS_PLAYING) || (status & DSBSTATUS_BUFFERLOST)){
return false;
}
return true;
}
// ==================== PROTECTED ======================
void SoundBuffer::createDsBuffer(IDirectSound8 *dsObject){
IDirectSoundBuffer *buffer;
const SoundInfo *soundInfo= sound->getInfo();
//format
WAVEFORMATEX format;
format.wFormatTag= WAVE_FORMAT_PCM;
format.nChannels= soundInfo->getChannels();
format.nSamplesPerSec= soundInfo->getSamplesPerSecond();
format.nAvgBytesPerSec= (soundInfo->getBitsPerSample() * soundInfo->getSamplesPerSecond() * soundInfo->getChannels())/8;
format.nBlockAlign= (soundInfo->getChannels() * soundInfo->getBitsPerSample())/8;
format.wBitsPerSample= soundInfo->getBitsPerSample();
format.cbSize= 0;
//buffer desc
DSBUFFERDESC dsBufferDesc;
memset(&dsBufferDesc, 0, sizeof(DSBUFFERDESC));
dsBufferDesc.dwSize= sizeof(DSBUFFERDESC);
dsBufferDesc.dwFlags= DSBCAPS_CTRLVOLUME;
dsBufferDesc.dwBufferBytes= size;
dsBufferDesc.lpwfxFormat= &format;
//create buffer
HRESULT hr= dsObject->CreateSoundBuffer(&dsBufferDesc, &buffer, NULL);
if (hr!=DS_OK){
throw megaglest_runtime_error("Failed to create direct sound buffer");
}
//query dx8 interface
hr = buffer->QueryInterface(IID_IDirectSoundBuffer8, (void**) &dsBuffer);
buffer->Release();
if (hr!=S_OK){
throw megaglest_runtime_error("Failed to create direct sound 8 static buffer");
}
}
// =====================================================
// class StaticBuffer
// =====================================================
// ===================== PUBLIC ========================
void StaticSoundBuffer::init(IDirectSound8 *dsObject, Sound *sound){
if(this->sound==NULL){
this->sound= sound;
this->size= sound->getInfo()->getSize();
createDsBuffer(dsObject);
dsBuffer->SetCurrentPosition(0);
fillDsBuffer();
}
}
void StaticSoundBuffer::end(){
dsBuffer->Stop();
dsBuffer->Release();
dsBuffer= NULL;
sound= NULL;
}
void StaticSoundBuffer::play(){
dsBuffer->SetVolume(dsVolume(sound->getVolume()));
dsBuffer->Play(0, 0, 0);
}
// ===================== PRIVATE =======================
void StaticSoundBuffer::fillDsBuffer(){
void * writePointer;
unsigned long size;
//lock
HRESULT hr= dsBuffer->Lock(0, 0, &writePointer, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
if (hr!=DS_OK){
throw megaglest_runtime_error("Failed to Lock direct sound buffer");
}
//copy memory
memcpy(writePointer, getStaticSound()->getSamples(), size);
//unlock
hr= dsBuffer->Unlock(writePointer, size, NULL, 0);
if (hr!=DS_OK){
throw megaglest_runtime_error("Failed to Unlock direct sound buffer");
}
}
// =====================================================
// class StrBuffer
// =====================================================
// ===================== PUBLIC ========================
StrSoundBuffer::StrSoundBuffer(){
state= sFree;
}
void StrSoundBuffer::init(IDirectSound8 *dsObject, Sound *sound, uint32 strBufferSize){
state= sStopped;
if(this->sound==NULL){
this->sound= sound;
this->size= strBufferSize;
createDsBuffer(dsObject);
dsBuffer->SetCurrentPosition(0);
fillDsBuffer();
}
else if(this->sound!=sound){
this->sound= sound;
this->size= strBufferSize;
dsBuffer->SetCurrentPosition(0);
fillDsBuffer();
}
}
void StrSoundBuffer::end(){
state= sFree;
dsBuffer->Stop();
dsBuffer->Release();
dsBuffer= NULL;
sound= NULL;
}
void StrSoundBuffer::play(int64 fadeOn){
assert(state==sStopped);
lastPlayCursor= 0;
if(fadeOn==0){
state= sPlaying;
dsBuffer->SetVolume(dsVolume(sound->getVolume()));
}
else{
this->fade= fadeOn;
state= sFadingOn;
chrono.start();
dsBuffer->SetVolume(dsVolume(0.f));
}
dsBuffer->Play(0, 0, DSBPLAY_LOOPING);
}
void StrSoundBuffer::update(){
switch(state){
case sFadingOn:
if(chrono.getMillis()>fade){
dsBuffer->SetVolume(dsVolume(sound->getVolume()));
state= sPlaying;
}
else{
dsBuffer->SetVolume(dsVolume(sound->getVolume()*(static_cast<float>(chrono.getMillis())/fade)));
}
refreshDsBuffer();
break;
case sFadingOff:
if(chrono.getMillis()>fade){
state= sStopped;
dsBuffer->Stop();
}
else{
dsBuffer->SetVolume(dsVolume(sound->getVolume()*(1.0f-static_cast<float>(chrono.getMillis())/fade)));
refreshDsBuffer();
}
break;
case sPlaying:
dsBuffer->SetVolume(dsVolume(sound->getVolume()));
refreshDsBuffer();
break;
default:
break;
}
}
void StrSoundBuffer::stop(int64 fadeOff){
if(fadeOff==0){
dsBuffer->Stop();
state= sStopped;
}
else{
this->fade= fadeOff;
state= sFadingOff;
chrono.start();
}
}
// ===================== PRIVATE =======================
void StrSoundBuffer::fillDsBuffer(){
void * writePointer;
unsigned long size;
//lock
HRESULT hr= dsBuffer->Lock(0, 0, &writePointer, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
if (hr!=DS_OK){
throw megaglest_runtime_error("Failed to Lock direct sound buffer");
}
//copy memory
readChunk(writePointer, size);
//unlock
hr= dsBuffer->Unlock(writePointer, size, NULL, 0 );
if (hr!=DS_OK){
throw megaglest_runtime_error("Failed to Unlock direct sound buffer");
}
}
void StrSoundBuffer::refreshDsBuffer(){
void *writePointer1, *writePointer2;
DWORD size1, size2;
DWORD playCursor;
DWORD bytesToLock;
DWORD status;
dsBuffer->GetStatus(&status);
assert(!(status & DSBSTATUS_BUFFERLOST));
HRESULT hr= dsBuffer->GetCurrentPosition(&playCursor, NULL);
if(hr!=DS_OK){
throw megaglest_runtime_error("Failed to Lock query play position");
}
//compute bytes to lock
if(playCursor>=lastPlayCursor){
bytesToLock= playCursor - lastPlayCursor;
}
else{
bytesToLock= size - (lastPlayCursor - playCursor);
}
//copy data
if(bytesToLock>0){
//lock
HRESULT hr=dsBuffer->Lock(lastPlayCursor, bytesToLock, &writePointer1, &size1, &writePointer2, &size2, 0);
if (hr!=DS_OK){
throw megaglest_runtime_error("Failed to Lock direct sound buffer");
}
//copy memory
assert(size1+size2==bytesToLock);
readChunk(writePointer1, size1);
readChunk(writePointer2, size2);
//unlock
hr= dsBuffer->Unlock(writePointer1, size1, writePointer2, size2);
if (hr!=DS_OK){
throw megaglest_runtime_error("Failed to Unlock direct sound buffer");
}
}
lastPlayCursor= playCursor;
}
void StrSoundBuffer::readChunk(void *writePointer, uint32 size){
StrSound *s= getStrSound();
uint32 readSize= s->read(static_cast<int8*>(writePointer), size);
if(readSize<size){
StrSound *next= s->getNext()==NULL? s: s->getNext();
next->restart();
next->read(&static_cast<int8*>(writePointer)[readSize], size-readSize);
next->setVolume(s->getVolume());
sound= next;
}
}
// =====================================================
// class SoundPlayerDs8
// =====================================================
SoundPlayerDs8::SoundPlayerDs8(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
dsObject= NULL;
initOk = false;
}
bool SoundPlayerDs8::init(const SoundPlayerParams *params){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
initOk = false;
HRESULT hr;
if(params == NULL) {
throw std::runtime_error("params == NULL");
}
this->params= *params;
try {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//reserve memory for buffers
staticSoundBuffers.resize(params->staticBufferCount);
strSoundBuffers.resize(params->strBufferCount);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//create object
hr=DirectSoundCreate8(NULL, &dsObject, NULL);
if (hr!=DS_OK){
throw megaglest_runtime_error("Can't create direct sound object");
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
//Set cooperative level
hr= dsObject->SetCooperativeLevel(GetActiveWindow(), DSSCL_PRIORITY);
if (hr!=DS_OK){
throw megaglest_runtime_error("Can't set cooperative level of dsound");
}
initOk = true;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"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());
}
return initOk;
}
void SoundPlayerDs8::end(){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
stopAllSounds();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void SoundPlayerDs8::play(StaticSound *staticSound){
if(initOk == false) return;
int bufferIndex= -1;
assert(staticSound!=NULL);
//if buffer found, play the sound
if (findStaticBuffer(staticSound, &bufferIndex)){
staticSoundBuffers[bufferIndex].init(dsObject, staticSound);
staticSoundBuffers[bufferIndex].play();
}
}
void SoundPlayerDs8::play(StrSound *strSound, int64 fadeOn){
if(initOk == false) return;
int bufferIndex= -1;
//play sound if buffer found
if(findStrBuffer(strSound, &bufferIndex)){
strSoundBuffers[bufferIndex].init(dsObject, strSound, params.strBufferSize);
strSoundBuffers[bufferIndex].play(fadeOn);
}
}
void SoundPlayerDs8::stop(StrSound *strSound, int64 fadeOff){
if(initOk == false) return;
//find the buffer with this sound and stop it
for(unsigned int i= 0; i<params.strBufferCount; ++i){
if(strSoundBuffers[i].getSound()==strSound){
strSoundBuffers[i].stop(fadeOff);
}
}
}
void SoundPlayerDs8::stopAllSounds(int64 fadeOff){
if(initOk == false) return;
for(unsigned int i=0; i<params.strBufferCount; ++i){
if(!strSoundBuffers[i].isFree()){
strSoundBuffers[i].stop(fadeOff);
strSoundBuffers[i].end();
}
}
for(unsigned int i=0; i<params.staticBufferCount; ++i){
if(!staticSoundBuffers[i].isFree()){
staticSoundBuffers[i].end();
}
}
}
void SoundPlayerDs8::updateStreams(){
if(initOk == false) return;
for(unsigned int i=0; i<params.strBufferCount; ++i){
strSoundBuffers[i].update();
}
}
// ===================== PRIVATE =======================
bool SoundPlayerDs8::findStaticBuffer(Sound *sound, int *bufferIndex){
bool bufferFound= false;
if(initOk == false) return bufferFound;
assert(sound!=NULL);
//1st: we try fo find a stopped buffer with the same sound
for(unsigned int i=0; i<staticSoundBuffers.size(); ++i){
if(sound==staticSoundBuffers[i].getSound() && staticSoundBuffers[i].isReady()){
*bufferIndex= i;
bufferFound= true;
break;
}
}
//2nd: we try to find a free buffer
if(!bufferFound){
for(uint32 i=0; i<staticSoundBuffers.size(); ++i){
if(staticSoundBuffers[i].isFree()){
*bufferIndex= i;
bufferFound= true;
break;
}
}
}
//3rd: we try to find a stopped buffer
if(!bufferFound){
for(unsigned int i=0; i<staticSoundBuffers.size(); ++i){
if(staticSoundBuffers[i].isReady()){
staticSoundBuffers[i].end();
*bufferIndex= i;
bufferFound= true;
break;
}
}
}
return bufferFound;
}
bool SoundPlayerDs8::findStrBuffer(Sound *sound, int *bufferIndex){
bool bufferFound= false;
if(initOk == false) return bufferFound;
assert(sound!=NULL);
assert(sound->getVolume()<=1.0f && sound->getVolume()>=0.0f);
//We try to find a free or ready buffer
if(!bufferFound){
for(uint32 i=0; i<strSoundBuffers.size(); ++i){
if(strSoundBuffers[i].isFree() || strSoundBuffers[i].isReady()){
*bufferIndex= i;
bufferFound= true;
break;
}
}
}
return bufferFound;
}
// =====================================================
// Misc
// =====================================================
long dsVolume(float floatVolume){
float correctedVol= std::log10f(floatVolume*9.f+1.f);
long vol= static_cast<long>(DSBVOLUME_MIN+correctedVol*(DSBVOLUME_MAX-DSBVOLUME_MIN));
return clamp(vol, DSBVOLUME_MIN, DSBVOLUME_MAX);
}
}}}//end namespace

View File

@ -179,18 +179,20 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
// First add the standard tags
//
#ifdef WIN32
const char *homeDir = getenv("USERPROFILE");
const char *homeDirX = getenv("USERPROFILE");
#else
string home = getUserHome();
const char *homeDir = home.c_str();
const char *homeDirX = home.c_str();
#endif
mapTagReplacementValues["~/"] = (homeDir != NULL ? homeDir : "");
mapTagReplacementValues["$HOME"] = (homeDir != NULL ? homeDir : "");
mapTagReplacementValues["%%HOME%%"] = (homeDir != NULL ? homeDir : "");
mapTagReplacementValues["%%USERPROFILE%%"] = (homeDir != NULL ? homeDir : "");
mapTagReplacementValues["%%HOMEPATH%%"] = (homeDir != NULL ? homeDir : "");
mapTagReplacementValues["{HOMEPATH}"] = (homeDir != NULL ? homeDir : "");
string homeDir = safeCharPtrCopy(homeDirX, 8096);
mapTagReplacementValues["~/"] = homeDir;
mapTagReplacementValues["$HOME"] = homeDir;
mapTagReplacementValues["%%HOME%%"] = homeDir;
mapTagReplacementValues["%%USERPROFILE%%"] = homeDir;
mapTagReplacementValues["%%HOMEPATH%%"] = homeDir;
mapTagReplacementValues["{HOMEPATH}"] = homeDir;
// For win32 we allow use of the appdata variable since that is the recommended
// place for application data in windows platform
@ -281,18 +283,20 @@ bool Properties::applyTagsToValue(string &value, const std::map<string,string> *
}
else {
#ifdef WIN32
const char *homeDir = getenv("USERPROFILE");
const char *homeDirX = getenv("USERPROFILE");
#else
string home = getUserHome();
const char *homeDir = home.c_str();
const char *homeDirX = home.c_str();
#endif
replaceAll(value, "~/", (homeDir != NULL ? homeDir : ""));
replaceAll(value, "$HOME", (homeDir != NULL ? homeDir : ""));
replaceAll(value, "%%HOME%%", (homeDir != NULL ? homeDir : ""));
replaceAll(value, "%%USERPROFILE%%",(homeDir != NULL ? homeDir : ""));
replaceAll(value, "%%HOMEPATH%%", (homeDir != NULL ? homeDir : ""));
replaceAll(value, "{HOMEPATH}", (homeDir != NULL ? homeDir : ""));
string homeDir = safeCharPtrCopy(homeDirX, 8096);
replaceAll(value, "~/", homeDir);
replaceAll(value, "$HOME", homeDir);
replaceAll(value, "%%HOME%%", homeDir);
replaceAll(value, "%%USERPROFILE%%",homeDir);
replaceAll(value, "%%HOMEPATH%%", homeDir);
replaceAll(value, "{HOMEPATH}", homeDir);
// For win32 we allow use of the appdata variable since that is the recommended
// place for application data in windows platform

View File

@ -75,7 +75,6 @@ IF(BUILD_MEGAGLEST_TESTS)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/win32_deps/include)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/posix)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/platform/win32)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/source/shared_lib/include/sound/ds8)
INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl )
ELSE()
INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_ROOT}platform/sdl )

View File

@ -256,7 +256,7 @@ int processMesh(xmlNode *n, FILE *outfile)
/* populate the MeshHeader structure appropriately */
memset(&mh, 0, sizeof(struct MeshHeader));
strncpy((char*)mh.name, (char*)xmlGetProp(n, name), NAMESIZE);
strncpy((char*)mh.name, (char*)xmlGetProp(n, name), NAMESIZE-1);
mh.frameCount = (uint32)atoi((char*)xmlGetProp(n, frameCount));
mh.vertexCount = (uint32)atoi((char*)xmlGetProp(n, vertexCount));
mh.indexCount = (uint32)atoi((char*)xmlGetProp(n, indexCount));