Page 1 of 1

Objects accessing eachother (OOP question)

PostPosted: Feb 18, 2004 @ 10:23pm
by Volte6

PostPosted: Feb 18, 2004 @ 10:32pm
by warmi
Of course you are going to have to pass a pointer. I personally prefer to use some sort of rendering context class for the backbuffer ( basically a fancy wrapper around backbuffer) and a separate class for storing game images.
Each game object would then keep either a pointer or some sort of ID for the images associated with it and request at run time a pointer to the images it needs from the images repository class.

To access other classes (rendering context or images repository) generally you would have to either pass a pointer to your game objects class or create a global static class containing methods for obtaining pointers to various global classes and include header to it with every class definition.

PostPosted: Feb 18, 2004 @ 10:34pm
by Pam
There are many ways to do this of course.

I have a RasterizerObject that handles all of the drawing and keeps track of the backbuffer, etc.

Your other objects can store a pointer to the RasterizerObject and call routines in that object to draw stuff on the screen.

Pam

PostPosted: Feb 18, 2004 @ 10:36pm
by Kzinti

PostPosted: Feb 18, 2004 @ 10:43pm
by Pam

PostPosted: Feb 18, 2004 @ 11:55pm
by Volte6

PostPosted: Feb 19, 2004 @ 1:26am
by Dan East
I usually have a struct representing the System State. It contains objects and data that I want available to all components. Classes like the console and renderer, and data such as the current frame counter, length of current frame, current tick count, user input data (keystates and mouse position), etc. Then I pass a pointer to that struct to all functions.

Older games like Quake just make all that stuff global, which is bad for a number of reasons. Most importantly, some other mobile platforms do not support global variables.

Dan East