Kha
Kha copied to clipboard
Krom is not hot reloading code
Setup
VSCode: 1.20.1
Kha: Git
Haxe: 4.0.0 Preview 3
HXCPP: 3.4.196
Test Case
Main.hx
package;
import kha.System;
class Main {
public static function main() {
System.init({title: "Project", width: 1024, height: 768}, function () {
new Project();
});
}
}
Project.hx:
class Project {
public function new() {
System.notifyOnRender(render);
Scheduler.addTimeTask(update, 0, 1 / 60);
//trace("Test");
}
function update(): Void {
//trace("Test 2");
}
function render(framebuffer: Framebuffer): Void {
}
}
Result
Compiling the project I get the following output https://hastebin.com/yonorihuzu.tex. After making changes to the file (Uncommenting the traces above) the debugger returns the following messages:
Haxe compile end.
Haxe compile end.
But the trace is not shown in the debugger
That's because the previous implementations of update and render are already saved away by System/Scheduler. Have a look at http://kodegarden.org for a workaround.
Does this mean you have to create a closure for every callback?
I changed Project.hx
to the following:
class Project {
public function new() {
System.notifyOnRender(function(buffer) { render(buffer); });
Scheduler.addTimeTask(function() { update(); } , 0, 1 / 60);
// trace("Test");
}
function update(): Void {
// trace("Works");
}
function render(framebuffer: Framebuffer): Void {
var graphics = framebuffer.g2;
graphics.begin(false);
graphics.color = Color.Red;
graphics.fillRect(100, 100, 250, 250);
graphics.end();
}
}
Changing the color of the rect to Blue
and it is still not updating for me
Yes, if you need hot-patching to work via that callback you have to add some kind of indirection until I eventually patch the Haxe compiler to optionally do it automatically.
Can reproduce, doesn't work in Krom although it does work in the Kode Garden, something is broken...
Any updates?
Any ice cream for me?
I think that fixed already? https://github.com/Kode/Krom/pull/130 My question: how to run hot reload, just build for Krom and resave files?
Yes, Krom watches your files then reloads automatically when you use the --watch parameter. Haxe was update to v4.0 last week though and I haven't tested it with that yet - not unlikely that it's broken again.
I will provide ice cream via patreon if you can provide some examples on how to run krom and also run with the --watch
parameter. I build Krom from source and the build succeeds. I run it for my project via ..\Krom\build\x64\Release\Krom.exe build\krom build\krom-resources
and nothing happens (immediately exits). Krom does work from Kode, but isn't ideal for my workflow and familiarity of the ide. So...
1 scoop:
Example on how to configure code to run Krom with --watch
using Kode
2 scoops:
Example on how to run Krom from the command line with the --watch
parameter. Also, with the --watch
param enabled, do I just do node Kha/make.js krom
to hot reload the code?
So you're trying to run it without vscode or Kode Studio? Because in those everything is setup automatically.
I prefer to code with vi, so it would be ideal to be able to run the command from the command line.
Kode is set up to do hot code reloading? Does the code get pushed on save? How does it work?
Yes, Kode Studio is setup to hot-reload Haxe code, shader code and assets when used with Krom. When it works. Code is compiled on save, Krom itself then parses and diffs the js output. And alternatively there's also rblsb's html5 hot-reload solution which has the advantage that it currently works.
Is there a way to run this functionality from the command line since kode isn't my ideal workflow?
On Mon, Aug 24, 2020, 11:20 Robert Konrad [email protected] wrote:
Yes, Kode Studio is setup to hot-reload Haxe code, shader code and assets when used with Krom. When it works. Code is compiled on save, Krom itself then parses and diffs the js output. And alternatively there's also rblsb's html5 hot-reload solution which has the advantage that it currently works.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Kode/Kha/issues/767#issuecomment-679192187, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4CQIGE5VKKL5474DDJ6RDSCKAMTANCNFSM4EULFHOQ .
Sure, you just need to add the --watch parameter. But as said, it isn't currently working. Also noticed though that your Krom call is wrong. Have a look at the readme - more than anything it requires the assetsdir (the krom dir in your build dir), the shadersdir (that's krom-resources in a normal build) is actually optional and only required for hot-reloading shaders.