Page 5 of 5

Re: Hot *restart* plugin that actually works? Feasible.

Posted: Sun Jan 28, 2018 5:46 pm
by zorg
pgimeno wrote: Sun Jan 28, 2018 5:00 pm I'm wondering if it's possible to call love.event.quit("restart") from a thread. The docs don't mention this, but I don't see why not. So, you could have a dedicated thread monitoring your filesystem. Perhaps even interfacing to a file modification monitor library via FFI if available.

The only problem I see with this way of restarting is that while hot restarting, you should ensure that your program returns false in the love.quit() event if you define it. That's where it may interfere with some workflows and require manual intervention. Maybe Löve could incorporate love.event.quit("forcerestart") to ignore the result of love.quit(), but I'm not sure that's wise. It would be best if Löve was also changed to make love.quit() receive a force parameter that is true if it will ignore the return value and quit straight away.
Probably depends whether love.event.quit('restart') only kills off the active thread's lua state, the main one's regardless which thread it was called from, or all of them; i haven't looked into the source to see which it is.

I also don't know whether supplying 'restart' makes löve execute the love.quit callback or whether it just skips it entirely.

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 6:10 pm
by hasen
zorg wrote: Sun Jan 28, 2018 3:39 pm I don't give a squat about how corona does it, to be completely honest.
I think the real issue is that we're trying to achieve in our own code what is built in the Corona simulator. I guess we'll just have to wait until they add it to Love (if they ever do). But thanks for your code, it's a workaround in the meantime.
pgimeno wrote: Sun Jan 28, 2018 5:00 pm I call that "hot restart". "Reload" to me applies to individual files, as in, when you modify a file, it is reloaded into the running program. Everyone else has understood it that way. "Restart" implies your application starts again from the beginning.
No sorry, you should google 'reload program', it means exactly what I said it did. As for 'hot restart'...I never heard of that before.

Re: Hot *restart* plugin that actually works? Feasible.

Posted: Sun Jan 28, 2018 8:07 pm
by pgimeno
zorg wrote: Sun Jan 28, 2018 5:46 pmI also don't know whether supplying 'restart' makes löve execute the love.quit callback or whether it just skips it entirely.
I've checked, it gets called and it blocks the restart when returning true.

Re: Hot reload plugin that actually works?

Posted: Sun Jan 28, 2018 11:41 pm
by alloyed
It's interesting to read people claim that hotswapping is impossible when I've been doing it since forever~
I understand the point, that doing it for arbitrary lua code is impossible, but when you're the master of your own app you can apply the structure you need to make it work yourself.

example here: https://github.com/Alloyed/gabe/blob/master/main.lua

I always wanted to write more comprehensive docs but never got around to it.

So a few notes on practical usage:

* I don't automatically reload: you need to press a button, just like you would refresh a webpage. Automatic hotswapping is totally possible in this framework, I just choose not to use it so I have full understanding of when and how my code changes.

* I don't try to resolve the issues that pop up when you change something in a class constructor and older instances of the class don't notice. It's fine if these error or go into a bad state, because hard resets are as easy as soft reloads in this framework.

* Error handling isn't as comprehensive as I like. More often than not I'll opt for the hard reset to fix an error instead of the soft option. This would probably be better if I had more debugging tools that I could leave on for cheap, like a stepwise debugger/rewind option.

EDIT: about the words used to describe the feature: I call changing the behavior of the game to match the current code "reloading". Restarting the game without throwing away assets or things like the window I call "resetting", as in resetting the state of the game.

Re: Hot reload plugin that actually works?

Posted: Mon Jan 29, 2018 1:28 am
by pgimeno
hasen wrote: Sun Jan 28, 2018 6:10 pmNo sorry, you should google 'reload program', it means exactly what I said it did. As for 'hot restart'...I never heard of that before.
I've googled "hot reload". Most hits I found talked about reloading a single file and not the whole application. Which is what everyone here thought you were talking about.

alloyed wrote: Sun Jan 28, 2018 11:41 pm It's interesting to read people claim that hotswapping is impossible when I've been doing it since forever~
I understand the point, that doing it for arbitrary lua code is impossible, but when you're the master of your own app you can apply the structure you need to make it work yourself.
Then we're all in agreement :) Zorg said basically the same thing in the second post of the thread. I pointed out the impossibility of making it general enough to cover all workflows, gave some examples of things that can't possibly be covered by such a library, and I even said that "[o]f course it's possible to have hot reload under the assumption that you stick to a certain workflow" (after all, lovedebug and lick do it).

Re: Hot reload plugin that actually works?

Posted: Mon Jan 29, 2018 9:28 am
by hasen
pgimeno wrote: Mon Jan 29, 2018 1:28 am I've googled "hot reload". Most hits I found talked about reloading a single file and not the whole application. Which is what everyone here thought you were talking about.
The top result in Google is about React Native https://facebook.github.io/react-native ... ading.html

I've used React Native and it reloads the app on any changes. Not sure what you've been searching for.

Whatever happened to your code for Corona that didn't work anyway?

Re: Hot reload plugin that actually works?

Posted: Mon Jan 29, 2018 10:57 am
by pgimeno
hasen wrote: Mon Jan 29, 2018 9:28 am I've used React Native and it reloads the app on any changes. Not sure what you've been searching for.
React native page wrote: Hot Reloading

The idea behind hot reloading is to keep the app running and to inject new versions of the files that you edited at runtime. This way, you don't lose any of your state which is especially useful if you are tweaking the UI.
https://facebook.github.io/react-native ... ading.html (emphasis mine).
That's single-file reload without restarting, in my book.

hasen wrote: Mon Jan 29, 2018 9:28 am Whatever happened to your code for Corona that didn't work anyway?
It's moot since my code demonstrated the problems with hot swapping, but you later clarified you were talking about hot restart.

Re: Hot reload plugin that actually works?

Posted: Tue Jan 30, 2018 11:56 am
by Nelvin
I'm developing using Corona as well as Löve and Corona has two productivity features but non is a hot reloading of code as in patch the code of your running app.

Corona does a simple automatic restart of the app as soon as you modify any file realted to the project, as someone else wrote in this thread, it's just the same as pressing alt-l in Visual Studio Code to restart your game.

The second feature is Live Builds - that's particularly helpful when working with mobiles devices. You can build your APK and install and run it on multiple devices in your local network and now, whenever you change a file in your project, the running APKs get just this tiny little changed files as an update and, again, the game just restarts. That's a pretty decent feature if you start tweaking you code for multiple displays/devices or if you do a multiplayer game. I f.i. did a quiz game prototype where you have a quiz host and multiple devices to be used in the game. Any code change was up and already running on 3 devices within a very few seconds.

Real hotloading in a language as dynamic as Lua is really hard and it would require to use indirections in almost every case, i.e. any local's or cached values (like references to other objects/tables etc.) would still point to old version if you reload any code. Defold with it's (IMO, pretty ugly) messaging system probably can do it but you'll lose a lot of freedom in how to write your code.

Real hotloading is f.i. done by Casey Muratori in his Handmade Hero streams in a pretty impressive way and actually while coding in C/++.

Re: Hot reload plugin that actually works?

Posted: Mon Feb 05, 2018 3:10 pm
by coffeecat
I am deeply attracted to the idea of hot reloading and interactive development, and have been working in this area for a long time. In my opinion hot reload is definitely doable, and when you manage to implement it correctly, it can boost your productivity greatly.

The most simple way to do this is reloading the whole game by switching out global variables, rerun love.load(), etc. In the past, I have used cupid for this [1]. I have a modified version here [2]. In my experience, it has been quite robust.

It is also possible to handle states correctly during the hot reload, but it is more specific to a particular game. To implement hot reloading with states correctly, you have to keep hot reloading in mind when designing your game program architecture. In my current game project, a room is represented by a single Lua function, and room states are in the environment [3] of that function. Therefore I can catch all room states cleanly by a fsetenv. This approach creates a sandbox for room scripts, doesn't put cognitive burden on any part of the code, and work correctly with hot reload. Sometimes old room states may be incompatible with the new room script, and I will do a manual reset of the room states. When even that doesn't work out, I will hot reload the whole game.

In companion with code hot reloading, I have created lovecat [4] to help with interactive game development. Instead of writing constants in your Lua program, you can reference a lovecat value. Lovecat will arrange that you can interactively manipulate the constant in a browser. Lovecat is a bit outdated now, but I'll update it soon, and also switch to HSLuv [5] for color manipulating.

I am also proposing an API addition to LOVE, which enables getting notified of source file update events from the operating system. [6] This will be much more efficient than polling for all source files every 0.x second, which unfortunately is the approach cupid and others take. Please vote for it, if you find it helpful. :D

[1] https://bitbucket.org/basicer/cupid/
[2] https://github.com/CoffeeKitty/lovecat/ ... /cupid.lua
[3] https://www.lua.org/manual/5.1/manual.html#2.9
[4] https://love2d.org/forums/viewtopic.php?f=5&t=80932
[5] http://www.hsluv.org
[6] https://bitbucket.org/rude/love/issues/ ... ns-of-file

Re: Hot reload plugin that actually works?

Posted: Mon Apr 09, 2018 11:53 am
by TheMeq
Your link [2] no longer works.

Cupid doesn't work in 11.0 :(