einstein/cpp-source/main.cpp

113 lines
2.6 KiB
C++
Raw Permalink Normal View History

2013-09-21 21:05:25 +00:00
#include <stdlib.h>
#include <iostream>
#include <SDL.h>
#include <SDL_main.h>
#include <SDL_ttf.h>
#include "main.h"
#include "utils.h"
#include "storage.h"
#include "unicode.h"
#include "messages.h"
#include "sound.h"
Screen screen;
Random rndGen;
static void initScreen()
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
2015-10-04 12:07:19 +00:00
throw Exception(std::wstring(L"Error initializing SDL: ") +
2013-09-21 21:05:25 +00:00
fromMbcs(SDL_GetError()));
atexit(SDL_Quit);
if (TTF_Init())
throw Exception(L"Error initializing font engine");
2015-10-04 12:07:19 +00:00
screen.setMode(VideoMode(800, 600, 24,
2013-09-21 21:05:25 +00:00
getStorage()->get(L"fullscreen", 1) != 0));
screen.initCursors();
2015-10-04 12:07:19 +00:00
2013-09-21 21:05:25 +00:00
SDL_Surface *mouse = loadImage(L"cursor.bmp");
SDL_SetColorKey(mouse, SDL_SRCCOLORKEY, SDL_MapRGB(mouse->format, 0, 0, 0));
screen.setMouseImage(mouse);
SDL_FreeSurface(mouse);
SDL_WM_SetCaption("Einstein", NULL);
#ifdef __APPLE__
screen.setCursor(false);
#else
screen.setCursor(getStorage()->get(L"niceCursor", 1));
#endif
}
static void initAudio()
{
sound = new Sound();
sound->setVolume((float)getStorage()->get(L"volume", 20) / 100.0f);
}
#ifdef __APPLE__
static std::wstring getResourcesPath(const std::wstring& path)
{
int idx = path.find_last_of(L'/');
2015-10-04 12:07:19 +00:00
return path.substr(0, idx) + L"/../../";
2013-09-21 21:05:25 +00:00
}
#endif
static void loadResources(const std::wstring &selfPath)
{
StringList dirs;
#ifdef WIN32
2015-10-04 12:07:19 +00:00
dirs.push_back(getStorage()->get(L"path", L"") + L"\\res");
2013-09-21 21:05:25 +00:00
#else
#ifdef __APPLE__
dirs.push_back(getResourcesPath(selfPath));
#else
dirs.push_back(PREFIX L"/share/einstein/res");
dirs.push_back(fromMbcs(getenv("HOME")) + L"/.einstein/res");
#endif
#endif
dirs.push_back(L"res");
dirs.push_back(L".");
resources = new ResourcesCollection(dirs);
msg.load();
}
/*static void checkBetaExpire()
{
if (1124832535L + 60L*60L*24L*40L < time(NULL)) {
Font font(L"laudcn2.ttf", 16);
Area area;
2015-10-04 12:07:19 +00:00
showMessageWindow(&area, L"darkpattern.bmp",
700, 100, &font, 255,255,255,
2013-09-21 21:05:25 +00:00
msg(L"expired"));
}
}*/
int main(int argc, char *argv[])
{
#ifndef WIN32
ensureDirExists(fromMbcs(getenv("HOME")) + std::wstring(L"/.einstein"));
#endif
2015-10-04 12:07:19 +00:00
2013-09-21 21:05:25 +00:00
try {
loadResources(fromUtf8(argv[0]));
initScreen();
initAudio();
// checkBetaExpire();
menu();
getStorage()->flush();
} catch (Exception &e) {
std::cerr << L"ERROR: " << e.getMessage() << std::endl;
} catch (...) {
std::cerr << L"ERROR: Unknown exception" << std::endl;
}
screen.doneCursors();
2015-10-04 12:07:19 +00:00
2013-09-21 21:05:25 +00:00
return 0;
}