GameDev General

Pages: 1... 567
I'm 32 years old. I've been playing games longer than you have been alive and I know how to optimize settings to make the most out of shitty hardware. The laptop is an off the shelf intel product (which back in 2006 wasn't that good). Can't test my desktop as it hasn't been hooked up for a while now.
There's no need for drama, some people honestly don't know that optifine even adds settings and options in the first place. Lumpkin just isn't downcasting from a Person instance to a BHXSpecter instance, which is good practice in programming but not in real life.
Last edited on
Is it okay to use globals when setting up a demo?
Yeah but you should still avoid it when you can. Sometimes you can't avoid it at all (or you can, but it would be even uglier to do so) but you can minimise the "damage" by hiding global variables in namespaces or classes or by making them file-static.
Don't forget another way to minimize the damage is if you can, use constant globals. I do this for my games in regard to if I know tile size for my maps or for my screen resolution that I want to set.

const int SCREEN_W = ###;
const int SCREEN_H = ###;
const int TILE_SIZE = ###; 

Yes, I know capitalized variables are usually used for macros, but I prefer to use it for constants too.
Last edited on by closed account z6A9GNh0
I thought capital globals were the norm. I tend to avoid macros at all costs. The only macros I have are header guards.

I hide globals in namespaces usually. But I just wondered if it was okay temporarily because I wanted to get a demo working soon.
Definitely; globals are one bad thing but non-const ones are much worse. By "damage", though, I meant the chance of naming conflicts, breaking encapsulation, and increasing coupling between different modules. It also makes all your code that relies on globals non-reentrant.
Last edited on
The only globals I'm using in the demo are going to be in the main loop. My engine has no globals whatsoever.
Just on the topic of macros, as this( points out, sometimes you may want to use them (I have actually used this exact sort of thing before), otherwise your code risks getting both complex and unreadable.

Just wanted to point that out, in case anyone reading this thread didn't know about this sort of thing.
closed account (o1vk4iN6)
That still doesn't call for use of macros as you can just use std::function with std::bind to avoid marcos and still produce even cleaner syntax than CALL_MEMBER_FN(obj, fn_ptr)(params...).
That is actually nice, but now I will have to look into std::function and std::bind as I've never used them. I have to admit, I haven't used much of the library, but that is something I will have to keep in mind if I need to do that in future projects.
Why would I need to use std::function or std::bind? What are their purposes?
To make your life easier.
Like can you give me an example?

xerzi already did =>

Contrived example:

typedef std::function<void()> action;


void stuff( action actiontoperform )
  // do prep stuff

  actiontoperform();  // do the action

  // do cleanup stuff

int main()
  MyClass obj;

  obj.DoSomethingWithAFile( "myfile.txt" );  // how to call the function normally

  // but if we want to pass it as an 'action':

  action act = std::bind( &MyClass::DoSomethingWithAFile, &obj, "myfile.txt" );

  stuff( act );  // <- send it to our 'stuff' function

Notice how I did not have to pass the 'obj' or the filename to the "stuff" function. All that information is stored within the std::function object. All I have to do is call it as if it were a normal void() function.
Last edited on
Topic archived. No new replies allowed.
Pages: 1... 567