#ifndef SYNTHETICWALKER_H #define SYNTHETICWALKER_H #include "SyntheticPath.h" /** walk along a path using a known walking speed */ class SyntheticWalker { public: enum class Type { FLOOR, NON_FLOOR, }; class Listener { public: virtual void onWalk(Timestamp walkedTime, float walkedDistance, const Point3 curPos, const Type type) = 0; }; private: /** the path to walk along */ SyntheticPath path; /** walking-speed in meter per sec */ float walkSpeed_meterPerSec = 1.2; /** adjusted while walking */ float walkedDistance = 0; /** adjusted while walking */ Timestamp walkedTime; /** the listener to inform */ std::vector listeners; const char* name = "SynWalker"; public: /** ctor */ SyntheticWalker(SyntheticPath path) : path(path) { ; } /** attach a new listener */ void addListener(Listener* l) { this->listeners.push_back(l); } bool done() { return path.doneAtDistance(this->walkedDistance); } /** increment the walk */ Point3 tick(const Timestamp timePassed) { // update time this->walkedTime += timePassed; // update the walked distance using the walking speed this->walkedDistance += walkSpeed_meterPerSec * timePassed.sec(); // get the current position along the path const Point3 curPosOnPath = path.getPosAfterDistance(this->walkedDistance); const bool isPlainPart = path.isPlain(this->walkedDistance); const Type type = (isPlainPart) ? (Type::FLOOR) : (Type::NON_FLOOR); Log::add(name, "walkTime: " + std::to_string(walkedTime.sec()) + " walkDistance: " + std::to_string(walkedDistance) + " -> " + curPosOnPath.asString() ); // inform listener for (Listener* l : listeners) {l->onWalk(walkedTime, walkedDistance, curPosOnPath, type);} return curPosOnPath; } }; #endif // SYNTHETICWALKER_H