More efficient game structures?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: More efficient game structures?

Post by Asimov »

Hi Seven,

If your logger was a class, you wouldn't need to pass it around. Every class that uses the logger, could include the header file, and then every class that needed to use it could.

For instance if you had a public variable called x in your logger class and say class boat want to access it. Once logger has been included you can acesss x by simply
using logger.x();

Or you if you want x to be private you could include a function

float logger::getX()
{
return x;
}

and call it from your class boat or any other class with something like

float myx=logger.getX();

If you had a variable in your logger class that needed to be incremented, you just need to make a function that increments the variable, and just call that function from any other class.

I see very few occasions where a global variable is needed, apart from what CuteAlien said heh heh.

PS. I come from a time of programming where all variables were global. It took a long time to get out of the habit LOL.

PPs. Actually I come from an age before variables heh heh. eg
ld hl, 16384
ld de, 16385
ld bc, 6143
ld (hl), 0
ldir
Post Reply