Taking this basic gaming class in C++ is really a neat experience. It allows me to do something fun while learning something tedious or boring. Some say that learning this way is a bad idea, because you can end up learning the teacher’s bad habits.

While that is probably true, I feel that you also will learn the teachers good habits, tricks, shortcuts, and hard learned lessons. One of those that I learned about while completing section 8 of the course was the Texture Holder. What a great idea, to load the textures once and then “farm” them out to objects that need them.

I’m sure this is not just the teacher’s method, and many probably use this trick, but I really appreciate the way that John Horton presented it. You can see my latest commit on GitLab, if you are interested.

someJello

So, as my game, JelloStorm progresses, I’ve been using the Texture Holder class we built to load up all of my jello.

Another interesting this is this “pragma once” statement that he puts at the beginning of the files. The idea is that the compiler should only perform action on the file once. Instead of recompiling it for each time it is called. The alternative is to use include guards like ifndef and define the called include if it is not done so already.

My limited understanding is the best choice is based on the particular compiler you use. So, if you are on Linux, like me, using gcc, then it will optimize include guards instead of pragma statements. If you are on Windows, using something like Microsoft Visual Studio, pragma statements are optimized. So, it would seem best to use the one for which you are building.

Of note, while researching this, it seems that if you are to build something cross platform, you are better off using the include guards. I guess that pragma statements are not part of the compiling standard, and may or may not work with every compiler. However, include guards (like ifndef and define) are part of the standard, and will work on every compiler, making them the safest choice.

So, I think I will go with include guards in the future, rather than pragma statements to make sure my work is suitable everywhere. After I’m done with this class, of course….

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *