1 #include "pch.h" 2 #include "Editor.hpp" 3 4 5 #include <QApplication> 6 #include <QTimer> 7 8 #include <boost/thread.hpp> 9 10 #include "../Main/Factory.hpp" 11 12 #include "MainWindow.hpp" 13 14 namespace sh 15 { 16 Editor()17 Editor::Editor() 18 : mMainWindow(NULL) 19 , mApplication(NULL) 20 , mInitialized(false) 21 , mThread(NULL) 22 { 23 } 24 ~Editor()25 Editor::~Editor() 26 { 27 if (mMainWindow) 28 mMainWindow->mRequestExit = true; 29 30 if (mThread) 31 mThread->join(); 32 delete mThread; 33 } 34 show()35 void Editor::show() 36 { 37 if (!mInitialized) 38 { 39 mInitialized = true; 40 41 mThread = new boost::thread(boost::bind(&Editor::runThread, this)); 42 } 43 else 44 { 45 if (mMainWindow) 46 mMainWindow->mRequestShowWindow = true; 47 } 48 } 49 runThread()50 void Editor::runThread() 51 { 52 int argc = 0; 53 char** argv = NULL; 54 mApplication = new QApplication(argc, argv); 55 mApplication->setQuitOnLastWindowClosed(false); 56 mMainWindow = new MainWindow(); 57 mMainWindow->mSync = &mSync; 58 mMainWindow->show(); 59 60 mApplication->exec(); 61 62 delete mApplication; 63 } 64 update()65 void Editor::update() 66 { 67 sh::Factory::getInstance().doMonitorShaderFiles(); 68 69 if (!mMainWindow) 70 return; 71 72 73 { 74 boost::mutex::scoped_lock lock(mSync.mActionMutex); 75 76 // execute pending actions 77 while (mMainWindow->mActionQueue.size()) 78 { 79 Action* action = mMainWindow->mActionQueue.front(); 80 action->execute(); 81 delete action; 82 mMainWindow->mActionQueue.pop(); 83 } 84 } 85 { 86 boost::mutex::scoped_lock lock(mSync.mQueryMutex); 87 88 // execute pending queries 89 for (std::vector<Query*>::iterator it = mMainWindow->mQueries.begin(); it != mMainWindow->mQueries.end(); ++it) 90 { 91 Query* query = *it; 92 if (!query->mDone) 93 query->execute(); 94 } 95 } 96 97 boost::mutex::scoped_lock lock2(mSync.mUpdateMutex); 98 99 // update the list of materials 100 mMainWindow->mState.mMaterialList.clear(); 101 sh::Factory::getInstance().listMaterials(mMainWindow->mState.mMaterialList); 102 103 // update global settings 104 mMainWindow->mState.mGlobalSettingsMap.clear(); 105 sh::Factory::getInstance().listGlobalSettings(mMainWindow->mState.mGlobalSettingsMap); 106 107 // update configuration list 108 mMainWindow->mState.mConfigurationList.clear(); 109 sh::Factory::getInstance().listConfigurationNames(mMainWindow->mState.mConfigurationList); 110 111 // update shader list 112 mMainWindow->mState.mShaderSets.clear(); 113 sh::Factory::getInstance().listShaderSets(mMainWindow->mState.mShaderSets); 114 115 mMainWindow->mState.mErrors += sh::Factory::getInstance().getErrorLog(); 116 } 117 118 } 119