summaryrefslogtreecommitdiffstats
path: root/src/app/app.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/app.cpp')
-rw-r--r--src/app/app.cpp64
1 files changed, 34 insertions, 30 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 751ff21..118e100 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -15,6 +15,7 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
+#include "common/config.h"
#include "app/app.h"
@@ -29,17 +30,21 @@
#include "object/robotmain.h"
+#include <boost/filesystem.hpp>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
-#include <fstream>
-
#include <stdlib.h>
#include <libintl.h>
#include <unistd.h>
+#ifdef OPENAL_SOUND
+ #include "sound/oalsound/alsound.h"
+#endif
+
+
template<> CApplication* CSingleton<CApplication>::mInstance = nullptr;
//! Static buffer for putenv locale
@@ -89,7 +94,6 @@ CApplication::CApplication()
m_private = new ApplicationPrivate();
m_iMan = new CInstanceManager();
m_eventQueue = new CEventQueue(m_iMan);
- m_pluginManager = new CPluginManager();
m_profile = new CProfile();
m_engine = nullptr;
@@ -130,7 +134,7 @@ CApplication::CApplication()
m_mouseButtonsState = 0;
m_trackedKeys = 0;
- m_dataPath = "./data";
+ m_dataPath = COLOBOT_DEFAULT_DATADIR;
m_language = LANGUAGE_ENV;
@@ -142,7 +146,6 @@ CApplication::CApplication()
m_dataDirs[DIR_AI] = "ai";
m_dataDirs[DIR_FONT] = "fonts";
m_dataDirs[DIR_HELP] = "help";
- m_dataDirs[DIR_I18N] = "i18n";
m_dataDirs[DIR_ICON] = "icons";
m_dataDirs[DIR_LEVEL] = "levels";
m_dataDirs[DIR_MODEL] = "models";
@@ -159,9 +162,6 @@ CApplication::~CApplication()
delete m_eventQueue;
m_eventQueue = nullptr;
- delete m_pluginManager;
- m_pluginManager = nullptr;
-
delete m_profile;
m_profile = nullptr;
@@ -274,13 +274,10 @@ bool CApplication::Create()
{
GetLogger()->Info("Creating CApplication\n");
- // I know, a primitive way to check for dir, but works
- std::string readmePath = m_dataPath + "/README.txt";
- std::ifstream testReadme;
- testReadme.open(readmePath.c_str(), std::ios_base::in);
- if (!testReadme.good())
+ boost::filesystem::path dataPath(m_dataPath);
+ if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) )
{
- GetLogger()->Error("Could not open test file in data dir: '%s'\n", readmePath.c_str());
+ GetLogger()->Error("Data directory '%s' doesn't exist or is not a directory\n", m_dataPath.c_str());
m_errorMessage = std::string("Could not read from data directory:\n") +
std::string("'") + m_dataPath + std::string("'\n") +
std::string("Please check your installation, or supply a valid data directory by -datadir option.");
@@ -319,19 +316,15 @@ bool CApplication::Create()
langStr += locale;
strcpy(S_LANGUAGE, langStr.c_str());
putenv(S_LANGUAGE);
- setlocale(LC_ALL, "");
+ setlocale(LC_ALL, locale.c_str());
GetLogger()->Debug("Set locale to '%s'\n", locale.c_str());
- std::string trPath = m_dataPath + "/" + m_dataDirs[DIR_I18N];
- bindtextdomain("colobot", trPath.c_str());
+ bindtextdomain("colobot", COLOBOT_I18N_DIR);
bind_textdomain_codeset("colobot", "UTF-8");
textdomain("colobot");
GetLogger()->Debug("Testing gettext translation: '%s'\n", gettext("Colobot rules!"));
- // Temporarily -- only in windowed mode
- m_deviceConfig.fullScreen = false;
-
//Create the sound instance.
if (!GetProfile().InitCurrentDirectory()) {
GetLogger()->Warn("Config not found. Default values will be used!\n");
@@ -341,13 +334,12 @@ bool CApplication::Create()
if (GetProfile().GetLocalProfileString("Resources", "Data", path))
m_dataPath = path;
- m_pluginManager->LoadFromProfile();
- m_sound = static_cast<CSoundInterface*>(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_SOUND));
-
- if (!m_sound) {
- GetLogger()->Error("Sound not loaded, falling back to fake sound!\n");
- m_sound = new CSoundInterface();
- }
+ #ifdef OPENAL_SOUND
+ m_sound = static_cast<CSoundInterface *>(new ALSound());
+ #else
+ GetLogger()->Info("No sound support.\n");
+ m_sound = new CSoundInterface();
+ #endif
m_sound->Create(true);
if (GetProfile().GetLocalProfileString("Resources", "Sound", path))
@@ -388,7 +380,20 @@ bool CApplication::Create()
m_exitCode = 3;
return false;
}
-
+
+ // load settings from profile
+ int iValue;
+ if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) ) {
+ std::vector<Math::IntPoint> modes;
+ GetVideoResolutionList(modes, true, true);
+ if (static_cast<unsigned int>(iValue) < modes.size())
+ m_deviceConfig.size = modes.at(iValue);
+ }
+
+ if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) ) {
+ m_deviceConfig.fullScreen = (iValue == 1);
+ }
+
if (! CreateVideoSurface())
return false; // dialog is in function
@@ -408,8 +413,7 @@ bool CApplication::Create()
// Don't generate joystick events
SDL_JoystickEventState(SDL_IGNORE);
-
-
+
// The video is ready, we can create and initalize the graphics device
m_device = new Gfx::CGLDevice(m_deviceConfig);
if (! m_device->Create() )