From d694fcc7c25adebd36c0aa9012f43222766da584 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 9 Apr 2022 18:21:26 -0700 Subject: [PATCH] Fix climbing on the right bug + eager-render boolprop * New boolProp to help debug memory issues: eager-render, set it to false and the loadscreen will not eagerload Go images for all the level chunks. * Finally fix the level collision bug where the player could climb walls to the right. --- pkg/balance/boolprops.go | 4 ++++ pkg/balance/numbers.go | 8 ++++++++ pkg/collision/collide_level.go | 8 ++++++-- pkg/modal/loadscreen/loadscreen.go | 10 +++++++--- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pkg/balance/boolprops.go b/pkg/balance/boolprops.go index e278717..fa0552f 100644 --- a/pkg/balance/boolprops.go +++ b/pkg/balance/boolprops.go @@ -45,6 +45,10 @@ var Boolprops = map[string]Boolprop{ Get: func() bool { return CompressDrawings }, Set: func(v bool) { CompressDrawings = v }, }, + "eager-render": { + Get: func() bool { return EagerRenderLevelChunks }, + Set: func(v bool) { EagerRenderLevelChunks = v }, + }, } // GetBoolProp reads the current value of a boolProp. diff --git a/pkg/balance/numbers.go b/pkg/balance/numbers.go index cfbbead..3ceceaa 100644 --- a/pkg/balance/numbers.go +++ b/pkg/balance/numbers.go @@ -105,6 +105,14 @@ var ( // Limits on the Flood Fill tool so it doesn't run away on us. FloodToolVoidLimit = 600 // If clicking the void, +- 1000 px limit FloodToolLimit = 1200 // If clicking a valid color on the level + + // Eager render level chunks to images during the load screen. + // Originally chunks rendered to image and SDL texture on-demand, the loadscreen was + // added to eager load (to image) the whole entire level at once (SDL textures were + // still on demand, as they scroll into screen). Control this in-game with + // `boolProp eager-render false` and the loadscreen will go quicker cuz it won't + // load the whole entire level. Maybe useful to explore memory issues. + EagerRenderLevelChunks = true ) // Edit Mode Values diff --git a/pkg/collision/collide_level.go b/pkg/collision/collide_level.go index 1e240b7..33d7ae0 100644 --- a/pkg/collision/collide_level.go +++ b/pkg/collision/collide_level.go @@ -55,8 +55,8 @@ The `target` is the point the actor wants to move to on this tick. */ func CollidesWithGrid(d Actor, grid *level.Chunker, target render.Point) (*Collide, bool) { var ( - P = d.Position() - S = d.Size() + P = d.Position() + S = d.Size() hitbox = d.Hitbox() result = &Collide{ @@ -162,6 +162,10 @@ func CollidesWithGrid(d Actor, grid *level.Chunker, target render.Point) (*Colli // left wall sometimes, but breaks walking up leftward slopes. point.X = capLeft } + if capRight != 0 && point.X > capRight { + // This if check fixes the climbing-walls-on-the-right bug. + point.X = capRight + } if has := result.ScanBoundingBox(render.Rect{ X: point.X, diff --git a/pkg/modal/loadscreen/loadscreen.go b/pkg/modal/loadscreen/loadscreen.go index 7ac1676..5accb18 100644 --- a/pkg/modal/loadscreen/loadscreen.go +++ b/pkg/modal/loadscreen/loadscreen.go @@ -7,6 +7,7 @@ import ( "git.kirsle.net/apps/doodle/pkg/balance" "git.kirsle.net/apps/doodle/pkg/level" + "git.kirsle.net/apps/doodle/pkg/log" "git.kirsle.net/apps/doodle/pkg/shmem" "git.kirsle.net/apps/doodle/pkg/uix" "git.kirsle.net/go/render" @@ -225,9 +226,12 @@ func Loop(windowSize render.Rect, e render.Engine) { // of chunks vs. chunks remaining to pre-cache bitmaps from. func PreloadAllChunkBitmaps(chunker *level.Chunker) { loadChunksTarget := len(chunker.Chunks) - // if loadChunksTarget == 0 { - // return - // } + + // Skipping the eager rendering of chunks? + if !balance.EagerRenderLevelChunks { + log.Info("PreloadAllChunkBitmaps: skipping eager render") + return + } for { remaining := chunker.PrerenderN(10)