amulet icon indicating copy to clipboard operation
amulet copied to clipboard

Allow 'am.restart()' from lua in the SDL backend.

Open kevinw opened this issue 4 years ago • 6 comments

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.

kevinw avatar Feb 27 '20 17:02 kevinw

What's the use-case for this?

ianmaclarty avatar Feb 27 '20 23:02 ianmaclarty

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.

kevinw avatar Mar 02 '20 21:03 kevinw

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

kevinw avatar Mar 10 '20 15:03 kevinw

Why not just hit F5 after making a change though? Loading all files each frame is probably not going to be great for performance.

ianmaclarty avatar Mar 10 '20 21:03 ianmaclarty

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.

kevinw avatar Mar 24 '20 18:03 kevinw

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.

ianmaclarty avatar Mar 24 '20 22:03 ianmaclarty