amulet
amulet copied to clipboard
Allow 'am.restart()' from lua in the SDL backend.
Does this kind of change need multiplatform support and documentation in the pull request, or are you happy to add undocumented functions incrementally? Happy to help with the former if so.
What's the use-case for this?
I was implementing some live reload-like-features for shaders on the Lua side. i.e., if a shader's text has changed, then we just reload the world. But perhaps that's the kind of functionality that is better served in the engine.
specifically something like this:
local live_files = {}
local last_check_time = 0
local CHECK_INTERVAL_SECS = 0.3
local function check_live_files()
for filename, contents in pairs(live_files) do
local f = io.open(filename, "r")
if f == nil then
log("could not open live file " .. filename)
elseif f:read("*all") ~= contents then
log("reloading because file changed: " .. filename)
am.restart()
end
end
end
Why not just hit F5 after making a change though? Loading all files each frame is probably not going to be great for performance.
I have it doing the actual file check every 2 seconds or something.
Basically my point is, being able to hack together a live-reload harness type thing from Lua is made possible by providing an am.restart() func.
I still don't understand what's the issue with just pressing F5. To me this is preferable to since you can then control when the game restarts.