-
Notifications
You must be signed in to change notification settings - Fork 3
/
LuaThread.cpp
54 lines (41 loc) · 1.03 KB
/
LuaThread.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
#include "LuaThread.hpp"
LuaThread::LuaThread(Console* consoleInput)
{
_thread = new QThread(this);
_runTimer = new QTimer(this);
_console = consoleInput;
}
void LuaThread::start()
{
this->moveToThread(_thread);
_runTimer->moveToThread(_thread);
connect(_thread, SIGNAL(started()), this, SLOT(startEvent()));
connect(_runTimer, SIGNAL(timeout()), this, SLOT(runEvent()));
_thread->start();
}
void LuaThread::stop()
{
_runTimer->stop();
_thread->exit();
}
void LuaThread::startEvent()
{
_runTimer->start(runInterval);
}
void LuaThread::runEvent()
{
if (exeScript->frameFunction)
{
auto _result = exeScript->frameFunction();
if (!_result.valid())
{
sol::error _err = _result;
auto _errStr = QString(_err.what());
_console->printMessage(_errStr + "<br>", 3);
_runTimer->stop();
_thread->exit();
}
}
if (_runTimer->interval() != runInterval)
_runTimer->setInterval(runInterval);
}