BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Properties | Events | List of all members
BrawlLib.Internal.CoolTimer Class Reference

A timer created from OpenTK's gamewindow. More...

Public Member Functions

void Run (double updatesPerSec, double framesPerSec)
 Runs the timer until Stop() is called. Do note that the function that calls this will be suspended until the timer is stopped. Code located after where you call this will then be executed after. More...
 
void Stop ()
 

Properties

double TargetRenderFrequency [get, set]
 Gets or sets a double representing the target render frequency, in hertz. More...
 
double TargetRenderPeriod [get, set]
 Gets or sets a double representing the target render period, in seconds. More...
 
double RenderFrequency [get]
 Gets a double representing the actual frequency of RenderFrame events, in hertz (i.e. fps or frames per second). More...
 
double RenderPeriod [get]
 Gets a double representing the period of RenderFrame events, in seconds. More...
 
double RenderTime [get, protected set]
 Gets a double representing the time spent in the RenderFrame function, in seconds. More...
 
double TargetUpdateFrequency [get, set]
 Gets or sets a double representing the target update frequency, in hertz. More...
 
double TargetUpdatePeriod [get, set]
 Gets or sets a double representing the target update period, in seconds. More...
 
double UpdateFrequency [get]
 Gets a double representing the frequency of UpdateFrame events, in hertz. More...
 
double UpdatePeriod [get]
 Gets a double representing the period of UpdateFrame events, in seconds. More...
 
double UpdateTime [get]
 Gets a double representing the time spent in the UpdateFrame function, in seconds. More...
 
bool IsRunning [get]
 

Events

EventHandler< FrameEventArgsRenderFrame
 
EventHandler< FrameEventArgsUpdateFrame
 

Detailed Description

A timer created from OpenTK's gamewindow.

Member Function Documentation

◆ Run()

void BrawlLib.Internal.CoolTimer.Run ( double  updatesPerSec,
double  framesPerSec 
)
inline

Runs the timer until Stop() is called. Do note that the function that calls this will be suspended until the timer is stopped. Code located after where you call this will then be executed after.

Parameters
updatesPerSecFPS of update events.
framesPerSecFPS of render events.
216 {
217 _running = true;
218 //try
219 //{
220 //Action<object, DoWorkEventArgs> work = (object sender, DoWorkEventArgs e) =>
221 //{
222 TargetUpdateFrequency = updatesPerSec;
223 TargetRenderFrequency = framesPerSec;
224
225 _updateWatch.Reset();
226 _renderWatch.Reset();
227
228 if (TargetUpdateFrequency != 0)
229 {
230 _updateWatch.Start();
231 }
232
233 if (TargetRenderFrequency != 0)
234 {
235 _renderWatch.Start();
236 }
237
238 while (true)
239 {
240 ProcessEvents();
241 if (!_running)
242 {
243 return;
244 }
245
246 UpdateAndRenderFrame();
247 }
248
249 //};
250 //using (BackgroundWorker b = new BackgroundWorker())
251 //{
252 // b.DoWork += new DoWorkEventHandler(work);
253 // //b.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completed);
254 // b.RunWorkerAsync();
255 //}
256 //}
257 //catch
258 //{
259 // _running = false;
260 // return;
261 //}
262 }
double TargetRenderFrequency
Gets or sets a double representing the target render frequency, in hertz.
Definition: CoolTimer.cs:38
double TargetUpdateFrequency
Gets or sets a double representing the target update frequency, in hertz.
Definition: CoolTimer.cs:130

◆ Stop()

void BrawlLib.Internal.CoolTimer.Stop ( )
inline
393 {
394 _running = false;
395 }

Property Documentation

◆ IsRunning

bool BrawlLib.Internal.CoolTimer.IsRunning
get

◆ RenderFrequency

double BrawlLib.Internal.CoolTimer.RenderFrequency
get

Gets a double representing the actual frequency of RenderFrame events, in hertz (i.e. fps or frames per second).

92 {
93 get
94 {
95 if (_renderPeriod == 0.0)
96 {
97 return 1.0;
98 }
99
100 return 1.0 / _renderPeriod;
101 }
102 }

◆ RenderPeriod

double BrawlLib.Internal.CoolTimer.RenderPeriod
get

Gets a double representing the period of RenderFrame events, in seconds.

◆ RenderTime

double BrawlLib.Internal.CoolTimer.RenderTime
getprotected set

Gets a double representing the time spent in the RenderFrame function, in seconds.

113 {
114 get => _renderTime;
115 protected set => _renderTime = value;
116 }

◆ TargetRenderFrequency

double BrawlLib.Internal.CoolTimer.TargetRenderFrequency
getset

Gets or sets a double representing the target render frequency, in hertz.

A value of 0.0 indicates that RenderFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).

Values lower than 1.0Hz are clamped to 1.0Hz. Values higher than 200.0Hz are clamped to 200.0Hz.

38 {
39 get
40 {
41 if (TargetRenderPeriod == 0.0)
42 {
43 return 0.0;
44 }
45
46 return 1.0 / TargetRenderPeriod;
47 }
48 set
49 {
50 double v = value.Clamp(0.0, 200.0);
51
52 if (v < 1.0)
53 {
55 }
56 else
57 {
58 TargetRenderPeriod = 1.0 / v;
59 }
60 }
61 }
double TargetRenderPeriod
Gets or sets a double representing the target render period, in seconds.
Definition: CoolTimer.cs:71

◆ TargetRenderPeriod

double BrawlLib.Internal.CoolTimer.TargetRenderPeriod
getset

Gets or sets a double representing the target render period, in seconds.

A value of 0.0 indicates that RenderFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).

Values lower than 0.005 seconds (200Hz) are clamped to 0.0. Values higher than 1.0 seconds (1Hz) are clamped to 1.0.

71 {
72 get => _targetRenderPeriod;
73 set
74 {
75 double v = value.Clamp(0.0, 1.0);
76
77 if (v < 0.001)
78 {
79 _targetRenderPeriod = 0.0;
80 }
81 else
82 {
83 _targetRenderPeriod = v;
84 }
85 }
86 }

◆ TargetUpdateFrequency

double BrawlLib.Internal.CoolTimer.TargetUpdateFrequency
getset

Gets or sets a double representing the target update frequency, in hertz.

A value of 0.0 indicates that UpdateFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).

Values lower than 1.0Hz are clamped to 1.0Hz. Values higher than 200.0Hz are clamped to 200.0Hz.

130 {
131 get
132 {
133 if (TargetUpdatePeriod == 0.0)
134 {
135 return 0.0;
136 }
137
138 return 1.0 / TargetUpdatePeriod;
139 }
140 set
141 {
142 double v = value.Clamp(0.0, 200.0);
143
144 if (v < 1.0)
145 {
146 TargetUpdatePeriod = 0.0;
147 }
148 else
149 {
150 TargetUpdatePeriod = 1.0 / v;
151 }
152 }
153 }
double TargetUpdatePeriod
Gets or sets a double representing the target update period, in seconds.
Definition: CoolTimer.cs:163

◆ TargetUpdatePeriod

double BrawlLib.Internal.CoolTimer.TargetUpdatePeriod
getset

Gets or sets a double representing the target update period, in seconds.

A value of 0.0 indicates that UpdateFrame events are generated at the maximum possible frequency (i.e. only limited by the hardware's capabilities).

Values lower than 0.005 seconds (200Hz) are clamped to 0.0. Values higher than 1.0 seconds (1Hz) are clamped to 1.0.

163 {
164 get => _targetUpdatePeriod;
165 set
166 {
167 double v = value.Clamp(0.0, 1.0);
168
169 if (v <= 0.005)
170 {
171 _targetUpdatePeriod = 0.0;
172 }
173 else
174 {
175 _targetUpdatePeriod = v;
176 }
177 }
178 }

◆ UpdateFrequency

double BrawlLib.Internal.CoolTimer.UpdateFrequency
get

Gets a double representing the frequency of UpdateFrame events, in hertz.

184 {
185 get
186 {
187 if (_updatePeriod == 0.0)
188 {
189 return 1.0;
190 }
191
192 return 1.0 / _updatePeriod;
193 }
194 }

◆ UpdatePeriod

double BrawlLib.Internal.CoolTimer.UpdatePeriod
get

Gets a double representing the period of UpdateFrame events, in seconds.

◆ UpdateTime

double BrawlLib.Internal.CoolTimer.UpdateTime
get

Gets a double representing the time spent in the UpdateFrame function, in seconds.

Event Documentation

◆ RenderFrame

EventHandler<FrameEventArgs> BrawlLib.Internal.CoolTimer.RenderFrame

◆ UpdateFrame

EventHandler<FrameEventArgs> BrawlLib.Internal.CoolTimer.UpdateFrame

The documentation for this class was generated from the following file: