Skip to content

Commit

Permalink
Trying to limit calls to display updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Senior committed Jun 1, 2020
1 parent 681233f commit bc704b4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 29 deletions.
20 changes: 12 additions & 8 deletions src/aboutScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def display(self, display, source):
# Pygame clock for setting frame rate.
clock = pygame.time.Clock()

# Switch for limiting the display.flip calls to just when a display
# update has occured.
self.updated = True

# Main display loop.
run_about = True
while run_about:
Expand Down Expand Up @@ -183,18 +187,18 @@ def display(self, display, source):
if button.rect.collidepoint(pygame.mouse.get_pos()):
button.hovered = True
button.updated = True
elif button.active == True:
button.draw(display)
self.updated = True
elif button.active == True and button.hovered == True:
button.hovered = False
button.updated = True

for button in self.buttons:
# If any of the buttons have had changes happen to them
# then redraw them.
if button.updated:
button.draw(display)
button.draw(display)
self.updated = True

# Update the screen to display the updated draws.
display.flip()
if self.updated:
display.flip()
self.updated = False

# Pause the loop until all of the frame rate time has passed.
clock.tick(self.frameRate)
23 changes: 18 additions & 5 deletions src/helpScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def display(self, display, source):
self.button_ringingPage.rect.x = self.button_serverPage.rect.x - 10 - self.button_ringingPage.rect.w

display.blit(self.backgroundFade, (0, 0))
display.flip()

if source == "menuScreen":
helpPage = "server"
Expand All @@ -148,6 +149,7 @@ def display(self, display, source):
self.button_serverPage.active = True

self.drawBackground(display)
display.flip()

for button in self.buttons:
if button.updated:
Expand All @@ -160,6 +162,8 @@ def display(self, display, source):
display.flip()

clock = pygame.time.Clock()

self.updated = True

run_help = True
while run_help:
Expand All @@ -178,27 +182,36 @@ def display(self, display, source):
self.button_serverPage.active = False
self.button_ringingPage.active = True
self.drawBackground(display)
for button in self.buttons:
button.draw(display)
for txt in text:
txt.draw(display)
self.updated = True
elif self.button_ringingPage.rect.collidepoint(event.pos) and self.button_ringingPage.active == True:
text = self.ringingText
self.button_serverPage.active = True
self.button_ringingPage.active = False
self.drawBackground(display)
for button in self.buttons:
button.draw(display)
for txt in text:
txt.draw(display)
self.updated = True

for button in self.buttons:
if button.rect.collidepoint(pygame.mouse.get_pos()):
button.hovered = True
button.updated = True
elif button.active == True:
button.draw(display)
self.updated = True
elif button.active == True and button.hovered == True:
button.hovered = False
button.updated = True
button.draw(display)
self.updated = True

for button in self.buttons:
if button.updated:
button.draw(display)
if self.updated:
display.flip()
self.updated = False

display.flip()
clock.tick(self.frameRate)
20 changes: 15 additions & 5 deletions src/menuScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,22 @@ def display(self, display):
for button in self.buttons:
button.hovered = False
button.draw(display)
button.updated = False

self.updateConnectionStatusMessage(display)

self.updated = True

while self.run_menu:
for box in self.input_boxes:
if box.updated:
box.draw(display, redrawTitle=False)
box.updated = False
for button in self.buttons:
if button.updated:
button.draw(display)
self.updated = True
#for button in self.buttons:
# if button.updated:
# button.draw(display)
# print("BARRR")

for event in pygame.event.get():
if event.type == pygame.QUIT:
Expand Down Expand Up @@ -222,10 +227,15 @@ def display(self, display):
if button.rect.collidepoint(pygame.mouse.get_pos()):
button.hovered = True
button.updated = True
elif button.active == True:
button.draw(display)
self.updated = True
elif button.active == True and button.hovered == True:
button.hovered = False
button.updated = True
button.draw(display)
self.updated = True

display.flip()
if self.updated:
display.flip()
self.updated = False
clock.tick(self.frameRate)
25 changes: 20 additions & 5 deletions src/optionsScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ def display(self, display, source):
display.flip()

clock = pygame.time.Clock()

self.updated = True

run_options = True
while run_options:
Expand Down Expand Up @@ -264,6 +266,7 @@ def display(self, display, source):
self.drawBackground(display)
for txt in text:
txt.draw(display)
self.updated = True
elif self.button_tuning.rect.collidepoint(event.pos) and self.button_tuning.active == True:
optionsPage = 'tuning'
text = self.tuningText
Expand All @@ -273,6 +276,7 @@ def display(self, display, source):
self.drawBackground(display)
for txt in text:
txt.draw(display)
self.updated = True
elif self.button_other.rect.collidepoint(event.pos) and self.button_other.active == True:
optionsPage = 'other'
text = self.otherText
Expand All @@ -282,6 +286,7 @@ def display(self, display, source):
self.drawBackground(display)
for txt in text:
txt.draw(display)
self.updated = True

for box in self.bellNumberInputBoxes:
box.mouseDownEvent(event, self.win)
Expand All @@ -295,28 +300,38 @@ def display(self, display, source):
if event.type == pygame.KEYDOWN:
if self.activeBox and self.activeBox.active:
self.activeBox.keyDownEvent(event, self.win)
self.updated = True

for button in self.buttons:
if button.rect.collidepoint(pygame.mouse.get_pos()):
button.hovered = True
button.updated = True
elif button.active == True:
button.draw(display)
self.updated = True
elif button.active == True and button.hovered == True:
button.hovered = False
button.updated = True
button.draw(display)
self.updated = True

if optionsPage == 'keys':
for box in self.bellNumberInputBoxes:
if box.updated:
box.draw(display)
box.updated = False
self.updated = True
for box in self.bellKeyInputBoxes:
if box.updated:
box.draw(display)
box.updated = False
self.updated = True

#for button in self.buttons:
# if button.updated:
# button.draw(display)

for button in self.buttons:
if button.updated:
button.draw(display)
if self.updated:
display.flip()
self.updated = False

display.flip()
clock.tick(self.frameRate)
17 changes: 11 additions & 6 deletions src/ringingScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,11 @@ def display(self, display):
button.hovered = False
button.draw(display)

self.updated = True

run_ringing = True
while run_ringing:

for button in self.buttons:
if button.updated:
button.draw(display)

for event in pygame.event.get():
if event.type == pygame.QUIT:
run_ringing = False
Expand All @@ -242,6 +240,7 @@ def display(self, display):
for button in self.buttons:
button.hovered = False
button.draw(display)
self.updated = True
elif self.button_options.rect.collidepoint(event.pos):
run_ringing = False
return 'optionsScreen'
Expand All @@ -267,10 +266,13 @@ def display(self, display):
if button.rect.collidepoint(pygame.mouse.get_pos()):
button.hovered = True
button.updated = True
elif button.active == True:
button.draw(display)
self.updated = True
elif button.active == True and button.hovered == True:
button.hovered = False
button.updated = True
button.draw(display)
self.updated = True

try:
stroke, bellNumber = self.network.getBellRung()
Expand All @@ -282,7 +284,10 @@ def display(self, display):
self.bells[bellNumber].bellRung(stroke)
self.bells[bellNumber].draw(display)
pygame.mixer.Channel(bellNumber-1).play(self.audio.bells[bellNumber])
self.updated = True

display.flip()
if self.updated:
display.flip()
self.updated = False

clock.tick(self.frameRate)

0 comments on commit bc704b4

Please sign in to comment.