Kha icon indicating copy to clipboard operation
Kha copied to clipboard

Krom is not hot reloading code

Open Jarrio opened this issue 6 years ago • 15 comments

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

Jarrio avatar Mar 08 '18 14:03 Jarrio

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.

RobDangerous avatar Mar 08 '18 14:03 RobDangerous

Does this mean you have to create a closure for every callback?

sh-dave avatar Mar 08 '18 15:03 sh-dave

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

Jarrio avatar Mar 08 '18 15:03 Jarrio

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.

RobDangerous avatar Mar 08 '18 15:03 RobDangerous

Can reproduce, doesn't work in Krom although it does work in the Kode Garden, something is broken...

RobDangerous avatar Mar 08 '18 15:03 RobDangerous

Any updates?

belohlavek avatar Nov 03 '19 14:11 belohlavek

Any ice cream for me?

RobDangerous avatar Nov 03 '19 15:11 RobDangerous

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?

RblSb avatar Nov 03 '19 15:11 RblSb

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.

RobDangerous avatar Nov 03 '19 15:11 RobDangerous

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?

skylerparr avatar Aug 19 '20 16:08 skylerparr

So you're trying to run it without vscode or Kode Studio? Because in those everything is setup automatically.

RobDangerous avatar Aug 23 '20 18:08 RobDangerous

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?

skylerparr avatar Aug 23 '20 22:08 skylerparr

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.

RobDangerous avatar Aug 24 '20 15:08 RobDangerous

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 .

skylerparr avatar Aug 24 '20 15:08 skylerparr

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.

RobDangerous avatar Aug 24 '20 15:08 RobDangerous