mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-10 08:29:44 +00:00
added clasters items
This commit is contained in:
parent
262efb493a
commit
eb29d8fcac
27
src/Core/Crawl/clasteritem.cpp
Normal file
27
src/Core/Crawl/clasteritem.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
//#
|
||||
//# 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 "claster.h"
|
||||
#include "clasteritem.h"
|
||||
|
||||
ClasterItem::ClasterItem() {
|
||||
|
||||
}
|
||||
|
||||
ClasterItem::~ClasterItem() {
|
||||
if (parentClasters().size() && *parentClasters().begin()) {
|
||||
(*parentClasters().begin())->remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ClasterItem::setClaster(Claster *claster) {
|
||||
_parentClasters += claster;
|
||||
}
|
||||
|
||||
const QSet<Claster *> &ClasterItem::parentClasters() const {
|
||||
return _parentClasters;
|
||||
}
|
54
src/Core/Crawl/clasteritem.h
Normal file
54
src/Core/Crawl/clasteritem.h
Normal file
@ -0,0 +1,54 @@
|
||||
//#
|
||||
//# 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 "iworlditem.h"
|
||||
|
||||
#include <QSet>
|
||||
|
||||
|
||||
#ifndef CLASTERITEM_H
|
||||
#define CLASTERITEM_H
|
||||
|
||||
class Claster;
|
||||
|
||||
/**
|
||||
* @brief The ClasterItem class This is item of the claster object. Thi class can be used as a one element of the claster class.
|
||||
* @note This object invoke the Claster::remove method in destructor.
|
||||
*/
|
||||
class ClasterItem: public IWorldItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ClasterItem();
|
||||
~ClasterItem();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief setClaster invoked when object added to new claster.
|
||||
* @param claster pointer to invoker claster object.
|
||||
*/
|
||||
virtual void setClaster(Claster *claster);
|
||||
|
||||
/**
|
||||
* @brief removeClaster
|
||||
* @param claster
|
||||
*/
|
||||
virtual void removeClaster(Claster *claster);
|
||||
|
||||
/**
|
||||
* @brief parentClasters return current parent clasters list;
|
||||
* @return
|
||||
*/
|
||||
const QSet<Claster *> &parentClasters() const;
|
||||
private:
|
||||
|
||||
QSet<Claster*> _parentClasters;
|
||||
|
||||
friend class Claster;
|
||||
};
|
||||
|
||||
#endif // CLASTERITEM_H
|
@ -5,6 +5,7 @@
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include "claster.h"
|
||||
#include "iai.h"
|
||||
#include "iworld.h"
|
||||
#include "iworlditem.h"
|
||||
@ -80,11 +81,11 @@ void IWorld::setPlayer(QObject *newPlayer) {
|
||||
}
|
||||
|
||||
if (_player) {
|
||||
removeItem(_player->guiId());
|
||||
removeIAtomictem(_player->guiId());
|
||||
}
|
||||
|
||||
_player = newPlayerObject;
|
||||
addItem("player", _player);
|
||||
addAtomicItem("player", _player);
|
||||
|
||||
emit playerChanged();
|
||||
}
|
||||
@ -146,6 +147,22 @@ void IWorld::clearItems() {
|
||||
_items.clear();
|
||||
}
|
||||
|
||||
void IWorld::addItem(IWorldItem *obj) {
|
||||
// Work wih claster
|
||||
if (auto claster = dynamic_cast<Claster*>(obj)) {
|
||||
|
||||
return;
|
||||
}
|
||||
// Work With atomic items
|
||||
|
||||
}
|
||||
|
||||
void IWorld::removeItem(int id) {
|
||||
// Work wih claster
|
||||
|
||||
// Work With atomic items
|
||||
}
|
||||
|
||||
void IWorld::deinit() {
|
||||
if (_player) {
|
||||
delete _player;
|
||||
@ -173,12 +190,12 @@ void IWorld::deinit() {
|
||||
}
|
||||
|
||||
|
||||
void IWorld::addItem(const QString& group, IWorldItem* obj) {
|
||||
void IWorld::addAtomicItem(const QString& group, IWorldItem* obj) {
|
||||
_items.insert(obj->guiId(), WorldObjectWraper{obj, group});
|
||||
_itemsGroup.insert(group, obj->guiId());
|
||||
}
|
||||
|
||||
bool IWorld::removeItem(int id) {
|
||||
bool IWorld::removeIAtomictem(int id) {
|
||||
auto obj = _items.value(id);
|
||||
|
||||
if (!obj.objectPtr) {
|
||||
@ -193,9 +210,9 @@ bool IWorld::removeItem(int id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int IWorld::removeAnyItemFromGroup(const QString &group) {
|
||||
int IWorld::removeAnyAtomicItemFromGroup(const QString &group) {
|
||||
int anyObjectId = _itemsGroup.value(group);
|
||||
if (!removeItem(anyObjectId)) {
|
||||
if (!removeIAtomictem(anyObjectId)) {
|
||||
return false;
|
||||
|
||||
}
|
||||
@ -268,12 +285,12 @@ void IWorld::worldChanged(const WorldObjects &objects) {
|
||||
break;
|
||||
}
|
||||
|
||||
addItem(it.key(), obj);
|
||||
addAtomicItem(it.key(), obj);
|
||||
diff.addedIds.append(obj->guiId());
|
||||
}
|
||||
} else {
|
||||
for (; count < 0; ++count ) {
|
||||
int removedObjectId = removeAnyItemFromGroup(it.key());
|
||||
int removedObjectId = removeAnyAtomicItemFromGroup(it.key());
|
||||
if (!removedObjectId) {
|
||||
QuasarAppUtils::Params::log("World::changeCountObjects error delete object!",
|
||||
QuasarAppUtils::Warning);
|
||||
|
@ -311,22 +311,39 @@ private:
|
||||
|
||||
void worldChanged(const WorldObjects& objects);
|
||||
void clearItems();
|
||||
void addItem(const QString &group, IWorldItem *obj);
|
||||
|
||||
/**
|
||||
* @brief removeItem This method remove object with @a id.
|
||||
* @brief addItem This method remove object from the scane. If object are calster then this method remove all child objects.
|
||||
* @param obj pointer to any engine object.
|
||||
*/
|
||||
void addItem(IWorldItem *obj);
|
||||
|
||||
/**
|
||||
* @brief removeItem This method remove item from the world. If the @a id are id of the claster object then its child object will be removed too.
|
||||
*/
|
||||
void removeItem(int id);
|
||||
|
||||
/**
|
||||
* @brief addAtomicItem This method execure atomic operation of add new item. This method support only atomic objects. (not clasters)
|
||||
* @param group This is group of the atomic object.
|
||||
* @param obj This is pointer to the atomic object. If the object are claster then it will be added without childs objects.
|
||||
*/
|
||||
void addAtomicItem(const QString &group, IWorldItem *obj);
|
||||
|
||||
/**
|
||||
* @brief removeIAtomictem This method remove object with @a id. This method work with atomic objects only. If you rty remove claster objects then it will be ramoved witohout child objects.
|
||||
* @param id This is id of removed objects.
|
||||
* @return return true if object remove successul
|
||||
*/
|
||||
bool removeItem(int id);
|
||||
bool removeIAtomictem(int id);
|
||||
|
||||
/**
|
||||
* @brief removeAnyItemFromGroup This method remove any object from group and return id of removed object.
|
||||
* @brief removeAnyAtomicItemFromGroup This method remove any object from group and return id of removed object.
|
||||
* @param group This is name of the objects group
|
||||
* @return id of removed object.
|
||||
* @note if object not removed return 0
|
||||
*/
|
||||
int removeAnyItemFromGroup(const QString &group);
|
||||
int removeAnyAtomicItemFromGroup(const QString &group);
|
||||
|
||||
QHash<int, WorldObjectWraper> _items;
|
||||
QMultiHash<QString, int> _itemsGroup;
|
||||
|
@ -8,15 +8,20 @@
|
||||
|
||||
#include "claster.h"
|
||||
#include "singleclasterworlditem.h"
|
||||
#include "quasarapp.h"
|
||||
|
||||
SingleClasterWorldItem::SingleClasterWorldItem() {
|
||||
|
||||
}
|
||||
|
||||
void SingleClasterWorldItem::setClaster(Claster *claster) {
|
||||
if (_parentClaster) {
|
||||
_parentClaster->remove(guiId());
|
||||
if (parentClasters().size() > 0) {
|
||||
debug_assert(parentClasters().size() > 1, "Internal error occured, The singleClaster object have multiple claster parents!!");
|
||||
|
||||
Claster* parent = *parentClasters().begin();
|
||||
parent->remove(this);
|
||||
removeClaster(parent);
|
||||
}
|
||||
|
||||
_parentClaster = claster;
|
||||
ClasterItem::setClaster(claster);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
#ifndef SINGLECLASTERWORLDITEM_H
|
||||
#define SINGLECLASTERWORLDITEM_H
|
||||
|
||||
#include "iworlditem.h"
|
||||
#include "clasteritem.h"
|
||||
|
||||
class Claster;
|
||||
|
||||
@ -17,8 +17,9 @@ class Claster;
|
||||
* @brief The SingleClasterWorldItem class This is wraper of the OWorldOitem for the controll parent clasters.
|
||||
* This object can belong to only one cluster in one time
|
||||
*/
|
||||
class CRAWL_EXPORT SingleClasterWorldItem: public IWorldItem
|
||||
class CRAWL_EXPORT SingleClasterWorldItem: public ClasterItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SingleClasterWorldItem();
|
||||
|
||||
@ -27,10 +28,9 @@ private:
|
||||
/**
|
||||
* @brief setClaster invoked when object added to new claster.
|
||||
* @param claster pointer to invoker claster object.
|
||||
* @note This implementation can be sets only one object as a parent.
|
||||
*/
|
||||
void setClaster(Claster *claster);
|
||||
|
||||
Claster* _parentClaster = nullptr;
|
||||
void setClaster(Claster *claster) override;
|
||||
|
||||
friend class Claster;
|
||||
};
|
||||
|
18
tests/units/clasterstest.cpp
Normal file
18
tests/units/clasterstest.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
//#
|
||||
//# Copyright (C) 2020-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 "clasterstest.h"
|
||||
#include <QtTest>
|
||||
|
||||
ClastersTest::ClastersTest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ClastersTest::test() {
|
||||
QVERIFY(false);
|
||||
}
|
27
tests/units/clasterstest.h
Normal file
27
tests/units/clasterstest.h
Normal file
@ -0,0 +1,27 @@
|
||||
//#
|
||||
//# Copyright (C) 2020-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.
|
||||
//#s
|
||||
|
||||
#include "test.h"
|
||||
#include "testutils.h"
|
||||
|
||||
#ifndef CLASTERSTEST_H
|
||||
#define CLASTERSTEST_H
|
||||
|
||||
/**
|
||||
* @brief The ClastersTest class This test of the claster objects system.
|
||||
*/
|
||||
class ClastersTest: public Test, protected TestUtils
|
||||
{
|
||||
public:
|
||||
ClastersTest();
|
||||
|
||||
// Test interface
|
||||
public:
|
||||
void test() override;
|
||||
};
|
||||
|
||||
#endif // CLASTERSTEST_H
|
Loading…
x
Reference in New Issue
Block a user