1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/apps/opencs/main.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
2.3 KiB
C++
Raw Normal View History

2012-11-22 12:30:02 +00:00
#include "editor.hpp"
2012-12-04 19:43:47 +00:00
#include <exception>
2014-05-03 11:01:29 +00:00
#include <string>
2012-12-04 19:43:47 +00:00
#include <QApplication>
2013-02-17 13:46:50 +00:00
#include <QIcon>
#include <QSurfaceFormat>
#include <osg/DisplaySettings>
2012-11-22 12:30:02 +00:00
#include <components/debug/debugging.hpp>
2022-10-19 17:02:00 +00:00
#include <components/debug/debuglog.hpp>
#include <components/platform/platform.hpp>
#include "model/doc/messages.hpp"
#include "model/world/universalid.hpp"
#ifdef Q_OS_MAC
#include <QDir>
#endif
2014-05-03 11:01:29 +00:00
Q_DECLARE_METATYPE(std::string)
2022-10-19 17:02:00 +00:00
class QEvent;
class QObject;
2012-12-04 19:43:47 +00:00
class Application : public QApplication
{
private:
bool notify(QObject* receiver, QEvent* event) override
2022-09-22 18:26:05 +00:00
{
try
2022-09-22 18:26:05 +00:00
{
2012-12-04 19:43:47 +00:00
return QApplication::notify(receiver, event);
2022-09-22 18:26:05 +00:00
}
catch (const std::exception& exception)
2012-12-04 19:43:47 +00:00
{
2018-08-14 16:01:09 +00:00
Log(Debug::Error) << "An exception has been caught: " << exception.what();
2012-12-04 19:43:47 +00:00
}
return false;
2022-09-22 18:26:05 +00:00
}
2012-12-04 19:43:47 +00:00
public:
Application(int& argc, char* argv[])
: QApplication(argc, argv)
{
}
};
void setQSurfaceFormat()
{
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setVersion(2, 1);
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setDepthBufferSize(24);
format.setSamples(ds->getMultiSamples());
format.setStencilBufferSize(ds->getMinimumNumStencilBits());
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
QSurfaceFormat::setDefaultFormat(format);
}
int runApplication(int argc, char* argv[])
2012-11-21 16:31:18 +00:00
{
Platform::init();
#ifdef Q_OS_MAC
setenv("OSG_GL_TEXTURE_STORAGE", "OFF", 0);
#endif
Q_INIT_RESOURCE(resources);
2013-11-02 01:48:30 +00:00
qRegisterMetaType<std::string>("std::string");
qRegisterMetaType<CSMWorld::UniversalId>("CSMWorld::UniversalId");
qRegisterMetaType<CSMDoc::Message>("CSMDoc::Message");
2014-05-03 11:01:29 +00:00
setQSurfaceFormat();
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
Application application(argc, argv);
2012-11-22 12:30:02 +00:00
application.setWindowIcon(QIcon(":./openmw-cs.png"));
2013-02-17 13:46:50 +00:00
CS::Editor editor(argc, argv);
#ifdef __linux__
setlocale(LC_NUMERIC, "C");
#endif
2012-11-21 16:31:18 +00:00
if (!editor.makeIPCServer())
{
editor.connectToIPCServer();
return 0;
}
return editor.run();
}
int main(int argc, char* argv[])
{
return wrapApplication(&runApplication, argc, argv, "OpenMW-CS");
2013-02-17 13:46:50 +00:00
}