Chapter 10. Debugging and Performance

In this chapter, we will cover:

  • Debugging Python code
  • Debugging C++ code
  • Using the PStats tool for finding performance bottlenecks
  • Improving performance by flattening scenes
  • Implementing performance critical code in C++

Introduction

As game programmers, our job is to translate the rules, ways of interaction, and ideas defined either by us or the game designers and producers in our development team into program code. We act as the interface between the language of the designers and the language of the computer.

Most of the time we're doing fine when expressing game rules as clever algorithms, but from time to time things go wrong and bugs and errors are introduced to the game. While violations of programming language rules are detected and pointed out to us programmers by compilers and interpreters, errors caused by misinterpretations of the design specifications or by faulty algorithms are the ones that are putting us into all sorts of trouble.

Many of these programming mistakes cause wrong and unintended behavior that is immediately visible to players, who will at best be disappointed by a buggy and broken game. This means that we need to find and fix these errors to keep up quality and produce excellent games. To achieve this goal, we must realize two things: One, programming errors do happen—there's nothing to be ashamed of about that. What we should be ashamed of is being unable to find out what the problem is and how to fix it. Secondly, locating software bugs in big codebases can be a daunting, cumbersome, and even a near impossible task without the support of proper tools.

This is the reason why this chapter will introduce common programs and workflows involved in searching and fixing erroneous program code. Running a program in a debugger and stepping through the code line by line while inspecting its behavior is a part of the basics any programmer has to know!

While our first goal when developing program code should always be to write correct and working implementations of algorithms, there also are functional requirements we need to fulfill. In the case of game development, this mostly means one thing: Maintaining program performance to keep the game updating smoothly, at an interactive rate of thirty times per second or more.

This would be a much easier task if there were not game entity behaviors to be executed, collisions to be found and resolved, animations to be updated, and geometry to be rendered in every frame. A lot of things are going on when one single frame of a game is rendered, and whenever we hit a performance problem, we need to find the root of the problem and find a solution to the problem.

Of course this is not done by trial and error, but by measuring and observing the various components of our game code and the engine. For this purpose, we are going to use the profiling tool included with the Panda3D engine to learn about the possibilities and features it provides for locating performance problems.

Complex scenes containing lots of models are the cause of many performance problems. This is why this chapter will introduce the measures Panda3D provides for simplifying scenes to decrease the load on the scene management and the rendering stages of the engine.

Finally, we will take a look at how to add modules written in C++ to the engine, which can be useful for implementing very complex algorithms that perform poorly when written and run in Python.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset