From b6f4b22bd2998a825d2c5eef581273e4ee933fbb Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 23 Feb 2022 21:55:15 +0100 Subject: [PATCH] fix bug, reload net --- mainLoop.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mainLoop.py b/mainLoop.py index 5f90a21..7f66617 100644 --- a/mainLoop.py +++ b/mainLoop.py @@ -4,10 +4,12 @@ from Map import Map from CarController import CarController from PySide6.QtWidgets import QFileDialog, QToolBox -from PySide6.QtCore import QElapsedTimer, QTimer, QElapsedTimer, QObject, Signal, Slot +from PySide6.QtCore import QElapsedTimer, QTimer, QElapsedTimer, QObject, Signal, Slot, QThread, QMutex class mainLoop(QObject): updateFPS = Signal(int) + mutex = QMutex() + def __init__(self, parent): super().__init__() self.parent = parent @@ -30,16 +32,26 @@ class mainLoop(QObject): self.fpsTimer = QElapsedTimer() self.updateFPS.connect(self.parent.updatePhysicsFps) + def threadSafe(func): + def inner(*args, **kwargs): + args[0].mutex.lock() + func(*args, **kwargs) + args[0].mutex.unlock() + return inner + def start(self): self.fpsTimer.start() + self.stopSignal.connect(self.timer.stop) + @threadSafe def update(self): try: self.controller.update() except: (type, value, traceback) = sys.exc_info() print(type, value, traceback) - + + @threadSafe def openNetwork(self, filename): if filename == '': return @@ -48,6 +60,7 @@ class mainLoop(QObject): self.controller.prepareRoute() + @threadSafe def openVehicles(self, filename): if filename == '': return @@ -55,6 +68,7 @@ class mainLoop(QObject): if self.map.isLoaded(): self.controller.prepareRoute() + @threadSafe def quickLoad(self): self.map.fromPath("test2.net.xml") self.painter.generateTransform()