Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / panoply_preview / tool_main.cpp
bloba84bf61f1994a1a1498566e175589cbef69d7cc3
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2014-2016 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <nel/misc/types_nl.h>
18 #include "tool_main.h"
20 // STL includes
21 #include <stdio.h>
22 #ifdef NL_OS_WINDOWS
23 # include <windows.h>
24 # include <direct.h>
25 # include <tchar.h>
26 #endif
28 // Qt includes
29 #include <qglobal.h>
31 #ifdef Q_COMPILER_RVALUE_REFS
32 #undef Q_COMPILER_RVALUE_REFS
33 #endif
35 #include <QApplication>
36 #include <QtCore/QMap>
37 #include <QtCore/qdebug.h>
38 #include <QStyleFactory>
40 #ifdef QT_STATICPLUGIN
42 #include <QtPlugin>
44 #if defined(Q_OS_WIN32)
45 Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
46 #elif defined(Q_OS_MAC)
47 Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
48 #elif defined(Q_OS_UNIX)
49 Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
50 #endif
52 #endif
54 // NeL includes
55 #include <nel/misc/debug.h>
56 #include <nel/misc/common.h>
57 #include <nel/misc/file.h>
58 #include <nel/misc/path.h>
59 #include <nel/misc/command.h>
60 #include <nel/misc/sheet_id.h>
62 // Project includes
63 #include "../shared_widgets/common.h"
64 #include "tool_config.h"
65 #include "main_window.h"
67 using namespace std;
68 using namespace NLMISC;
70 namespace NLTOOLS {
72 namespace {
74 CFileDisplayer *s_FileDisplayer = NULL;
76 } /* anonymous namespace */
78 } /* namespace NLTOOLS */
80 void usage()
82 /* from Qt sample */
84 qWarning() << "Usage: mainwindow [-SizeHint<color> <width>x<height>] ...";
85 exit(1);
88 QMap<QString, QSize> parseCustomSizeHints(int argc, char **argv)
90 /* from Qt sample */
92 QMap<QString, QSize> result;
94 for (int i = 1; i < argc; ++i) {
95 QString arg = QString::fromLocal8Bit(argv[i]);
97 if (arg.startsWith(QLatin1String("-SizeHint"))) {
98 QString name = arg.mid(9);
99 if (name.isEmpty())
100 usage();
101 if (++i == argc)
102 usage();
103 QString sizeStr = QString::fromLocal8Bit(argv[i]);
104 int idx = sizeStr.indexOf(QLatin1Char('x'));
105 if (idx == -1)
106 usage();
107 bool ok;
108 int w = sizeStr.left(idx).toInt(&ok);
109 if (!ok)
110 usage();
111 int h = sizeStr.mid(idx + 1).toInt(&ok);
112 if (!ok)
113 usage();
114 result[name] = QSize(w, h);
118 return result;
121 #ifdef NL_OS_WINDOWS
122 # ifdef _UNICODE
123 # define tstring wstring
124 # else
125 # define tstring string
126 # endif
127 #endif
129 sint main(int argc, char **argv)
131 // go nel!
133 // use log.log if NEL_LOG_IN_FILE and NLTOOLS_USE_LOG_LOG defined as 1
134 createDebug(NULL, NLTOOLS_USE_LOG_LOG, false);
136 #if NLTOOLS_USE_LOG
137 // create toverhex_client.log
138 // filedisplayer only deletes the 001 etc
139 if (NLTOOLS_ERASE_LOG && CFile::isExists(NLTOOLS_LOG_FILE))
140 CFile::deleteFile(NLTOOLS_LOG_FILE);
141 // initialize the log file
142 NLTOOLS::s_FileDisplayer = new CFileDisplayer();
143 NLTOOLS::s_FileDisplayer->setParam(NLTOOLS_LOG_FILE, NLTOOLS_ERASE_LOG);
144 DebugLog->addDisplayer(NLTOOLS::s_FileDisplayer);
145 InfoLog->addDisplayer(NLTOOLS::s_FileDisplayer);
146 WarningLog->addDisplayer(NLTOOLS::s_FileDisplayer);
147 AssertLog->addDisplayer(NLTOOLS::s_FileDisplayer);
148 ErrorLog->addDisplayer(NLTOOLS::s_FileDisplayer);
149 #endif
151 nlinfo("Welcome to NeL!");
154 // low fragmentation heap (windows)
155 #if NLTOOLS_LOW_FRAGMENTATION_HEAP
156 ULONG heapFragValue = 2; // enable low fragmentation heap
157 if (HeapSetInformation(GetProcessHeap(),
158 HeapCompatibilityInformation,
159 &heapFragValue, sizeof(heapFragValue)))
161 nlinfo("HeapSetInformation OK!\n");
163 else
165 nlwarning("HeapSetInformation FAIL! (%d)\n", GetLastError());
167 #endif
169 #ifdef NL_OS_WINDOWS
170 HRESULT hr;
171 hr = hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
172 bool coInitOk = (hr == S_OK) || (hr == S_FALSE);
173 #endif
175 CSheetId::initWithoutSheet();
177 NLQT::preApplication();
178 QApplication app(argc, const_cast<char **>(argv));
179 NLQT::postApplication();
181 QMap<QString, QSize> customSizeHints = parseCustomSizeHints(argc, argv);
183 NLTOOLS::CMainWindow mainWin(customSizeHints);
184 mainWin.resize(800, 600);
185 mainWin.show(); // calls isVisible(true)
187 int result = app.exec();
189 #ifdef NL_OS_WINDOWS
190 if (coInitOk) CoUninitialize();
191 #endif
193 return result;
196 /* end of file */