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() { for _, key := range c.Engine().GetKeyboardKeys() {
switch key { switch key {
case gg.KeyF: 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: 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 "surdeus.su/core/gg/mx"
import ( import (
"strings" //"strings"
"fmt" //"fmt"
) )
type Debug struct { type Debug struct {
@ -34,82 +34,40 @@ func (d *Debug) Draw(c Context) *gg.Drawing {
e := c.Engine() e := c.Engine()
relTri := tri.Rel() relTri := tri.Rel()
relPlayer := player.Rel() relPlayer := player.Rel()
keys := c.Engine().GetKeyboardKeys()
keyStrs := []string{} c.Dprint(
keyStrs = append(keyStrs, fmt.Sprintf( "counter = ", counter, "\n",
"counter: %d", counter, "tps = ", int(c.Engine().TPS()), "\n",
)) "fps = ", int(c.Engine().FPS()), "\n",
keyStrs = append(keyStrs, fmt.Sprintf( "dframe = ", int(c.Engine().Dframe()), "\n",
"tps: %d", int(c.Engine().TPS()), "frame = ", int(c.Engine().Frame()), "\n",
)) "relPlayerPos = ", relPlayer.GetPosition(), "\n",
keyStrs = append(keyStrs, fmt.Sprintf( "absPlayerPos = ", player.GetPosition(), "\n",
"fps: %d", int(c.Engine().FPS()), "relTriPos = ", relTri.GetPosition(), "\n",
)) "absTriPos = ", tri.GetPosition(), "\n",
keyStrs = append(keyStrs, fmt.Sprintf( "absTriRot = " , mx.Degree(tri.GetRotation()), "\n",
"dframe: %d", int(c.Engine().Dframe()), "keys = ", keys, "\n",
))
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(),
))
keyStrs = append(keyStrs, fmt.Sprintf( "GetMouseButtons(...) = ",
"relTriPos: %v", relTri.GetPosition(), c.Engine().GetMouseButtons(), "\n",
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriPos: %v", tri.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
"absTriRot: %v", mx.Degree(tri.GetRotation()),
))
keys := []string{} "GetMouseWheel(...) = ", "\n",
for _, k := range e.GetKeyboardKeys() { c.Engine().GetMouseWheel(), "\n",
keys = append(keys, k.String())
}
keyStrs = append(keyStrs, fmt.Sprintf(
"keys: %s", strings.Join(keys, ", "),
))
keyStrs = append(keyStrs, fmt.Sprintf( "camera.GetPosition(...) = ",
"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().X, camera.GetPosition().X,
camera.GetPosition().Y, camera.GetPosition().Y, "\n",
))
keyStrs = append(keyStrs, fmt.Sprintf(
"realCursorPos: %v", e.GetRealCursorPosition()))
keyStrs = append(keyStrs, fmt.Sprintf(
"absCursorPos: %v", e.GetAbsCursorPosition() ))
keyStrs = append(keyStrs, "GetRealCursorPosition(...) = ",
fmt.Sprintf( e.GetRealCursorPosition(), "\n",
"absWinSize: %v",
c.Engine().GetAbsWinSize(), "GetAbsCursorPos(...) = ",
), e.GetAbsCursorPosition(), "\n",
"GetAbsWinSize(...) = ",
c.Engine().GetAbsWinSize(), "\n",
) )
e.DebugPrint(c.Image(),
strings.Join(keyStrs, "\n"))
return nil return nil
} }

View file

@ -1,5 +1,7 @@
package gg package gg
import "fmt"
// The type is used to provide // The type is used to provide
// custom behaviour for drawing and updating etc. // custom behaviour for drawing and updating etc.
type Context struct { type Context struct {
@ -33,3 +35,15 @@ func (c Context) Events() Events {
return c.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. // Returns currently pressed buttons.
func (e *Engine) MouseButtons() []MouseButton { func (e *Engine) GetMouseButtons() []MouseButton {
ret := make([]MouseButton, len(e.buttons)) ret := make([]MouseButton, len(e.buttons))
i := 0 i := 0
for v := range e.buttons { for v := range e.buttons {
@ -185,7 +185,7 @@ func (e *Engine) IsButtoned(b MouseButton) bool {
return ok return ok
} }
func (e *Engine) Wheel() mx.Vector { func (e *Engine) GetMouseWheel() mx.Vector {
return e.wheel return e.wheel
} }