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 - SFJ

Pages: [1]
1
System / Re: Error when using threads in a class
« on: March 24, 2015, 07:36:05 pm »
OK, thanks for your answer and sorry for not reading the doc. :)
For everybody else, this is my solution: "static sf::Thread firstFuncThread(std::bind(&MY_CLASS::firstFunc, this, 1234));"

2
System / Re: Error when using threads in a class
« on: March 24, 2015, 06:21:26 pm »
Wait, but what do I have to write when I use additional arguments for "firstFunc()", for example "firstFunc(int counterStart)"? I tried "static sf::Thread firstFuncThread(&MY_CLASS::firstFunc, 1234, this);" and "static sf::Thread firstFuncThread(std::bind(&MY_CLASS::firstFunc, 1234), this);", but none of them work (they both produce hundreds of lines of errors).

3
System / Re: Error when using threads in a class
« on: March 24, 2015, 06:07:59 pm »
Ahh, this works now,  thank you very much!

4
System / Error when using threads in a class
« on: March 24, 2015, 05:46:54 pm »
Hi,

I am trying to call a function inside a class, which creates a static thread:

#include <cstdio>
#include <conio.h>
#include <SFML/System.hpp>

class MY_CLASS
{
        public:
                void firstFunc()
                {
                        int counter = 0;
                        while(1)
                        {
                                printf("Hello from firstFunc() %d\n", counter);
                                counter++;
                                sf::sleep(sf::Time(sf::seconds(1)));
                        }
                }
                void firstFuncCaller()
                {
                        static sf::Thread firstFuncThread(&MY_CLASS::firstFunc);
                        firstFuncThread.launch();
                }
};

int main()
{
        MY_CLASS myClassInstance;
        int counter = 0;
       
        myClassInstance.firstFuncCaller();
        while(1)
        {
                printf("Hello from main() %d\n", counter);
                counter++;
                sf::sleep(sf::Time(sf::seconds(1)));
        }
       
        return 0;
}

But every time I compile it, I get the following error:

In file included from c:\mingw\include\sfml\system\thread.hpp:193:0,
                 from c:\mingw\include\sfml\system.hpp:40,
                 from srcs/consoleTests/threadTest/threadTest.cpp:3:
c:\mingw\include\sfml\system\thread.inl: In instantiation of 'void sf::priv::ThreadFunctor<T>::run() [with T = void (MY_CLASS::*)()]':
srcs/consoleTests/threadTest/threadTest.cpp:42:1:   required from here
c:\mingw\include\sfml\system\thread.inl:39:25: error: must use '.*' or '->*' to call pointer-to-member function in '((sf::priv::ThreadFunctor<void (MY_CLASS::*)()>*)this)->sf::priv::ThreadFunctor<void (MY_CLASS::*)()>::m_functor (...)', e.g. '(... ->* ((sf::priv::ThreadFunctor<void (MY_CLASS::*)()>*)this)->sf::priv::ThreadFunctor<void (MY_CLASS::*)()>::m_functor) (...)'
     virtual void run() {m_functor();}
                         ^

What do I have to change in my code to let it compile properly?
Thanks for any help.

5
Feature requests / Relative mouse mode
« on: December 28, 2014, 02:19:52 pm »
I'm trying to accomplish something like SDL2's "SDL_SetRelativeMouseMode(SDL_TRUE)". I want to use SFML instead of SDL, because SFML has got some much easier functions for keyboard, window, font/text and audio/music control. Did I maybe overlook this feature? I also tried setting the mouse to the center of the window every frame, but when the program is really slow, the user is still able to make the mouse cursor escape the window. With SDL2's relative mouse mode, this cannot happen.

So, how can I reach this in SFML?:

//In the window constructor (the initialize mouse part):
SDL_WarpMouseInWindow(window, width/2, height/2);
SDL_SetRelativeMouseMode(SDL_TRUE);                             // <---- this

//In the event loop
SDL_Event e;
while(SDL_PollEvent(&e))
{
        if(e.type == SDL_MOUSEMOTION)                           // <---- and this
        {
                mouseXChg = e.motion.xrel;
                mouseYChg = e.motion.yrel;
        }
}
 

Pages: [1]
anything