PageRenderTime 103ms CodeModel.GetById 53ms app.highlight 9ms RepoModel.GetById 32ms app.codeStats 0ms

/python/framerate.py

https://bitbucket.org/lonkero173/pulse
Python | 105 lines | 57 code | 25 blank | 23 comment | 4 complexity | 781cc3da586fa4243bde05337a16990c MD5 | raw file
  1# -*- coding: utf-8 -*-
  2import fofclone
  3
  4class framerate:
  5	def __init__(self):
  6		import fofclone	#having trouble with some aspects of python embedding.... this is necessary at the moment, wish I knew why...
  7		self.module_ref=fofclone
  8		self.render_time=self.module_ref.EVERY_FRAME
  9		self.is_global=True
 10
 11		self.name="Framerate display"		#required
 12		self.description="Prints framerate data, lots of it"	#required
 13
 14		self.sframerate=0.0
 15		self.hframerate=0.0
 16		self.framecount=0
 17		self.framedelay=0
 18		self.updatetime=0
 19		self.low=100000000.0		#this is an impossible framerate a.t.m	(if SDL_Delay(10) is respected...)
 20		self.high=0.0
 21		self.average=0.0
 22		self.time_played=0
 23
 24
 25	def render(self):
 26		# do the updating work, there is so little of it that there is no point in a seperate update function
 27		self.framecount+=1;
 28
 29		self.framedelay=self.module_ref.get_framedelay()
 30		self.time_played+=self.framedelay
 31		self.updatetime = self.module_ref.get_updatetime()
 32
 33		if(self.framedelay>0.0):
 34			self.sframerate*=0.99
 35			self.sframerate+=10.0/self.framedelay
 36			self.hframerate=1000.0/self.framedelay
 37
 38			#self.average=(self.average*(self.framecount-1)+self.hframerate)/self.framecount
 39			self.average+=(self.hframerate-self.average)/self.framecount
 40		else:
 41			# getting a frame in <1 ms means on average +1000 to the framerate
 42			self.sframerate*=0.95
 43			self.sframerate+=50.0/1000.0
 44			self.hframerate+=1000.0
 45
 46		# ignore first 10 frames for minimum framerate calculations as there is only one frame update during the entire loading process (but more may come...)
 47		if(self.hframerate<self.low and self.framecount>10): self.low=self.hframerate;
 48		if(self.hframerate>self.high): self.high=self.hframerate;
 49
 50		# print the frame that is being drawn
 51		self.module_ref.simple_print("Frame:",0.50,0.60)
 52		self.module_ref.simple_print("%d"%(self.framecount),0.80,0.60)
 53		
 54		# print the render time
 55		self.module_ref.simple_print("Update Time:",0.50,0.55)
 56		self.module_ref.simple_print("%d"%(self.updatetime),0.80,0.55)
 57
 58		# a smooth framerate
 59		self.module_ref.simple_print("Fps (Smooth):",0.50,0.50)
 60		self.module_ref.simple_print("%5.3f "%(self.sframerate),0.80,0.50)
 61
 62		# a hard framerate, no averaging out
 63		self.module_ref.simple_print("Fps (Absolute):",0.50,0.45)
 64		self.module_ref.simple_print("%5.3f"%(self.hframerate),0.80,0.45)
 65
 66		#high
 67		self.module_ref.simple_print("High:",0.50,0.40)
 68		self.module_ref.simple_print("%5.3f"%(self.high),0.80,0.40)
 69
 70		#low
 71		self.module_ref.simple_print("Low:",0.50,0.35)
 72		self.module_ref.simple_print("%5.3f"%(self.low),0.80,0.35)
 73
 74		#average
 75		self.module_ref.simple_print("Average:",0.50,0.30)
 76		self.module_ref.simple_print("%5.3f"%(self.average),0.80,0.30)
 77		
 78		#print self.sframerate
 79		
 80
 81	def save_settings(self):
 82		self.module_ref.save_setting("time_played",str(self.time_played))
 83
 84	def load_settings(self):
 85		temp=self.module_ref.load_setting("time_played")
 86		try:
 87			self.time_played=long(temp)
 88		except:
 89			pass
 90
 91
 92
 93	"""
 94	unused functions
 95	def build_menu(self):
 96		pass
 97
 98	def update(self):
 99		pass
100
101	"""
102
103#print "a",hasattr(scoredisplayer(), "name"),"b"
104
105fofclone.add_widget(framerate)