Exercise 11.1: Turn off asteroid “ asteroid collisions in Spacewar

Turn off the asteroid-to-asteroid collisions in the Spacewar game. To do this, override the cCritterAsteroid::collidesWith(cCritter *pcritterother) method. You'll need to prototype the method in gamespacewar.h and implement it in gamespacewar.cpp. The implementation code should have these two lines.

 if(pcritterother->IsKindOf(RUNTIME_CLASS(cCritterAsteroid)))      return cCollider::DONTCOLLIDE;  return cCritter::collidesWith(pcritterother); 

Does this make the game run faster? Compare speeds before and after, using the Game popup menu to change the number of critters. When you compare the speeds of builds always make sure that both are Debug builds or both are Release builds.

Exercise 11.2: Compare performance of cCollider using list and array

(a) Run the Spacewar game on your machine and notice if it lurches when you shoot some critters. Note the updates per second with a huge number of critters. (b) Now go into collider.h, comment out the line #define USECOLLIDERLIST, to switch from a list to an array for the cCollider . Rebuild the program, making sure to use Build Set Active Configuration to the Release build if the build you checked in step (a) was also a Release build. Compare performance. On some machines you won't notice a difference and on some you will. At one point a tester saw some freeze-ups of the program when using the array build, though maybe the bug was only a transient coincidence .

Exercise 11.3: Sequence diagrams for adding and deleting critters

Recall that a sequence diagram's column really represents one individual object's behavior. In the case where there's only one object of the type under consideration we only write the class name instead of the name of the object; in the case where we're discussing more than one object of a given type, we write a class name with a colon and an object name. In doing parts (a) and (b) we may want to check the Pop Framework code for details or, even better, use the debugger to step through the sequence of events when you add or delete a critter.

  1. Draw a sequence diagram with columns for cGame , cColliderPair , cCritter:pa , cCritter:pb , cCollider and possibly cBiota to map the functions called when you add pa to the game, assuming that pb is a critter already in the game that pa is interested in colliding with.

  2. Draw a sequence diagram with the same columns to show what happens when pa is deleted.

Software Engineering and Computer Games
Software Engineering and Computer Games
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net