Spit and polish

* Made the loadscreen useful again (give it work to do async so the game
  doesn't simply freeze during): does a first call to LoadUnloadChunks
  to preload the viewport chunks.
* Hide the mouse cursor when movement keys are pressed.
This commit is contained in:
Noah 2022-05-07 18:54:37 -07:00
parent 450c6b3bb2
commit 434416d3a4
5 changed files with 27 additions and 6 deletions

View File

@ -147,8 +147,10 @@ func Loop(ev *event.State) {
if SceneName == "Play" { if SceneName == "Play" {
// Toggle between GameplayMode and MouseMode. // Toggle between GameplayMode and MouseMode.
if p1mode == GameplayMode { if p1mode == GameplayMode {
shmem.FlashError("Mouse Mode: Left stick moves the cursor.")
p1mode = MouseMode p1mode = MouseMode
} else { } else {
shmem.FlashError("Game Mode: Left stick moves the player.")
p1mode = GameplayMode p1mode = GameplayMode
} }

View File

@ -6,6 +6,7 @@ import (
"git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/balance"
"git.kirsle.net/apps/doodle/pkg/collision" "git.kirsle.net/apps/doodle/pkg/collision"
"git.kirsle.net/apps/doodle/pkg/cursor"
"git.kirsle.net/apps/doodle/pkg/doodads" "git.kirsle.net/apps/doodle/pkg/doodads"
"git.kirsle.net/apps/doodle/pkg/gamepad" "git.kirsle.net/apps/doodle/pkg/gamepad"
"git.kirsle.net/apps/doodle/pkg/keybind" "git.kirsle.net/apps/doodle/pkg/keybind"
@ -17,6 +18,7 @@ import (
"git.kirsle.net/apps/doodle/pkg/physics" "git.kirsle.net/apps/doodle/pkg/physics"
"git.kirsle.net/apps/doodle/pkg/savegame" "git.kirsle.net/apps/doodle/pkg/savegame"
"git.kirsle.net/apps/doodle/pkg/scripting" "git.kirsle.net/apps/doodle/pkg/scripting"
"git.kirsle.net/apps/doodle/pkg/shmem"
"git.kirsle.net/apps/doodle/pkg/sprites" "git.kirsle.net/apps/doodle/pkg/sprites"
"git.kirsle.net/apps/doodle/pkg/uix" "git.kirsle.net/apps/doodle/pkg/uix"
"git.kirsle.net/go/render" "git.kirsle.net/go/render"
@ -43,7 +45,8 @@ type PlayScene struct {
drawing *uix.Canvas drawing *uix.Canvas
scripting *scripting.Supervisor scripting *scripting.Supervisor
running bool running bool
deathBarrier int // Y position of death barrier in case of falling OOB. deathBarrier int // Y position of death barrier in case of falling OOB.
lastCursor render.Point // position of cursor X,Y last tick
// Score variables. // Score variables.
startTime time.Time // wallclock time when level begins startTime time.Time // wallclock time when level begins
@ -282,6 +285,7 @@ func (s *PlayScene) setupAsync(d *Doodle) error {
// images which later get fed directly into SDL2 saving speed at // images which later get fed directly into SDL2 saving speed at
// runtime, + the bitmap generation is pretty wicked fast anyway. // runtime, + the bitmap generation is pretty wicked fast anyway.
loadscreen.PreloadAllChunkBitmaps(s.Level.Chunker) loadscreen.PreloadAllChunkBitmaps(s.Level.Chunker)
s.drawing.LoadUnloadChunks(true)
// Gamepad: put into GameplayMode. // Gamepad: put into GameplayMode.
gamepad.SetMode(gamepad.GameplayMode) gamepad.SetMode(gamepad.GameplayMode)
@ -624,6 +628,9 @@ func (s *PlayScene) GetCheated() bool {
// This is the common handler function between easy methods such as // This is the common handler function between easy methods such as
// BeatLevel, FailLevel, and DieByFire. // BeatLevel, FailLevel, and DieByFire.
func (s *PlayScene) ShowEndLevelModal(success bool, title, message string) { func (s *PlayScene) ShowEndLevelModal(success bool, title, message string) {
// Always restore the cursor.
cursor.Current = cursor.NewPointer(s.d.Engine)
config := modal.ConfigEndLevel{ config := modal.ConfigEndLevel{
Engine: s.d.Engine, Engine: s.d.Engine,
Success: success, Success: success,
@ -758,6 +765,15 @@ func (s *PlayScene) Loop(d *Doodle, ev *event.State) error {
// Touch regions. // Touch regions.
s.LoopTouchable(ev) s.LoopTouchable(ev)
// Hide the mouse cursor if a gameplay input was received.
if keybind.Right(ev) || keybind.Left(ev) || keybind.Up(ev) || keybind.Down(ev) ||
keybind.Use(ev) {
cursor.Current = cursor.NoCursor
} else if s.lastCursor != shmem.Cursor {
cursor.Current = cursor.NewPointer(s.d.Engine)
}
s.lastCursor = shmem.Cursor
s.movePlayer(ev) s.movePlayer(ev)
if err := s.drawing.Loop(ev); err != nil { if err := s.drawing.Loop(ev); err != nil {
log.Error("Drawing loop error: %s", err.Error()) log.Error("Drawing loop error: %s", err.Error())

View File

@ -54,7 +54,7 @@ func (w *Canvas) presentCursor(e render.Engine) {
// Are we editing with a thick brush? // Are we editing with a thick brush?
if w.Tool == drawtool.LineTool || w.Tool == drawtool.RectTool || if w.Tool == drawtool.LineTool || w.Tool == drawtool.RectTool ||
w.Tool == drawtool.PencilTool || w.Tool == drawtool.EllipseTool || w.Tool == drawtool.PencilTool || w.Tool == drawtool.EllipseTool ||
w.Tool == drawtool.EraserTool { w.Tool == drawtool.EraserTool && w.Editable {
// Draw a box where the brush size is. // Draw a box where the brush size is.
if w.BrushSize > 0 { if w.BrushSize > 0 {

View File

@ -17,9 +17,11 @@ import (
LoadUnloadChunks optimizes memory for (level) canvases by warming up chunk images LoadUnloadChunks optimizes memory for (level) canvases by warming up chunk images
that fall within the LoadingViewport and freeing chunks that are outside of it. that fall within the LoadingViewport and freeing chunks that are outside of it.
*/ */
func (w *Canvas) LoadUnloadChunks() { func (w *Canvas) LoadUnloadChunks(force ...bool) {
if w.level == nil || shmem.Tick%balance.CanvasLoadUnloadModuloTicks != 0 || !balance.Feature.LoadUnloadChunk { if !(len(force) > 0 && force[0]) {
return if w.level == nil || shmem.Tick%balance.CanvasLoadUnloadModuloTicks != 0 || !balance.Feature.LoadUnloadChunk || (len(force) > 0 && force[0]) {
return
}
} }
var ( var (

View File

@ -497,11 +497,12 @@ func (c Settings) makeControllerTab(tabFrame *ui.TabFrame, Width, Height int) *u
Value: int(gamepad.NStyle), Value: int(gamepad.NStyle),
}, },
}, },
SelectValue: *c.ControllerStyle, SelectValue: &c.ControllerStyle,
OnSelect: func(v interface{}) { OnSelect: func(v interface{}) {
style, _ := v.(int) style, _ := v.(int)
log.Error("style: %d", style) log.Error("style: %d", style)
gamepad.SetStyle(gamepad.Style(style)) gamepad.SetStyle(gamepad.Style(style))
*c.ControllerStyle = style
saveGameSettings() saveGameSettings()
}, },
}, },