Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/wasm-application-runner.ts @ 466:5055031f4a06 bgo-commands-codegen
- Added browserify to build. This allows using require calls for modules that
work with tsc compiler.
- removed older stuff related to Protocol Buffers and Flatbuffers
- changed triple-slash references to import statements
- module prefixes are now added at call sites
- added cmake module for filename handling
- switched to Ninja for sample build
- Added virtual dtor in ICommand
author | bgo-osimis |
---|---|
date | Mon, 11 Feb 2019 16:00:04 +0100 |
parents | e641d3978856 |
children | 7105a0bad250 |
comparison
equal
deleted
inserted
replaced
448:cc47e6eaefb0 | 466:5055031f4a06 |
---|---|
1 ///<reference path='stone-framework-loader.ts'/> | 1 import Stone = require('./stone-framework-loader'); |
2 ///<reference path='wasm-viewport.ts'/> | 2 import StoneViewport = require('./wasm-viewport'); |
3 | 3 |
4 if (!('WebAssembly' in window)) { | 4 if (!('WebAssembly' in window)) { |
5 alert('Sorry, your browser does not support WebAssembly :('); | 5 alert('Sorry, your browser does not support WebAssembly :('); |
6 } | 6 } |
7 | 7 |
8 declare var StoneFrameworkModule : Stone.Framework; | 8 //var StoneFrameworkModule : Stone.Framework = (<any>window).StoneFrameworkModule; |
9 //export declare var StoneFrameworkModule : Stone.Framework; | |
9 | 10 |
10 // global functions | 11 // global functions |
11 var WasmWebService_NotifyError: Function = null; | 12 var WasmWebService_NotifyError: Function = null; |
12 var WasmWebService_NotifySuccess: Function = null; | 13 var WasmWebService_NotifySuccess: Function = null; |
13 var WasmWebService_NotifyCachedSuccess: Function = null; | 14 var WasmWebService_NotifyCachedSuccess: Function = null; |
14 var WasmDelayedCallExecutor_ExecuteCallback: Function = null; | 15 var WasmDelayedCallExecutor_ExecuteCallback: Function = null; |
15 var WasmDoAnimation: Function = null; | 16 var WasmDoAnimation: Function = null; |
16 var SetStartupParameter: Function = null; | 17 var SetStartupParameter: Function = null; |
17 var CreateWasmApplication: Function = null; | 18 var CreateWasmApplication: Function = null; |
18 var CreateCppViewport: Function = null; | 19 export var CreateCppViewport: Function = null; |
19 var ReleaseCppViewport: Function = null; | 20 var ReleaseCppViewport: Function = null; |
20 var StartWasmApplication: Function = null; | 21 var StartWasmApplication: Function = null; |
21 var SendMessageToStoneApplication: Function = null; | 22 export var SendMessageToStoneApplication: Function = null; |
22 | |
23 | 23 |
24 function DoAnimationThread() { | 24 function DoAnimationThread() { |
25 if (WasmDoAnimation != null) { | 25 if (WasmDoAnimation != null) { |
26 WasmDoAnimation(); | 26 WasmDoAnimation(); |
27 } | 27 } |
28 | 28 |
29 setTimeout(DoAnimationThread, 100); // Update the viewport content every 100ms if need be | 29 setTimeout(DoAnimationThread, 100); // Update the viewport content every 100ms if need be |
30 } | 30 } |
31 | |
32 | 31 |
33 function GetUriParameters(): Map<string, string> { | 32 function GetUriParameters(): Map<string, string> { |
34 var parameters = window.location.search.substr(1); | 33 var parameters = window.location.search.substr(1); |
35 | 34 |
36 if (parameters != null && | 35 if (parameters != null && |
70 } | 69 } |
71 | 70 |
72 StartWasmApplication(orthancBaseUrl); | 71 StartWasmApplication(orthancBaseUrl); |
73 | 72 |
74 // trigger a first resize of the canvas that has just been initialized | 73 // trigger a first resize of the canvas that has just been initialized |
75 Stone.WasmViewport.ResizeAll(); | 74 StoneViewport.WasmViewport.ResizeAll(); |
76 | 75 |
77 DoAnimationThread(); | 76 DoAnimationThread(); |
78 } | 77 } |
79 | 78 |
80 function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) { | 79 export function InitializeWasmApplication(wasmModuleName: string, orthancBaseUrl: string) { |
81 | 80 |
82 Stone.Framework.Configure(wasmModuleName); | 81 Stone.Framework.Configure(wasmModuleName); |
83 | 82 |
84 // Wait for the Orthanc Framework to be initialized (this initializes | 83 // Wait for the Orthanc Framework to be initialized (this initializes |
85 // the WebAssembly environment) and then, create and initialize the Wasm application | 84 // the WebAssembly environment) and then, create and initialize the Wasm application |
86 Stone.Framework.Initialize(true, function () { | 85 Stone.Framework.Initialize(true, function () { |
87 | 86 |
88 console.log("Connecting C++ methods to JS methods"); | 87 console.log("Connecting C++ methods to JS methods"); |
89 | 88 |
90 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); | 89 SetStartupParameter = (<any> window).StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']); |
91 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); | 90 CreateWasmApplication = (<any> window).StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']); |
92 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); | 91 CreateCppViewport = (<any> window).StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); |
93 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); | 92 ReleaseCppViewport = (<any> window).StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); |
94 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); | 93 StartWasmApplication = (<any> window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); |
95 | 94 |
96 WasmWebService_NotifyCachedSuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']); | 95 (<any> window).WasmWebService_NotifyCachedSuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']); |
97 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); | 96 (<any> window).WasmWebService_NotifySuccess = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']); |
98 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); | 97 (<any> window).WasmWebService_NotifyError = (<any> window).StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']); |
99 WasmDelayedCallExecutor_ExecuteCallback = StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']); | 98 (<any> window).WasmDelayedCallExecutor_ExecuteCallback = (<any> window).StoneFrameworkModule.cwrap('WasmDelayedCallExecutor_ExecuteCallback', null, ['number']); |
100 WasmDoAnimation = StoneFrameworkModule.cwrap('WasmDoAnimation', null, []); | 99 // no need to put this into the globals for it's only used in this very module |
100 WasmDoAnimation = (<any> window).StoneFrameworkModule.cwrap('WasmDoAnimation', null, []); | |
101 | 101 |
102 SendMessageToStoneApplication = StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']); | 102 SendMessageToStoneApplication = (<any> window).StoneFrameworkModule.cwrap('SendMessageToStoneApplication', 'string', ['string']); |
103 | 103 |
104 console.log("Connecting C++ methods to JS methods - done"); | 104 console.log("Connecting C++ methods to JS methods - done"); |
105 | 105 |
106 // Prevent scrolling | 106 // Prevent scrolling |
107 document.body.addEventListener('touchmove', function (event) { | 107 document.body.addEventListener('touchmove', function (event) { |
109 }, false); | 109 }, false); |
110 | 110 |
111 _InitializeWasmApplication(orthancBaseUrl); | 111 _InitializeWasmApplication(orthancBaseUrl); |
112 }); | 112 }); |
113 } | 113 } |
114 | |
115 | |
116 // exports.InitializeWasmApplication = InitializeWasmApplication; | |
117 | |
118 | |
119 |