// CSE 143 // Homework 5 // http://www.cs.washington.edu/education/courses/143/00su/homework/ // 30 Jul 2000, Ken Yasuhara #include #include "gp142.h" #include "fireworksdisplay.h" ////////////////////////////////////////////////////////////////////// // constructors, destructor // slowdownFactor's default value is 1 FireworksDisplay::FireworksDisplay(const char scriptFilename[], const int slowdownFactor) : script(scriptFilename) { fireworkCount = 0; for (int i = 0; i < MAX_FIREWORK_COUNT; i++) { fireworks[i] = NULL; } backgroundObjectCount = 0; for (i = 0; i < MAX_BACKGROUND_OBJECT_COUNT; i++) { backgroundObjects[i] = NULL; } time = 0; assert(slowdownFactor > 0); periodicEventsPerFrame = slowdownFactor; script.getNextFirework(nextFirework, nextFireworkLaunchTime); // sets whether or not to animate; Run is an enum // animation can also be turned on and off by the end-user // via choices on the graphics window RUN menu display.setAnimation(Run); } ////////////////////////////////////////////////////////////////////// // managing backgroundObjects, fireworks void FireworksDisplay::addScheduledFireworks() { while (nextFirework != NULL && nextFireworkLaunchTime <= time) { if (nextFireworkLaunchTime < time) { printf("FireworksDisplay: launched out-of-order firework late\n"); } addFirework(nextFirework); script.getNextFirework(nextFirework, nextFireworkLaunchTime); } } ////////////////////////////////////////////////////////////////////// // animation void FireworksDisplay::paintFrame() { // paint background first, so foreground elements appear as though // they're closer paintBackground(); paintFireworks(); // forces redraw; effects of paint might not appear on screen otherwise display.flush(); } void FireworksDisplay::waitUntilNextFrame() { int periodicEventCount = 0; while (periodicEventCount < periodicEventsPerFrame) { // don't really need mouse/keyboard event info, but need to // pass something in for ref. params. int mouseX, mouseY; char keyPress; GP142Event nextGP142Event = display.getNextEvent(mouseX, mouseY, keyPress); if (nextGP142Event == Periodic) periodicEventCount++; else if (nextGP142Event == Quit) exit(0); } }