added event server

This commit is contained in:
Andrei Yankovich 2021-08-05 18:43:01 +03:00
parent 621aab73d4
commit f3df22ff1e
6 changed files with 73 additions and 5 deletions

View File

@ -19,6 +19,7 @@
#include "thread" #include "thread"
#include "chrono" #include "chrono"
#include "diff.h" #include "diff.h"
#include "eventserver.h"
namespace CRAWL { namespace CRAWL {
@ -26,10 +27,13 @@ namespace CRAWL {
IWorld::IWorld() { IWorld::IWorld() {
qRegisterMetaType<WorldRule::const_iterator>("WorldRule::const_iterator"); qRegisterMetaType<WorldRule::const_iterator>("WorldRule::const_iterator");
connect(this, &IWorld::sigWorldChanged, this, &IWorld::worldChanged, Qt::QueuedConnection); connect(this, &IWorld::sigWorldChanged, this, &IWorld::worldChanged, Qt::QueuedConnection);
_eventServer = new EventServer;
} }
IWorld::~IWorld() { IWorld::~IWorld() {
reset(); reset();
delete _eventServer;
} }
void IWorld::init() {prepare();} void IWorld::init() {prepare();}
@ -50,17 +54,14 @@ void IWorld::render(unsigned int tbfMsec) {
for (auto i = _items.begin(); i != _items.end(); ++i) { for (auto i = _items.begin(); i != _items.end(); ++i) {
(*i)->render(tbfMsec); (*i)->render(tbfMsec);
// intersects event. _eventServer->process(*i);
if ((*i)->intersects(*_player)) {
_player->onIntersects((*i));
}
} }
_ItemsMutex.unlock(); _ItemsMutex.unlock();
updateWorld(); updateWorld();
int waitTime = 1000 / _targetFps - tbfMsec; int waitTime = 1000 / targetFps() - tbfMsec;
if (waitTime > 0) if (waitTime > 0)
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); std::this_thread::sleep_for(std::chrono::milliseconds(waitTime));
} }

View File

@ -32,6 +32,7 @@ class GroundClaster;
class IControl; class IControl;
class IAI; class IAI;
class IWorldLight; class IWorldLight;
class EventServer;
/** /**
* @brief WorldObjects This is map list of the avalable objects and its count on a lvl-long point. * @brief WorldObjects This is map list of the avalable objects and its count on a lvl-long point.
@ -482,6 +483,8 @@ private:
void removeAnyItemFromGroup(const QString &group, void removeAnyItemFromGroup(const QString &group,
QList<int>* removedObjectsList = nullptr); QList<int>* removedObjectsList = nullptr);
EventServer * _eventServer = nullptr;
QHash<int, IWorldItem*> _items; QHash<int, IWorldItem*> _items;
QMultiHash<QString, int> _itemsGroup; QMultiHash<QString, int> _itemsGroup;
QMultiHash<QString, int> _lastItemsGroup; QMultiHash<QString, int> _lastItemsGroup;

View File

@ -66,6 +66,9 @@ Model {
] ]
rotation: (model)? model.rotation: Qt.quaternion(0, 0, 0, 0) rotation: (model)? model.rotation: Qt.quaternion(0, 0, 0, 0)
scale: (model)? model.size: Qt.vector3d(0, 0, 0); scale: (model)? model.size: Qt.vector3d(0, 0, 0);
source: (model)? model.mash: "#Cube"; source: (model)? model.mash: "#Cube";
position: (model) ? model.position: Qt.vector3d(0,0,0); position: (model) ? model.position: Qt.vector3d(0,0,0);

View File

@ -22,6 +22,7 @@ class GuiObject;
* For Create your own motion alghoritm you need to override two methods: * For Create your own motion alghoritm you need to override two methods:
* * renderPosition * * renderPosition
* * renderRotation * * renderRotation
*
*/ */
class CRAWL_EXPORT BaseMotion : public virtual IRender class CRAWL_EXPORT BaseMotion : public virtual IRender
{ {

View 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 "eventserver.h"
#include <Crawl/iworlditem.h>
namespace CRAWL {
EventServer::EventServer() {
}
void EventServer::process(IWorldItem *item) {
// intersects event.
// if ((item)->intersects(*_player)) {
// _player->onIntersects((*i));
// }
}
}

View File

@ -0,0 +1,33 @@
//#
//# 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 EVENTSERVER_H
#define EVENTSERVER_H
namespace CRAWL {
class IWorldItem;
/**
* @brief The EventServer class process all game events.
*/
class EventServer
{
public:
EventServer();
/**
* @brief process This method process al events of an @a item object
* @param item This is processed object.
*/
void process(IWorldItem* item);
};
}
#endif // EVENTSERVER_H