Code cleanup for TouchScreenMode
This commit is contained in:
parent
b8665c8b8d
commit
21847f5e57
|
@ -44,6 +44,11 @@ Some minor changes:
|
|||
* The game window maximizes on startup to fill the screen.
|
||||
* Fixed a few places where the old "Load Level" menu was being called instead
|
||||
of the fancy new one with the listbox.
|
||||
* Fixed a touch screen detection bug that was causing the mouse cursor to hide
|
||||
on Macbooks when using their touchpad.
|
||||
* Add a `--touch` command line flag to the game binary, which forces touch screen
|
||||
mode to always be on (which hides the mouse cursor), in case of touch screen
|
||||
detection errors or annoyances.
|
||||
|
||||
Some code cleanup and architecture changes:
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"git.kirsle.net/SketchyMaze/doodle/pkg/chatbot"
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/gamepad"
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/native"
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/plus/bootstrap"
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/plus/dpp"
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/shmem"
|
||||
|
@ -101,6 +102,11 @@ func main() {
|
|||
Aliases: []string{"w"},
|
||||
Usage: "set the window size (e.g. -w 1024x768) or special value: desktop, mobile, landscape, maximized",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "touch",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "force TouchScreenMode to be on at all times, which hides the mouse cursor",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "guitest",
|
||||
Usage: "enter the GUI Test scene on startup",
|
||||
|
@ -167,10 +173,9 @@ func main() {
|
|||
balance.FeaturesOn()
|
||||
}
|
||||
|
||||
// Offline mode?
|
||||
if c.Bool("offline") {
|
||||
shmem.OfflineMode = true
|
||||
}
|
||||
// Set other program flags.
|
||||
shmem.OfflineMode = c.Bool("offline")
|
||||
native.ForceTouchScreenModeAlwaysOn = c.Bool("touch")
|
||||
|
||||
// SDL engine.
|
||||
engine := sdl.New(
|
||||
|
|
|
@ -31,6 +31,10 @@ var (
|
|||
Y: 60,
|
||||
}
|
||||
|
||||
// Threshold of how many ticks should pass between the last Fingers Up
|
||||
// event and a mouse movement, to indicate that TouchScreenMode should end.
|
||||
TouchScreenModeLastFingerDownTicks uint64 = 10
|
||||
|
||||
// Player speeds, gravity and movement physics.
|
||||
PlayerMaxVelocity float64 = 7
|
||||
PlayerJumpVelocity float64 = -15
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package native
|
||||
|
||||
import (
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/balance"
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
|
||||
"git.kirsle.net/SketchyMaze/doodle/pkg/shmem"
|
||||
"git.kirsle.net/go/render/event"
|
||||
|
@ -9,13 +10,16 @@ import (
|
|||
// Common code to handle basic touch screen detection.
|
||||
|
||||
var (
|
||||
// Force the TouchScreenMode to always be enabled.
|
||||
ForceTouchScreenModeAlwaysOn bool
|
||||
|
||||
isTouchScreenMode bool
|
||||
lastFingerDownTick uint64
|
||||
)
|
||||
|
||||
// IsTouchScreenMode is activated when the user has touched the screen, and false when the mouse is moved.
|
||||
func IsTouchScreenMode() bool {
|
||||
return isTouchScreenMode
|
||||
return ForceTouchScreenModeAlwaysOn || isTouchScreenMode
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -51,7 +55,7 @@ func UpdateTouchScreenMode(ev *event.State) {
|
|||
|
||||
// If we have registered a mouse event a few ticks after the finger was
|
||||
// removed, it is a real mouse cursor and we exit touch screen mode.
|
||||
if ev.IsMouseEvent && shmem.Tick-lastFingerDownTick > 5 {
|
||||
if ev.IsMouseEvent && shmem.Tick-lastFingerDownTick > balance.TouchScreenModeLastFingerDownTicks {
|
||||
log.Info("TouchScreenMode OFF")
|
||||
isTouchScreenMode = false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user