feat: better debugging messaging interface.

This commit is contained in:
Andrey Parhomenko 2024-06-02 22:31:56 +05:00
parent 5cd9a65dfb
commit 8a57cfe9e6
4 changed files with 49 additions and 75 deletions

View file

@ -59,9 +59,11 @@ func (cam *Camera) OnUpdate(c gg.Context) {
for _, key := range c.Engine().GetKeyboardKeys() {
switch key {
case gg.KeyF:
cam.AddScale(mx.V2(d*cam.ScaleSpeed * dt))
cam.AddScale(mx.VX(d*cam.ScaleSpeed * dt))
case gg.KeyG:
cam.AddScale(mx.VY(d*cam.ScaleSpeed * dt))
case gg.KeyR:
cam.Rotate(d*mx.Pi * cam.ScaleSpeed * dt)
cam.Rotate(d*mx.Pi * cam.RotationSpeed * dt)
}
}
}

View file

@ -5,8 +5,8 @@ import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
import (
"strings"
"fmt"
//"strings"
//"fmt"
)
type Debug struct {
@ -34,82 +34,40 @@ func (d *Debug) Draw(c Context) *gg.Drawing {
e := c.Engine()
relTri := tri.Rel()
relPlayer := player.Rel()
keys := c.Engine().GetKeyboardKeys()
keyStrs := []string{}
keyStrs = append(keyStrs, fmt.Sprintf(
"counter: %d", counter,
))
keyStrs = append(keyStrs, fmt.Sprintf(
"tps: %d", int(c.Engine().TPS()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"fps: %d", int(c.Engine().FPS()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"dframe: %d", int(c.Engine().Dframe()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"frame: %d", int(c.Engine().Frame()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"relPlayerPos: %v", relPlayer.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absPlayerPos: %v", player.GetPosition(),
))
c.Dprint(
"counter = ", counter, "\n",
"tps = ", int(c.Engine().TPS()), "\n",
"fps = ", int(c.Engine().FPS()), "\n",
"dframe = ", int(c.Engine().Dframe()), "\n",
"frame = ", int(c.Engine().Frame()), "\n",
"relPlayerPos = ", relPlayer.GetPosition(), "\n",
"absPlayerPos = ", player.GetPosition(), "\n",
"relTriPos = ", relTri.GetPosition(), "\n",
"absTriPos = ", tri.GetPosition(), "\n",
"absTriRot = " , mx.Degree(tri.GetRotation()), "\n",
"keys = ", keys, "\n",
keyStrs = append(keyStrs, fmt.Sprintf(
"relTriPos: %v", relTri.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriPos: %v", tri.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriRot: %v", mx.Degree(tri.GetRotation()),
))
"GetMouseButtons(...) = ",
c.Engine().GetMouseButtons(), "\n",
keys := []string{}
for _, k := range e.GetKeyboardKeys() {
keys = append(keys, k.String())
}
keyStrs = append(keyStrs, fmt.Sprintf(
"keys: %s", strings.Join(keys, ", "),
))
"GetMouseWheel(...) = ", "\n",
c.Engine().GetMouseWheel(), "\n",
keyStrs = append(keyStrs, fmt.Sprintf(
"buttons: %v", c.Engine().MouseButtons(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"wheel: %v", c.Engine().Wheel(),
))
/*if rectMove.ContainsPoint(e.AbsCursorPosition()) {
keyStrs = append(keyStrs, "contains cursor")
}
if rectMove.Vertices().Contained(rect).Len() > 0 ||
rect.Vertices().Contained(rectMove).Len() > 0 {
keyStrs = append(keyStrs, "rectangles intersect")
}*/
keyStrs = append(keyStrs, fmt.Sprintf(
"camera position: %v %v",
"camera.GetPosition(...) = ",
camera.GetPosition().X,
camera.GetPosition().Y,
))
keyStrs = append(keyStrs, fmt.Sprintf(
"realCursorPos: %v", e.GetRealCursorPosition()))
keyStrs = append(keyStrs, fmt.Sprintf(
"absCursorPos: %v", e.GetAbsCursorPosition() ))
camera.GetPosition().Y, "\n",
keyStrs = append(keyStrs,
fmt.Sprintf(
"absWinSize: %v",
c.Engine().GetAbsWinSize(),
),
"GetRealCursorPosition(...) = ",
e.GetRealCursorPosition(), "\n",
"GetAbsCursorPos(...) = ",
e.GetAbsCursorPosition(), "\n",
"GetAbsWinSize(...) = ",
c.Engine().GetAbsWinSize(), "\n",
)
e.DebugPrint(c.Image(),
strings.Join(keyStrs, "\n"))
return nil
}

View file

@ -1,5 +1,7 @@
package gg
import "fmt"
// The type is used to provide
// custom behaviour for drawing and updating etc.
type Context struct {
@ -33,3 +35,15 @@ func (c Context) Events() Events {
return c.events
}
func (c Context) Dprint(v ...any) {
c.Engine().DebugPrint(c.Image(), fmt.Sprint(v...))
}
func (c Context) Dprintln(v ...any) {
c.Engine().DebugPrint(c.Image(), fmt.Sprintln(v...))
}
func (c Context) Dprintf(format string, v ...any) {
c.Engine().DebugPrint(c.Image(), fmt.Sprintf(format, v...))
}

View file

@ -94,7 +94,7 @@ func (e *Engine) GraphicsLibrary() GraphicsLibrary {
}
// Returns currently pressed buttons.
func (e *Engine) MouseButtons() []MouseButton {
func (e *Engine) GetMouseButtons() []MouseButton {
ret := make([]MouseButton, len(e.buttons))
i := 0
for v := range e.buttons {
@ -185,7 +185,7 @@ func (e *Engine) IsButtoned(b MouseButton) bool {
return ok
}
func (e *Engine) Wheel() mx.Vector {
func (e *Engine) GetMouseWheel() mx.Vector {
return e.wheel
}