-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.h
53 lines (40 loc) · 970 Bytes
/
scene.h
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
#ifndef SCENE_H
#define SCENE_H
#include "ball.h"
#include <vector>
#include <mutex>
#include <thread>
#include <condition_variable>
class Scene
{
public:
explicit Scene(int width, int height, int ballsCount);
~Scene();
void add(int x, int y);
bool remove(int x, int y);
Ball* select(int x, int y);
Ball* getSelected();
void moveSelected(int dx, int dy);
void lock() { m_mutex.lock(); }
void unlock() { m_mutex.unlock(); }
const std::vector<Ball>& getBalls() const
{
return m_balls;
}
void update();
private:
typedef std::lock_guard<std::mutex> Lock;
void calculate();
std::vector<Ball>::iterator getBallIt(int x, int y);
Ball* getBall();
std::vector<Ball> m_balls;
int m_selected;
int m_width;
int m_height;
std::mutex m_mutex;
std::thread m_updateThread;
std::condition_variable m_condVar;
bool m_done;
bool m_isNotified;
};
#endif // SCENE_H