Use webassembly for ammo+krom

This commit is contained in:
luboslenco 2019-11-16 14:11:32 +01:00
parent 405da0e10e
commit f310776985
2 changed files with 51 additions and 15 deletions

View file

@ -42,6 +42,7 @@ class Starter {
#end
kha.System.start({title: Main.projectName, width: c.window_w, height: c.window_h, window: {mode: windowMode, windowFeatures: windowFeatures}, framebuffer: {samplesPerPixel: c.window_msaa, verticalSync: c.window_vsync}}, function(window:kha.Window) {
iron.App.init(function() {
#if arm_loadscreen
function load(g:kha.graphics2.Graphics) {
@ -78,7 +79,18 @@ class Starter {
var print = function(s:String) { trace(s); };
var loaded = function() { tasks--; start(); };
untyped __js__("(1, eval)({0})", b.toString());
#if kha_krom
var instantiateWasm = function(imports, successCallback) {
var wasmbin = Krom.loadBlob("ammo.wasm.wasm");
var module = new js.lib.webassembly.Module(wasmbin);
var inst = new js.lib.webassembly.Instance(module, imports);
successCallback(inst);
return inst.exports;
};
untyped __js__("Ammo({print:print, instantiateWasm:instantiateWasm}).then(loaded)");
#else
untyped __js__("Ammo({print:print}).then(loaded)");
#end
});
}
#end
@ -94,9 +106,27 @@ class Starter {
#end
tasks = 1;
#if (js && arm_bullet) tasks++; loadLibAmmo("ammo.js"); #end
#if (js && arm_navigation) tasks++; loadLib("recast.js"); #end
#if (arm_config) tasks++; armory.data.Config.load(function() { tasks--; start(); }); #end
#if (js && arm_bullet)
tasks++;
#if kha_krom
loadLibAmmo("ammo.wasm.js");
#else
loadLibAmmo("ammo.js");
#end
#end
#if (js && arm_navigation)
tasks++;
loadLib("recast.js");
#end
#if (arm_config)
tasks++;
armory.data.Config.load(function() { tasks--; start(); });
#end
tasks--; start();
}
}

View file

@ -98,11 +98,17 @@ project.addSources('Sources');
assets.add_khafile_def('arm_bullet')
if not os.path.exists('Libraries/haxebullet'):
f.write(add_armory_library(sdk_path + '/lib/', 'haxebullet', rel_path=rel_path))
if state.target.startswith('krom') or state.target == 'html5' or state.target == 'node':
if state.target.startswith('krom'):
ammojs_path = sdk_path + '/lib/haxebullet/ammo/ammo.wasm.js'
ammojs_path = ammojs_path.replace('\\', '/').replace('//', '/')
f.write(add_assets(ammojs_path, rel_path=rel_path))
ammojs_wasm_path = sdk_path + '/lib/haxebullet/ammo/ammo.wasm.wasm'
ammojs_wasm_path = ammojs_wasm_path.replace('\\', '/').replace('//', '/')
f.write(add_assets(ammojs_wasm_path, rel_path=rel_path))
elif state.target == 'html5' or state.target == 'node':
ammojs_path = sdk_path + '/lib/haxebullet/ammo/ammo.js'
ammojs_path = ammojs_path.replace('\\', '/').replace('//', '/')
f.write(add_assets(ammojs_path, rel_path=rel_path))
# haxe.macro.Compiler.includeFile(ammojs_path)
elif wrd.arm_physics_engine == 'Oimo':
assets.add_khafile_def('arm_oimo')
if not os.path.exists('Libraries/oimo'):