Noah Petherbridge
6def8f7625
* Fix collision detection to allow actors to walk up slopes smoothly, without losing any horizontal velocity. * Fix scrolling a level canvas so that chunks near the right or bottom edge of the viewpoint were getting culled prematurely. * Centralize JavaScript exception catching logic to attach Go and JS stack traces where possible to be more useful for debugging. * Performance: flush all SDL2 textures from memory between scene transitions in the app. Also add a `flush-textures` dev console command to flush the textures at any time - they all should regenerate if still needed based on underlying go.Images which can be garbage collected.
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package doodle
|
|
|
|
import (
|
|
"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/scripting/exceptions"
|
|
"git.kirsle.net/go/render/event"
|
|
)
|
|
|
|
// Scene is an abstraction for a game mode in Doodle. The app points to one
|
|
// scene at a time and that scene has control over the main loop, and its own
|
|
// state information.
|
|
type Scene interface {
|
|
Name() string
|
|
Setup(*Doodle) error
|
|
Destroy() error
|
|
|
|
// Loop should update the scene's state but not draw anything.
|
|
Loop(*Doodle, *event.State) error
|
|
|
|
// Draw should use the scene's state to figure out what pixels need
|
|
// to draw to the screen.
|
|
Draw(*Doodle) error
|
|
}
|
|
|
|
// Goto a scene. First it unloads the current scene.
|
|
func (d *Doodle) Goto(scene Scene) error {
|
|
// Inform the gamepad controller what scene.
|
|
gamepad.SceneName = scene.Name()
|
|
|
|
// Clear any debug labels.
|
|
customDebugLabels = []debugLabel{}
|
|
|
|
// Teardown existing scene.
|
|
if d.Scene != nil {
|
|
d.Scene.Destroy()
|
|
}
|
|
|
|
// Teardown exceptions modal (singleton windows so it can clean up).
|
|
exceptions.Teardown()
|
|
|
|
// Flush all SDL2 textures between scenes.
|
|
native.FreeTextures(d.Engine)
|
|
|
|
log.Info("Goto Scene: %s", scene.Name())
|
|
d.Scene = scene
|
|
return d.Scene.Setup(d)
|
|
}
|