Should I modify SFML???

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

User avatar
THe Floating Brain
Chaos Rift Junior
Chaos Rift Junior
Posts: 284
Joined: Tue Dec 28, 2010 7:22 pm
Current Project: RTS possible Third Person shooter engine.
Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
Programming Language of Choice: C/C++, Python 3, C#
Location: U.S

Should I modify SFML???

Post by THe Floating Brain »

Okay so I finally think I have a rough idea of vectors and I wrote these functions
(Calculates a vector)
http://pastebin.com/h6KqWVKu
("Lightning" is the version of my engine)
(Moves a object along a vector)
http://pastebin.com/3dXv5WfQ
Problem being... despite all the long double variables I put the movement of a object along a vector is inaccurate (just slightly).
HELP!.jpg
HELP!.jpg (10.51 KiB) Viewed 2372 times
The reason is that when I pass the "GotoX", and "GotoY" variables (from my function above) into SFML's .Move function the data is corrupted because .Move takes float variables instead of long double variables. So I am wondering if I should go through the trouble of changing SFML's .Move function to take long double's instead of float and possibly other functions and also compromise SFML's performance?

P.s Language = C++
P.s.s I know I sometimes have a hard time getting my point across so if any clarification is needed let me know :-)
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself

ImageImage
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: Should I modify SFML???

Post by GroundUpEngine »

Sometimes we should keep it simple, if you wanna use the SFML API as is.. just use float (up to 7 digits i believe, which is not bad) variables for your maths ;)
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Should I modify SFML???

Post by Ginto8 »

... The fact that you're using long doubles when floats are all you need (and, more to the point, you're using an api that focuses on floats) proves that you are not yet at the level where you'd be capable of modifying SFML, disregarding that it really shouldn't be necessary at all.

It may interest you to know that SFML uses OpenGL for a backend, and OpenGL, although you can pass it doubles, converts everything to floats internally, so there really isn't much point anyway.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: Should I modify SFML???

Post by GroundUpEngine »

Ginto8 wrote:It may interest you to know that SFML uses OpenGL for a backend, and OpenGL, although you can pass it doubles, converts everything to floats internally, so there really isn't much point anyway.
I was about to address that! Good point.
User avatar
THe Floating Brain
Chaos Rift Junior
Chaos Rift Junior
Posts: 284
Joined: Tue Dec 28, 2010 7:22 pm
Current Project: RTS possible Third Person shooter engine.
Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
Programming Language of Choice: C/C++, Python 3, C#
Location: U.S

Re: Should I modify SFML???

Post by THe Floating Brain »

Ginto8 wrote:... The fact that you're using long doubles when floats are all you need (and, more to the point, you're using an api that focuses on floats) proves that you are not yet at the level where you'd be capable of modifying SFML,
I know how :| (change the function args in the source and in bolth copies of the headers in VC++ and in C: if any warnings come up according to that also change them to long doubles)
Ginto8 wrote:It may interest you to know that SFML uses OpenGL for a backend, and OpenGL, although you can pass it doubles, converts everything to floats internally, so there really isn't much point anyway.
(I did know that SFML used openGL) So it realy doesent matter 0.0. Thing is though it is even less acurate when I dont use doubles so I am not sure what to do. Poeple told me that my vector calculation function is correct. :/ Not sure were to go here.
GroundUpEngine wrote:I was about to address that! Good point.
+1
GroundUpEngine wrote:just use float (up to 7 digits i believe,
actually its 6 :mrgreen:
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself

ImageImage
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Re: Should I modify SFML???

Post by pritam »

There is a good reason using floats for movement, it's a lot smoother. If you need to run an if statement where your x/y variables reaches 300, use typecasting:

Code: Select all

if( (int)playerX )
Don't bother changing SFML, the effort is not worth it by far, there would hardly be improvement and you're not considering events where floats are necessary.

Edit: Actually typecasting doesn't round nicely, use this instead:

Code: Select all

(int) floor( f + 0.5f );
Last edited by pritam on Sun Feb 06, 2011 9:40 pm, edited 1 time in total.
User avatar
THe Floating Brain
Chaos Rift Junior
Chaos Rift Junior
Posts: 284
Joined: Tue Dec 28, 2010 7:22 pm
Current Project: RTS possible Third Person shooter engine.
Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
Programming Language of Choice: C/C++, Python 3, C#
Location: U.S

Re: Should I modify SFML???

Post by THe Floating Brain »

But if it never equils the desired position that wont work.
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself

ImageImage
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Re: Should I modify SFML???

Post by pritam »

THe Floating Brain wrote:But if it never equils the desired position that wont work.
Well, that's entirely up to you, use other operators.
JesseGuarascia
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 70
Joined: Mon Dec 13, 2010 10:55 pm

Re: Should I modify SFML???

Post by JesseGuarascia »

Hold on, let me get this straight. You want to change an entire API that is revolved around the float data type, because you want to use long doubles instead? :roll:

Also, Pritam's got it right. If you really desire a whole 300 constant value, just floor/ceil the thing. SFML's amazing; don't go breaking it because you're too lazy to change a long double to a float. :P
-- Jesse Guarascia

I like C/++, SDL, SFML, OpenGL and Lua. If you don't like those, then gtfo my sig pl0x (jk trollololololol)
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: Should I modify SFML???

Post by GroundUpEngine »

THe Floating Brainquote wrote:
GroundUpEngine wrote:just use float (up to 7 digits i believe,
actually its 6 :mrgreen:

Code: Select all

float lol = 1.234567;
JesseGuarascia wrote: :roll:
+1
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Should I modify SFML???

Post by MrDeathNote »

GroundUpEngine wrote:
THe Floating Brainquote wrote:
GroundUpEngine wrote:just use float (up to 7 digits i believe,
actually its 6 :mrgreen:

Code: Select all

float lol = 1.234567;
:lol: lol.
JesseGuarascia wrote: :roll:
+2

This is a really odd thread, I find it really hard to believe that you're actually considering changing the SFML API for no good reason, a float should be more than enough to work with. If the values aren't being set right then you're doing something wrong. But the short answer to "Should I modify SFML???" is NO!!
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Should I modify SFML???

Post by xiphirx »

I'm really confused....

How big are your input values? Do you know what the range of a long is?...

Code: Select all

//Calculate Magnitude.//
						GotoX -= Object.GetPosition().x;
						GotoY -= Object.GetPosition().y;
						long double Magnitude;
Why do you need a long double? float is fine...

Code: Select all

Magn(GotoX, GotoY, Magnitude);
Curious to see what that does... and why you couldn't just write the Pythagorean theorem out instead of having an odd function for it.

Code: Select all

//Go The Desired Speed.//
                                                GotoX *= Speed;
                                                GotoY *= Speed;
This is where your values are messed up, I think...

Just to note, it looks like you don't have a good grasp on vectors. If you did, you would have probably used SFML's own vector2f class :P
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
N64vSNES
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Thu Aug 12, 2010 11:25 am

Re: Should I modify SFML???

Post by N64vSNES »

xiphirx wrote:If you did, you would have probably used SFML's own vector2f class :P
:lol:

So...You want to fuck with SFML's source because you want to use a double over a float? :shock:
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Should I modify SFML???

Post by Falco Girgis »

THe Floating Brain wrote:Okay so I finally think I have a rough idea of vectors and I wrote these functions
(Calculates a vector)
http://pastebin.com/h6KqWVKu
("Lightning" is the version of my engine)
(Moves a object along a vector)
http://pastebin.com/3dXv5WfQ
Problem being... despite all the long double variables I put the movement of a object along a vector is inaccurate (just slightly).
HELP!.jpg
The reason is that when I pass the "GotoX", and "GotoY" variables (from my function above) into SFML's .Move function the data is corrupted because .Move takes float variables instead of long double variables. So I am wondering if I should go through the trouble of changing SFML's .Move function to take long double's instead of float and possibly other functions and also compromise SFML's performance?

P.s Language = C++
P.s.s I know I sometimes have a hard time getting my point across so if any clarification is needed let me know :-)
Honestly, why in fuck's name would you be using doubles? Why would you EVER need that kind of precision? That's only for exact numbers and scientific calculations.

And keep in mind that there is not a 1-to-1 relationship between an IEEE 32-bit single precision float (the variable you know as "float") and an integer. How many bytes are used to represent both? Float = 4 bytes. Integer = 4 bytes. They are literally the same size. They are literally both only capable of holding a permutation of their number of bits. So you are going to be missing some "exact" values that exist in an integer with a float. That's how it works.

You have no IDEA what the performance implications of using doubles usually is. Modern GPUs are only NOW starting to hardware accelerate doubles. A lot of the time the routines are written completely and software for GIGANTIC performance drops (because there's no support for the IEEE 64-bit float in hardware). We don't EVER use double precision floats in game development...
User avatar
THe Floating Brain
Chaos Rift Junior
Chaos Rift Junior
Posts: 284
Joined: Tue Dec 28, 2010 7:22 pm
Current Project: RTS possible Third Person shooter engine.
Favorite Gaming Platforms: PC, Wii, Xbox 360, GAME CUBE!!!!!!!!!!!!!!!!!!!!!!
Programming Language of Choice: C/C++, Python 3, C#
Location: U.S

Re: Should I modify SFML???

Post by THe Floating Brain »

God I feel realy embaressed :oops: :oops: :oops:
GyroVorbis wrote: Honestly, why in fuck's name would you be using doubles? Why would you EVER need that kind of precision? That's only for exact numbers and scientific calculations.

And keep in mind that there is not a 1-to-1 relationship between an IEEE 32-bit single precision float (the variable you know as "float") and an integer. How many bytes are used to represent both? Float = 4 bytes. Integer = 4 bytes. They are literally the same size. They are literally both only capable of holding a permutation of their number of bits.
Damn C++ book lied to me :nono:
N64vSNES wrote:So...You want to fuck with SFML's source because you want to use a double over a float? :shock:
Not any more I did though beacuse I am apparently a terrible programmer :lol:
xiphirx wrote:I'm really confused....
How big are your input values? Do you know what the range of a long is?...
19 digets.
xiphirx wrote:

Code: Select all

//Go The Desired Speed.//
GotoX *= Speed;
GotoY *= Speed;
This is where your values are messed up, I think...
Why do you think that?
xiphirx wrote: Just to note, it looks like you don't have a good grasp on vectors. If you did, you would have probably used SFML's own vector2f class :P
hence...
Okay so I finally think I have a rough idea of vectors and I wrote these functions
"Why did we say we were going to say we were going to change the world tomorrow yesterday? Maybe you can." - Myself

ImageImage
Post Reply