fix thread timer
This commit is contained in:
parent
dc2e43f257
commit
3b83e1e2e8
10
main.py
10
main.py
@ -13,6 +13,7 @@ from window import Ui_MainWindow
|
|||||||
from mainLoop import mainLoop
|
from mainLoop import mainLoop
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
|
stopMainLoopTimer = Signal()
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.ui = Ui_MainWindow()
|
self.ui = Ui_MainWindow()
|
||||||
@ -45,11 +46,13 @@ class MainWindow(QMainWindow):
|
|||||||
self.drawTimer.timeout.connect(self.updateFPS)
|
self.drawTimer.timeout.connect(self.updateFPS)
|
||||||
self.drawTimer.start(1000/60)
|
self.drawTimer.start(1000/60)
|
||||||
|
|
||||||
self.ui.startButton.clicked.connect(self.mainLoop.timer.start)
|
self.ui.startButton.clicked.connect(self.mainLoop.startTimer)
|
||||||
self.ui.stopButton.clicked.connect(self.mainLoop.timer.stop)
|
self.ui.stopButton.clicked.connect(self.mainLoop.stopTimer)
|
||||||
|
|
||||||
|
self.stopMainLoopTimer.connect(self.mainLoop.stopTimer)
|
||||||
|
|
||||||
self.ui.mainFPS_set.valueChanged.connect(self.drawTimer.setInterval)
|
self.ui.mainFPS_set.valueChanged.connect(self.drawTimer.setInterval)
|
||||||
self.ui.physicsFPS_set.valueChanged.connect(self.mainLoop.timer.setInterval)
|
self.ui.physicsFPS_set.valueChanged.connect(self.mainLoop.setTimerInterval)
|
||||||
|
|
||||||
self.fpsTimer = QElapsedTimer()
|
self.fpsTimer = QElapsedTimer()
|
||||||
self.fpsTimer.start()
|
self.fpsTimer.start()
|
||||||
@ -90,6 +93,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.mainLoop.openVehicles(filename[0])
|
self.mainLoop.openVehicles(filename[0])
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
self.stopMainLoopTimer.emit()
|
||||||
self.updateThread.quit()
|
self.updateThread.quit()
|
||||||
self.updateThread.wait()
|
self.updateThread.wait()
|
||||||
super().close()
|
super().close()
|
||||||
|
25
mainLoop.py
25
mainLoop.py
@ -1,5 +1,3 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
from Map import Map
|
from Map import Map
|
||||||
from CarController import CarController
|
from CarController import CarController
|
||||||
|
|
||||||
@ -22,10 +20,7 @@ class mainLoop(QObject):
|
|||||||
self.painter.addMap(self.map)
|
self.painter.addMap(self.map)
|
||||||
self.painter.addCarController(self.controller)
|
self.painter.addCarController(self.controller)
|
||||||
|
|
||||||
self.timer = QTimer()
|
self.timer = None
|
||||||
self.timer.timeout.connect(self.update)
|
|
||||||
self.timer.timeout.connect(self.updateFps)
|
|
||||||
self.timer.setInterval(1000/60)
|
|
||||||
|
|
||||||
self.fpsTimer = QElapsedTimer()
|
self.fpsTimer = QElapsedTimer()
|
||||||
self.updateFPS.connect(self.parent.updatePhysicsFps)
|
self.updateFPS.connect(self.parent.updatePhysicsFps)
|
||||||
@ -41,8 +36,26 @@ class mainLoop(QObject):
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.fpsTimer.start()
|
self.fpsTimer.start()
|
||||||
|
|
||||||
|
self.timer = QTimer()
|
||||||
|
self.timer.timeout.connect(self.updateFps)
|
||||||
|
self.timer.timeout.connect(self.update)
|
||||||
|
self.timer.setInterval(1000/60)
|
||||||
self.stopSignal.connect(self.timer.stop)
|
self.stopSignal.connect(self.timer.stop)
|
||||||
|
|
||||||
|
def startTimer(self):
|
||||||
|
self.timer.start()
|
||||||
|
|
||||||
|
def stopTimer(self):
|
||||||
|
self.timer.stop()
|
||||||
|
|
||||||
|
def setTimerInterval(self,t):
|
||||||
|
self.timer.setInterval(t)
|
||||||
|
|
||||||
|
def quit(self):
|
||||||
|
super().quit()
|
||||||
|
self.timer.stop()
|
||||||
|
|
||||||
@threadSafe
|
@threadSafe
|
||||||
def update(self):
|
def update(self):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user