
--fichier commun aux 2dgame et aux warp

function OnStatEnter()
	--pour les stats
	local statdata = Load("Statistics","DataArray")

	if not statdata.IsRegistered(self.Name.."_timeSpent") then	
		statdata.RegisterValue(self.Name.."_timeSpent",0)
	end	
	
	if not statdata.IsRegistered(self.Name.."_fps") then	
		statdata.RegisterValue(self.Name.."_fps",0)
	end	
			
	statdata.Set("CurTimeSpent",OPTime.GetTime())
	
	statdata.Set("FpsCounter",0)
end

function OnStatLeave()
	--stat
		---gestion du tps	
	local statdata = Load("Statistics","DataArray")
		
	statdata.Set("TotalTimeSpent",statdata.Get('TotalTimeSpent')+OPTime.GetTime() - statdata.Get("CurTimeSpent"))
	
	local n = statdata.Get(self.Name.."_timeSpent")	+ OPTime.GetTime()  - statdata.Get("CurTimeSpent")
	statdata.Set(self.Name.."_timeSpent",n )	
		
	--on calcule le fps moyen
	length = OPTime.GetTime() - statdata.Get("CurTimeSpent")
	fpsspent = statdata.Get("FpsCounter")
	
	--OPLog.Log("length fps "..length.." "..fpsspent)
	statdata.Set(self.Name.."_fps",fpsspent / length)	
	
end
