annotate Platforms/Wasm/stone-framework-loader.ts @ 242:092db46c6291 am

improved SDL/Wasm unification
author am@osimis.io
date Wed, 20 Jun 2018 14:20:55 +0200
parents 126c9c0c9333
children 5055031f4a06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
1 module Stone {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
2 /**
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
3 * This file contains primitives to interface with WebAssembly and
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
4 * with the Stone framework.
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
5 **/
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
6
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
7 export declare type InitializationCallback = () => void;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
8
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
9 export declare var StoneFrameworkModule : any;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
10
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
11 //const ASSETS_FOLDER : string = "assets/lib";
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
12 //const WASM_FILENAME : string = "orthanc-framework";
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
13
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
14
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
15 export class Framework
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
16 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
17 private static singleton_ : Framework = null;
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 237
diff changeset
18 private static wasmModuleName_ : string = null;
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 237
diff changeset
19
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 237
diff changeset
20 public static Configure(wasmModuleName: string) {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 237
diff changeset
21 this.wasmModuleName_ = wasmModuleName;
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 237
diff changeset
22 }
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 237
diff changeset
23
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
24 private constructor(verbose : boolean)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
25 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
26 //this.ccall('Initialize', null, [ 'number' ], [ verbose ]);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
27 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
28
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
29
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
30 public ccall(name: string,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
31 returnType: string,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
32 argTypes: Array<string>,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
33 argValues: Array<any>) : any
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
34 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
35 return StoneFrameworkModule.ccall(name, returnType, argTypes, argValues);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
36 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
37
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
38
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
39 public cwrap(name: string,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
40 returnType: string,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
41 argTypes: Array<string>) : any
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
42 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
43 return StoneFrameworkModule.cwrap(name, returnType, argTypes);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
44 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
45
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
46
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
47 public static GetInstance() : Framework
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
48 {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
49 if (Framework.singleton_ == null) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
50 throw new Error('The WebAssembly module is not loaded yet');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
51 } else {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
52 return Framework.singleton_;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
53 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
54 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
55
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
56
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
57 public static Initialize(verbose: boolean,
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
58 callback: InitializationCallback)
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
59 {
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 237
diff changeset
60 console.log('Initializing WebAssembly Module');
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
61
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
62 (<any> window).StoneFrameworkModule = {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
63 preRun: [
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
64 function() {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
65 console.log('Loading the Stone Framework using WebAssembly');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
66 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
67 ],
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
68 postRun: [
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
69 function() {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
70 // This function is called by ".js" wrapper once the ".wasm"
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
71 // WebAssembly module has been loaded and compiled by the
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
72 // browser
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
73 console.log('WebAssembly is ready');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
74 Framework.singleton_ = new Framework(verbose);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
75 callback();
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
76 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
77 ],
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
78 print: function(text : string) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
79 console.log(text);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
80 },
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
81 printErr: function(text : string) {
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
82 console.error(text);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
83 },
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
84 totalDependencies: 0
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
85 };
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
86
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
87 // Dynamic loading of the JavaScript wrapper around WebAssembly
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
88 var script = document.createElement('script');
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
89 script.type = 'application/javascript';
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
90 //script.src = "orthanc-stone.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 237
diff changeset
91 script.src = this.wasmModuleName_ + ".js";// "OrthancStoneSimpleViewer.js"; // ASSETS_FOLDER + '/' + WASM_FILENAME + '.js';
223
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
92 script.async = true;
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
93 document.head.appendChild(script);
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
94 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
95 }
d30a10d574ec refactoring continued - not working
am@osimis.io
parents:
diff changeset
96 }