Emscripten fixes

This commit is contained in:
Joshua Granick
2023-05-19 23:10:16 -07:00
parent df2ae53ad3
commit eec6e5e0fa
5 changed files with 47 additions and 48 deletions

View File

@@ -13,9 +13,9 @@
#elif defined (EMSCRIPTEN) #elif defined (EMSCRIPTEN)
#define LIME_GLES #define LIME_GLES
#define LIME_GLES3_API // #define LIME_GLES3_API
#include <GLES3/gl3.h> #include <GLES2/gl2.h>
#include <GLES3/gl2ext.h> #include <GLES2/gl2ext.h>
#elif defined (TIZEN) #elif defined (TIZEN)

View File

@@ -55,7 +55,7 @@ class Bytes
return untyped $sget(b, pos); return untyped $sget(b, pos);
#elseif flash #elseif flash
return b[pos]; return b[pos];
#elseif cpp #elseif (cpp || emscripten)
return untyped b[pos]; return untyped b[pos];
#elseif java #elseif java
return untyped b[pos] & 0xFF; return untyped b[pos] & 0xFF;
@@ -72,7 +72,7 @@ class Bytes
untyped $sset(b, pos, v); untyped $sset(b, pos, v);
#elseif flash #elseif flash
b[pos] = v; b[pos] = v;
#elseif cpp #elseif (cpp || emscripten)
untyped b[pos] = v; untyped b[pos] = v;
#elseif java #elseif java
b[pos] = cast v; b[pos] = cast v;
@@ -104,7 +104,7 @@ class Bytes
cs.system.Array.Copy(src.b, srcpos, b, pos, len); cs.system.Array.Copy(src.b, srcpos, b, pos, len);
#elseif python #elseif python
python.Syntax.code("self.b[{0}:{0}+{1}] = src.b[srcpos:srcpos+{1}]", pos, len); python.Syntax.code("self.b[{0}:{0}+{1}] = src.b[srcpos:srcpos+{1}]", pos, len);
#elseif cpp #elseif (cpp || emscripten)
b.blit(pos, src.b, srcpos, len); b.blit(pos, src.b, srcpos, len);
#else #else
var b1 = b; var b1 = b;
@@ -136,7 +136,7 @@ class Bytes
pos += len & ~3; pos += len & ~3;
for (i in 0...len & 3) for (i in 0...len & 3)
set(pos++, value); set(pos++, value);
#elseif cpp #elseif (cpp || emscripten)
untyped __global__.__hxcpp_memory_memset(b, pos, len, value); untyped __global__.__hxcpp_memory_memset(b, pos, len, value);
#else #else
for (i in 0...len) for (i in 0...len)
@@ -206,7 +206,7 @@ class Bytes
return length - other.length; return length - other.length;
// #elseif cs // #elseif cs
// TODO: memcmp if unsafe flag is on // TODO: memcmp if unsafe flag is on
#elseif cpp #elseif (cpp || emscripten)
return b.memcmp(other.b); return b.memcmp(other.b);
#else #else
var b1 = b; var b1 = b;
@@ -232,7 +232,7 @@ class Bytes
#elseif flash #elseif flash
b.position = pos; b.position = pos;
return b.readDouble(); return b.readDouble();
#elseif cpp #elseif (cpp || emscripten)
if (pos < 0 || pos + 8 > length) throw Error.OutsideBounds; if (pos < 0 || pos + 8 > length) throw Error.OutsideBounds;
return untyped __global__.__hxcpp_memory_get_double(b, pos); return untyped __global__.__hxcpp_memory_get_double(b, pos);
#else #else
@@ -254,7 +254,7 @@ class Bytes
#elseif flash #elseif flash
b.position = pos; b.position = pos;
return b.readFloat(); return b.readFloat();
#elseif cpp #elseif (cpp || emscripten)
if (pos < 0 || pos + 4 > length) throw Error.OutsideBounds; if (pos < 0 || pos + 4 > length) throw Error.OutsideBounds;
return untyped __global__.__hxcpp_memory_get_float(b, pos); return untyped __global__.__hxcpp_memory_get_float(b, pos);
#else #else
@@ -278,7 +278,7 @@ class Bytes
#elseif flash #elseif flash
b.position = pos; b.position = pos;
b.writeDouble(v); b.writeDouble(v);
#elseif cpp #elseif (cpp || emscripten)
if (pos < 0 || pos + 8 > length) throw Error.OutsideBounds; if (pos < 0 || pos + 8 > length) throw Error.OutsideBounds;
untyped __global__.__hxcpp_memory_set_double(b, pos, v); untyped __global__.__hxcpp_memory_set_double(b, pos, v);
#else #else
@@ -304,7 +304,7 @@ class Bytes
#elseif flash #elseif flash
b.position = pos; b.position = pos;
b.writeFloat(v); b.writeFloat(v);
#elseif cpp #elseif (cpp || emscripten)
if (pos < 0 || pos + 4 > length) throw Error.OutsideBounds; if (pos < 0 || pos + 4 > length) throw Error.OutsideBounds;
untyped __global__.__hxcpp_memory_set_float(b, pos, v); untyped __global__.__hxcpp_memory_set_float(b, pos, v);
#else #else
@@ -398,7 +398,7 @@ class Bytes
#elseif flash #elseif flash
b.position = pos; b.position = pos;
return b.readUTFBytes(len); return b.readUTFBytes(len);
#elseif cpp #elseif (cpp || emscripten)
var result:String = ""; var result:String = "";
untyped __global__.__hxcpp_string_of_bytes(b, result, pos, len); untyped __global__.__hxcpp_string_of_bytes(b, result, pos, len);
return result; return result;
@@ -510,7 +510,7 @@ class Bytes
var b = new flash.utils.ByteArray(); var b = new flash.utils.ByteArray();
b.length = length; b.length = length;
return new Bytes(length, b); return new Bytes(length, b);
#elseif cpp #elseif (cpp || emscripten)
var a = new BytesData(); var a = new BytesData();
if (length > 0) cpp.NativeArray.setSize(a, length); if (length > 0) cpp.NativeArray.setSize(a, length);
return new Bytes(length, a); return new Bytes(length, a);
@@ -540,7 +540,7 @@ class Bytes
var b = new flash.utils.ByteArray(); var b = new flash.utils.ByteArray();
b.writeUTFBytes(s); b.writeUTFBytes(s);
return new Bytes(b.length, b); return new Bytes(b.length, b);
#elseif cpp #elseif (cpp || emscripten)
var a = new BytesData(); var a = new BytesData();
untyped __global__.__hxcpp_bytes_of_string(a, s); untyped __global__.__hxcpp_bytes_of_string(a, s);
return new Bytes(a.length, a); return new Bytes(a.length, a);
@@ -638,7 +638,7 @@ class Bytes
return untyped __dollar__sget(b, pos); return untyped __dollar__sget(b, pos);
#elseif flash #elseif flash
return b[pos]; return b[pos];
#elseif cpp #elseif (cpp || emscripten)
return untyped b.unsafeGet(pos); return untyped b.unsafeGet(pos);
#elseif java #elseif java
return untyped b[pos] & 0xFF; return untyped b[pos] & 0xFF;

View File

@@ -7,7 +7,7 @@ import lime.app.Event;
#if haxe4 #if haxe4
import sys.thread.Deque; import sys.thread.Deque;
import sys.thread.Thread; import sys.thread.Thread;
#elseif cpp #elseif (cpp || emscripten)
import cpp.vm.Deque; import cpp.vm.Deque;
import cpp.vm.Thread; import cpp.vm.Thread;
#elseif neko #elseif neko
@@ -30,7 +30,7 @@ class ThreadPool
public var onProgress = new Event<Dynamic->Void>(); public var onProgress = new Event<Dynamic->Void>();
public var onRun = new Event<Dynamic->Void>(); public var onRun = new Event<Dynamic->Void>();
#if (cpp || neko) #if (cpp || neko || emscripten)
@:noCompletion private var __synchronous:Bool; @:noCompletion private var __synchronous:Bool;
@:noCompletion private var __workCompleted:Int; @:noCompletion private var __workCompleted:Int;
@:noCompletion private var __workIncoming = new Deque<ThreadPoolMessage>(); @:noCompletion private var __workIncoming = new Deque<ThreadPoolMessage>();
@@ -45,7 +45,7 @@ class ThreadPool
currentThreads = 0; currentThreads = 0;
#if (cpp || neko) #if (cpp || neko || emscripten)
__workQueued = 0; __workQueued = 0;
__workCompleted = 0; __workCompleted = 0;
#end #end
@@ -67,7 +67,7 @@ class ThreadPool
// } // }
public function queue(state:Dynamic = null):Void public function queue(state:Dynamic = null):Void
{ {
#if (cpp || neko) #if (cpp || neko || emscripten)
// TODO: Better way to handle this? // TODO: Better way to handle this?
if (Application.current != null && Application.current.window != null && !__synchronous) if (Application.current != null && Application.current.window != null && !__synchronous)
@@ -98,7 +98,7 @@ class ThreadPool
public function sendComplete(state:Dynamic = null):Void public function sendComplete(state:Dynamic = null):Void
{ {
#if (cpp || neko) #if (cpp || neko || emscripten)
if (!__synchronous) if (!__synchronous)
{ {
__workResult.add(new ThreadPoolMessage(COMPLETE, state)); __workResult.add(new ThreadPoolMessage(COMPLETE, state));
@@ -111,7 +111,7 @@ class ThreadPool
public function sendError(state:Dynamic = null):Void public function sendError(state:Dynamic = null):Void
{ {
#if (cpp || neko) #if (cpp || neko || emscripten)
if (!__synchronous) if (!__synchronous)
{ {
__workResult.add(new ThreadPoolMessage(ERROR, state)); __workResult.add(new ThreadPoolMessage(ERROR, state));
@@ -124,7 +124,7 @@ class ThreadPool
public function sendProgress(state:Dynamic = null):Void public function sendProgress(state:Dynamic = null):Void
{ {
#if (cpp || neko) #if (cpp || neko || emscripten)
if (!__synchronous) if (!__synchronous)
{ {
__workResult.add(new ThreadPoolMessage(PROGRESS, state)); __workResult.add(new ThreadPoolMessage(PROGRESS, state));
@@ -137,7 +137,7 @@ class ThreadPool
@:noCompletion private function runWork(state:Dynamic = null):Void @:noCompletion private function runWork(state:Dynamic = null):Void
{ {
#if (cpp || neko) #if (cpp || neko || emscripten)
if (!__synchronous) if (!__synchronous)
{ {
__workResult.add(new ThreadPoolMessage(WORK, state)); __workResult.add(new ThreadPoolMessage(WORK, state));
@@ -150,7 +150,7 @@ class ThreadPool
doWork.dispatch(state); doWork.dispatch(state);
} }
#if (cpp || neko) #if (cpp || neko || emscripten)
@:noCompletion private function __doWork():Void @:noCompletion private function __doWork():Void
{ {
while (true) while (true)

View File

@@ -1,17 +1,17 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>::APP_TITLE::</title> <title>::APP_TITLE::</title>
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
::if linkedLibraries::::foreach (linkedLibraries):: ::if linkedLibraries::::foreach (linkedLibraries)::
<script type="text/javascript" src="::__current__::"></script>::end::::end:: <script type="text/javascript" src="::__current__::"></script>::end::::end::
<script> <script>
window.addEventListener ("touchmove", function (event) { event.preventDefault (); }, false); window.addEventListener ("touchmove", function (event) { event.preventDefault (); }, false);
if (typeof window.devicePixelRatio != 'undefined' && window.devicePixelRatio > 2) { if (typeof window.devicePixelRatio != 'undefined' && window.devicePixelRatio > 2) {
@@ -19,7 +19,7 @@
meta.setAttribute ('content', 'width=device-width, initial-scale=' + (2 / window.devicePixelRatio) + ', user-scalable=no'); meta.setAttribute ('content', 'width=device-width, initial-scale=' + (2 / window.devicePixelRatio) + ', user-scalable=no');
} }
</script> </script>
<style> <style>
html,body { margin: 0; padding: 0; height: 100%; overflow: hidden; } html,body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
#content { background: #000000; width: 100%; height: 100%; } #content { background: #000000; width: 100%; height: 100%; }
@@ -35,18 +35,18 @@
font-style: normal; font-style: normal;
}::end::::end:: }::end::::end::
</style> </style>
</head> </head>
<body> <body>
::foreach assets::::if (type == "font"):: ::foreach assets::::if (type == "font")::
<span style="font-family: ::id::"> </span>::end::::end:: <span style="font-family: ::id::"> </span>::end::::end::
<div id="content"> <div id="content">
<canvas id="canvas"::if (WIN_WIDTH != 0):: width="::WIN_WIDTH::px"::end::::if (WIN_HEIGHT != 0):: height="::WIN_HEIGHT::px"::end::></canvas> <canvas id="canvas"::if (WIN_WIDTH != 0):: width="::WIN_WIDTH::px"::end::::if (WIN_HEIGHT != 0):: height="::WIN_HEIGHT::px"::end::></canvas>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var Module = {}; var Module = {};
Module.canvas = document.getElementById ("canvas"); Module.canvas = document.getElementById ("canvas");
//::if DEBUG::Module.setStatus = function (msg) { console.log (msg); };::else::Module.setStatus = function(_) {};::end:: //::if DEBUG::Module.setStatus = function (msg) { console.log (msg); };::else::Module.setStatus = function(_) {};::end::
@@ -55,19 +55,19 @@
var container = document.getElementById ("content"); var container = document.getElementById ("content");
Module.canvas.width = container.clientWidth; Module.canvas.width = container.clientWidth;
Module.canvas.height = container.clientHeight; Module.canvas.height = container.clientHeight;
window.addEventListener ("resize", function (e) { window.addEventListener ("resize", function (e) {
Module.canvas.width = container.clientWidth; Module.canvas.width = container.clientWidth;
Module.canvas.height = container.clientHeight; Module.canvas.height = container.clientHeight;
}, true);::end::::end:: }, true);::end::::end::
</script> </script>
::if DEBUG::<script type="text/javascript" src="./webgl-debug.js"></script>::end:: ::if DEBUG::<script type="text/javascript" src="./webgl-debug.js"></script>::end::
<script type="text/javascript" src="./::APP_FILE::.js"></script> <script type="text/javascript" src="./::APP_FILE::.js"></script>
</body> </body>
</html> </html>

View File

@@ -127,10 +127,11 @@ class EmscriptenPlatform extends PlatformTarget
if (noOutput) return; if (noOutput) return;
CPPHelper.compile(project, targetDirectory + "/obj", ["-Demscripten", "-Dwebgl", "-Dstatic_link"]); CPPHelper.compile(project, targetDirectory + "/obj", ["-Demscripten", "-Dwebgl", "-Dstatic_link"]);
// CPPHelper.compile(project, targetDirectory + "/obj", ["-Demscripten", "-Dwebgl", "-Dstatic_link"], "BuildMain.xml");
project.path(sdkPath); project.path(sdkPath);
System.runCommand("", "emcc", [targetDirectory + "/obj/Main.cpp", "-o", targetDirectory + "/obj/Main.o"], true, false, true); System.runCommand("", "emcc", ["-c", targetDirectory + "/obj/Main.cpp", "-o", targetDirectory + "/obj/Main.o"], true, false, true);
args = ["Main.o"]; args = ["Main.o"];
@@ -159,11 +160,8 @@ class EmscriptenPlatform extends PlatformTarget
"-o", "-o",
"ApplicationMain.o" "ApplicationMain.o"
]); ]);
System.runCommand(targetDirectory + "/obj", "emcc", args, true, false, true);
args = ["ApplicationMain.o"]; if (project.targetFlags.exists("webassembly") || project.targetFlags.exists("wasm") || !project.targetFlags.exists("asmjs"))
if (project.targetFlags.exists("webassembly") || project.targetFlags.exists("wasm"))
{ {
args.push("-s"); args.push("-s");
args.push("WASM=1"); args.push("WASM=1");
@@ -404,7 +402,8 @@ class EmscriptenPlatform extends PlatformTarget
ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/template", destination, context); ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/template", destination, context);
ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context); ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context);
ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/hxml", targetDirectory + "/haxe", context); ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/hxml", targetDirectory + "/haxe", context);
ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/cpp", targetDirectory + "/obj", context); // ProjectHelper.recursiveSmartCopyTemplate(project, "emscripten/cpp", targetDirectory + "/obj", context);
ProjectHelper.recursiveSmartCopyTemplate(project, "cpp/static", targetDirectory + "/obj", context);
for (asset in project.assets) for (asset in project.assets)
{ {