Skip to content

Commit

Permalink
Should work
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Jonsén committed Oct 20, 2015
1 parent cfbbc29 commit 6a95060
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lab3/CollisionSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ simulate(double limit)
{
predict(&particles[i], limit);
}
pq.insert(Event(0.0, 0, 0)); // redraw event
pq.toss(Event(0.0, 0, 0)); // redraw event

// the main event-driven simulation loop
while (!pq.isEmpty() && !quit) {
Expand Down Expand Up @@ -67,15 +67,15 @@ predict(Particle* a, double limit)
double dt = a->timeToHit(particles[i]);
if (t + dt <= limit)
{
pq.insert(Event(t + dt, a, &particles[i]));
pq.toss(Event(t + dt, a, &particles[i]));
}
}

// particle-wall collisions
double dtX = a->timeToHitVerticalWall();
double dtY = a->timeToHitHorizontalWall();
if (t + dtX <= limit) pq.insert(Event(t + dtX, a, 0));
if (t + dtY <= limit) pq.insert(Event(t + dtY, 0, a));
if (t + dtX <= limit) pq.toss(Event(t + dtX, a, 0));
if (t + dtY <= limit) pq.toss(Event(t + dtY, 0, a));
}

/**
Expand All @@ -97,7 +97,7 @@ redraw(double limit)
SDL_Delay(20); // pause for 20 milliseconds
if (t < limit)
{
pq.insert(Event(t + 1.0 / hz, 0, 0));
pq.toss(Event(t + 1.0 / hz, 0, 0));
}
}

Expand Down
11 changes: 8 additions & 3 deletions lab3/MinPQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ class MinPQ
* Find the smallest item in the priority queue.
* Return the smallest item, or throw min_pq_error if empty.
*/
const Comparable & findMin() const
const Comparable & findMin()
{

if(isEmpty())
throw min_pq_error("findMin: tom heap");

if (!orderOK)
fixHeap();
return array[1];
}

Expand All @@ -78,8 +82,9 @@ class MinPQ
*/
void toss(const Comparable & x)
{
array[currentSize++] = x;
orderOK = currentSize == 1 || array.at(currentSize/2 - (currentSize-1) % 2) > x;
checkSize();
array[++currentSize] = x;
orderOK = array.at(currentSize/2) >= x;
}

/**
Expand Down
Binary file modified lab3/a.out
Binary file not shown.

0 comments on commit 6a95060

Please sign in to comment.