-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (46 loc) · 1.31 KB
/
main.py
File metadata and controls
61 lines (46 loc) · 1.31 KB
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
55
56
57
58
59
60
61
import time
import threading
import pygame
import flashbox
import logger
logger.reset_log()
logger.log(f"Initializing Flashbox {flashbox.VERSION}...")
pygame.mixer.pre_init(44100, -16, 2, 2)
pygame.mixer.init()
pygame.init()
f = flashbox.Flashbox()
FPS = 120
clock = pygame.time.Clock()
pygame.event.set_allowed([pygame.QUIT, pygame.KEYDOWN, pygame.TEXTINPUT, pygame.MOUSEBUTTONUP])
pygame.display.set_caption(f"Flashbox {flashbox.VERSION}")
pygame.display.set_icon(pygame.image.load("images/flashbox.ico"))
run = 1
f.load()
class PeriodicSleeper(threading.Thread):
def __init__(self, task_function, period):
super().__init__()
self.task_function = task_function
self.period = period
self.i = 0
self.t0 = time.time()
self.start()
def sleep(self):
self.i += 1
delta = self.t0 + self.period * self.i - time.time()
if delta > 0:
time.sleep(delta)
def run(self):
while 1:
self.task_function()
self.sleep()
if run:
sleeper = PeriodicSleeper(f.update_time, 0.001)
while run:
run = f.run
clock.tick(FPS)
f.update()
f.draw()
pygame.display.update()
logger.log("Not anymore inside the loop! Quitting...")
f.save()
pygame.quit()