From fc0b60f15ffefd2a98a2947b40381b640ce406f2 Mon Sep 17 00:00:00 2001 From: EndrII Date: Thu, 15 Jul 2021 00:48:28 +0300 Subject: [PATCH] ref #88 added trees and grees --- src/Core/Crawl/guiobject.h | 3 +++ src/Core/Crawl/iworld.cpp | 26 +++++++++++++++++--- src/Core/Crawl/iworld.h | 31 ++++++++++++++++++++---- src/Core/CrawlModule/Scene.qml | 2 ++ src/JungleLvl/private/grees.cpp | 24 +++++++++++++++++++ src/JungleLvl/private/grees.h | 32 +++++++++++++++++++++++++ src/JungleLvl/private/longgress.cpp | 21 ++++++++++++++++ src/JungleLvl/private/longgress.h | 32 +++++++++++++++++++++++++ src/JungleLvl/private/tree.cpp | 37 +++++++++++++++++++++++++++++ src/JungleLvl/private/tree.h | 30 +++++++++++++++++++++++ src/JungleLvl/private/world.cpp | 19 ++++++++++++++- 11 files changed, 248 insertions(+), 9 deletions(-) create mode 100644 src/JungleLvl/private/grees.cpp create mode 100644 src/JungleLvl/private/grees.h create mode 100644 src/JungleLvl/private/longgress.cpp create mode 100644 src/JungleLvl/private/longgress.h create mode 100644 src/JungleLvl/private/tree.cpp create mode 100644 src/JungleLvl/private/tree.h diff --git a/src/Core/Crawl/guiobject.h b/src/Core/Crawl/guiobject.h index 45c59d5..0f914ac 100644 --- a/src/Core/Crawl/guiobject.h +++ b/src/Core/Crawl/guiobject.h @@ -16,6 +16,9 @@ #include "Crawl/irender.h" #define DEFAULT_VIEW_TEMPLATE "qrc:/CrawlModule/GraphicItem.qml" +/** the AUTO_CLASS_NAME define gets name from the class and namespace. + */ +#define AUTO_CLASS_NAME typeid(this).name() namespace CRAWL { diff --git a/src/Core/Crawl/iworld.cpp b/src/Core/Crawl/iworld.cpp index 2fbb6ab..d6c4fbd 100644 --- a/src/Core/Crawl/iworld.cpp +++ b/src/Core/Crawl/iworld.cpp @@ -24,7 +24,8 @@ namespace CRAWL { IWorld::IWorld() { - + qRegisterMetaType("WorldRule::const_iterator"); + connect(this, &IWorld::sigWorldChanged, this, &IWorld::worldChanged, Qt::QueuedConnection); } IWorld::~IWorld() { @@ -62,6 +63,7 @@ void IWorld::render(unsigned int tbfMsec) { emit sigGameFinished(_player->getCurrentStatus()); } + updateWorld(); int waitTime = 1000 / _targetFps - tbfMsec; if (waitTime > 0) @@ -84,7 +86,7 @@ bool IWorld::start() { _player->setControl(_userInterface); - worldChanged(*_worldRules->begin()); + worldChanged(_worldRules->cbegin()); setTargetFps(60); setRunning(true); @@ -338,6 +340,18 @@ void IWorld::setHdr(const QString &hdr) { emit hdrChanged(); } +void IWorld::updateWorld() { + + if (_currendWorldLevel->isEmpty() || !_worldRules || !_player) + return; + + float distance = _player->position().x(); + auto nextLevel = _currendWorldLevel + 1; + if (nextLevel != _worldRules->cend() && distance > nextLevel.key()) { + emit sigWorldChanged(nextLevel); + } +} + const QQuaternion &IWorld::cameraRatation() const { return _cameraRatation; } @@ -377,8 +391,12 @@ const QVector3D &IWorld::cameraReleativePosition() const { return _cameraReleativePosition; } -void IWorld::worldChanged(WorldObjects objects) { +void IWorld::worldChanged(WorldRule::const_iterator iterator) { + if (_currendWorldLevel == iterator) + return; + + auto objects = iterator.value(); objects[_player->className()] = 1; for (auto it = objects.begin(); it != objects.end(); ++it) { @@ -395,6 +413,8 @@ void IWorld::worldChanged(WorldObjects objects) { } } } + + _currendWorldLevel = iterator; } int IWorld::wordlStatus() const { diff --git a/src/Core/Crawl/iworld.h b/src/Core/Crawl/iworld.h index 58e244b..3e22042 100644 --- a/src/Core/Crawl/iworld.h +++ b/src/Core/Crawl/iworld.h @@ -276,6 +276,13 @@ signals: */ void hdrChanged(); + /** + * @brief sigWorldChanged emit this signal if you want to change level of the world. + * @note this signal needed for the move WorldChange method into main thread. + * @param objects this is iterator of the world rule object. + */ + void sigWorldChanged(WorldRule::const_iterator objects); + protected: /** @@ -369,6 +376,11 @@ protected: return type; } + /** + * @brief updateWorld This method check current distance and load neede level and level objects. + */ + void updateWorld(); + private slots: /** @@ -376,6 +388,13 @@ private slots: */ void handleStop(); + /** + * @brief worldChanged This method generate diff for the qml + * @param objects This is iterator of the world rules object that contains list of object on lvl + * @note This method addd player object to this list. + */ + void worldChanged(WorldRule::const_iterator objects); + private: /** * @brief prepare This method initialize world object. @@ -383,6 +402,10 @@ private: * @return true if world initialized successful */ bool prepare(); + + /** + * @brief reset This method reset all world objects. + */ void reset(); @@ -399,12 +422,8 @@ private: void setRunning(bool newRunning); /** - * @brief worldChanged This method generate diff for the qml - * @param objects This is list of object on lvl - * @note This method addd player object to this list. + * @brief clearItems This method remove all created items from world. */ - void worldChanged(WorldObjects objects); - void clearItems(); /** @@ -472,6 +491,8 @@ private: QString _hdrMap; WorldRule *_worldRules = nullptr; + WorldRule::const_iterator _currendWorldLevel; + IPlayer *_player = nullptr; IControl *_userInterface = nullptr; IAI *_backgroundAI = nullptr; diff --git a/src/Core/CrawlModule/Scene.qml b/src/Core/CrawlModule/Scene.qml index 2a0bb42..06db392 100644 --- a/src/Core/CrawlModule/Scene.qml +++ b/src/Core/CrawlModule/Scene.qml @@ -89,7 +89,9 @@ View3D { for (var i = 0; i < arrayObjects.length; ++i) { if (id === arrayObjects[i].guiId) { + arrayObjects[i].destroy(); arrayObjects.splice(i,1); + } } } diff --git a/src/JungleLvl/private/grees.cpp b/src/JungleLvl/private/grees.cpp new file mode 100644 index 0000000..d449234 --- /dev/null +++ b/src/JungleLvl/private/grees.cpp @@ -0,0 +1,24 @@ +//# +//# 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 "grees.h" + +namespace JungleLvl { + +Grees::Grees(): CRAWL::IWorldItem(AUTO_CLASS_NAME) { + setMash("qrc:/mesh/meshes/Plant/Grass.mesh"); + setBaseColorMap("qrc:/mesh/meshes/Plant/Grass_Base.jpg"); + setSize({1,1,1}); + setRatation(QQuaternion::fromEulerAngles({0,0, static_cast(rand() % 360)})); + +} + +void Grees::onIntersects(const IWorldItem *) { + +} + +} diff --git a/src/JungleLvl/private/grees.h b/src/JungleLvl/private/grees.h new file mode 100644 index 0000000..712187e --- /dev/null +++ b/src/JungleLvl/private/grees.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 GREES_H +#define GREES_H + +#include +#include + +namespace JungleLvl { + +/** + * @brief The Grees class + */ +class CRAWL_JUNGLE_LEVEL_EXPORT Grees: public CRAWL::IWorldItem +{ + Q_OBJECT +public: + Grees(); + + // IWorldItem interface +protected: + void onIntersects(const IWorldItem *item) override; +}; +} +#endif // GREES_H diff --git a/src/JungleLvl/private/longgress.cpp b/src/JungleLvl/private/longgress.cpp new file mode 100644 index 0000000..b21c59c --- /dev/null +++ b/src/JungleLvl/private/longgress.cpp @@ -0,0 +1,21 @@ +//# +//# 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 "longgress.h" +namespace JungleLvl { + +LongGress::LongGress(): CRAWL::IWorldItem(AUTO_CLASS_NAME) { + setMash("qrc:/mesh/meshes/Plant/Long_grass.mesh"); + setBaseColorMap("qrc:/mesh/meshes/Plant/LongGrass_Base.jpg"); + setSize({1,1,1}); + setRatation(QQuaternion::fromEulerAngles({0,0, static_cast(rand() % 360)})); +} + +void LongGress::onIntersects(const IWorldItem *) { + +} +} diff --git a/src/JungleLvl/private/longgress.h b/src/JungleLvl/private/longgress.h new file mode 100644 index 0000000..2e495ed --- /dev/null +++ b/src/JungleLvl/private/longgress.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 LONGGRESS_H +#define LONGGRESS_H + +#include +#include + + +namespace JungleLvl { + +class CRAWL_JUNGLE_LEVEL_EXPORT LongGress: public CRAWL::IWorldItem +{ + Q_OBJECT + +public: + LongGress(); + + // IWorldItem interface +protected: + void onIntersects(const IWorldItem *item) override; +}; + +} + +#endif // LONGGRESS_H diff --git a/src/JungleLvl/private/tree.cpp b/src/JungleLvl/private/tree.cpp new file mode 100644 index 0000000..50647be --- /dev/null +++ b/src/JungleLvl/private/tree.cpp @@ -0,0 +1,37 @@ +//# +//# 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 "tree.h" +namespace JungleLvl { + +Tree::Tree(): CRAWL::IWorldItem(AUTO_CLASS_NAME) { + + QStringList mashes { + "qrc:/mesh/meshes/Plant/Tree_1.mesh", + "qrc:/mesh/meshes/Plant/Tree_2.mesh", + "qrc:/mesh/meshes/Plant/Tree_3.mesh", + "qrc:/mesh/meshes/Plant/Tree_4.mesh", + "qrc:/mesh/meshes/Plant/Tree_5.mesh", + "qrc:/mesh/meshes/Plant/Tree_6.mesh", + + }; + + setMash(mashes[rand() % mashes.size()]); + setBaseColorMap("qrc:/mesh/meshes/Plant/Tree_Base.jpg"); + setSize({1,1,1}); + setRatation(QQuaternion::fromEulerAngles({static_cast(rand() % 60 - 30), + static_cast(rand() % 60 - 30), + static_cast(rand() % 360)})); + + if (rand() % 2) + setZ(-static_cast(rand() % 10)); +} + +void Tree::onIntersects(const IWorldItem *) { + +} +} diff --git a/src/JungleLvl/private/tree.h b/src/JungleLvl/private/tree.h new file mode 100644 index 0000000..32975b1 --- /dev/null +++ b/src/JungleLvl/private/tree.h @@ -0,0 +1,30 @@ +//# +//# 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 TREE_H +#define TREE_H + +#include +#include + +namespace JungleLvl { + +/** + * @brief The Tree class + */ +class CRAWL_JUNGLE_LEVEL_EXPORT Tree : public CRAWL::IWorldItem +{ + Q_OBJECT +public: + Tree(); + + // IWorldItem interface +protected: + void onIntersects(const IWorldItem *) override; +}; +} +#endif // TREE_H diff --git a/src/JungleLvl/private/world.cpp b/src/JungleLvl/private/world.cpp index 0237550..2b6185c 100644 --- a/src/JungleLvl/private/world.cpp +++ b/src/JungleLvl/private/world.cpp @@ -5,8 +5,11 @@ //# of this license document, but changing it is not allowed. //# +#include "grees.h" #include "ground.h" +#include "longgress.h" #include "snake.h" +#include "tree.h" #include "world.h" #include "Crawl/iworlditem.h" @@ -21,7 +24,21 @@ World::World() { CRAWL::WorldRule *World::initWorldRules() { return new CRAWL::WorldRule { {0, { - {registerObject(), 1}}} + {registerObject(), 1}, + {registerObject(), 500}, + {registerObject(), 100}, + {registerObject(), 0} + + } + }, + {500, { + {registerObject(), 1}, + {registerObject(), 500}, + {registerObject(), 100}, + {registerObject(), 100} + + } + } }; }