thread
This commit is contained in:
12
GameState.py
12
GameState.py
@@ -5,13 +5,15 @@ from lamps.Lamp import CREDIT
|
|||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
from lamps.LampGroup import *
|
from lamps.LampGroup import *
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import threading
|
||||||
|
|
||||||
class GameState:
|
class GameState:
|
||||||
players = None
|
players = None
|
||||||
credits = config.BALLS_PER_GAME
|
credits = config.BALLS_PER_GAME
|
||||||
isPlaying = False
|
isPlaying = False
|
||||||
isStarted = False
|
isStarted = False
|
||||||
isIdle = asyncio.Event()
|
isIdle = True
|
||||||
|
idleThread = None
|
||||||
|
|
||||||
def __init__(self, playerStateFactory, highscore, specialDisplay, currentPlayerID = 0):
|
def __init__(self, playerStateFactory, highscore, specialDisplay, currentPlayerID = 0):
|
||||||
CREDIT.activate()
|
CREDIT.activate()
|
||||||
@@ -45,13 +47,17 @@ class GameState:
|
|||||||
|
|
||||||
def startIdleLoop(self):
|
def startIdleLoop(self):
|
||||||
logging.info("Starting Idle Loop")
|
logging.info("Starting Idle Loop")
|
||||||
asyncio.run(self.idleLoop())
|
self.isIdle = True
|
||||||
|
self.idleThread = threading.Thread(target=self.idleLoop)
|
||||||
|
self.idleThread.start()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stopIdleLoop(self):
|
def stopIdleLoop(self):
|
||||||
logging.info("Stopping Idle Loop")
|
logging.info("Stopping Idle Loop")
|
||||||
self.isIdle.set()
|
self.isIdle = False
|
||||||
|
self.idleThread.join()
|
||||||
self.deactivate_all()
|
self.deactivate_all()
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def deactivate_all(self):
|
def deactivate_all(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user