From 3bb9da6cdfb15f49395d2f87e3dfe480b79857f6 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Wed, 25 Dec 2013 11:42:00 -0800 Subject: [PATCH] - removed directsound related references as it has been deprecated since 3.6.0.1 - coverity related fixes --- source/g3d_viewer/main.cpp | 2 +- source/glest_game/CMakeLists.txt | 1 - source/glest_game/main/main.cpp | 2 +- .../menu/menu_state_options_graphics.cpp | 4 - .../menu/menu_state_options_network.cpp | 5 - .../menu/menu_state_options_sound.cpp | 8 - source/glest_game/network/network_message.cpp | 12 +- source/glest_game/network/network_message.h | 2 +- source/shared_lib/CMakeLists.txt | 1 - .../include/platform/common/platform_common.h | 4 +- .../include/sound/ds8/sound_factory_ds8.h | 31 - .../include/sound/ds8/sound_player_ds8.h | 136 ----- .../sources/feathery_ftp/ftpTargetWin32.c | 1 + .../platform/common/platform_common.cpp | 2 +- .../sources/platform/posix/socket.cpp | 15 +- .../platform/win32/factory_repository.cpp | 4 - .../sources/sound/ds8/sound_player_ds8.cpp | 528 ------------------ source/shared_lib/sources/util/properties.cpp | 36 +- source/tests/CMakeLists.txt | 1 - source/tools/glexemel/xml2g.c | 2 +- 20 files changed, 45 insertions(+), 752 deletions(-) delete mode 100644 source/shared_lib/include/sound/ds8/sound_factory_ds8.h delete mode 100644 source/shared_lib/include/sound/ds8/sound_player_ds8.h delete mode 100644 source/shared_lib/sources/sound/ds8/sound_player_ds8.cpp diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 72ce2155..1276f73e 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -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 += "/"; } diff --git a/source/glest_game/CMakeLists.txt b/source/glest_game/CMakeLists.txt index bf9e7294..d3d0de77 100644 --- a/source/glest_game/CMakeLists.txt +++ b/source/glest_game/CMakeLists.txt @@ -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 ) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index f2df0716..1f69a2dd 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -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]; diff --git a/source/glest_game/menu/menu_state_options_graphics.cpp b/source/glest_game/menu/menu_state_options_graphics.cpp index 464252bf..3aac17d7 100644 --- a/source/glest_game/menu/menu_state_options_graphics.cpp +++ b/source/glest_game/menu/menu_state_options_graphics.cpp @@ -393,10 +393,6 @@ void MenuStateOptionsGraphics::reloadUI() { std::vector 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")); diff --git a/source/glest_game/menu/menu_state_options_network.cpp b/source/glest_game/menu/menu_state_options_network.cpp index cb995611..b6cd38e9 100644 --- a/source/glest_game/menu/menu_state_options_network.cpp +++ b/source/glest_game/menu/menu_state_options_network.cpp @@ -257,11 +257,6 @@ void MenuStateOptionsNetwork::reloadUI() { std::vector 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"); diff --git a/source/glest_game/menu/menu_state_options_sound.cpp b/source/glest_game/menu/menu_state_options_sound.cpp index 14b2196f..15e1ab8a 100644 --- a/source/glest_game/menu/menu_state_options_sound.cpp +++ b/source/glest_game/menu/menu_state_options_sound.cpp @@ -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 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); diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index 5d27348f..7e44ea5e 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -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++; diff --git a/source/glest_game/network/network_message.h b/source/glest_game/network/network_message.h index 38c1db8f..af6d5511 100644 --- a/source/glest_game/network/network_message.h +++ b/source/glest_game/network/network_message.h @@ -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: diff --git a/source/shared_lib/CMakeLists.txt b/source/shared_lib/CMakeLists.txt index 2b6b5868..44006ec8 100644 --- a/source/shared_lib/CMakeLists.txt +++ b/source/shared_lib/CMakeLists.txt @@ -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) diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index aa13c0a2..667d4ea8 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -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); }; // ===================================================== diff --git a/source/shared_lib/include/sound/ds8/sound_factory_ds8.h b/source/shared_lib/include/sound/ds8/sound_factory_ds8.h deleted file mode 100644 index 0f99892d..00000000 --- a/source/shared_lib/include/sound/ds8/sound_factory_ds8.h +++ /dev/null @@ -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 diff --git a/source/shared_lib/include/sound/ds8/sound_player_ds8.h b/source/shared_lib/include/sound/ds8/sound_player_ds8.h deleted file mode 100644 index 76c2c24b..00000000 --- a/source/shared_lib/include/sound/ds8/sound_player_ds8.h +++ /dev/null @@ -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 -#include - -#include - -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(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(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 staticSoundBuffers; - vector 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 diff --git a/source/shared_lib/sources/feathery_ftp/ftpTargetWin32.c b/source/shared_lib/sources/feathery_ftp/ftpTargetWin32.c index 37ea9877..579126d1 100644 --- a/source/shared_lib/sources/feathery_ftp/ftpTargetWin32.c +++ b/source/shared_lib/sources/feathery_ftp/ftpTargetWin32.c @@ -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); diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index dbfadaa5..7b5eda7a 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -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 && diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index dd86c116..15f97a10 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -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 diff --git a/source/shared_lib/sources/platform/win32/factory_repository.cpp b/source/shared_lib/sources/platform/win32/factory_repository.cpp index 5037a845..e650d474 100644 --- a/source/shared_lib/sources/platform/win32/factory_repository.cpp +++ b/source/shared_lib/sources/platform/win32/factory_repository.cpp @@ -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; } diff --git a/source/shared_lib/sources/sound/ds8/sound_player_ds8.cpp b/source/shared_lib/sources/sound/ds8/sound_player_ds8.cpp deleted file mode 100644 index 28ab185a..00000000 --- a/source/shared_lib/sources/sound/ds8/sound_player_ds8.cpp +++ /dev/null @@ -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 -#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(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(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(writePointer), size); - if(readSizegetNext()==NULL? s: s->getNext(); - next->restart(); - next->read(&static_cast(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; igetVolume()<=1.0f && sound->getVolume()>=0.0f); - - //We try to find a free or ready buffer - if(!bufferFound){ - for(uint32 i=0; i(DSBVOLUME_MIN+correctedVol*(DSBVOLUME_MAX-DSBVOLUME_MIN)); - return clamp(vol, DSBVOLUME_MIN, DSBVOLUME_MAX); -} - -}}}//end namespace diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 3e7411fc..254cf2da 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -179,18 +179,20 @@ std::map Properties::getTagReplacementValues(std::map * } 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 diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index a70cd57b..089bfbe9 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -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 ) diff --git a/source/tools/glexemel/xml2g.c b/source/tools/glexemel/xml2g.c index 39b5345c..9020201f 100644 --- a/source/tools/glexemel/xml2g.c +++ b/source/tools/glexemel/xml2g.c @@ -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));