Skip to content

Instantly share code, notes, and snippets.

@josefnpat
Last active August 29, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josefnpat/06fa0829c3a2a568a81a to your computer and use it in GitHub Desktop.
Save josefnpat/06fa0829c3a2a568a81a to your computer and use it in GitHub Desktop.
The Nick Waanders FPS Rating Module (For LÖVE 0.8.x and 0.9.x)

WaandersRate

The Nick Waanders FPS Rating Module (For LÖVE 0.8.x and 0.9.x) Draws an emoticon in relation to the FPS.

  • 0-16: Nick is angry.
  • 16-24: Nick is yelling.
  • 24-30: Nick is content.
  • 30-60: Nick is Cool.

Author

@josefnpat, © 2014

Thanks to @nickwaanders for the story and the idea.

License

zlib/libpng

This library uses a deviation of mastastealth's LÖVEy emoticon set .

Usage

Simply make require "waandersrate"() the last line of your love.draw.

function love.draw()
  require "waandersrate"()
end

You can also choose where to draw:

function love.draw()
  -- Lower right corner is way cooler!
  require "waandersrate"(love.graphics.getWidth()-16,love.graphics.getHeight()-16)
end

Why?

Read story.md

function love.draw()
require "waandersrate"() -- The only required line!
love.graphics.print("Simulated FPS: "..love.timer.getFPS(),64,64)
end
-- Override love.timer.getFPS for testing
function love.timer.getFPS()
return love.mouse.getX()/love.graphics.getWidth()*60
end

I once worked at THQ studio Relic Entertainment on The Outfit, which some may remember as one of the earlier games for the Xbox 360. We started with a PC engine (single-threaded), and we had to convert it to a complete game on a next-gen multi-core console in about 18 months. About three months before shipping, we were still running at about 5 FPS on the 360. Obviously this game needed some severe optimization.

When I did some performance measurements, it became clear that as much as the code was slow and very "PC," there were also lots of problems on the content side as well. Some models were too detailed, some shaders were too expensive, and some missions simply had too many guys running around.

It's hard to convince a team of 100 people that the programmers can't simply "fix" the performance of the engine, and that some of the ways people had gotten used to working to needed to be changed. People needed to understand that the performance of the game was everybody's problem, and I figured the best way to do this is with a bit of humor that had a bit of hidden truth behind it.

The solution took maybe an hour. A fellow programmer took four pictures of my face -- one really happy, one normal, one a bit angry, and one where I am pulling my hair out. I put this image in the corner of the screen, and it was linked to the frame rate. If the game ran at over 30fps, I was really happy, if it ran below 20, I was angry.

After this change, the whole FPS issue transformed from, "Ah, the programmers will fix it." to, "Hmm, if I put this model in, Nick is going to be angry! I'd better optimize this a little first." People could instantly see if a change they made had an impact on the frame rate, and we ended up shipping the game at 30fps.

  • Nick Waanders

Source

-- The Nick Waanders FPS Rating Module (For LÖVE 0.8.x and 0.9.x)
-- Draws an emoticon in relation to the FPS.
-- 0-16: Angry 16-24: Yelling 24-30: Content 30-60: Cool.
-- Author: josefnpat, 2014
-- License: zlib/libpng
-- Uses an deviation of mastastealth's LÖVEy emoticon set.
-- http://opengameart.org/content/mastastealth%E2%80%99s-l%C3%B6vey
-- CC-BY 3.0+/GPL compatible zlib_license
local waandersrate = {
_VERSION = 'WaandersRate 1.0',
_LICENSE = 'zlib/libpng',
}
waandersrate._get_fps=love.timer.getFPS
waandersrate._fps_levels = {16,24,30,60}
waandersrate._raw = {
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\
bWFnZVJlYWR5ccllPAAAAXtJREFUeNpi/P//PwMlgAVEfGe0RxbjAeIiIPYAYjOo2Ckg3gHEfUD8\
BaaQ8/9BBgaQC74x2MFo+78MDvf/p3T9/3/86n84uPvs//+auf//c7o9AKkBqYVhuAFAHPhfwBdV\
Izp49ub/f53E/2C1UAMYgRxwIDAzMDKwHZ/GwGChhd/Trz8wMGgmMHx/+x7Ch7qg5X9Cx3+iwZxt\
/8F6kLxw/v/BiwgFIGFsGAa+/vj/n9kJpIGBCeowLQYTdYQzYVEL04osBgJc7AwMqjJKICbMgO8M\
LEyofkXWgC2tsLEyIRtwn+H6I+JTz99/DAx3nt5FNmArw6r9xBuw4xTD92/fNiHHguh/Vucv/x+/\
wh2QMPDz1///2olfwXrQElLIf804SGLBBUCaA+v+g9Wip0Qo7fpfPOjh/5mb////9BVV88aj///r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3tWpReBZbisFTtnoc56zr/AdcA\
UZL355fyAAAAAElFTkSuQmCC\
",
}
function waandersrate._loadimage(file, name)
return love.graphics.newImage(
love.image.newImageData(
love.filesystem.newFileData(file, name:gsub("_", "."), "base64")))
end
waandersrate._images = {}
for fps_index,raw_data in pairs(waandersrate._raw) do
local fps_level = waandersrate._fps_levels[fps_index]
waandersrate._images[fps_level] =
waandersrate._loadimage(raw_data, fps_level..".png")
end
function waandersrate.draw(ix,iy)
local x,y = ix or 4,iy or 4
local index
for fps_index,fps_level in pairs(waandersrate._fps_levels) do
if waandersrate._get_fps() < fps_level then
index = fps_index
break
end
end
index = index or #waandersrate._fps_levels
love.graphics.draw(waandersrate._images[waandersrate._fps_levels[index]],x,y)
end
return waandersrate.draw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment