annotate Platforms/Wasm/wasm-application.ts @ 274:dc1beee33134 am-2

split SdlApplication into NativeApplication and SdlApplication
author am@osimis.io
date Fri, 24 Aug 2018 13:52:55 +0200
parents 65562a28fe05
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
225
am@osimis.io
parents:
diff changeset
1 ///<reference path='stone-framework-loader.ts'/>
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 226
diff changeset
2 ///<reference path='wasm-viewport.ts'/>
225
am@osimis.io
parents:
diff changeset
3
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
4 if (!('WebAssembly' in window)) {
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
5 alert('Sorry, your browser does not support WebAssembly :(');
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
6 }
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
7
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
8 declare var StoneFrameworkModule : Stone.Framework;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
9
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
10 // global functions
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
11 var WasmWebService_NotifyError: Function = null;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
12 var WasmWebService_NotifySuccess: Function = null;
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
13 var WasmWebService_SetBaseUri: Function = null;
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
14 var NotifyUpdateContent: Function = null;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
15 var SetStartupParameter: Function = null;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
16 var CreateWasmApplication: Function = null;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
17 var CreateCppViewport: Function = null;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
18 var ReleaseCppViewport: Function = null;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
19 var StartWasmApplication: Function = null;
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
20
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
21
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
22 function UpdateContentThread() {
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
23 if (NotifyUpdateContent != null) {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
24 NotifyUpdateContent();
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
25 }
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
26
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
27 setTimeout(UpdateContentThread, 100); // Update the viewport content every 100ms if need be
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
28 }
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
29
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
30
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
31 function GetUriParameters() {
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
32 var parameters = window.location.search.substr(1);
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
33
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
34 if (parameters != null &&
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
35 parameters != '') {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
36 var result = {};
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
37 var tokens = parameters.split('&');
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
38
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
39 for (var i = 0; i < tokens.length; i++) {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
40 var tmp = tokens[i].split('=');
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
41 if (tmp.length == 2) {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
42 result[tmp[0]] = decodeURIComponent(tmp[1]);
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
43 }
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
44 }
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
45
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
46 return result;
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
47 }
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
48 else {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
49 return {};
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
50 }
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
51 }
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
52
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 226
diff changeset
53 module Stone {
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
54
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
55 export class WasmApplication {
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
56
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
57 private viewport_: WasmViewport;
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
58 private canvasId_: string;
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
59
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
60 private pimpl_: any; // Private pointer to the underlying WebAssembly C++ object
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
61
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
62 public constructor(canvasId: string) {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
63 this.canvasId_ = canvasId;
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
64 //this.module_ = module;
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 226
diff changeset
65 }
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
66 }
229
b0ba3b38a23c ScheduleRedraw can handle multiple viewports
am@osimis.io
parents: 226
diff changeset
67 }
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
68
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
69
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
70 function _InitializeWasmApplication(canvasId: string, orthancBaseUrl: string): void {
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
71
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
72 /************************************** */
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
73 CreateWasmApplication();
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
74 WasmWebService_SetBaseUri(orthancBaseUrl);
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
75
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents: 225
diff changeset
76
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
77 // parse uri and transmit the parameters to the app before initializing it
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
78 var parameters = GetUriParameters();
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
79
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
80 for (var key in parameters) {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
81 if (parameters.hasOwnProperty(key)) {
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
82 SetStartupParameter(key, parameters[key]);
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
83 }
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
84 }
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
85
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
86 StartWasmApplication();
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
87 /************************************** */
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
88
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
89 UpdateContentThread();
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
90 }
226
1fa4c65c7e1b WasmViewport in ts
am@osimis.io
parents: 225
diff changeset
91
240
ddbb339ed4cf orthancBaseUrl is now configurable
am@osimis.io
parents: 238
diff changeset
92 function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) {
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
93
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
94 Stone.Framework.Configure(wasmModuleName);
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
95
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
96 // Wait for the Orthanc Framework to be initialized (this initializes
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
97 // the WebAssembly environment) and then, create and initialize the Wasm application
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
98 Stone.Framework.Initialize(true, function () {
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
99
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
100 console.log("Connecting C++ methods to JS methods");
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
101
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
102 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']);
231
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 230
diff changeset
103 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']);
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 230
diff changeset
104 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []);
5027cb2feb51 viewport is now part of the Application itself and not global anymore
am@osimis.io
parents: 230
diff changeset
105 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']);
233
68856534f005 added layout to VSOL, SDL & wasm working
am@osimis.io
parents: 231
diff changeset
106 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['number']);
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
107
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
108 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
109 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']);
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
110 WasmWebService_SetBaseUri = StoneFrameworkModule.cwrap('WasmWebService_SetBaseUri', null, ['string']);
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
111 NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, []);
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
112
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
113 console.log("Connecting C++ methods to JS methods - done - 2");
240
ddbb339ed4cf orthancBaseUrl is now configurable
am@osimis.io
parents: 238
diff changeset
114
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
115 // Prevent scrolling
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
116 document.body.addEventListener('touchmove', function (event) {
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
117 event.preventDefault();
230
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
118 }, false);
7d2631320615 wasm-application.js is now in ts
am@osimis.io
parents: 229
diff changeset
119
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
120 _InitializeWasmApplication("canvas", orthancBaseUrl);
238
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
121 });
126c9c0c9333 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
122 }