Files
qt5-legatus-legacy/Lts/Services/AreaEffectSimulation/handler_effector.cpp
T
2026-08-13 18:33:10 +02:00

88 lines
2.7 KiB
C++
Executable File

/**
* Object class for HandlerEffector
* $Id$
* $HeadURL$
* $Author$
*/
#include "handler_effector.h"
#include "main_handler.h"
#include "object_charge_effect.h"
#include "object_effector.h"
namespace AreaEffectSimulation
{
HandlerEffector::HandlerEffector(AreaEffectSimulation::MainHandler *mainhandler, QObject *parent)
: QObject(parent)
, m_mainHandler(mainhandler)
, m_logger(getLogger(QStringLiteral("HandlerEffector")))
{
m_ppmDtc = m_mainHandler->dds()->ppmDtc();
m_ppmDtc->enableType(true);
m_ppmDtc->waitForHistoricalDataType(100);
m_ppmDtc->enableParticipant(true);
m_ppmDtc->waitForHistoricalDataParticipant(100);
}
//-----------------------------------------------------------------------------
bool HandlerEffector::init()
{
DEBUG_LOG(m_logger) << "HandlerEffector::init";
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::participantChanged,
this, &HandlerEffector::onParticipantChanged);
{
auto cb = [this](const ParticipantManagement::Participant & data)
{
onParticipantChanged(data, DataModification::eAdded);
};
m_ppmDtc->participants(cb);
}
return true;
}
// TODO Wird aufgerufen, wenn zur Laufzeit ein neuer Effektor angelegt werden muss. (Topic PPM Participant)
// und von createEffector
void HandlerEffector::createEffector(int participantId)
{
if (m_effectors.contains(participantId))
return;
DEBUG_LOG(m_logger)<<"createEffector participantId:" << participantId;
ObjectEffector* objectEffector = new ObjectEffector(m_mainHandler, this);
objectEffector->init(participantId);
m_effectors.insert(participantId, objectEffector);
}
// TODO Wird aufgerufen, wenn zur Laufzeit ein Effektor geloescht wird. (Topic?)
void HandlerEffector::deleteEffector(int participantId)
{
DEBUG_LOG(m_logger)<<"deleteEffector participantId:" << participantId;
delete m_effectors[participantId];
m_effectors.remove(participantId);
}
void HandlerEffector::onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType)
{
//DEBUG_LOG(m_logger)<<"onParticipantChanged participantId:" << data.id();
if (modType == DataModification::eRemoved)
{
DEBUG_LOG(m_logger) << "m_participantsOutsideMap.remove participantId: " << data.id();
if (m_effectors.contains(data.id()))
deleteEffector(data.id());
return;
}
if (m_ppmDtc->isArtilleryType(data.typeId()))
{
// Filter TypeClass Unit
ParticipantManagement::Type type = m_ppmDtc->type(data.typeId());
if (type.typeClass() != ParticipantManagement::TypeClass_def::Unit)
createEffector(data.id());
}
else
if (m_effectors.contains(data.id()))
deleteEffector(data.id());
}
}