2012-11-22 12:30:02 +00:00
# include "editor.hpp"
2014-12-01 03:08:27 +00:00
# include <openengine/bullet/BulletShapeLoader.h>
2013-08-21 22:14:29 +00:00
# include <QApplication>
2013-09-03 06:44:21 +00:00
# include <QLocalServer>
# include <QLocalSocket>
2013-09-08 12:31:20 +00:00
# include <QMessageBox>
2012-11-22 12:30:02 +00:00
2013-11-02 01:48:30 +00:00
# include <OgreRoot.h>
# include <OgreRenderWindow.h>
2014-03-16 11:44:01 +00:00
# include <extern/shiny/Main/Factory.hpp>
# include <extern/shiny/Platforms/Ogre/OgrePlatform.hpp>
2014-02-25 10:58:32 +00:00
# include <components/ogreinit/ogreinit.hpp>
2015-01-13 16:29:25 +00:00
# include <components/nifogre/ogrenifloader.hpp>
2014-03-09 11:32:21 +00:00
# include <components/bsa/resources.hpp>
2012-11-26 11:29:22 +00:00
# include "model/doc/document.hpp"
# include "model/world/data.hpp"
2014-02-25 10:58:32 +00:00
CS : : Editor : : Editor ( OgreInit : : OgreInit & ogreInit )
2014-10-17 12:23:27 +00:00
: mUserSettings ( mCfgMgr ) , mOverlaySystem ( 0 ) , mDocumentManager ( mCfgMgr ) ,
2015-05-01 00:24:27 +00:00
mViewManager ( mDocumentManager ) , mPid ( " " ) ,
mLock ( ) , mIpcServerName ( " org.openmw.OpenCS " ) , mServer ( NULL ) , mClientSocket ( NULL )
2012-11-22 12:30:02 +00:00
{
2014-03-09 11:32:21 +00:00
std : : pair < Files : : PathContainer , std : : vector < std : : string > > config = readConfig ( ) ;
2014-02-25 10:58:32 +00:00
2014-03-09 11:32:21 +00:00
setupDataFiles ( config . first ) ;
2014-02-25 10:58:32 +00:00
2014-05-05 10:56:03 +00:00
CSMSettings : : UserSettings : : instance ( ) . loadSettings ( " opencs.ini " ) ;
2014-09-17 07:13:21 +00:00
mSettings . setModel ( CSMSettings : : UserSettings : : instance ( ) ) ;
2013-09-03 09:12:19 +00:00
2014-02-25 10:58:32 +00:00
ogreInit . init ( ( mCfgMgr . getUserConfigPath ( ) / " opencsOgre.log " ) . string ( ) ) ;
2013-09-10 14:45:01 +00:00
2015-01-13 16:29:25 +00:00
NifOgre : : Loader : : setShowMarkers ( true ) ;
2014-10-17 12:23:27 +00:00
mOverlaySystem . reset ( new CSVRender : : OverlaySystem ) ;
2014-03-09 11:32:21 +00:00
Bsa : : registerResources ( Files : : Collections ( config . first , ! mFsStrict ) , config . second , true ,
mFsStrict ) ;
2014-07-04 10:46:57 +00:00
mDocumentManager . listResources ( ) ;
2013-09-10 14:45:01 +00:00
mNewGame . setLocalData ( mLocal ) ;
2013-10-27 03:55:44 +00:00
mFileDialog . setLocalData ( mLocal ) ;
2013-09-10 14:45:01 +00:00
2014-04-21 07:02:58 +00:00
connect ( & mDocumentManager , SIGNAL ( documentAdded ( CSMDoc : : Document * ) ) ,
this , SLOT ( documentAdded ( CSMDoc : : Document * ) ) ) ;
2014-04-26 11:11:27 +00:00
connect ( & mDocumentManager , SIGNAL ( lastDocumentDeleted ( ) ) ,
this , SLOT ( lastDocumentDeleted ( ) ) ) ;
2014-04-21 07:02:58 +00:00
2013-09-08 10:06:28 +00:00
connect ( & mViewManager , SIGNAL ( newGameRequest ( ) ) , this , SLOT ( createGame ( ) ) ) ;
connect ( & mViewManager , SIGNAL ( newAddonRequest ( ) ) , this , SLOT ( createAddon ( ) ) ) ;
2013-02-02 15:14:58 +00:00
connect ( & mViewManager , SIGNAL ( loadDocumentRequest ( ) ) , this , SLOT ( loadDocument ( ) ) ) ;
2013-09-08 07:33:45 +00:00
connect ( & mViewManager , SIGNAL ( editSettingsRequest ( ) ) , this , SLOT ( showSettings ( ) ) ) ;
2013-02-02 15:14:58 +00:00
2013-09-08 10:06:28 +00:00
connect ( & mStartup , SIGNAL ( createGame ( ) ) , this , SLOT ( createGame ( ) ) ) ;
connect ( & mStartup , SIGNAL ( createAddon ( ) ) , this , SLOT ( createAddon ( ) ) ) ;
2013-02-02 15:14:58 +00:00
connect ( & mStartup , SIGNAL ( loadDocument ( ) ) , this , SLOT ( loadDocument ( ) ) ) ;
2013-09-08 07:26:43 +00:00
connect ( & mStartup , SIGNAL ( editConfig ( ) ) , this , SLOT ( showSettings ( ) ) ) ;
2013-02-07 11:52:01 +00:00
2013-10-27 03:55:44 +00:00
connect ( & mFileDialog , SIGNAL ( signalOpenFiles ( const boost : : filesystem : : path & ) ) ,
this , SLOT ( openFiles ( const boost : : filesystem : : path & ) ) ) ;
connect ( & mFileDialog , SIGNAL ( signalCreateNewFile ( const boost : : filesystem : : path & ) ) ,
this , SLOT ( createNewFile ( const boost : : filesystem : : path & ) ) ) ;
2015-05-29 22:37:58 +00:00
connect ( & mFileDialog , SIGNAL ( rejected ( ) ) , this , SLOT ( cancelFileDialog ( ) ) ) ;
2013-03-07 02:00:59 +00:00
2013-09-10 14:45:01 +00:00
connect ( & mNewGame , SIGNAL ( createRequest ( const boost : : filesystem : : path & ) ) ,
2013-10-19 16:43:47 +00:00
this , SLOT ( createNewGame ( const boost : : filesystem : : path & ) ) ) ;
2015-05-29 22:37:58 +00:00
connect ( & mNewGame , SIGNAL ( cancelCreateGame ( ) ) , this , SLOT ( cancelCreateGame ( ) ) ) ;
2012-11-22 12:30:02 +00:00
}
2014-10-14 20:02:19 +00:00
CS : : Editor : : ~ Editor ( )
2014-12-04 14:09:42 +00:00
{
2014-12-04 20:50:03 +00:00
mPidFile . close ( ) ;
2014-12-04 14:09:42 +00:00
if ( mServer & & boost : : filesystem : : exists ( mPid ) )
2015-01-15 11:13:53 +00:00
static_cast < void > ( // silence coverity warning
remove ( mPid . string ( ) . c_str ( ) ) ) ; // ignore any error
2014-12-04 20:38:33 +00:00
2014-12-01 03:08:27 +00:00
// cleanup global resources used by OEngine
delete OEngine : : Physic : : BulletShapeManager : : getSingletonPtr ( ) ;
2014-12-04 14:09:42 +00:00
}
2014-10-14 20:02:19 +00:00
2014-02-25 10:58:32 +00:00
void CS : : Editor : : setupDataFiles ( const Files : : PathContainer & dataDirs )
{
for ( Files : : PathContainer : : const_iterator iter = dataDirs . begin ( ) ; iter ! = dataDirs . end ( ) ; + + iter )
{
2014-03-21 10:56:48 +00:00
QString path = QString : : fromUtf8 ( iter - > string ( ) . c_str ( ) ) ;
2014-02-25 10:58:32 +00:00
mFileDialog . addFiles ( path ) ;
}
}
2015-06-16 02:48:45 +00:00
std : : pair < Files : : PathContainer , std : : vector < std : : string > > CS : : Editor : : readConfig ( bool quiet )
2012-11-22 12:30:02 +00:00
{
2013-03-07 02:00:59 +00:00
boost : : program_options : : variables_map variables ;
2015-02-03 12:18:03 +00:00
boost : : program_options : : options_description desc ( " Syntax: openmw-cs <options> \n Allowed options " ) ;
2013-02-02 15:14:58 +00:00
2013-03-07 02:00:59 +00:00
desc . add_options ( )
2014-09-13 18:41:57 +00:00
( " data " , boost : : program_options : : value < Files : : PathContainer > ( ) - > default_value ( Files : : PathContainer ( ) , " data " ) - > multitoken ( ) - > composing ( ) )
2013-03-07 02:00:59 +00:00
( " data-local " , boost : : program_options : : value < std : : string > ( ) - > default_value ( " " ) )
( " fs-strict " , boost : : program_options : : value < bool > ( ) - > implicit_value ( true ) - > default_value ( false ) )
2013-10-18 20:11:14 +00:00
( " encoding " , boost : : program_options : : value < std : : string > ( ) - > default_value ( " win1252 " ) )
2014-03-09 11:32:21 +00:00
( " resources " , boost : : program_options : : value < std : : string > ( ) - > default_value ( " resources " ) )
( " fallback-archive " , boost : : program_options : : value < std : : vector < std : : string > > ( ) - >
2014-07-21 10:15:21 +00:00
default_value ( std : : vector < std : : string > ( ) , " fallback-archive " ) - > multitoken ( ) )
( " script-blacklist " , boost : : program_options : : value < std : : vector < std : : string > > ( ) - > default_value ( std : : vector < std : : string > ( ) , " " )
- > multitoken ( ) , " exclude specified script from the verifier (if the use of the blacklist is enabled) " )
( " script-blacklist-use " , boost : : program_options : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( true ) , " enable script blacklisting " ) ;
2013-02-02 15:14:58 +00:00
2013-03-07 02:00:59 +00:00
boost : : program_options : : notify ( variables ) ;
2012-11-23 13:05:49 +00:00
2015-06-16 03:09:44 +00:00
mCfgMgr . readConfiguration ( variables , desc , quiet ) ;
2012-11-23 13:05:49 +00:00
2014-05-12 08:32:57 +00:00
mDocumentManager . setEncoding (
ToUTF8 : : calculateEncoding ( variables [ " encoding " ] . as < std : : string > ( ) ) ) ;
2014-03-16 11:44:01 +00:00
mDocumentManager . setResourceDir ( mResources = variables [ " resources " ] . as < std : : string > ( ) ) ;
2014-02-25 10:58:32 +00:00
2014-07-21 10:15:21 +00:00
if ( variables [ " script-blacklist-use " ] . as < bool > ( ) )
mDocumentManager . setBlacklistedScripts (
variables [ " script-blacklist " ] . as < std : : vector < std : : string > > ( ) ) ;
2014-03-09 11:32:21 +00:00
mFsStrict = variables [ " fs-strict " ] . as < bool > ( ) ;
2013-09-08 12:31:20 +00:00
Files : : PathContainer dataDirs , dataLocal ;
2013-03-07 02:00:59 +00:00
if ( ! variables [ " data " ] . empty ( ) ) {
2013-09-08 12:31:20 +00:00
dataDirs = Files : : PathContainer ( variables [ " data " ] . as < Files : : PathContainer > ( ) ) ;
2013-03-07 02:00:59 +00:00
}
2013-02-04 12:46:54 +00:00
2013-03-07 02:00:59 +00:00
std : : string local = variables [ " data-local " ] . as < std : : string > ( ) ;
if ( ! local . empty ( ) ) {
2013-09-08 12:31:20 +00:00
dataLocal . push_back ( Files : : PathContainer : : value_type ( local ) ) ;
2013-03-07 02:00:59 +00:00
}
2012-11-26 11:29:22 +00:00
2013-09-08 12:31:20 +00:00
mCfgMgr . processPaths ( dataDirs ) ;
mCfgMgr . processPaths ( dataLocal , true ) ;
if ( ! dataLocal . empty ( ) )
mLocal = dataLocal [ 0 ] ;
else
{
QMessageBox messageBox ;
messageBox . setWindowTitle ( tr ( " No local data path available " ) ) ;
messageBox . setIcon ( QMessageBox : : Critical ) ;
messageBox . setStandardButtons ( QMessageBox : : Ok ) ;
messageBox . setText ( tr ( " <br><b>OpenCS is unable to access the local data directory. This may indicate a faulty configuration or a broken install.</b> " ) ) ;
messageBox . exec ( ) ;
QApplication : : exit ( 1 ) ;
}
2013-03-07 02:00:59 +00:00
2013-09-08 12:31:20 +00:00
dataDirs . insert ( dataDirs . end ( ) , dataLocal . begin ( ) , dataLocal . end ( ) ) ;
2013-03-07 02:00:59 +00:00
2014-04-23 03:19:53 +00:00
//iterate the data directories and add them to the file dialog for loading
for ( Files : : PathContainer : : const_iterator iter = dataDirs . begin ( ) ; iter ! = dataDirs . end ( ) ; + + iter )
{
2014-04-29 11:16:58 +00:00
QString path = QString : : fromUtf8 ( iter - > string ( ) . c_str ( ) ) ;
2014-04-23 03:19:53 +00:00
mFileDialog . addFiles ( path ) ;
}
2014-03-09 11:32:21 +00:00
return std : : make_pair ( dataDirs , variables [ " fallback-archive " ] . as < std : : vector < std : : string > > ( ) ) ;
2013-03-07 02:00:59 +00:00
}
2013-09-08 10:06:28 +00:00
void CS : : Editor : : createGame ( )
{
mStartup . hide ( ) ;
if ( mNewGame . isHidden ( ) )
mNewGame . show ( ) ;
mNewGame . raise ( ) ;
mNewGame . activateWindow ( ) ;
}
2015-05-29 22:37:58 +00:00
void CS : : Editor : : cancelCreateGame ( )
{
if ( ! mDocumentManager . isEmpty ( ) )
return ;
mNewGame . hide ( ) ;
if ( mStartup . isHidden ( ) )
mStartup . show ( ) ;
mStartup . raise ( ) ;
mStartup . activateWindow ( ) ;
}
2013-09-08 10:06:28 +00:00
void CS : : Editor : : createAddon ( )
2013-03-07 02:00:59 +00:00
{
mStartup . hide ( ) ;
2015-06-16 02:48:45 +00:00
mFileDialog . clearFiles ( ) ;
std : : pair < Files : : PathContainer , std : : vector < std : : string > > config = readConfig ( /*quiet*/ true ) ;
setupDataFiles ( config . first ) ;
2013-10-31 23:12:13 +00:00
mFileDialog . showDialog ( CSVDoc : : ContentAction_New ) ;
2013-02-02 15:14:58 +00:00
}
2015-05-29 22:37:58 +00:00
void CS : : Editor : : cancelFileDialog ( )
{
if ( ! mDocumentManager . isEmpty ( ) )
return ;
mFileDialog . hide ( ) ;
if ( mStartup . isHidden ( ) )
mStartup . show ( ) ;
mStartup . raise ( ) ;
mStartup . activateWindow ( ) ;
}
2013-02-02 15:14:58 +00:00
void CS : : Editor : : loadDocument ( )
{
2013-02-07 12:11:41 +00:00
mStartup . hide ( ) ;
2015-06-16 02:48:45 +00:00
mFileDialog . clearFiles ( ) ;
std : : pair < Files : : PathContainer , std : : vector < std : : string > > config = readConfig ( /*quiet*/ true ) ;
setupDataFiles ( config . first ) ;
2013-10-31 23:12:13 +00:00
mFileDialog . showDialog ( CSVDoc : : ContentAction_Edit ) ;
2013-02-05 21:06:36 +00:00
}
2013-02-02 15:14:58 +00:00
2013-10-27 03:55:44 +00:00
void CS : : Editor : : openFiles ( const boost : : filesystem : : path & savePath )
2013-02-05 21:06:36 +00:00
{
2013-03-07 02:00:59 +00:00
std : : vector < boost : : filesystem : : path > files ;
2013-10-27 03:55:44 +00:00
foreach ( const QString & path , mFileDialog . selectedFilePaths ( ) )
2014-03-21 10:56:48 +00:00
files . push_back ( path . toUtf8 ( ) . constData ( ) ) ;
2013-10-07 03:10:38 +00:00
2014-04-21 07:02:58 +00:00
mDocumentManager . addDocument ( files , savePath , false ) ;
2013-02-07 11:52:01 +00:00
2013-10-23 03:20:21 +00:00
mFileDialog . hide ( ) ;
2013-03-07 02:00:59 +00:00
}
2013-10-27 03:55:44 +00:00
void CS : : Editor : : createNewFile ( const boost : : filesystem : : path & savePath )
2013-03-07 02:00:59 +00:00
{
std : : vector < boost : : filesystem : : path > files ;
2013-10-02 02:29:45 +00:00
foreach ( const QString & path , mFileDialog . selectedFilePaths ( ) ) {
2014-03-21 10:56:48 +00:00
files . push_back ( path . toUtf8 ( ) . constData ( ) ) ;
2013-03-07 02:00:59 +00:00
}
2014-09-15 21:44:07 +00:00
files . push_back ( savePath ) ;
2013-03-07 02:00:59 +00:00
2014-04-21 07:02:58 +00:00
mDocumentManager . addDocument ( files , savePath , true ) ;
2013-02-07 11:52:01 +00:00
2013-10-23 03:20:21 +00:00
mFileDialog . hide ( ) ;
2012-11-22 12:30:02 +00:00
}
2013-09-10 14:45:01 +00:00
void CS : : Editor : : createNewGame ( const boost : : filesystem : : path & file )
2013-09-08 12:31:20 +00:00
{
std : : vector < boost : : filesystem : : path > files ;
2013-09-10 14:45:01 +00:00
files . push_back ( file ) ;
2013-09-08 12:31:20 +00:00
2014-04-21 07:02:58 +00:00
mDocumentManager . addDocument ( files , file , true ) ;
2013-09-08 12:31:20 +00:00
mNewGame . hide ( ) ;
}
2013-09-03 09:12:19 +00:00
void CS : : Editor : : showStartup ( )
{
2013-09-06 04:02:51 +00:00
if ( mStartup . isHidden ( ) )
mStartup . show ( ) ;
mStartup . raise ( ) ;
mStartup . activateWindow ( ) ;
2013-09-03 09:12:19 +00:00
}
2013-09-08 07:26:43 +00:00
void CS : : Editor : : showSettings ( )
{
if ( mSettings . isHidden ( ) )
mSettings . show ( ) ;
2015-01-02 03:50:35 +00:00
mSettings . move ( QCursor : : pos ( ) ) ;
2013-09-08 07:26:43 +00:00
mSettings . raise ( ) ;
mSettings . activateWindow ( ) ;
}
2013-09-03 06:44:21 +00:00
bool CS : : Editor : : makeIPCServer ( )
{
2014-12-04 14:09:42 +00:00
try
{
mPid = boost : : filesystem : : temp_directory_path ( ) ;
2015-02-03 12:18:03 +00:00
mPid / = " openmw-cs.pid " ;
2014-12-04 14:09:42 +00:00
bool pidExists = boost : : filesystem : : exists ( mPid ) ;
2014-12-04 20:50:03 +00:00
mPidFile . open ( mPid ) ;
2014-12-04 14:09:42 +00:00
mLock = boost : : interprocess : : file_lock ( mPid . string ( ) . c_str ( ) ) ;
if ( ! mLock . try_lock ( ) )
{
std : : cerr < < " OpenCS already running. " < < std : : endl ;
return false ;
}
# ifdef _WIN32
2014-12-04 20:50:03 +00:00
mPidFile < < GetCurrentProcessId ( ) < < std : : endl ;
2014-12-04 14:09:42 +00:00
# else
2014-12-04 20:50:03 +00:00
mPidFile < < getpid ( ) < < std : : endl ;
2014-12-04 14:09:42 +00:00
# endif
mServer = new QLocalServer ( this ) ;
if ( pidExists )
{
// hack to get the temp directory path
mServer - > listen ( " dummy " ) ;
QString fullPath = mServer - > fullServerName ( ) ;
mServer - > close ( ) ;
fullPath . remove ( QRegExp ( " dummy$ " ) ) ;
fullPath + = mIpcServerName ;
2015-06-11 20:36:19 +00:00
if ( boost : : filesystem : : exists ( fullPath . toUtf8 ( ) . constData ( ) ) )
2014-12-04 14:09:42 +00:00
{
// TODO: compare pid of the current process with that in the file
std : : cout < < " Detected unclean shutdown. " < < std : : endl ;
// delete the stale file
2015-06-11 20:36:19 +00:00
if ( remove ( fullPath . toUtf8 ( ) . constData ( ) ) )
2014-12-04 14:09:42 +00:00
std : : cerr < < " ERROR removing stale connection file " < < std : : endl ;
}
}
}
catch ( const std : : exception & e )
{
std : : cerr < < " ERROR " < < e . what ( ) < < std : : endl ;
return false ;
}
2013-09-03 09:12:19 +00:00
2013-09-06 04:02:51 +00:00
if ( mServer - > listen ( mIpcServerName ) )
{
connect ( mServer , SIGNAL ( newConnection ( ) ) , this , SLOT ( showStartup ( ) ) ) ;
return true ;
}
2013-09-03 09:12:19 +00:00
2013-09-06 04:02:51 +00:00
mServer - > close ( ) ;
2014-12-04 14:09:42 +00:00
mServer = NULL ;
2013-09-06 04:02:51 +00:00
return false ;
2013-09-03 06:44:21 +00:00
}
2013-09-03 09:12:19 +00:00
void CS : : Editor : : connectToIPCServer ( )
{
2013-09-06 04:02:51 +00:00
mClientSocket = new QLocalSocket ( this ) ;
mClientSocket - > connectToServer ( mIpcServerName ) ;
mClientSocket - > close ( ) ;
2013-09-03 09:12:19 +00:00
}
2012-11-22 12:30:02 +00:00
int CS : : Editor : : run ( )
{
2013-09-08 12:31:20 +00:00
if ( mLocal . empty ( ) )
return 1 ;
2014-03-16 11:44:01 +00:00
mStartup . show ( ) ;
QApplication : : setQuitOnLastWindowClosed ( true ) ;
return QApplication : : exec ( ) ;
}
std : : auto_ptr < sh : : Factory > CS : : Editor : : setupGraphics ( )
{
2014-09-26 01:26:33 +00:00
std : : string renderer =
# if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
" Direct3D9 Rendering Subsystem " ;
# else
" OpenGL Rendering Subsystem " ;
# endif
2014-09-28 00:17:54 +00:00
std : : string renderSystem = mUserSettings . setting ( " Video/render system " , renderer . c_str ( ) ) . toStdString ( ) ;
2014-09-26 01:26:33 +00:00
Ogre : : Root : : getSingleton ( ) . setRenderSystem ( Ogre : : Root : : getSingleton ( ) . getRenderSystemByName ( renderSystem ) ) ;
2013-11-02 01:48:30 +00:00
2014-10-15 07:48:01 +00:00
// Initialise Ogre::OverlaySystem after Ogre::Root but before initialisation
2014-10-15 20:29:46 +00:00
mOverlaySystem . get ( ) ;
2014-10-15 07:48:01 +00:00
2013-11-02 01:48:30 +00:00
Ogre : : Root : : getSingleton ( ) . initialise ( false ) ;
// Create a hidden background window to keep resources
Ogre : : NameValuePairList params ;
params . insert ( std : : make_pair ( " title " , " " ) ) ;
2014-09-14 02:48:00 +00:00
std : : string antialiasing = mUserSettings . settingValue ( " Video/antialiasing " ) . toStdString ( ) ;
if ( antialiasing = = " MSAA 16 " ) antialiasing = " 16 " ;
else if ( antialiasing = = " MSAA 8 " ) antialiasing = " 8 " ;
else if ( antialiasing = = " MSAA 4 " ) antialiasing = " 4 " ;
else if ( antialiasing = = " MSAA 2 " ) antialiasing = " 2 " ;
else antialiasing = " 0 " ;
params . insert ( std : : make_pair ( " FSAA " , antialiasing ) ) ;
2014-09-25 08:15:34 +00:00
params . insert ( std : : make_pair ( " vsync " , " false " ) ) ;
2013-11-02 01:48:30 +00:00
params . insert ( std : : make_pair ( " hidden " , " true " ) ) ;
2013-12-24 19:59:59 +00:00
# if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
params . insert ( std : : make_pair ( " macAPI " , " cocoa " ) ) ;
# endif
2014-09-16 20:29:11 +00:00
// NOTE: fullscreen mode not supported (doesn't really make sense for opencs)
2014-09-16 09:50:25 +00:00
Ogre : : RenderWindow * hiddenWindow = Ogre : : Root : : getSingleton ( ) . createRenderWindow ( " InactiveHidden " , 1 , 1 , false , & params ) ;
2013-11-02 01:48:30 +00:00
hiddenWindow - > setActive ( false ) ;
2014-03-16 11:44:01 +00:00
sh : : OgrePlatform * platform =
new sh : : OgrePlatform ( " General " , ( mResources / " materials " ) . string ( ) ) ;
2012-11-22 12:30:02 +00:00
2014-10-10 02:35:14 +00:00
// for font used in overlays
Ogre : : Root : : getSingleton ( ) . addResourceLocation ( ( mResources / " mygui " ) . string ( ) ,
" FileSystem " , Ogre : : ResourceGroupManager : : DEFAULT_RESOURCE_GROUP_NAME , true ) ;
2014-03-16 11:44:01 +00:00
if ( ! boost : : filesystem : : exists ( mCfgMgr . getCachePath ( ) ) )
boost : : filesystem : : create_directories ( mCfgMgr . getCachePath ( ) ) ;
2013-03-03 21:58:26 +00:00
2014-03-16 11:44:01 +00:00
platform - > setCacheFolder ( mCfgMgr . getCachePath ( ) . string ( ) ) ;
std : : auto_ptr < sh : : Factory > factory ( new sh : : Factory ( platform ) ) ;
2014-09-26 01:26:33 +00:00
QString shLang = mUserSettings . settingValue ( " General/shader mode " ) ;
QString rend = renderSystem . c_str ( ) ;
bool openGL = rend . contains ( QRegExp ( " ^OpenGL " , Qt : : CaseInsensitive ) ) ;
bool glES = rend . contains ( QRegExp ( " ^OpenGL ES " , Qt : : CaseInsensitive ) ) ;
// force shader language based on render system
if ( shLang = = " "
| | ( openGL & & shLang = = " hlsl " )
| | ( ! openGL & & shLang = = " glsl " )
| | ( glES & & shLang ! = " glsles " ) )
{
shLang = openGL ? ( glES ? " glsles " : " glsl " ) : " hlsl " ;
//no group means "General" group in the "ini" file standard
mUserSettings . setDefinitions ( " shader mode " , ( QStringList ( ) < < shLang ) ) ;
}
2014-09-14 02:48:00 +00:00
enum sh : : Language lang ;
2014-09-18 12:17:37 +00:00
if ( shLang = = " glsl " ) lang = sh : : Language_GLSL ;
else if ( shLang = = " glsles " ) lang = sh : : Language_GLSLES ;
else if ( shLang = = " hlsl " ) lang = sh : : Language_HLSL ;
else lang = sh : : Language_CG ;
2014-09-14 02:48:00 +00:00
factory - > setCurrentLanguage ( lang ) ;
2014-03-16 11:44:01 +00:00
factory - > setWriteSourceCache ( true ) ;
factory - > setReadSourceCache ( true ) ;
factory - > setReadMicrocodeCache ( true ) ;
factory - > setWriteMicrocodeCache ( true ) ;
factory - > loadAllFiles ( ) ;
2014-10-17 11:49:33 +00:00
bool shaders = mUserSettings . setting ( " 3d-render/shaders " , QString ( " true " ) ) = = " true " ? true : false ;
2014-09-24 12:41:49 +00:00
sh : : Factory : : getInstance ( ) . setShadersEnabled ( shaders ) ;
2014-09-28 00:17:54 +00:00
std : : string fog = mUserSettings . setting ( " Shader/fog " , QString ( " true " ) ) . toStdString ( ) ;
2014-09-23 23:33:19 +00:00
sh : : Factory : : getInstance ( ) . setGlobalSetting ( " fog " , fog ) ;
2014-03-16 11:44:01 +00:00
2014-09-26 01:26:33 +00:00
2014-09-28 00:17:54 +00:00
std : : string shadows = mUserSettings . setting ( " Shader/shadows " , QString ( " false " ) ) . toStdString ( ) ;
2014-09-23 23:33:19 +00:00
sh : : Factory : : getInstance ( ) . setGlobalSetting ( " shadows " , shadows ) ;
2014-03-16 11:44:01 +00:00
2014-09-28 00:17:54 +00:00
std : : string shadows_pssm = mUserSettings . setting ( " Shader/shadows_pssm " , QString ( " false " ) ) . toStdString ( ) ;
2014-09-23 23:33:19 +00:00
sh : : Factory : : getInstance ( ) . setGlobalSetting ( " shadows_pssm " , shadows_pssm ) ;
2014-03-16 11:44:01 +00:00
2014-09-28 00:17:54 +00:00
std : : string render_refraction = mUserSettings . setting ( " Shader/render_refraction " , QString ( " false " ) ) . toStdString ( ) ;
2014-09-23 23:33:19 +00:00
sh : : Factory : : getInstance ( ) . setGlobalSetting ( " render_refraction " , render_refraction ) ;
// internal setting - may be switched on or off by the use of shader configurations
sh : : Factory : : getInstance ( ) . setGlobalSetting ( " viewproj_fix " , " false " ) ;
2014-09-22 06:24:06 +00:00
2014-10-19 11:41:56 +00:00
std : : string num_lights = mUserSettings . setting ( " 3d-render-adv/num_lights " , QString ( " 8 " ) ) . toStdString ( ) ;
2014-09-28 00:17:54 +00:00
sh : : Factory : : getInstance ( ) . setGlobalSetting ( " num_lights " , num_lights ) ;
2014-03-16 11:44:01 +00:00
/// \todo add more configurable shiny settings
return factory ;
2013-03-03 21:58:26 +00:00
}
2014-04-21 07:02:58 +00:00
void CS : : Editor : : documentAdded ( CSMDoc : : Document * document )
{
mViewManager . addView ( document ) ;
2014-04-26 11:11:27 +00:00
}
void CS : : Editor : : lastDocumentDeleted ( )
{
2014-11-21 19:59:23 +00:00
QApplication : : quit ( ) ;
2014-05-03 12:36:06 +00:00
}