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

Pages: [1]
1
Graphics / How to rotate sprite, keeping the original position?
« on: June 26, 2014, 11:45:08 pm »
How to rotate sprite, keeping the original position? Sprite position changes every time. It goes to ~ 300 degrees. :)
Sprite* square;
....
square->SetRotation((float)rand()%360);
 

2
System / How to create a thread(with args) from the method?
« on: March 27, 2014, 12:42:29 am »
Hi!

How to create a thread(with args) from the method?

class A
{
public:
    A()
    {
         // understood that does not work
         pThread = new sf::Thread(std::bind(&Method, 15, 25), this));
    }
    ~A()
    {
         delete pThread;
    }
    void Method(int a, int b);

    private:
        sf::Thread* pThread;
};
 

3
Network / How read recive data? (const void*)
« on: March 26, 2014, 07:10:57 pm »
Hello! I need to read the incoming packets.

I can not make it through sf::Packet, since the structure of the package is not known.
I need to convert the received packet data(const void*) to "classical" set bits in hex ​​format. (example: 00:00:00:04:00:00:00:0c:68:65:6c:6c:6f:20:73:65:72:76:65:72)

ps: by TcpSocket

4
Graphics / How to create a copy of the class?
« on: January 12, 2014, 06:35:49 am »
Greetings!
I want to make a base class Depictable for graphics that will hold my methods.
It inherits from sf :: Drawable.
class Depictable: public sf::Drawable
{
            ...
    public:
            virtual ~Depictable() {}

    private:
            void draw(sf::RenderTarget& target, sf::RenderStates states) const {}
            ...
};
 
I want to do is an exact copy of the class sf :: RectangleShape.
class Rectangle : public Depictable,  public sf::RectangleShape
{
    public:
                virtual ~Rectangle() {}
                explicit Rectangle(const sf::Vector2f& size = sf::Vector2f(0, 0)) { setSize(size); }
};
 
and then draw it.
        Rectangle* line = new Rectangle(sf::Vector2f(50, 10));
        line->setFillColor(sf::Color::White);
        line->setPosition(100, 100);
        app.draw(*line);
 
Naturally, the line is drawn.
How to make a class so that it is drawn?
except sf::RectangleShape* line = new Rectangle(sf::Vector2f(50, 10));

5
General / Question about destructors of some classes.
« on: May 18, 2013, 01:23:03 pm »
Good day.
I have a question.
Why destructors some classes:
sf::~TcpSocket, sf::~Thread
do not call methods:
sf::TcpSocke::disconnect(),  sf::Thread::terminate()
?
When using them appear some discomfort, for example:
sf::Thread* thread= new sf::Thread(&fooo);
thread.launch();
...
delete thread;
The thread is still active, you have to manually call thread->terminate().

ps: And yet, it would be nice to add the processing status for threads. (sf::Thread::Status)

6
System / SFML in the future.
« on: December 19, 2012, 08:10:50 pm »
Will there be any in the library of methods for process management and implementation of the singleton pattern?


Sorry for my English.

7
System / multithreading and srand
« on: December 07, 2012, 01:58:46 pm »
Hi.  :)
How to use a randomizer with multithreading?
simple ex:
class Myc
{
public:
        Myc()
        {
        }

        ~Myc()
        {
                for (int i = 0; i < threads.size(); ++i)
                        if(sf::Thread* thr = threads[i])
                        {
                                thr->terminate();
                                delete thr;
                        }
                threads.clear();
        }

        void Start()
        {
                // 3 thread
                for (int i = 0; i < 3; ++i)
                        threads.push_back(new sf::Thread(&Myc::ThrFun, this));

                for (int i = 0; i < threads.size(); ++i)
                        threads[i]->launch();
        }

        void ThrFun()
        {
                sf::Clock clock;

                while (true)
                {
                        if (clock.getElapsedTime().asSeconds() >= 3)
                        {
                                // problem
                                int r = rand()%100+1;
                                std::cout << r << std::endl;

                                clock.restart();
                        }
                }
        }

private:
        std::vector<sf::Thread*> threads;
};

int main()
{
        srand((unsigned)time(NULL));

        Myc m;
        m.Start();

        std::cin.get();
}
 

result:
The same value in each thread. Since the mutex does not work, or I did not use true.

8
Graphics / Divide the image into parts for animation.
« on: October 03, 2012, 03:16:49 pm »
Hello! How to divide the image to animate?
Give an example, please.

img example source:


Pages: [1]