This commit is contained in:
ajuvercr 2019-09-17 18:27:44 +02:00
parent a7e7218417
commit 1f18f3d16f
4 changed files with 13 additions and 17 deletions

View file

@ -1,5 +1,6 @@
// A dependency graph that contains any wasm must all be imported // A dependency graph that contains any wasm must all be imported
// asynchronously. This `bootstrap.js` file does the single async import, so // asynchronously. This `bootstrap.js` file does the single async import, so
// that no one else needs to worry about it again. // that no one else needs to worry about it again.
// Import index.js that executes index.ts
import("./index.js") import("./index.js")
.catch(e => console.error("Error importing `index.js`:", e)); .catch(e => console.error("Error importing `index.js`:", e));

View file

@ -5,6 +5,8 @@
<title>Hello wasm-pack!</title> <title>Hello wasm-pack!</title>
</head> </head>
<body> <body>
<canvas id="c" width=1700 height=900></canvas>
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript> <noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
<script src="./bootstrap.js"></script> <script src="./bootstrap.js"></script>
</body> </body>

View file

@ -1,5 +1,4 @@
import { Game } from "planetwars"; import { Game } from "planetwars";
import { memory } from "planetwars/plantwars_bg"
import { Shader } from "./webgl/shader" import { Shader } from "./webgl/shader"
import { main } from './index.ts' import { main } from './index.ts'
@ -14,19 +13,3 @@ fetch(game_location)
.then((response) => { .then((response) => {
main(Game.new(response)); main(Game.new(response));
}).catch(console.error); }).catch(console.error);
// const g = Game.new("");
// const p1 = g.locations();
// const s1 = g.location_count();
// console.log(p1, s1);
// const a1 = new Float64Array(memory.buffer, p1, s1 * 3);
// console.log(a1);
// g.add_location(0.5, 1.2, 3.14);
// const p2 = g.locations();
// const s2 = g.location_count();
// const a2 = new Float64Array(memory.buffer, p2, s2 * 3);
// console.log(a2);

View file

@ -1,5 +1,15 @@
import { Game } from "planetwars"; import { Game } from "planetwars";
import { memory } from "planetwars/plantwars_bg";
const CANVAS = <HTMLCanvasElement>document.getElementById("c");
function create_array(ptr: number, size: number): Float64Array {
return new Float64Array(memory.buffer, ptr, size);
}
export function main(game: Game) { export function main(game: Game) {
console.log(game.turn_count()); console.log(game.turn_count());
console.log(create_array(game.get_viewbox(), 4));
} }