240 likes | 363 Views
Software Performance on an X-Box Game. Brandon Yaussy. Outline. Introduction Development Tower Defense Tools and Techniques Problem Sets Other Performance. Introduction. My partner and I are working on an X-Box game C# XNA Development Kit Tower Defense
E N D
Software Performance on an X-Box Game Brandon Yaussy
Outline • Introduction • Development • Tower Defense • Tools and Techniques • Problem Sets • Other Performance
Introduction • My partner and I are working on an X-Box game • C# • XNA Development Kit • Tower Defense • Waves of enemies walk a preset path • You build towers to combat them • Towers automatically fire when in range • Many problems throughout game • Freeze-Ups • Frame Rate Drops
Development • Planned ahead before coding • Structure • Classes • Inheritance • Used online samples to start • Game class • ScreenManager class • Wrote our own classes
Behind the Scenes • Game Class • Runs everything – starts the game, initializes the classes and objects for play • ScreenManager Class • Preps the different screens for display • MainMenuScreen, PauseScreen, GameplayScreen… • Sprite Class • Initialize() • Update() • Draw()
More Behind the Scenes • Towers • Enemies • Characters • Projectiles • Behaviours • XML files • Sprite Sheets
Source Monitor • Freeware program designed to allow developers to see inside their source code • How much code, how much comments • Depth • Complexity • Includes Tables and Graphs • Kiviat Diagram
Complexity Formula • M = E – N + 2P • M – Cyclic Complexity • E – # of Edges • N – # of Nodes • P – # ofConnected Components • Developed by Thomas McCabe • Believed the value should not exceed 10 • Most Software Engineers believe that should be 15
Kiviat Diagram • 6 attributes that SourceMonitor believes are important for keeping up good performance.
Code Visualizer • Visual analysis tool that complements SourceMonitor • Illustrates control flow • Charts and Diagrams • UML diagrams • Sequence Diagrams • Used to show class relations • Project Statistics • Coupling • Cohesion
Reverse Engineering • Process of understanding the structure and operation of software in order to learn its functions • Basically used to determine design decisions from end products with no additional knowledge of the procedures involved at the beginning. • Why it’s useful to us. • Two people, sometimes working separately • Very busy schedules • Working on it for a year and a half
Problem 1 • Problem: Frame rate would continuously drop once game had started. • Cause: draw() function in Gameplay Screen wasn’t clearing old iterations of objects. • Tool or Technique: Code Visualizer : Code Compare
Explanation • The game displays objects and backgrounds in frames • They go so fast, it tricks the eye into believing it’s smooth movement • Ours got worse and worse • Every sprite has a draw function, that is called from the screen class’ draw function. • This is done multiple times per second to provide animation. • However, the objects being drawn weren’t being destroyed. • It eventually became too much.
Problem 2 • Problem: Frame Rate would instantly shoot to 0 when a tower was placed in competitive mode. • Cause: Setup() in placeTower() was calling the wrong loeadTexture() function. • Tool or Technique:SourceMonitor
Explanation • When a user places a tower, the code calls the placeTower() function which includes the following function calls in order of ascending intricacy • checkColor() • Setup() • Finalize() • addProjectile() • checkSpot() • Build() • Setup should have had a complexity of 2, but instead was marked at 144+. • Setup() was calling a loadTexture() function that causes every texture in the game to be loaded.
Problem 3 • Problem: Game froze when trying to start game in cooperative mode. • Cause: I never had our playerList updated to include two players instead of one. • Tool or Technique: Debugger
Explanation • Whenever a game is started, it needs to preload all of the textures and characters and place certain objects, such as players, into lists. • Our playerList wasn’t updating to a maxSize of 2. • Tried to play cooperative mode, but couldn’t because there was no second player.
Problem 4 • Problem: Game would freeze anytime a cannon tower was built. • Cause: An infinite for-loop was created whenever the first cannon tower was added. • Tool or Technique: Debugging
Explanation • Whenever sprites need to be drawn, they go into a list and then the draw function has a specific for-loop for that category. • In this case, the category is cannon tower. • The for-loop needs to know when to stop looping and since this changes, we use the list count as a stopper. • Since the list had at least one element, the for-loop was activated. • However, I never changed the stopper value from 0 to list count.
HandleInput() • I decided to use my static analysis tool, SourceMonitor, for some other improvements. • Came across a very complex function, HandleInput() and wanted to make it less complex. • HandleInput(), like the name implies, takes button or key presses from the user and acts accordingly. • Separated into blocks of code • Ended up successfully lower… • Lines of code from roughly 750 to 665 • Number of method calls from 86-63
Renew Documentation • My partner and I realized how much we had forgotten about the older, critical classes as the year went by. • We worked separately on some. • Some were borrowed templates. • Never needed changed. • Decided we needed to write documentation and figured we’d try some reverse engineering to write up block comments. • Worked on commenting the other’s functions. • Went backwards through the process in order to relearn it and correctly comment. • After all of our methods and classes were commented, we went from 12% comments to 25.2%.