• Content count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About andrewo

  • Rank
  1. Quote:Original post by Trap Singletons are global variables without the initialization order problem. Nothing more, nothing less. There are significant differences between a singleton and a global variable. Unlike a global variable, a singleton isn't simply data. A singleton should provide a public interface that regulates how the programmer interacts with it. Singletons thus provide some level of data hiding since a programmer will access it only through its public interface. One major problem with global variables is unrestricted, unprotected access - the singleton design pattern overcomes this since the coder interacts with it only through public functions. I tend to use the singleton design pattern for lower-level managers and such. I have difficulty, for example, creating and passing around a settings-manager throughout a program since it needs to be accessed by multiple parts of the engine and there should be only one instance of it.
  2. Quote:Original post by petewood Are people really still using Singletons? Just Create One. Why is it that every time someone brings up the singleton design pattern, someone has to derail the thread into a ridiculous debate over the design implications of using them? The original poster was simply asking for help in developing his Singleton class - the usefulness and debate over the singleton design pattern are irrelevant.
  3. Clean Coding

    Quote:Original post by Brandon N I find having to scroll a page to read code makes it less readable. Your second version would significantly increase the likelihood of having to scroll. It unnecessarily makes the code longer. Furthermore, anyone not using intellisense these days is just wasting their own time. You should never be forced to find the declaration of a variable to determine its type. This seems like a rather inane thing to disagree over, but I strongly suggest using the one declaration per line rule. True, this style requires significantly more screen space, but it's certainly warranted, just as breaking a long expression down into multiple lines is necessary to preserve readability. Also, this slighlty more verbose style allows one to more easily identify the variable's type. Also note that it is just as ridiculous to rely exclusively on intellisense to identify a variable as it is for one to be forced to find the declaration of the variable to determine its type. Both means reinforce to the reader the variable's type. Remember, however, that to a person that reads the code, the one declaration per line rule is far more readable. The cost of scrolling in this example is outweighed by the increased readability of the declarations. A person reviewing a routine can far more easily identify the variables when they are declared on a line by themselves. Certainly, this is a rather subjective style consideration, though.
  4. Clean Coding

    Quote:Original post by Dakar Alos, I would consolidate the three variable lines into one: int score1, score2, score3; Then, you could do something like score1 = score2 = score3 = 0;. I disagree with this advice. Placing each variable declaration on its own line greatly increases readability. When one attempts to fit multiple variable declarations on a line, it detracts from readability and clutters code - effectively rendering it less manageable. Consider this: int x, y; int width, height; Mammal dog, cat, monkey, lion, tiger; Reptile lizard, alligator; Amphibian frog, toad; I consider that to be a whole lot less readable and a lot less manageable than this: int x; int y; int width; int height; Mammal dog; Mammal cat; Mammal monkey; Mammal lion; Mammal tiger; Reptile lizard; Reptile alligator; Amphibian frog; Amphibian toad; This style is a lot more manageable and allows the coder to more easily identify a variable and its type. You can easily tell that the toad is an Amphibian, not a Reptile. This distinction isn't as obvious in the first example. Sorry, I know this is a small nitpick but this may save you a headache or two later on. Likewise, it's always easier to start off with good coding habits than to later switch to them.
  5. load a 3D land from a bitmap

    You probably want to look into loading a height map. I believe there's a tutorial at if you're using OpenGL. There's also a good tutorial at You'll essentially be determining the height of each point by looking at the intensity of each pixel. Both of these tutorials describe how to load a RAW file and then create a height map from it. If you mean by bitmap, a Windows '.bmp' file, then it's simple enough to write a function that extracts the data from a Windows '.bmp' file.
  6. dynamically deleting arrays

    When you do p = "hello" you're actually changing what p is pointing to. In this example, you're pointing to the string "hello" rather than modifying the memory you allocated. You could try something like: strcpy(p, "hello") instead. That way, you'd be modifying your dynamically-allocated memory rather than making p point to a constant string.
  7. OpenGL in SDL

    You could probably follow along with the book if you skip its initialization code. Though it can be tiring and complicated, I'd suggest using a book's OpenGL initialization code rather than writing your own if you're new to OpenGL. That way, you can follow along with the entire book and avoid obscure bugs that might come up.
  8. Game engin question

    You may want to look at the Enginuity engine tutorial: or you could look at one of id's open source engines: There are also various books on game programming that you should look into if you are in need of more tutorials or information. If you're new to game programming, I'd strongly suggest you make simpler games first as developing a SRPG for your first project would be ridiculously difficult. Likewise, if you are new to using graphics libraries then you should probably learn one first (OpenGL, DirectX, and SDL are popular libraries). Game programming can be incredibly difficult, good luck.
  9. Trying to install SUSE LINUX

    I believe SUSE provides floppy images if you cannot boot from a CD. A google search came up with I think that's what you're looking for. I might be wrong here, but I think sometimes you can enable booting from a CD by changing a setting in your BIOS - if you haven't looked into that yet.
  10. Sorry, I posted a file you could use but messed up the source tags. I couldn't seem to fix it either (it was a really huge file). Just do what Auron suggested and you'll be fine :)
  11. Gmail Acounts

    I'd like a gmail invite if anyone has an extra one to spare [smile] My current email address is Thanks!
  12. One of the files you modified may inadvertently include the some or all of the rest of your project. You might want to make sure you're making proper use of include guards. Also, you might not want to include everything in every file if nothing else works.
  13. I think you could use typeid for that. if (typeid(object) == CObjectType) { } I don't think its performance is particularly good, but neither is Java's instanceOf. Edit: Beaten, sorry.
  14. OpenGL Rotation in ortho

    I think that you'd probably be able to use a rotation formula to find the new x and y coordinates. If I remember correctly, that would be: x' = cos(angle) * x - sin(angle) * y y' = sin(angle) * x + cos(angle) * y