fix bug, reload net
This commit is contained in:
parent
9b2546bfd6
commit
b6f4b22bd2
16
mainLoop.py
16
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,9 +32,18 @@ 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()
|
||||
@ -40,6 +51,7 @@ class mainLoop(QObject):
|
||||
(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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user