Skip to content

A budding framework of bite-sized helper libraries for DRGTK.

License

Notifications You must be signed in to change notification settings

Erquint/giatros

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Giatros

…is (so far) a framework of bite-sized helper libraries for DRGTK.
Keep them together but require only the ones you need.
I suggest creating a /lib/ directory beside your /app/ and cloning the repo into it.

There is still much to optimize as the first implementations have many performance issues. I'm just concentrating on getting proofs of concept out first before I bury myself in analysis.

A "plug-and-play" library for performance tracking of your project.
Just require it and feed the primitives it provides to DRGTK rendering pipeline like this: args.outputs.labels << Giatros::Frametimer.frametime_label.
I could even have Frametimer do that last step for you but wanted you to be able to reposition, scale and color the primitives natively to your liking. Thinking on it… I should make a variant later.

Go check out the basic sample if any of this isn't clear.

Giatros::Frametimer::frametime_rawFloat (in seconds)

Returns delta-time (time elapsed) from start of the last tick (frame) to start of the current one.

Giatros::Frametimer::frametimeFloat (in seconds)

Returns the median frametiming of the last n (defined by clock_window) ticks (frames).

Giatros::Frametimer::fpsFloat (in frames-per-second)

Returns the median FPS of the last n (defined by clock_window) ticks (frames).

Giatros::Frametimer::frametime_labelHash (DRGTK label primitive)

Returns a pre-formatted frametime label (based on frametime) which you can directly feed to args.outputs.labels as is or after repositioning if you so choose.

Giatros::Frametimer::fps_labelHash (DRGTK label primitive)

Returns a pre-formatted FPS label (based on fps) which you can directly feed to args.outputs.labels as is or after repositioning if you so choose.

Giatros::Frametimer::graphHash (DRGTK sprite primitive)

Returns a pre-formatted frametime sprite (based on frametime_raw) which you can directly feed to args.outputs.sprites as is or after repositioning/resizing if you so choose.
clock_window dictates the internal horizontal resolution.

Returns the current length of the rolling window of last ticks (frames) stored to be used for the graph and median-averaging.

Allows to set the length of the rolling window of last ticks (frames) stored to be used for the graph and median-averaging.

WARNING: it's currently discouraged to increase this clock window due to performance issues. An optimization that would allow for better performance scaling is pending.

Sick of pesky nils getting into your arithmetics and DRGTK silently allowing them to spread like NaNs?
Tired of wasting time on hunting down the specific instruction that plagued your calculations with nil in the first place?

Frankly, exceptions were invented for this but lacking in DRGTK.
Just require this library to return exceptions on nil arithmetics attempts.

Here's an example of the exception:

-> 4/nil
* EXCEPTION: TypeError (nil can't be coerced into Fixnum): 4 / nil

Yup, it even tells you the operation that caused it along with the first operand.

(You should get a different error if nil was the first operand but that's a whole another story and may later change on DRGTK side.)

Array#medianFloat

I've still no idea why a median method isn't already a part of Ruby or mRuby core but here you go for all your statistical needs.

If you're unfamiliar with how median is calculated:
Sort an array and pick the middle or the average of 2 middle values depending on whether the set length is odd or even.

Array#sumNumeric

Did I already mention DRGTK is weird? So while you can use Array#sum in Ruby proper — it's not defined in DRGTK.
Well, surely, you can just array.inject(:+) like in ye olden times, right… right? Not so fast.
Arithmetical operators in DRGTK are held together by dark magic and a crumpled wad of duct tape. Sometimes they decide to stop existing at all if you're looking at them weird. Passing them as argument to Array#inject or Array#reduce counts as a shifty look.

The workaround is to use the block overload of reduce/inject like this: [4, 20].reduce{|sum, summand| sum + summand}. So you could either use that monstrosity raw or [4, 20].sum if you require array_sum.rb.

About

A budding framework of bite-sized helper libraries for DRGTK.

Resources

License

Stars

Watchers

Forks

Languages