#8 in Game programming books
Use arrows to jump to the previous/next product
Reddit mentions of Game Coding Complete
Sentiment score: 3
Reddit mentions: 4
We found 4 Reddit mentions of Game Coding Complete. Here are the top ones.
Buying options
View on Amazon.comor
Used Book in Good Condition
Specs:
Height | 9.75 Inches |
Length | 7.75 Inches |
Number of items | 1 |
Weight | 3.4061419479 Pounds |
Width | 2.25 Inches |
Based on the code you provided:
for (int y = 0; y < arrayHeight; y++)
{
for (int x = 0; x < arrayWidth; x++)
{
MapGrid[x, y].draw();
}
}
You're encountering a cache miss every time you access a grid cell. When the program is executed, a chunk of memory is loaded from the RAM into the CPU's program cache. This improves execution time by minimizing the number of times the CPU has to ask the RAM for data (which is relatively slow). To fully understand the problem it may be valuable to review what a 2d array actually is: an array of pointers to arrays. Because of this, each array (column, if you think about it as a 2d array) could be anywhere in memory. When you iterate over the first element in each array, the CPU has to grab that array from memory and put it in the program cache. The iteration in the loop you're getting the first element of the second array, which isn't in the cache, so it has to clear the cache and load the second array. This is the origin of your slowdown. Solving this problem is easy, just iterate over an entire array at once, reducing the potential cache misses from xy to x.
for (int x = 0; x < arrayWidth; x++)
{
for (int y = 0; y < arrayHeight; y++)
{
MapGrid[x, y].draw();
}
}
Another option is to use one contiguous array in memory. This will help with access time by minimizing the number of cache misses. You can still treat it as a 2d array by making an intermediate method to access an element:
GetElementAt(int x, int y)
{
return MapGrid[x arrayWidth + y];
}
Hope this helps! :)
If you want to learn more about this, there's a great section of Game Coding Complete that talks all about cache misses and how terrible they are for performance.
Edit: After the first optimization it reduces the potential cache misses to approximately x instead of y. This is just an estimate though, because it depends on your platform, your CPU's L1/L2 cache size, and how things are allocated at runtime.
I kind of sounds like you're whining.
go to /r/gamedev
If you know how to program effectively and you want to do something solo. Learn how to Art. If you know how to Art, learn better programming skills.
here's some of my favorite book recommendations
Programming:
Game Coding Complete
The fucking bible as far as books on game development goes. Made by one of the senior developers on the Ultima series. Seriously. Good book.
Game Engine Architecture
Also a really good book, teaches you more about usability beyond yourself if you ever find time or reason to expand your team.
Art:
Drawing on the Right side of the brain This is a very good text for getting you out of your comfort zone and into the mindset you need to have to do good art. This book won't teach you how to make good art, practice will, but its a good first step.
I'd also start looking around, take a look at Blender, we have a great community at /r/Blender and start learning how to do modelling, theres some great tutorials on the gamedev subreddit, as well as a number of classes on Programming and one on Game Concept art at University of Reddit.
Now get up off your ass and start building a game. Pixel. By. Pixel.
and if you have any questions, shoot me a pm, I'd be glad to help!
Be sure to take a look at Microsoft XNA Game Studio 3.0 Unleashed.
It has a good section on high level shader language, and of course lots on the basics of the framework.
Otherwise, I might also suggest Game Coding Complete, Third Edition. PartII and on is a lot of C++ implementation details, but Part I has a great deal of good advice, concepts, and ideas that are applicable. Best to see if your local library has it.
Currently I'm reading Game Coding Complete by Mike McShaffry -- it is Code Complete for game developers. It discusses topics from basic project setup till rendering, AI and networking. Also it provides additional reading material for further reading. Imho very good book and recommended read. http://www.amazon.co.uk/Game-Coding-Complete-Mike-McShaffry/dp/1584506806