Skip to content

Commit fcd0923

Browse files
committed
FIXED BUTTON BUG,INCREASED FPS
fix button label bug ,increased fps, fixed glich and flashes
1 parent 901aaf1 commit fcd0923

3 files changed

Lines changed: 50 additions & 27 deletions

File tree

Button.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,15 @@ def __init__(self, x, y, width, height, label, on_click_callback=None):
1212
self.label = label
1313
self.on_click_callback = on_click_callback
1414
self.is_hovered = False
15-
self_rectangle = None
16-
self.label = None
1715

1816
def draw(self):
1917
# Draw the button rectangle
2018
color = (54, 45, 42, 0) if not self.is_hovered else (200, 200, 200, 255)
21-
self.rectangle = shapes.Rectangle(self.x, self.y, self.width, self.height, color=color)
22-
self.rectangle.draw()
19+
shapes.Rectangle(self.x, self.y, self.width, self.height, color=color).draw()
2320

2421
label_x = self.x + self.width // 2
2522
label_y = self.y + self.height // 2
26-
self.label=pyglet.text.Label(self.label, font_size=12, x=label_x, y=label_y, anchor_x='center', anchor_y='center')
27-
self.label.draw()
23+
pyglet.text.Label(self.label, font_size=12, x=label_x, y=label_y, anchor_x='center', anchor_y='center').draw()
2824

2925

3026
def on_mouse_motion(self, x, y, dx, dy):
@@ -33,7 +29,5 @@ def on_mouse_motion(self, x, y, dx, dy):
3329
def on_mouse_press(self, x, y, button, modifiers):
3430
if self.is_hovered and button == pyglet.window.mouse.LEFT and self.on_click_callback:
3531
self.on_click_callback()
36-
def change_visible(self):
37-
self.rectangle.visible = not self.rectangle.visible
38-
self.label.visible = not self.label.visible
32+
3933

core/utils/options.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33
# Conditional Rendering with Occlusion queries
44
ADVANCED_OPENGL = False # Not recommended unless using NVIDIA cards.
55
# Might cause more slowdowns that speedups.
6+
DOUBLE_BUFFER = True
7+
DEPTH_SIZE = 32
68
WIDTH = 1000
79
HEIGHT = 562
810
is_white = False
9-
VSYNC = True
11+
SMOOTH_FPS = True
12+
VSYNC = True
13+
# Max CPU ahead frames
14+
MAX_CPU_AHEAD_FRAMES = 3 # Number of frames the CPU can be ahead of the GPU until waiting for it to finish rendering.
15+
# Higher values gives higher framerate but causes framerate instability and higher frame spikes
16+
# Lower values causes average lower framerate but gives smoother framerate
17+
# Recommended values are between 0 and 9
18+
19+
# Legacy Smooth FPS
20+
SMOOTH_FPS = False # Legacy way to force the flushing of command buffer and forces the CPU to wait for the GPU to finish rendering.
21+
# Incompatible Max CPU Ahead Frames (it won't be effective)
22+
# Enable this to test whether its impact is better. Similar to Max CPU Ahead frames to 0

shell_startup.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,30 @@
55
import pyglet.gl as gl
66
from pyglet.graphics import Batch
77
from 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

1014
class 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():
191208
class 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

218234
if __name__ == "__main__":
219235
computer = Computer()
220-
pyglet.app.run()
236+
pyglet.app.run(interval=1/float("inf"))

0 commit comments

Comments
 (0)