File size: 1,167 Bytes
3d2dbcf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include "roadnet/trafficlight.h"
#include "roadnet/roadnet.h"
namespace CityFlow {
void TrafficLight::init(int initPhaseIndex) {
if (intersection->isVirtual)
return;
this->curPhaseIndex = initPhaseIndex;
this->remainDuration = phases[initPhaseIndex].time;
}
int TrafficLight::getCurrentPhaseIndex() {
return this->curPhaseIndex;
}
LightPhase &TrafficLight::getCurrentPhase() {
return this->phases.at(this->curPhaseIndex);
}
Intersection &TrafficLight::getIntersection() {
return *this->intersection;
}
std::vector<LightPhase> &TrafficLight::getPhases() {
return phases;
}
void TrafficLight::passTime(double seconds) {
if(intersection->isVirtual)
return;
remainDuration -= seconds;
while (remainDuration <= 0.0) {
curPhaseIndex = (curPhaseIndex + 1) % (int) phases.size();
remainDuration += phases[curPhaseIndex].time;
}
}
void TrafficLight::setPhase(int phaseIndex) {
curPhaseIndex = phaseIndex;
}
void TrafficLight::reset() {
init(0);
}
}
|