1/* 2 * Copyright 2007, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8#include "PolygonQueue.h" 9 10#include <stdio.h> 11#include <string.h> 12 13#include "Polygon.h" 14 15// constructor 16PolygonQueue::PolygonQueue(Polygon* start, int32 depth) 17 : fPolygons(new Polygon*[depth]), 18 fDepth(depth) 19{ 20 for (int32 i = 0; i < fDepth; i++) 21 fPolygons[i] = NULL; 22 fPolygons[fDepth - 1] = start; 23} 24 25// destructor 26PolygonQueue::~PolygonQueue() 27{ 28 for (int32 i = 0; i < fDepth; i++) 29 delete fPolygons[i]; 30 delete[] fPolygons; 31} 32 33// Head 34Polygon* 35PolygonQueue::Head() const 36{ 37 return fPolygons[fDepth - 1]; 38} 39 40// Tail 41Polygon* 42PolygonQueue::Tail() const 43{ 44 return fPolygons[0]; 45} 46 47// Step 48void 49PolygonQueue::Step() 50{ 51 if (Polygon* p = Head()) { 52 Polygon *np = p->Step(); 53 // drop tail 54 delete Tail(); 55 // shift 56 for (int32 i = 0; i < fDepth - 1; i++) 57 fPolygons[i] = fPolygons[i + 1]; 58 // and put new head at top 59 fPolygons[fDepth - 1] = np; 60 } 61} 62