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.


Topics - jp

Pages: [1]
1
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?

2
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?

3
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]