You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classFps(object):
def__init__(self):
self.prev_time=time.time()
self.clock=Clock()
self.font=Font()
self.benchmark=Trueself.get()
self.t=0self.dt=self.manage(fps=120)
fps=round(self.clock.get_fps())
self.countFps=1self.sumFps=0self.avg=fps//self.countFpsself.max=fpsself.min=1_000_000defmanage(self, fps):
""" Manage the delta time (Time between two frame) """self.clock.tick(fps) # Cadence the clock of the gameself.dt=float(time.time() -self.prev_time) # The time between old frame and the new frameself.prev_time=time.time() # Previous framereturnself.dt*60# 60 is fps we need to have in gamedefaverage(self):
""" Make a average of fps getted @return average of fps, max fps, min fps """fps=round(self.clock.get_fps())
self.sumFps+=fpsself.countFps+=1self.avg=self.sumFps//self.countFpsiffps>self.max:
self.max=fpsifself.min>fps>0:
self.min=fpsreturnself.avg,self.max,self.mindefget(self):
""" get the framerate in game """returnround(self.clock.get_fps())
defdraw(self,surface):
""" Display on a surface all informations about the framerate in game """msg= [self.font.font.render(f'{self.get()} Fps',0,(255,255,255)),self.font.font.render(f'avg: {self.avg} Fps',0,(255,255,255)),self.font.font.render(f'max: {self.max} Fps',0,(255,255,255)),self.font.font.render(f'min: {self.min} Fps',0,(255,255,255)),self.font.font.render(f'var: {round(self.dt,3)} ms',0,(255,255,255))]
self.font.outline(surface,msg[1],(5,5))
self.font.outline(surface,msg[0],(5,msg[0].get_height() +7))
self.font.outline(surface,msg[2],(msg[0].get_width() *2.5,5))
self.font.outline(surface,msg[3],(msg[0].get_width() *2.5,msg[2].get_height() *1.5))
self.font.outline(surface,msg[4],(5,msg[1].get_height() *2.5))
surface.blit(msg[1],(5,5))
surface.blit(msg[0],(5,msg[0].get_height() +7))
surface.blit(msg[2],(msg[0].get_width() *2.5,5))
surface.blit(msg[3],(msg[0].get_width() *2.5,msg[2].get_height() *1.5))
surface.blit(msg[4],(5,msg[1].get_height() *2.5))
We need to improve the code of Fps class when #7#19 is done
I suppose wrong things
The Fps class must be a Singleton. Why ? Because we need to have dt variable on many class like Entity object or Scene class
The code style not correspond with actual code
The draw function is maybe on a wrong place.
The average function return also a min value and max value (Weird)
Unknow self.t variable ?
The text was updated successfully, but these errors were encountered:
Old code
We need to improve the code of
Fps
class when #7 #19 is doneI suppose wrong things
Fps
class must be aSingleton
. Why ? Because we need to havedt
variable on many class likeEntity
object orScene
classdraw
function is maybe on a wrong place.average
function return also a min value and max value (Weird)self.t
variable ?The text was updated successfully, but these errors were encountered: