Page 1 of 1

SDL_Surface passing

Posted: Sat May 15, 2010 10:43 am
by Bullet Pulse
Do you prefer to send a pointer to the buffer to an object each time, like this:

Code: Select all

//In main loop
player.Draw(system.buffer)
Or do you prefer to have a static pointer to an SDL_Surface in the object's class, like this:

Code: Select all

//In main file
Player::Initialize(system.buffer);
Player player;

//In main loop
player.Draw();

//player.h
static void Initialize(SDL_Surface *surface);
static SDL_Surface *surface;

//player.cpp
SDL_Surface *Text::surface;
void Player::Initialize(SDL_Surface *buffer)
{
	surface = buffer;
}
Does it make any difference in efficiency or usefulness?
I think it could, because you don't have to pass a reference to the buffer every time you want to draw something to the screen.

What do you think?

Re: SDL_Surface passing

Posted: Sat May 15, 2010 10:49 am
by davidthefat
I like to use the pointer way, I just like it IDK why

Re: SDL_Surface passing

Posted: Sat May 15, 2010 10:49 am
by XianForce
Personally, I have the window as a global singleton, because almost everything needs access to it.

Re: SDL_Surface passing

Posted: Sat May 15, 2010 11:07 am
by Bullet Pulse
XianForce wrote:Personally, I have the window as a global singleton, because almost everything needs access to it.
I like that idea, do you have a static getInstance() function to access it?

Re: SDL_Surface passing

Posted: Sat May 15, 2010 11:27 am
by Bakkon

Code: Select all

bool Player::Render(SDL_Surface* screen);

Re: SDL_Surface passing

Posted: Sat May 15, 2010 12:41 pm
by XianForce
Bullet Pulse wrote:
XianForce wrote:Personally, I have the window as a global singleton, because almost everything needs access to it.
I like that idea, do you have a static getInstance() function to access it?
Well... Yes and no I suppose... Basically I have an ApplicationSystem. The ApplicationSystem is the only global I have in the project, and holds pointers to a VideoSystem, AudioSystem, StateMachine, and a ResourceSystem (as soon as I finish the ResourceSystem at least). The VideoSystem holds the window, so anything I want to render, I use the VideoSystem for. I also have some macros so I can just do this:

Code: Select all

FF_VideoSystem->Render(position, surface);