From 391171da87b06a0c22afffe5b42d2d60aa890cbe Mon Sep 17 00:00:00 2001 From: Alan Hardman Date: Wed, 19 Feb 2025 00:06:40 -0700 Subject: [PATCH 1/2] Update old TransitionType references --- .docs/modules/Noble.html | 5 ++--- Noble.lua | 2 +- README.md | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.docs/modules/Noble.html b/.docs/modules/Noble.html index 06d3394..43474a9 100644 --- a/.docs/modules/Noble.html +++ b/.docs/modules/Noble.html @@ -260,7 +260,7 @@

See

- transition(NewScene[, __duration=1.5[, __transition=Noble.TransitionType.DIP_TO_BLACK[, __transitionProperties={}[, __sceneProperties={}]]]]) + transition(NewScene[, __duration=1.5[, __transition=Noble.Transition.DipToBlack[, __transitionProperties={}[, __sceneProperties={}]]]])
Transition to a new scene (at the end of this frame). @@ -282,7 +282,7 @@

Parameters

  • __transition Noble.Transition - = Noble.TransitionType.DIP_TO_BLACK (default) + = Noble.Transition.DipToBlack (default)
    If a transition duration is set, use this transition type. If not set, it will use the value of configuration.defaultTransition.
  • @@ -495,4 +495,3 @@

    Fields

    - diff --git a/Noble.lua b/Noble.lua index 9f69600..bd1c4b3 100644 --- a/Noble.lua +++ b/Noble.lua @@ -209,7 +209,7 @@ local queuedScene = nil --- Additional calls to this method within the same frame (before the already-called transition begins), will override previous calls. Any calls to this method once a transition begins will be ignored until the transition completes. -- @tparam NobleScene NewScene The scene to transition to. Pass the scene's class, not an instance of the scene. You always transition from `Noble.currentScene` -- @number[opt=1.5] __duration The length of the transition, in seconds. --- @tparam[opt=Noble.TransitionType.DIP_TO_BLACK] Noble.Transition __transition If a transition duration is set, use this transition type. If not set, it will use the value of `configuration.defaultTransition`. +-- @tparam[opt=Noble.Transition.DipToBlack] Noble.Transition __transition If a transition duration is set, use this transition type. If not set, it will use the value of `configuration.defaultTransition`. -- @tparam[opt={}] table __transitionProperties A table consisting of properties for this transition. Properties not set here will use values that transition's `defaultProperties` table. -- @tparam[opt={}] table __sceneProperties A table consisting of user-defined properties which are passed into and handled by the new scene's init() method. -- @usage diff --git a/README.md b/README.md index 2cc94bd..06589d6 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ In general, Lua best-practices are followed, but in some cases code style and na - Methods and variables are **camelCase**. - “Class” names are **TitleCase**, and Lua “modules” are treated as nested classes, thus `Noble.Text` instead of `noble.text`. -- Constants, such as `Noble.TransitionType.DIP_TO_BLACK`, are **ALL_CAPS_SNAKE_CASE** +- Constants, such as `Noble.Transition.Type.CUT`, are **ALL_CAPS_SNAKE_CASE** - Argument names are prefixed with a **double-underscore**, as in `__displayName`. This mostly impacts documentation legibility. I’m very sorry but it couldn’t be helped. 😆 - Names are verbose by default; no abbreviations. This includes aliases for Playdate packages, so `playdate.graphics` is aliased as `Graphics`, instead of `gfx`. -Some of these conventions run counter to those seen in the Playdate SDK. In places where there’s a potential conflict, either an alias is created for Noble Engine’s version to match the engine’s code style, or the Playdate SDK item is given preference and Noble Engine stays out of its way. \ No newline at end of file +Some of these conventions run counter to those seen in the Playdate SDK. In places where there’s a potential conflict, either an alias is created for Noble Engine’s version to match the engine’s code style, or the Playdate SDK item is given preference and Noble Engine stays out of its way. From 9e02b9dd0ca371b029aaf65f75e9f6af0f2c4fdf Mon Sep 17 00:00:00 2001 From: Alan Hardman Date: Sat, 12 Apr 2025 18:07:33 -0600 Subject: [PATCH 2/2] Optimize transitions with tiled dithers Uses mask image for CrossDissolve, and adds a new DipTile that draws a tiled dither pattern rather than a full-screen dither. Updates DipToBlack and DipToWhite to use DipTile. For DipTile the max frame rate on hardware improves by 68%, and for CrossDissolve by 59%. Both are noticeably smoother when running games at the SDK default of 30 FPS, and no longer drop below that frame rate unless other expensive computation is happening during the transition. Tested on launch hardware (PDU-Y-01). --- modules/Noble.Transition.lua | 1 + modules/Noble.Transition/CrossDissolve.lua | 10 +++++- modules/Noble.Transition/DipTile.lua | 38 ++++++++++++++++++++++ modules/Noble.Transition/DipToBlack.lua | 6 ++-- modules/Noble.Transition/DipToWhite.lua | 6 ++-- 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 modules/Noble.Transition/DipTile.lua diff --git a/modules/Noble.Transition.lua b/modules/Noble.Transition.lua index d51b574..29fec07 100644 --- a/modules/Noble.Transition.lua +++ b/modules/Noble.Transition.lua @@ -205,6 +205,7 @@ import 'libraries/noble/modules/Noble.Transition/Cut.lua' -- import 'libraries/noble/modules/Noble.Transition/CrossDissolve.lua' import 'libraries/noble/modules/Noble.Transition/Dip.lua' +import 'libraries/noble/modules/Noble.Transition/DipTile.lua' import 'libraries/noble/modules/Noble.Transition/DipToBlack.lua' import 'libraries/noble/modules/Noble.Transition/DipToWhite.lua' -- diff --git a/modules/Noble.Transition/CrossDissolve.lua b/modules/Noble.Transition/CrossDissolve.lua index 69f1f10..f3ac779 100644 --- a/modules/Noble.Transition/CrossDissolve.lua +++ b/modules/Noble.Transition/CrossDissolve.lua @@ -17,10 +17,18 @@ transition.defaultProperties = { dither = Graphics.image.kDitherTypeBayer4x4 } +transition.tilePattern = Graphics.image.new(8, 8, Graphics.kColorBlack) + function transition:setProperties(__properties) self.dither = __properties.dither or self.defaultProperties.dither + self.oldSceneScreenshot:addMask(true) end function transition:draw() - self.oldSceneScreenshot:drawFaded(0, 0, 1 - self.sequence:get(), self.dither) + self.oldSceneScreenshot:clearMask(1) + Graphics.lockFocus(self.oldSceneScreenshot:getMaskImage()) + self.tilePattern:fadedImage(self.sequence:get(), self.dither) + :drawTiled(0, 0, 400, 240) + Graphics.unlockFocus() + self.oldSceneScreenshot:draw(0, 0) end \ No newline at end of file diff --git a/modules/Noble.Transition/DipTile.lua b/modules/Noble.Transition/DipTile.lua new file mode 100644 index 0000000..e013ae8 --- /dev/null +++ b/modules/Noble.Transition/DipTile.lua @@ -0,0 +1,38 @@ +--- +-- @submodule Noble.Transition + +class("DipTile", nil, Noble.Transition).extends(Noble.Transition) +local transition = Noble.Transition.DipTile +transition.name = "DipTile" + +-- Type +transition._type = Noble.Transition.Type.COVER + +--- Fade to a tiled color, then to the next scene. +-- @table Noble.Transition.Dip.defaultProperties +-- @number[opt=0.25] holdTime +-- @tparam Graphics.image tilePattern +-- @tparam[opt=Graphics.image.kDitherTypeBayer4x4] Graphics.image.kDither dither +-- @tparam[opt=Ease.outInQuad] Ease ease +-- @number[opt=0] x +-- @number[opt=0] y +transition.defaultProperties = { + holdTime = 0.25, + ease = Ease.outInQuad, + dither = Graphics.image.kDitherTypeBayer4x4, + tilePattern = nil, + x = 0, + y = 0 +} + +function transition:setProperties(__arguments) + self.dither = __arguments.dither or self.defaultProperties.dither + self.tilePattern = __arguments.tilePattern or self.defaultProperties.tilePattern + self.x = __arguments.x or self.defaultProperties.x + self.y = __arguments.y or self.defaultProperties.y +end + +function transition:draw() + self.tilePattern:fadedImage(self.sequence:get(), self.dither) + :drawTiled(self.x, self.y, 400, 240) +end \ No newline at end of file diff --git a/modules/Noble.Transition/DipToBlack.lua b/modules/Noble.Transition/DipToBlack.lua index e5c5f50..1f6795a 100644 --- a/modules/Noble.Transition/DipToBlack.lua +++ b/modules/Noble.Transition/DipToBlack.lua @@ -1,16 +1,16 @@ --- -- @submodule Noble.Transition -class("DipToBlack", nil, Noble.Transition).extends(Noble.Transition.Dip) +class("DipToBlack", nil, Noble.Transition).extends(Noble.Transition.DipTile) local transition = Noble.Transition.DipToBlack transition.name = "Dip to Black" --- Fade to black, then to the next scene. --- NOTE: The `panelImage` property is locked. +-- NOTE: The `tilePattern` property is locked. -- @see Noble.Transition.Dip.defaultProperties -- @table Noble.Transition.DipToBlack.defaultProperties -transition.panelImage = Graphics.image.new(400, 240, Graphics.kColorBlack) +transition.tilePattern = Graphics.image.new(8, 8, Graphics.kColorBlack) function transition:setCustomArguments(__arguments) transition.super.setCustomArguments(self, __arguments) diff --git a/modules/Noble.Transition/DipToWhite.lua b/modules/Noble.Transition/DipToWhite.lua index 23e2227..5685bf6 100644 --- a/modules/Noble.Transition/DipToWhite.lua +++ b/modules/Noble.Transition/DipToWhite.lua @@ -1,16 +1,16 @@ --- -- @submodule Noble.Transition -class("DipToWhite", nil, Noble.Transition).extends(Noble.Transition.Dip) +class("DipToWhite", nil, Noble.Transition).extends(Noble.Transition.DipTile) local transition = Noble.Transition.DipToWhite transition.name = "Dip to White" --- Fade to white, then to the next scene. --- NOTE: The `panelImage` property is locked. +-- NOTE: The `tilePattern` property is locked. -- @see Noble.Transition.Dip.defaultProperties -- @table Noble.Transition.DipToWhite.defaultProperties -transition.panelImage = Graphics.image.new(400, 240, Graphics.kColorWhite) +transition.tilePattern = Graphics.image.new(8, 8, Graphics.kColorWhite) function transition:setCustomArguments(__arguments) transition.super.setCustomArguments(self, __arguments)