void EntityList::destroyInstance() { if (InstancePtr() != NULL) { // De-register self from the SelectionSystem GlobalSelectionSystem().removeObserver(InstancePtr().get()); } InstancePtr() = EntityListPtr(); }
EntityList& EntityList::Instance() { if (InstancePtr() == NULL) { // Not yet instantiated, do it now InstancePtr() = EntityListPtr(new EntityList); // Register this instance with GlobalRadiant() at once GlobalRadiant().addEventListener(InstancePtr()); } return *InstancePtr(); }
LRESULT CALLBACK Window::WndProc(HWND handle, UINT message, WPARAM wParam, LPARAM lParam) { if (InstancePtr() != NULL && Instance().m_handle != NULL) if (Instance().HandleWindowMessage(message, wParam, lParam)) return 0; return DefWindowProc(handle, message, wParam, lParam); }
void PrefabSelector::onRadiantShutdown() { rMessage() << "PrefabSelector shutting down." << std::endl; // Destroy the window SendDestroyEvent(); InstancePtr().reset(); }
void LightInspector::onRadiantShutdown() { if (IsShownOnScreen()) { Hide(); } // Destroy the window SendDestroyEvent(); InstancePtr().reset(); }
void ModelSelector::onRadiantShutdown() { rMessage() << "ModelSelector shutting down." << std::endl; // Model references are kept by this class, release them before shutting down _treeView.reset(); _treeStore.reset(NULL); _treeStoreWithSkins.reset(NULL); // Destroy the window SendDestroyEvent(); InstancePtr().reset(); }
void PatchInspector::onRadiantShutdown() { rMessage() << "PatchInspector shutting down." << std::endl; if (IsShownOnScreen()) { Hide(); } // Destroy the window SendDestroyEvent(); InstancePtr().reset(); }
// Creates the singleton logfile with the given filename void LogFile::create(const std::string& filename) { if (InstancePtr() == NULL) { // No logfile yet, create one InstancePtr() = LogFilePtr(new LogFile(filename)); // Write the initialisation info to the logfile. rMessage() << "Started logging to " << InstancePtr()->_logFilename << std::endl; time_t localtime; time(&localtime); rMessage() << "Today is: " << ctime(&localtime) << "This is " << RADIANT_APPNAME_FULL() << std::endl; // Output the gtkmm version to the logfile std::string gtkVersion = string::to_string(GTKMM_MAJOR_VERSION) + "."; gtkVersion += string::to_string(GTKMM_MINOR_VERSION) + "."; gtkVersion += string::to_string(GTKMM_MICRO_VERSION); rMessage() << "gtkmm Version: " << gtkVersion << std::endl; } }
// Static show method void OverlayDialog::display(const cmd::ArgumentList& args) { // Maintain a static dialog instance and display it on demand OverlayDialogPtr& instance = InstancePtr(); if (instance == NULL) { instance.reset(new OverlayDialog); } // Update the dialog state from the registry, and show it instance->initialiseWidgets(); instance->show_all(); }
// Creates the singleton logfile with the given filename void LogFile::create(const std::string& filename) { if (InstancePtr() == NULL) { // No logfile yet, create one InstancePtr() = LogFilePtr(new LogFile(filename)); // Write the initialisation info to the logfile. rMessage() << "Started logging to " << InstancePtr()->_logFilename << std::endl; time_t localtime; time(&localtime); rMessage() << "Today is: " << ctime(&localtime) << "This is " << RADIANT_APPNAME_FULL() << std::endl; // Output the wxWidgets version to the logfile std::string wxVersion = string::to_string(wxMAJOR_VERSION) + "."; wxVersion += string::to_string(wxMINOR_VERSION) + "."; wxVersion += string::to_string(wxRELEASE_NUMBER); rMessage() << "wxWidgets Version: " << wxVersion << std::endl; } }
void MainWindow::on_actionCopyInstance_triggered() { if (!m_selectedInstance) return; CopyInstanceDialog copyInstDlg(m_selectedInstance, this); if (!copyInstDlg.exec()) return; QString instancesDir = MMC->settings()->get("InstanceDir").toString(); QString instDirName = DirNameFromString(copyInstDlg.instName(), instancesDir); QString instDir = PathCombine(instancesDir, instDirName); auto &loader = InstanceFactory::get(); BaseInstance *newInstance = NULL; auto error = loader.copyInstance(newInstance, m_selectedInstance, instDir); QString errorMsg = QString("Failed to create instance %1: ").arg(instDirName); switch (error) { case InstanceFactory::NoCreateError: newInstance->setName(copyInstDlg.instName()); newInstance->setIconKey(copyInstDlg.iconKey()); MMC->instances()->add(InstancePtr(newInstance)); return; case InstanceFactory::InstExists: { errorMsg += "An instance with the given directory name already exists."; CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; } case InstanceFactory::CantCreateDir: { errorMsg += "Failed to create the instance directory."; CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; } default: { errorMsg += QString("Unknown instance loader error %1").arg(error); CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); break; } } }
InstancePtr InstanceList::getInstanceById(QString instId) { QListIterator<InstancePtr> iter(m_instances); InstancePtr inst; while(iter.hasNext()) { inst = iter.next(); if (inst->id() == instId) break; } if (inst->id() != instId) return InstancePtr(); else return iter.peekPrevious(); }
ModelSelector& ModelSelector::Instance() { ModelSelectorPtr& instancePtr = InstancePtr(); if (instancePtr == NULL) { // Not yet instantiated, do it now instancePtr.reset(new ModelSelector); // Register this instance with GlobalRadiant() at once GlobalRadiant().signal_radiantShutdown().connect( sigc::mem_fun(*instancePtr, &ModelSelector::onRadiantShutdown) ); } return *instancePtr; }
typename CeresExpressionSolver<N>::InstancePtr CeresExpressionSolver<N>::createNewInstance(const typename Problem::ConstInput & constInput) const{ struct Instance : public CeresExpressionSolver::Instance { typename Impl<N>::AutoDiff exp; ceres::QuaternionParameterization parametrization; Instance(const typename Problem::ConstInput& constInput) : exp(new typename Impl<N>::TestErrorQuat()) { } virtual void solveInto(const typename Problem::Input & input, typename Problem::Output & output, const typename Problem::Variant v) override { const double *parameters[] {&input.qC[0][0], &input.p[0]}; switch(v){ case benchmark::EvalVariants::Eval :{ if(!exp.Evaluate(parameters, (double*)&output.r[0], nullptr)){ throw(std::runtime_error("ceres AutoDiffCostFunction.Evaluate failed.")); } } break; case benchmark::EvalVariants::EvalJacobian: { double J_q[3 * 4 * N], J_p[3 * 3]; double *jacobians[2] = {J_q, J_p}; double result[3]; if(!exp.Evaluate(parameters, result, jacobians)){ throw(std::runtime_error("ceres AutoDiffCostFunction.Evaluate failed.")); } Eigen::Map<Eigen::Matrix<double, 3, 4 * N, Eigen::RowMajor> > J_qMap(J_q); double localParamJac[4 * 3]; Eigen::Map<Eigen::Matrix<double, 4, 3, Eigen::RowMajor> > localParamJacMap(localParamJac); for(unsigned i = 0; i < N; i++){ parametrization.ComputeJacobian(&input.qC[i][0], localParamJac); output.jPhi[i] = J_qMap.template block<3, 4>(0, i * 4) * localParamJacMap; } output.jP = Eigen::Map<Eigen::Matrix<double, 3, 3, Eigen::RowMajor> >(J_p); } break; } } }; return InstancePtr(new Instance(constInput)); }
void OverlayDialog::destroy() { InstancePtr().reset(); }
void EntitySettings::destroy() { // free the instance InstancePtr() = EntitySettingsPtr(); }
void MainWindow::on_actionAddInstance_triggered() { #ifdef TEST_SEGV // For further testing stuff. int v = *((int*)-1); #endif if (!MMC->minecraftlist()->isLoaded() && m_versionLoadTask && m_versionLoadTask->isRunning()) { QEventLoop waitLoop; waitLoop.connect(m_versionLoadTask, SIGNAL(failed(QString)), SLOT(quit())); waitLoop.connect(m_versionLoadTask, SIGNAL(succeeded()), SLOT(quit())); waitLoop.exec(); } NewInstanceDialog newInstDlg(this); if (!newInstDlg.exec()) return; InstancePtr newInstance; QString instancesDir = MMC->settings()->get("InstanceDir").toString(); QString instDirName = DirNameFromString(newInstDlg.instName(), instancesDir); QString instDir = PathCombine(instancesDir, instDirName); auto &loader = InstanceFactory::get(); auto error = loader.createInstance(newInstance, newInstDlg.selectedVersion(), instDir); QString errorMsg = tr("Failed to create instance %1: ").arg(instDirName); switch (error) { case InstanceFactory::NoCreateError: newInstance->setName(newInstDlg.instName()); newInstance->setIconKey(newInstDlg.iconKey()); MMC->instances()->add(InstancePtr(newInstance)); break; case InstanceFactory::InstExists: { errorMsg += tr("An instance with the given directory name already exists."); CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); return; } case InstanceFactory::CantCreateDir: { errorMsg += tr("Failed to create the instance directory."); CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); return; } default: { errorMsg += tr("Unknown instance loader error %1").arg(error); CustomMessageBox::selectable(this, tr("Error"), errorMsg, QMessageBox::Warning)->show(); return; } } if (MMC->accounts()->anyAccountIsValid()) { ProgressDialog loadDialog(this); auto update = newInstance->doUpdate(); connect(update.get(), &Task::failed, [this](QString reason) { QString error = QString("Instance load failed: %1").arg(reason); CustomMessageBox::selectable(this, tr("Error"), error, QMessageBox::Warning) ->show(); }); loadDialog.exec(update.get()); } else { CustomMessageBox::selectable( this, tr("Error"), tr("MultiMC cannot download Minecraft or update instances unless you have at least " "one account added.\nPlease add your Mojang or Minecraft account."), QMessageBox::Warning)->show(); } }
void ScriptWindow::create() { assert(InstancePtr() == NULL); // prevent double-creations InstancePtr().reset(new ScriptWindow); }
void ScriptWindow::destroy() { InstancePtr().reset(); }
// Closes the singleton log instance void LogFile::close() { // Clear the pointer, this destructs any open logfile instance InstancePtr() = LogFilePtr(); }