55import pyglet .gl as gl
66from pyglet .graphics import Batch
77from Button import Button
8-
8+ from collections import deque
9+ pyglet .options ["shadow_window" ] = False
10+ pyglet .options ["debug_gl" ] = False
11+ pyglet .options ["search_local_libs" ] = True
12+ pyglet .options ["audio" ] = ("openal" , "pulse" , "directsound" , "xaudio2" , "silent" )
913
1014class Initialization (pyglet .window .Window ):
1115 def __init__ (self , ** kwargs ):
1216 super ().__init__ (** kwargs )
1317 # config
18+ """batches"""
1419 self .init_batch = Batch ()
1520 self .LoggingGUI_batch = Batch ()
21+ """baches end"""
22+ """vars"""
1623 self .No_Blur_LoggingGUI = False
24+ self .crraima = 0
25+ self .loop_counter = 0 # Initialize the loop counter
26+ self .ANIMATION_STARTUP_COMPLETED = False
27+ self .InUserGUI = False
28+ self .loop_counter = 0 # Initialize the loop counter
29+ self .options = options
30+ """vars end"""
31+ """images and sprites"""
1732 self .LoggingGUI_bg_img = pyglet .image .load ("core/assets/PythonOS/images/astounding_background1.jpg" )
1833 self .LoggingGUI_bg = pyglet .sprite .Sprite (
1934 self .LoggingGUI_bg_img ,
@@ -26,7 +41,7 @@ def __init__(self, **kwargs):
2641 self .LoggingGUI_bg_img_blurred_sprite = pyglet .sprite .Sprite (
2742 self .LoggingGUI_bg_img_blurred ,
2843 x = 0 ,
29- y = 0
44+ y = 0 ,
3045 )
3146 self .user_image = pyglet .image .load ("core/assets/PythonOS/images/account.png" )
3247 self .user_image_sprite = pyglet .sprite .Sprite (
@@ -86,19 +101,24 @@ def __init__(self, **kwargs):
86101 y = self .height / 30 ,
87102 batch = self .init_batch ,
88103 )
89- self .crraima = 0
90- self .loop_counter = 0 # Initialize the loop counter
91- self .ANIMATION_STARTUP_COMPLETED = False
92- self .InUserGUI = False
104+ """images and sprites end"""
105+
93106 self .clear ()
94- self . loop_counter = 0 # Initialize the loop counter
107+
95108 pyglet .clock .schedule_interval (
96109 self .update , 1 / 60
97110 )
111+ # GPU command syncs
112+ self .fences = deque ()
113+ gl .glFinish ()
114+ # self.fences.append(gl.glFenceSync(gl.GL_SYNC_GPU_COMMANDS_COMPLETE, 0)) # Broken in pyglet 2; glFenceSync is missing
98115
99116 def update (self , delta_time ):
100117 """Every time this method is called"""
101-
118+ while len (self .fences ) > self .options .MAX_CPU_AHEAD_FRAMES :
119+ fence = self .fences .popleft ()
120+ gl .glClientWaitSync (fence , gl .GL_SYNC_FLUSH_COMMANDS_BIT , 2147483647 )
121+ gl .glDeleteSync (fence )
102122 self .clear ()
103123 self .init_batch .draw ()
104124
@@ -107,7 +127,7 @@ def update(self, delta_time):
107127 self .WindowsLogoRightUp_sprite .draw ()
108128 self .WindowsLogoLeftDown_sprite .draw ()
109129 self .WindowsLogoRightDown_sprite .draw ()
110- pyglet .clock .schedule_once (self .delayfunc1 , 3.0 )
130+ pyglet .clock .schedule_once (self .delayfunc1 , 2 )
111131
112132 else :
113133 # Remove the sprites when animation is completed
@@ -125,10 +145,7 @@ def on_mouse_motion(self, x, y, dx, dy):
125145 # print("x: {0}, y: {1}".format(MOUSE_X, MOUSE_Y))
126146 try :
127147 self .button .on_mouse_motion (
128- x ,
129- y ,
130- dx ,
131- dy
148+ x ,y ,dx ,dy
132149 )
133150 except :
134151 pass
@@ -191,10 +208,10 @@ def initialize_logger():
191208class Computer :
192209 def __init__ (self ):
193210 self .config = gl .Config (
194- double_buffer = True ,
211+ double_buffer = options . DOUBLE_BUFFER ,
195212 major_version = 3 ,
196213 minor_version = 3 ,
197- depth_size = 32 ,
214+ depth_size = options . DEPTH_SIZE ,
198215 sample_buffers = bool (options .ANTIALIASING ),
199216 )
200217 self .window = Initialization (
@@ -207,7 +224,6 @@ def __init__(self):
207224
208225 )
209226 self .window .set_location (50 , 60 )
210- self .window .set_vsync (True )
211227 self .window .set_icon (pyglet .image .load ("core/assets/PythonOS/images/logo.png" ))
212228
213229
@@ -217,4 +233,4 @@ def main():
217233
218234if __name__ == "__main__" :
219235 computer = Computer ()
220- pyglet .app .run ()
236+ pyglet .app .run (interval = 1 / float ( "inf" ) )
0 commit comments