From b2d3d85c2212baa3ae50746d534eb5242c86e305 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 4 Oct 2020 23:44:40 +0100 Subject: [PATCH] bigfloats seem to work now Signed-off-by: Ian Jackson --- Makefile | 7 +++++-- templates/bigfloat.ts | 12 +++++++++--- templates/script.ts | 11 ++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 78b175f5..43b4554b 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,9 @@ USVG_PROCESSOR = usvg-processor LIBRARY_PROCESS_SVG = ./$(USVG_PROCESSOR) $@ $(wordlist 1,2,$^) '$(USVG) $(USVG_OPTIONS)' $(LIBRARY_FILES): $(USVG_PROCESSOR) Makefile +TS_SRCS= script bigfloat +TS_SRC_FILES= $(addprefix templates/,$(addsuffix .ts,$(TS_SRCS))) + LITFILES= LICENCE AGPLv3 TXTFILES= CC-BY-SA-3.0 CC-BY-SA-4.0 @@ -77,8 +80,8 @@ $(CARGO_TARGET_DIR)/debug/server: $(CARGO_TARGET_DIR)/release/server: $(CARGO) build --release -templates/%.js: templates/%.ts tsconfig.json - tsc --outfile $@.tmp $< 2>&1 \ +templates/script.js: $(TS_SRC_FILES) tsconfig.json + tsc --outfile $@.tmp $(TS_SRC_FILES) 2>&1 \ | perl -pe 's/\((\d+),(\d+)\):/:$$1:$$2:/'; \ test "$${PIPESTATUS[*]}" = "0 0" mv -f $@.tmp $@ diff --git a/templates/bigfloat.ts b/templates/bigfloat.ts index 89c3cd1e..0fafc012 100644 --- a/templates/bigfloat.ts +++ b/templates/bigfloat.ts @@ -79,9 +79,9 @@ namespace Bigfloats { export function pack(v: Unpacked): Packed { function hex16(x: number) { return ('000' + x.toString(16)).slice(-4); } function hex48(x: Limb) { - return (hex16(Math.floor(x / 0x100000000)) + '_' + - hex16( x & 0xffff0000) + '_' + - hex16( x & 0x0000ffff) ); + return (hex16(Math.floor(x / 0x100000000) ) + '_' + + hex16( (x & 0xffff0000) >> 16 ) + '_' + + hex16( x & 0x0000ffff ) ); } return ( (v.sign < 0 ? '!' : '+') + @@ -141,6 +141,12 @@ namespace Bigfloats { } } + export function add(p: Bigfloat, step: number): Bigfloat { + let v = unpack(p); + add_to_limb(v, 0, step * 0x10000); + return pack(v); + } + export function iter_upto(ap: Packed, bp: Packed, count: number): () => Packed { let av = unpack(ap); diff --git a/templates/script.ts b/templates/script.ts index 49c8632e..e6b207a1 100644 --- a/templates/script.ts +++ b/templates/script.ts @@ -63,7 +63,7 @@ type PieceInfo = { held : PlayerId | null, cseq : number | null, cseq_updatesvg : number | null, - z : number, + z : Bigfloat, zg : Generation, pinned: boolean, uos : UoDescription[], @@ -347,7 +347,7 @@ function some_keydown(e: KeyboardEvent) { } } } - +/* keyops_local['lower'] = function (uo: UoRecord) { // This is a bit subtle. We don't want to lower below pinned pieces // (unless we are pinned too, or the user is wresting). But maybe @@ -553,6 +553,7 @@ keyops_local['lower'] = function (uo: UoRecord) { let pinned = treat } +*/ keyops_local['wrest'] = function (uo: UoRecord) { wresting = !wresting; @@ -766,7 +767,7 @@ function drag_mousemove(e: MouseEvent) { console.log('CHECK RAISE ', dragraise, dragraise*dragraise, ddr2); piece_set_zlevel(piece,p, (oldtop_piece) => { let oldtop_p = pieces[oldtop_piece]!; - let z = oldtop_p.z + 1; + let z = Bigfloats.add(oldtop_p.z, 1); p.z = z; api_piece(api, "setz", piece,p, { z: z }); }); @@ -846,7 +847,7 @@ type PieceStateMessage = { svg: string, held: PlayerId, pos: Pos, - z: number, + z: Bigfloat, zg: Generation, pinned: boolean, uos: UoDescription[], @@ -959,7 +960,7 @@ pieceops.Move = function } pieceops.SetZLevel = function -(piece,p, info: { z: number, zg: Generation }) { +(piece,p, info: { z: Bigfloat, zg: Generation }) { piece_set_zlevel(piece,p, (oldtop_piece)=>{ let oldtop_p = pieces[oldtop_piece]!; p.z = info.z; -- 2.30.2