summaryrefslogtreecommitdiffstats
path: root/src/app/app.cpp
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-05-26 14:50:23 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2013-05-26 14:50:23 +0200
commit8f6fd2a1316432970f1d86515819e7bbe15ddab3 (patch)
tree5852619dfe41c59bb7bf23df2652b7a6d8d3689e /src/app/app.cpp
parentb41957f2f95d8f62817705a1c82322d9463d28a2 (diff)
downloadcolobot-8f6fd2a1316432970f1d86515819e7bbe15ddab3.tar.gz
colobot-8f6fd2a1316432970f1d86515819e7bbe15ddab3.tar.bz2
colobot-8f6fd2a1316432970f1d86515819e7bbe15ddab3.zip
Changes in texture code & refactoring
* refactored and altered slightly the texture pack code * added flushing of texture cache * some refactoring and const-correctness in CApplication methods
Diffstat (limited to 'src/app/app.cpp')
-rw-r--r--src/app/app.cpp154
1 files changed, 89 insertions, 65 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index ed76c69..932e61e 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -146,25 +146,24 @@ CApplication::CApplication()
m_dataPath = COLOBOT_DEFAULT_DATADIR;
m_langPath = COLOBOT_I18N_DIR;
+ m_texPackPath = "";
m_language = LANGUAGE_ENV;
- m_texPack = "";
-
m_lowCPU = true;
for (int i = 0; i < DIR_MAX; ++i)
- m_dataDirs[i] = nullptr;
+ m_standardDataDirs[i] = nullptr;
- m_dataDirs[DIR_AI] = "ai";
- m_dataDirs[DIR_FONT] = "fonts";
- m_dataDirs[DIR_HELP] = "help";
- m_dataDirs[DIR_ICON] = "icons";
- m_dataDirs[DIR_LEVEL] = "levels";
- m_dataDirs[DIR_MODEL] = "models";
- m_dataDirs[DIR_MUSIC] = "music";
- m_dataDirs[DIR_SOUND] = "sounds";
- m_dataDirs[DIR_TEXTURE] = "textures";
+ m_standardDataDirs[DIR_AI] = "ai";
+ m_standardDataDirs[DIR_FONT] = "fonts";
+ m_standardDataDirs[DIR_HELP] = "help";
+ m_standardDataDirs[DIR_ICON] = "icons";
+ m_standardDataDirs[DIR_LEVEL] = "levels";
+ m_standardDataDirs[DIR_MODEL] = "models";
+ m_standardDataDirs[DIR_MUSIC] = "music";
+ m_standardDataDirs[DIR_SOUND] = "sounds";
+ m_standardDataDirs[DIR_TEXTURE] = "textures";
}
CApplication::~CApplication()
@@ -272,7 +271,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl)\n");
GetLogger()->Message(" -langdir path set custom language directory path\n");
GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n");
- GetLogger()->Message(" -texpack name set texture pack\n");
+ GetLogger()->Message(" -texpack path set path to custom texture pack\n");
return PARSE_ARGS_HELP;
}
case OPT_DEBUG:
@@ -286,6 +285,18 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
GetLogger()->Info("Using custom data dir: '%s'\n", m_dataPath.c_str());
break;
}
+ case OPT_LANGDIR:
+ {
+ m_langPath = optarg;
+ GetLogger()->Info("Using custom language dir: '%s'\n", m_langPath.c_str());
+ break;
+ }
+ case OPT_TEXPACK:
+ {
+ m_texPackPath = optarg;
+ GetLogger()->Info("Using texturepack: '%s'\n", m_texPackPath.c_str());
+ break;
+ }
case OPT_LOGLEVEL:
{
LogLevel logLevel;
@@ -312,12 +323,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
m_language = language;
break;
}
- case OPT_LANGDIR:
- {
- m_langPath = optarg;
- GetLogger()->Info("Using custom language dir: '%s'\n", m_langPath.c_str());
- break;
- }
case OPT_VBO:
{
std::string vbo;
@@ -336,12 +341,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
break;
}
- case OPT_TEXPACK:
- {
- m_texPack = optarg;
- GetLogger()->Info("Using texturepack: '%s'\n", m_texPack.c_str());
- break;
- }
default:
assert(false); // should never get here
}
@@ -394,20 +393,27 @@ bool CApplication::Create()
m_sound->Create(true);
// Cache sound files
- if (defaultValues) {
+ if (defaultValues)
+ {
GetProfile().SetLocalProfileString("Resources", "Sound", GetDataSubdirPath(DIR_SOUND));
GetProfile().SetLocalProfileString("Resources", "Music", GetDataSubdirPath(DIR_MUSIC));
}
- if (GetProfile().GetLocalProfileString("Resources", "Sound", path)) {
+ if (GetProfile().GetLocalProfileString("Resources", "Sound", path))
+ {
m_sound->CacheAll(path);
- } else {
+ }
+ else
+ {
m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND));
}
- if (GetProfile().GetLocalProfileString("Resources", "Music", path)) {
+ if (GetProfile().GetLocalProfileString("Resources", "Music", path))
+ {
m_sound->AddMusicFiles(path);
- } else {
+ }
+ else
+ {
m_sound->AddMusicFiles(GetDataSubdirPath(DIR_MUSIC));
}
@@ -496,8 +502,6 @@ bool CApplication::Create()
m_engine->SetDevice(m_device);
- m_engine->SetTexturePack(m_texPack);
-
if (! m_engine->Create() )
{
m_errorMessage = std::string("Error in CEngine::Init()\n") + standardInfoMessage;
@@ -970,12 +974,12 @@ end:
return m_exitCode;
}
-int CApplication::GetExitCode()
+int CApplication::GetExitCode() const
{
return m_exitCode;
}
-const std::string& CApplication::GetErrorMessage()
+const std::string& CApplication::GetErrorMessage() const
{
return m_errorMessage;
}
@@ -1269,7 +1273,7 @@ void CApplication::ResumeSimulation()
GetLogger()->Info("Resume simulation\n");
}
-bool CApplication::GetSimulationSuspended()
+bool CApplication::GetSimulationSuspended() const
{
return m_simulationSuspended;
}
@@ -1327,48 +1331,48 @@ Event CApplication::CreateUpdateEvent()
return frameEvent;
}
-float CApplication::GetSimulationSpeed()
+float CApplication::GetSimulationSpeed() const
{
return m_simulationSpeed;
}
-float CApplication::GetAbsTime()
+float CApplication::GetAbsTime() const
{
return m_absTime;
}
-long long CApplication::GetExactAbsTime()
+long long CApplication::GetExactAbsTime() const
{
return m_exactAbsTime;
}
-long long CApplication::GetRealAbsTime()
+long long CApplication::GetRealAbsTime() const
{
return m_realAbsTime;
}
-float CApplication::GetRelTime()
+float CApplication::GetRelTime() const
{
return m_relTime;
}
-long long CApplication::GetExactRelTime()
+long long CApplication::GetExactRelTime() const
{
return m_exactRelTime;
}
-long long CApplication::GetRealRelTime()
+long long CApplication::GetRealRelTime() const
{
return m_realRelTime;
}
-Gfx::GLDeviceConfig CApplication::GetVideoConfig()
+Gfx::GLDeviceConfig CApplication::GetVideoConfig() const
{
return m_deviceConfig;
}
VideoQueryResult CApplication::GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions,
- bool fullScreen, bool resizeable)
+ bool fullScreen, bool resizeable) const
{
resolutions.clear();
@@ -1415,27 +1419,27 @@ void CApplication::SetDebugMode(bool mode)
m_debugMode = mode;
}
-bool CApplication::GetDebugMode()
+bool CApplication::GetDebugMode() const
{
return m_debugMode;
}
-int CApplication::GetKmods()
+int CApplication::GetKmods() const
{
return m_kmodState;
}
-bool CApplication::GetKmodState(int kmod)
+bool CApplication::GetKmodState(int kmod) const
{
return (m_kmodState & kmod) != 0;
}
-bool CApplication::GetTrackedKeyState(TrackedKey key)
+bool CApplication::GetTrackedKeyState(TrackedKey key) const
{
return (m_trackedKeys & key) != 0;
}
-bool CApplication::GetMouseButtonState(int index)
+bool CApplication::GetMouseButtonState(int index) const
{
return (m_mouseButtonsState & (1<<index)) != 0;
}
@@ -1453,7 +1457,7 @@ void CApplication::SetGrabInput(bool grab)
SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
}
-bool CApplication::GetGrabInput()
+bool CApplication::GetGrabInput() const
{
int result = SDL_WM_GrabInput(SDL_GRAB_QUERY);
return result == SDL_GRAB_ON;
@@ -1468,12 +1472,12 @@ void CApplication::SetMouseMode(MouseMode mode)
SDL_ShowCursor(SDL_DISABLE);
}
-MouseMode CApplication::GetMouseMode()
+MouseMode CApplication::GetMouseMode() const
{
return m_mouseMode;
}
-Math::Point CApplication::GetMousePos()
+Math::Point CApplication::GetMousePos() const
{
return m_mousePos;
}
@@ -1486,7 +1490,7 @@ void CApplication::MoveMouse(Math::Point pos)
SDL_WarpMouse(windowPos.x, windowPos.y);
}
-std::vector<JoystickDevice> CApplication::GetJoystickList()
+std::vector<JoystickDevice> CApplication::GetJoystickList() const
{
std::vector<JoystickDevice> result;
@@ -1503,7 +1507,7 @@ std::vector<JoystickDevice> CApplication::GetJoystickList()
return result;
}
-JoystickDevice CApplication::GetJoystick()
+JoystickDevice CApplication::GetJoystick() const
{
return m_joystick;
}
@@ -1525,36 +1529,37 @@ void CApplication::SetJoystickEnabled(bool enable)
}
}
-bool CApplication::GetJoystickEnabled()
+bool CApplication::GetJoystickEnabled() const
{
return m_joystickEnabled;
}
-std::string CApplication::GetDataDirPath()
+std::string CApplication::GetDataDirPath() const
{
return m_dataPath;
}
-std::string CApplication::GetDataSubdirPath(DataDir stdDir)
+std::string CApplication::GetDataSubdirPath(DataDir stdDir) const
{
int index = static_cast<int>(stdDir);
assert(index >= 0 && index < DIR_MAX);
std::stringstream str;
str << m_dataPath;
str << "/";
- str << m_dataDirs[index];
+ str << m_standardDataDirs[index];
return str.str();
}
-std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& subpath)
+std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& subpath) const
{
int index = static_cast<int>(stdDir);
assert(index >= 0 && index < DIR_MAX);
std::stringstream str;
str << m_dataPath;
str << "/";
- str << m_dataDirs[index];
- if (stdDir == DIR_HELP) {
+ str << m_standardDataDirs[index];
+ if (stdDir == DIR_HELP)
+ {
str << "/";
str << GetLanguageChar();
}
@@ -1563,12 +1568,31 @@ std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& sub
return str.str();
}
-Language CApplication::GetLanguage()
+std::string CApplication::GetTexPackFilePath(const std::string& textureName) const
+{
+ std::stringstream str;
+
+ if (! m_texPackPath.empty())
+ {
+ str << m_texPackPath;
+ str << "/";
+ str << textureName;
+ if (! boost::filesystem::exists(str.str()))
+ {
+ GetLogger()->Trace("Texture '%s' not in texpack\n", textureName.c_str());
+ str.str("");
+ }
+ }
+
+ return str.str();
+}
+
+Language CApplication::GetLanguage() const
{
return m_language;
}
-char CApplication::GetLanguageChar()
+char CApplication::GetLanguageChar() const
{
char langChar = 'E';
switch (m_language)
@@ -1703,7 +1727,7 @@ void CApplication::SetLowCPU(bool low)
m_lowCPU = low;
}
-bool CApplication::GetLowCPU()
+bool CApplication::GetLowCPU() const
{
return m_lowCPU;
}
@@ -1718,7 +1742,7 @@ void CApplication::StopPerformanceCounter(PerformanceCounter counter)
GetSystemUtils()->GetCurrentTimeStamp(m_performanceCounters[counter][1]);
}
-float CApplication::GetPerformanceCounterData(PerformanceCounter counter)
+float CApplication::GetPerformanceCounterData(PerformanceCounter counter) const
{
return m_performanceCountersData[counter];
}