-
Notifications
You must be signed in to change notification settings - Fork 1
/
elevatorsystem.cpp
99 lines (81 loc) · 2.02 KB
/
elevatorsystem.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "elevatorsystem.h"
ElevatorSystem::ElevatorSystem(QObject *parent) :
QObject(parent)
{
this->thread = new ElevatorSystemThread();
this->thread->elevatorSystem = this;
}
void ElevatorSystem::start()
{
this->time.start();
this->thread->start();
}
void ElevatorSystem::ElevatorSystemThread::run()
{
while (1)
{
if (this->elevatorSystem->tick() != 0) break;
// 60fps
this->msleep(1000/60);
}
}
int ElevatorSystem::tick()
{
// Get the time between frame
int elapsed = this->time.elapsed();
this->time.restart();
if (this->update(elapsed) != 0)
{
return 1;
}
this->draw();
return 0;
}
int ElevatorSystem::update(int elapsedTime)
{
// Update your system here
if(curResp) {
curAct = executeRespond(curResp);
curResp = executeAction(curAct);
curAct = NULL;
} else
curResp = executeAction(curAct);
//Uu tien Respond
if(curReq) {
curAct = executeRequest(curReq);
if(curAct != NULL)
qDebug() << "\n-----------\n";
curResp = executeAction(curAct);
curReq = NULL;
curAct = NULL;
}
return 0;
}
void ElevatorSystem::draw()
{
if (this->currentElevatorPosition != elevator[0])
{
this->currentElevatorPosition = elevator[0];
this->elevatorPositionChanged(this->currentElevatorPosition);
}
if (this->currentDoorPosition != eleDoor[0])
{
this->currentDoorPosition = eleDoor[0];
this->doorPositionChanged(this->currentDoorPosition);
}
if (this->currentMessage != curMessage)
{
this->currentMessage = curMessage;
this->currentMessageChanged(this->currentMessage);
}
if (this->currentWeight != eleWeight[0])
{
this->currentWeight = eleWeight[0];
this->currentWeightChanged(this->currentWeight);
}
if (this->currentLog != schedule[0])
{
this->currentLog = schedule[0];
this->currentLogChanged(this->currentLog);
}
}