Performance and Speed

If you write Python code to do complex numerical work and then compare the results to those done with C++, you will be disappointed. The plain truth is that Python is a slower language. In Python, every variable reference is a hash table lookup, and so is every function call. This cannot compete with C++, in which the locations of variables and functions are decided at compile time. However, this does not mean that Python is not suitable for game programming itjust means that you have to use it...

Figure The flat plane becomes a full rotating cube

Pyopengl Glrotatef Spin

Let's say you wanted to speed up and twist your rotating cube around a bit more. It's easy to fiddle with MatrixMode, especially since you've thought ahead and included a number of variables with which to do it x,y, and z rots are the rotations on each axis xrot yrot zrot 0.0 These variables, xrot, yrot, and zrot, can be used to rotate the cube in a new way on the x-, y-, and x-axes. Do so by adding a few lines to the top of drawgraphics glLoadidentity glTranslatef 0.0, 0.0, -5.0 global rquad...

Drawing a Square

Our third function is the code that actually draws the display, so let's call it drawgraphics . This function will actually display everything that goes onto the screen, so it will be doing most of the work in each example. First you glclear to clear the screen to a color, clear the buffer, and then reset with glLoadidentity. glLoadidentity actually moves you to the center of the screen, which is 0,0 on the x- and y-axis. Left and down are negative numbers, and right and up would be positive...

Lua Pros and Cons

Lua is probably the fastest of the three languages and usually uses the least amount of runtime memory. Lau has the smallest memory footprint for bundling. The Lau C API is very well documented and has good examples for integrating with C. The documentation has improved but is still a bit sketchy overall. Of the three languages, Lua it is probably the least documented the API being the exception , with the least amount of code comments. This makes for the largest ramp-up time to learn, and...

Memory Performance and Speed

Lua Table And Stack

Like most high-level languages, Lua manages memory automatically, so that you don't have to worry about allocating memory for new objects and freeing it when the objects are no longer needed. Lua manages memory automatically by running a garbage collector from time to time to collect any objects that are no longer accessible to Lua. The garbage collector picks up all of Lua's objects, including threads, tables, and so on. Although this is not an issue when running the Lua interpreter, when...