New Preserves float interface

This commit is contained in:
Tony Garnock-Jones 2021-02-17 15:36:43 +01:00
parent 730d40b90b
commit 608bdde8c8
3 changed files with 10 additions and 10 deletions

View File

@ -22,6 +22,6 @@
"types": "lib/index.d.ts",
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
"dependencies": {
"preserves": "0.5.2"
"preserves": "0.5.3"
}
}

View File

@ -16,7 +16,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------
import { $QuitDataspace, Double, Facet, Inbound, Outbound } from '@syndicate-lang/core';
import { $QuitDataspace, Double, Facet, Inbound, Outbound, floatValue } from '@syndicate-lang/core';
activate import { WindowEvent, template, Anchor } from '@syndicate-lang/html';
activate import { PeriodicTick } from '@syndicate-lang/timer';
@ -77,7 +77,7 @@ function spawnGame<T>(thisFacet: Facet<T>) {
field ypos: number = 312;
field yvel: number = 0;
assert Position(new Double(this.xpos), new Double(this.ypos));
assert Position(Double(this.xpos), Double(this.ypos));
assert Outbound(
ui.html('#board-area',
@ -99,7 +99,7 @@ function spawnGame<T>(thisFacet: Facet<T>) {
on message Inbound(WindowEvent('+click', $_e)) => this.yvel = -10;
const ms_per_tick = 1000.0 / 60;
on message Inbound(PeriodicTick(new Double(ms_per_tick))) => {
on message Inbound(PeriodicTick(Double(ms_per_tick))) => {
this.xpos += 0.15 * ms_per_tick;
this.ypos = (this.ypos + this.yvel);
this.yvel += ms_per_tick * 0.05;
@ -110,7 +110,7 @@ function spawnGame<T>(thisFacet: Facet<T>) {
spawn named 'border-scroll' {
let ui = new Anchor();
field pos: number = 0;
on asserted Position($xpos, _) => this.pos = Double.unwrap(xpos as any) % 23;
on asserted Position($xpos, _) => this.pos = floatValue(xpos) % 23;
assert Outbound(ui.html(
'#board-area',
template`<div class="scrolling-border" style="${`background-position-x: ${-this.pos}px`}"></div>`,
@ -138,10 +138,10 @@ function spawnGame<T>(thisFacet: Facet<T>) {
on start react { stop on (this.xpos <= 0) send message IncreaseScore(); };
field xpos: number = xlocation;
on asserted Position($xpos, _) => this.xpos = xlocation - Double.unwrap(xpos as any);
on asserted Position($xpos, _) => this.xpos = xlocation - floatValue(xpos);
on asserted Position($xpos, $ypos) => {
if (touchingPillar(Double.unwrap(xpos as any), Double.unwrap(ypos as any))) {
if (touchingPillar(floatValue(xpos), floatValue(ypos))) {
react {
assert GameOver();
}

View File

@ -16,7 +16,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------
import { preserves, Observe, Dataspace, Float, Facet } from "@syndicate-lang/core";
import { preserves, Observe, Dataspace, floatValue, Facet } from "@syndicate-lang/core";
export message type PeriodicTick(intervalMS);
export assertion type TimeLaterThan(deadlineMS);
@ -38,7 +38,7 @@ boot {
on start {
handle = setInterval(thisFacet.wrapExternal((thisFacet) => {
send message PeriodicTick(intervalMS);
}), Float.unwrap(intervalMS as any));
}), floatValue(intervalMS as any));
}
on stop {
if (handle) {
@ -59,7 +59,7 @@ boot {
let handle: any | null = null;
let finish: (() => void) | null = thisFacet.actor.dataspace.backgroundTask();
on start {
let delta = Float.unwrap(deadlineMS as any) - (+(new Date()));
let delta = floatValue(deadlineMS as any) - (+(new Date()));
handle = setTimeout(thisFacet.wrapExternal((thisFacet) => {
handle = null;
if (finish) finish();