diff --git a/ComponentBasic/ComponentBasic.vcxproj b/ComponentBasic/ComponentBasic.vcxproj index 6644b19..1685f31 100644 --- a/ComponentBasic/ComponentBasic.vcxproj +++ b/ComponentBasic/ComponentBasic.vcxproj @@ -37,7 +37,7 @@ 5.12.11_msvc2017_64 - core;gui + core;gui;concurrent debug @@ -67,7 +67,7 @@ - MessageBasic.lib;%(AdditionalDependencies) + MessageBasic.lib;SimsBasic.lib;%(AdditionalDependencies) @@ -101,12 +101,12 @@ - + - + diff --git a/ComponentBasic/ComponentBasic.vcxproj.filters b/ComponentBasic/ComponentBasic.vcxproj.filters index 981a467..477273e 100644 --- a/ComponentBasic/ComponentBasic.vcxproj.filters +++ b/ComponentBasic/ComponentBasic.vcxproj.filters @@ -35,9 +35,6 @@ Header Files - - Header Files - @@ -46,8 +43,13 @@ Source Files - + Source Files + + + Header Files + + \ No newline at end of file diff --git a/ComponentBasic/EntitiesManager.cpp b/ComponentBasic/EntitiesManager.cpp deleted file mode 100644 index 735cacb..0000000 --- a/ComponentBasic/EntitiesManager.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "EntityDocks.h" diff --git a/ComponentBasic/EntityDocks.cpp b/ComponentBasic/EntityDocks.cpp new file mode 100644 index 0000000..4678d7c --- /dev/null +++ b/ComponentBasic/EntityDocks.cpp @@ -0,0 +1,90 @@ +#include "EntityDocks.h" +#include + +QList> deduct_each(std::shared_ptr item) +{ + QList> rets; + auto immediate = std::make_shared(item); + + for (auto msg : DeduceFramework::_accept_stack) { + if (msg->targetEntity() == item->entityID()) { + auto enters = item->getEntryWithInType(msg->topicString()); + for (auto e : enters) + e(immediate, msg, rets); + } + } + return rets; +} + + +QList> DeduceFramework::_accept_stack; +void DeduceFramework::accept(const QList>& set) +{ + _accept_stack.append(set); +} + +#include +#include +void DeduceFramework::deduceBegin(std::shared_ptr ins) +{ + auto dt = QTime::currentTime(); + + auto ret_list_set = QtConcurrent::blockingMapped( + _entity_map.values(), deduct_each + ); + + _accept_stack.clear(); + for (auto vlist : ret_list_set) + emit this->reply(vlist); + + auto fmsg = std::make_shared(); + fmsg->reset(ins->targetEntity(), ins->sourceEntity()); + fmsg->_time_consume = dt.msecsTo(QTime::currentTime()); + emit this->complete(fmsg); +} + +#include +DeduceFramework::DeduceFramework() { + auto mgr_e = std::make_shared(); + mgr_e->append(this->shared_from_this()); + this->_entity_map[mgr_e->entityID()] = mgr_e; +} + +std::shared_ptr DeduceFramework::defaultNew() const +{ + throw std::logic_error("The method or operation is not implemented."); +} + +void DeduceFramework::bindEntity(uint64_t entity_id) +{ + this->_bind_entity = entity_id; +} + +QString DeduceFramework::name() const +{ + return NAME(DeduceFramework); +} + +void DeduceFramework::recoveryFrom(const QJsonObject& obj) +{ + throw std::logic_error("The method or operation is not implemented."); +} + +void DeduceFramework::saveTo(QJsonObject& obj) const +{ + throw std::logic_error("The method or operation is not implemented."); +} + +void DeduceFramework::execute(std::shared_ptr map, + std::shared_ptr in, QList>& out) +{ + +} +void DeduceFramework::execute(std::shared_ptr map, + std::shared_ptr in, QList>& out) +{ + auto rst = std::make_shared(); + rst->reset(in->targetEntity(), in->sourceEntity()); + rst->_entities_list = _entity_map.keys(); + out << rst; +} diff --git a/ComponentBasic/EntityDocks.h b/ComponentBasic/EntityDocks.h index 647d4cd..34e2cb3 100644 --- a/ComponentBasic/EntityDocks.h +++ b/ComponentBasic/EntityDocks.h @@ -1,2 +1,56 @@ #pragma once #include +#include +#include "componentbasic.h" +#include +#include + +class COMPONENTBASIC_EXPORT DeduceFramework : public QObject, +public ProcList< + WsRespond, + WsRespond> +{ + Q_OBJECT +private: + uint64_t _bind_entity = 0; + + QHash> _entity_map; + +signals: + /// + /// 推演过程中的回复信息 + /// + /// 消息列表 + void reply(const QList> &msg_set); + /// + /// 推演完成 + /// + /// 回复消息 + void complete(std::shared_ptr ins); + +public slots: + /// + /// 接收消息列表 + /// + /// 传入的消息队列 + void accept(const QList> &set); + /// + /// 推演入口 + /// + /// 消息 + void deduceBegin(std::shared_ptr ins); + +public: + static QList> _accept_stack; + DeduceFramework(); + + std::shared_ptr defaultNew() const override; + void bindEntity(uint64_t entity_id) override; + QString name() const override; + void recoveryFrom(const QJsonObject& obj) override; + void saveTo(QJsonObject& obj) const override; + + + void execute(std::shared_ptr map, std::shared_ptr in, QList>& out) override; + void execute(std::shared_ptr map, std::shared_ptr in, QList>& out) override; +}; \ No newline at end of file diff --git a/ComponentBasic/VisibleBox.cpp b/ComponentBasic/VisibleBox.cpp index 7cce13f..20dc6bb 100644 --- a/ComponentBasic/VisibleBox.cpp +++ b/ComponentBasic/VisibleBox.cpp @@ -51,12 +51,12 @@ QString Visible3DPlugin::name() const { return NAME(Visible3DPlugin); } -void Visible3DPlugin::execute(std::shared_ptr map, std::shared_ptr in, std::shared_ptr& out) +void Visible3DPlugin::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) { auto ins = std::make_shared(); ins->_lla_pos = _self_lla; ins->_posture_d3 = _self_posture; ins->_d3_data = _self_d3; ins->reset(_bind_entity, in->sourceEntity()); - out = ins; + out << ins; } diff --git a/ComponentBasic/VisibleBox.h b/ComponentBasic/VisibleBox.h index afd9101..2cf3582 100644 --- a/ComponentBasic/VisibleBox.h +++ b/ComponentBasic/VisibleBox.h @@ -23,7 +23,7 @@ public: void bindEntity(uint64_t entity_id) override; QString name() const override; - void execute(std::shared_ptr map, std::shared_ptr in, std::shared_ptr& out) override; + void execute(std::shared_ptr map, std::shared_ptr in, QList>& out) override; std::shared_ptr defaultNew() const override; void recoveryFrom(const QJsonObject& obj) override; diff --git a/ComponentBasic/componentbasic.h b/ComponentBasic/componentbasic.h index ae7622c..c9b2ba0 100644 --- a/ComponentBasic/componentbasic.h +++ b/ComponentBasic/componentbasic.h @@ -28,16 +28,17 @@ public: /// /// /// - virtual void execute(std::shared_ptr map, std::shared_ptr in, std::shared_ptr& out) = 0; + virtual void execute(std::shared_ptr map, std::shared_ptr in, QList>& out) = 0; /// /// WsRespond构造函数 /// /// 注册函数 explicit WsRespond(QHash& map) { - WsRespondEntry ins = [=](std::shared_ptr map, std::shared_ptr in, std::shared_ptr& out) { - std::shared_ptr o_ptr; - this->execute(map, std::static_pointer_cast(in), o_ptr); - out = o_ptr; + WsRespondEntry ins = [=](std::shared_ptr map, std::shared_ptr in, QList>& out) { + QList> o_ptrs; + this->execute(map, std::static_pointer_cast(in), o_ptrs); + std::transform(o_ptrs.begin(), o_ptrs.end(), std::back_inserter(out), + [](std::shared_ptr v) { return std::static_pointer_cast(v); }); }; map[SelfType::signature()] = ins; } diff --git a/MessageBasic/messagebasic.cpp b/MessageBasic/messagebasic.cpp index da33cc1..c9d4086 100644 --- a/MessageBasic/messagebasic.cpp +++ b/MessageBasic/messagebasic.cpp @@ -144,6 +144,10 @@ EntityTotalGet::EntityTotalGet() :AbstractMessage(NAME(EntityTotalGet)) { } +EntityTotalList::EntityTotalList() + :AbstractMessage(NAME(EntityTotalList)) { +} + void EntityTotalList::recoveryFrom(const QJsonObject& obj) { AbstractMessage::recoveryFrom(obj); diff --git a/MessageBasic/messagebasic.h b/MessageBasic/messagebasic.h index 8df130c..28404b0 100644 --- a/MessageBasic/messagebasic.h +++ b/MessageBasic/messagebasic.h @@ -121,13 +121,20 @@ struct MESSAGEBASIC_EXPORT EntityAllocte : public AbstractMessage { void saveTo(QJsonObject& obj) const override; }; +/// +/// 获取所有实体句柄 +/// struct MESSAGEBASIC_EXPORT EntityTotalGet : public AbstractMessage { EntityTotalGet(); }; - +/// +/// 所有实体列表 +/// struct MESSAGEBASIC_EXPORT EntityTotalList : public AbstractMessage { QList _entities_list; + EntityTotalList(); + // 通过 WsMessage 继承 void recoveryFrom(const QJsonObject& obj) override; void saveTo(QJsonObject& obj) const override; diff --git a/SimsBasic/simsbasic.cpp b/SimsBasic/simsbasic.cpp index 0161d28..4ebce07 100644 --- a/SimsBasic/simsbasic.cpp +++ b/SimsBasic/simsbasic.cpp @@ -203,10 +203,7 @@ QList> ImmediateCore::execute(const WsRespondSignatur QList> rets; auto list = this->_bind_entity->getEntryWithSignature(resp_signature); for (auto func : list) { - std::shared_ptr out; - func(shared_from_this(), in, out); - - if (out) rets << out; + func(shared_from_this(), in, rets); } return rets; } @@ -216,10 +213,7 @@ QList> ImmediateCore::execute(std::shared_ptr> rets; auto list = this->_bind_entity->getEntryWithInType(in->topicString()); for (auto func : list) { - std::shared_ptr out; - func(shared_from_this(), in, out); - - if (out) rets << out; + func(shared_from_this(), in, rets); } return rets; } diff --git a/SimsBasic/simsbasic.h b/SimsBasic/simsbasic.h index 61ba3c5..d989a70 100644 --- a/SimsBasic/simsbasic.h +++ b/SimsBasic/simsbasic.h @@ -93,7 +93,7 @@ public: /// /// 所有消息处理单元通用接口 /// -using WsRespondEntry = std::function map, std::shared_ptr, std::shared_ptr&)>; +using WsRespondEntry = std::function map, std::shared_ptr, QList>&)>; /// /// 功能插件的基类