223 lines
5.3 KiB
C++
223 lines
5.3 KiB
C++
|
#include "internal_impl.h"
|
|||
|
|
|||
|
|
|||
|
RtWsEntity::RtWsEntity() {}
|
|||
|
|
|||
|
void RtWsEntity::resetTemplet(const QString& name) {
|
|||
|
this->_templet_name = name;
|
|||
|
}
|
|||
|
|
|||
|
QString RtWsEntity::templetName() const {
|
|||
|
return this->_templet_name;
|
|||
|
}
|
|||
|
|
|||
|
void RtWsEntity::resetID(uint64_t id) {
|
|||
|
this->_entity_id = id;
|
|||
|
}
|
|||
|
|
|||
|
uint64_t RtWsEntity::entityID() const {
|
|||
|
return this->_entity_id;
|
|||
|
}
|
|||
|
|
|||
|
void RtWsEntity::resetName(const QString& name) {
|
|||
|
this->_runtime_name = name;
|
|||
|
}
|
|||
|
|
|||
|
QString RtWsEntity::name() const {
|
|||
|
return this->_runtime_name;
|
|||
|
}
|
|||
|
|
|||
|
void RtWsEntity::append(std::shared_ptr<WsComponent> ins) {
|
|||
|
if (this->_comps_list.contains(ins->name()))
|
|||
|
return;
|
|||
|
|
|||
|
ins->bindEntity(this->shared_from_this());
|
|||
|
this->_comps_list[ins->name()] = ins;
|
|||
|
}
|
|||
|
|
|||
|
void RtWsEntity::remove(const QString& component_type) {
|
|||
|
this->_comps_list.remove(component_type);
|
|||
|
}
|
|||
|
|
|||
|
QList<std::shared_ptr<WsComponent>> RtWsEntity::components() const {
|
|||
|
return _comps_list.values();
|
|||
|
}
|
|||
|
|
|||
|
std::shared_ptr<WsEntity> RtWsEntity::defaultNew() const {
|
|||
|
auto newx = std::make_shared<RtWsEntity>();
|
|||
|
newx->_entity_id = this->_entity_id;
|
|||
|
newx->_templet_name = this->_templet_name;
|
|||
|
newx->_runtime_name = this->_runtime_name;
|
|||
|
|
|||
|
for (auto c : this->_comps_list)
|
|||
|
newx->append(c->defaultNew());
|
|||
|
return newx;
|
|||
|
}
|
|||
|
|
|||
|
#include <QSet>
|
|||
|
QList<QString> RtWsEntity::inputTypes() const
|
|||
|
{
|
|||
|
QList<QString> types;
|
|||
|
for (auto c : this->_comps_list)
|
|||
|
types.append(c->inputTypes());
|
|||
|
return types.toSet().toList();
|
|||
|
}
|
|||
|
|
|||
|
#include <QVariant>
|
|||
|
#include <QJsonArray>
|
|||
|
QList<WsRespondEntry> RtWsEntity::getEntryWithSignature(const WsRespondSignatureType& t) const
|
|||
|
{
|
|||
|
QList<WsRespondEntry> list;
|
|||
|
for (auto c : this->_comps_list)
|
|||
|
list.append(c->getEntryWithSignature(t));
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
QList<WsRespondEntry> RtWsEntity::getEntryWithInType(const QString& msg_type) const
|
|||
|
{
|
|||
|
QList<WsRespondEntry> list;
|
|||
|
for (auto c : this->_comps_list)
|
|||
|
list.append(c->getEntrysWithInType(msg_type));
|
|||
|
return list;
|
|||
|
}
|
|||
|
void RtWsEntity::recoveryFrom(const QJsonObject& obj)
|
|||
|
{
|
|||
|
this->_entity_id = obj["entity_id"].toVariant().toULongLong();
|
|||
|
this->_runtime_name = obj["entity_name"].toString();
|
|||
|
this->_templet_name = obj["entity_templet"].toString();
|
|||
|
|
|||
|
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 + "<EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
|
|||
|
|
|||
|
compins->recoveryFrom(value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void RtWsEntity::saveTo(QJsonObject& obj) const
|
|||
|
{
|
|||
|
obj["entity_id"] = QJsonValue::fromVariant(QVariant::fromValue(this->_entity_id));
|
|||
|
obj["entity_name"] = this->_runtime_name;
|
|||
|
obj["entity_templet"] = this->_templet_name;
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
|
|||
|
QString RtEntityManager::templetName() const
|
|||
|
{
|
|||
|
return "ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
|
|||
|
uint64_t RtEntityManager::entityID() const
|
|||
|
{
|
|||
|
return const_id;
|
|||
|
}
|
|||
|
|
|||
|
QString RtEntityManager::name() const
|
|||
|
{
|
|||
|
return "ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ψһʵ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
|
|||
|
void RtEntityManager::append(std::shared_ptr<WsComponent> ins) {
|
|||
|
_comps_list[ins->name()] = ins;
|
|||
|
}
|
|||
|
|
|||
|
std::shared_ptr<WsEntity> RtEntityManager::defaultNew() const
|
|||
|
{
|
|||
|
return nullptr;
|
|||
|
}
|
|||
|
|
|||
|
QList<WsRespondEntry> RtEntityManager::getEntryWithSignature(const WsRespondSignatureType& t) const
|
|||
|
{
|
|||
|
QList<WsRespondEntry> list;
|
|||
|
for (auto c : this->_comps_list)
|
|||
|
list.append(c->getEntryWithSignature(t));
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
QList<WsRespondEntry> RtEntityManager::getEntryWithInType(const QString& msg_type) const
|
|||
|
{
|
|||
|
QList<WsRespondEntry> list;
|
|||
|
for (auto c : this->_comps_list)
|
|||
|
list.append(c->getEntrysWithInType(msg_type));
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
void RtEntityManager::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 + "<EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
|
|||
|
|
|||
|
compins->recoveryFrom(value);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void RtEntityManager::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 RtEntityManager::remove(const QString& component_type)
|
|||
|
{
|
|||
|
this->_comps_list.remove(component_type);
|
|||
|
}
|
|||
|
|
|||
|
QList<std::shared_ptr<WsComponent>> RtEntityManager::components() const
|
|||
|
{
|
|||
|
return this->_comps_list.values();
|
|||
|
}
|
|||
|
|
|||
|
ImmediateKernel::ImmediateKernel(std::shared_ptr<WsEntity> bind) :_bind_entity(bind) {}
|
|||
|
|
|||
|
uint64_t ImmediateKernel::entityManagerID() const
|
|||
|
{
|
|||
|
return RtEntityManager::const_id;
|
|||
|
}
|
|||
|
|
|||
|
QList<std::shared_ptr<WsMessage>> ImmediateKernel::execute(const WsRespondSignatureType& resp_signature, std::shared_ptr<const WsMessage> in)
|
|||
|
{
|
|||
|
QList<std::shared_ptr<WsMessage>> rets;
|
|||
|
auto list = this->_bind_entity->getEntryWithSignature(resp_signature);
|
|||
|
for (auto func : list) {
|
|||
|
func(shared_from_this(), in, rets);
|
|||
|
}
|
|||
|
return rets;
|
|||
|
}
|
|||
|
|
|||
|
QList<std::shared_ptr<WsMessage>> ImmediateKernel::execute(std::shared_ptr<const WsMessage> in)
|
|||
|
{
|
|||
|
QList<std::shared_ptr<WsMessage>> rets;
|
|||
|
auto list = this->_bind_entity->getEntryWithInType(in->topicString());
|
|||
|
for (auto func : list) {
|
|||
|
func(shared_from_this(), in, rets);
|
|||
|
}
|
|||
|
return rets;
|
|||
|
}
|