Normalize static variables and functions

* get rid of some of them
 * put the rest into anonymous namespaces
master
Piotr Dziwinski 2015-08-06 10:12:20 +02:00
parent bdeeaf690b
commit 596bb49de0
13 changed files with 118 additions and 98 deletions

View File

@ -62,6 +62,7 @@ if(OPENAL_SOUND)
sound/oalsound/alsound.cpp sound/oalsound/alsound.cpp
sound/oalsound/buffer.cpp sound/oalsound/buffer.cpp
sound/oalsound/channel.cpp sound/oalsound/channel.cpp
sound/oalsound/check.cpp
) )
endif() endif()

View File

@ -61,8 +61,7 @@
template<> CApplication* CSingleton<CApplication>::m_instance = nullptr; template<> CApplication* CSingleton<CApplication>::m_instance = nullptr;
//! Static buffer for putenv locale char CApplication::m_languageLocale[] = { 0 };
static char S_LANGUAGE[50] = { 0 };
//! Interval of timer called to update joystick state //! Interval of timer called to update joystick state
@ -1699,8 +1698,8 @@ void CApplication::SetLanguage(Language language)
{ {
std::string langStr = "LANGUAGE="; std::string langStr = "LANGUAGE=";
langStr += locale; langStr += locale;
strcpy(S_LANGUAGE, langStr.c_str()); strcpy(m_languageLocale, langStr.c_str());
putenv(S_LANGUAGE); putenv(m_languageLocale);
GetLogger()->Trace("SetLanguage: Set LANGUAGE=%s in environment\n", locale.c_str()); GetLogger()->Trace("SetLanguage: Set LANGUAGE=%s in environment\n", locale.c_str());
} }

View File

@ -455,4 +455,7 @@ protected:
//! Headles mode //! Headles mode
bool m_headless; bool m_headless;
//! Static buffer for putenv locale
static char m_languageLocale[50];
}; };

View File

@ -36,12 +36,41 @@ template<> CInput* CSingleton<CInput>::m_instance = nullptr;
CInput::CInput() CInput::CInput()
{ {
m_keyTable =
{
{ INPUT_SLOT_LEFT, "left" },
{ INPUT_SLOT_RIGHT, "right" },
{ INPUT_SLOT_UP, "up" },
{ INPUT_SLOT_DOWN, "down" },
{ INPUT_SLOT_GUP, "gup" },
{ INPUT_SLOT_GDOWN, "gdown" },
{ INPUT_SLOT_CAMERA, "camera" },
{ INPUT_SLOT_DESEL, "desel" },
{ INPUT_SLOT_ACTION, "action" },
{ INPUT_SLOT_NEAR, "near" },
{ INPUT_SLOT_AWAY, "away" },
{ INPUT_SLOT_NEXT, "next" },
{ INPUT_SLOT_HUMAN, "human" },
{ INPUT_SLOT_QUIT, "quit" },
{ INPUT_SLOT_HELP, "help" },
{ INPUT_SLOT_PROG, "prog" },
{ INPUT_SLOT_VISIT, "visit" },
{ INPUT_SLOT_SPEED05, "speed05" },
{ INPUT_SLOT_SPEED10, "speed10" },
{ INPUT_SLOT_SPEED15, "speed15" },
{ INPUT_SLOT_SPEED20, "speed20" },
{ INPUT_SLOT_SPEED30, "speed30" },
{ INPUT_SLOT_SPEED40, "speed40" },
{ INPUT_SLOT_SPEED60, "speed60" },
{ INPUT_SLOT_CAMERA_UP, "camup" },
{ INPUT_SLOT_CAMERA_DOWN, "camdown" },
{ INPUT_SLOT_PAUSE, "pause" },
};
m_kmodState = 0; m_kmodState = 0;
m_mousePos = Math::Point(); m_mousePos = Math::Point();
m_mouseButtonsState = 0; m_mouseButtonsState = 0;
std::fill_n(m_keyPresses, INPUT_SLOT_MAX, false);
for(int i=0; i<INPUT_SLOT_MAX; i++)
m_keyPresses[i] = false;
m_joystickDeadzone = 0.2f; m_joystickDeadzone = 0.2f;
SetDefaultInputBindings(); SetDefaultInputBindings();
@ -271,37 +300,6 @@ InputSlot CInput::FindBinding(unsigned int key)
return INPUT_SLOT_MAX; return INPUT_SLOT_MAX;
} }
static std::map<InputSlot, std::string> keyTable =
{
{ INPUT_SLOT_LEFT, "left" },
{ INPUT_SLOT_RIGHT, "right" },
{ INPUT_SLOT_UP, "up" },
{ INPUT_SLOT_DOWN, "down" },
{ INPUT_SLOT_GUP, "gup" },
{ INPUT_SLOT_GDOWN, "gdown" },
{ INPUT_SLOT_CAMERA, "camera" },
{ INPUT_SLOT_DESEL, "desel" },
{ INPUT_SLOT_ACTION, "action" },
{ INPUT_SLOT_NEAR, "near" },
{ INPUT_SLOT_AWAY, "away" },
{ INPUT_SLOT_NEXT, "next" },
{ INPUT_SLOT_HUMAN, "human" },
{ INPUT_SLOT_QUIT, "quit" },
{ INPUT_SLOT_HELP, "help" },
{ INPUT_SLOT_PROG, "prog" },
{ INPUT_SLOT_VISIT, "visit" },
{ INPUT_SLOT_SPEED05, "speed05" },
{ INPUT_SLOT_SPEED10, "speed10" },
{ INPUT_SLOT_SPEED15, "speed15" },
{ INPUT_SLOT_SPEED20, "speed20" },
{ INPUT_SLOT_SPEED30, "speed30" },
{ INPUT_SLOT_SPEED40, "speed40" },
{ INPUT_SLOT_SPEED60, "speed60" },
{ INPUT_SLOT_CAMERA_UP, "camup" },
{ INPUT_SLOT_CAMERA_DOWN, "camdown" },
{ INPUT_SLOT_PAUSE, "pause" },
};
void CInput::SaveKeyBindings() void CInput::SaveKeyBindings()
{ {
std::stringstream key; std::stringstream key;
@ -313,7 +311,7 @@ void CInput::SaveKeyBindings()
key.str(""); key.str("");
key << b.primary << " " << b.secondary; key << b.primary << " " << b.secondary;
CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", keyTable[static_cast<InputSlot>(i)], key.str()); CConfigFile::GetInstancePointer()->SetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], key.str());
} }
for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++) for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++)
@ -334,7 +332,7 @@ void CInput::LoadKeyBindings()
{ {
InputBinding b; InputBinding b;
if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", keyTable[static_cast<InputSlot>(i)], keys)) if (!CConfigFile::GetInstancePointer()->GetStringProperty("Keybindings", m_keyTable[static_cast<InputSlot>(i)], keys))
continue; continue;
skey.clear(); skey.clear();
skey.str(keys); skey.str(keys);
@ -365,7 +363,7 @@ void CInput::LoadKeyBindings()
InputSlot CInput::SearchKeyById(std::string id) InputSlot CInput::SearchKeyById(std::string id)
{ {
for(auto& key : keyTable) for(auto& key : m_keyTable)
{ {
if ( id == key.second ) if ( id == key.second )
{ {

View File

@ -30,7 +30,7 @@
#include "math/intpoint.h" #include "math/intpoint.h"
#include <map>
/** /**
* \struct InputBinding * \struct InputBinding
@ -159,4 +159,6 @@ private:
InputBinding m_inputBindings[INPUT_SLOT_MAX]; InputBinding m_inputBindings[INPUT_SLOT_MAX];
JoyAxisBinding m_joyAxisBindings[JOY_AXIS_SLOT_MAX]; JoyAxisBinding m_joyAxisBindings[JOY_AXIS_SLOT_MAX];
float m_joystickDeadzone; float m_joystickDeadzone;
std::map<InputSlot, std::string> m_keyTable;
}; };

View File

@ -26,15 +26,15 @@
namespace namespace
{ {
static EventType UNIQUE_EVENT_TYPE = EVENT_USER;
const char* EVENT_TYPE_TEXT[EVENT_STD_MAX]; const char* EVENT_TYPE_TEXT[EVENT_STD_MAX];
} }
EventType GetUniqueEventType() EventType GetUniqueEventType()
{ {
int i = static_cast<int>(UNIQUE_EVENT_TYPE+1); static EventType uniqueEventType = EVENT_USER;
UNIQUE_EVENT_TYPE = static_cast<EventType>(i); int nextUniqueEventType = static_cast<int>(uniqueEventType+1);
return UNIQUE_EVENT_TYPE; uniqueEventType = static_cast<EventType>(nextUniqueEventType);
return uniqueEventType;
} }
void InitializeEventTypeTexts() void InitializeEventTypeTexts()

View File

@ -761,8 +761,10 @@ void InitializeRestext()
} }
namespace
static char g_gamerName[100]; {
char g_gamerName[100];
} // anonymous namespace
void SetGlobalGamerName(std::string name) void SetGlobalGamerName(std::string name)
{ {
@ -771,7 +773,10 @@ void SetGlobalGamerName(std::string name)
// Replaces the commands "\key name;" in a text. // Replaces the commands "\key name;" in a text.
static void PutKeyName(std::string& dst, const char* src) namespace
{
void PutKeyName(std::string& dst, const char* src)
{ {
dst.clear(); dst.clear();
@ -801,7 +806,7 @@ static void PutKeyName(std::string& dst, const char* src)
// Returns the translated text of a resource that needs key substitution // Returns the translated text of a resource that needs key substitution
static const char* GetResourceBase(ResType type, unsigned int num) const char* GetResourceBase(ResType type, unsigned int num)
{ {
const char *str = NULL; const char *str = NULL;
@ -846,6 +851,8 @@ static const char* GetResourceBase(ResType type, unsigned int num)
return gettext(str); return gettext(str);
} }
} // anonymous namespace
// Returns the text of a resource. // Returns the text of a resource.
bool GetResource(ResType type, unsigned int num, std::string& text) bool GetResource(ResType type, unsigned int num, std::string& text)

View File

@ -25,7 +25,10 @@
#include <vector> #include <vector>
static std::string VFormat(const char *fmt, va_list ap) namespace
{
std::string VFormat(const char *fmt, va_list ap)
{ {
size_t size = 1024; size_t size = 1024;
char stackbuf[1024]; char stackbuf[1024];
@ -47,6 +50,8 @@ static std::string VFormat(const char *fmt, va_list ap)
} }
} }
} // anonymous namespace
std::string StrUtils::Format(const char *fmt, ...) std::string StrUtils::Format(const char *fmt, ...)
{ {
va_list ap; va_list ap;

View File

@ -40,8 +40,8 @@ Buffer::~Buffer()
if (m_loaded) if (m_loaded)
{ {
alDeleteBuffers(1, &m_buffer); alDeleteBuffers(1, &m_buffer);
if (alCheck()) if (CheckOpenALError())
GetLogger()->Debug("Failed to unload buffer. Code %d\n", alGetCode()); GetLogger()->Debug("Failed to unload buffer. Code %d\n", GetOpenALErrorCode());
} }
} }

View File

@ -35,9 +35,9 @@ Channel::Channel()
{ {
alGenSources(1, &m_source); alGenSources(1, &m_source);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Failed to create sound source. Code: %d\n", alGetCode()); GetLogger()->Debug("Failed to create sound source. Code: %d\n", GetOpenALErrorCode());
m_ready = false; m_ready = false;
} }
else else
@ -54,8 +54,8 @@ Channel::~Channel()
alSourceStop(m_source); alSourceStop(m_source);
alSourcei(m_source, AL_BUFFER, 0); alSourcei(m_source, AL_BUFFER, 0);
alDeleteSources(1, &m_source); alDeleteSources(1, &m_source);
if (alCheck()) if (CheckOpenALError())
GetLogger()->Debug("Failed to delete sound source. Code: %d\n", alGetCode()); GetLogger()->Debug("Failed to delete sound source. Code: %d\n", GetOpenALErrorCode());
} }
} }
@ -71,9 +71,9 @@ bool Channel::Play()
alSourcei(m_source, AL_REFERENCE_DISTANCE, 10.0f); alSourcei(m_source, AL_REFERENCE_DISTANCE, 10.0f);
alSourcei(m_source, AL_MAX_DISTANCE, 110.0f); alSourcei(m_source, AL_MAX_DISTANCE, 110.0f);
alSourcePlay(m_source); alSourcePlay(m_source);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Could not play audio sound source. Code: %d\n", alGetCode()); GetLogger()->Debug("Could not play audio sound source. Code: %d\n", GetOpenALErrorCode());
} }
return true; return true;
} }
@ -86,9 +86,9 @@ bool Channel::Pause()
} }
alSourcePause(m_source); alSourcePause(m_source);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Could not pause audio sound source. Code: %d\n", alGetCode()); GetLogger()->Debug("Could not pause audio sound source. Code: %d\n", GetOpenALErrorCode());
} }
return true; return true;
} }
@ -102,9 +102,9 @@ bool Channel::SetPosition(const Math::Vector &pos)
} }
alSource3f(m_source, AL_POSITION, pos.x, pos.y, pos.z); alSource3f(m_source, AL_POSITION, pos.x, pos.y, pos.z);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Could not set sound position. Code: %d\n", alGetCode()); GetLogger()->Debug("Could not set sound position. Code: %d\n", GetOpenALErrorCode());
return false; return false;
} }
return true; return true;
@ -119,9 +119,9 @@ bool Channel::SetFrequency(float freq)
} }
alSourcef(m_source, AL_PITCH, freq); alSourcef(m_source, AL_PITCH, freq);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Could not set sound pitch to '%f'. Code: %d\n", freq, alGetCode()); GetLogger()->Debug("Could not set sound pitch to '%f'. Code: %d\n", freq, GetOpenALErrorCode());
return false; return false;
} }
return true; return true;
@ -137,9 +137,9 @@ float Channel::GetFrequency()
} }
alGetSourcef(m_source, AL_PITCH, &freq); alGetSourcef(m_source, AL_PITCH, &freq);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Could not get sound pitch. Code: %d\n", alGetCode()); GetLogger()->Debug("Could not get sound pitch. Code: %d\n", GetOpenALErrorCode());
return 0; return 0;
} }
@ -155,9 +155,9 @@ bool Channel::SetVolume(float vol)
} }
alSourcef(m_source, AL_GAIN, vol); alSourcef(m_source, AL_GAIN, vol);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode()); GetLogger()->Debug("Could not set sound volume to '%f'. Code: %d\n", vol, GetOpenALErrorCode());
return false; return false;
} }
return true; return true;
@ -173,9 +173,9 @@ float Channel::GetVolume()
} }
alGetSourcef(m_source, AL_GAIN, &vol); alGetSourcef(m_source, AL_GAIN, &vol);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Could not get sound volume. Code: %d\n", alGetCode()); GetLogger()->Debug("Could not get sound volume. Code: %d\n", GetOpenALErrorCode());
return 0; return 0;
} }
@ -287,9 +287,9 @@ bool Channel::SetBuffer(Buffer *buffer)
} }
alSourcei(m_source, AL_BUFFER, buffer->GetBuffer()); alSourcei(m_source, AL_BUFFER, buffer->GetBuffer());
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Warn("Could not set sound buffer. Code: %d\n", alGetCode()); GetLogger()->Warn("Could not set sound buffer. Code: %d\n", GetOpenALErrorCode());
return false; return false;
} }
m_initFrequency = GetFrequency(); m_initFrequency = GetFrequency();
@ -305,9 +305,9 @@ bool Channel::IsPlaying()
} }
alGetSourcei(m_source, AL_SOURCE_STATE, &status); alGetSourcei(m_source, AL_SOURCE_STATE, &status);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Warn("Could not get sound status. Code: %d\n", alGetCode()); GetLogger()->Warn("Could not get sound status. Code: %d\n", GetOpenALErrorCode());
return false; return false;
} }
@ -334,9 +334,9 @@ bool Channel::Stop()
} }
alSourceStop(m_source); alSourceStop(m_source);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Warn("Could not stop sound. Code: %d\n", alGetCode()); GetLogger()->Warn("Could not stop sound. Code: %d\n", GetOpenALErrorCode());
return false; return false;
} }
return true; return true;
@ -352,9 +352,9 @@ float Channel::GetCurrentTime()
ALfloat current; ALfloat current;
alGetSourcef(m_source, AL_SEC_OFFSET, &current); alGetSourcef(m_source, AL_SEC_OFFSET, &current);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode()); GetLogger()->Warn("Could not get source current play time. Code: %d\n", GetOpenALErrorCode());
return 0.0f; return 0.0f;
} }
return current; return current;
@ -369,9 +369,9 @@ void Channel::SetCurrentTime(float current)
} }
alSourcef(m_source, AL_SEC_OFFSET, current); alSourcef(m_source, AL_SEC_OFFSET, current);
if (alCheck()) if (CheckOpenALError())
{ {
GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode()); GetLogger()->Warn("Could not get source current play time. Code: %d\n", GetOpenALErrorCode());
} }
} }

View File

@ -0,0 +1,19 @@
#include "sound/oalsound/check.h"
namespace
{
ALenum g_errorCode = AL_NO_ERROR;
} // anonymous namespace
bool CheckOpenALError()
{
g_errorCode = alGetError();
return g_errorCode != AL_NO_ERROR;
}
ALenum GetOpenALErrorCode()
{
ALenum ret = g_errorCode;
g_errorCode = AL_NO_ERROR;
return ret;
}

View File

@ -24,20 +24,6 @@
#include "common/logger.h" #include "common/logger.h"
#include <al.h> #include <al.h>
#include <alc.h>
static ALenum CODE = AL_NO_ERROR;
inline bool alCheck()
{
CODE = alGetError();
return CODE != AL_NO_ERROR;
}
inline ALenum alGetCode()
{
ALenum ret = CODE;
CODE = AL_NO_ERROR;
return ret;
}
bool CheckOpenALError();
ALenum GetOpenALErrorCode();

View File

@ -36,7 +36,7 @@
namespace Ui namespace Ui
{ {
static int PERSO_COLOR[3*10*3] = const int PERSO_COLOR[3*10*3] =
{ {
// hair: // hair:
193, 221, 226, // white 193, 221, 226, // white