SDL_Surface passing

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Bullet Pulse
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 89
Joined: Sun Feb 21, 2010 6:25 pm

SDL_Surface passing

Post 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?
Image
User avatar
davidthefat
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 529
Joined: Mon Nov 10, 2008 3:51 pm
Current Project: Fully Autonomous Robot
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: California
Contact:

Re: SDL_Surface passing

Post by davidthefat »

I like to use the pointer way, I just like it IDK why
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: SDL_Surface passing

Post by XianForce »

Personally, I have the window as a global singleton, because almost everything needs access to it.
User avatar
Bullet Pulse
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 89
Joined: Sun Feb 21, 2010 6:25 pm

Re: SDL_Surface passing

Post 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?
Image
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: SDL_Surface passing

Post by Bakkon »

Code: Select all

bool Player::Render(SDL_Surface* screen);
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: SDL_Surface passing

Post 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);
Post Reply