chiark / gitweb /
bigfloats seem to work now
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Oct 2020 22:44:40 +0000 (23:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Oct 2020 22:44:40 +0000 (23:44 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Makefile
templates/bigfloat.ts
templates/script.ts

index 78b175f57c974145ee2b84aeb5c17bd7912f06bf..43b4554b633a7647209a1395a7e0a5ae713d16ae 100644 (file)
--- 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 $@
index 89c3cd1efcb2592e49f59df7bf50caebb819f005..0fafc01288d98420cb58d89de4f8d8f09402f4ea 100644 (file)
@@ -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);
index 49c8632e28ed0974ce048635ff5c77e90d42df77..e6b207a1be0671fa1a440bce4fa7f63eea62bee9 100644 (file)
@@ -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 = <PieceHandler>function
 }
 
 pieceops.SetZLevel = <PieceHandler>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;