From 56fd4bdaa652fb2caa09c19dfb25c34db02e0d91 Mon Sep 17 00:00:00 2001 From: EndrII Date: Mon, 16 Aug 2021 18:28:19 +0300 Subject: [PATCH] added menu system --- src/Client/languages/de.ts | 8 +- src/Client/languages/en.ts | 8 +- src/Client/languages/es.ts | 8 +- src/Client/languages/fr.ts | 8 +- src/Client/languages/ja.ts | 8 +- src/Client/languages/pl.ts | 8 +- src/Client/languages/ru.ts | 8 +- src/Client/languages/tr.ts | 8 +- src/Client/languages/uk.ts | 8 +- src/Client/languages/zh.ts | 8 +- src/Core/Crawl/ipreviewscaneworld.cpp | 23 +++--- src/Core/Crawl/ipreviewscaneworld.h | 1 - src/Core/Crawl/iworld.cpp | 100 +++++++++++++++-------- src/Core/Crawl/iworld.h | 72 +++++++++------- src/Core/Crawl/previewcontrol.h | 4 - src/Core/CrawlModule/Crawl.qml | 88 +++++++++++++++++++- src/Core/CrawlModule/MainMenu.qml | 57 +------------ src/Core/CrawlModule/MainMenuButton.qml | 4 +- src/Core/CrawlModule/PreviewControl.qml | 15 +--- src/Core/CrawlModule/Scene.qml | 4 +- src/Core/private/engine.cpp | 58 +------------ src/Core/private/engine.h | 28 ------- src/CrawlAbstractLvl/abstractlevel.cpp | 6 +- src/CrawlAbstractLvl/private/absnest.cpp | 35 ++++++++ src/CrawlAbstractLvl/private/absnest.h | 32 ++++++++ src/JungleLvl/jungle.cpp | 7 +- src/JungleLvl/private/nest.cpp | 40 +++++++++ src/JungleLvl/private/nest.h | 29 +++++++ 28 files changed, 401 insertions(+), 282 deletions(-) create mode 100644 src/CrawlAbstractLvl/private/absnest.cpp create mode 100644 src/CrawlAbstractLvl/private/absnest.h create mode 100644 src/JungleLvl/private/nest.cpp create mode 100644 src/JungleLvl/private/nest.h diff --git a/src/Client/languages/de.ts b/src/Client/languages/de.ts index 2d1d3ca..c7e0ac0 100644 --- a/src/Client/languages/de.ts +++ b/src/Client/languages/de.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/en.ts b/src/Client/languages/en.ts index ee3d98a..cce6330 100644 --- a/src/Client/languages/en.ts +++ b/src/Client/languages/en.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/es.ts b/src/Client/languages/es.ts index 4924ef4..ff74d90 100644 --- a/src/Client/languages/es.ts +++ b/src/Client/languages/es.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/fr.ts b/src/Client/languages/fr.ts index ee3d98a..cce6330 100644 --- a/src/Client/languages/fr.ts +++ b/src/Client/languages/fr.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/ja.ts b/src/Client/languages/ja.ts index ee3d98a..cce6330 100644 --- a/src/Client/languages/ja.ts +++ b/src/Client/languages/ja.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/pl.ts b/src/Client/languages/pl.ts index ee3d98a..cce6330 100644 --- a/src/Client/languages/pl.ts +++ b/src/Client/languages/pl.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/ru.ts b/src/Client/languages/ru.ts index ee3d98a..cce6330 100644 --- a/src/Client/languages/ru.ts +++ b/src/Client/languages/ru.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/tr.ts b/src/Client/languages/tr.ts index ee3d98a..cce6330 100644 --- a/src/Client/languages/tr.ts +++ b/src/Client/languages/tr.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/uk.ts b/src/Client/languages/uk.ts index ee3d98a..cce6330 100644 --- a/src/Client/languages/uk.ts +++ b/src/Client/languages/uk.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Client/languages/zh.ts b/src/Client/languages/zh.ts index ee3d98a..cce6330 100644 --- a/src/Client/languages/zh.ts +++ b/src/Client/languages/zh.ts @@ -29,6 +29,10 @@ Crawl + + Please Select level. If level is not availabel please bue it first. + + DefaultMenu @@ -80,10 +84,6 @@ PreviewControl - - Back to menu. - - Start diff --git a/src/Core/Crawl/ipreviewscaneworld.cpp b/src/Core/Crawl/ipreviewscaneworld.cpp index 2b44afa..87fdb27 100644 --- a/src/Core/Crawl/ipreviewscaneworld.cpp +++ b/src/Core/Crawl/ipreviewscaneworld.cpp @@ -13,6 +13,9 @@ namespace CRAWL { IPreviewScaneWorld::IPreviewScaneWorld(const IWorld* mainWorld) { debug_assert(mainWorld, "The mainWorld world option should be initialized."); _mainWorld = mainWorld; + + setCameraReleativePosition({0, 100, 100}); + setCameraRotation(QQuaternion::fromEulerAngles(-40,0,0)); } QString IPreviewScaneWorld::itemTextId() const { @@ -50,33 +53,32 @@ bool IPreviewScaneWorld::start(const StartData& config) { worldChanged(worldRules()->cbegin()); setTargetFps(60); - setRunning(true); + setVisible(true); + startRenderLoop(); return true; } bool IPreviewScaneWorld::stop() { - setRunning(false); - reset(); + stopRenderLoopWithClearItems(); + setVisible(false); + return true; } -void IPreviewScaneWorld::handleStop() { - stop(); -} - void IPreviewScaneWorld::handleRotation(double x, double y) { - auto normal = (QQuaternion::fromEulerAngles(x, y, 0) * QVector3D{0,0,1}).normalized(); + auto rotation = cameraRotation() * QQuaternion::fromEulerAngles(x, y, 0); + auto normal = (rotation * QVector3D{0,0,1}).normalized(); setCameraReleativePosition(normal * 100); - setCameraRotation(QQuaternion::rotationTo({1.0f, 0.0, 0.0}, {0,0,0})); + setCameraRotation(rotation); } void IPreviewScaneWorld::handleStart() { auto playerObj = dynamic_cast(player()); _configuration.setSnakePerks(playerObj->activeItems()); emit sigPrepareIsFinished(_configuration); - handleStop(); + stop(); } void IPreviewScaneWorld::handleSelect(int item, bool isSelected) { @@ -97,7 +99,6 @@ void IPreviewScaneWorld::initControl(IControl *control) { auto controlObject = dynamic_cast(control); if (controlObject) { - connect(controlObject, &PreviewControl::backToMenu, this, &IPreviewScaneWorld::handleStop); connect(controlObject, &PreviewControl::mousePositionChanged, this, &IPreviewScaneWorld::handleRotation); connect(controlObject, &PreviewControl::start, this, &IPreviewScaneWorld::handleStart); connect(controlObject, &PreviewControl::select, this, &IPreviewScaneWorld::handleSelect); diff --git a/src/Core/Crawl/ipreviewscaneworld.h b/src/Core/Crawl/ipreviewscaneworld.h index 3c27a29..afedd26 100644 --- a/src/Core/Crawl/ipreviewscaneworld.h +++ b/src/Core/Crawl/ipreviewscaneworld.h @@ -50,7 +50,6 @@ signals: private slots: - void handleStop(); void handleRotation(double x, double y); void handleStart(); void handleSelect(int item, bool isSelected); diff --git a/src/Core/Crawl/iworld.cpp b/src/Core/Crawl/iworld.cpp index 51eedb5..0aed561 100644 --- a/src/Core/Crawl/iworld.cpp +++ b/src/Core/Crawl/iworld.cpp @@ -21,6 +21,7 @@ #include "diff.h" #include "eventserver.h" #include "player.h" +#include namespace CRAWL { @@ -37,6 +38,7 @@ IWorld::IWorld() { } IWorld::~IWorld() { + disconnect(); reset(); delete _eventServer; } @@ -62,11 +64,6 @@ IControl *IWorld::initUserInterface() const { void IWorld::render(unsigned int tbfMsec) { - if (!_running) { - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - return; - } - _ItemsMutex.lock(); QList toRemove; for (auto i = _items.begin(); i != _items.end(); ++i) { @@ -103,18 +100,27 @@ void IWorld::initControl(IControl *control) { bool IWorld::start(const StartData& config) { + auto player = dynamic_cast(userInterface()); + if (!player) { + QuasarAppUtils::Params::log("Failed to start world. T userIterface control should be children class of the Palyer class", + QuasarAppUtils::Error); + + return false; + } + setWorldStatus(WorldStatus::Game); backgroundAI()->stopAI(); setPlayer(initPlayer(config.snakeType())); - userInterface()->setUserData(config.player()); + player->setUserData(config.player()); worldChanged(worldRules()->cbegin()); setTargetFps(60); - setRunning(true); _eventServer->start(); setVisible(true); + startRenderLoop(); + return true; } @@ -150,9 +156,12 @@ IWorldItem *IWorld::generate(const QString &objectType) const { } bool IWorld::stop() { - setRunning(false); - setVisible(false); _eventServer->stop(); + + stopRenderLoopWithClearItems(); + setVisible(false); + + emit sigGameFinished(); return true; } @@ -167,7 +176,6 @@ IWorldItem *IWorld::getItem(int id) const { } void IWorld::clearItems() { - IWorld::stop(); while (_items.cbegin() != _items.cend()) { removeItem(*_items.cbegin()); @@ -242,6 +250,8 @@ void IWorld::removeItem(IWorldItem* item, QList *removedObjectsList) { void IWorld::reset() { + stop(); + if (_player) { _player = nullptr; } @@ -261,7 +271,6 @@ void IWorld::reset() { _backgroundAI = nullptr; } - clearItems(); setHdr(""); } @@ -317,6 +326,44 @@ void IWorld::removeAnyItemFromGroup(const QString &group, removeItem(anyObjectId, removedObjectsList); } +void IWorld::startRenderLoop() { + if (isRendering()) + return; + + _renderLoop = true; + _renderLoopFuture = QtConcurrent::run([this](){renderLoop();}); +} + +void IWorld::stopRenderLoopWithClearItems() { + stopRenderLoop(); + clearItems(); +} + +void IWorld::stopRenderLoop() { + _renderLoop = false; + _renderLoopFuture.waitForFinished(); +} + +bool IWorld::isRendering() const { + return _renderLoopFuture.isRunning(); +} + +void IWorld::renderLoop() { + + while (_renderLoop) { + + quint64 currentTime = QDateTime::currentMSecsSinceEpoch(); + + if (!_oldTimeRender) { + _oldTimeRender = currentTime; + continue; + } + + render(currentTime - _oldTimeRender); + _oldTimeRender = currentTime; + } +} + const WorldRule *IWorld::worldRules() { if (!_worldRules) @@ -334,16 +381,8 @@ void IWorld::setVisible(bool visible) { emit visibleChanged(); } -void IWorld::playerIsDead(PlayableObject *) const { - emit sigGameFinished(); -} - -bool IWorld::running() const { - return _running; -} - -void IWorld::setRunning(bool newRunning) { - _running = newRunning; +void IWorld::playerIsDead(PlayableObject *) { + stop(); } int IWorld::targetFps() const { @@ -402,10 +441,10 @@ IAI *IWorld::backgroundAI() { return _backgroundAI; } -Player *IWorld::userInterface() { +IControl *IWorld::userInterface() { if (!_userInterface) { - _userInterface = dynamic_cast(initUserInterface()); + _userInterface = initUserInterface(); initControl(_userInterface); } @@ -486,20 +525,11 @@ void IWorld::runAsBackGround() { setTargetFps(30); } -QObject *IWorld::getMenu() const { - return _menu; +QObject *IWorld::getMenu() { + return userInterface(); } -void IWorld::setMenu(QObject *newMenu) { - if (_menu == newMenu) - return; - - _menu = newMenu; - emit menuChanged(); -} - -bool IWorld::visible() const -{ +bool IWorld::visible() const { return _visible; } diff --git a/src/Core/Crawl/iworld.h b/src/Core/Crawl/iworld.h index 783e87e..30e97e8 100644 --- a/src/Core/Crawl/iworld.h +++ b/src/Core/Crawl/iworld.h @@ -13,6 +13,7 @@ #include "playableobject.h" #include "startdata.h" +#include #include #include #include @@ -67,11 +68,10 @@ class CRAWL_EXPORT IWorld : public QObject, public IRender, public IItem /** * @brief menu This propertye contains user interface model that initialised on the IWorld::userInterface method. For get more information see the IContol class. - * @see IWorld::setMenu * @see IWorld::getMenu * @see IWorld::userInterface */ - Q_PROPERTY(QObject * menu READ getMenu WRITE setMenu NOTIFY menuChanged) + Q_PROPERTY(QObject * menu READ getMenu NOTIFY menuChanged) Q_PROPERTY(QString hdr READ hdr NOTIFY hdrChanged) Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) @@ -187,7 +187,7 @@ public: * @return pointe to requaried object. * @note if you want to get ovject in the render function of another ItemWorld object then use the IWorldItem::getItem method. */ - IWorldItem *getItem(int id) const; + Q_INVOKABLE IWorldItem *getItem(int id) const; /** * @brief cameraReleativePosition return a releative of player camera position. @@ -199,7 +199,7 @@ public: * @brief userInterface This method return pointer to userinterface. * @return pointer to user interface */ - Player *userInterface(); + IControl *userInterface(); /** * @brief wordlStatus This method return current world status. @@ -246,19 +246,10 @@ public: /** * @brief menu This method return current pointer to the user interface of this world. * @return pointer of the user Interface of this world. - * @see IWorld::setMenu * @see IWorld::menu * @see IWorld::userInterface */ - QObject *getMenu() const; - /** - * @brief setMenu This method sets new user interface object fot this world. - * @param newMenu This is new object of user interfavce of this world. - * @see IWorld::getMenu - * @see IWorld::menu - * @see IWorld::userInterface - */ - void setMenu(QObject *newMenu); + QObject *getMenu(); /** * @brief reset This method reset all world objects. @@ -429,18 +420,6 @@ protected: */ void updateWorld(); - /** - * @brief running This varibale check in render function if the running is true then render loop are working correctly - * @return status of the render function - */ - bool running() const; - - /** - * @brief setRunning This method sets runnign render function status. - * @param newRunning new status of the render function - */ - void setRunning(bool newRunning); - /** * @brief worldRules This method return world cure map. * @return world rule map. @@ -456,7 +435,35 @@ protected: /** * @brief playerIsDead This method will be invoked when player object get signal dead. */ - virtual void playerIsDead(PlayableObject*) const; + virtual void playerIsDead(PlayableObject*); + + /** + * @brief isRendering This method erturn true if the render loop is working else false. + * @return true if the render loop is working else false. + * @see IWorld::stopRenderLoop + * @see IWorld::startRenderLoop + */ + bool isRendering() const; + + /** + * @brief stopRenderLoop This method stop render loop in engine. + * @see IWorld::isRendering + * @see IWorld::startRenderLoop + */ + void stopRenderLoop(); + + /** + * @brief startRenderLoop This method start render loop in engine. + * @see IWorld::stopRenderLoop + * @see IWorld::isRendering + */ + void startRenderLoop(); + + /** + * @brief stopRenderLoopWithClearItems This method stoped render loop and clear all created items. + * @see IWorld::stopRenderLoop + */ + void stopRenderLoopWithClearItems(); protected slots: virtual void onIntersects(const IWorldItem * trigger, QList list); @@ -476,7 +483,6 @@ private slots: void handleStop(); private: - /** * @brief clearItems This method remove all created items from world. */ @@ -536,6 +542,9 @@ private: void removeAnyItemFromGroup(const QString &group, QList* removedObjectsList = nullptr); + void renderLoop(); + QFuture _renderLoopFuture; + EventServer * _eventServer = nullptr; QHash _items; @@ -553,15 +562,16 @@ private: PlayableObject *_player = nullptr; IAI *_backgroundAI = nullptr; - Player *_userInterface = nullptr; - QObject *_menu = nullptr; + IControl *_userInterface = nullptr; int _worldStatus = 0; QHash> _registeredTypes; int _targetFps = 60; - bool _running = false; + quint64 _oldTimeRender = 0; + bool _visible = true; + bool _renderLoop = false; // testing friend ClastersTest; diff --git a/src/Core/Crawl/previewcontrol.h b/src/Core/Crawl/previewcontrol.h index 76922e8..cc18584 100644 --- a/src/Core/Crawl/previewcontrol.h +++ b/src/Core/Crawl/previewcontrol.h @@ -23,10 +23,6 @@ public: QString initQmlView() const override; signals: - /** - * @brief backToMenu Emit when user click the return to main menu button. - */ - void backToMenu(); /** * @brief start emited when user click start button from the preview menu. diff --git a/src/Core/CrawlModule/Crawl.qml b/src/Core/CrawlModule/Crawl.qml index bcc17b7..274d9e5 100644 --- a/src/Core/CrawlModule/Crawl.qml +++ b/src/Core/CrawlModule/Crawl.qml @@ -22,6 +22,15 @@ ApplicationWindow { Metrix {id: metrix} + Label { + anchors.fill: parent + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + font.pixelSize: 25 + wrapMode: Text.WordWrap + text: qsTr("Please Select level. If level is not availabel please bue it first.") + } + Scene { id: scane; worldModel: (model)? model.world : null; @@ -34,10 +43,83 @@ ApplicationWindow { anchors.fill: parent; } - MainMenu { + ToolButton { + text: "👾" + font.pixelSize: 35 + + onClicked: { + mainMenuPopUp.open() + } + visible: !mainMenuPopUp.visible + } + + Drawer { + id: mainMenuPopUp + closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside + + height: parent.height + width: parent.width / 3 + + MainMenu { + id: mainMenu + model: (mainWindow.model)? mainWindow.model.menu: null; + anchors.fill: parent; + } + } + + PagePopUp { + id: settingsPopUp + + source: SettingsView { + id: settingsView + model: mainMenu.model ? mainMenu.model.userSettingsModel: null + } + + standardButtons: Dialog.Save | Dialog.Cancel | Dialog.RestoreDefaults + modal: false; + width: parent.width * 0.8 + height: parent.height * 0.8; + + onAccepted: { + settingsView.save(); + } + + onReset: { + settingsView.reset(); + } + + onOpened: { + settingsView.update(); + } + + } + + PagePopUp { + id: storePopUp + source: StoreView { + id: view + model: mainMenu.model ? mainMenu.model.storeView: null + + } + + modal: false; + width: parent.width * 0.8 + height: parent.height * 0.8; + + } + + PagePopUp { + id: selectLvl + source: SelectLevelView { + id: selectLvlView + model: mainMenu.model ? mainMenu.model.selectLevelModle: null + + } + + modal: false; + width: parent.width * 0.8 + height: parent.height * 0.8; - model: (mainWindow.model)? mainWindow.model.menu: null; - anchors.fill: parent; } NotificationServiceView { diff --git a/src/Core/CrawlModule/MainMenu.qml b/src/Core/CrawlModule/MainMenu.qml index 57b80ec..f263243 100644 --- a/src/Core/CrawlModule/MainMenu.qml +++ b/src/Core/CrawlModule/MainMenu.qml @@ -29,8 +29,8 @@ Item { anchors.bottomMargin: 0 anchors.topMargin: 0 - columns: 3 - rows: 2 + columns: 1 + rows: 10 transformOrigin: Item.Center @@ -74,59 +74,6 @@ Item { } - PagePopUp { - id: settingsPopUp - source: SettingsView { - id: settingsView - model: root.model ? root.model.userSettingsModel: null - } - - standardButtons: Dialog.Save | Dialog.Cancel | Dialog.RestoreDefaults - modal: false; - width: parent.width * 0.8 - height: parent.height * 0.8; - - onAccepted: { - settingsView.save(); - } - - onReset: { - settingsView.reset(); - } - - onOpened: { - settingsView.update(); - } - - } - - PagePopUp { - id: storePopUp - source: StoreView { - id: view - model: root.model ? root.model.storeView: null - - } - - modal: false; - width: parent.width * 0.8 - height: parent.height * 0.8; - - } - - PagePopUp { - id: selectLvl - source: SelectLevelView { - id: selectLvlView - model: root.model ? root.model.selectLevelModle: null - - } - - modal: false; - width: parent.width * 0.8 - height: parent.height * 0.8; - - } } diff --git a/src/Core/CrawlModule/MainMenuButton.qml b/src/Core/CrawlModule/MainMenuButton.qml index fd6b666..1675f23 100644 --- a/src/Core/CrawlModule/MainMenuButton.qml +++ b/src/Core/CrawlModule/MainMenuButton.qml @@ -13,12 +13,12 @@ import QtQuick.Layouts Button { id: exit Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter - font.pixelSize: height * 0.1 + font.pixelSize: height * 0.2 display: AbstractButton.TextBesideIcon spacing: 4 focusPolicy: Qt.StrongFocus Layout.preferredHeight: parent.height / (parent.rows + 1) - Layout.preferredWidth: parent.width / (parent.columns + 1) + Layout.preferredWidth: parent.width / (parent.columns + 0.5) } diff --git a/src/Core/CrawlModule/PreviewControl.qml b/src/Core/CrawlModule/PreviewControl.qml index da6555b..094ef71 100644 --- a/src/Core/CrawlModule/PreviewControl.qml +++ b/src/Core/CrawlModule/PreviewControl.qml @@ -23,10 +23,6 @@ AbstractMenuView { Layout.columnSpan: 4 Layout.rowSpan: 1 - onClicked: { - model.userTap() - } - property bool track: false property real oldX: 0 @@ -65,20 +61,11 @@ AbstractMenuView { } } - Button { - text: qsTr("Back to menu.") - onClicked: { - if (model) { - model.backToMenu() - } - } - } - Button { text: qsTr("Start") onClicked: { if (model) { - model.backToMenu() + model.start() } } } diff --git a/src/Core/CrawlModule/Scene.qml b/src/Core/CrawlModule/Scene.qml index 7a0c816..7813252 100644 --- a/src/Core/CrawlModule/Scene.qml +++ b/src/Core/CrawlModule/Scene.qml @@ -56,10 +56,10 @@ View3D { return; } - const objModel = model.getGameObject(cppObjId); + const objModel = worldModel.getItem(cppObjId); if (!objModel) { - console.log("object model not found"); + console.log("model of the crawl object is not found"); return; } diff --git a/src/Core/private/engine.cpp b/src/Core/private/engine.cpp index 779d608..7be0bff 100644 --- a/src/Core/private/engine.cpp +++ b/src/Core/private/engine.cpp @@ -32,15 +32,16 @@ Engine::Engine(QObject *parent): QObject(parent) { } Engine::~Engine() { - stopRenderLoop(); - delete _menu; - delete _currentUser; + for (auto it = _availableLvls.begin(); it != _availableLvls.end(); ++it) { delete it.value(); } _availableLvls.clear(); + + delete _menu; + delete _currentUser; } QObject *Engine::scane() { @@ -86,9 +87,6 @@ void Engine::setLevel(ILevel *world) { return; } - startRenderLoop(); - _currentLevel->world()->runAsBackGround(); - connect(_currentLevel->previewScane(), &IPreviewScaneWorld::sigPrepareIsFinished, this, &Engine::start); @@ -136,11 +134,6 @@ void Engine::stop() const { if (!_currentLevel) return; - - if (!_currentLevel->world()->stop()) { - return; - } - _currentLevel->previewScane()->start(_currentLevel->previewScane()->configuration()); } @@ -179,49 +172,6 @@ ILevel *Engine::getLastLevel() { return nullptr; } -QObject *Engine::getGameObject(int id) const { - if (!_currentLevel) - return nullptr; - - return _currentLevel->world()->getItem(id); -} - -void Engine::startRenderLoop() { - if (isRendering()) - return; - - _renderLoop = true; - _renderLoopFuture = QtConcurrent::run([this](){renderLoop();}); -} - -void Engine::stopRenderLoop() { - _renderLoop = false; - _renderLoopFuture.waitForFinished(); -} - -bool Engine::isRendering() const { - return _renderLoopFuture.isRunning(); -} - -void Engine::renderLoop() { - - if (!_currentLevel) - return; - - while (_renderLoop) { - - quint64 currentTime = QDateTime::currentMSecsSinceEpoch(); - - if (!_oldTimeRender) { - _oldTimeRender = currentTime; - continue; - } - - _currentLevel->world()->render(currentTime - _oldTimeRender); - _oldTimeRender = currentTime; - } -} - QObject *Engine::menu() const { return _menu; } diff --git a/src/Core/private/engine.h b/src/Core/private/engine.h index ee47429..5e2af5d 100644 --- a/src/Core/private/engine.h +++ b/src/Core/private/engine.h @@ -77,29 +77,6 @@ public: */ QObject* world() const; - /** - * @brief getGameObject This method using in qml for getting main model of the gui objects. - * @param id This is id of the gui object. - * @return pointer to game object model - */ - Q_INVOKABLE QObject *getGameObject(int id) const; - - /** - * @brief startRenderLoop This method start render loop in engine. - */ - void startRenderLoop(); - - /** - * @brief stopRenderLoop This method stop render loop in engine. - */ - void stopRenderLoop(); - - /** - * @brief isRendering This method erturn true if the render loop is working else false. - * @return true if the render loop is working else false. - */ - bool isRendering() const; - /** * @brief currentUser This method return pointer too current user. * @return pointer too current user. @@ -197,13 +174,8 @@ private: MainMenuModel *_menu = nullptr; - quint64 _oldTimeRender = 0; - User *_currentUser = nullptr; Store *_store = nullptr; - - QFuture _renderLoopFuture; - bool _renderLoop = false; }; } diff --git a/src/CrawlAbstractLvl/abstractlevel.cpp b/src/CrawlAbstractLvl/abstractlevel.cpp index c688db5..69329bf 100644 --- a/src/CrawlAbstractLvl/abstractlevel.cpp +++ b/src/CrawlAbstractLvl/abstractlevel.cpp @@ -8,9 +8,13 @@ #include "abstractlevel.h" #include "abslvlworld.h" +#include + AbstractLevel::AbstractLevel() { initAbstractLvlResources(); - setWorld(new AbstractLvl::AbsLvlWorld()); + auto world = new AbstractLvl::AbsLvlWorld(); + setWorld(world); + setPreviewScane(new AbstractLvl::AbsNest(world)); } diff --git a/src/CrawlAbstractLvl/private/absnest.cpp b/src/CrawlAbstractLvl/private/absnest.cpp new file mode 100644 index 0000000..dfa0994 --- /dev/null +++ b/src/CrawlAbstractLvl/private/absnest.cpp @@ -0,0 +1,35 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "absnest.h" +#include "obstacleblue.h" + +#include + +namespace AbstractLvl { + +AbsNest::AbsNest(IWorld * mainWorld): CRAWL::IPreviewScaneWorld(mainWorld) { + +} + +CRAWL::WorldRule *AbsNest::initWorldRules() { + return new CRAWL::WorldRule { + {0, + { + {registerObject(), 1}, + {registerObject(), 1} + } + } + + }; +} + +QString AbsNest::initHdrBackGround() const { + return ""; +} + +} diff --git a/src/CrawlAbstractLvl/private/absnest.h b/src/CrawlAbstractLvl/private/absnest.h new file mode 100644 index 0000000..ae61e1d --- /dev/null +++ b/src/CrawlAbstractLvl/private/absnest.h @@ -0,0 +1,32 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + + +#ifndef ABSNEST_H +#define ABSNEST_H +#include + + +namespace AbstractLvl { + +/** + * @brief The AbsNest class Abstrcat nest level + */ +class AbsNest: public CRAWL::IPreviewScaneWorld +{ +public: + AbsNest(IWorld *mainWorld); + + // IWorld interface +public: + CRAWL::WorldRule *initWorldRules() override; + QString initHdrBackGround() const override; + +}; + +} +#endif // ABSNEST_H diff --git a/src/JungleLvl/jungle.cpp b/src/JungleLvl/jungle.cpp index 971b4b1..cddf393 100644 --- a/src/JungleLvl/jungle.cpp +++ b/src/JungleLvl/jungle.cpp @@ -8,9 +8,14 @@ #include "jungle.h" #include "world.h" +#include "nest.h" Jungle::Jungle() { initJungleLvlResources(); - setWorld(new JungleLvl::World()); + auto world = new JungleLvl::World(); + + setWorld(world); + + setPreviewScane(new JungleLvl::Nest(world)); } diff --git a/src/JungleLvl/private/nest.cpp b/src/JungleLvl/private/nest.cpp new file mode 100644 index 0000000..fb44087 --- /dev/null +++ b/src/JungleLvl/private/nest.cpp @@ -0,0 +1,40 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "absaluteplate.h" +#include "grees.h" +#include "ground.h" +#include "nest.h" + +#include +#include +#include + +namespace JungleLvl { + +Nest::Nest(IWorld *mainWorld): CRAWL::IPreviewScaneWorld(mainWorld) { + +} + +CRAWL::WorldRule *Nest::initWorldRules() { + using Day = CRAWL::Day; + + return new CRAWL::WorldRule { + {0, { + {registerObject(), 1}, + {registerObject(), 1}, + {registerObject(), 1}, + {registerObject(), 500} + } + } + }; +} + +QString Nest::initHdrBackGround() const { + return ""; +} +} diff --git a/src/JungleLvl/private/nest.h b/src/JungleLvl/private/nest.h new file mode 100644 index 0000000..12e8f30 --- /dev/null +++ b/src/JungleLvl/private/nest.h @@ -0,0 +1,29 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the GPLv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef NEST_H +#define NEST_H +#include + +namespace JungleLvl { + +/** + * @brief The Nest class + */ +class Nest: public CRAWL::IPreviewScaneWorld +{ +public: + Nest(IWorld *mainWorld); + + // IWorld interface +public: + CRAWL::WorldRule *initWorldRules() override; + QString initHdrBackGround() const override; +}; + +} +#endif // NEST_H