Skip to content

Commit

Permalink
refactoring to use events instead of movereminders to have remote con…
Browse files Browse the repository at this point in the history
…trolled enabled earlier #1922 #12
  • Loading branch information
behrisch committed Apr 5, 2024
1 parent af1c921 commit db4e8b9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/microsim/MSVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4775,7 +4775,7 @@ MSVehicle::updateState(double vNext) {
myState.myPreviousSpeed = myState.mySpeed;
myState.mySpeed = MAX2(vNext, 0.);

if (myInfluencer != nullptr && myInfluencer->isRemoteControlled()) {
if (isRemoteControlled()) {
deltaPos = myInfluencer->implicitDeltaPosRemote(this);
}

Expand Down
23 changes: 17 additions & 6 deletions src/microsim/devices/MSDevice_FCDReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ MSDevice_FCDReplay::init() {
throw ProcessError();
}
myHandler.addTrafficObjects();
MSNet::getInstance()->getBeginOfTimestepEvents()->addEvent(new MoveVehicles(), SIMSTEP + DELTA_T);
}
}

Expand All @@ -94,30 +95,40 @@ MSDevice_FCDReplay::~MSDevice_FCDReplay() {


bool
MSDevice_FCDReplay::notifyMove(SUMOTrafficObject& veh,
double /*oldPos*/,
double /*newPos*/,
double /*newSpeed*/) {
MSDevice_FCDReplay::move() {
if (myTrajectory == nullptr || myTrajectory->empty()) {
// removal happens via the usual MSVehicle::hasArrived mechanism
// TODO we may need to set an arrivalPos
return false;
}
MSVehicle* v = dynamic_cast<MSVehicle*>(&veh);
MSVehicle* v = dynamic_cast<MSVehicle*>(&myHolder);
if (v == nullptr) {
return false;
}
const auto& p = myTrajectory->front();
const std::string& edgeID = SUMOXMLDefinitions::getEdgeIDFromLane(std::get<1>(p));
const int laneIdx = SUMOXMLDefinitions::getIndexFromLane(std::get<1>(p));
libsumo::Vehicle::moveToXY(veh.getID(), edgeID, laneIdx, std::get<0>(p).x(), std::get<0>(p).y(),
libsumo::Vehicle::moveToXY(myHolder.getID(), edgeID, laneIdx, std::get<0>(p).x(), std::get<0>(p).y(),
std::get<4>(p), 7);
v->setPreviousSpeed(std::get<3>(p), std::numeric_limits<double>::min());
myTrajectory->erase(myTrajectory->begin());
return true;
}


SUMOTime
MSDevice_FCDReplay::MoveVehicles::execute(SUMOTime /* currentTime */) {
MSVehicleControl& c = MSNet::getInstance()->getVehicleControl();
for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
MSDevice_FCDReplay* device = static_cast<MSDevice_FCDReplay*>(i->second->getDevice(typeid(MSDevice_FCDReplay)));
if (device != nullptr && i->second->hasDeparted()) {
device->move();
}
}
return DELTA_T;
}


// ---------------------------------------------------------------------------
// MSDevice_FCDReplay::FCDHandler-methods
// ---------------------------------------------------------------------------
Expand Down
14 changes: 10 additions & 4 deletions src/microsim/devices/MSDevice_FCDReplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once
#include <config.h>

#include <utils/common/Command.h>
#include <utils/xml/SUMOSAXHandler.h>
#include "MSVehicleDevice.h"

Expand Down Expand Up @@ -61,10 +62,7 @@ class MSDevice_FCDReplay : public MSVehicleDevice {
/// @brief Destructor.
~MSDevice_FCDReplay();

bool notifyMove(SUMOTrafficObject& veh,
double oldPos,
double newPos,
double newSpeed);
bool move();

/// @brief return the name for this type of device
const std::string deviceName() const {
Expand All @@ -85,6 +83,14 @@ class MSDevice_FCDReplay : public MSVehicleDevice {
*/
MSDevice_FCDReplay(SUMOVehicle& holder, const std::string& id);

class MoveVehicles : public Command {
public:
SUMOTime execute(SUMOTime currentTime);
private:
/// @brief Invalidated assignment operator.
MoveVehicles& operator=(const MoveVehicles&) = delete;
};

class FCDHandler : public SUMOSAXHandler {
public:
void reset();
Expand Down
34 changes: 17 additions & 17 deletions src/microsim/devices/MSTransportableDevice_FCDReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,6 @@ MSTransportableDevice_FCDReplay::~MSTransportableDevice_FCDReplay() {
}


SUMOTime
MSTransportableDevice_FCDReplay::MovePedestrians::execute(SUMOTime /* currentTime */) {
MSTransportableControl& c = MSNet::getInstance()->getPersonControl();
std::vector<MSTransportable*> toRemove;
for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
MSTransportableDevice_FCDReplay* device = static_cast<MSTransportableDevice_FCDReplay*>(i->second->getDevice(typeid(MSTransportableDevice_FCDReplay)));
if (device != nullptr && device->move()) {
toRemove.push_back(&device->getHolder());
}
}
for (MSTransportable* t : toRemove) {
t->removeStage(0, false);
}
return DELTA_T;
}


bool
MSTransportableDevice_FCDReplay::move() {
MSPerson* person = dynamic_cast<MSPerson*>(&myHolder);
Expand All @@ -109,4 +92,21 @@ MSTransportableDevice_FCDReplay::move() {
}


SUMOTime
MSTransportableDevice_FCDReplay::MovePedestrians::execute(SUMOTime /* currentTime */) {
MSTransportableControl& c = MSNet::getInstance()->getPersonControl();
std::vector<MSTransportable*> toRemove;
for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
MSTransportableDevice_FCDReplay* device = static_cast<MSTransportableDevice_FCDReplay*>(i->second->getDevice(typeid(MSTransportableDevice_FCDReplay)));
if (device != nullptr && device->move()) {
toRemove.push_back(&device->getHolder());
}
}
for (MSTransportable* t : toRemove) {
t->removeStage(0, false);
}
return DELTA_T;
}


/****************************************************************************/

0 comments on commit db4e8b9

Please sign in to comment.