This commit is contained in:
codeboss 2025-06-12 08:04:17 +08:00
parent dc57bcd94c
commit 22be09682d
5 changed files with 125 additions and 2 deletions

View File

@ -65,8 +65,12 @@ void DeduceFramework::init_framework()
mgr_e->append(this->shared_from_this()); mgr_e->append(this->shared_from_this());
auto info_pulls = std::make_shared<ComponentsInfoPull>(); auto info_pulls = std::make_shared<ComponentsInfoPull>();
mgr_e->append(info_pulls); mgr_e->append(info_pulls);
this->_entity_map_over_0xffff[mgr_e->entityID()] = mgr_e; this->_entity_map_over_0xffff[mgr_e->entityID()] = mgr_e;
auto res_e = std::make_shared<RtResourceManager>();
info_pulls = std::make_shared<ComponentsInfoPull>();
res_e->append(info_pulls);
this->_entity_map_over_0xffff[res_e->entityID()] = res_e;
} }
std::shared_ptr<WsComponent> DeduceFramework::defaultNew() const std::shared_ptr<WsComponent> DeduceFramework::defaultNew() const
@ -174,6 +178,7 @@ void DeduceFramework::execute(std::shared_ptr<Immediate> map,
ins->_component_types = this->_factory_ins->allComponentTypes(); ins->_component_types = this->_factory_ins->allComponentTypes();
ins->_entity_templets[NAME(RtEntityManager)] = RtEntityManager::const_id; ins->_entity_templets[NAME(RtEntityManager)] = RtEntityManager::const_id;
ins->_entity_templets[NAME(RtResourceManager)] = RtResourceManager::const_id;
for (auto ekey : this->_templets_within_0x2ff_0xffff.keys()) for (auto ekey : this->_templets_within_0x2ff_0xffff.keys())
ins->_entity_templets[ekey] = this->_templets_within_0x2ff_0xffff[ekey]->entityID(); ins->_entity_templets[ekey] = this->_templets_within_0x2ff_0xffff[ekey]->entityID();

View File

@ -223,3 +223,88 @@ QList<std::shared_ptr<WsMessage>> ImmediateKernel::execute(std::shared_ptr<const
} }
return rets; return rets;
} }
uint64_t ImmediateKernel::resourceManagerID() const
{
return RtResourceManager::const_id;
}
QString RtResourceManager::templetName() const
{
return "RtResourceManager";
}
uint64_t RtResourceManager::entityID() const
{
return const_id;
}
QString RtResourceManager::name() const
{
return "资源管理器实例";
}
std::shared_ptr<WsEntity> RtResourceManager::defaultNew() const
{
return nullptr;
}
QList<WsRespondEntry> RtResourceManager::getEntryWithSignature(const WsRespondSignatureType& t) const
{
QList<WsRespondEntry> list;
for (auto c : this->_comps_list)
list.append(c->getEntryWithSignature(t));
return list;
}
QList<WsRespondEntry> RtResourceManager::getEntryWithInType(const QString& msg_type) const
{
QList<WsRespondEntry> list;
for (auto c : this->_comps_list)
list.append(c->getEntrysWithInType(msg_type));
return list;
}
void RtResourceManager::recoveryFrom(const QJsonObject& obj)
{
auto array = obj["component_array"].toArray();
for (auto idx = 0; idx < array.size(); ++idx) {
auto value = array.at(idx).toObject();
auto type = value["component_type"].toString();
auto compins = this->_comps_list[type];
if (!compins)
throw new UniException(type + "类型插件不存在!");
compins->recoveryFrom(value);
}
}
void RtResourceManager::saveTo(QJsonObject& obj) const
{
QJsonArray array;
for (auto c : this->_comps_list)
{
QJsonObject comp_obj;
comp_obj["component_type"] = c->name();
c->saveTo(comp_obj);
array.append(comp_obj);
}
obj["component_array"] = array;
}
void RtResourceManager::append(std::shared_ptr<WsComponent> ins)
{
ins->bindEntity(this->shared_from_this());
this->_comps_list[ins->name()] = ins;
}
void RtResourceManager::remove(const QString& component_type)
{
this->_comps_list.remove(component_type);
}
QList<std::shared_ptr<WsComponent>> RtResourceManager::components() const
{
return this->_comps_list.values();
}

View File

@ -118,6 +118,30 @@ public:
void saveTo(QJsonObject& obj) const override; void saveTo(QJsonObject& obj) const override;
}; };
class SIMSBASIC_EXPORT RtResourceManager : public WsEntity, public ComponentSet,
public std::enable_shared_from_this<RtResourceManager>
{
public:
static const uint64_t const_id = 0x01f0;
QHash<QString, std::shared_ptr<WsComponent>> _comps_list;
QString templetName() const override;
uint64_t entityID() const override;
QString name() const override;
std::shared_ptr<WsEntity> defaultNew() const override;
QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const override;
QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const override;
void recoveryFrom(const QJsonObject& obj) override;
void saveTo(QJsonObject& obj) const override;
void append(std::shared_ptr<WsComponent> ins) override;
void remove(const QString& component_type) override;
QList<std::shared_ptr<WsComponent>> components() const override;
};
/// <summary> /// <summary>
/// 实体内迅捷调用核心 /// 实体内迅捷调用核心
/// </summary> /// </summary>
@ -133,6 +157,8 @@ public:
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
virtual uint64_t entityManagerID() const override; virtual uint64_t entityManagerID() const override;
virtual uint64_t resourceManagerID() const override;
/// <summary> /// <summary>
/// 实体内指定类型的调用立即执行 /// 实体内指定类型的调用立即执行
/// </summary> /// </summary>
@ -146,4 +172,5 @@ public:
/// <returns></returns> /// <returns></returns>
virtual QList<std::shared_ptr<WsMessage>> execute(std::shared_ptr<const WsMessage> in) override; virtual QList<std::shared_ptr<WsMessage>> execute(std::shared_ptr<const WsMessage> in) override;
}; };

View File

@ -77,6 +77,11 @@ public:
/// <returns></returns> /// <returns></returns>
virtual uint64_t entityManagerID() const = 0; virtual uint64_t entityManagerID() const = 0;
/// <summary> /// <summary>
/// 获取资源管理器id
/// </summary>
/// <returns></returns>
virtual uint64_t resourceManagerID() const = 0;
/// <summary>
/// 实体内指定类型的调用立即执行 /// 实体内指定类型的调用立即执行
/// </summary> /// </summary>
/// <param name="in"></param> /// <param name="in"></param>

View File

@ -28,7 +28,8 @@ void TempletAssemble::reply_accept(const QList<std::shared_ptr<WsMessage>>& msg_
this->_component_types->addItems(conv->_component_types); this->_component_types->addItems(conv->_component_types);
for (auto info : conv->_entity_templets.keys()) { for (auto info : conv->_entity_templets.keys()) {
auto templat_id = conv->_entity_templets[info]; auto templat_id = conv->_entity_templets[info];
if ((QList<uint64_t>{RtEntityManager::const_id}).contains(templat_id)) if ((QList<uint64_t>{ RtEntityManager::const_id, RtResourceManager::const_id })
.contains(templat_id))
continue; continue;
auto cell = new QStandardItem(info); auto cell = new QStandardItem(info);