added event server

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

View File

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

View File

@ -32,6 +32,7 @@ class GroundClaster;
class IControl;
class IAI;
class IWorldLight;
class EventServer;
/**
* @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,
QList<int>* removedObjectsList = nullptr);
EventServer * _eventServer = nullptr;
QHash<int, IWorldItem*> _items;
QMultiHash<QString, int> _itemsGroup;
QMultiHash<QString, int> _lastItemsGroup;

View File

@ -66,6 +66,9 @@ Model {
]
rotation: (model)? model.rotation: Qt.quaternion(0, 0, 0, 0)
scale: (model)? model.size: Qt.vector3d(0, 0, 0);
source: (model)? model.mash: "#Cube";
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:
* * renderPosition
* * renderRotation
*
*/
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