-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.cpp
More file actions
141 lines (124 loc) · 5.07 KB
/
main.cpp
File metadata and controls
141 lines (124 loc) · 5.07 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*************************************************************************/
/* godot_x11.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
// included first since os_x11.h pulls in xlib with it's stupid #define Bool
#include <QCoreApplication>
#include <qlogging.h>
#include "core/version.h"
#include "main/main_class.h"
#include "core/os/os.h"
#include "EASTL/unique_ptr.h"
#include <climits>
#include <clocale>
#include <cstdlib>
#include <QDir>
#include <QDebug>
#ifdef Q_OS_WIN32
#include <windows.h>
static HINSTANCE godot_hinstance = nullptr;
#else
static void *godot_hinstance = nullptr;
#endif
#ifdef Q_OS_WIN32
// For export templates, add a section; the exporter will patch it to enclose
// the data appended to the executable (bundled PCK)
#ifndef TOOLS_ENABLED
#if defined _MSC_VER
#pragma section("pck", read)
__declspec(allocate("pck")) static char dummy[8] = { 0 };
#elif defined __GNUC__
static const char dummy[8] __attribute__((section("pck"), used)) = { 0 };
#endif
#endif
#endif
#define WRAP_QT_MESSAGES
#ifdef WRAP_QT_MESSAGES
/* NOTE: enable this to set breakpoints on qdebug messages. */
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &lMessage)
{
//(%1:%2, %3): %4").arg(context.file).arg(context.line).arg(context.function)
QString text;
switch (type)
{
case QtDebugMsg:
text = QString("Qt::Debug : %4").arg(lMessage.constData());
break;
case QtInfoMsg:
text = QString("Qt::Debug : %4").arg(lMessage.constData());
break;
case QtWarningMsg:
text = QString("Qt::Warning : %4").arg(lMessage.constData());
break;
case QtCriticalMsg:
text = QString("Qt::Critical : %4").arg(lMessage.constData());
break;
case QtFatalMsg:
text = QString("Qt::Fatal : %4").arg(lMessage.constData());
abort();
}
QByteArray az = text.toUtf8();
printf("%s\n",az.data());
}
#endif
int mainT(int argc, char *argv[]) {
#ifdef WRAP_QT_MESSAGES
qInstallMessageHandler(myMessageOutput);
#endif
QCoreApplication app(argc,argv);
QCoreApplication::setApplicationName(VERSION_SHORT_NAME);
QCoreApplication::setApplicationVersion(VERSION_BRANCH);
//TODO: Re-enable this one day - QCoreApplication::setOrganizationName("Segs");
eastl::unique_ptr<OS> os(instantiateOS(godot_hinstance));
setlocale(LC_CTYPE, "");
QString cwd = QDir::currentPath();
qDebug() << "EXECUTABLE CWD:"<<cwd;
Error err = Main::setup();
if (err != OK) {
return 255;
}
if (Main::start())
os->run(); // it is actually the OS that decides how to run
Main::cleanup();
if (!QDir::setCurrent(cwd)) {
ERR_PRINT("Couldn't return to previous working directory.");
}
return os->get_exit_code();
}
int main(int argc, char *argv[]) {
#ifdef CRASH_HANDLER_EXCEPTION
godot_hinstance = GetModuleHandle(nullptr);
__try {
return mainT<OS_Windows>(argc,argv);
} __except (CrashHandlerException(GetExceptionInformation())) {
return 1;
}
#else
return mainT(argc,argv);
#endif
}