Game Development Reference
In-Depth Information
rule, like to optimize, so here are some pointers. Matrices involve a lot of ar-
ithmetic so reducing the use of matrices is generally a good thing. The most
optimized code is the code that never runs.
At the moment, each sprite is made of two triangles, making a total of six ver-
tices, but really, a sprite could be made with a mere four vertices. A good starting
point to address this would be investigating the index buffer functions in the
OpenGL documentation.
Modern CPUs have specialized hardware, SIMD (which stands for Single In-
struction, Multiple Data), to do matrix and vector operations. The SIMD in-
structions dramatically increase the speed of matrix calculations. Unfortunately,
at the time of writing, SIMD operations are only supported under the Mono
implementation of C#.
Most of your test programs will be built in debug mode. Release mode is much
faster. There is also an option to turn on optimization if you right-click the
project in the solution explorer and choose Properties.
Garbage collection is one thing that can make C# slower than a language like
C++. The best way to avoid slow down from the garbage collection is to reduce
the amount of objects created in the main loop. You are creating an object any
time you use the keyword new . Objects are best created once in the constructor
or defined as a member of the object and not in the process or render loops.
Some of the matrix operations create matrices. It makes them convenient to use
and a lot of the object creation will be optimized away, but they can be made
more efficient. When debugging, if you right-click the window, there's an option
called ''Go to Disassembly.'' This shows the IL (intermediate language) gener-
ated by each line of the C# code. The fewer IL instructions, the faster the code will
run, provided the release build optimization doesn't already remove these IL
instructions for you. Unfortunately, any optimizations the compiler performs
will generally not be shown in the disassembly.
 
Search WWH ::




Custom Search