update
This commit is contained in:
parent
904b7ee29a
commit
8ff26d2257
|
@ -101,10 +101,12 @@
|
|||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="EntitiesManager.cpp" />
|
||||
<ClCompile Include="MapRoute.cpp" />
|
||||
<ClCompile Include="VisibleBox.cpp" />
|
||||
<ClInclude Include="componentbasic_global.h" />
|
||||
<ClInclude Include="componentbasic.h" />
|
||||
<ClInclude Include="EntityDocks.h" />
|
||||
<ClInclude Include="MapRoute.h" />
|
||||
<ClInclude Include="VisibleBox.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
<ClInclude Include="MapRoute.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EntityDocks.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="VisibleBox.cpp">
|
||||
|
@ -43,5 +46,8 @@
|
|||
<ClCompile Include="MapRoute.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EntitiesManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1 @@
|
|||
#include "EntityDocks.h"
|
|
@ -0,0 +1,2 @@
|
|||
#pragma once
|
||||
#include <simsbasic.h>
|
|
@ -51,12 +51,12 @@ QString Visible3DPlugin::name() const {
|
|||
return NAME(Visible3DPlugin);
|
||||
}
|
||||
|
||||
void Visible3DPlugin::execute(std::shared_ptr<const Get3DBox> in, std::shared_ptr<Box3DDesc>& out)
|
||||
void Visible3DPlugin::execute(std::shared_ptr<ImmediateMap> map, std::shared_ptr<const Get3DBox> in, std::shared_ptr<Box3DDesc>& out)
|
||||
{
|
||||
auto ins = std::make_shared<Box3DDesc>();
|
||||
ins->setPosition(_self_lla);
|
||||
ins->setPosture(_self_posture);
|
||||
ins->setTarget(_bind_entity, in->sourceEntity());
|
||||
ins->setVolume(_self_d3);
|
||||
ins->_lla_pos = _self_lla;
|
||||
ins->_posture_d3 = _self_posture;
|
||||
ins->_d3_data = _self_d3;
|
||||
ins->reset(_bind_entity, in->sourceEntity());
|
||||
out = ins;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
void bindEntity(uint64_t entity_id) override;
|
||||
QString name() const override;
|
||||
|
||||
void execute(std::shared_ptr<const Get3DBox> in, std::shared_ptr<Box3DDesc>& out) override;
|
||||
void execute(std::shared_ptr<ImmediateMap> map, std::shared_ptr<const Get3DBox> in, std::shared_ptr<Box3DDesc>& out) override;
|
||||
|
||||
std::shared_ptr<WsComponent> defaultNew() const override;
|
||||
void recoveryFrom(const QJsonObject& obj) override;
|
||||
|
|
|
@ -28,15 +28,15 @@ public:
|
|||
/// </summary>
|
||||
/// <param name="in"></param>
|
||||
/// <param name="out"></param>
|
||||
virtual void execute(std::shared_ptr<const MsgA> in, std::shared_ptr<MsgB>& out) = 0;
|
||||
virtual void execute(std::shared_ptr<ImmediateMap> map, std::shared_ptr<const MsgA> in, std::shared_ptr<MsgB>& out) = 0;
|
||||
/// <summary>
|
||||
/// WsRespond构造函数
|
||||
/// </summary>
|
||||
/// <param name="map">注册函数</param>
|
||||
explicit WsRespond(QHash<WsRespondSignatureType, WsRespondEntry>& map) {
|
||||
WsRespondEntry ins = [=](std::shared_ptr<const WsMessage> in, std::shared_ptr<WsMessage>& out) {
|
||||
WsRespondEntry ins = [=](std::shared_ptr<ImmediateMap> map, std::shared_ptr<const WsMessage> in, std::shared_ptr<WsMessage>& out) {
|
||||
std::shared_ptr<MsgB> o_ptr;
|
||||
this->execute(std::static_pointer_cast<const MsgA>(in), o_ptr);
|
||||
this->execute(map, std::static_pointer_cast<const MsgA>(in), o_ptr);
|
||||
out = o_ptr;
|
||||
};
|
||||
map[SelfType::signature()] = ins;
|
||||
|
|
|
@ -64,6 +64,11 @@
|
|||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
|
|
|
@ -10,180 +10,56 @@ void from_to_recovery(uint64_t& f, uint64_t& t, const QJsonObject& o) {
|
|||
t = o["target_entity"].toVariant().toULongLong();
|
||||
}
|
||||
|
||||
DeduceRequest::DeduceRequest() {}
|
||||
|
||||
void DeduceRequest::reset(uint64_t from, uint64_t to) {
|
||||
_from_id = from;
|
||||
_to_id = to;
|
||||
DeduceRequest::DeduceRequest()
|
||||
:AbstractMessage(NAME(DeduceRequest)) {
|
||||
}
|
||||
|
||||
void DeduceRequest::recoveryFrom(const QJsonObject& obj)
|
||||
{
|
||||
from_to_recovery(_from_id, _to_id, obj);
|
||||
}
|
||||
|
||||
void DeduceRequest::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
from_to_save(_from_id, _to_id, obj);
|
||||
}
|
||||
|
||||
QString DeduceRequest::topicString() const
|
||||
{
|
||||
return NAME(DeduceRequest);
|
||||
}
|
||||
|
||||
uint64_t DeduceRequest::targetEntity() const
|
||||
{
|
||||
return _to_id;
|
||||
}
|
||||
|
||||
uint64_t DeduceRequest::sourceEntity() const
|
||||
{
|
||||
return _from_id;
|
||||
}
|
||||
|
||||
SyncRequest::SyncRequest() {
|
||||
}
|
||||
|
||||
void SyncRequest::reset(uint64_t from, uint64_t to, double timepoint)
|
||||
{
|
||||
_from_id = from;
|
||||
_to_id = to;
|
||||
this->_time_current = timepoint;
|
||||
SyncRequest::SyncRequest()
|
||||
:AbstractMessage(NAME(SyncRequest)),
|
||||
_time_current(0) {
|
||||
}
|
||||
|
||||
void SyncRequest::recoveryFrom(const QJsonObject& obj)
|
||||
{
|
||||
from_to_recovery(_from_id, _to_id, obj);
|
||||
this->_time_current = obj["current_time"].toDouble();
|
||||
AbstractMessage::recoveryFrom(obj);
|
||||
DOUOBLE_PEAK(_time_current);
|
||||
}
|
||||
|
||||
void SyncRequest::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
from_to_save(_from_id, _to_id, obj);
|
||||
obj["current_time"] = this->_time_current;
|
||||
AbstractMessage::saveTo(obj);
|
||||
DOUBLE_SAVE(_time_current);
|
||||
}
|
||||
|
||||
QString SyncRequest::topicString() const
|
||||
{
|
||||
return NAME(SyncRequest);
|
||||
}
|
||||
|
||||
uint64_t SyncRequest::targetEntity() const
|
||||
{
|
||||
return _to_id;
|
||||
}
|
||||
|
||||
uint64_t SyncRequest::sourceEntity() const
|
||||
{
|
||||
return _from_id;
|
||||
}
|
||||
|
||||
RespondDefault::RespondDefault() {
|
||||
}
|
||||
|
||||
void RespondDefault::reset(uint64_t from, uint64_t to, double consume) {
|
||||
_from_id = from;
|
||||
_to_id = to;
|
||||
_time_consume = consume;
|
||||
}
|
||||
|
||||
double RespondDefault::consume() const {
|
||||
return this->_time_consume;
|
||||
RespondDefault::RespondDefault()
|
||||
:AbstractMessage(NAME(RespondDefault)),
|
||||
_time_consume(0) {
|
||||
}
|
||||
|
||||
void RespondDefault::recoveryFrom(const QJsonObject& obj)
|
||||
{
|
||||
from_to_recovery(_from_id, _to_id, obj);
|
||||
this->_time_consume = obj["time_consume"].toDouble();
|
||||
AbstractMessage::recoveryFrom(obj);
|
||||
DOUOBLE_PEAK(_time_consume);
|
||||
}
|
||||
|
||||
void RespondDefault::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
from_to_save(_from_id, _to_id, obj);
|
||||
obj["time_consume"] = this->_time_consume;
|
||||
}
|
||||
|
||||
QString RespondDefault::topicString() const
|
||||
{
|
||||
return NAME(DeduceRequest);
|
||||
}
|
||||
|
||||
uint64_t RespondDefault::targetEntity() const
|
||||
{
|
||||
return _to_id;
|
||||
}
|
||||
|
||||
uint64_t RespondDefault::sourceEntity() const
|
||||
{
|
||||
return _from_id;
|
||||
AbstractMessage::saveTo(obj);
|
||||
DOUBLE_SAVE(_time_consume);
|
||||
}
|
||||
|
||||
Get3DBox::Get3DBox()
|
||||
{
|
||||
}
|
||||
|
||||
void Get3DBox::reset(uint64_t from, uint64_t to)
|
||||
{
|
||||
_from_id = from;
|
||||
_to_id = to;
|
||||
}
|
||||
|
||||
void Get3DBox::recoveryFrom(const QJsonObject& obj)
|
||||
{
|
||||
from_to_recovery(_from_id, _to_id, obj);
|
||||
}
|
||||
|
||||
void Get3DBox::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
from_to_save(_from_id, _to_id, obj);
|
||||
}
|
||||
|
||||
QString Get3DBox::topicString() const
|
||||
{
|
||||
return NAME(Get3DBox);
|
||||
}
|
||||
|
||||
uint64_t Get3DBox::targetEntity() const
|
||||
{
|
||||
return _to_id;
|
||||
}
|
||||
|
||||
uint64_t Get3DBox::sourceEntity() const
|
||||
{
|
||||
return _from_id;
|
||||
:AbstractMessage(NAME(Get3DBox)) {
|
||||
}
|
||||
|
||||
Box3DDesc::Box3DDesc()
|
||||
{
|
||||
:AbstractMessage(NAME(Box3DDesc)) {
|
||||
}
|
||||
|
||||
void Box3DDesc::setTarget(uint64_t from, uint64_t to) {
|
||||
_from_id = from;
|
||||
_to_id = to;
|
||||
}
|
||||
|
||||
void Box3DDesc::setVolume(const D3Data& d) {
|
||||
this->_d3_data = d;
|
||||
}
|
||||
|
||||
D3Data Box3DDesc::volume() const { return this->_d3_data; }
|
||||
|
||||
void Box3DDesc::setPosture(const Posture& p) {
|
||||
_posture_d3 = p;
|
||||
}
|
||||
|
||||
Posture Box3DDesc::posture() const { return this->_posture_d3; }
|
||||
|
||||
void Box3DDesc::setPosition(const LLAPos& lla) {
|
||||
_lla_pos = lla;
|
||||
}
|
||||
|
||||
LLAPos Box3DDesc::position() const { return this->_lla_pos; }
|
||||
|
||||
void Box3DDesc::recoveryFrom(const QJsonObject& obj)
|
||||
{
|
||||
from_to_recovery(_from_id, _to_id, obj);
|
||||
AbstractMessage::recoveryFrom(obj);
|
||||
|
||||
DOUOBLE_PEAK(this->_d3_data._height_m);
|
||||
DOUOBLE_PEAK(this->_d3_data._length_m);
|
||||
DOUOBLE_PEAK(this->_d3_data._width_m);
|
||||
|
@ -199,7 +75,7 @@ void Box3DDesc::recoveryFrom(const QJsonObject& obj)
|
|||
|
||||
void Box3DDesc::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
from_to_save(_from_id, _to_id, obj);
|
||||
AbstractMessage::saveTo(obj);
|
||||
|
||||
DOUBLE_SAVE(this->_d3_data._height_m);
|
||||
DOUBLE_SAVE(this->_d3_data._length_m);
|
||||
|
@ -214,17 +90,78 @@ void Box3DDesc::saveTo(QJsonObject& obj) const
|
|||
DOUBLE_SAVE(this->_posture_d3._roll_deg);
|
||||
}
|
||||
|
||||
QString Box3DDesc::topicString() const
|
||||
{
|
||||
return NAME(Box3DDesc);
|
||||
EntityAllocte::EntityAllocte()
|
||||
:AbstractMessage(NAME(EntityAllocte)) {
|
||||
}
|
||||
|
||||
uint64_t Box3DDesc::targetEntity() const
|
||||
void EntityAllocte::recoveryFrom(const QJsonObject& obj)
|
||||
{
|
||||
AbstractMessage::recoveryFrom(obj);
|
||||
|
||||
STRING_PEAK(_entity_templet);
|
||||
}
|
||||
|
||||
void EntityAllocte::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
AbstractMessage::saveTo(obj);
|
||||
|
||||
STRING_SAVE(_entity_templet);
|
||||
}
|
||||
|
||||
AbstractMessage::AbstractMessage(const QString& topic) :_topic_string(topic) {}
|
||||
|
||||
void AbstractMessage::reset(uint64_t from, uint64_t to) {
|
||||
this->_from_id = from;
|
||||
this->_to_id = to;
|
||||
}
|
||||
|
||||
// ͨ¹ý WsMessage ¼Ì³Ð
|
||||
void AbstractMessage::recoveryFrom(const QJsonObject& obj) {
|
||||
from_to_recovery(_from_id, _to_id, obj);
|
||||
}
|
||||
|
||||
void AbstractMessage::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
from_to_save(_from_id, _to_id, obj);
|
||||
}
|
||||
|
||||
QString AbstractMessage::topicString() const
|
||||
{
|
||||
return _topic_string;
|
||||
}
|
||||
|
||||
uint64_t AbstractMessage::targetEntity() const
|
||||
{
|
||||
return _to_id;
|
||||
}
|
||||
|
||||
uint64_t Box3DDesc::sourceEntity() const
|
||||
uint64_t AbstractMessage::sourceEntity() const
|
||||
{
|
||||
return _from_id;
|
||||
}
|
||||
|
||||
EntityTotalGet::EntityTotalGet()
|
||||
:AbstractMessage(NAME(EntityTotalGet)) {
|
||||
}
|
||||
|
||||
void EntityTotalList::recoveryFrom(const QJsonObject& obj)
|
||||
{
|
||||
AbstractMessage::recoveryFrom(obj);
|
||||
|
||||
QStringList strs;
|
||||
STRLIST_PEAK(strs);
|
||||
std::transform(strs.begin(), strs.end(),
|
||||
std::back_inserter(_entities_list),
|
||||
[](QString v) { return v.toULongLong(); });
|
||||
}
|
||||
|
||||
void EntityTotalList::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
AbstractMessage::saveTo(obj);
|
||||
|
||||
QStringList strs;
|
||||
std::transform(_entities_list.begin(), _entities_list.end(),
|
||||
std::back_inserter(strs),
|
||||
[](int v) { return QString(",").arg(v); });
|
||||
STRLIST_SAVE(strs);
|
||||
}
|
||||
|
|
|
@ -8,15 +8,20 @@
|
|||
#define DOUBLE_SAVE(u) obj[NAME(u)] = u
|
||||
#define DOUOBLE_PEAK(u) u = obj[NAME(u)].toDouble()
|
||||
|
||||
/// <summary>
|
||||
/// ÍÆÑÝÇëÇó
|
||||
/// </summary>
|
||||
class MESSAGEBASIC_EXPORT DeduceRequest : public WsMessage {
|
||||
#define STRING_SAVE(u) obj[NAME(u)] = u
|
||||
#define STRING_PEAK(u) u = obj[NAME(u)].toString()
|
||||
|
||||
#define STRLIST_SAVE(u) obj[NAME(u)] = u.join(",")
|
||||
#define STRLIST_PEAK(u) u = obj[NAME(u)].toString().split(",")
|
||||
|
||||
class MESSAGEBASIC_EXPORT AbstractMessage : public WsMessage {
|
||||
private:
|
||||
uint64_t _from_id = 0, _to_id = 0;
|
||||
QString _topic_string;
|
||||
|
||||
public:
|
||||
DeduceRequest();
|
||||
AbstractMessage(const QString& topic);
|
||||
virtual ~AbstractMessage() = default;
|
||||
|
||||
void reset(uint64_t from, uint64_t to);
|
||||
|
||||
|
@ -28,69 +33,45 @@ public:
|
|||
uint64_t sourceEntity() const override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 推演请求
|
||||
/// </summary>
|
||||
struct MESSAGEBASIC_EXPORT DeduceRequest : public AbstractMessage {
|
||||
DeduceRequest();
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 默认的无返回消息的处理过程通用返回消息
|
||||
/// </summary>
|
||||
class MESSAGEBASIC_EXPORT RespondDefault : public WsMessage {
|
||||
private:
|
||||
uint64_t _from_id = 0, _to_id = 0;
|
||||
struct MESSAGEBASIC_EXPORT RespondDefault : public AbstractMessage {
|
||||
double _time_consume;
|
||||
|
||||
public:
|
||||
RespondDefault();
|
||||
|
||||
void reset(uint64_t from, uint64_t to, double consume);
|
||||
|
||||
double consume() const;
|
||||
|
||||
// 通过 WsMessage 继承
|
||||
void recoveryFrom(const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
QString topicString() const override;
|
||||
uint64_t targetEntity() const override;
|
||||
uint64_t sourceEntity() const override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 时间同步消息
|
||||
/// </summary>
|
||||
class MESSAGEBASIC_EXPORT SyncRequest : public WsMessage {
|
||||
private:
|
||||
uint64_t _from_id = 0, _to_id = 0;
|
||||
struct MESSAGEBASIC_EXPORT SyncRequest : public AbstractMessage {
|
||||
double _time_current;
|
||||
|
||||
public:
|
||||
SyncRequest();
|
||||
|
||||
void reset(uint64_t from, uint64_t to, double timepoint);
|
||||
|
||||
// 通过 WsMessage 继承
|
||||
void recoveryFrom(const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
QString topicString() const override;
|
||||
uint64_t targetEntity() const override;
|
||||
uint64_t sourceEntity() const override;
|
||||
};
|
||||
|
||||
// 体积盒可视化插件定义消息 =======================================================
|
||||
/// <summary>
|
||||
/// 获取体积盒详细数据
|
||||
/// </summary>
|
||||
class MESSAGEBASIC_EXPORT Get3DBox : public WsMessage {
|
||||
private:
|
||||
uint64_t _from_id = 0, _to_id = 0;
|
||||
|
||||
public:
|
||||
struct MESSAGEBASIC_EXPORT Get3DBox : public AbstractMessage {
|
||||
Get3DBox();
|
||||
|
||||
void reset(uint64_t from, uint64_t to);
|
||||
|
||||
// ͨ¹ý WsMessage ¼Ì³Ð
|
||||
void recoveryFrom(const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
QString topicString() const override;
|
||||
uint64_t targetEntity() const override;
|
||||
uint64_t sourceEntity() const override;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
@ -104,7 +85,7 @@ struct Posture {
|
|||
/// <summary>
|
||||
/// 三维数据结构定义
|
||||
/// </summary>
|
||||
struct D3Data{
|
||||
struct D3Data {
|
||||
double _length_m = 0;
|
||||
double _width_m = 0;
|
||||
double _height_m = 0;
|
||||
|
@ -113,29 +94,41 @@ struct D3Data{
|
|||
/// <summary>
|
||||
/// 体积盒详细数据定义
|
||||
/// </summary>
|
||||
class MESSAGEBASIC_EXPORT Box3DDesc : public WsMessage {
|
||||
private:
|
||||
uint64_t _from_id = 0, _to_id = 0;
|
||||
struct MESSAGEBASIC_EXPORT Box3DDesc : public AbstractMessage {
|
||||
D3Data _d3_data;
|
||||
Posture _posture_d3;
|
||||
LLAPos _lla_pos;
|
||||
|
||||
public:
|
||||
Box3DDesc();
|
||||
|
||||
void setTarget(uint64_t from, uint64_t to);
|
||||
void setVolume(const D3Data &d);
|
||||
D3Data volume() const;
|
||||
void setPosture(const Posture &p);
|
||||
Posture posture() const;
|
||||
void setPosition(const LLAPos &lla);
|
||||
LLAPos position() const;
|
||||
|
||||
|
||||
// 通过 WsMessage 继承
|
||||
void recoveryFrom(const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
QString topicString() const override;
|
||||
uint64_t targetEntity() const override;
|
||||
uint64_t sourceEntity() const override;
|
||||
};
|
||||
|
||||
// 实体构造消息定义 ==========================================
|
||||
|
||||
/// <summary>
|
||||
/// 实体构造
|
||||
/// </summary>
|
||||
struct MESSAGEBASIC_EXPORT EntityAllocte : public AbstractMessage {
|
||||
QString _entity_templet = "";
|
||||
|
||||
EntityAllocte();
|
||||
|
||||
// 通过 WsMessage 继承
|
||||
void recoveryFrom(const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
};
|
||||
|
||||
struct MESSAGEBASIC_EXPORT EntityTotalGet : public AbstractMessage {
|
||||
EntityTotalGet();
|
||||
};
|
||||
|
||||
struct MESSAGEBASIC_EXPORT EntityTotalList : public AbstractMessage {
|
||||
QList<uint64_t> _entities_list;
|
||||
|
||||
// 通过 WsMessage 继承
|
||||
void recoveryFrom(const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
};
|
|
@ -10,48 +10,48 @@ QString UniException::content() const noexcept
|
|||
return _error_store;
|
||||
}
|
||||
|
||||
WsEntity::WsEntity() {}
|
||||
RtEntity::RtEntity() {}
|
||||
|
||||
void WsEntity::resetTemplet(const QString& name) {
|
||||
void RtEntity::resetTemplet(const QString& name) {
|
||||
this->_templet_name = name;
|
||||
}
|
||||
|
||||
QString WsEntity::templetName() const {
|
||||
QString RtEntity::templetName() const {
|
||||
return this->_templet_name;
|
||||
}
|
||||
|
||||
void WsEntity::resetID(uint64_t id) {
|
||||
void RtEntity::resetID(uint64_t id) {
|
||||
this->_entity_id = id;
|
||||
}
|
||||
|
||||
uint64_t WsEntity::entityID() const {
|
||||
uint64_t RtEntity::entityID() const {
|
||||
return this->_entity_id;
|
||||
}
|
||||
|
||||
void WsEntity::resetName(const QString& name) {
|
||||
void RtEntity::resetName(const QString& name) {
|
||||
this->_runtime_name = name;
|
||||
}
|
||||
|
||||
QString WsEntity::name() const {
|
||||
QString RtEntity::name() const {
|
||||
return this->_runtime_name;
|
||||
}
|
||||
|
||||
void WsEntity::append(std::shared_ptr<WsComponent> ins) {
|
||||
void RtEntity::append(std::shared_ptr<WsComponent> ins) {
|
||||
if (this->_comps_list.contains(ins->name()))
|
||||
return;
|
||||
this->_comps_list[ins->name()] = ins;
|
||||
}
|
||||
|
||||
void WsEntity::remove(const QString& component_type) {
|
||||
void RtEntity::remove(const QString& component_type) {
|
||||
this->_comps_list.remove(component_type);
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<WsComponent>> WsEntity::components() const {
|
||||
QList<std::shared_ptr<WsComponent>> RtEntity::components() const {
|
||||
return _comps_list.values();
|
||||
}
|
||||
|
||||
std::shared_ptr<WsEntity> WsEntity::defaultNew() const {
|
||||
auto newx = std::make_shared<WsEntity>();
|
||||
std::shared_ptr<WsEntity> RtEntity::defaultNew() const {
|
||||
auto newx = std::make_shared<RtEntity>();
|
||||
newx->_entity_id = this->_entity_id;
|
||||
newx->_templet_name = this->_templet_name;
|
||||
newx->_runtime_name = this->_runtime_name;
|
||||
|
@ -62,7 +62,7 @@ std::shared_ptr<WsEntity> WsEntity::defaultNew() const {
|
|||
}
|
||||
|
||||
#include <QSet>
|
||||
QList<QString> WsEntity::inputTypes() const
|
||||
QList<QString> RtEntity::inputTypes() const
|
||||
{
|
||||
QList<QString> types;
|
||||
for (auto c : this->_comps_list)
|
||||
|
@ -72,22 +72,22 @@ QList<QString> WsEntity::inputTypes() const
|
|||
|
||||
#include <QVariant>
|
||||
#include <QJsonArray>
|
||||
QList<WsRespondEntry> WsEntity::getEntryWithSignature(const WsRespondSignatureType& t) const
|
||||
QList<WsRespondEntry> RtEntity::getEntryWithSignature(const WsRespondSignatureType& t) const
|
||||
{
|
||||
QList<WsRespondEntry> list;
|
||||
for(auto c : this->_comps_list)
|
||||
for (auto c : this->_comps_list)
|
||||
list.append(c->getEntryWithSignature(t));
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<WsRespondEntry> WsEntity::getEntryWithInType(const QString& msg_type) const
|
||||
QList<WsRespondEntry> RtEntity::getEntryWithInType(const QString& msg_type) const
|
||||
{
|
||||
QList<WsRespondEntry> list;
|
||||
for(auto c : this->_comps_list)
|
||||
for (auto c : this->_comps_list)
|
||||
list.append(c->getEntrysWithInType(msg_type));
|
||||
return list;
|
||||
}
|
||||
void WsEntity::recoveryFrom(const QJsonObject& obj)
|
||||
void RtEntity::recoveryFrom(const QJsonObject& obj)
|
||||
{
|
||||
this->_entity_id = obj["entity_id"].toVariant().toULongLong();
|
||||
this->_runtime_name = obj["entity_name"].toString();
|
||||
|
@ -106,7 +106,7 @@ void WsEntity::recoveryFrom(const QJsonObject& obj)
|
|||
}
|
||||
}
|
||||
|
||||
void WsEntity::saveTo(QJsonObject& obj) const
|
||||
void RtEntity::saveTo(QJsonObject& obj) const
|
||||
{
|
||||
obj["entity_id"] = QJsonValue::fromVariant(QVariant::fromValue(this->_entity_id));
|
||||
obj["entity_name"] = this->_runtime_name;
|
||||
|
@ -122,3 +122,104 @@ void WsEntity::saveTo(QJsonObject& obj) const
|
|||
}
|
||||
obj["component_array"] = array;
|
||||
}
|
||||
|
||||
QString EntitiesManager::templetName() const
|
||||
{
|
||||
return "实体管理器";
|
||||
}
|
||||
|
||||
uint64_t EntitiesManager::entityID() const
|
||||
{
|
||||
return const_id;
|
||||
}
|
||||
|
||||
QString EntitiesManager::name() const
|
||||
{
|
||||
return "实体管理器唯一实例";
|
||||
}
|
||||
|
||||
void EntitiesManager::append(std::shared_ptr<WsComponent> ins) {
|
||||
_comps_list[ins->name()] = ins;
|
||||
}
|
||||
|
||||
std::shared_ptr<WsEntity> EntitiesManager::defaultNew() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QList<WsRespondEntry> EntitiesManager::getEntryWithSignature(const WsRespondSignatureType& t) const
|
||||
{
|
||||
QList<WsRespondEntry> list;
|
||||
for (auto c : this->_comps_list)
|
||||
list.append(c->getEntryWithSignature(t));
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<WsRespondEntry> EntitiesManager::getEntryWithInType(const QString& msg_type) const
|
||||
{
|
||||
QList<WsRespondEntry> list;
|
||||
for (auto c : this->_comps_list)
|
||||
list.append(c->getEntrysWithInType(msg_type));
|
||||
return list;
|
||||
}
|
||||
|
||||
void EntitiesManager::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 EntitiesManager::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;
|
||||
}
|
||||
|
||||
ImmediateCore::ImmediateCore(std::shared_ptr<WsEntity> bind) :_bind_entity(bind) {}
|
||||
|
||||
uint64_t ImmediateCore::entityManagerID() const
|
||||
{
|
||||
return EntitiesManager::const_id;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<WsMessage>> ImmediateCore::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) {
|
||||
std::shared_ptr<WsMessage> out;
|
||||
func(shared_from_this(), in, out);
|
||||
|
||||
if (out) rets << out;
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
||||
QList<std::shared_ptr<WsMessage>> ImmediateCore::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) {
|
||||
std::shared_ptr<WsMessage> out;
|
||||
func(shared_from_this(), in, out);
|
||||
|
||||
if (out) rets << out;
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
|
|
@ -60,15 +60,41 @@ public:
|
|||
virtual uint64_t sourceEntity() const = 0;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 所有消息处理单元通用接口
|
||||
/// </summary>
|
||||
using WsRespondEntry = std::function<void(std::shared_ptr<const WsMessage>, std::shared_ptr<WsMessage>&)>;
|
||||
/// <summary>
|
||||
/// Respond签名类型
|
||||
/// </summary>
|
||||
using WsRespondSignatureType = std::pair<QString, QString>;
|
||||
|
||||
/// <summary>
|
||||
/// 实体内立即执行入口
|
||||
/// </summary>
|
||||
class ImmediateMap {
|
||||
public:
|
||||
virtual ~ImmediateMap() = default;
|
||||
/// <summary>
|
||||
/// 获取实体管理器id
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
virtual uint64_t entityManagerID() const = 0;
|
||||
/// <summary>
|
||||
/// 实体内指定类型的调用立即执行
|
||||
/// </summary>
|
||||
/// <param name="in"></param>
|
||||
/// <returns></returns>
|
||||
virtual QList<std::shared_ptr<WsMessage>> execute(const WsRespondSignatureType& resp_signature, std::shared_ptr<const WsMessage> in) = 0;
|
||||
/// <summary>
|
||||
/// 实体内兼容调用立即执行
|
||||
/// </summary>
|
||||
/// <param name="in"></param>
|
||||
/// <returns></returns>
|
||||
virtual QList<std::shared_ptr<WsMessage>> execute(std::shared_ptr<const WsMessage> in) = 0;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 所有消息处理单元通用接口
|
||||
/// </summary>
|
||||
using WsRespondEntry = std::function<void(std::shared_ptr<ImmediateMap> map, std::shared_ptr<const WsMessage>, std::shared_ptr<WsMessage>&)>;
|
||||
|
||||
/// <summary>
|
||||
/// 功能插件的基类
|
||||
/// </summary>
|
||||
|
@ -112,19 +138,60 @@ public:
|
|||
virtual QList<WsRespondEntry> getEntrysWithInType(const QString& msg_type) const = 0;
|
||||
};
|
||||
|
||||
class WsEntity : public Serializable {
|
||||
public:
|
||||
virtual ~WsEntity() = default;
|
||||
|
||||
/// <summary>
|
||||
/// 获取本实例的模板名
|
||||
/// </summary>
|
||||
/// <returns>模板名称</returns>
|
||||
virtual QString templetName() const = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 获取本实例的运行ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
virtual uint64_t entityID() const = 0;
|
||||
/// <summary>
|
||||
/// 获取本实例的运行名称
|
||||
/// </summary>
|
||||
/// <returns>运行名称</returns>
|
||||
virtual QString name() const = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 深度克隆本实例,插件和数据一致
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
virtual std::shared_ptr<WsEntity> defaultNew() const = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 通过指定的签名获取处理入口
|
||||
/// </summary>
|
||||
/// <param name="t">签名</param>
|
||||
/// <returns>处理接口</returns>
|
||||
virtual QList<WsRespondEntry> getEntryWithSignature(const WsRespondSignatureType& t) const = 0;
|
||||
/// <summary>
|
||||
/// 通过输入消息类型获取处理入口
|
||||
/// </summary>
|
||||
/// <param name="msg_type">输入消息类型</param>
|
||||
/// <returns>处理接口列表</returns>
|
||||
virtual QList<WsRespondEntry> getEntryWithInType(const QString& msg_type) const = 0;
|
||||
};
|
||||
|
||||
#include <QHash>
|
||||
/// <summary>
|
||||
/// 内存实体实例类型
|
||||
/// </summary>
|
||||
class SIMSBASIC_EXPORT WsEntity : public Serializable, public std::enable_shared_from_this<WsEntity> {
|
||||
class SIMSBASIC_EXPORT RtEntity : public WsEntity, public std::enable_shared_from_this<RtEntity> {
|
||||
private:
|
||||
uint64_t _entity_id = 0;
|
||||
QString _templet_name, _runtime_name;
|
||||
QHash<QString, std::shared_ptr<WsComponent>> _comps_list;
|
||||
|
||||
public:
|
||||
explicit WsEntity();
|
||||
virtual ~WsEntity() = default;
|
||||
explicit RtEntity();
|
||||
virtual ~RtEntity() = default;
|
||||
|
||||
/// <summary>
|
||||
/// 重置本实例模板名
|
||||
|
@ -180,7 +247,6 @@ public:
|
|||
/// <returns></returns>
|
||||
virtual std::shared_ptr<WsEntity> defaultNew() const;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 允许输入的消息类型
|
||||
/// </summary>
|
||||
|
@ -202,4 +268,49 @@ public:
|
|||
// 通过 Serializable 继承
|
||||
void recoveryFrom(const QJsonObject& obj) override;
|
||||
void saveTo(QJsonObject& obj) const override;
|
||||
};
|
||||
|
||||
|
||||
class SIMSBASIC_EXPORT EntitiesManager : public WsEntity {
|
||||
public:
|
||||
static const uint64_t const_id = 0x01ff;
|
||||
QHash<QString, std::shared_ptr<WsComponent>> _comps_list;
|
||||
|
||||
QString templetName() const override;
|
||||
uint64_t entityID() const override;
|
||||
QString name() const override;
|
||||
void append(std::shared_ptr<WsComponent> ins);
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
class SIMSBASIC_EXPORT ImmediateCore : public ImmediateMap, public std::enable_shared_from_this<ImmediateCore> {
|
||||
private:
|
||||
std::shared_ptr<WsEntity> _bind_entity = nullptr;
|
||||
|
||||
public:
|
||||
ImmediateCore(std::shared_ptr<WsEntity> bind);
|
||||
/// <summary>
|
||||
/// 获取实体管理器id
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
virtual uint64_t entityManagerID() const override;
|
||||
/// <summary>
|
||||
/// 实体内指定类型的调用立即执行
|
||||
/// </summary>
|
||||
/// <param name="in"></param>
|
||||
/// <returns></returns>
|
||||
virtual QList<std::shared_ptr<WsMessage>> execute(const WsRespondSignatureType& resp_signature, std::shared_ptr<const WsMessage> in) override;
|
||||
/// <summary>
|
||||
/// 实体内兼容调用立即执行
|
||||
/// </summary>
|
||||
/// <param name="in"></param>
|
||||
/// <returns></returns>
|
||||
virtual QList<std::shared_ptr<WsMessage>> execute(std::shared_ptr<const WsMessage> in) override;
|
||||
|
||||
};
|
Loading…
Reference in New Issue