SFML и C++ Уроки \ Разработка игр › Форумы › SFML Graphics › Thread › Ответ в теме: Thread
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#include<SFML\Graphics.hpp> #define PI 3.1415926535 class Main { private: sf::CircleShape* shape1, *shape2; sf::ContextSettings* settings; sf::Clock* clock; sf::RenderWindow* window; sf::Event* evt; sf::Mutex* mut; sf::Thread* drawThread; float time; public: Main() { settings = new sf::ContextSettings(16,24,2,0,8); clock = new sf::Clock; window = new sf::RenderWindow(sf::VideoMode(800, 600), "SFML works!", sf::Style::Close, *settings); mut = new sf::Mutex; drawThread = new sf::Thread(&Main::THREAD_Draw, this); evt = new sf::Event; shape1 = new sf::CircleShape(100); shape2 = new sf::CircleShape(100); shape1->setFillColor(sf::Color::Green); shape2->setFillColor(sf::Color::Red); shape1->setPosition(100, 0); shape2->setPosition(300, 0); time = 0; PlayMain(); } void PlayMain() { while (window->isOpen()) { time = (float)clock->getElapsedTime().asMicroseconds()/800; clock->restart(); while(window->pollEvent(*evt)) { if(evt->type == sf::Event::Closed) window->close(); } window->clear(); window->setActive(false); drawThread->launch(); drawThread->wait(); window->display(); } } void THREAD_Draw() { mut->lock(); window->draw(*shape1); window->draw(*shape2); mut->unlock(); } }; int main() { Main xMain; return 0; } |
Вот