move delay calculation code from helper to random walk class

This commit is contained in:
Mathieu Lacage
2007-07-19 10:01:42 +02:00
parent 3ae6f849ac
commit bb7208b754
3 changed files with 12 additions and 28 deletions

View File

@@ -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 ();
}

View File

@@ -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
{

View File

@@ -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;