# run with
# gnuplot -e 'datafile="../../bench_results_2012-11-20_10-46-56/data-0-cmd0.data"' plot

#set terminal jpeg
set terminal pngcairo enhanced
set xlabel "GameTime (in minutes)"
set xtics nomirror
set ytics nomirror
set border 3
#set xrange [0:20]
#set xrange [10:15]



outdir="./"

#set object 1 rect from screen 0, 0 to screen 1, 1 behind fc rgb "black" fillstyle transparent solid 0.1
#set object 2 rect from 0, 0 to 100000, 3000 behind fc rgb "white" fillstyle transparent solid 0.7


# helper  functions
blend(x,a) = (sum = (sum == 0)? x: sum*a+x*(1-a), sum)
blend2(x,a) = (sum2 = (sum2 == 0)? x: sum2*a+x*(1-a), sum2)
blend3(x,a) = (sum3 = (sum3 == 0)? x: sum3*a+x*(1-a), sum3)
blend4(x,a) = (sum4 = (sum4 == 0)? x: sum4*a+x*(1-a), sum4)
blend5(x,a) = (sum5 = (sum5 == 0)? x: sum5*a+x*(1-a), sum5)
blend6(x,a) = (sum6 = (sum6 == 0)? x: sum6*a+x*(1-a), sum6)
blend7(x,a) = (sum7 = (sum7 == 0)? x: sum7*a+x*(1-a), sum7)
init(x) = (sum = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0, sum7 = 0)


# the different FPS
set key opaque invert box top right
set yrange [0:300]
set ylabel "FPS"
set title "FPS"
set output outdir . "benchmark_fps.png"
plot \
	datafile using ($1/30/60):2 with lines title "FPS (effective)", \
	datafile using ($1/30/60):3 every 60 with lines title "FPS (drawing)", \
	datafile using ($1/30/60):4 every 60 with lines  title "FPS (simulation)"


# miliseconds per frame
set key opaque invert box top left reverse Left
set yrange [0:*]
set ylabel "FrameTime (in ms)"
set title "FrameTime"
set output outdir . "benchmark_mspf.png"
set label "30FPS"  front  at screen 0.5, first 37  tc rgb "white"
set label "30FPS"  front  at screen 0.5, first 38
plot sum = init(0), \
	datafile using ($1/30/60):(1000/$2) with lines title "effective", \
	datafile using ($1/30/60):(blend(1000/$2, 0.9995)) with lines title "effective blended", \
	datafile using ($1/30/60):(1000/$3) every 60 with lines title "rendering", \
	datafile using ($1/30/60):(1000/$4) every 60 with lines title "simulation", \
	datafile using ($1/30/60):(33) with line notitle
unset label

# miliseconds per frame
set key opaque invert box top left reverse Left
set yrange [0:*]
set ylabel "FrameTime (in ms)"
set title "FrameTime"
set output outdir . "benchmark_msratio.png"
set label "30FPS"  front  at screen 0.5, first 34  tc rgb "white"
set label "30FPS"  front  at screen 0.5, first 35
plot sum = init(0), \
	datafile using ($1/30/60):(blend(1000/$2, 0.9995)) with filledcurves y2=0 lc rgb "red" title "total", \
	datafile using ($1/30/60):(blend6(1000/$3, 0.999)) with filledcurves y2=0 lc rgb "green" title "rendering", \
	datafile using ($1/30/60):(blend2(1000/$2, 0.9995) * blend3($7/$4, 0.9995)) with filledcurves y2=0 lc rgb "blue" title "sim", \
	datafile using ($1/30/60):((blend4(1000/$2, 0.9995) * blend5(1 - $7/$4, 0.9995)) - blend7(1000/$3, 0.999)) with filledcurves y2=0 lc rgb "yellow" title "unknown", \
\
	sum = init(0), \
	datafile using ($1/30/60):(blend(1000/$2, 0.9995)) with line lc rgb "red" notitle, \
	datafile using ($1/30/60):(blend6(1000/$3, 0.999)) with line lc rgb "green" notitle, \
	datafile using ($1/30/60):(blend2(1000/$2, 0.9995) * blend3($7/$4, 0.9995)) with line lc rgb "blue" notitle, \
	datafile using ($1/30/60):((blend4(1000/$2, 0.9995) * blend5(1 - $7/$4, 0.9995)) - blend7(1000/$3, 0.999)) with line lc rgb "yellow" notitle, \
\
	datafile using ($1/30/60):(33) with line notitle
unset label



# miliseconds per frame
set key nobox
set yrange [0:100]
set ylabel "%"
set title "Sim/Rendering Ratio"
set output outdir . "benchmark_ratio.png"
plot \
	datafile using ($1/30/60):(100) every 60 with filledcurves y2=0 lc rgb "green" title "rendering", \
sum = init(0), \
	datafile using ($1/30/60):(blend($7*(100/$4), 0.999) > 100 ? 100 : blend($7*(100/$4), 0.999)) with filledcurves y2=0 lc rgb "red" title "simulation"


# drawFrameTime_ms / objects
set yrange [0:*]
set ylabel "µs"
set title "per object/unit overhead"
set output outdir . "benchmark_unit_correlation.png"
plot sum = init(0), \
	datafile using ($1/30/60):((1000000/$3)/($5 + $6)) every 60 with lines lc rgb "green" title "rendering", \
	datafile using ($1/30/60):(blend((1000000/$3)/($5 + $6), 0.9995)) with lines lc rgb "#008800" notitle, \
	datafile using ($1/30/60):((1000000/$4)/$5) every 60 with lines lc rgb "red" title "simulation", \
	datafile using ($1/30/60):(blend2((1000000/$4)/$5, 0.9995)) with lines lc rgb "#880000" notitle, \
	datafile using ($1/30/60):((10000*$8)/$5) every 60 with lines lc rgb "blue" title "lua"

quit
