void FastQSPWindow::openFile(const QString &filename) { qspFilePath = filename; builder.clear(); if (gameIsOpen) autosave(); gameDirectory = QFileInfo(filename).absolutePath() + "/"; if (!QSPLoadGameWorld(filename.toStdWString().c_str(), &gameDirectory)) qCritical() << QString("Could not open file: ") << filename; if (QSPRestartGame(QSP_TRUE)) { gameMenu->setEnabled(true); builder.setGameDir(gameDirectory); netManager.setGameDirectory(gameDirectory); loadFonts(); QFile configFile(gameDirectory + QLatin1String("config.xml")); if (configFile.open(QFile::ReadOnly)) { QTextStream stream(&configFile); QString config = stream.readLine(); configFile.close(); QRegExp re; re.setMinimal(true); re.setPattern("width=\"(\\d+)\""); if (re.indexIn(config)) gameWidth = re.cap(1).toInt(); else gameWidth = 800; re.setPattern("height=\"(\\d+)\""); if (re.indexIn(config) > 0) gameHeight = re.cap(1).toInt(); else gameHeight = 600; aspectRatio = qreal(gameWidth) / qreal(gameHeight); re.setPattern("title=\"(.+)\""); if (re.indexIn(config) >= 0) setWindowTitle(re.cap(1)); else setWindowTitle("FastQSP"); re.setPattern("icon=\"(.+)\""); if (re.indexIn(config) >= 0) QApplication::setWindowIcon(QIcon(gameDirectory + re.cap(1))); } aspectRatio = qreal(gameWidth) / qreal(gameHeight); loadPage(); webView->resize(gameWidth, gameHeight); resize(gameWidth, gameHeight); gameIsOpen = true; saveDir = gameDirectory + "save/"; if (!saveDir.exists()) { saveDir.mkpath("."); } timer.restart(); } }
void QSPCallBacks::OpenGame(QSPString file, QSP_BOOL isNewGame) { if (m_frame->IsQuit()) return; if (QSPLoadGameWorld(file, isNewGame) && isNewGame) { wxFileName fileName(wxString(file.Str, file.End)); m_gamePath = fileName.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); m_frame->UpdateGamePath(m_gamePath); } }
void *QSPThreadProc(void *ptr) { // (QSPEvent != QSP_EVT_EXIT) while (true) { //pthread_mutex_lock(&qsp_mutex); while (!qsp_events.empty()) { QspEvent ev = qsp_events.front(); switch (ev.type) { case QSP_EVT_EXIT: return 0; case QSP_EVT_OPENGAME: if (!QSPLoadGameWorld(ev.p_str.c_str())) ShowError(); else { chdir(GetQuestPath().c_str()); QSPRestartGame(QSP_TRUE); } break; case QSP_EVT_RESTART: if (!QSPRestartGame(QSP_TRUE)) ShowError(); break; case QSP_EVT_SAVEGAME: if (!QSPSaveGame((QSP_CHAR *) ev.p_str.c_str(), QSP_FALSE)) ShowError(); break; case QSP_EVT_OPENSAVEDGAME: if (!QSPOpenSavedGame((QSP_CHAR *) ev.p_str.c_str(), QSP_TRUE)) ShowError(); break; case QSP_EVT_EXECSTRING: if (!QSPExecString((const QSP_CHAR *)ev.p_str.c_str(), QSP_TRUE)) ShowError(); else if(ev.p_str.find("OPENQST")!=ev.p_str.npos){ chdir(GetQuestPath().c_str()); } break; case QSP_EVT_EXECSELACTION: if (!QSPExecuteSelActionCode(QSP_TRUE)) ShowError(); break; case QSP_EVT_SETOBJINDEX: if (!QSPSetSelObjectIndex(ev.p_int, QSP_TRUE)) ShowError(); break; case QSP_EVT_SETUSERINPUT: QSPSetInputStrText(ev.p_str.c_str()); break; case QSP_EVT_EXECUSERINPUT: if (!QSPExecUserInput(QSP_TRUE)) ShowError(); break; case QSP_EVT_DONEMENU: QSPSelectMenuItem(ev.p_int); break; default: usleep(500); } qsp_events.pop(); } QSPEventProcessed = true; //pthread_mutex_unlock(&qsp_mutex); usleep(500); } return 0; }