annotate Platforms/Wasm/stone-framework-loader.ts @ 585:b9ce24c606ae

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