mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Add couple native declarations to JSO APIs. Update sample
This commit is contained in:
parent
7108dfbac7
commit
810012872c
|
@ -16,6 +16,9 @@
|
|||
package org.teavm.classlib.java.lang;
|
||||
|
||||
import org.teavm.interop.DelegateTo;
|
||||
import org.teavm.interop.Platforms;
|
||||
import org.teavm.interop.SupportedOn;
|
||||
import org.teavm.jso.browser.Navigator;
|
||||
import org.teavm.runtime.GC;
|
||||
|
||||
/**
|
||||
|
@ -85,4 +88,9 @@ public class TRuntime {
|
|||
private long totalMemoryLowLevel() {
|
||||
return GC.availableBytes();
|
||||
}
|
||||
|
||||
@SupportedOn(Platforms.JAVASCRIPT)
|
||||
public int availableProcessors() {
|
||||
return Navigator.hardwareConcurrency();
|
||||
}
|
||||
}
|
|
@ -40,4 +40,7 @@ public final class Navigator {
|
|||
|
||||
@JSBody(script = "return navigator.getGamepads();")
|
||||
public static native Gamepad[] getGamepads();
|
||||
|
||||
@JSBody(script = "return navigator.hardwareConcurrency")
|
||||
public static native int hardwareConcurrency();
|
||||
}
|
||||
|
|
|
@ -155,6 +155,8 @@ public abstract class Window implements JSObject, WindowEventTarget, StorageProv
|
|||
|
||||
public abstract void postMessage(JSObject message);
|
||||
|
||||
public abstract void postMessage(JSObject message, JSArrayReader<JSObject> transfer);
|
||||
|
||||
public abstract void postMessage(JSObject message, String targetOrigin);
|
||||
|
||||
public abstract void postMessage(JSObject message, String targetOrigin, JSArrayReader<JSObject> transfer);
|
||||
|
@ -163,6 +165,10 @@ public abstract class Window implements JSObject, WindowEventTarget, StorageProv
|
|||
postMessage(message, targetOrigin, JSArray.of(transfer));
|
||||
}
|
||||
|
||||
public final void postMessage(JSObject message, JSObject... transfer) {
|
||||
postMessage(message, JSArray.of(transfer));
|
||||
}
|
||||
|
||||
@JSBody(script = "return window;")
|
||||
public static native Window current();
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class RenderWorker {
|
|||
renderer.render()
|
||||
val perfEnd = System.nanoTime()
|
||||
val buffer = extractBuffer(raster.flip())
|
||||
postMessageFromWorker(JSObjects.createWithoutProto<JSMapLike<JSObject>>().apply {
|
||||
Window.worker().postMessage(JSObjects.createWithoutProto<JSMapLike<JSObject>>().apply {
|
||||
set("data", buffer)
|
||||
set("time", JSNumber.valueOf((perfEnd - perfStart).toInt()))
|
||||
}, JSArray.of(buffer))
|
||||
|
|
|
@ -35,7 +35,7 @@ fun main(args: Array<out String>) {
|
|||
fun runController() {
|
||||
val performanceIndicator = HTMLDocument.current().getElementById("performance-indicator")
|
||||
var performanceIndicatorByWorkers: List<HTMLElement> = emptyList()
|
||||
val maxWorkers = cpuCount()
|
||||
val maxWorkers = Runtime.getRuntime().availableProcessors()
|
||||
var workerType = WorkerType.JS
|
||||
val controller = Controller(SCENE_WIDTH, SCENE_HEIGHT) { index, value ->
|
||||
if (index == -1) {
|
||||
|
|
|
@ -18,15 +18,7 @@ package org.teavm.samples.software3d.teavm
|
|||
|
||||
import org.teavm.jso.JSBody
|
||||
import org.teavm.jso.JSByRef
|
||||
import org.teavm.jso.JSObject
|
||||
import org.teavm.jso.core.JSArray
|
||||
import org.teavm.jso.typedarrays.ArrayBuffer
|
||||
|
||||
@JSBody(params = ["data"], script = "return data.buffer;")
|
||||
external fun extractBuffer(@JSByRef data: IntArray): ArrayBuffer
|
||||
|
||||
@JSBody(params = ["message", "transferable"], script = "self.postMessage(message, transferable);")
|
||||
external fun postMessageFromWorker(message: JSObject, transferable: JSArray<out JSObject>)
|
||||
|
||||
@JSBody(script = "return navigator.hardwareConcurrency;")
|
||||
external fun cpuCount(): Int
|
||||
external fun extractBuffer(@JSByRef data: IntArray): ArrayBuffer
|
Loading…
Reference in New Issue
Block a user