ADD: added json lib and made some changes in the entity class

This commit is contained in:
hwinkel
2023-07-05 22:11:44 +02:00
parent 5485c8550e
commit 3333fadf20
6 changed files with 53 additions and 25 deletions

View File

@@ -34,6 +34,7 @@ namespace Entities
{
OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, OwnType, EntityKind);
OwnShipTrack->setPosition(SimCore::Position());
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__);
@@ -52,19 +53,31 @@ namespace Entities
void Entity::setPosition(SimCore::Position pos)
{
OwnShipTrack->setPosition(pos);
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
newSimTrack.setPosition(pos);
}
void Entity::setSpeed(double val)
{
OwnShipTrack->Speed.setValue(val);
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
newSimTrack.Speed.setValue(val);
MovemtServer_->sendMessage(newSimTrack.buildMessage().serialize());
}
void Entity::setCourse(double val)
{
OwnShipTrack->Course.setValue(val);
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
newSimTrack.Course.setValue(val);
LOG_S(INFO)<< "NEW Course: "<< val;
MovemtServer_->sendMessage(newSimTrack.buildMessage().serialize());
}
void Entity::setPitch( double val)
{
OwnShipTrack->Pitch.setValue(val);
SimCore::SimTrack newSimTrack(OwnShipTrack->getIdentifier(),WHISPER::SourceType::ENTITY,EntityKind_);
newSimTrack.Pitch.setValue(val);
}
void Entity::start()
@@ -107,15 +120,33 @@ namespace Entities
if (MovemtServer_->countClients() > 0 )
{
std::string msg = MovemtServer_->getLatestMessage();
if (msg == "Hello Server")
{
if(OwnShipTrack->getPosition().isValid())
{
LOG_S(INFO)<< "POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
MovementWorkerStarted = true;
MovemtServer_->sendMessage(OwnShipTrack->buildMessage().serialize());
}
}
LOG_S(INFO)<< "Initial Message send to MovementWorker";
}
}
}
void Entity::handleMovement()
{
if (!MovementWorkerStarted)
{
startMovementWorker();
}else
{
std::string msg = MovemtServer_->getLatestMessage();
auto newTrack = SimCore::SimTrack::unpack(msg);
if (newTrack != nullptr)
{
OwnShipTrack->setPosition(newTrack->getPosition());
LOG_S(INFO)<< "new POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
}
}
}
@@ -127,22 +158,7 @@ namespace Entities
LOG_S(INFO)<< "main loop started";
while (!stopMainLoop)
{
if (!MovementWorkerStarted)
{
startMovementWorker();
}else
{
std::string msg = MovemtServer_->getLatestMessage();
auto newTrack = SimCore::SimTrack::unpack(msg);
if (newTrack != nullptr)
{
OwnShipTrack->setPosition(newTrack->getPosition());
LOG_S(INFO)<< "new POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
}
}
handleMovement();
std::this_thread::sleep_for(std::chrono::milliseconds(500));