From 10b5bb706a265de0ccaa79ea2cd48cc03336721f Mon Sep 17 00:00:00 2001 From: codeboss <2422523675@qq.com> Date: Tue, 10 Jun 2025 12:41:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=87=8D=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ComponentBasic/EntityDocks.cpp | 26 +++++----- ComponentBasic/EntityDocks.h | 12 ++--- ComponentBasic/VisibleBox.cpp | 2 +- ComponentBasic/VisibleBox.h | 2 +- ComponentBasic/componentbasic.h | 4 +- ComponentBasic/invisible_component.cpp | 2 +- ComponentBasic/invisible_component.h | 2 +- SimsBasic/simsbasic.cpp | 66 +++++++++++++------------- SimsBasic/simsbasic.h | 28 ++++++----- 9 files changed, 75 insertions(+), 69 deletions(-) diff --git a/ComponentBasic/EntityDocks.cpp b/ComponentBasic/EntityDocks.cpp index 74b0fee..de07395 100644 --- a/ComponentBasic/EntityDocks.cpp +++ b/ComponentBasic/EntityDocks.cpp @@ -4,7 +4,7 @@ QList> deduct_each(std::shared_ptr item) { QList> rets; - auto immediate = std::make_shared(item); + auto immediate = std::make_shared(item); for (auto msg : DeduceFramework::_accept_stack) { if (msg->targetEntity() == item->entityID()) { @@ -51,7 +51,7 @@ DeduceFramework::DeduceFramework() void DeduceFramework::init_backend() { - auto mgr_e = std::make_shared(); + auto mgr_e = std::make_shared(); mgr_e->append(this->shared_from_this()); this->_entity_map_over_0xffff[mgr_e->entityID()] = mgr_e; @@ -82,7 +82,7 @@ void DeduceFramework::saveTo(QJsonObject& obj) const throw std::logic_error("The method or operation is not implemented."); } -void DeduceFramework::execute(std::shared_ptr map, +void DeduceFramework::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) { auto dt = QTime::currentTime(); @@ -100,7 +100,7 @@ void DeduceFramework::execute(std::shared_ptr map, result->_success_mark = true; auto ins_t = this->_templets_within_0x2ff_0xffff[in->_template_name]; - auto new_copy = std::static_pointer_cast(ins_t->defaultNew()); + auto new_copy = std::static_pointer_cast(ins_t->defaultNew()); new_copy->resetID(0xffff); auto desc_p = std::make_shared(); new_copy->append(desc_p); @@ -129,7 +129,7 @@ void DeduceFramework::execute(std::shared_ptr map, else { result->_success_mark = true; - auto target_ins = std::static_pointer_cast( + auto target_ins = std::static_pointer_cast( this->_entity_map_over_0xffff[in->_entity_id_over_0xffff] ); target_ins->resetName(in->_entity_name); @@ -145,7 +145,7 @@ void DeduceFramework::execute(std::shared_ptr map, out << result; } -void DeduceFramework::execute(std::shared_ptr map, +void DeduceFramework::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) { auto rst = std::make_shared(); @@ -154,7 +154,7 @@ void DeduceFramework::execute(std::shared_ptr map, out << rst; } -void DeduceFramework::execute(std::shared_ptr map, +void DeduceFramework::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) { auto ins = std::make_shared(); @@ -166,7 +166,7 @@ void DeduceFramework::execute(std::shared_ptr map, out << ins; } -void DeduceFramework::execute(std::shared_ptr map, +void DeduceFramework::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) { auto dt = QTime::currentTime(); @@ -177,7 +177,7 @@ void DeduceFramework::execute(std::shared_ptr map, switch ((EntityOperateType)in->_operate_code) { case EntityOperateType::NEW: { nins->_success_mark = true; - auto ent_t = std::make_shared(); + auto ent_t = std::make_shared(); ent_t->resetTemplet(in->_template_name); auto desc_p = std::make_shared(); ent_t->append(desc_p); @@ -188,7 +188,7 @@ void DeduceFramework::execute(std::shared_ptr map, std::transform(_templets_within_0x2ff_0xffff.begin(), _templets_within_0x2ff_0xffff.end(), std::back_inserter(allids), - [](std::shared_ptr i) { return i->entityID(); }); + [](std::shared_ptr i) { return i->entityID(); }); // 重置模板id while (allids.contains(ent_t->entityID())) { @@ -236,7 +236,7 @@ void DeduceFramework::execute(std::shared_ptr map, out << nins; } -void DeduceFramework::execute(std::shared_ptr map, +void DeduceFramework::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) { auto dt = QTime::currentTime(); @@ -245,7 +245,7 @@ void DeduceFramework::execute(std::shared_ptr map, result->reset(in->targetEntity(), in->sourceEntity()); // 提取目标实例 ==================================================== - std::shared_ptr target_ins = nullptr; + std::shared_ptr target_ins = nullptr; if (in->_entity_id_within_0x2ff_0xffffffffffffffff < 0xffff) { for (auto info_t : this->_templets_within_0x2ff_0xffff) { if (info_t->entityID() == in->_entity_id_within_0x2ff_0xffffffffffffffff) { @@ -256,7 +256,7 @@ void DeduceFramework::execute(std::shared_ptr map, } else { if (this->_entity_map_over_0xffff.contains(in->_entity_id_within_0x2ff_0xffffffffffffffff)) { - target_ins = std::static_pointer_cast( + target_ins = std::static_pointer_cast( this->_entity_map_over_0xffff[in->_entity_id_within_0x2ff_0xffffffffffffffff]); } } diff --git a/ComponentBasic/EntityDocks.h b/ComponentBasic/EntityDocks.h index fe48816..abdd8cb 100644 --- a/ComponentBasic/EntityDocks.h +++ b/ComponentBasic/EntityDocks.h @@ -34,7 +34,7 @@ private: std::weak_ptr _bind_entity; std::shared_ptr _factory_ins; - QHash> _templets_within_0x2ff_0xffff; + QHash> _templets_within_0x2ff_0xffff; QHash> _entity_map_over_0xffff; signals: @@ -74,10 +74,10 @@ public: 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; - 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; + 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; + 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; - 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 6523781..341a468 100644 --- a/ComponentBasic/VisibleBox.cpp +++ b/ComponentBasic/VisibleBox.cpp @@ -49,7 +49,7 @@ QString VisibleCubePlugin::name() const { return NAME(VisibleCubePlugin); } -void VisibleCubePlugin::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) +void VisibleCubePlugin::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) { auto ins = std::make_shared(); ins->_lla_pos = _self_lla; diff --git a/ComponentBasic/VisibleBox.h b/ComponentBasic/VisibleBox.h index 36be1d0..61ce86e 100644 --- a/ComponentBasic/VisibleBox.h +++ b/ComponentBasic/VisibleBox.h @@ -23,7 +23,7 @@ public: void bindEntity(std::weak_ptr ins) override; QString name() 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; std::shared_ptr defaultNew() const override; void recoveryFrom(const QJsonObject& obj) override; diff --git a/ComponentBasic/componentbasic.h b/ComponentBasic/componentbasic.h index c9b2ba0..dc83731 100644 --- a/ComponentBasic/componentbasic.h +++ b/ComponentBasic/componentbasic.h @@ -28,13 +28,13 @@ public: /// /// /// - virtual void execute(std::shared_ptr map, std::shared_ptr in, QList>& 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, QList>& out) { + 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), diff --git a/ComponentBasic/invisible_component.cpp b/ComponentBasic/invisible_component.cpp index 2a1aeba..1a3ff35 100644 --- a/ComponentBasic/invisible_component.cpp +++ b/ComponentBasic/invisible_component.cpp @@ -14,7 +14,7 @@ QString ComponentsInfoPull::name() const #include #include -void ComponentsInfoPull::execute(std::shared_ptr map, +void ComponentsInfoPull::execute(std::shared_ptr map, std::shared_ptr in, QList>& out) { auto rst = std::make_shared(); diff --git a/ComponentBasic/invisible_component.h b/ComponentBasic/invisible_component.h index 5408f90..e1f004c 100644 --- a/ComponentBasic/invisible_component.h +++ b/ComponentBasic/invisible_component.h @@ -15,7 +15,7 @@ public: void bindEntity(std::weak_ptr ins) override; QString name() 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; std::shared_ptr defaultNew() const override; void recoveryFrom(const QJsonObject& obj) override; diff --git a/SimsBasic/simsbasic.cpp b/SimsBasic/simsbasic.cpp index 315a387..cece96c 100644 --- a/SimsBasic/simsbasic.cpp +++ b/SimsBasic/simsbasic.cpp @@ -10,33 +10,33 @@ QString UniException::content() const noexcept return _error_store; } -RtEntity::RtEntity() {} +RtWsEntity::RtWsEntity() {} -void RtEntity::resetTemplet(const QString& name) { +void RtWsEntity::resetTemplet(const QString& name) { this->_templet_name = name; } -QString RtEntity::templetName() const { +QString RtWsEntity::templetName() const { return this->_templet_name; } -void RtEntity::resetID(uint64_t id) { +void RtWsEntity::resetID(uint64_t id) { this->_entity_id = id; } -uint64_t RtEntity::entityID() const { +uint64_t RtWsEntity::entityID() const { return this->_entity_id; } -void RtEntity::resetName(const QString& name) { +void RtWsEntity::resetName(const QString& name) { this->_runtime_name = name; } -QString RtEntity::name() const { +QString RtWsEntity::name() const { return this->_runtime_name; } -void RtEntity::append(std::shared_ptr ins) { +void RtWsEntity::append(std::shared_ptr ins) { if (this->_comps_list.contains(ins->name())) return; @@ -44,16 +44,16 @@ void RtEntity::append(std::shared_ptr ins) { this->_comps_list[ins->name()] = ins; } -void RtEntity::remove(const QString& component_type) { +void RtWsEntity::remove(const QString& component_type) { this->_comps_list.remove(component_type); } -QList> RtEntity::components() const { +QList> RtWsEntity::components() const { return _comps_list.values(); } -std::shared_ptr RtEntity::defaultNew() const { - auto newx = std::make_shared(); +std::shared_ptr RtWsEntity::defaultNew() const { + auto newx = std::make_shared(); newx->_entity_id = this->_entity_id; newx->_templet_name = this->_templet_name; newx->_runtime_name = this->_runtime_name; @@ -64,7 +64,7 @@ std::shared_ptr RtEntity::defaultNew() const { } #include -QList RtEntity::inputTypes() const +QList RtWsEntity::inputTypes() const { QList types; for (auto c : this->_comps_list) @@ -74,7 +74,7 @@ QList RtEntity::inputTypes() const #include #include -QList RtEntity::getEntryWithSignature(const WsRespondSignatureType& t) const +QList RtWsEntity::getEntryWithSignature(const WsRespondSignatureType& t) const { QList list; for (auto c : this->_comps_list) @@ -82,14 +82,14 @@ QList RtEntity::getEntryWithSignature(const WsRespondSignatureTy return list; } -QList RtEntity::getEntryWithInType(const QString& msg_type) const +QList RtWsEntity::getEntryWithInType(const QString& msg_type) const { QList list; for (auto c : this->_comps_list) list.append(c->getEntrysWithInType(msg_type)); return list; } -void RtEntity::recoveryFrom(const QJsonObject& obj) +void RtWsEntity::recoveryFrom(const QJsonObject& obj) { this->_entity_id = obj["entity_id"].toVariant().toULongLong(); this->_runtime_name = obj["entity_name"].toString(); @@ -108,7 +108,7 @@ void RtEntity::recoveryFrom(const QJsonObject& obj) } } -void RtEntity::saveTo(QJsonObject& obj) const +void RtWsEntity::saveTo(QJsonObject& obj) const { obj["entity_id"] = QJsonValue::fromVariant(QVariant::fromValue(this->_entity_id)); obj["entity_name"] = this->_runtime_name; @@ -125,31 +125,31 @@ void RtEntity::saveTo(QJsonObject& obj) const obj["component_array"] = array; } -QString EntitiesManager::templetName() const +QString RtEntityManager::templetName() const { return "实体管理器"; } -uint64_t EntitiesManager::entityID() const +uint64_t RtEntityManager::entityID() const { return const_id; } -QString EntitiesManager::name() const +QString RtEntityManager::name() const { return "实体管理器唯一实例"; } -void EntitiesManager::append(std::shared_ptr ins) { +void RtEntityManager::append(std::shared_ptr ins) { _comps_list[ins->name()] = ins; } -std::shared_ptr EntitiesManager::defaultNew() const +std::shared_ptr RtEntityManager::defaultNew() const { return nullptr; } -QList EntitiesManager::getEntryWithSignature(const WsRespondSignatureType& t) const +QList RtEntityManager::getEntryWithSignature(const WsRespondSignatureType& t) const { QList list; for (auto c : this->_comps_list) @@ -157,7 +157,7 @@ QList EntitiesManager::getEntryWithSignature(const WsRespondSign return list; } -QList EntitiesManager::getEntryWithInType(const QString& msg_type) const +QList RtEntityManager::getEntryWithInType(const QString& msg_type) const { QList list; for (auto c : this->_comps_list) @@ -165,7 +165,7 @@ QList EntitiesManager::getEntryWithInType(const QString& msg_typ return list; } -void EntitiesManager::recoveryFrom(const QJsonObject& obj) +void RtEntityManager::recoveryFrom(const QJsonObject& obj) { auto array = obj["component_array"].toArray(); for (auto idx = 0; idx < array.size(); ++idx) { @@ -180,7 +180,7 @@ void EntitiesManager::recoveryFrom(const QJsonObject& obj) } } -void EntitiesManager::saveTo(QJsonObject& obj) const +void RtEntityManager::saveTo(QJsonObject& obj) const { QJsonArray array; for (auto c : this->_comps_list) @@ -193,24 +193,24 @@ void EntitiesManager::saveTo(QJsonObject& obj) const obj["component_array"] = array; } -void EntitiesManager::remove(const QString& component_type) +void RtEntityManager::remove(const QString& component_type) { this->_comps_list.remove(component_type); } -QList> EntitiesManager::components() const +QList> RtEntityManager::components() const { return this->_comps_list.values(); } -ImmediateCore::ImmediateCore(std::shared_ptr bind) :_bind_entity(bind) {} +ImmediateKernel::ImmediateKernel(std::shared_ptr bind) :_bind_entity(bind) {} -uint64_t ImmediateCore::entityManagerID() const +uint64_t ImmediateKernel::entityManagerID() const { - return EntitiesManager::const_id; + return RtEntityManager::const_id; } -QList> ImmediateCore::execute(const WsRespondSignatureType& resp_signature, std::shared_ptr in) +QList> ImmediateKernel::execute(const WsRespondSignatureType& resp_signature, std::shared_ptr in) { QList> rets; auto list = this->_bind_entity->getEntryWithSignature(resp_signature); @@ -220,7 +220,7 @@ QList> ImmediateCore::execute(const WsRespondSignatur return rets; } -QList> ImmediateCore::execute(std::shared_ptr in) +QList> ImmediateKernel::execute(std::shared_ptr in) { QList> rets; auto list = this->_bind_entity->getEntryWithInType(in->topicString()); diff --git a/SimsBasic/simsbasic.h b/SimsBasic/simsbasic.h index 410f317..c43b244 100644 --- a/SimsBasic/simsbasic.h +++ b/SimsBasic/simsbasic.h @@ -68,9 +68,9 @@ using WsRespondSignatureType = std::pair; /// /// 实体内立即执行入口 /// -class ImmediateMap { +class Immediate { public: - virtual ~ImmediateMap() = default; + virtual ~Immediate() = default; /// /// 获取实体管理器id /// @@ -93,8 +93,11 @@ public: /// /// 所有消息处理单元通用接口 /// -using WsRespondEntry = std::function map, std::shared_ptr, QList>&)>; +using WsRespondEntry = std::function map, std::shared_ptr, QList>&)>; +/// +/// 实体抽象接口 +/// class WsEntity : public Serializable { public: virtual ~WsEntity() = default; @@ -179,6 +182,9 @@ public: virtual QList getEntrysWithInType(const QString& msg_type) const = 0; }; +/// +/// 组件管理接口 +/// class ComponentSet { public: /// @@ -202,15 +208,15 @@ public: /// /// 内存实体实例类型 /// -class SIMSBASIC_EXPORT RtEntity : public WsEntity, public ComponentSet, public std::enable_shared_from_this { +class SIMSBASIC_EXPORT RtWsEntity : public WsEntity, public ComponentSet, public std::enable_shared_from_this { private: uint64_t _entity_id = 0; QString _templet_name, _runtime_name; QHash> _comps_list; public: - explicit RtEntity(); - virtual ~RtEntity() = default; + explicit RtWsEntity(); + virtual ~RtWsEntity() = default; /// /// 重置本实例模板名 @@ -290,8 +296,8 @@ public: }; -class SIMSBASIC_EXPORT EntitiesManager : public WsEntity, public ComponentSet, - public std::enable_shared_from_this +class SIMSBASIC_EXPORT RtEntityManager : public WsEntity, public ComponentSet, + public std::enable_shared_from_this { public: static const uint64_t const_id = 0x01ff; @@ -300,7 +306,7 @@ public: QString templetName() const override; uint64_t entityID() const override; QString name() const override; - void append(std::shared_ptr ins); + void append(std::shared_ptr ins) override; void remove(const QString& component_type) override; QList> components() const override; @@ -313,12 +319,12 @@ public: }; -class SIMSBASIC_EXPORT ImmediateCore : public ImmediateMap, public std::enable_shared_from_this { +class SIMSBASIC_EXPORT ImmediateKernel : public Immediate, public std::enable_shared_from_this { private: std::shared_ptr _bind_entity = nullptr; public: - ImmediateCore(std::shared_ptr bind); + ImmediateKernel(std::shared_ptr bind); /// /// 获取实体管理器id ///