pulse /python/framerate.py

Language Python Lines 105
MD5 Hash 781cc3da586fa4243bde05337a16990c Estimated Cost $1,334 (why?)
Repository https://bitbucket.org/lonkero173/pulse View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
# -*- coding: utf-8 -*-
import fofclone

class framerate:
	def __init__(self):
		import fofclone	#having trouble with some aspects of python embedding.... this is necessary at the moment, wish I knew why...
		self.module_ref=fofclone
		self.render_time=self.module_ref.EVERY_FRAME
		self.is_global=True

		self.name="Framerate display"		#required
		self.description="Prints framerate data, lots of it"	#required

		self.sframerate=0.0
		self.hframerate=0.0
		self.framecount=0
		self.framedelay=0
		self.updatetime=0
		self.low=100000000.0		#this is an impossible framerate a.t.m	(if SDL_Delay(10) is respected...)
		self.high=0.0
		self.average=0.0
		self.time_played=0


	def render(self):
		# do the updating work, there is so little of it that there is no point in a seperate update function
		self.framecount+=1;

		self.framedelay=self.module_ref.get_framedelay()
		self.time_played+=self.framedelay
		self.updatetime = self.module_ref.get_updatetime()

		if(self.framedelay>0.0):
			self.sframerate*=0.99
			self.sframerate+=10.0/self.framedelay
			self.hframerate=1000.0/self.framedelay

			#self.average=(self.average*(self.framecount-1)+self.hframerate)/self.framecount
			self.average+=(self.hframerate-self.average)/self.framecount
		else:
			# getting a frame in <1 ms means on average +1000 to the framerate
			self.sframerate*=0.95
			self.sframerate+=50.0/1000.0
			self.hframerate+=1000.0

		# ignore first 10 frames for minimum framerate calculations as there is only one frame update during the entire loading process (but more may come...)
		if(self.hframerate<self.low and self.framecount>10): self.low=self.hframerate;
		if(self.hframerate>self.high): self.high=self.hframerate;

		# print the frame that is being drawn
		self.module_ref.simple_print("Frame:",0.50,0.60)
		self.module_ref.simple_print("%d"%(self.framecount),0.80,0.60)
		
		# print the render time
		self.module_ref.simple_print("Update Time:",0.50,0.55)
		self.module_ref.simple_print("%d"%(self.updatetime),0.80,0.55)

		# a smooth framerate
		self.module_ref.simple_print("Fps (Smooth):",0.50,0.50)
		self.module_ref.simple_print("%5.3f "%(self.sframerate),0.80,0.50)

		# a hard framerate, no averaging out
		self.module_ref.simple_print("Fps (Absolute):",0.50,0.45)
		self.module_ref.simple_print("%5.3f"%(self.hframerate),0.80,0.45)

		#high
		self.module_ref.simple_print("High:",0.50,0.40)
		self.module_ref.simple_print("%5.3f"%(self.high),0.80,0.40)

		#low
		self.module_ref.simple_print("Low:",0.50,0.35)
		self.module_ref.simple_print("%5.3f"%(self.low),0.80,0.35)

		#average
		self.module_ref.simple_print("Average:",0.50,0.30)
		self.module_ref.simple_print("%5.3f"%(self.average),0.80,0.30)
		
		#print self.sframerate
		

	def save_settings(self):
		self.module_ref.save_setting("time_played",str(self.time_played))

	def load_settings(self):
		temp=self.module_ref.load_setting("time_played")
		try:
			self.time_played=long(temp)
		except:
			pass



	"""
	unused functions
	def build_menu(self):
		pass

	def update(self):
		pass

	"""

#print "a",hasattr(scoredisplayer(), "name"),"b"

fofclone.add_widget(framerate)
Back to Top