mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-15 07:41:21 +02:00
Merge pull request #1242 from AverageConsumer/codex/final-frame-output-hooks
This commit is contained in:
@@ -435,7 +435,8 @@ local GEN2_HOOKS = {
|
||||
-- pointer with the touch overlay given first refusal, the palette zone list
|
||||
-- handed to the present pass, the letterbox and the HUD rect.
|
||||
"input.step", "input.pointer",
|
||||
"render.zones", "render.compose", "render.letterbox", "render.hud",
|
||||
"render.zones", "render.compose", "render.output_enabled", "render.output",
|
||||
"render.letterbox", "render.hud",
|
||||
}
|
||||
|
||||
local function assertShared(name, sites, kind)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package.path = "./?.lua;./?/init.lua;" .. package.path
|
||||
|
||||
local T = require("tests.modkit")
|
||||
local Game2 = require("src.core.Game2")
|
||||
local Runtime = require("src.mods.Runtime")
|
||||
local Hooks = require("src.mods.Hooks")
|
||||
|
||||
local savedHooks = Runtime.hooks
|
||||
local hooks = Hooks.new()
|
||||
Runtime.hooks = hooks
|
||||
|
||||
local received
|
||||
hooks:wrap("render.output", function(_, context)
|
||||
received = context
|
||||
return true
|
||||
end, 0, "test")
|
||||
hooks:wrap("render.output_enabled", function() return false end, 0, "test")
|
||||
|
||||
local canvas = love.graphics.newCanvas(640, 480)
|
||||
local presentCalls = 0
|
||||
local game = setmetatable({
|
||||
frameFit = function() return 3, 80, 24, 1, 480, 432 end,
|
||||
presentCanvas = function() presentCalls = presentCalls + 1 return canvas end,
|
||||
drawScene = function() end,
|
||||
drawHud = function() end,
|
||||
}, Game2)
|
||||
|
||||
Game2.draw(game)
|
||||
T.eq(received, nil, "a disabled Gold output hook does not run")
|
||||
T.eq(presentCalls, 0, "a disabled Gold output hook keeps the direct path")
|
||||
|
||||
hooks:wrap("render.output_enabled", function() return true end, 10, "test")
|
||||
Game2.draw(game)
|
||||
T.check(received ~= nil, "Gold raises render.output for an enabled subscriber")
|
||||
T.eq(received and received.canvas, canvas,
|
||||
"Gold hands render.output the finished present canvas")
|
||||
T.eq(received and received.generation, 2,
|
||||
"Gold identifies the output context without changing Gen 1")
|
||||
T.eq(received and received.gameX, 80, "Gold output carries the fitted game X")
|
||||
T.eq(received and received.gameY, 24, "Gold output carries the fitted game Y")
|
||||
T.eq(received and received.gameWidth, 480,
|
||||
"Gold output carries the fitted game width")
|
||||
T.eq(received and received.gameHeight, 432,
|
||||
"Gold output carries the fitted game height")
|
||||
|
||||
Runtime.hooks = savedHooks
|
||||
T.finish("gen2 render output seam")
|
||||
@@ -987,6 +987,33 @@ check(fallback.style == "doublecircle",
|
||||
"a hook naming an unregistered style falls back to the vanilla bits")
|
||||
Runtime.install(Events.new(), Hooks.new(), {})
|
||||
|
||||
-- ------- gated final-output ownership
|
||||
|
||||
local outputHooks = Hooks.new()
|
||||
Runtime.install(Events.new(), outputHooks, {})
|
||||
local outputCalls, outputContext = 0, nil
|
||||
outputHooks:wrap("render.output", function(nextLink, context)
|
||||
outputCalls, outputContext = outputCalls + 1, context
|
||||
return true
|
||||
end, 0, "test")
|
||||
outputHooks:wrap("render.output_enabled", function() return false end, 0, "test")
|
||||
Renderer:init()
|
||||
Renderer.presentCanvas = nil
|
||||
Renderer:beginFrame(false)
|
||||
Renderer:endFrame(nil, nil)
|
||||
check(outputCalls == 0 and Renderer.presentCanvas == nil,
|
||||
"a disabled output hook leaves the direct render path untouched")
|
||||
|
||||
outputHooks:wrap("render.output_enabled", function() return true end, 10, "test")
|
||||
Renderer:init()
|
||||
Renderer.presentCanvas = nil
|
||||
Renderer:beginFrame(false)
|
||||
Renderer:endFrame(nil, nil)
|
||||
check(outputCalls == 1 and outputContext and outputContext.canvas,
|
||||
"an enabled output hook receives the finished frame")
|
||||
check(outputContext and outputContext.generation == 1,
|
||||
"the output context identifies the active generation")
|
||||
|
||||
-- ------- asset transforms
|
||||
|
||||
local function seedTransform(id, source)
|
||||
|
||||
Reference in New Issue
Block a user