2018-06-17 02:59:23 +00:00
|
|
|
package doodle
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-07-25 03:57:22 +00:00
|
|
|
"git.kirsle.net/apps/doodle/doodads"
|
2018-06-17 02:59:23 +00:00
|
|
|
"git.kirsle.net/apps/doodle/render"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Frames to cache for FPS calculation.
|
|
|
|
const maxSamples = 100
|
|
|
|
|
2018-07-26 02:38:54 +00:00
|
|
|
// Debug mode options, these can be enabled in the dev console
|
|
|
|
// like: boolProp DebugOverlay true
|
|
|
|
var (
|
2018-08-11 00:19:47 +00:00
|
|
|
DebugOverlay = false
|
2018-07-26 02:38:54 +00:00
|
|
|
DebugCollision = true
|
|
|
|
)
|
|
|
|
|
2018-06-17 02:59:23 +00:00
|
|
|
var (
|
|
|
|
fpsCurrentTicks uint32 // current time we get sdl.GetTicks()
|
|
|
|
fpsLastTime uint32 // last time we printed the fpsCurrentTicks
|
|
|
|
fpsCurrent int
|
|
|
|
fpsFrames int
|
|
|
|
fpsSkipped uint32
|
|
|
|
fpsInterval uint32 = 1000
|
|
|
|
)
|
|
|
|
|
|
|
|
// DrawDebugOverlay draws the debug FPS text on the SDL canvas.
|
|
|
|
func (d *Doodle) DrawDebugOverlay() {
|
2018-07-26 02:38:54 +00:00
|
|
|
if !d.Debug || !DebugOverlay {
|
2018-06-17 02:59:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-22 00:12:22 +00:00
|
|
|
label := fmt.Sprintf(
|
2018-07-22 03:43:01 +00:00
|
|
|
"FPS: %d (%dms) S:%s F12=screenshot",
|
2018-06-17 02:59:23 +00:00
|
|
|
fpsCurrent,
|
|
|
|
fpsSkipped,
|
2018-07-26 02:38:54 +00:00
|
|
|
d.Scene.Name(),
|
2018-06-17 02:59:23 +00:00
|
|
|
)
|
2018-07-22 00:12:22 +00:00
|
|
|
|
|
|
|
err := d.Engine.DrawText(
|
|
|
|
render.Text{
|
|
|
|
Text: label,
|
|
|
|
Size: 24,
|
|
|
|
Color: DebugTextColor,
|
|
|
|
Stroke: DebugTextStroke,
|
|
|
|
Shadow: DebugTextShadow,
|
|
|
|
},
|
2018-07-22 03:43:01 +00:00
|
|
|
render.Point{
|
2018-07-22 00:12:22 +00:00
|
|
|
X: DebugTextPadding,
|
Menu Toolbar for Editor + Shell Prompts + Theme
* Added a "menu toolbar" to the top of the Edit Mode with useful buttons
that work: New Level, New Doodad (same thing), Save, Save as, Open.
* Added ability for the dev console to prompt the user for a question,
which opens the console automatically. "Save", "Save as" and "Load"
ask for their filenames this way.
* Started groundwork for theming the app. The palette window is a light
brown with an orange title bar, the Menu Toolbar has a black
background, etc.
* Added support for multiple fonts instead of just monospace. DejaVu
Sans (normal and bold) are used now for most labels and window titles,
respectively. The dev console uses DejaVu Sans Mono as before.
* Update ui.Label to accept PadX and PadY separately instead of only
having the Padding option which did both.
* Improvements to Frame packing algorithm.
* Set the SDL draw mode to BLEND so we can use alpha colors properly,
so now the dev console is semi-translucent.
2018-08-12 00:30:00 +00:00
|
|
|
Y: DebugTextPadding + 32, // extra padding to not overlay menu bars
|
2018-07-22 00:12:22 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("DrawDebugOverlay: text error: %s", err.Error())
|
|
|
|
}
|
2018-06-17 02:59:23 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 03:57:22 +00:00
|
|
|
// DrawCollisionBox draws the collision box around a Doodad.
|
|
|
|
func (d *Doodle) DrawCollisionBox(actor doodads.Doodad) {
|
2018-07-26 02:38:54 +00:00
|
|
|
if !d.Debug || !DebugCollision {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-25 03:57:22 +00:00
|
|
|
var (
|
|
|
|
rect = doodads.GetBoundingRect(actor)
|
|
|
|
box = doodads.GetCollisionBox(rect)
|
|
|
|
)
|
|
|
|
|
|
|
|
d.Engine.DrawLine(render.DarkGreen, box.Top[0], box.Top[1])
|
|
|
|
d.Engine.DrawLine(render.DarkBlue, box.Bottom[0], box.Bottom[1])
|
|
|
|
d.Engine.DrawLine(render.DarkYellow, box.Left[0], box.Left[1])
|
|
|
|
d.Engine.DrawLine(render.Red, box.Right[0], box.Right[1])
|
|
|
|
}
|
|
|
|
|
2018-06-17 02:59:23 +00:00
|
|
|
// TrackFPS shows the current FPS once per second.
|
|
|
|
func (d *Doodle) TrackFPS(skipped uint32) {
|
|
|
|
fpsFrames++
|
2018-07-22 00:12:22 +00:00
|
|
|
fpsCurrentTicks = d.Engine.GetTicks()
|
2018-06-17 02:59:23 +00:00
|
|
|
|
|
|
|
// Skip the first second.
|
|
|
|
if fpsCurrentTicks < fpsInterval {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if fpsLastTime < fpsCurrentTicks-fpsInterval {
|
|
|
|
fpsLastTime = fpsCurrentTicks
|
|
|
|
fpsCurrent = fpsFrames
|
|
|
|
fpsFrames = 0
|
|
|
|
fpsSkipped = skipped
|
|
|
|
}
|
|
|
|
}
|