Skip to content

Add debug callbacks - #54

Open
GammaGames wants to merge 1 commit into
NobleRobot:mainfrom
GammaGames:debug
Open

Add debug callbacks#54
GammaGames wants to merge 1 commit into
NobleRobot:mainfrom
GammaGames:debug

Conversation

@GammaGames

Copy link
Copy Markdown
Contributor

Fixes #53

Is playdate.debugDraw called on hardware? I don't have a devices so I can't test

@Mark-LaCroix

Copy link
Copy Markdown
Member

This is good. I'll have to run some tests before pulling, just to be sure there's no overhead, or it's worth it even if there is. It might be a bit before I do another sprint, though. Happy to hear from others if they want to take a crack at seeing how this runs/works on device.

@GammaGames

Copy link
Copy Markdown
Contributor Author

If there is overhead you could always check pd.isSimulator before enabling the callback

@Mark-LaCroix Mark-LaCroix added the enhancement New feature or request label Jun 2, 2024
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
…stream PR NobleRobot#54, adapted)

Scenes now get a drawDebug() callback, a debugColor property, and
enableDebug()/disableDebug() methods. Debug drawing is enabled on scene
enter and disabled on scene exit, and is guarded by playdate.isSimulator
so there is no overhead on hardware, where playdate.debugDraw is not
rendered anyway.

Adapted from upstream PR NobleRobot#54 (fixes upstream issue NobleRobot#53) with corrections:
debugColor defaults to a {r, g, b, a} table (the PR's Graphics.kColorWhite
default crashed table.unpack), disableDebug() sets playdate.debugDraw to
nil instead of an empty function so the runtime skips the call, and it no
longer resets Noble.showFPS on scene exit.

Co-authored-by: GammaGames <GammaGames@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
Hand-patch the LDoc-generated HTML (as done in d781092 for
NobleSprite.html) to cover changes the earlier commits missed:

- Noble.html: add the missing sidebar index entry for
  Noble.performTransition (the body entry was added in 50be77b, but
  the function was undiscoverable from the nav).
- Noble.GameData.html: add sidebar and body entries for
  resetFromDisk() and resetAllFromDisk() (added in 7aa010a,
  upstream PR NobleRobot#85).
- Noble.Transition.html: replace the stale "panelImage property is
  locked" notes for DipToBlack/DipToWhite with tilePattern and point
  their See references at DipTile; add the new DipTile submodule and
  its defaultProperties table (47f83cf, upstream PR NobleRobot#92); document the
  per-invocation callback properties on the onStart/onMidpoint/
  onHoldTimeElapsed/onComplete entries (50be77b).
- NobleScene.html: add the debugColor property, enableDebug/
  disableDebug methods, and drawDebug callback (b587cd8, upstream
  PR NobleRobot#54), plus the gameWillTerminate/deviceWillSleep/deviceWillLock/
  deviceDidUnlock callbacks (b034f38, upstream issue NobleRobot#55).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
…stream PR NobleRobot#54, adapted)

Scenes now get a drawDebug() callback, a debugColor property, and
enableDebug()/disableDebug() methods. Debug drawing is enabled on scene
enter and disabled on scene exit, and is guarded by playdate.isSimulator
so there is no overhead on hardware, where playdate.debugDraw is not
rendered anyway.

Adapted from upstream PR NobleRobot#54 (fixes upstream issue NobleRobot#53) with corrections:
debugColor defaults to a {r, g, b, a} table (the PR's Graphics.kColorWhite
default crashed table.unpack), disableDebug() sets playdate.debugDraw to
nil instead of an empty function so the runtime skips the call, and it no
longer resets Noble.showFPS on scene exit.

Co-authored-by: GammaGames <GammaGames@users.noreply.github.com>
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
Hand-patch the LDoc-generated HTML (as done in d781092 for
NobleSprite.html) to cover changes the earlier commits missed:

- Noble.html: add the missing sidebar index entry for
  Noble.performTransition (the body entry was added in 50be77b, but
  the function was undiscoverable from the nav).
- Noble.GameData.html: add sidebar and body entries for
  resetFromDisk() and resetAllFromDisk() (added in 7aa010a,
  upstream PR NobleRobot#85).
- Noble.Transition.html: replace the stale "panelImage property is
  locked" notes for DipToBlack/DipToWhite with tilePattern and point
  their See references at DipTile; add the new DipTile submodule and
  its defaultProperties table (47f83cf, upstream PR NobleRobot#92); document the
  per-invocation callback properties on the onStart/onMidpoint/
  onHoldTimeElapsed/onComplete entries (50be77b).
- NobleScene.html: add the debugColor property, enableDebug/
  disableDebug methods, and drawDebug callback (b587cd8, upstream
  PR NobleRobot#54), plus the gameWillTerminate/deviceWillSleep/deviceWillLock/
  deviceDidUnlock callbacks (b034f38, upstream issue NobleRobot#55).
@ericlewis

Copy link
Copy Markdown

I integrated this into my local tree (it's a great feature — fixes #53) and hit a couple of issues worth flagging:

  1. The debugColor default crashes on scene enter. Graphics.kColorWhite is a number constant, but enter() calls playdate.setDebugDrawColor(table.unpack(self.debugColor)), so any scene that doesn't override debugColor with a table crashes as soon as it enters. A {r, g, b, a} table default (e.g. {1, 0, 0, 1}) matches what setDebugDrawColor() expects.

  2. disableDebug() resets Noble.showFPS. Setting Noble.showFPS = false on every scene exit silently turns off the FPS display for games that enabled it, which feels like an unrelated side effect — probably better to leave showFPS alone.

  3. Re: the overhead question above — gating on playdate.isSimulator (as @GammaGames suggested) works nicely, since playdate.debugDraw() isn't rendered on hardware anyway. Setting playdate.debugDraw = nil in disableDebug() (instead of an empty function) also lets the runtime skip the call entirely.

FWIW, here's the shape I ended up with locally:

NobleScene.debugColor = {1, 0, 0, 1}

function NobleScene:enableDebug()
	if (playdate.isSimulator) then
		playdate.setDebugDrawColor(table.unpack(self.debugColor))
		playdate.debugDraw = function()
			self:drawDebug()
		end
	end
end

function NobleScene:disableDebug()
	playdate.debugDraw = nil
end

with enter() calling self:enableDebug() and exit() calling self:disableDebug() as in this PR. Happy to share the full diff if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for debugDraw in scenes

3 participants