From bb7208b75471001487ba106d85df7ce1a4fc033e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 19 Jul 2007 10:01:42 +0200 Subject: [PATCH] move delay calculation code from helper to random walk class --- src/node/random-walk-2d-mobility-model.cc | 20 ++++++++++++-------- src/node/static-speed-helper.cc | 17 ----------------- src/node/static-speed-helper.h | 3 --- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/node/random-walk-2d-mobility-model.cc b/src/node/random-walk-2d-mobility-model.cc index 83fd8761d..ee0b82fc9 100644 --- a/src/node/random-walk-2d-mobility-model.cc +++ b/src/node/random-walk-2d-mobility-model.cc @@ -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 (); } diff --git a/src/node/static-speed-helper.cc b/src/node/static-speed-helper.cc index e09a7112f..03e1f066d 100644 --- a/src/node/static-speed-helper.cc +++ b/src/node/static-speed-helper.cc @@ -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 { diff --git a/src/node/static-speed-helper.h b/src/node/static-speed-helper.h index 4b97b39f9..90fe0601a 100644 --- a/src/node/static-speed-helper.h +++ b/src/node/static-speed-helper.h @@ -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;