move delay calculation code from helper to random walk class
This commit is contained in:
@@ -133,18 +133,22 @@ RandomWalk2dMobilityModel::Start (void)
|
||||
void
|
||||
RandomWalk2dMobilityModel::DoWalk (Time delayLeft)
|
||||
{
|
||||
Time delay = m_helper.GetDelayToNextPosition (m_parameters->m_bounds,
|
||||
delayLeft);
|
||||
if (delay < delayLeft)
|
||||
Position position = m_helper.GetCurrentPosition ();
|
||||
Speed speed = m_helper.GetSpeed ();
|
||||
Position nextPosition = position;
|
||||
nextPosition.x += speed.dx * delayLeft.GetSeconds ();
|
||||
nextPosition.y += speed.dy * delayLeft.GetSeconds ();
|
||||
if (m_parameters->m_bounds.IsInside (nextPosition))
|
||||
{
|
||||
m_event = Simulator::Schedule (delay, &RandomWalk2dMobilityModel::Rebound, this,
|
||||
delayLeft - delay);
|
||||
m_event = Simulator::Schedule (delayLeft, &RandomWalk2dMobilityModel::Start, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ASSERT (delay == delayLeft);
|
||||
m_event = Simulator::Schedule (delay, &RandomWalk2dMobilityModel::Start, this);
|
||||
}
|
||||
nextPosition = m_parameters->m_bounds.CalculateIntersection (position, speed);
|
||||
Time delay = Seconds ((nextPosition.x - position.x) / speed.dx);
|
||||
m_event = Simulator::Schedule (delay, &RandomWalk2dMobilityModel::Rebound, this,
|
||||
delayLeft - delay);
|
||||
}
|
||||
NotifyCourseChange ();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,23 +64,6 @@ StaticSpeedHelper::Reset (const Speed &speed)
|
||||
m_speed = speed;
|
||||
m_pauseEnd = Simulator::Now ();
|
||||
}
|
||||
Time
|
||||
StaticSpeedHelper::GetDelayToNextPosition (const Rectangle &bounds, Time delayLeft)
|
||||
{
|
||||
UpdateFull (bounds);
|
||||
Position nextPosition = m_position;
|
||||
nextPosition.x += m_speed.dx * delayLeft.GetSeconds ();
|
||||
nextPosition.y += m_speed.dy * delayLeft.GetSeconds ();
|
||||
if (bounds.IsInside (nextPosition))
|
||||
{
|
||||
return delayLeft;
|
||||
}
|
||||
|
||||
nextPosition = bounds.CalculateIntersection (m_position, m_speed);
|
||||
Time delay = Seconds ((nextPosition.x - m_position.x) / m_speed.dx);
|
||||
return delay;
|
||||
}
|
||||
|
||||
void
|
||||
StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const
|
||||
{
|
||||
|
||||
@@ -16,11 +16,8 @@ class StaticSpeedHelper
|
||||
void InitializePosition (const Position &position);
|
||||
|
||||
void Reset (const Speed &speed, const Time &pauseDelay);
|
||||
|
||||
void Reset (const Speed &speed);
|
||||
Time GetDelayToNextPosition (const Rectangle &bounds, Time delayLeft);
|
||||
Position GetCurrentPosition (const Rectangle &bounds) const;
|
||||
|
||||
Position GetCurrentPosition (void) const;
|
||||
Speed GetSpeed (void) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user