SFML community forums

Help => Window => Topic started by: nomonkeybusiness on February 24, 2009, 01:32:45 pm

Title: Is there a GetError() in sfml?
Post by: nomonkeybusiness on February 24, 2009, 01:32:45 pm
Hi all! I'm new to the forum, and new to SFML.
I am studying at Gotland University, where I study to become a game programmer. I have previously used SDL to build games, and I think I have a decent knowledge of C++.
Anyhow. I am just getting started with SFML, and I'm wondering wether there is a function similar to SDL's "SDL_GetError()" wich returns a const char*, containing a description of the last error that occured. So..is there?
Thanks

/Christoffer
Title: Is there a GetError() in sfml?
Post by: Daazku on February 24, 2009, 02:10:26 pm
Nope
Title: Is there a GetError() in sfml?
Post by: Laurent on February 24, 2009, 02:49:46 pm
Errors are written on the standard error output (std::cerr).
Title: Is there a GetError() in sfml?
Post by: nomonkeybusiness on February 24, 2009, 03:57:59 pm
Yes, i just noticed, thank you ;)
Title: Is there a GetError() in sfml?
Post by: nomonkeybusiness on February 24, 2009, 04:00:14 pm
While we're on the subject of comparing SDL and SFML.
I'm building a basic framework, and I'm having a "drawImage()" in my cRenderTools class.
Is there any way of obtaining the renderwindow to draw on, from an outside class without having to send it there via function arguments?
Like sdl's SDL_GetVideoSurface() ?
Title: Is there a GetError() in sfml?
Post by: Laurent on February 24, 2009, 04:15:17 pm
Quote
Is there any way of obtaining the renderwindow to draw on

And which one is it? In SFML you can have multiple render windows at the same time.
Title: Is there a GetError() in sfml?
Post by: nomonkeybusiness on February 24, 2009, 04:17:32 pm
Oh. Didn't know that. Well, it seems kind of...not good to initialize a new renderwindow for the purpose of drawing stuff on, so a would like to obtain the main renderwindow, the one that I initialize in my cApp-class.
Title: Is there a GetError() in sfml?
Post by: dunce on February 25, 2009, 08:46:47 am
Quote
...not good to initialize a new renderwindow for the purpose of drawing stuff on, so a would like to obtain the main renderwindow, the one that I initialize in my cApp-class.


1. Make your own renderwindow derived singleton class for main render target and use something like this: MainRenderWnd::getInstance().whatever()
2. Use global variable if you are stuck at C style.
Title: Is there a GetError() in sfml?
Post by: Tank on February 26, 2009, 08:39:07 am
Quote from: "dunce"
1. Make your own renderwindow derived singleton class for main render target and use something like this: MainRenderWnd::getInstance().whatever()
2. Use global variable if you are stuck at C style.

Uhm.. In my opinion both suggestions aren't really good. Singletons should be used *extreme* rarely. It's better to give references to a RenderTarget  instead making everything dependent on that one singleton.
And second, do never ever use global variables. I'd be fine if C++ didn't allow them. ;)
Title: Is there a GetError() in sfml?
Post by: Daazku on February 26, 2009, 02:19:32 pm
Quote from: "Tank"

And second, do never ever use global variables. I'd be fine if C++ didn't allow them. ;)


And global accessor?
Title: Is there a GetError() in sfml?
Post by: Tank on February 26, 2009, 11:51:23 pm
Global accessors are global variables wrapped into an accessor function. :) Why don't just encapsulate stuff into something where it belongs to? Nothing needs to be "just there".
Title: Is there a GetError() in sfml?
Post by: Daazku on February 27, 2009, 02:18:20 pm
And how will you desing a game with Graphics. Audio, Network, Game engine without global accessor? All objects need to use these module and the simplest (and fastest) way to do that is via global accessor.

"Global" -> "Static" don't exist for nothing.
Title: Is there a GetError() in sfml?
Post by: Nexus on February 28, 2009, 01:59:02 am
Quote from: "Daazku"
And how will you desing a game with Graphics. Audio, Network, Game engine without global accessor? All objects need to use these module and the simplest (and fastest) way to do that is via global accessor.
The fastest, no. The simplest, yes. But only in the short term. The dependencies you create can become your doom. For example graphics: You don't need them everywhere. Not at all. You can let a single or a few classes handle graphics and call their methods with logic parameters. Creating a sf::Sprite and instantly drawing it everywhere something needs to be drawn might be the wrong way...

Quote from: "Daazku"
"Global" -> "Static" don't exist for nothing.
Not for nothing. But backward compatibility is one of the reasons.
Title: Is there a GetError() in sfml?
Post by: Groogy on February 28, 2009, 01:04:20 pm
I would instead keep global variables in a namespace, you know like for things that don't need to be objects.

Like an ImageManager, though it needs two dynamic arrays to keep track of image and the name of image. Those I would keep global but only the functions within the namespace would be allowed to use them.

Like I have a "private" function in the namespace called "AllocData" that is not declared in the header file and it allocates the arrays. And thne the only function used outside is "sf::Image * GetImage(const char * name)". If your not going to use global here, would you instead place them in the GetImage function as a static variable?

I would say global variables is just a taboo by teachers and books. It's still Not everything needs to be objects, it only makes the application slower, so if it can be designed as not an object would be faster and better.
Title: Is there a GetError() in sfml?
Post by: Tank on February 28, 2009, 03:22:03 pm
Quote
"Global" -> "Static" don't exist for nothing.

Statics don't imply being global, at least not being in any global namespace.

IMHO Nexus is absolutely right. You create a lot of dependencies, thus writing code that is far away from being modular. This is something that's often done wrong with games, in my opinion. Why should classes like "Weapon" or "Player" draw themselves? You should rather write classes that *use* those, e.g. for displaying or sending stuff over the network.

Quote
I would instead keep global variables in a namespace, you know like for things that don't need to be objects.

Nothing "needs" to be an object, but it's just more logical, especially in terms of object oriented programming. Why doesn't your ImageManager belong to something more specific? Like a Game class or Gamestate class or whatever? I can't understand why resource managers are just "there" and don't belong to anything. That's a reason why I dislike singletons, and your design is a kind of singleton.

Quote
I would say global variables is just a taboo by teachers and books. It's still Not everything needs to be objects, it only makes the application slower, so if it can be designed as not an object would be faster and better.

There's a reason why teachers and books (also good books, for example by Bjarne Stroustrup) teach you that you shouldn't use such designs. There's also a reason why you shouldn't use "goto". Mostly people just don't know the reason and think it's only a "programmer taboo", but it isn't.
Not everything should belong to an object, that's true, but only for modularity reasons. For example, you should not write overloading functions for operator<< using ofstreams as a member. And please show up where your method is somewhat faster than *elegant* C++ code. The difference is neglectable. And if you've got a reason to produce more dirty code, you can still do that when performance penalties occure, but not by pre-optimization.
Title: Is there a GetError() in sfml?
Post by: Groogy on February 28, 2009, 03:47:03 pm
Most programmers want things virtual in C++, kinda like aiming against what Objective-C or Ruby or any dynamic language provides. The whole function lookup process makes it slower. While when you stay with the original C version, it just binds the function to the symbol compiled in the executable.

And sure I agree Globals are bad, but they are very usable, and if used you should only have it as some internal things for a set of functions.



I think we've strayed off-topic.
Title: Is there a GetError() in sfml?
Post by: Tank on March 02, 2009, 09:46:52 am
Quote from: "Groogy"
Most programmers want things virtual in C++

Hopefully only when needed. Virtual functions are only needed for polymorphism. But yeah, most C++ programmers declare function virtual by default, which is a big no-no.

Quote
II think we've strayed off-topic.

True, but since the original question has been answered, I guess nobody cares. ;)