-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
118 lines (96 loc) · 3.26 KB
/
main.cpp
File metadata and controls
118 lines (96 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <QtGui>
#include "gamewidget.h"
#include "gamestock.h"
#include "gameprofile.h"
#include "defines.h"
#include "displaywrapper.h"
#include "scaler.h"
#ifdef Q_OS_WIN32
#include "SDL.h"
#include "SDL_mixer.h"
#else
#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"
#endif
#undef main
int main(int argc, char *argv[])
{
//QApplication::setGraphicsSystem("opengl");
QApplication::setGraphicsSystem("raster");
QApplication a(argc, argv);
// resources
QString resourcePath = a.applicationDirPath();
resourcePath.chop(3);
resourcePath += "data/"; // bin -> data
// on X11, we'll check if data directory exists locally first
#ifdef Q_WS_X11
if (!QDir(resourcePath).exists())
resourcePath = "/usr/share/chains/data/";
#endif
if (!QDir(resourcePath).exists()) {
QMessageBox::critical(0, QString("Files are missing"),
QString("Cannot find data folder<br><b>%1</b><br>%2 will exit now.")
.arg(resourcePath, GameName),
QMessageBox::Close);
a.quit();
return -1;
}
// display wrapper
DisplayWrapper::init();
// SDL sound initialization
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
qDebug() << "Unable to initialize SDL: " << SDL_GetError();
//fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
return -1;
}
// settings of audio (could be changed)
int audio_rate = 22050;
Uint16 audio_format = MIX_DEFAULT_FORMAT;
int audio_channels = 2;
int audio_buffers = 1024;
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
qDebug() << "Unable to initialize audio: " << Mix_GetError();
//fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError());
return -1;
}
// prioritize thread
QThread::currentThread()->setPriority(QThread::HighPriority);
// scaler initialization
Scaler::init();
// translation
QSettings settings("xlabsoft","chains");
QString lang = settings.value("Language", "").toString();
QTranslator translator;
if (!lang.isEmpty()) {
QString langpath = resourcePath + "lang/";
QString filename = langpath + "chains_" + lang + ".qm";
//QMessageBox::about(0, "", filename);
if (!langpath.isEmpty() && QFile::exists(filename)) {
translator.load(filename);
a.installTranslator(&translator);
}
}
// set stylesheet
QString stylepath = ":/style/style.css";
//#ifdef Q_OS_WIN
// if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA)
// stylepath = ":/style/style_vista.css";
//#endif
QString style = "";
QFile f(stylepath);
if (f.open(QIODevice::ReadOnly)) {
QTextStream ts(&f);
style = ts.readAll().simplified();
f.close();
}
qApp->setStyleSheet(style);
// main widget & startup
GameWidget w(resourcePath);
int result = a.exec();
// deinitialization of SDL
Mix_CloseAudio();
SDL_Quit();
// deinitialization of DisplayWrapper
DisplayWrapper::restoreVideoMode();
return result;
}