feat(fps_counter): Added FPS counter, removed slowdown

you can hide debug info by pressing f3
This commit is contained in:
n3tael 2024-04-03 17:07:30 +03:00
parent 54c276bd8b
commit 1b25a258cf
Signed by: n3tael
GPG Key ID: F305925762F035A8

34
main.py
View File

@ -71,12 +71,26 @@ def cap(rN):
return 0
return rN
def renderDebugInfo(gPlayer, clock, fontSize = 18):
font = pygame.freetype.Font(None, fontSize)
font_fg = (255, 255, 255)
font_bg = (255, 255, 255, 80)
fps_surf = font.render("FPS: " + str(int(clock.get_fps())), font_fg, font_bg)[0]
cPos_surf = font.render("cPos: " + str(gPlayer.cPos), font_fg, font_bg)[0]
cRot_surf = font.render("cRot: " + str(gPlayer.cRot), font_fg, font_bg)[0]
return fps_surf, cPos_surf, cRot_surf
def mainLoop():
gPlayer = GyroVector(0,1)
display = pygame.display.set_mode((1280,720))
font = pygame.freetype.Font(None,18)
clock = pygame.time.Clock()
fontSize = 18
debugInfo = True
while True:
framestart = time_ns()
#framestart = time_ns()
for event in pygame.event.get():
if event.type == pygame.QUIT:
@ -93,6 +107,9 @@ def mainLoop():
gPlayer -= GyroVector(OFFSET * gPlayer.cRot, 1)
if keys[pygame.K_s]:
gPlayer += GyroVector(OFFSET * gPlayer.cRot, 1)
if keys[pygame.K_F3]:
debugInfo = not debugInfo
display.fill(WHITE)
#pygame.draw.rect(display,BLACK, c_tr(Poincare2Klein(gPlayer.cPos) * -100) + (100,100),0)
drawn = draw(level,gPlayer,PI/2,160)
@ -103,13 +120,18 @@ def mainLoop():
pygame.draw.rect(display,i.color, (n,360 - (cap(i.height) * 360),10,cap(i.height) * 1000))
n += 8
font.render_to(display, (8, 8), "cPos: " + str(gPlayer.cPos), (255, 255, 255), (0, 0, 0))
font.render_to(display, (8, 26), "cRot: " + str(gPlayer.cRot), (255, 255, 255), (0, 0, 0))
if debugInfo:
fps_surf, cPos_surf, cRot_surf = renderDebugInfo(gPlayer, clock, fontSize)
display.blit(fps_surf, (0, 0))
display.blit(cPos_surf, (0, fps_surf.get_height()))
display.blit(cRot_surf, (0, fps_surf.get_height() + fontSize))
pygame.display.update()
frameend = time_ns()
sleep((frameend-framestart) / F_)
#frameend = time_ns()
clock.tick()
#sleep((frameend-framestart) / F_)
return True
def main():