| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  | package iron.system; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Time { | 
					
						
							| 
									
										
										
										
											2025-06-02 16:32:28 +00:00
										 |  |  | 	public static var scale = 1.0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	static var frequency: Null<Int> = null; | 
					
						
							|  |  |  | 	static function initFrequency() { | 
					
						
							|  |  |  | 		frequency = kha.Display.primary != null ? kha.Display.primary.frequency : 60; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  | 	public static var step(get, never): Float; | 
					
						
							|  |  |  | 	static function get_step(): Float { | 
					
						
							|  |  |  | 		if (frequency == null) initFrequency(); | 
					
						
							|  |  |  | 		return 1 / frequency; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-06-01 23:18:35 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2025-06-02 04:18:44 +00:00
										 |  |  | 	static var _fixedStep: Null<Float>; | 
					
						
							| 
									
										
										
										
											2025-06-01 23:18:35 +00:00
										 |  |  | 	public static var fixedStep(get, never): Float; | 
					
						
							|  |  |  | 	static function get_fixedStep(): Float { | 
					
						
							| 
									
										
										
										
											2025-06-02 04:18:44 +00:00
										 |  |  | 		return _fixedStep; | 
					
						
							| 
									
										
										
										
											2025-06-01 23:18:35 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2025-06-02 04:18:44 +00:00
										 |  |  | 	public static function initFixedStep(value: Float = 1 / 60) { | 
					
						
							|  |  |  | 		_fixedStep = value; | 
					
						
							| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-02 04:18:44 +00:00
										 |  |  | 	static var lastTime = 0.0; | 
					
						
							| 
									
										
										
										
											2025-06-02 16:32:28 +00:00
										 |  |  | 	static var _delta = 0.0; | 
					
						
							|  |  |  | 	public static var delta(get, never): Float; | 
					
						
							|  |  |  | 	static function get_delta(): Float { | 
					
						
							|  |  |  | 		return _delta; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2025-06-02 04:18:44 +00:00
										 |  |  | 	static var lastRenderTime = 0.0; | 
					
						
							| 
									
										
										
										
											2025-06-02 16:32:28 +00:00
										 |  |  | 	static var _renderDelta = 0.0; | 
					
						
							|  |  |  | 	public static var renderDelta(get, never): Float; | 
					
						
							|  |  |  | 	static function get_renderDelta(): Float { | 
					
						
							|  |  |  | 		return _renderDelta; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  | 	public static inline function time(): Float { | 
					
						
							|  |  |  | 		return kha.Scheduler.time(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2025-06-02 16:32:28 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  | 	public static inline function realTime(): Float { | 
					
						
							|  |  |  | 		return kha.Scheduler.realTime(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public static function update() { | 
					
						
							| 
									
										
										
										
											2025-06-02 16:32:28 +00:00
										 |  |  | 		_delta = realTime() - lastTime; | 
					
						
							| 
									
										
										
										
											2025-06-02 04:18:44 +00:00
										 |  |  | 		lastTime = realTime(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public static function render() { | 
					
						
							| 
									
										
										
										
											2025-06-02 16:32:28 +00:00
										 |  |  | 		_renderDelta = realTime() - lastRenderTime; | 
					
						
							| 
									
										
										
										
											2025-06-02 04:18:44 +00:00
										 |  |  | 		lastRenderTime = realTime(); | 
					
						
							| 
									
										
										
										
											2025-01-22 16:18:30 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |