debug

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

README

Debug

Here we expose a debug console that can be run by having the debug flag set. For a ease of use just run mage dr to get a debug run in process.

Note that the current plumbing here is rather lossy as it takes a bit to realize that the main scene has changed contexts. Given this expect this implementation to be deprecated in the near future (hopefully).

Documentation

Index

Constants

View Source
const RecreationNeeded = "RecreationNeeded"

RecreationNeeded tracks when we should recheck for main loop changes

Variables

View Source
var Scene = scene.Scene{
	Start: func(ctx *scene.Context) {
		mainIsRunning = true

		dFPS := render.NewDrawFPS(0.1, nil, 900, 10)
		ctx.DrawStack.Draw(dFPS, 1)
		fnt := render.DefaultFont()

		titleFnt, _ := fnt.RegenerateWith(fonthelper.WithSizeAndColor(20, image.NewUniform(colornames.Crimson)))

		keyX := 10.0
		tqX := 140.0

		kTitle := titleFnt.NewText("KeyUsage", keyX, 10)
		ctx.DrawStack.Draw(kTitle, 0)

		bound2 := render.NewLine(tqX-10, 5, tqX-10, float64(ctx.Window.Height()), colornames.Beige)
		ctx.DrawStack.Draw(bound2, 0)

		logTitle := titleFnt.NewText("Logging", tqX, 10)
		ctx.DrawStack.Draw(logTitle, 0)

		fntSize := 14.0
		fnt, _ = fnt.RegenerateWith(fonthelper.WithSizeAndColor(fntSize, image.NewUniform(colornames.Aliceblue)))

		bkg := render.NewColorBox(50, 50, colornames.Lightslategray)
		ctx.Window.(*oak.Window).SetBackground(
			bkg.Modify(mod.Resize(ctx.Window.Width(), ctx.Window.Height(), mod.CubicResampling)),
		)

		tq := textqueue.New(
			ctx, "",
			floatgeom.Point2{tqX, 50}, layers.Hover,
			fnt.Copy(),
			15*time.Second,
		)
		ctx.DrawStack.Draw(tq, 0)

		keyQFnt, _ := fnt.RegenerateWith(fonthelper.WithColor(image.NewUniform(colornames.Aliceblue)))

		keyQueue := textqueue.New(
			ctx, "KeyChange",
			floatgeom.Point2{keyX, 50}, layers.Hover,
			keyQFnt,
			4*time.Second,
		)
		ctx.DrawStack.Draw(keyQueue, 0)

		dbgStart := time.Now()
		go func() {
			d := 5.0 * time.Second
			t := time.NewTimer(d)
			defer t.Stop()
			for {
				select {
				case <-t.C:
					ctx.EventHandler.Trigger("DisplayText", fmt.Sprintf("<--- %.0f seconds after starts", time.Now().Sub(dbgStart).Seconds()))
					t.Reset(d)
				case <-ctx.Done():
					mainIsRunning = false
					return
				}
			}
		}()

		startWatchdog(ctx)

		ctx.EventHandler.GlobalBind(RecreationNeeded, func(id event.CID, payload interface{}) int {

			event.GlobalBind(key.Down, func(_ event.CID, k interface{}) int {
				kValue := k.(key.Event)
				ctx.EventHandler.Trigger("KeyChange", fmt.Sprintf("Press: %v", keyCodeString(kValue.Code)))
				return 0
			})
			event.GlobalBind(key.Up, func(_ event.CID, k interface{}) int {
				kValue := k.(key.Event)
				ctx.EventHandler.Trigger("KeyChange", fmt.Sprintf("Release: %v", keyCodeString(kValue.Code)))
				return 0
			})

			return 0
		})

		return

	}, Loop: func() (cont bool) {

		return mainIsRunning
	}, End: func() (nextScene string, result *scene.Result) {

		os.Exit(1)
		return "", nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL