Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jp

Pages: [1]
1
As far as I know std::sin and std::sinf do the exact same thing, so comparing them will result in the same performance. The reason why they were added, are founded in the C world and to align with similar function sets. With C++ function overloads, you can write functions with different types but the same function name. ;)
Aha, that would explain the result.
But just thinking, that float precision (7 digits) has faster approximation than double (15 digits), because the more precision for Sine() the slower the calculation. Getting accurate 7 decimal precision for Sine should be clearly faster than calculating 15 decimal precision. So I guess STL is using double formula for float?
But this is a C++ STL issue, maybe I should ask C++ forum about this :).

2
Currently trigonometric function are far from being bottlenecks for SFML.
Yes true it's not a bottleneck.
I think I am going to use those myself in my own code if I need sin/cos because they are there now, although first needs proper testing.

Just found there is also std::sinf() (C++11) which I was thinking surely is faster because less digits to calculate, but I just tested and was surprised to find out it has the same speed as sin() (unless I made an error in testing).

3
It is very interesting. Would be nice to share the code.

Ok, just pushed the first version to github:

https://github.com/PekkaCoder/FastSineCos

I have a test bench code and other testing codes also - I am planning to add it there also at some point. So everybody can test it easily and be sure it works (plus see the speed difference).

Also it's a "quick" first version, so quite likely I keep improving it and adding some things later on.

One of the tricks why I get it faster is the fact that when one rotates something, normally the next angle is close to the previous angle, like : 1.52, 1.56, 1.68 etc... So this class uses this as an advantage to calculate the value faster.

4
Hi

I was thinking I might be able to provide some code to SFML ... possibly ... :).
It's this: There are sin() and cos() functions at least in 3 modules:

Transformable.hpp
rotate.hpp
view.hpp

And there something like this:

float angle = m_rotation * 3.141592654f / 180.f;
float cosine = static_cast<float>(std::cos(angle));
float sine = static_cast<float>(std::sin(angle));
 

sin() and cos() are significantly slower than multiplication and division so I was thinking if I could find an approximation function which gives the same result/accuracy as sin/cos but is faster. Now I finished working on that and my function fastSin(float angle) is more than 80% faster than std::sin() (and I can do the same for cos()). The good thing is that it is basically as accurate as std::sin(). So calling for example std::sin(0.2866) and fastSin(0.2866) gives the same result, it is just > 80% faster (so about 2 times faster).
(actually in testing it was 82% -340%  faster depending on how many sin() calls in a row).

I know this is not super critical, as those functions with sin/cos (like the getTransform()) are not likely to be called hundreds of thousands of times per second. But if this is any useful I am ready to provide the code for it.

By the way, I studied mathematics in an university and actually my final thesis was just about this: approximating functions (like sin()) by polynomial functions.

Any thoughts?

5
Window / Re: SFML with MFC - sf::RenderWindow resize/update issue
« on: March 03, 2021, 06:07:32 pm »
You shouldn't just poll during the OnSize handling, but you should always poll.
With that being said, I'm not sure if that works correctly with the MFC setup, since SFML will drain the normal OS event queue, so MFC doesn't get any events to handle :D

Oh, I think the idea then is that instead of reacting to MFC events (mouse/size) I should poll SFML events instead and react to them. Like I could set a tight timer in MFC View and keep polling there sfml message. Ok, I could try that.

6
Window / Re: SFML with MFC - sf::RenderWindow resize/update issue
« on: March 03, 2021, 01:24:52 pm »
SFML requires you to always process events, also when it's embedded in another UI framework (MFC, Qt, wxWidgets, etc).

Ok, thanks, good to know. So seems like I was on a right path even though I did not know this :).

So, am I doing this correctly by polling all the event in OnSize():

while (sfmlWindow.pollEvent(event));
 

Or is there a better way to handle the sfml events in my OnSize function?

Or should I somehow only poll the size-event and leave others untouched (because in the SFML event buffer there could be other events as well)?

7
Window / SFML with MFC - sf::RenderWindow resize/update issue
« on: March 02, 2021, 11:27:24 am »
I use SFML with MFC. I want to keep the ball I draw at the same position/size when resizing the window. I read that I have to use setView() to set the new view according to the new CView window size. I tried it but it did not work directly like instructed on the websites. Then I investigated and got it working with this version (all related code here):

// When I create the window I initialize SFML window in CView class:
sf::RenderWindow sfmlWindow(GetSafeHwnd());
// ...
// Then when I get a WM_SIZE windows message, I do this in its OnSize() handler:
sf::Event event;
while (sfmlWindow.pollEvent(event));
sf::FloatRect visibleArea(0, 0, sfmlWindow.getSize().x, sfmlWindow.getSize().y);
sf::View newView{ visibleArea };
sfmlWindow.setView(newView);
 

I am happy it finally works (took me long time to figure it out :) ), but... is this really how it should be done (the correct way)?

I have couple of questions:
1) Why do I need to poll all the events in order the RenderWindow to update its size? Also, I was thinking that should the RenderWindow automatically do this update when I resize the window - why it does not change its m_size variable automatically when I resize? sfmlWindow.getSize() will not get updated to the new size if I do not flush the events with the while loop above it. Because I did some reseach: If I do not do that while() loop to poll all the events, the RenderWindow m_size will not get updated to the new size, and I am guessing this is why the sf::view does not get the correct values for the newView.

2) If I always need to empty the sf event queue (like I do above), what is the correct way to do it and where/in which function(s)? Does this issue also occur with other events like mouse events? So if my MFC CView gets a mouse event do I have to first flush the SFML event queue in order the SFML to be in a correct state?

8
General / Re: Error installing/compiling with VS2015 community
« on: January 18, 2016, 01:59:43 am »
uh, I found the problem!! :). Just for the record, it was this: In properties Advanced/Compile As , I has "compile as C" , :). I was testing something in the morning and I guess was copied to all projects somehow (still dont know why all other projects had it also? even though I started new projects). So that should be "compile as C++". Its strange that even after re-installing it was still there , C compilation. Maybe it stayed in the registry.


If a moderator can delete this post, maybe best to delete as it was not a SFML issue. or move it.

9
General / Re: Error installing/compiling with VS2015 community
« on: January 18, 2016, 12:06:32 am »
Don't know, but this never happened before. Am sure all (including namespaces) were compiling ok yesterday. But yes, just uninstalling and re-installing VS now.

But the odd thing is that if I start a totally new x64 project it does not understand "namespace". But lets see what happens after I re-installed.

10
General / Re: Error installing/compiling with VS2015 community
« on: January 17, 2016, 09:25:25 pm »
hmm, I found something strange... my 64 bit project does not understand "namespace" keyword :) (32 bit understands). So this might be the issue. I will try to solve this and come back after that if there is any SFML related issues. This is why it was complaining about "namespace sf".

Yes, its possible my VS got somehow broken today. It worked ok yesterday so it surpriced me...




11
General / Re: Error installing/compiling with VS2015 community
« on: January 17, 2016, 08:56:54 pm »
Sorry I pasted the wrong file name... I did not use GCC version but VS version. I really used: SFML-2.3.2-windows-vc14-64-bit. I just compiled again using this one and it gives the same error messages.

But the first error messages are coming from SFML, so why are they coming?

The VC errors can be because of the SFML error messages, isnt it?

The first error message is: "error C2061: syntax error: identifier 'sf'", so it cannot find the sf namespace for same reason. I guess it has nothing to do with VS header files.

12
General / Error installing/compiling with VS2015 community
« on: January 17, 2016, 02:55:47 pm »
****** UPDATE: please note this problem seems to be due to VC++ problem which seems to be "broken" somehow on my machine currently, so this post can be ignored until I fix it ***********

SOLVED (VS SETTINGS ISSUE): IF YOU WANT TO KNOW THE REASON, ITS IN THE LAST POST.

********************************************************************************


Hello,
I followed the instructions from the SFML documentation to install SFML to my Visual Studio 2015 community but I keep getting these errors:

1>------ Build started: Project: SfmlConcoleTemp, Configuration: Debug x64 ------
1>  main.cpp
1>e:\important\programming\c++\temp\sfmlconcoletemp\sfmlconcoletemp\include\sfml\config.hpp(163): error C2061: syntax error: identifier 'sf'
1>e:\important\programming\c++\temp\sfmlconcoletemp\sfmlconcoletemp\include\sfml\config.hpp(163): error C2059: syntax error: ';'
1>e:\important\programming\c++\temp\sfmlconcoletemp\sfmlconcoletemp\include\sfml\config.hpp(164): error C2449: found '{' at file scope (missing function header?)
1>e:\important\programming\c++\temp\sfmlconcoletemp\sfmlconcoletemp\include\sfml\config.hpp(190): error C2059: syntax error: '}'
1>e:\important\programming\c++\temp\sfmlconcoletemp\sfmlconcoletemp\include\sfml\system\clock.hpp(35): error C2061: syntax error: identifier 'sf'
1>e:\important\programming\c++\temp\sfmlconcoletemp\sfmlconcoletemp\include\sfml\system\clock.hpp(35): error C2059: syntax error: ';'
1>e:\important\programming\c++\temp\sfmlconcoletemp\sfmlconcoletemp\include\sfml\system\clock.hpp(36): error C2449: found '{' at file scope (missing function header?)
1>e:\important\programming\c++\temp\sfmlconcoletemp\sfmlconcoletemp\include\sfml\system\clock.hpp(84): error C2059: syntax error: '}'
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\vcruntime.h(294): error C2146: syntax error: missing ')' before identifier '_StackCookie'
...

I put my SMFL folder to: H:\SFML   and then I also tried to put it on the same project where the project is but it does not help.

The project recognizes #include <SFML\Graphics.hpp> ... it does not give any red marks when I put it in main.cpp so the project can see  SFML\Graphics.hpp.

I have done it in couple of ways (I also followed the youtube instructions at watch?v=2JVpmWwMo0o ) but I get the same error. Is there some setting in VS2015 default project which are not compatible with SFML? I tried Windows version and console version but I get the same errors.

I downloaded SFML-2.3.2-windows-vc14-64-bit and have Windows 10 compiled with 64bit projects.

Does the binary SFML-2.3.2-windows-vc14-64-bit work out of the box or I have to compile it somehow?

Thank you.

Pages: [1]
anything