• Advertisement

Archived

This topic is now archived and is closed to further replies.

DD surfaces... global or passed

This topic is 6620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Most of the time I pass them globally. But now I'm working on an engine, and I want the user to be able to use as many surfaces as they want, so for that I have to pass them in the function.

But I don't think performance suffers that much when passing surfaces in a function (I know it does suffer some though).

Share this post


Link to post
Share on other sites
Advertisement
Someone correct me if am wrong but what is given to you by Direct Draw is a pointer rather than the actual surface itself. Hence if you pass the LPDIRECTDRAWSURFACE object to a function all you are really passing is the pointer, a simple 4 bytes, and not the entire surface. So I guess it would be a performance drain but only a nominal one.

Share this post


Link to post
Share on other sites
I guess what I was getting at was this:

Declare as global or in winmain (and thus pass into the game loop)?

Perhaps I didn't word it clearly enough.. still probably not . It was a question I've had for a couple months, and I finally got around to posting it--or what was left of it in my mind.

Six

Share this post


Link to post
Share on other sites
Personally I prefer the nice organization that a well thought out set of C++ classes offer as opposed to global data. IMHO, it makes it easier to program in the long run, especially as you're engine grows in complexity, and if done correctly you can limit performance hits from accessing encapsulated data.

Share this post


Link to post
Share on other sites
Sieggy,
Which leads me back to the original question; in a broader sense. Is your class declared globally or in main?

Six

Share this post


Link to post
Share on other sites
SixPack,

While most view it as a sacrilege, I suppose, I use a skeleton MFC structure. Now that preference aside, I have my major interfaces to Direct3D kept as members of my application's window class which is inherited from CFrameWindow. It handles all my major coordination of rendering. My application specific surfaces like my tiles and such are stored in classes that represent that object type. For instance CTile allows me to code behavior specific for that object type as well as provide access to its surface.
I probably dragged this out too much! If I was using winapi style code I probably would still do a similar construction as I described above: wrap my major interfaces and surfaces into a scene managment class stored in main and my other surfaces into classes that cooresponded to their object's function. I like the idea that a class can hold data, manipulate, and store it "behind the scene" so to speak, and the querying class does not have to know about what was going. You can't really guarantee this kind of relationship with global data so I avoid use of globals. Some poeple still aren't real big fanatics of the object oriented style but I think its incredibly powerfull, IMHO. I long answer, but does that answer you're question?

Share this post


Link to post
Share on other sites
ahhh... winmain or globally. I'd definately go with globally. I don't think I've seen a program yet that has declared direct draw variables in winmain. Well that's my recomendation!

Share this post


Link to post
Share on other sites
Just wanted to get your( guys/gals) feelings on this-

When using DirectDraw (whether it be encapsulated in a class or stand alone), do you pass the surfaces to functions or do you leave them as global variables?

I've seen this done both ways, but my feeling is that performance suffers when they are passed.

Six

Share this post


Link to post
Share on other sites

  • Advertisement