| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660 |
- // The Module object: Our interface to the outside world. We import
- // and export values on it. There are various ways Module can be used:
- // 1. Not defined. We create it here
- // 2. A function parameter, function(Module) { ..generated code.. }
- // 3. pre-run appended it, var Module = {}; ..generated code..
- // 4. External script tag defines var Module.
- // We need to check if Module already exists (e.g. case 3 above).
- // Substitution will be replaced with actual code on later stage of the build,
- // this way Closure Compiler will not mangle it (e.g. case 4. above).
- // Note that if you want to run closure, and also to use Module
- // after the generated code, you will need to define var Module = {};
- // before the code. Then that object will be used in the code, and you
- // can continue to use Module afterwards as well.
- var Module = typeof Module !== 'undefined' ? Module : {};
- // --pre-jses are emitted after the Module integration code, so that they can
- // refer to Module (if they choose; they can also define Module)
- // {{PRE_JSES}}
- // Sometimes an existing Module object exists with properties
- // meant to overwrite the default module functionality. Here
- // we collect those properties and reapply _after_ we configure
- // the current environment's defaults to avoid having to be so
- // defensive during initialization.
- var moduleOverrides = {};
- var key;
- for (key in Module) {
- if (Module.hasOwnProperty(key)) {
- moduleOverrides[key] = Module[key];
- }
- }
- var arguments_ = [];
- var thisProgram = './this.program';
- var quit_ = function(status, toThrow) {
- throw toThrow;
- };
- // Determine the runtime environment we are in. You can customize this by
- // setting the ENVIRONMENT setting at compile time (see settings.js).
- var ENVIRONMENT_IS_WEB = false;
- var ENVIRONMENT_IS_WORKER = false;
- var ENVIRONMENT_IS_NODE = false;
- var ENVIRONMENT_IS_SHELL = false;
- ENVIRONMENT_IS_WEB = typeof window === 'object';
- ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
- // N.b. Electron.js environment is simultaneously a NODE-environment, but
- // also a web environment.
- ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
- ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
- // `/` should be present at the end if `scriptDirectory` is not empty
- var scriptDirectory = '';
- function locateFile(path) {
- if (Module['locateFile']) {
- return Module['locateFile'](path, scriptDirectory);
- }
- return scriptDirectory + path;
- }
- // Hooks that are implemented differently in different runtime environments.
- var read_,
- readAsync,
- readBinary,
- setWindowTitle;
- var nodeFS;
- var nodePath;
- if (ENVIRONMENT_IS_NODE) {
- if (ENVIRONMENT_IS_WORKER) {
- scriptDirectory = require('path').dirname(scriptDirectory) + '/';
- } else {
- scriptDirectory = __dirname + '/';
- }
- // include: node_shell_read.js
- read_ = function shell_read(filename, binary) {
- if (!nodeFS) nodeFS = require('fs');
- if (!nodePath) nodePath = require('path');
- filename = nodePath['normalize'](filename);
- return nodeFS['readFileSync'](filename, binary ? null : 'utf8');
- };
- readBinary = function readBinary(filename) {
- var ret = read_(filename, true);
- if (!ret.buffer) {
- ret = new Uint8Array(ret);
- }
- assert(ret.buffer);
- return ret;
- };
- // end include: node_shell_read.js
- if (process['argv'].length > 1) {
- thisProgram = process['argv'][1].replace(/\\/g, '/');
- }
- arguments_ = process['argv'].slice(2);
- if (typeof module !== 'undefined') {
- module['exports'] = Module;
- }
- process['on']('uncaughtException', function(ex) {
- // suppress ExitStatus exceptions from showing an error
- if (!(ex instanceof ExitStatus)) {
- throw ex;
- }
- });
- process['on']('unhandledRejection', abort);
- quit_ = function(status) {
- process['exit'](status);
- };
- Module['inspect'] = function () { return '[Emscripten Module object]'; };
- } else
- if (ENVIRONMENT_IS_SHELL) {
- if (typeof read != 'undefined') {
- read_ = function shell_read(f) {
- return read(f);
- };
- }
- readBinary = function readBinary(f) {
- var data;
- if (typeof readbuffer === 'function') {
- return new Uint8Array(readbuffer(f));
- }
- data = read(f, 'binary');
- assert(typeof data === 'object');
- return data;
- };
- if (typeof scriptArgs != 'undefined') {
- arguments_ = scriptArgs;
- } else if (typeof arguments != 'undefined') {
- arguments_ = arguments;
- }
- if (typeof quit === 'function') {
- quit_ = function(status) {
- quit(status);
- };
- }
- if (typeof print !== 'undefined') {
- // Prefer to use print/printErr where they exist, as they usually work better.
- if (typeof console === 'undefined') console = /** @type{!Console} */({});
- console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
- console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr !== 'undefined' ? printErr : print);
- }
- } else
- // Note that this includes Node.js workers when relevant (pthreads is enabled).
- // Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
- // ENVIRONMENT_IS_NODE.
- if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
- if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
- scriptDirectory = self.location.href;
- } else if (typeof document !== 'undefined' && document.currentScript) { // web
- scriptDirectory = document.currentScript.src;
- }
- // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them.
- // otherwise, slice off the final part of the url to find the script directory.
- // if scriptDirectory does not contain a slash, lastIndexOf will return -1,
- // and scriptDirectory will correctly be replaced with an empty string.
- if (scriptDirectory.indexOf('blob:') !== 0) {
- scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/')+1);
- } else {
- scriptDirectory = '';
- }
- // Differentiate the Web Worker from the Node Worker case, as reading must
- // be done differently.
- {
- // include: web_or_worker_shell_read.js
- read_ = function(url) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, false);
- xhr.send(null);
- return xhr.responseText;
- };
- if (ENVIRONMENT_IS_WORKER) {
- readBinary = function(url) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, false);
- xhr.responseType = 'arraybuffer';
- xhr.send(null);
- return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response));
- };
- }
- readAsync = function(url, onload, onerror) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.responseType = 'arraybuffer';
- xhr.onload = function() {
- if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
- onload(xhr.response);
- return;
- }
- onerror();
- };
- xhr.onerror = onerror;
- xhr.send(null);
- };
- // end include: web_or_worker_shell_read.js
- }
- setWindowTitle = function(title) { document.title = title };
- } else
- {
- }
- // Set up the out() and err() hooks, which are how we can print to stdout or
- // stderr, respectively.
- var out = Module['print'] || console.log.bind(console);
- var err = Module['printErr'] || console.warn.bind(console);
- // Merge back in the overrides
- for (key in moduleOverrides) {
- if (moduleOverrides.hasOwnProperty(key)) {
- Module[key] = moduleOverrides[key];
- }
- }
- // Free the object hierarchy contained in the overrides, this lets the GC
- // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array.
- moduleOverrides = null;
- // Emit code to handle expected values on the Module object. This applies Module.x
- // to the proper local x. This has two benefits: first, we only emit it if it is
- // expected to arrive, and second, by using a local everywhere else that can be
- // minified.
- if (Module['arguments']) arguments_ = Module['arguments'];
- if (Module['thisProgram']) thisProgram = Module['thisProgram'];
- if (Module['quit']) quit_ = Module['quit'];
- // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message
- var STACK_ALIGN = 16;
- function alignMemory(size, factor) {
- if (!factor) factor = STACK_ALIGN; // stack alignment (16-byte) by default
- return Math.ceil(size / factor) * factor;
- }
- function getNativeTypeSize(type) {
- switch (type) {
- case 'i1': case 'i8': return 1;
- case 'i16': return 2;
- case 'i32': return 4;
- case 'i64': return 8;
- case 'float': return 4;
- case 'double': return 8;
- default: {
- if (type[type.length-1] === '*') {
- return 4; // A pointer
- } else if (type[0] === 'i') {
- var bits = Number(type.substr(1));
- assert(bits % 8 === 0, 'getNativeTypeSize invalid bits ' + bits + ', type ' + type);
- return bits / 8;
- } else {
- return 0;
- }
- }
- }
- }
- function warnOnce(text) {
- if (!warnOnce.shown) warnOnce.shown = {};
- if (!warnOnce.shown[text]) {
- warnOnce.shown[text] = 1;
- err(text);
- }
- }
- // include: runtime_functions.js
- // Wraps a JS function as a wasm function with a given signature.
- function convertJsFunctionToWasm(func, sig) {
- // If the type reflection proposal is available, use the new
- // "WebAssembly.Function" constructor.
- // Otherwise, construct a minimal wasm module importing the JS function and
- // re-exporting it.
- if (typeof WebAssembly.Function === "function") {
- var typeNames = {
- 'i': 'i32',
- 'j': 'i64',
- 'f': 'f32',
- 'd': 'f64'
- };
- var type = {
- parameters: [],
- results: sig[0] == 'v' ? [] : [typeNames[sig[0]]]
- };
- for (var i = 1; i < sig.length; ++i) {
- type.parameters.push(typeNames[sig[i]]);
- }
- return new WebAssembly.Function(type, func);
- }
- // The module is static, with the exception of the type section, which is
- // generated based on the signature passed in.
- var typeSection = [
- 0x01, // id: section,
- 0x00, // length: 0 (placeholder)
- 0x01, // count: 1
- 0x60, // form: func
- ];
- var sigRet = sig.slice(0, 1);
- var sigParam = sig.slice(1);
- var typeCodes = {
- 'i': 0x7f, // i32
- 'j': 0x7e, // i64
- 'f': 0x7d, // f32
- 'd': 0x7c, // f64
- };
- // Parameters, length + signatures
- typeSection.push(sigParam.length);
- for (var i = 0; i < sigParam.length; ++i) {
- typeSection.push(typeCodes[sigParam[i]]);
- }
- // Return values, length + signatures
- // With no multi-return in MVP, either 0 (void) or 1 (anything else)
- if (sigRet == 'v') {
- typeSection.push(0x00);
- } else {
- typeSection = typeSection.concat([0x01, typeCodes[sigRet]]);
- }
- // Write the overall length of the type section back into the section header
- // (excepting the 2 bytes for the section id and length)
- typeSection[1] = typeSection.length - 2;
- // Rest of the module is static
- var bytes = new Uint8Array([
- 0x00, 0x61, 0x73, 0x6d, // magic ("\0asm")
- 0x01, 0x00, 0x00, 0x00, // version: 1
- ].concat(typeSection, [
- 0x02, 0x07, // import section
- // (import "e" "f" (func 0 (type 0)))
- 0x01, 0x01, 0x65, 0x01, 0x66, 0x00, 0x00,
- 0x07, 0x05, // export section
- // (export "f" (func 0 (type 0)))
- 0x01, 0x01, 0x66, 0x00, 0x00,
- ]));
- // We can compile this wasm module synchronously because it is very small.
- // This accepts an import (at "e.f"), that it reroutes to an export (at "f")
- var module = new WebAssembly.Module(bytes);
- var instance = new WebAssembly.Instance(module, {
- 'e': {
- 'f': func
- }
- });
- var wrappedFunc = instance.exports['f'];
- return wrappedFunc;
- }
- var freeTableIndexes = [];
- // Weak map of functions in the table to their indexes, created on first use.
- var functionsInTableMap;
- function getEmptyTableSlot() {
- // Reuse a free index if there is one, otherwise grow.
- if (freeTableIndexes.length) {
- return freeTableIndexes.pop();
- }
- // Grow the table
- try {
- wasmTable.grow(1);
- } catch (err) {
- if (!(err instanceof RangeError)) {
- throw err;
- }
- throw 'Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.';
- }
- return wasmTable.length - 1;
- }
- // Add a wasm function to the table.
- function addFunctionWasm(func, sig) {
- // Check if the function is already in the table, to ensure each function
- // gets a unique index. First, create the map if this is the first use.
- if (!functionsInTableMap) {
- functionsInTableMap = new WeakMap();
- for (var i = 0; i < wasmTable.length; i++) {
- var item = wasmTable.get(i);
- // Ignore null values.
- if (item) {
- functionsInTableMap.set(item, i);
- }
- }
- }
- if (functionsInTableMap.has(func)) {
- return functionsInTableMap.get(func);
- }
- // It's not in the table, add it now.
- var ret = getEmptyTableSlot();
- // Set the new value.
- try {
- // Attempting to call this with JS function will cause of table.set() to fail
- wasmTable.set(ret, func);
- } catch (err) {
- if (!(err instanceof TypeError)) {
- throw err;
- }
- var wrapped = convertJsFunctionToWasm(func, sig);
- wasmTable.set(ret, wrapped);
- }
- functionsInTableMap.set(func, ret);
- return ret;
- }
- function removeFunction(index) {
- functionsInTableMap.delete(wasmTable.get(index));
- freeTableIndexes.push(index);
- }
- // 'sig' parameter is required for the llvm backend but only when func is not
- // already a WebAssembly function.
- function addFunction(func, sig) {
- return addFunctionWasm(func, sig);
- }
- // end include: runtime_functions.js
- // include: runtime_debug.js
- // end include: runtime_debug.js
- function makeBigInt(low, high, unsigned) {
- return unsigned ? ((+((low>>>0)))+((+((high>>>0)))*4294967296.0)) : ((+((low>>>0)))+((+((high|0)))*4294967296.0));
- }
- var tempRet0 = 0;
- var setTempRet0 = function(value) {
- tempRet0 = value;
- };
- var getTempRet0 = function() {
- return tempRet0;
- };
- // === Preamble library stuff ===
- // Documentation for the public APIs defined in this file must be updated in:
- // site/source/docs/api_reference/preamble.js.rst
- // A prebuilt local version of the documentation is available at:
- // site/build/text/docs/api_reference/preamble.js.txt
- // You can also build docs locally as HTML or other formats in site/
- // An online HTML version (which may be of a different version of Emscripten)
- // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
- var wasmBinary;if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
- var noExitRuntime;if (Module['noExitRuntime']) noExitRuntime = Module['noExitRuntime'];
- if (typeof WebAssembly !== 'object') {
- abort('no native wasm support detected');
- }
- // include: runtime_safe_heap.js
- // In MINIMAL_RUNTIME, setValue() and getValue() are only available when building with safe heap enabled, for heap safety checking.
- // In traditional runtime, setValue() and getValue() are always available (although their use is highly discouraged due to perf penalties)
- /** @param {number} ptr
- @param {number} value
- @param {string} type
- @param {number|boolean=} noSafe */
- function setValue(ptr, value, type, noSafe) {
- type = type || 'i8';
- if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
- switch(type) {
- case 'i1': HEAP8[((ptr)>>0)] = value; break;
- case 'i8': HEAP8[((ptr)>>0)] = value; break;
- case 'i16': HEAP16[((ptr)>>1)] = value; break;
- case 'i32': HEAP32[((ptr)>>2)] = value; break;
- case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math.min((+(Math.floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((ptr)>>2)] = tempI64[0],HEAP32[(((ptr)+(4))>>2)] = tempI64[1]); break;
- case 'float': HEAPF32[((ptr)>>2)] = value; break;
- case 'double': HEAPF64[((ptr)>>3)] = value; break;
- default: abort('invalid type for setValue: ' + type);
- }
- }
- /** @param {number} ptr
- @param {string} type
- @param {number|boolean=} noSafe */
- function getValue(ptr, type, noSafe) {
- type = type || 'i8';
- if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
- switch(type) {
- case 'i1': return HEAP8[((ptr)>>0)];
- case 'i8': return HEAP8[((ptr)>>0)];
- case 'i16': return HEAP16[((ptr)>>1)];
- case 'i32': return HEAP32[((ptr)>>2)];
- case 'i64': return HEAP32[((ptr)>>2)];
- case 'float': return HEAPF32[((ptr)>>2)];
- case 'double': return HEAPF64[((ptr)>>3)];
- default: abort('invalid type for getValue: ' + type);
- }
- return null;
- }
- // end include: runtime_safe_heap.js
- // Wasm globals
- var wasmMemory;
- //========================================
- // Runtime essentials
- //========================================
- // whether we are quitting the application. no code should run after this.
- // set in exit() and abort()
- var ABORT = false;
- // set by exit() and abort(). Passed to 'onExit' handler.
- // NOTE: This is also used as the process return code code in shell environments
- // but only when noExitRuntime is false.
- var EXITSTATUS;
- /** @type {function(*, string=)} */
- function assert(condition, text) {
- if (!condition) {
- abort('Assertion failed: ' + text);
- }
- }
- // Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
- function getCFunc(ident) {
- var func = Module['_' + ident]; // closure exported function
- assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
- return func;
- }
- // C calling interface.
- /** @param {string|null=} returnType
- @param {Array=} argTypes
- @param {Arguments|Array=} args
- @param {Object=} opts */
- function ccall(ident, returnType, argTypes, args, opts) {
- // For fast lookup of conversion functions
- var toC = {
- 'string': function(str) {
- var ret = 0;
- if (str !== null && str !== undefined && str !== 0) { // null string
- // at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
- var len = (str.length << 2) + 1;
- ret = stackAlloc(len);
- stringToUTF8(str, ret, len);
- }
- return ret;
- },
- 'array': function(arr) {
- var ret = stackAlloc(arr.length);
- writeArrayToMemory(arr, ret);
- return ret;
- }
- };
- function convertReturnValue(ret) {
- if (returnType === 'string') return UTF8ToString(ret);
- if (returnType === 'boolean') return Boolean(ret);
- return ret;
- }
- var func = getCFunc(ident);
- var cArgs = [];
- var stack = 0;
- if (args) {
- for (var i = 0; i < args.length; i++) {
- var converter = toC[argTypes[i]];
- if (converter) {
- if (stack === 0) stack = stackSave();
- cArgs[i] = converter(args[i]);
- } else {
- cArgs[i] = args[i];
- }
- }
- }
- var ret = func.apply(null, cArgs);
- var asyncMode = opts && opts.async;
- var runningAsync = typeof Asyncify === 'object' && Asyncify.currData;
- var prevRunningAsync = typeof Asyncify === 'object' && Asyncify.asyncFinalizers.length > 0;
- // Check if we started an async operation just now.
- if (runningAsync && !prevRunningAsync) {
- // If so, the WASM function ran asynchronous and unwound its stack.
- // We need to return a Promise that resolves the return value
- // once the stack is rewound and execution finishes.
- return new Promise(function(resolve) {
- Asyncify.asyncFinalizers.push(function(ret) {
- if (stack !== 0) stackRestore(stack);
- resolve(convertReturnValue(ret));
- });
- });
- }
- ret = convertReturnValue(ret);
- if (stack !== 0) stackRestore(stack);
- // If this is an async ccall, ensure we return a promise
- if (opts && opts.async) return Promise.resolve(ret);
- return ret;
- }
- /** @param {string=} returnType
- @param {Array=} argTypes
- @param {Object=} opts */
- function cwrap(ident, returnType, argTypes, opts) {
- argTypes = argTypes || [];
- // When the function takes numbers and returns a number, we can just return
- // the original function
- var numericArgs = argTypes.every(function(type){ return type === 'number'});
- var numericRet = returnType !== 'string';
- if (numericRet && numericArgs && !opts) {
- return getCFunc(ident);
- }
- return function() {
- return ccall(ident, returnType, argTypes, arguments, opts);
- }
- }
- var ALLOC_NORMAL = 0; // Tries to use _malloc()
- var ALLOC_STACK = 1; // Lives for the duration of the current function call
- // allocate(): This is for internal use. You can use it yourself as well, but the interface
- // is a little tricky (see docs right below). The reason is that it is optimized
- // for multiple syntaxes to save space in generated code. So you should
- // normally not use allocate(), and instead allocate memory using _malloc(),
- // initialize it with setValue(), and so forth.
- // @slab: An array of data.
- // @allocator: How to allocate memory, see ALLOC_*
- /** @type {function((Uint8Array|Array<number>), number)} */
- function allocate(slab, allocator) {
- var ret;
- if (allocator == ALLOC_STACK) {
- ret = stackAlloc(slab.length);
- } else {
- ret = _malloc(slab.length);
- }
- if (slab.subarray || slab.slice) {
- HEAPU8.set(/** @type {!Uint8Array} */(slab), ret);
- } else {
- HEAPU8.set(new Uint8Array(slab), ret);
- }
- return ret;
- }
- // include: runtime_strings.js
- // runtime_strings.js: Strings related runtime functions that are part of both MINIMAL_RUNTIME and regular runtime.
- // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns
- // a copy of that string as a Javascript String object.
- var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined;
- /**
- * @param {number} idx
- * @param {number=} maxBytesToRead
- * @return {string}
- */
- function UTF8ArrayToString(heap, idx, maxBytesToRead) {
- var endIdx = idx + maxBytesToRead;
- var endPtr = idx;
- // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
- // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
- // (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity)
- while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr;
- if (endPtr - idx > 16 && heap.subarray && UTF8Decoder) {
- return UTF8Decoder.decode(heap.subarray(idx, endPtr));
- } else {
- var str = '';
- // If building with TextDecoder, we have already computed the string length above, so test loop end condition against that
- while (idx < endPtr) {
- // For UTF8 byte structure, see:
- // http://en.wikipedia.org/wiki/UTF-8#Description
- // https://www.ietf.org/rfc/rfc2279.txt
- // https://tools.ietf.org/html/rfc3629
- var u0 = heap[idx++];
- if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; }
- var u1 = heap[idx++] & 63;
- if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; }
- var u2 = heap[idx++] & 63;
- if ((u0 & 0xF0) == 0xE0) {
- u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
- } else {
- u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heap[idx++] & 63);
- }
- if (u0 < 0x10000) {
- str += String.fromCharCode(u0);
- } else {
- var ch = u0 - 0x10000;
- str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
- }
- }
- }
- return str;
- }
- // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a
- // copy of that string as a Javascript String object.
- // maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit
- // this parameter to scan the string until the first \0 byte. If maxBytesToRead is
- // passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the
- // middle, then the string will cut short at that byte index (i.e. maxBytesToRead will
- // not produce a string of exact length [ptr, ptr+maxBytesToRead[)
- // N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may
- // throw JS JIT optimizations off, so it is worth to consider consistently using one
- // style or the other.
- /**
- * @param {number} ptr
- * @param {number=} maxBytesToRead
- * @return {string}
- */
- function UTF8ToString(ptr, maxBytesToRead) {
- return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
- }
- // Copies the given Javascript String object 'str' to the given byte array at address 'outIdx',
- // encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP.
- // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
- // Parameters:
- // str: the Javascript string to copy.
- // heap: the array to copy to. Each index in this array is assumed to be one 8-byte element.
- // outIdx: The starting offset in the array to begin the copying.
- // maxBytesToWrite: The maximum number of bytes this function can write to the array.
- // This count should include the null terminator,
- // i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else.
- // maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator.
- // Returns the number of bytes written, EXCLUDING the null terminator.
- function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
- if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes.
- return 0;
- var startIdx = outIdx;
- var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator.
- for (var i = 0; i < str.length; ++i) {
- // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
- // See http://unicode.org/faq/utf_bom.html#utf16-3
- // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629
- var u = str.charCodeAt(i); // possibly a lead surrogate
- if (u >= 0xD800 && u <= 0xDFFF) {
- var u1 = str.charCodeAt(++i);
- u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF);
- }
- if (u <= 0x7F) {
- if (outIdx >= endIdx) break;
- heap[outIdx++] = u;
- } else if (u <= 0x7FF) {
- if (outIdx + 1 >= endIdx) break;
- heap[outIdx++] = 0xC0 | (u >> 6);
- heap[outIdx++] = 0x80 | (u & 63);
- } else if (u <= 0xFFFF) {
- if (outIdx + 2 >= endIdx) break;
- heap[outIdx++] = 0xE0 | (u >> 12);
- heap[outIdx++] = 0x80 | ((u >> 6) & 63);
- heap[outIdx++] = 0x80 | (u & 63);
- } else {
- if (outIdx + 3 >= endIdx) break;
- heap[outIdx++] = 0xF0 | (u >> 18);
- heap[outIdx++] = 0x80 | ((u >> 12) & 63);
- heap[outIdx++] = 0x80 | ((u >> 6) & 63);
- heap[outIdx++] = 0x80 | (u & 63);
- }
- }
- // Null-terminate the pointer to the buffer.
- heap[outIdx] = 0;
- return outIdx - startIdx;
- }
- // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
- // null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP.
- // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write.
- // Returns the number of bytes written, EXCLUDING the null terminator.
- function stringToUTF8(str, outPtr, maxBytesToWrite) {
- return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite);
- }
- // Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte.
- function lengthBytesUTF8(str) {
- var len = 0;
- for (var i = 0; i < str.length; ++i) {
- // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8.
- // See http://unicode.org/faq/utf_bom.html#utf16-3
- var u = str.charCodeAt(i); // possibly a lead surrogate
- if (u >= 0xD800 && u <= 0xDFFF) u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF);
- if (u <= 0x7F) ++len;
- else if (u <= 0x7FF) len += 2;
- else if (u <= 0xFFFF) len += 3;
- else len += 4;
- }
- return len;
- }
- // end include: runtime_strings.js
- // include: runtime_strings_extra.js
- // runtime_strings_extra.js: Strings related runtime functions that are available only in regular runtime.
- // Given a pointer 'ptr' to a null-terminated ASCII-encoded string in the emscripten HEAP, returns
- // a copy of that string as a Javascript String object.
- function AsciiToString(ptr) {
- var str = '';
- while (1) {
- var ch = HEAPU8[((ptr++)>>0)];
- if (!ch) return str;
- str += String.fromCharCode(ch);
- }
- }
- // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
- // null-terminated and encoded in ASCII form. The copy will require at most str.length+1 bytes of space in the HEAP.
- function stringToAscii(str, outPtr) {
- return writeAsciiToMemory(str, outPtr, false);
- }
- // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
- // a copy of that string as a Javascript String object.
- var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined;
- function UTF16ToString(ptr, maxBytesToRead) {
- var endPtr = ptr;
- // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself.
- // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage.
- var idx = endPtr >> 1;
- var maxIdx = idx + maxBytesToRead / 2;
- // If maxBytesToRead is not passed explicitly, it will be undefined, and this
- // will always evaluate to true. This saves on code size.
- while (!(idx >= maxIdx) && HEAPU16[idx]) ++idx;
- endPtr = idx << 1;
- if (endPtr - ptr > 32 && UTF16Decoder) {
- return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
- } else {
- var str = '';
- // If maxBytesToRead is not passed explicitly, it will be undefined, and the for-loop's condition
- // will always evaluate to true. The loop is then terminated on the first null char.
- for (var i = 0; !(i >= maxBytesToRead / 2); ++i) {
- var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
- if (codeUnit == 0) break;
- // fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
- str += String.fromCharCode(codeUnit);
- }
- return str;
- }
- }
- // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
- // null-terminated and encoded in UTF16 form. The copy will require at most str.length*4+2 bytes of space in the HEAP.
- // Use the function lengthBytesUTF16() to compute the exact number of bytes (excluding null terminator) that this function will write.
- // Parameters:
- // str: the Javascript string to copy.
- // outPtr: Byte address in Emscripten HEAP where to write the string to.
- // maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null
- // terminator, i.e. if maxBytesToWrite=2, only the null terminator will be written and nothing else.
- // maxBytesToWrite<2 does not write any bytes to the output, not even the null terminator.
- // Returns the number of bytes written, EXCLUDING the null terminator.
- function stringToUTF16(str, outPtr, maxBytesToWrite) {
- // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
- if (maxBytesToWrite === undefined) {
- maxBytesToWrite = 0x7FFFFFFF;
- }
- if (maxBytesToWrite < 2) return 0;
- maxBytesToWrite -= 2; // Null terminator.
- var startPtr = outPtr;
- var numCharsToWrite = (maxBytesToWrite < str.length*2) ? (maxBytesToWrite / 2) : str.length;
- for (var i = 0; i < numCharsToWrite; ++i) {
- // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
- var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
- HEAP16[((outPtr)>>1)] = codeUnit;
- outPtr += 2;
- }
- // Null-terminate the pointer to the HEAP.
- HEAP16[((outPtr)>>1)] = 0;
- return outPtr - startPtr;
- }
- // Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
- function lengthBytesUTF16(str) {
- return str.length*2;
- }
- function UTF32ToString(ptr, maxBytesToRead) {
- var i = 0;
- var str = '';
- // If maxBytesToRead is not passed explicitly, it will be undefined, and this
- // will always evaluate to true. This saves on code size.
- while (!(i >= maxBytesToRead / 4)) {
- var utf32 = HEAP32[(((ptr)+(i*4))>>2)];
- if (utf32 == 0) break;
- ++i;
- // Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing.
- // See http://unicode.org/faq/utf_bom.html#utf16-3
- if (utf32 >= 0x10000) {
- var ch = utf32 - 0x10000;
- str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
- } else {
- str += String.fromCharCode(utf32);
- }
- }
- return str;
- }
- // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
- // null-terminated and encoded in UTF32 form. The copy will require at most str.length*4+4 bytes of space in the HEAP.
- // Use the function lengthBytesUTF32() to compute the exact number of bytes (excluding null terminator) that this function will write.
- // Parameters:
- // str: the Javascript string to copy.
- // outPtr: Byte address in Emscripten HEAP where to write the string to.
- // maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null
- // terminator, i.e. if maxBytesToWrite=4, only the null terminator will be written and nothing else.
- // maxBytesToWrite<4 does not write any bytes to the output, not even the null terminator.
- // Returns the number of bytes written, EXCLUDING the null terminator.
- function stringToUTF32(str, outPtr, maxBytesToWrite) {
- // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed.
- if (maxBytesToWrite === undefined) {
- maxBytesToWrite = 0x7FFFFFFF;
- }
- if (maxBytesToWrite < 4) return 0;
- var startPtr = outPtr;
- var endPtr = startPtr + maxBytesToWrite - 4;
- for (var i = 0; i < str.length; ++i) {
- // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
- // See http://unicode.org/faq/utf_bom.html#utf16-3
- var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
- if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
- var trailSurrogate = str.charCodeAt(++i);
- codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
- }
- HEAP32[((outPtr)>>2)] = codeUnit;
- outPtr += 4;
- if (outPtr + 4 > endPtr) break;
- }
- // Null-terminate the pointer to the HEAP.
- HEAP32[((outPtr)>>2)] = 0;
- return outPtr - startPtr;
- }
- // Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte.
- function lengthBytesUTF32(str) {
- var len = 0;
- for (var i = 0; i < str.length; ++i) {
- // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
- // See http://unicode.org/faq/utf_bom.html#utf16-3
- var codeUnit = str.charCodeAt(i);
- if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) ++i; // possibly a lead surrogate, so skip over the tail surrogate.
- len += 4;
- }
- return len;
- }
- // Allocate heap space for a JS string, and write it there.
- // It is the responsibility of the caller to free() that memory.
- function allocateUTF8(str) {
- var size = lengthBytesUTF8(str) + 1;
- var ret = _malloc(size);
- if (ret) stringToUTF8Array(str, HEAP8, ret, size);
- return ret;
- }
- // Allocate stack space for a JS string, and write it there.
- function allocateUTF8OnStack(str) {
- var size = lengthBytesUTF8(str) + 1;
- var ret = stackAlloc(size);
- stringToUTF8Array(str, HEAP8, ret, size);
- return ret;
- }
- // Deprecated: This function should not be called because it is unsafe and does not provide
- // a maximum length limit of how many bytes it is allowed to write. Prefer calling the
- // function stringToUTF8Array() instead, which takes in a maximum length that can be used
- // to be secure from out of bounds writes.
- /** @deprecated
- @param {boolean=} dontAddNull */
- function writeStringToMemory(string, buffer, dontAddNull) {
- warnOnce('writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!');
- var /** @type {number} */ lastChar, /** @type {number} */ end;
- if (dontAddNull) {
- // stringToUTF8Array always appends null. If we don't want to do that, remember the
- // character that existed at the location where the null will be placed, and restore
- // that after the write (below).
- end = buffer + lengthBytesUTF8(string);
- lastChar = HEAP8[end];
- }
- stringToUTF8(string, buffer, Infinity);
- if (dontAddNull) HEAP8[end] = lastChar; // Restore the value under the null character.
- }
- function writeArrayToMemory(array, buffer) {
- HEAP8.set(array, buffer);
- }
- /** @param {boolean=} dontAddNull */
- function writeAsciiToMemory(str, buffer, dontAddNull) {
- for (var i = 0; i < str.length; ++i) {
- HEAP8[((buffer++)>>0)] = str.charCodeAt(i);
- }
- // Null-terminate the pointer to the HEAP.
- if (!dontAddNull) HEAP8[((buffer)>>0)] = 0;
- }
- // end include: runtime_strings_extra.js
- // Memory management
- function alignUp(x, multiple) {
- if (x % multiple > 0) {
- x += multiple - (x % multiple);
- }
- return x;
- }
- var HEAP,
- /** @type {ArrayBuffer} */
- buffer,
- /** @type {Int8Array} */
- HEAP8,
- /** @type {Uint8Array} */
- HEAPU8,
- /** @type {Int16Array} */
- HEAP16,
- /** @type {Uint16Array} */
- HEAPU16,
- /** @type {Int32Array} */
- HEAP32,
- /** @type {Uint32Array} */
- HEAPU32,
- /** @type {Float32Array} */
- HEAPF32,
- /** @type {Float64Array} */
- HEAPF64;
- function updateGlobalBufferAndViews(buf) {
- buffer = buf;
- Module['HEAP8'] = HEAP8 = new Int8Array(buf);
- Module['HEAP16'] = HEAP16 = new Int16Array(buf);
- Module['HEAP32'] = HEAP32 = new Int32Array(buf);
- Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf);
- Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf);
- Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf);
- Module['HEAPF32'] = HEAPF32 = new Float32Array(buf);
- Module['HEAPF64'] = HEAPF64 = new Float64Array(buf);
- }
- var TOTAL_STACK = 5242880;
- var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216;
- // include: runtime_init_table.js
- // In regular non-RELOCATABLE mode the table is exported
- // from the wasm module and this will be assigned once
- // the exports are available.
- var wasmTable;
- // end include: runtime_init_table.js
- // include: runtime_stack_check.js
- // end include: runtime_stack_check.js
- // include: runtime_assertions.js
- // end include: runtime_assertions.js
- var __ATPRERUN__ = []; // functions called before the runtime is initialized
- var __ATINIT__ = []; // functions called during startup
- var __ATMAIN__ = []; // functions called when main() is to be run
- var __ATEXIT__ = []; // functions called during shutdown
- var __ATPOSTRUN__ = []; // functions called after the main() is called
- var runtimeInitialized = false;
- var runtimeExited = false;
- __ATINIT__.push({ func: function() { ___wasm_call_ctors() } });
- function preRun() {
- if (Module['preRun']) {
- if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
- while (Module['preRun'].length) {
- addOnPreRun(Module['preRun'].shift());
- }
- }
- callRuntimeCallbacks(__ATPRERUN__);
- }
- function initRuntime() {
- runtimeInitialized = true;
-
- callRuntimeCallbacks(__ATINIT__);
- }
- function preMain() {
-
- callRuntimeCallbacks(__ATMAIN__);
- }
- function exitRuntime() {
- runtimeExited = true;
- }
- function postRun() {
- if (Module['postRun']) {
- if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
- while (Module['postRun'].length) {
- addOnPostRun(Module['postRun'].shift());
- }
- }
- callRuntimeCallbacks(__ATPOSTRUN__);
- }
- function addOnPreRun(cb) {
- __ATPRERUN__.unshift(cb);
- }
- function addOnInit(cb) {
- __ATINIT__.unshift(cb);
- }
- function addOnPreMain(cb) {
- __ATMAIN__.unshift(cb);
- }
- function addOnExit(cb) {
- }
- function addOnPostRun(cb) {
- __ATPOSTRUN__.unshift(cb);
- }
- // include: runtime_math.js
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc
- // end include: runtime_math.js
- // A counter of dependencies for calling run(). If we need to
- // do asynchronous work before running, increment this and
- // decrement it. Incrementing must happen in a place like
- // Module.preRun (used by emcc to add file preloading).
- // Note that you can add dependencies in preRun, even though
- // it happens right before run - run will be postponed until
- // the dependencies are met.
- var runDependencies = 0;
- var runDependencyWatcher = null;
- var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
- function getUniqueRunDependency(id) {
- return id;
- }
- function addRunDependency(id) {
- runDependencies++;
- if (Module['monitorRunDependencies']) {
- Module['monitorRunDependencies'](runDependencies);
- }
- }
- function removeRunDependency(id) {
- runDependencies--;
- if (Module['monitorRunDependencies']) {
- Module['monitorRunDependencies'](runDependencies);
- }
- if (runDependencies == 0) {
- if (runDependencyWatcher !== null) {
- clearInterval(runDependencyWatcher);
- runDependencyWatcher = null;
- }
- if (dependenciesFulfilled) {
- var callback = dependenciesFulfilled;
- dependenciesFulfilled = null;
- callback(); // can add another dependenciesFulfilled
- }
- }
- }
- Module["preloadedImages"] = {}; // maps url to image data
- Module["preloadedAudios"] = {}; // maps url to audio data
- /** @param {string|number=} what */
- function abort(what) {
- if (Module['onAbort']) {
- Module['onAbort'](what);
- }
- what += '';
- err(what);
- ABORT = true;
- EXITSTATUS = 1;
- what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.';
- // Use a wasm runtime error, because a JS error might be seen as a foreign
- // exception, which means we'd run destructors on it. We need the error to
- // simply make the program stop.
- var e = new WebAssembly.RuntimeError(what);
- // Throw the error whether or not MODULARIZE is set because abort is used
- // in code paths apart from instantiation where an exception is expected
- // to be thrown when abort is called.
- throw e;
- }
- // {{MEM_INITIALIZER}}
- // include: memoryprofiler.js
- // end include: memoryprofiler.js
- // include: URIUtils.js
- function hasPrefix(str, prefix) {
- return String.prototype.startsWith ?
- str.startsWith(prefix) :
- str.indexOf(prefix) === 0;
- }
- // Prefix of data URIs emitted by SINGLE_FILE and related options.
- var dataURIPrefix = 'data:application/octet-stream;base64,';
- // Indicates whether filename is a base64 data URI.
- function isDataURI(filename) {
- return hasPrefix(filename, dataURIPrefix);
- }
- var fileURIPrefix = "file://";
- // Indicates whether filename is delivered via file protocol (as opposed to http/https)
- function isFileURI(filename) {
- return hasPrefix(filename, fileURIPrefix);
- }
- // end include: URIUtils.js
- var wasmBinaryFile = 'App.wasm';
- if (!isDataURI(wasmBinaryFile)) {
- wasmBinaryFile = locateFile(wasmBinaryFile);
- }
- function getBinary(file) {
- try {
- if (file == wasmBinaryFile && wasmBinary) {
- return new Uint8Array(wasmBinary);
- }
- if (readBinary) {
- return readBinary(file);
- } else {
- throw "both async and sync fetching of the wasm failed";
- }
- }
- catch (err) {
- abort(err);
- }
- }
- function getBinaryPromise() {
- // If we don't have the binary yet, try to to load it asynchronously.
- // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
- // See https://github.com/github/fetch/pull/92#issuecomment-140665932
- // Cordova or Electron apps are typically loaded from a file:// url.
- // So use fetch if it is available and the url is not a file, otherwise fall back to XHR.
- if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
- if (typeof fetch === 'function'
- && !isFileURI(wasmBinaryFile)
- ) {
- return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
- if (!response['ok']) {
- throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
- }
- return response['arrayBuffer']();
- }).catch(function () {
- return getBinary(wasmBinaryFile);
- });
- }
- else {
- if (readAsync) {
- // fetch is not available or url is file => try XHR (readAsync uses XHR internally)
- return new Promise(function(resolve, reject) {
- readAsync(wasmBinaryFile, function(response) { resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))) }, reject)
- });
- }
- }
- }
-
- // Otherwise, getBinary should be able to get it synchronously
- return Promise.resolve().then(function() { return getBinary(wasmBinaryFile); });
- }
- // Create the wasm instance.
- // Receives the wasm imports, returns the exports.
- function createWasm() {
- // prepare imports
- var info = {
- 'env': asmLibraryArg,
- 'wasi_snapshot_preview1': asmLibraryArg,
- };
- // Load the wasm module and create an instance of using native support in the JS engine.
- // handle a generated wasm instance, receiving its exports and
- // performing other necessary setup
- /** @param {WebAssembly.Module=} module*/
- function receiveInstance(instance, module) {
- var exports = instance.exports;
- exports = Asyncify.instrumentWasmExports(exports);
- Module['asm'] = exports;
- wasmMemory = Module['asm']['memory'];
- updateGlobalBufferAndViews(wasmMemory.buffer);
- wasmTable = Module['asm']['__indirect_function_table'];
- removeRunDependency('wasm-instantiate');
- }
- // we can't run yet (except in a pthread, where we have a custom sync instantiator)
- addRunDependency('wasm-instantiate');
- function receiveInstantiatedSource(output) {
- // 'output' is a WebAssemblyInstantiatedSource object which has both the module and instance.
- // receiveInstance() will swap in the exports (to Module.asm) so they can be called
- // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line.
- // When the regression is fixed, can restore the above USE_PTHREADS-enabled path.
- receiveInstance(output['instance']);
- }
- function instantiateArrayBuffer(receiver) {
- return getBinaryPromise().then(function(binary) {
- return WebAssembly.instantiate(binary, info);
- }).then(receiver, function(reason) {
- err('failed to asynchronously prepare wasm: ' + reason);
- abort(reason);
- });
- }
- // Prefer streaming instantiation if available.
- function instantiateAsync() {
- if (!wasmBinary &&
- typeof WebAssembly.instantiateStreaming === 'function' &&
- !isDataURI(wasmBinaryFile) &&
- // Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
- !isFileURI(wasmBinaryFile) &&
- typeof fetch === 'function') {
- return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function (response) {
- var result = WebAssembly.instantiateStreaming(response, info);
- return result.then(receiveInstantiatedSource, function(reason) {
- // We expect the most common failure cause to be a bad MIME type for the binary,
- // in which case falling back to ArrayBuffer instantiation should work.
- err('wasm streaming compile failed: ' + reason);
- err('falling back to ArrayBuffer instantiation');
- return instantiateArrayBuffer(receiveInstantiatedSource);
- });
- });
- } else {
- return instantiateArrayBuffer(receiveInstantiatedSource);
- }
- }
- // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
- // to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel
- // to any other async startup actions they are performing.
- if (Module['instantiateWasm']) {
- try {
- var exports = Module['instantiateWasm'](info, receiveInstance);
- exports = Asyncify.instrumentWasmExports(exports);
- return exports;
- } catch(e) {
- err('Module.instantiateWasm callback failed with error: ' + e);
- return false;
- }
- }
- instantiateAsync();
- return {}; // no exports yet; we'll fill them in later
- }
- // Globals used by JS i64 conversions (see makeSetValue)
- var tempDouble;
- var tempI64;
- // === Body ===
- var ASM_CONSTS = {
- 20020: function() {if ((window.AudioContext || window.webkitAudioContext) === undefined) { return 0; } if (typeof(miniaudio) === 'undefined') { miniaudio = {}; miniaudio.devices = []; miniaudio.track_device = function(device) { for (var iDevice = 0; iDevice < miniaudio.devices.length; ++iDevice) { if (miniaudio.devices[iDevice] == null) { miniaudio.devices[iDevice] = device; return iDevice; } } miniaudio.devices.push(device); return miniaudio.devices.length - 1; }; miniaudio.untrack_device_by_index = function(deviceIndex) { miniaudio.devices[deviceIndex] = null; while (miniaudio.devices.length > 0) { if (miniaudio.devices[miniaudio.devices.length-1] == null) { miniaudio.devices.pop(); } else { break; } } }; miniaudio.untrack_device = function(device) { for (var iDevice = 0; iDevice < miniaudio.devices.length; ++iDevice) { if (miniaudio.devices[iDevice] == device) { return miniaudio.untrack_device_by_index(iDevice); } } }; miniaudio.get_device_by_index = function(deviceIndex) { return miniaudio.devices[deviceIndex]; }; } return 1;},
- 21260: function() {return (navigator.mediaDevices !== undefined && navigator.mediaDevices.getUserMedia !== undefined);},
- 21401: function() {try { var temp = new (window.AudioContext || window.webkitAudioContext)(); var sampleRate = temp.sampleRate; temp.close(); return sampleRate; } catch(e) { return 0; }},
- 21627: function($0, $1, $2, $3, $4) {var channels = $0; var sampleRate = $1; var bufferSize = $2; var isCapture = $3; var pDevice = $4; if (typeof(miniaudio) === 'undefined') { return -1; } var device = {}; device.webaudio = new (window.AudioContext || window.webkitAudioContext)({sampleRate:sampleRate}); device.webaudio.suspend(); device.intermediaryBufferSizeInBytes = channels * bufferSize * 4; device.intermediaryBuffer = Module._malloc(device.intermediaryBufferSizeInBytes); device.intermediaryBufferView = new Float32Array(Module.HEAPF32.buffer, device.intermediaryBuffer, device.intermediaryBufferSizeInBytes); device.scriptNode = device.webaudio.createScriptProcessor(bufferSize, channels, channels); if (isCapture) { device.scriptNode.onaudioprocess = function(e) { if (device.intermediaryBuffer === undefined) { return; } for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) { e.outputBuffer.getChannelData(iChannel).fill(0.0); } var sendSilence = false; if (device.streamNode === undefined) { sendSilence = true; } if (e.inputBuffer.numberOfChannels != channels) { console.log("Capture: Channel count mismatch. " + e.inputBufer.numberOfChannels + " != " + channels + ". Sending silence."); sendSilence = true; } var totalFramesProcessed = 0; while (totalFramesProcessed < e.inputBuffer.length) { var framesRemaining = e.inputBuffer.length - totalFramesProcessed; var framesToProcess = framesRemaining; if (framesToProcess > (device.intermediaryBufferSizeInBytes/channels/4)) { framesToProcess = (device.intermediaryBufferSizeInBytes/channels/4); } if (sendSilence) { device.intermediaryBufferView.fill(0.0); } else { for (var iFrame = 0; iFrame < framesToProcess; ++iFrame) { for (var iChannel = 0; iChannel < e.inputBuffer.numberOfChannels; ++iChannel) { device.intermediaryBufferView[iFrame*channels + iChannel] = e.inputBuffer.getChannelData(iChannel)[totalFramesProcessed + iFrame]; } } } ccall("ma_device_process_pcm_frames_capture__webaudio", "undefined", ["number", "number", "number"], [pDevice, framesToProcess, device.intermediaryBuffer]); totalFramesProcessed += framesToProcess; } }; navigator.mediaDevices.getUserMedia({audio:true, video:false}) .then(function(stream) { device.streamNode = device.webaudio.createMediaStreamSource(stream); device.streamNode.connect(device.scriptNode); device.scriptNode.connect(device.webaudio.destination); }) .catch(function(error) { device.scriptNode.connect(device.webaudio.destination); }); } else { device.scriptNode.onaudioprocess = function(e) { if (device.intermediaryBuffer === undefined) { return; } var outputSilence = false; if (e.outputBuffer.numberOfChannels != channels) { console.log("Playback: Channel count mismatch. " + e.outputBufer.numberOfChannels + " != " + channels + ". Outputting silence."); outputSilence = true; return; } var totalFramesProcessed = 0; while (totalFramesProcessed < e.outputBuffer.length) { var framesRemaining = e.outputBuffer.length - totalFramesProcessed; var framesToProcess = framesRemaining; if (framesToProcess > (device.intermediaryBufferSizeInBytes/channels/4)) { framesToProcess = (device.intermediaryBufferSizeInBytes/channels/4); } ccall("ma_device_process_pcm_frames_playback__webaudio", "undefined", ["number", "number", "number"], [pDevice, framesToProcess, device.intermediaryBuffer]); if (outputSilence) { for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) { e.outputBuffer.getChannelData(iChannel).fill(0.0); } } else { for (var iChannel = 0; iChannel < e.outputBuffer.numberOfChannels; ++iChannel) { for (var iFrame = 0; iFrame < framesToProcess; ++iFrame) { e.outputBuffer.getChannelData(iChannel)[totalFramesProcessed + iFrame] = device.intermediaryBufferView[iFrame*channels + iChannel]; } } } totalFramesProcessed += framesToProcess; } }; device.scriptNode.connect(device.webaudio.destination); } return miniaudio.track_device(device);},
- 25511: function($0) {return miniaudio.get_device_by_index($0).webaudio.sampleRate;},
- 25613: function($0) {var device = miniaudio.get_device_by_index($0); if (device.scriptNode !== undefined) { device.scriptNode.onaudioprocess = function(e) {}; device.scriptNode.disconnect(); device.scriptNode = undefined; } if (device.streamNode !== undefined) { device.streamNode.disconnect(); device.streamNode = undefined; } device.webaudio.close(); device.webaudio = undefined; if (device.intermediaryBuffer !== undefined) { Module._free(device.intermediaryBuffer); device.intermediaryBuffer = undefined; device.intermediaryBufferView = undefined; device.intermediaryBufferSizeInBytes = undefined; } miniaudio.untrack_device_by_index($0);},
- 26292: function($0) {miniaudio.get_device_by_index($0).webaudio.resume();},
- 26374: function($0) {miniaudio.get_device_by_index($0).webaudio.suspend();}
- };
- function callRuntimeCallbacks(callbacks) {
- while(callbacks.length > 0) {
- var callback = callbacks.shift();
- if (typeof callback == 'function') {
- callback(Module); // Pass the module as the first argument.
- continue;
- }
- var func = callback.func;
- if (typeof func === 'number') {
- if (callback.arg === undefined) {
- (function() { dynCall_v.call(null, func); })();
- } else {
- (function(a1) { dynCall_vi.apply(null, [func, a1]); })(callback.arg);
- }
- } else {
- func(callback.arg === undefined ? null : callback.arg);
- }
- }
- }
- function demangle(func) {
- return func;
- }
- function demangleAll(text) {
- var regex =
- /\b_Z[\w\d_]+/g;
- return text.replace(regex,
- function(x) {
- var y = demangle(x);
- return x === y ? x : (y + ' [' + x + ']');
- });
- }
- function jsStackTrace() {
- var error = new Error();
- if (!error.stack) {
- // IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
- // so try that as a special-case.
- try {
- throw new Error();
- } catch(e) {
- error = e;
- }
- if (!error.stack) {
- return '(no stack trace available)';
- }
- }
- return error.stack.toString();
- }
- function stackTrace() {
- var js = jsStackTrace();
- if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
- return demangleAll(js);
- }
- function ___assert_fail(condition, filename, line, func) {
- abort('Assertion failed: ' + UTF8ToString(condition) + ', at: ' + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
- }
- function _emscripten_asm_const_int(code, sigPtr, argbuf) {
- var args = readAsmConstArgs(sigPtr, argbuf);
- return ASM_CONSTS[code].apply(null, args);
- }
- var JSEvents={inEventHandler:0,removeAllEventListeners:function() {
- for(var i = JSEvents.eventHandlers.length-1; i >= 0; --i) {
- JSEvents._removeHandler(i);
- }
- JSEvents.eventHandlers = [];
- JSEvents.deferredCalls = [];
- },registerRemoveEventListeners:function() {
- if (!JSEvents.removeEventListenersRegistered) {
- __ATEXIT__.push(JSEvents.removeAllEventListeners);
- JSEvents.removeEventListenersRegistered = true;
- }
- },deferredCalls:[],deferCall:function(targetFunction, precedence, argsList) {
- function arraysHaveEqualContent(arrA, arrB) {
- if (arrA.length != arrB.length) return false;
-
- for(var i in arrA) {
- if (arrA[i] != arrB[i]) return false;
- }
- return true;
- }
- // Test if the given call was already queued, and if so, don't add it again.
- for(var i in JSEvents.deferredCalls) {
- var call = JSEvents.deferredCalls[i];
- if (call.targetFunction == targetFunction && arraysHaveEqualContent(call.argsList, argsList)) {
- return;
- }
- }
- JSEvents.deferredCalls.push({
- targetFunction: targetFunction,
- precedence: precedence,
- argsList: argsList
- });
-
- JSEvents.deferredCalls.sort(function(x,y) { return x.precedence < y.precedence; });
- },removeDeferredCalls:function(targetFunction) {
- for(var i = 0; i < JSEvents.deferredCalls.length; ++i) {
- if (JSEvents.deferredCalls[i].targetFunction == targetFunction) {
- JSEvents.deferredCalls.splice(i, 1);
- --i;
- }
- }
- },canPerformEventHandlerRequests:function() {
- return JSEvents.inEventHandler && JSEvents.currentEventHandler.allowsDeferredCalls;
- },runDeferredCalls:function() {
- if (!JSEvents.canPerformEventHandlerRequests()) {
- return;
- }
- for(var i = 0; i < JSEvents.deferredCalls.length; ++i) {
- var call = JSEvents.deferredCalls[i];
- JSEvents.deferredCalls.splice(i, 1);
- --i;
- call.targetFunction.apply(null, call.argsList);
- }
- },eventHandlers:[],removeAllHandlersOnTarget:function(target, eventTypeString) {
- for(var i = 0; i < JSEvents.eventHandlers.length; ++i) {
- if (JSEvents.eventHandlers[i].target == target &&
- (!eventTypeString || eventTypeString == JSEvents.eventHandlers[i].eventTypeString)) {
- JSEvents._removeHandler(i--);
- }
- }
- },_removeHandler:function(i) {
- var h = JSEvents.eventHandlers[i];
- h.target.removeEventListener(h.eventTypeString, h.eventListenerFunc, h.useCapture);
- JSEvents.eventHandlers.splice(i, 1);
- },registerOrRemoveHandler:function(eventHandler) {
- var jsEventHandler = function jsEventHandler(event) {
- // Increment nesting count for the event handler.
- ++JSEvents.inEventHandler;
- JSEvents.currentEventHandler = eventHandler;
- // Process any old deferred calls the user has placed.
- JSEvents.runDeferredCalls();
- // Process the actual event, calls back to user C code handler.
- eventHandler.handlerFunc(event);
- // Process any new deferred calls that were placed right now from this event handler.
- JSEvents.runDeferredCalls();
- // Out of event handler - restore nesting count.
- --JSEvents.inEventHandler;
- };
-
- if (eventHandler.callbackfunc) {
- eventHandler.eventListenerFunc = jsEventHandler;
- eventHandler.target.addEventListener(eventHandler.eventTypeString, jsEventHandler, eventHandler.useCapture);
- JSEvents.eventHandlers.push(eventHandler);
- JSEvents.registerRemoveEventListeners();
- } else {
- for(var i = 0; i < JSEvents.eventHandlers.length; ++i) {
- if (JSEvents.eventHandlers[i].target == eventHandler.target
- && JSEvents.eventHandlers[i].eventTypeString == eventHandler.eventTypeString) {
- JSEvents._removeHandler(i--);
- }
- }
- }
- },getNodeNameForTarget:function(target) {
- if (!target) return '';
- if (target == window) return '#window';
- if (target == screen) return '#screen';
- return (target && target.nodeName) ? target.nodeName : '';
- },fullscreenEnabled:function() {
- return document.fullscreenEnabled
- // Safari 13.0.3 on macOS Catalina 10.15.1 still ships with prefixed webkitFullscreenEnabled.
- // TODO: If Safari at some point ships with unprefixed version, update the version check above.
- || document.webkitFullscreenEnabled
- ;
- }};
-
- function setLetterbox(element, topBottom, leftRight) {
- // Cannot use margin to specify letterboxes in FF or Chrome, since those ignore margins in fullscreen mode.
- element.style.paddingLeft = element.style.paddingRight = leftRight + 'px';
- element.style.paddingTop = element.style.paddingBottom = topBottom + 'px';
- }
-
- function hideEverythingExceptGivenElement(onlyVisibleElement) {
- var child = onlyVisibleElement;
- var parent = child.parentNode;
- var hiddenElements = [];
- while (child != document.body) {
- var children = parent.children;
- for (var i = 0; i < children.length; ++i) {
- if (children[i] != child) {
- hiddenElements.push({ node: children[i], displayState: children[i].style.display });
- children[i].style.display = 'none';
- }
- }
- child = parent;
- parent = parent.parentNode;
- }
- return hiddenElements;
- }
-
- var restoreOldWindowedStyle=null;
-
- function maybeCStringToJsString(cString) {
- // "cString > 2" checks if the input is a number, and isn't of the special
- // values we accept here, EMSCRIPTEN_EVENT_TARGET_* (which map to 0, 1, 2).
- // In other words, if cString > 2 then it's a pointer to a valid place in
- // memory, and points to a C string.
- return cString > 2 ? UTF8ToString(cString) : cString;
- }
-
- var specialHTMLTargets=[0, typeof document !== 'undefined' ? document : 0, typeof window !== 'undefined' ? window : 0];
- function findEventTarget(target) {
- target = maybeCStringToJsString(target);
- var domElement = specialHTMLTargets[target] || (typeof document !== 'undefined' ? document.querySelector(target) : undefined);
- return domElement;
- }
- function findCanvasEventTarget(target) { return findEventTarget(target); }
- function _emscripten_get_canvas_element_size(target, width, height) {
- var canvas = findCanvasEventTarget(target);
- if (!canvas) return -4;
- HEAP32[((width)>>2)] = canvas.width;
- HEAP32[((height)>>2)] = canvas.height;
- }
- function getCanvasElementSize(target) {
- var stackTop = stackSave();
- var w = stackAlloc(8);
- var h = w + 4;
-
- var targetInt = stackAlloc(target.id.length+1);
- stringToUTF8(target.id, targetInt, target.id.length+1);
- var ret = _emscripten_get_canvas_element_size(targetInt, w, h);
- var size = [HEAP32[((w)>>2)], HEAP32[((h)>>2)]];
- stackRestore(stackTop);
- return size;
- }
-
- function _emscripten_set_canvas_element_size(target, width, height) {
- var canvas = findCanvasEventTarget(target);
- if (!canvas) return -4;
- canvas.width = width;
- canvas.height = height;
- return 0;
- }
- function setCanvasElementSize(target, width, height) {
- if (!target.controlTransferredOffscreen) {
- target.width = width;
- target.height = height;
- } else {
- // This function is being called from high-level JavaScript code instead of asm.js/Wasm,
- // and it needs to synchronously proxy over to another thread, so marshal the string onto the heap to do the call.
- var stackTop = stackSave();
- var targetInt = stackAlloc(target.id.length+1);
- stringToUTF8(target.id, targetInt, target.id.length+1);
- _emscripten_set_canvas_element_size(targetInt, width, height);
- stackRestore(stackTop);
- }
- }
- function registerRestoreOldStyle(canvas) {
- var canvasSize = getCanvasElementSize(canvas);
- var oldWidth = canvasSize[0];
- var oldHeight = canvasSize[1];
- var oldCssWidth = canvas.style.width;
- var oldCssHeight = canvas.style.height;
- var oldBackgroundColor = canvas.style.backgroundColor; // Chrome reads color from here.
- var oldDocumentBackgroundColor = document.body.style.backgroundColor; // IE11 reads color from here.
- // Firefox always has black background color.
- var oldPaddingLeft = canvas.style.paddingLeft; // Chrome, FF, Safari
- var oldPaddingRight = canvas.style.paddingRight;
- var oldPaddingTop = canvas.style.paddingTop;
- var oldPaddingBottom = canvas.style.paddingBottom;
- var oldMarginLeft = canvas.style.marginLeft; // IE11
- var oldMarginRight = canvas.style.marginRight;
- var oldMarginTop = canvas.style.marginTop;
- var oldMarginBottom = canvas.style.marginBottom;
- var oldDocumentBodyMargin = document.body.style.margin;
- var oldDocumentOverflow = document.documentElement.style.overflow; // Chrome, Firefox
- var oldDocumentScroll = document.body.scroll; // IE
- var oldImageRendering = canvas.style.imageRendering;
-
- function restoreOldStyle() {
- var fullscreenElement = document.fullscreenElement
- || document.webkitFullscreenElement
- || document.msFullscreenElement
- ;
- if (!fullscreenElement) {
- document.removeEventListener('fullscreenchange', restoreOldStyle);
-
- // Unprefixed Fullscreen API shipped in Chromium 71 (https://bugs.chromium.org/p/chromium/issues/detail?id=383813)
- // As of Safari 13.0.3 on macOS Catalina 10.15.1 still ships with prefixed webkitfullscreenchange. TODO: revisit this check once Safari ships unprefixed version.
- document.removeEventListener('webkitfullscreenchange', restoreOldStyle);
-
- setCanvasElementSize(canvas, oldWidth, oldHeight);
-
- canvas.style.width = oldCssWidth;
- canvas.style.height = oldCssHeight;
- canvas.style.backgroundColor = oldBackgroundColor; // Chrome
- // IE11 hack: assigning 'undefined' or an empty string to document.body.style.backgroundColor has no effect, so first assign back the default color
- // before setting the undefined value. Setting undefined value is also important, or otherwise we would later treat that as something that the user
- // had explicitly set so subsequent fullscreen transitions would not set background color properly.
- if (!oldDocumentBackgroundColor) document.body.style.backgroundColor = 'white';
- document.body.style.backgroundColor = oldDocumentBackgroundColor; // IE11
- canvas.style.paddingLeft = oldPaddingLeft; // Chrome, FF, Safari
- canvas.style.paddingRight = oldPaddingRight;
- canvas.style.paddingTop = oldPaddingTop;
- canvas.style.paddingBottom = oldPaddingBottom;
- canvas.style.marginLeft = oldMarginLeft; // IE11
- canvas.style.marginRight = oldMarginRight;
- canvas.style.marginTop = oldMarginTop;
- canvas.style.marginBottom = oldMarginBottom;
- document.body.style.margin = oldDocumentBodyMargin;
- document.documentElement.style.overflow = oldDocumentOverflow; // Chrome, Firefox
- document.body.scroll = oldDocumentScroll; // IE
- canvas.style.imageRendering = oldImageRendering;
- if (canvas.GLctxObject) canvas.GLctxObject.GLctx.viewport(0, 0, oldWidth, oldHeight);
-
- if (currentFullscreenStrategy.canvasResizedCallback) {
- (function(a1, a2, a3) { dynCall_iiii.apply(null, [currentFullscreenStrategy.canvasResizedCallback, a1, a2, a3]); })(37, 0, currentFullscreenStrategy.canvasResizedCallbackUserData);
- }
- }
- }
- document.addEventListener('fullscreenchange', restoreOldStyle);
- // Unprefixed Fullscreen API shipped in Chromium 71 (https://bugs.chromium.org/p/chromium/issues/detail?id=383813)
- // As of Safari 13.0.3 on macOS Catalina 10.15.1 still ships with prefixed webkitfullscreenchange. TODO: revisit this check once Safari ships unprefixed version.
- document.addEventListener('webkitfullscreenchange', restoreOldStyle);
- return restoreOldStyle;
- }
-
- function restoreHiddenElements(hiddenElements) {
- for (var i = 0; i < hiddenElements.length; ++i) {
- hiddenElements[i].node.style.display = hiddenElements[i].displayState;
- }
- }
-
- var currentFullscreenStrategy={};
-
- /** @suppress {checkTypes} */
- function jstoi_q(str) {
- return parseInt(str);
- }
- function softFullscreenResizeWebGLRenderTarget() {
- var dpr = devicePixelRatio;
- var inHiDPIFullscreenMode = currentFullscreenStrategy.canvasResolutionScaleMode == 2;
- var inAspectRatioFixedFullscreenMode = currentFullscreenStrategy.scaleMode == 2;
- var inPixelPerfectFullscreenMode = currentFullscreenStrategy.canvasResolutionScaleMode != 0;
- var inCenteredWithoutScalingFullscreenMode = currentFullscreenStrategy.scaleMode == 3;
- var screenWidth = inHiDPIFullscreenMode ? Math.round(innerWidth*dpr) : innerWidth;
- var screenHeight = inHiDPIFullscreenMode ? Math.round(innerHeight*dpr) : innerHeight;
- var w = screenWidth;
- var h = screenHeight;
- var canvas = currentFullscreenStrategy.target;
- var canvasSize = getCanvasElementSize(canvas);
- var x = canvasSize[0];
- var y = canvasSize[1];
- var topMargin;
-
- if (inAspectRatioFixedFullscreenMode) {
- if (w*y < x*h) h = (w * y / x) | 0;
- else if (w*y > x*h) w = (h * x / y) | 0;
- topMargin = ((screenHeight - h) / 2) | 0;
- }
-
- if (inPixelPerfectFullscreenMode) {
- setCanvasElementSize(canvas, w, h);
- if (canvas.GLctxObject) canvas.GLctxObject.GLctx.viewport(0, 0, w, h);
- }
-
- // Back to CSS pixels.
- if (inHiDPIFullscreenMode) {
- topMargin /= dpr;
- w /= dpr;
- h /= dpr;
- // Round to nearest 4 digits of precision.
- w = Math.round(w*1e4)/1e4;
- h = Math.round(h*1e4)/1e4;
- topMargin = Math.round(topMargin*1e4)/1e4;
- }
-
- if (inCenteredWithoutScalingFullscreenMode) {
- var t = (innerHeight - jstoi_q(canvas.style.height)) / 2;
- var b = (innerWidth - jstoi_q(canvas.style.width)) / 2;
- setLetterbox(canvas, t, b);
- } else {
- canvas.style.width = w + 'px';
- canvas.style.height = h + 'px';
- var b = (innerWidth - w) / 2;
- setLetterbox(canvas, topMargin, b);
- }
-
- if (!inCenteredWithoutScalingFullscreenMode && currentFullscreenStrategy.canvasResizedCallback) {
- (function(a1, a2, a3) { dynCall_iiii.apply(null, [currentFullscreenStrategy.canvasResizedCallback, a1, a2, a3]); })(37, 0, currentFullscreenStrategy.canvasResizedCallbackUserData);
- }
- }
-
- function getBoundingClientRect(e) {
- return specialHTMLTargets.indexOf(e) < 0 ? e.getBoundingClientRect() : {'left':0,'top':0};
- }
- function _JSEvents_resizeCanvasForFullscreen(target, strategy) {
- var restoreOldStyle = registerRestoreOldStyle(target);
- var cssWidth = strategy.softFullscreen ? innerWidth : screen.width;
- var cssHeight = strategy.softFullscreen ? innerHeight : screen.height;
- var rect = getBoundingClientRect(target);
- var windowedCssWidth = rect.width;
- var windowedCssHeight = rect.height;
- var canvasSize = getCanvasElementSize(target);
- var windowedRttWidth = canvasSize[0];
- var windowedRttHeight = canvasSize[1];
-
- if (strategy.scaleMode == 3) {
- setLetterbox(target, (cssHeight - windowedCssHeight) / 2, (cssWidth - windowedCssWidth) / 2);
- cssWidth = windowedCssWidth;
- cssHeight = windowedCssHeight;
- } else if (strategy.scaleMode == 2) {
- if (cssWidth*windowedRttHeight < windowedRttWidth*cssHeight) {
- var desiredCssHeight = windowedRttHeight * cssWidth / windowedRttWidth;
- setLetterbox(target, (cssHeight - desiredCssHeight) / 2, 0);
- cssHeight = desiredCssHeight;
- } else {
- var desiredCssWidth = windowedRttWidth * cssHeight / windowedRttHeight;
- setLetterbox(target, 0, (cssWidth - desiredCssWidth) / 2);
- cssWidth = desiredCssWidth;
- }
- }
-
- // If we are adding padding, must choose a background color or otherwise Chrome will give the
- // padding a default white color. Do it only if user has not customized their own background color.
- if (!target.style.backgroundColor) target.style.backgroundColor = 'black';
- // IE11 does the same, but requires the color to be set in the document body.
- if (!document.body.style.backgroundColor) document.body.style.backgroundColor = 'black'; // IE11
- // Firefox always shows black letterboxes independent of style color.
-
- target.style.width = cssWidth + 'px';
- target.style.height = cssHeight + 'px';
-
- if (strategy.filteringMode == 1) {
- target.style.imageRendering = 'optimizeSpeed';
- target.style.imageRendering = '-moz-crisp-edges';
- target.style.imageRendering = '-o-crisp-edges';
- target.style.imageRendering = '-webkit-optimize-contrast';
- target.style.imageRendering = 'optimize-contrast';
- target.style.imageRendering = 'crisp-edges';
- target.style.imageRendering = 'pixelated';
- }
-
- var dpiScale = (strategy.canvasResolutionScaleMode == 2) ? devicePixelRatio : 1;
- if (strategy.canvasResolutionScaleMode != 0) {
- var newWidth = (cssWidth * dpiScale)|0;
- var newHeight = (cssHeight * dpiScale)|0;
- setCanvasElementSize(target, newWidth, newHeight);
- if (target.GLctxObject) target.GLctxObject.GLctx.viewport(0, 0, newWidth, newHeight);
- }
- return restoreOldStyle;
- }
- function _emscripten_enter_soft_fullscreen(target, fullscreenStrategy) {
- target = findEventTarget(target);
- if (!target) return -4;
-
- var strategy = {
- scaleMode: HEAP32[((fullscreenStrategy)>>2)],
- canvasResolutionScaleMode: HEAP32[(((fullscreenStrategy)+(4))>>2)],
- filteringMode: HEAP32[(((fullscreenStrategy)+(8))>>2)],
- canvasResizedCallback: HEAP32[(((fullscreenStrategy)+(12))>>2)],
- canvasResizedCallbackUserData: HEAP32[(((fullscreenStrategy)+(16))>>2)],
- target: target,
- softFullscreen: true
- };
-
- var restoreOldStyle = _JSEvents_resizeCanvasForFullscreen(target, strategy);
-
- document.documentElement.style.overflow = 'hidden'; // Firefox, Chrome
- document.body.scroll = "no"; // IE11
- document.body.style.margin = '0px'; // Override default document margin area on all browsers.
-
- var hiddenElements = hideEverythingExceptGivenElement(target);
-
- function restoreWindowedState() {
- restoreOldStyle();
- restoreHiddenElements(hiddenElements);
- removeEventListener('resize', softFullscreenResizeWebGLRenderTarget);
- if (strategy.canvasResizedCallback) {
- (function(a1, a2, a3) { dynCall_iiii.apply(null, [strategy.canvasResizedCallback, a1, a2, a3]); })(37, 0, strategy.canvasResizedCallbackUserData);
- }
- currentFullscreenStrategy = 0;
- }
- restoreOldWindowedStyle = restoreWindowedState;
- currentFullscreenStrategy = strategy;
- addEventListener('resize', softFullscreenResizeWebGLRenderTarget);
-
- // Inform the caller that the canvas size has changed.
- if (strategy.canvasResizedCallback) {
- (function(a1, a2, a3) { dynCall_iiii.apply(null, [strategy.canvasResizedCallback, a1, a2, a3]); })(37, 0, strategy.canvasResizedCallbackUserData);
- }
-
- return 0;
- }
- function _JSEvents_requestFullscreen(target, strategy) {
- // EMSCRIPTEN_FULLSCREEN_SCALE_DEFAULT + EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE is a mode where no extra logic is performed to the DOM elements.
- if (strategy.scaleMode != 0 || strategy.canvasResolutionScaleMode != 0) {
- _JSEvents_resizeCanvasForFullscreen(target, strategy);
- }
-
- if (target.requestFullscreen) {
- target.requestFullscreen();
- } else if (target.webkitRequestFullscreen) {
- target.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
- } else {
- return JSEvents.fullscreenEnabled() ? -3 : -1;
- }
-
- currentFullscreenStrategy = strategy;
-
- if (strategy.canvasResizedCallback) {
- (function(a1, a2, a3) { dynCall_iiii.apply(null, [strategy.canvasResizedCallback, a1, a2, a3]); })(37, 0, strategy.canvasResizedCallbackUserData);
- }
-
- return 0;
- }
- function _emscripten_exit_fullscreen() {
- if (!JSEvents.fullscreenEnabled()) return -1;
- // Make sure no queued up calls will fire after this.
- JSEvents.removeDeferredCalls(_JSEvents_requestFullscreen);
-
- var d = specialHTMLTargets[1];
- if (d.exitFullscreen) {
- d.fullscreenElement && d.exitFullscreen();
- } else if (d.webkitExitFullscreen) {
- d.webkitFullscreenElement && d.webkitExitFullscreen();
- } else {
- return -1;
- }
-
- return 0;
- }
- function _emscripten_get_element_css_size(target, width, height) {
- target = findEventTarget(target);
- if (!target) return -4;
-
- var rect = getBoundingClientRect(target);
- HEAPF64[((width)>>3)] = rect.width;
- HEAPF64[((height)>>3)] = rect.height;
-
- return 0;
- }
- function fillPointerlockChangeEventData(eventStruct) {
- var pointerLockElement = document.pointerLockElement || document.mozPointerLockElement || document.webkitPointerLockElement || document.msPointerLockElement;
- var isPointerlocked = !!pointerLockElement;
- /** @suppress {checkTypes} */
- HEAP32[((eventStruct)>>2)] = isPointerlocked;
- var nodeName = JSEvents.getNodeNameForTarget(pointerLockElement);
- var id = (pointerLockElement && pointerLockElement.id) ? pointerLockElement.id : '';
- stringToUTF8(nodeName, eventStruct + 4, 128);
- stringToUTF8(id, eventStruct + 132, 128);
- }
- /** @suppress {missingProperties} */
- function _emscripten_get_pointerlock_status(pointerlockStatus) {
- if (pointerlockStatus) fillPointerlockChangeEventData(pointerlockStatus);
- if (!document.body || (!document.body.requestPointerLock && !document.body.mozRequestPointerLock && !document.body.webkitRequestPointerLock && !document.body.msRequestPointerLock)) {
- return -1;
- }
- return 0;
- }
- function _emscripten_memcpy_big(dest, src, num) {
- HEAPU8.copyWithin(dest, src, src + num);
- }
- function _emscripten_performance_now() {
- return performance.now();
- }
- function _emscripten_get_heap_size() {
- return HEAPU8.length;
- }
-
- function abortOnCannotGrowMemory(requestedSize) {
- abort('OOM');
- }
- function _emscripten_resize_heap(requestedSize) {
- requestedSize = requestedSize >>> 0;
- abortOnCannotGrowMemory(requestedSize);
- }
- function fillMouseEventData(eventStruct, e, target) {
- var idx = eventStruct >> 2;
- HEAP32[idx + 0] = e.screenX;
- HEAP32[idx + 1] = e.screenY;
- HEAP32[idx + 2] = e.clientX;
- HEAP32[idx + 3] = e.clientY;
- HEAP32[idx + 4] = e.ctrlKey;
- HEAP32[idx + 5] = e.shiftKey;
- HEAP32[idx + 6] = e.altKey;
- HEAP32[idx + 7] = e.metaKey;
- HEAP16[idx*2 + 16] = e.button;
- HEAP16[idx*2 + 17] = e.buttons;
-
- HEAP32[idx + 9] = e["movementX"]
- ;
-
- HEAP32[idx + 10] = e["movementY"]
- ;
-
- var rect = getBoundingClientRect(target);
- HEAP32[idx + 11] = e.clientX - rect.left;
- HEAP32[idx + 12] = e.clientY - rect.top;
-
- }
- function registerMouseEventCallback(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
- if (!JSEvents.mouseEvent) JSEvents.mouseEvent = _malloc( 64 );
- target = findEventTarget(target);
-
- var mouseEventHandlerFunc = function(ev) {
- var e = ev || event;
-
- // TODO: Make this access thread safe, or this could update live while app is reading it.
- fillMouseEventData(JSEvents.mouseEvent, e, target);
-
- if ((function(a1, a2, a3) { dynCall_iiii.apply(null, [callbackfunc, a1, a2, a3]); })(eventTypeId, JSEvents.mouseEvent, userData)) e.preventDefault();
- };
-
- var eventHandler = {
- target: target,
- allowsDeferredCalls: eventTypeString != 'mousemove' && eventTypeString != 'mouseenter' && eventTypeString != 'mouseleave', // Mouse move events do not allow fullscreen/pointer lock requests to be handled in them!
- eventTypeString: eventTypeString,
- callbackfunc: callbackfunc,
- handlerFunc: mouseEventHandlerFunc,
- useCapture: useCapture
- };
- JSEvents.registerOrRemoveHandler(eventHandler);
- }
- function _emscripten_set_click_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerMouseEventCallback(target, userData, useCapture, callbackfunc, 4, "click", targetThread);
- return 0;
- }
- function fillFullscreenChangeEventData(eventStruct) {
- var fullscreenElement = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement;
- var isFullscreen = !!fullscreenElement;
- /** @suppress{checkTypes} */
- HEAP32[((eventStruct)>>2)] = isFullscreen;
- HEAP32[(((eventStruct)+(4))>>2)] = JSEvents.fullscreenEnabled();
- // If transitioning to fullscreen, report info about the element that is now fullscreen.
- // If transitioning to windowed mode, report info about the element that just was fullscreen.
- var reportedElement = isFullscreen ? fullscreenElement : JSEvents.previousFullscreenElement;
- var nodeName = JSEvents.getNodeNameForTarget(reportedElement);
- var id = (reportedElement && reportedElement.id) ? reportedElement.id : '';
- stringToUTF8(nodeName, eventStruct + 8, 128);
- stringToUTF8(id, eventStruct + 136, 128);
- HEAP32[(((eventStruct)+(264))>>2)] = reportedElement ? reportedElement.clientWidth : 0;
- HEAP32[(((eventStruct)+(268))>>2)] = reportedElement ? reportedElement.clientHeight : 0;
- HEAP32[(((eventStruct)+(272))>>2)] = screen.width;
- HEAP32[(((eventStruct)+(276))>>2)] = screen.height;
- if (isFullscreen) {
- JSEvents.previousFullscreenElement = fullscreenElement;
- }
- }
- function registerFullscreenChangeEventCallback(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
- if (!JSEvents.fullscreenChangeEvent) JSEvents.fullscreenChangeEvent = _malloc( 280 );
-
- var fullscreenChangeEventhandlerFunc = function(ev) {
- var e = ev || event;
-
- var fullscreenChangeEvent = JSEvents.fullscreenChangeEvent;
-
- fillFullscreenChangeEventData(fullscreenChangeEvent);
-
- if ((function(a1, a2, a3) { dynCall_iiii.apply(null, [callbackfunc, a1, a2, a3]); })(eventTypeId, fullscreenChangeEvent, userData)) e.preventDefault();
- };
-
- var eventHandler = {
- target: target,
- eventTypeString: eventTypeString,
- callbackfunc: callbackfunc,
- handlerFunc: fullscreenChangeEventhandlerFunc,
- useCapture: useCapture
- };
- JSEvents.registerOrRemoveHandler(eventHandler);
- }
- function _emscripten_set_fullscreenchange_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- if (!JSEvents.fullscreenEnabled()) return -1;
- target = findEventTarget(target);
- if (!target) return -4;
- registerFullscreenChangeEventCallback(target, userData, useCapture, callbackfunc, 19, "fullscreenchange", targetThread);
-
- // Unprefixed Fullscreen API shipped in Chromium 71 (https://bugs.chromium.org/p/chromium/issues/detail?id=383813)
- // As of Safari 13.0.3 on macOS Catalina 10.15.1 still ships with prefixed webkitfullscreenchange. TODO: revisit this check once Safari ships unprefixed version.
- registerFullscreenChangeEventCallback(target, userData, useCapture, callbackfunc, 19, "webkitfullscreenchange", targetThread);
-
- return 0;
- }
- function registerKeyEventCallback(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
- if (!JSEvents.keyEvent) JSEvents.keyEvent = _malloc( 164 );
-
- var keyEventHandlerFunc = function(e) {
-
- var keyEventData = JSEvents.keyEvent;
- var idx = keyEventData >> 2;
-
- HEAP32[idx + 0] = e.location;
- HEAP32[idx + 1] = e.ctrlKey;
- HEAP32[idx + 2] = e.shiftKey;
- HEAP32[idx + 3] = e.altKey;
- HEAP32[idx + 4] = e.metaKey;
- HEAP32[idx + 5] = e.repeat;
- HEAP32[idx + 6] = e.charCode;
- HEAP32[idx + 7] = e.keyCode;
- HEAP32[idx + 8] = e.which;
- stringToUTF8(e.key || '', keyEventData + 36, 32);
- stringToUTF8(e.code || '', keyEventData + 68, 32);
- stringToUTF8(e.char || '', keyEventData + 100, 32);
- stringToUTF8(e.locale || '', keyEventData + 132, 32);
-
- if ((function(a1, a2, a3) { dynCall_iiii.apply(null, [callbackfunc, a1, a2, a3]); })(eventTypeId, keyEventData, userData)) e.preventDefault();
- };
-
- var eventHandler = {
- target: findEventTarget(target),
- allowsDeferredCalls: true,
- eventTypeString: eventTypeString,
- callbackfunc: callbackfunc,
- handlerFunc: keyEventHandlerFunc,
- useCapture: useCapture
- };
- JSEvents.registerOrRemoveHandler(eventHandler);
- }
- function _emscripten_set_keydown_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerKeyEventCallback(target, userData, useCapture, callbackfunc, 2, "keydown", targetThread);
- return 0;
- }
- function _emscripten_set_keypress_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerKeyEventCallback(target, userData, useCapture, callbackfunc, 1, "keypress", targetThread);
- return 0;
- }
- function _emscripten_set_keyup_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerKeyEventCallback(target, userData, useCapture, callbackfunc, 3, "keyup", targetThread);
- return 0;
- }
- var Browser={mainLoop:{scheduler:null,method:"",currentlyRunningMainloop:0,func:null,arg:0,timingMode:0,timingValue:0,currentFrameNumber:0,queue:[],pause:function() {
- Browser.mainLoop.scheduler = null;
- // Incrementing this signals the previous main loop that it's now become old, and it must return.
- Browser.mainLoop.currentlyRunningMainloop++;
- },resume:function() {
- Browser.mainLoop.currentlyRunningMainloop++;
- var timingMode = Browser.mainLoop.timingMode;
- var timingValue = Browser.mainLoop.timingValue;
- var func = Browser.mainLoop.func;
- Browser.mainLoop.func = null;
- // do not set timing and call scheduler, we will do it on the next lines
- setMainLoop(func, 0, false, Browser.mainLoop.arg, true);
- _emscripten_set_main_loop_timing(timingMode, timingValue);
- Browser.mainLoop.scheduler();
- },updateStatus:function() {
- if (Module['setStatus']) {
- var message = Module['statusMessage'] || 'Please wait...';
- var remaining = Browser.mainLoop.remainingBlockers;
- var expected = Browser.mainLoop.expectedBlockers;
- if (remaining) {
- if (remaining < expected) {
- Module['setStatus'](message + ' (' + (expected - remaining) + '/' + expected + ')');
- } else {
- Module['setStatus'](message);
- }
- } else {
- Module['setStatus']('');
- }
- }
- },runIter:function(func) {
- if (ABORT) return;
- if (Module['preMainLoop']) {
- var preRet = Module['preMainLoop']();
- if (preRet === false) {
- return; // |return false| skips a frame
- }
- }
- try {
- func();
- } catch (e) {
- if (e instanceof ExitStatus) {
- return;
- } else if (e == 'unwind') {
- return;
- } else {
- if (e && typeof e === 'object' && e.stack) err('exception thrown: ' + [e, e.stack]);
- throw e;
- }
- }
- if (Module['postMainLoop']) Module['postMainLoop']();
- }},isFullscreen:false,pointerLock:false,moduleContextCreatedCallbacks:[],workers:[],init:function() {
- if (!Module["preloadPlugins"]) Module["preloadPlugins"] = []; // needs to exist even in workers
-
- if (Browser.initted) return;
- Browser.initted = true;
-
- try {
- new Blob();
- Browser.hasBlobConstructor = true;
- } catch(e) {
- Browser.hasBlobConstructor = false;
- console.log("warning: no blob constructor, cannot create blobs with mimetypes");
- }
- Browser.BlobBuilder = typeof MozBlobBuilder != "undefined" ? MozBlobBuilder : (typeof WebKitBlobBuilder != "undefined" ? WebKitBlobBuilder : (!Browser.hasBlobConstructor ? console.log("warning: no BlobBuilder") : null));
- Browser.URLObject = typeof window != "undefined" ? (window.URL ? window.URL : window.webkitURL) : undefined;
- if (!Module.noImageDecoding && typeof Browser.URLObject === 'undefined') {
- console.log("warning: Browser does not support creating object URLs. Built-in browser image decoding will not be available.");
- Module.noImageDecoding = true;
- }
-
- // Support for plugins that can process preloaded files. You can add more of these to
- // your app by creating and appending to Module.preloadPlugins.
- //
- // Each plugin is asked if it can handle a file based on the file's name. If it can,
- // it is given the file's raw data. When it is done, it calls a callback with the file's
- // (possibly modified) data. For example, a plugin might decompress a file, or it
- // might create some side data structure for use later (like an Image element, etc.).
-
- var imagePlugin = {};
- imagePlugin['canHandle'] = function imagePlugin_canHandle(name) {
- return !Module.noImageDecoding && /\.(jpg|jpeg|png|bmp)$/i.test(name);
- };
- imagePlugin['handle'] = function imagePlugin_handle(byteArray, name, onload, onerror) {
- var b = null;
- if (Browser.hasBlobConstructor) {
- try {
- b = new Blob([byteArray], { type: Browser.getMimetype(name) });
- if (b.size !== byteArray.length) { // Safari bug #118630
- // Safari's Blob can only take an ArrayBuffer
- b = new Blob([(new Uint8Array(byteArray)).buffer], { type: Browser.getMimetype(name) });
- }
- } catch(e) {
- warnOnce('Blob constructor present but fails: ' + e + '; falling back to blob builder');
- }
- }
- if (!b) {
- var bb = new Browser.BlobBuilder();
- bb.append((new Uint8Array(byteArray)).buffer); // we need to pass a buffer, and must copy the array to get the right data range
- b = bb.getBlob();
- }
- var url = Browser.URLObject.createObjectURL(b);
- var img = new Image();
- img.onload = function img_onload() {
- assert(img.complete, 'Image ' + name + ' could not be decoded');
- var canvas = document.createElement('canvas');
- canvas.width = img.width;
- canvas.height = img.height;
- var ctx = canvas.getContext('2d');
- ctx.drawImage(img, 0, 0);
- Module["preloadedImages"][name] = canvas;
- Browser.URLObject.revokeObjectURL(url);
- if (onload) onload(byteArray);
- };
- img.onerror = function img_onerror(event) {
- console.log('Image ' + url + ' could not be decoded');
- if (onerror) onerror();
- };
- img.src = url;
- };
- Module['preloadPlugins'].push(imagePlugin);
-
- var audioPlugin = {};
- audioPlugin['canHandle'] = function audioPlugin_canHandle(name) {
- return !Module.noAudioDecoding && name.substr(-4) in { '.ogg': 1, '.wav': 1, '.mp3': 1 };
- };
- audioPlugin['handle'] = function audioPlugin_handle(byteArray, name, onload, onerror) {
- var done = false;
- function finish(audio) {
- if (done) return;
- done = true;
- Module["preloadedAudios"][name] = audio;
- if (onload) onload(byteArray);
- }
- function fail() {
- if (done) return;
- done = true;
- Module["preloadedAudios"][name] = new Audio(); // empty shim
- if (onerror) onerror();
- }
- if (Browser.hasBlobConstructor) {
- try {
- var b = new Blob([byteArray], { type: Browser.getMimetype(name) });
- } catch(e) {
- return fail();
- }
- var url = Browser.URLObject.createObjectURL(b); // XXX we never revoke this!
- var audio = new Audio();
- audio.addEventListener('canplaythrough', function() { finish(audio) }, false); // use addEventListener due to chromium bug 124926
- audio.onerror = function audio_onerror(event) {
- if (done) return;
- console.log('warning: browser could not fully decode audio ' + name + ', trying slower base64 approach');
- function encode64(data) {
- var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
- var PAD = '=';
- var ret = '';
- var leftchar = 0;
- var leftbits = 0;
- for (var i = 0; i < data.length; i++) {
- leftchar = (leftchar << 8) | data[i];
- leftbits += 8;
- while (leftbits >= 6) {
- var curr = (leftchar >> (leftbits-6)) & 0x3f;
- leftbits -= 6;
- ret += BASE[curr];
- }
- }
- if (leftbits == 2) {
- ret += BASE[(leftchar&3) << 4];
- ret += PAD + PAD;
- } else if (leftbits == 4) {
- ret += BASE[(leftchar&0xf) << 2];
- ret += PAD;
- }
- return ret;
- }
- audio.src = 'data:audio/x-' + name.substr(-3) + ';base64,' + encode64(byteArray);
- finish(audio); // we don't wait for confirmation this worked - but it's worth trying
- };
- audio.src = url;
- // workaround for chrome bug 124926 - we do not always get oncanplaythrough or onerror
- Browser.safeSetTimeout(function() {
- finish(audio); // try to use it even though it is not necessarily ready to play
- }, 10000);
- } else {
- return fail();
- }
- };
- Module['preloadPlugins'].push(audioPlugin);
-
- // Canvas event setup
-
- function pointerLockChange() {
- Browser.pointerLock = document['pointerLockElement'] === Module['canvas'] ||
- document['mozPointerLockElement'] === Module['canvas'] ||
- document['webkitPointerLockElement'] === Module['canvas'] ||
- document['msPointerLockElement'] === Module['canvas'];
- }
- var canvas = Module['canvas'];
- if (canvas) {
- // forced aspect ratio can be enabled by defining 'forcedAspectRatio' on Module
- // Module['forcedAspectRatio'] = 4 / 3;
-
- canvas.requestPointerLock = canvas['requestPointerLock'] ||
- canvas['mozRequestPointerLock'] ||
- canvas['webkitRequestPointerLock'] ||
- canvas['msRequestPointerLock'] ||
- function(){};
- canvas.exitPointerLock = document['exitPointerLock'] ||
- document['mozExitPointerLock'] ||
- document['webkitExitPointerLock'] ||
- document['msExitPointerLock'] ||
- function(){}; // no-op if function does not exist
- canvas.exitPointerLock = canvas.exitPointerLock.bind(document);
-
- document.addEventListener('pointerlockchange', pointerLockChange, false);
- document.addEventListener('mozpointerlockchange', pointerLockChange, false);
- document.addEventListener('webkitpointerlockchange', pointerLockChange, false);
- document.addEventListener('mspointerlockchange', pointerLockChange, false);
-
- if (Module['elementPointerLock']) {
- canvas.addEventListener("click", function(ev) {
- if (!Browser.pointerLock && Module['canvas'].requestPointerLock) {
- Module['canvas'].requestPointerLock();
- ev.preventDefault();
- }
- }, false);
- }
- }
- },createContext:function(canvas, useWebGL, setInModule, webGLContextAttributes) {
- if (useWebGL && Module.ctx && canvas == Module.canvas) return Module.ctx; // no need to recreate GL context if it's already been created for this canvas.
-
- var ctx;
- var contextHandle;
- if (useWebGL) {
- // For GLES2/desktop GL compatibility, adjust a few defaults to be different to WebGL defaults, so that they align better with the desktop defaults.
- var contextAttributes = {
- antialias: false,
- alpha: false,
- majorVersion: (typeof WebGL2RenderingContext !== 'undefined') ? 2 : 1,
- };
-
- if (webGLContextAttributes) {
- for (var attribute in webGLContextAttributes) {
- contextAttributes[attribute] = webGLContextAttributes[attribute];
- }
- }
-
- // This check of existence of GL is here to satisfy Closure compiler, which yells if variable GL is referenced below but GL object is not
- // actually compiled in because application is not doing any GL operations. TODO: Ideally if GL is not being used, this function
- // Browser.createContext() should not even be emitted.
- if (typeof GL !== 'undefined') {
- contextHandle = GL.createContext(canvas, contextAttributes);
- if (contextHandle) {
- ctx = GL.getContext(contextHandle).GLctx;
- }
- }
- } else {
- ctx = canvas.getContext('2d');
- }
-
- if (!ctx) return null;
-
- if (setInModule) {
- if (!useWebGL) assert(typeof GLctx === 'undefined', 'cannot set in module if GLctx is used, but we are a non-GL context that would replace it');
-
- Module.ctx = ctx;
- if (useWebGL) GL.makeContextCurrent(contextHandle);
- Module.useWebGL = useWebGL;
- Browser.moduleContextCreatedCallbacks.forEach(function(callback) { callback() });
- Browser.init();
- }
- return ctx;
- },destroyContext:function(canvas, useWebGL, setInModule) {},fullscreenHandlersInstalled:false,lockPointer:undefined,resizeCanvas:undefined,requestFullscreen:function(lockPointer, resizeCanvas) {
- Browser.lockPointer = lockPointer;
- Browser.resizeCanvas = resizeCanvas;
- if (typeof Browser.lockPointer === 'undefined') Browser.lockPointer = true;
- if (typeof Browser.resizeCanvas === 'undefined') Browser.resizeCanvas = false;
-
- var canvas = Module['canvas'];
- function fullscreenChange() {
- Browser.isFullscreen = false;
- var canvasContainer = canvas.parentNode;
- if ((document['fullscreenElement'] || document['mozFullScreenElement'] ||
- document['msFullscreenElement'] || document['webkitFullscreenElement'] ||
- document['webkitCurrentFullScreenElement']) === canvasContainer) {
- canvas.exitFullscreen = Browser.exitFullscreen;
- if (Browser.lockPointer) canvas.requestPointerLock();
- Browser.isFullscreen = true;
- if (Browser.resizeCanvas) {
- Browser.setFullscreenCanvasSize();
- } else {
- Browser.updateCanvasDimensions(canvas);
- }
- } else {
- // remove the full screen specific parent of the canvas again to restore the HTML structure from before going full screen
- canvasContainer.parentNode.insertBefore(canvas, canvasContainer);
- canvasContainer.parentNode.removeChild(canvasContainer);
-
- if (Browser.resizeCanvas) {
- Browser.setWindowedCanvasSize();
- } else {
- Browser.updateCanvasDimensions(canvas);
- }
- }
- if (Module['onFullScreen']) Module['onFullScreen'](Browser.isFullscreen);
- if (Module['onFullscreen']) Module['onFullscreen'](Browser.isFullscreen);
- }
-
- if (!Browser.fullscreenHandlersInstalled) {
- Browser.fullscreenHandlersInstalled = true;
- document.addEventListener('fullscreenchange', fullscreenChange, false);
- document.addEventListener('mozfullscreenchange', fullscreenChange, false);
- document.addEventListener('webkitfullscreenchange', fullscreenChange, false);
- document.addEventListener('MSFullscreenChange', fullscreenChange, false);
- }
-
- // create a new parent to ensure the canvas has no siblings. this allows browsers to optimize full screen performance when its parent is the full screen root
- var canvasContainer = document.createElement("div");
- canvas.parentNode.insertBefore(canvasContainer, canvas);
- canvasContainer.appendChild(canvas);
-
- // use parent of canvas as full screen root to allow aspect ratio correction (Firefox stretches the root to screen size)
- canvasContainer.requestFullscreen = canvasContainer['requestFullscreen'] ||
- canvasContainer['mozRequestFullScreen'] ||
- canvasContainer['msRequestFullscreen'] ||
- (canvasContainer['webkitRequestFullscreen'] ? function() { canvasContainer['webkitRequestFullscreen'](Element['ALLOW_KEYBOARD_INPUT']) } : null) ||
- (canvasContainer['webkitRequestFullScreen'] ? function() { canvasContainer['webkitRequestFullScreen'](Element['ALLOW_KEYBOARD_INPUT']) } : null);
-
- canvasContainer.requestFullscreen();
- },exitFullscreen:function() {
- // This is workaround for chrome. Trying to exit from fullscreen
- // not in fullscreen state will cause "TypeError: Document not active"
- // in chrome. See https://github.com/emscripten-core/emscripten/pull/8236
- if (!Browser.isFullscreen) {
- return false;
- }
-
- var CFS = document['exitFullscreen'] ||
- document['cancelFullScreen'] ||
- document['mozCancelFullScreen'] ||
- document['msExitFullscreen'] ||
- document['webkitCancelFullScreen'] ||
- (function() {});
- CFS.apply(document, []);
- return true;
- },nextRAF:0,fakeRequestAnimationFrame:function(func) {
- // try to keep 60fps between calls to here
- var now = Date.now();
- if (Browser.nextRAF === 0) {
- Browser.nextRAF = now + 1000/60;
- } else {
- while (now + 2 >= Browser.nextRAF) { // fudge a little, to avoid timer jitter causing us to do lots of delay:0
- Browser.nextRAF += 1000/60;
- }
- }
- var delay = Math.max(Browser.nextRAF - now, 0);
- setTimeout(func, delay);
- },requestAnimationFrame:function(func) {
- if (typeof requestAnimationFrame === 'function') {
- requestAnimationFrame(func);
- return;
- }
- var RAF = Browser.fakeRequestAnimationFrame;
- RAF(func);
- },safeRequestAnimationFrame:function(func) {
- return Browser.requestAnimationFrame(function() {
- if (ABORT) return;
- func();
- });
- },safeSetTimeout:function(func, timeout) {
- noExitRuntime = true;
- return setTimeout(function() {
- if (ABORT) return;
- func();
- }, timeout);
- },getMimetype:function(name) {
- return {
- 'jpg': 'image/jpeg',
- 'jpeg': 'image/jpeg',
- 'png': 'image/png',
- 'bmp': 'image/bmp',
- 'ogg': 'audio/ogg',
- 'wav': 'audio/wav',
- 'mp3': 'audio/mpeg'
- }[name.substr(name.lastIndexOf('.')+1)];
- },getUserMedia:function(func) {
- if(!window.getUserMedia) {
- window.getUserMedia = navigator['getUserMedia'] ||
- navigator['mozGetUserMedia'];
- }
- window.getUserMedia(func);
- },getMovementX:function(event) {
- return event['movementX'] ||
- event['mozMovementX'] ||
- event['webkitMovementX'] ||
- 0;
- },getMovementY:function(event) {
- return event['movementY'] ||
- event['mozMovementY'] ||
- event['webkitMovementY'] ||
- 0;
- },getMouseWheelDelta:function(event) {
- var delta = 0;
- switch (event.type) {
- case 'DOMMouseScroll':
- // 3 lines make up a step
- delta = event.detail / 3;
- break;
- case 'mousewheel':
- // 120 units make up a step
- delta = event.wheelDelta / 120;
- break;
- case 'wheel':
- delta = event.deltaY
- switch(event.deltaMode) {
- case 0:
- // DOM_DELTA_PIXEL: 100 pixels make up a step
- delta /= 100;
- break;
- case 1:
- // DOM_DELTA_LINE: 3 lines make up a step
- delta /= 3;
- break;
- case 2:
- // DOM_DELTA_PAGE: A page makes up 80 steps
- delta *= 80;
- break;
- default:
- throw 'unrecognized mouse wheel delta mode: ' + event.deltaMode;
- }
- break;
- default:
- throw 'unrecognized mouse wheel event: ' + event.type;
- }
- return delta;
- },mouseX:0,mouseY:0,mouseMovementX:0,mouseMovementY:0,touches:{},lastTouches:{},calculateMouseEvent:function(event) { // event should be mousemove, mousedown or mouseup
- if (Browser.pointerLock) {
- // When the pointer is locked, calculate the coordinates
- // based on the movement of the mouse.
- // Workaround for Firefox bug 764498
- if (event.type != 'mousemove' &&
- ('mozMovementX' in event)) {
- Browser.mouseMovementX = Browser.mouseMovementY = 0;
- } else {
- Browser.mouseMovementX = Browser.getMovementX(event);
- Browser.mouseMovementY = Browser.getMovementY(event);
- }
-
- // check if SDL is available
- if (typeof SDL != "undefined") {
- Browser.mouseX = SDL.mouseX + Browser.mouseMovementX;
- Browser.mouseY = SDL.mouseY + Browser.mouseMovementY;
- } else {
- // just add the mouse delta to the current absolut mouse position
- // FIXME: ideally this should be clamped against the canvas size and zero
- Browser.mouseX += Browser.mouseMovementX;
- Browser.mouseY += Browser.mouseMovementY;
- }
- } else {
- // Otherwise, calculate the movement based on the changes
- // in the coordinates.
- var rect = Module["canvas"].getBoundingClientRect();
- var cw = Module["canvas"].width;
- var ch = Module["canvas"].height;
-
- // Neither .scrollX or .pageXOffset are defined in a spec, but
- // we prefer .scrollX because it is currently in a spec draft.
- // (see: http://www.w3.org/TR/2013/WD-cssom-view-20131217/)
- var scrollX = ((typeof window.scrollX !== 'undefined') ? window.scrollX : window.pageXOffset);
- var scrollY = ((typeof window.scrollY !== 'undefined') ? window.scrollY : window.pageYOffset);
-
- if (event.type === 'touchstart' || event.type === 'touchend' || event.type === 'touchmove') {
- var touch = event.touch;
- if (touch === undefined) {
- return; // the "touch" property is only defined in SDL
-
- }
- var adjustedX = touch.pageX - (scrollX + rect.left);
- var adjustedY = touch.pageY - (scrollY + rect.top);
-
- adjustedX = adjustedX * (cw / rect.width);
- adjustedY = adjustedY * (ch / rect.height);
-
- var coords = { x: adjustedX, y: adjustedY };
-
- if (event.type === 'touchstart') {
- Browser.lastTouches[touch.identifier] = coords;
- Browser.touches[touch.identifier] = coords;
- } else if (event.type === 'touchend' || event.type === 'touchmove') {
- var last = Browser.touches[touch.identifier];
- if (!last) last = coords;
- Browser.lastTouches[touch.identifier] = last;
- Browser.touches[touch.identifier] = coords;
- }
- return;
- }
-
- var x = event.pageX - (scrollX + rect.left);
- var y = event.pageY - (scrollY + rect.top);
-
- // the canvas might be CSS-scaled compared to its backbuffer;
- // SDL-using content will want mouse coordinates in terms
- // of backbuffer units.
- x = x * (cw / rect.width);
- y = y * (ch / rect.height);
-
- Browser.mouseMovementX = x - Browser.mouseX;
- Browser.mouseMovementY = y - Browser.mouseY;
- Browser.mouseX = x;
- Browser.mouseY = y;
- }
- },asyncLoad:function(url, onload, onerror, noRunDep) {
- var dep = !noRunDep ? getUniqueRunDependency('al ' + url) : '';
- readAsync(url, function(arrayBuffer) {
- assert(arrayBuffer, 'Loading data file "' + url + '" failed (no arrayBuffer).');
- onload(new Uint8Array(arrayBuffer));
- if (dep) removeRunDependency(dep);
- }, function(event) {
- if (onerror) {
- onerror();
- } else {
- throw 'Loading data file "' + url + '" failed.';
- }
- });
- if (dep) addRunDependency(dep);
- },resizeListeners:[],updateResizeListeners:function() {
- var canvas = Module['canvas'];
- Browser.resizeListeners.forEach(function(listener) {
- listener(canvas.width, canvas.height);
- });
- },setCanvasSize:function(width, height, noUpdates) {
- var canvas = Module['canvas'];
- Browser.updateCanvasDimensions(canvas, width, height);
- if (!noUpdates) Browser.updateResizeListeners();
- },windowedWidth:0,windowedHeight:0,setFullscreenCanvasSize:function() {
- // check if SDL is available
- if (typeof SDL != "undefined") {
- var flags = HEAPU32[((SDL.screen)>>2)];
- flags = flags | 0x00800000; // set SDL_FULLSCREEN flag
- HEAP32[((SDL.screen)>>2)] = flags
- }
- Browser.updateCanvasDimensions(Module['canvas']);
- Browser.updateResizeListeners();
- },setWindowedCanvasSize:function() {
- // check if SDL is available
- if (typeof SDL != "undefined") {
- var flags = HEAPU32[((SDL.screen)>>2)];
- flags = flags & ~0x00800000; // clear SDL_FULLSCREEN flag
- HEAP32[((SDL.screen)>>2)] = flags
- }
- Browser.updateCanvasDimensions(Module['canvas']);
- Browser.updateResizeListeners();
- },updateCanvasDimensions:function(canvas, wNative, hNative) {
- if (wNative && hNative) {
- canvas.widthNative = wNative;
- canvas.heightNative = hNative;
- } else {
- wNative = canvas.widthNative;
- hNative = canvas.heightNative;
- }
- var w = wNative;
- var h = hNative;
- if (Module['forcedAspectRatio'] && Module['forcedAspectRatio'] > 0) {
- if (w/h < Module['forcedAspectRatio']) {
- w = Math.round(h * Module['forcedAspectRatio']);
- } else {
- h = Math.round(w / Module['forcedAspectRatio']);
- }
- }
- if (((document['fullscreenElement'] || document['mozFullScreenElement'] ||
- document['msFullscreenElement'] || document['webkitFullscreenElement'] ||
- document['webkitCurrentFullScreenElement']) === canvas.parentNode) && (typeof screen != 'undefined')) {
- var factor = Math.min(screen.width / w, screen.height / h);
- w = Math.round(w * factor);
- h = Math.round(h * factor);
- }
- if (Browser.resizeCanvas) {
- if (canvas.width != w) canvas.width = w;
- if (canvas.height != h) canvas.height = h;
- if (typeof canvas.style != 'undefined') {
- canvas.style.removeProperty( "width");
- canvas.style.removeProperty("height");
- }
- } else {
- if (canvas.width != wNative) canvas.width = wNative;
- if (canvas.height != hNative) canvas.height = hNative;
- if (typeof canvas.style != 'undefined') {
- if (w != wNative || h != hNative) {
- canvas.style.setProperty( "width", w + "px", "important");
- canvas.style.setProperty("height", h + "px", "important");
- } else {
- canvas.style.removeProperty( "width");
- canvas.style.removeProperty("height");
- }
- }
- }
- },wgetRequests:{},nextWgetRequestHandle:0,getNextWgetRequestHandle:function() {
- var handle = Browser.nextWgetRequestHandle;
- Browser.nextWgetRequestHandle++;
- return handle;
- }};
- function _emscripten_set_main_loop_timing(mode, value) {
- Browser.mainLoop.timingMode = mode;
- Browser.mainLoop.timingValue = value;
-
- if (!Browser.mainLoop.func) {
- return 1; // Return non-zero on failure, can't set timing mode when there is no main loop.
- }
-
- if (mode == 0 /*EM_TIMING_SETTIMEOUT*/) {
- Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler_setTimeout() {
- var timeUntilNextTick = Math.max(0, Browser.mainLoop.tickStartTime + value - _emscripten_get_now())|0;
- setTimeout(Browser.mainLoop.runner, timeUntilNextTick); // doing this each time means that on exception, we stop
- };
- Browser.mainLoop.method = 'timeout';
- } else if (mode == 1 /*EM_TIMING_RAF*/) {
- Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler_rAF() {
- Browser.requestAnimationFrame(Browser.mainLoop.runner);
- };
- Browser.mainLoop.method = 'rAF';
- } else if (mode == 2 /*EM_TIMING_SETIMMEDIATE*/) {
- if (typeof setImmediate === 'undefined') {
- // Emulate setImmediate. (note: not a complete polyfill, we don't emulate clearImmediate() to keep code size to minimum, since not needed)
- var setImmediates = [];
- var emscriptenMainLoopMessageId = 'setimmediate';
- var Browser_setImmediate_messageHandler = function(event) {
- // When called in current thread or Worker, the main loop ID is structured slightly different to accommodate for --proxy-to-worker runtime listening to Worker events,
- // so check for both cases.
- if (event.data === emscriptenMainLoopMessageId || event.data.target === emscriptenMainLoopMessageId) {
- event.stopPropagation();
- setImmediates.shift()();
- }
- }
- addEventListener("message", Browser_setImmediate_messageHandler, true);
- setImmediate = /** @type{function(function(): ?, ...?): number} */(function Browser_emulated_setImmediate(func) {
- setImmediates.push(func);
- if (ENVIRONMENT_IS_WORKER) {
- if (Module['setImmediates'] === undefined) Module['setImmediates'] = [];
- Module['setImmediates'].push(func);
- postMessage({target: emscriptenMainLoopMessageId}); // In --proxy-to-worker, route the message via proxyClient.js
- } else postMessage(emscriptenMainLoopMessageId, "*"); // On the main thread, can just send the message to itself.
- })
- }
- Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler_setImmediate() {
- setImmediate(Browser.mainLoop.runner);
- };
- Browser.mainLoop.method = 'immediate';
- }
- return 0;
- }
-
- var _emscripten_get_now;if (ENVIRONMENT_IS_NODE) {
- _emscripten_get_now = function() {
- var t = process['hrtime']();
- return t[0] * 1e3 + t[1] / 1e6;
- };
- } else if (typeof dateNow !== 'undefined') {
- _emscripten_get_now = dateNow;
- } else _emscripten_get_now = function() { return performance.now(); }
- ;
- function setMainLoop(browserIterationFunc, fps, simulateInfiniteLoop, arg, noSetTiming) {
- noExitRuntime = true;
-
- assert(!Browser.mainLoop.func, 'emscripten_set_main_loop: there can only be one main loop function at once: call emscripten_cancel_main_loop to cancel the previous one before setting a new one with different parameters.');
-
- Browser.mainLoop.func = browserIterationFunc;
- Browser.mainLoop.arg = arg;
-
- var thisMainLoopId = Browser.mainLoop.currentlyRunningMainloop;
-
- Browser.mainLoop.runner = function Browser_mainLoop_runner() {
- if (ABORT) return;
- if (Browser.mainLoop.queue.length > 0) {
- var start = Date.now();
- var blocker = Browser.mainLoop.queue.shift();
- blocker.func(blocker.arg);
- if (Browser.mainLoop.remainingBlockers) {
- var remaining = Browser.mainLoop.remainingBlockers;
- var next = remaining%1 == 0 ? remaining-1 : Math.floor(remaining);
- if (blocker.counted) {
- Browser.mainLoop.remainingBlockers = next;
- } else {
- // not counted, but move the progress along a tiny bit
- next = next + 0.5; // do not steal all the next one's progress
- Browser.mainLoop.remainingBlockers = (8*remaining + next)/9;
- }
- }
- console.log('main loop blocker "' + blocker.name + '" took ' + (Date.now() - start) + ' ms'); //, left: ' + Browser.mainLoop.remainingBlockers);
- Browser.mainLoop.updateStatus();
-
- // catches pause/resume main loop from blocker execution
- if (thisMainLoopId < Browser.mainLoop.currentlyRunningMainloop) return;
-
- setTimeout(Browser.mainLoop.runner, 0);
- return;
- }
-
- // catch pauses from non-main loop sources
- if (thisMainLoopId < Browser.mainLoop.currentlyRunningMainloop) return;
-
- // Implement very basic swap interval control
- Browser.mainLoop.currentFrameNumber = Browser.mainLoop.currentFrameNumber + 1 | 0;
- if (Browser.mainLoop.timingMode == 1/*EM_TIMING_RAF*/ && Browser.mainLoop.timingValue > 1 && Browser.mainLoop.currentFrameNumber % Browser.mainLoop.timingValue != 0) {
- // Not the scheduled time to render this frame - skip.
- Browser.mainLoop.scheduler();
- return;
- } else if (Browser.mainLoop.timingMode == 0/*EM_TIMING_SETTIMEOUT*/) {
- Browser.mainLoop.tickStartTime = _emscripten_get_now();
- }
-
- // Signal GL rendering layer that processing of a new frame is about to start. This helps it optimize
- // VBO double-buffering and reduce GPU stalls.
-
- Browser.mainLoop.runIter(browserIterationFunc);
-
- // catch pauses from the main loop itself
- if (thisMainLoopId < Browser.mainLoop.currentlyRunningMainloop) return;
-
- // Queue new audio data. This is important to be right after the main loop invocation, so that we will immediately be able
- // to queue the newest produced audio samples.
- // TODO: Consider adding pre- and post- rAF callbacks so that GL.newRenderingFrameStarted() and SDL.audio.queueNewAudioData()
- // do not need to be hardcoded into this function, but can be more generic.
- if (typeof SDL === 'object' && SDL.audio && SDL.audio.queueNewAudioData) SDL.audio.queueNewAudioData();
-
- Browser.mainLoop.scheduler();
- }
-
- if (!noSetTiming) {
- if (fps && fps > 0) _emscripten_set_main_loop_timing(0/*EM_TIMING_SETTIMEOUT*/, 1000.0 / fps);
- else _emscripten_set_main_loop_timing(1/*EM_TIMING_RAF*/, 1); // Do rAF by rendering each frame (no decimating)
-
- Browser.mainLoop.scheduler();
- }
-
- if (simulateInfiniteLoop) {
- throw 'unwind';
- }
- }
- function _emscripten_set_main_loop(func, fps, simulateInfiniteLoop) {
- var browserIterationFunc = (function() { dynCall_v.call(null, func); });
- setMainLoop(browserIterationFunc, fps, simulateInfiniteLoop);
- }
- function _emscripten_set_mousedown_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerMouseEventCallback(target, userData, useCapture, callbackfunc, 5, "mousedown", targetThread);
- return 0;
- }
- function _emscripten_set_mouseenter_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerMouseEventCallback(target, userData, useCapture, callbackfunc, 33, "mouseenter", targetThread);
- return 0;
- }
- function _emscripten_set_mouseleave_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerMouseEventCallback(target, userData, useCapture, callbackfunc, 34, "mouseleave", targetThread);
- return 0;
- }
- function _emscripten_set_mousemove_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerMouseEventCallback(target, userData, useCapture, callbackfunc, 8, "mousemove", targetThread);
- return 0;
- }
- function _emscripten_set_mouseup_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerMouseEventCallback(target, userData, useCapture, callbackfunc, 6, "mouseup", targetThread);
- return 0;
- }
- function registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
- if (!JSEvents.pointerlockChangeEvent) JSEvents.pointerlockChangeEvent = _malloc( 260 );
-
- var pointerlockChangeEventHandlerFunc = function(ev) {
- var e = ev || event;
-
- var pointerlockChangeEvent = JSEvents.pointerlockChangeEvent;
- fillPointerlockChangeEventData(pointerlockChangeEvent);
-
- if ((function(a1, a2, a3) { dynCall_iiii.apply(null, [callbackfunc, a1, a2, a3]); })(eventTypeId, pointerlockChangeEvent, userData)) e.preventDefault();
- };
-
- var eventHandler = {
- target: target,
- eventTypeString: eventTypeString,
- callbackfunc: callbackfunc,
- handlerFunc: pointerlockChangeEventHandlerFunc,
- useCapture: useCapture
- };
- JSEvents.registerOrRemoveHandler(eventHandler);
- }
- /** @suppress {missingProperties} */
- function _emscripten_set_pointerlockchange_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- // TODO: Currently not supported in pthreads or in --proxy-to-worker mode. (In pthreads mode, document object is not defined)
- if (!document || !document.body || (!document.body.requestPointerLock && !document.body.mozRequestPointerLock && !document.body.webkitRequestPointerLock && !document.body.msRequestPointerLock)) {
- return -1;
- }
-
- target = findEventTarget(target);
- if (!target) return -4;
- registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, 20, "pointerlockchange", targetThread);
- registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, 20, "mozpointerlockchange", targetThread);
- registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, 20, "webkitpointerlockchange", targetThread);
- registerPointerlockChangeEventCallback(target, userData, useCapture, callbackfunc, 20, "mspointerlockchange", targetThread);
- return 0;
- }
- function registerUiEventCallback(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
- if (!JSEvents.uiEvent) JSEvents.uiEvent = _malloc( 36 );
-
- target = findEventTarget(target);
-
- var uiEventHandlerFunc = function(ev) {
- var e = ev || event;
- if (e.target != target) {
- // Never take ui events such as scroll via a 'bubbled' route, but always from the direct element that
- // was targeted. Otherwise e.g. if app logs a message in response to a page scroll, the Emscripten log
- // message box could cause to scroll, generating a new (bubbled) scroll message, causing a new log print,
- // causing a new scroll, etc..
- return;
- }
- var b = document.body; // Take document.body to a variable, Closure compiler does not outline access to it on its own.
- if (!b) {
- // During a page unload 'body' can be null, with "Cannot read property 'clientWidth' of null" being thrown
- return;
- }
- var uiEvent = JSEvents.uiEvent;
- HEAP32[((uiEvent)>>2)] = e.detail;
- HEAP32[(((uiEvent)+(4))>>2)] = b.clientWidth;
- HEAP32[(((uiEvent)+(8))>>2)] = b.clientHeight;
- HEAP32[(((uiEvent)+(12))>>2)] = innerWidth;
- HEAP32[(((uiEvent)+(16))>>2)] = innerHeight;
- HEAP32[(((uiEvent)+(20))>>2)] = outerWidth;
- HEAP32[(((uiEvent)+(24))>>2)] = outerHeight;
- HEAP32[(((uiEvent)+(28))>>2)] = pageXOffset;
- HEAP32[(((uiEvent)+(32))>>2)] = pageYOffset;
- if ((function(a1, a2, a3) { dynCall_iiii.apply(null, [callbackfunc, a1, a2, a3]); })(eventTypeId, uiEvent, userData)) e.preventDefault();
- };
-
- var eventHandler = {
- target: target,
- eventTypeString: eventTypeString,
- callbackfunc: callbackfunc,
- handlerFunc: uiEventHandlerFunc,
- useCapture: useCapture
- };
- JSEvents.registerOrRemoveHandler(eventHandler);
- }
- function _emscripten_set_resize_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- registerUiEventCallback(target, userData, useCapture, callbackfunc, 10, "resize", targetThread);
- return 0;
- }
- function registerWheelEventCallback(target, userData, useCapture, callbackfunc, eventTypeId, eventTypeString, targetThread) {
- if (!JSEvents.wheelEvent) JSEvents.wheelEvent = _malloc( 96 );
-
- // The DOM Level 3 events spec event 'wheel'
- var wheelHandlerFunc = function(ev) {
- var e = ev || event;
- var wheelEvent = JSEvents.wheelEvent;
- fillMouseEventData(wheelEvent, e, target);
- HEAPF64[(((wheelEvent)+(64))>>3)] = e["deltaX"];
- HEAPF64[(((wheelEvent)+(72))>>3)] = e["deltaY"];
- HEAPF64[(((wheelEvent)+(80))>>3)] = e["deltaZ"];
- HEAP32[(((wheelEvent)+(88))>>2)] = e["deltaMode"];
- if ((function(a1, a2, a3) { dynCall_iiii.apply(null, [callbackfunc, a1, a2, a3]); })(eventTypeId, wheelEvent, userData)) e.preventDefault();
- };
-
- var eventHandler = {
- target: target,
- allowsDeferredCalls: true,
- eventTypeString: eventTypeString,
- callbackfunc: callbackfunc,
- handlerFunc: wheelHandlerFunc,
- useCapture: useCapture
- };
- JSEvents.registerOrRemoveHandler(eventHandler);
- }
- function _emscripten_set_wheel_callback_on_thread(target, userData, useCapture, callbackfunc, targetThread) {
- target = findEventTarget(target);
- if (typeof target.onwheel !== 'undefined') {
- registerWheelEventCallback(target, userData, useCapture, callbackfunc, 9, "wheel", targetThread);
- return 0;
- } else {
- return -1;
- }
- }
- function _emscripten_sleep(ms) {
- Asyncify.handleSleep(function(wakeUp) {
- Browser.safeSetTimeout(wakeUp, ms);
- });
- }
- function __webgl_enable_ANGLE_instanced_arrays(ctx) {
- // Extension available in WebGL 1 from Firefox 26 and Google Chrome 30 onwards. Core feature in WebGL 2.
- var ext = ctx.getExtension('ANGLE_instanced_arrays');
- if (ext) {
- ctx['vertexAttribDivisor'] = function(index, divisor) { ext['vertexAttribDivisorANGLE'](index, divisor); };
- ctx['drawArraysInstanced'] = function(mode, first, count, primcount) { ext['drawArraysInstancedANGLE'](mode, first, count, primcount); };
- ctx['drawElementsInstanced'] = function(mode, count, type, indices, primcount) { ext['drawElementsInstancedANGLE'](mode, count, type, indices, primcount); };
- return 1;
- }
- }
-
- function __webgl_enable_OES_vertex_array_object(ctx) {
- // Extension available in WebGL 1 from Firefox 25 and WebKit 536.28/desktop Safari 6.0.3 onwards. Core feature in WebGL 2.
- var ext = ctx.getExtension('OES_vertex_array_object');
- if (ext) {
- ctx['createVertexArray'] = function() { return ext['createVertexArrayOES'](); };
- ctx['deleteVertexArray'] = function(vao) { ext['deleteVertexArrayOES'](vao); };
- ctx['bindVertexArray'] = function(vao) { ext['bindVertexArrayOES'](vao); };
- ctx['isVertexArray'] = function(vao) { return ext['isVertexArrayOES'](vao); };
- return 1;
- }
- }
-
- function __webgl_enable_WEBGL_draw_buffers(ctx) {
- // Extension available in WebGL 1 from Firefox 28 onwards. Core feature in WebGL 2.
- var ext = ctx.getExtension('WEBGL_draw_buffers');
- if (ext) {
- ctx['drawBuffers'] = function(n, bufs) { ext['drawBuffersWEBGL'](n, bufs); };
- return 1;
- }
- }
-
- function __webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance(ctx) {
- // Closure is expected to be allowed to minify the '.dibvbi' property, so not accessing it quoted.
- return !!(ctx.dibvbi = ctx.getExtension('WEBGL_draw_instanced_base_vertex_base_instance'));
- }
-
- function __webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance(ctx) {
- // Closure is expected to be allowed to minify the '.mdibvbi' property, so not accessing it quoted.
- return !!(ctx.mdibvbi = ctx.getExtension('WEBGL_multi_draw_instanced_base_vertex_base_instance'));
- }
-
- function __webgl_enable_WEBGL_multi_draw(ctx) {
- // Closure is expected to be allowed to minify the '.multiDrawWebgl' property, so not accessing it quoted.
- return !!(ctx.multiDrawWebgl = ctx.getExtension('WEBGL_multi_draw'));
- }
- var GL={counter:1,buffers:[],programs:[],framebuffers:[],renderbuffers:[],textures:[],uniforms:[],shaders:[],vaos:[],contexts:[],offscreenCanvases:{},timerQueriesEXT:[],queries:[],samplers:[],transformFeedbacks:[],syncs:[],programInfos:{},stringCache:{},stringiCache:{},unpackAlignment:4,recordError:function recordError(errorCode) {
- if (!GL.lastError) {
- GL.lastError = errorCode;
- }
- },getNewId:function(table) {
- var ret = GL.counter++;
- for (var i = table.length; i < ret; i++) {
- table[i] = null;
- }
- return ret;
- },getSource:function(shader, count, string, length) {
- var source = '';
- for (var i = 0; i < count; ++i) {
- var len = length ? HEAP32[(((length)+(i*4))>>2)] : -1;
- source += UTF8ToString(HEAP32[(((string)+(i*4))>>2)], len < 0 ? undefined : len);
- }
- return source;
- },createContext:function(canvas, webGLContextAttributes) {
-
- var ctx =
- (webGLContextAttributes.majorVersion > 1)
- ?
- canvas.getContext("webgl2", webGLContextAttributes)
- :
- (canvas.getContext("webgl", webGLContextAttributes)
- // https://caniuse.com/#feat=webgl
- );
-
- if (!ctx) return 0;
-
- var handle = GL.registerContext(ctx, webGLContextAttributes);
-
- return handle;
- },registerContext:function(ctx, webGLContextAttributes) {
- // without pthreads a context is just an integer ID
- var handle = GL.getNewId(GL.contexts);
-
- var context = {
- handle: handle,
- attributes: webGLContextAttributes,
- version: webGLContextAttributes.majorVersion,
- GLctx: ctx
- };
-
- // Store the created context object so that we can access the context given a canvas without having to pass the parameters again.
- if (ctx.canvas) ctx.canvas.GLctxObject = context;
- GL.contexts[handle] = context;
- if (typeof webGLContextAttributes.enableExtensionsByDefault === 'undefined' || webGLContextAttributes.enableExtensionsByDefault) {
- GL.initExtensions(context);
- }
-
- return handle;
- },makeContextCurrent:function(contextHandle) {
-
- GL.currentContext = GL.contexts[contextHandle]; // Active Emscripten GL layer context object.
- Module.ctx = GLctx = GL.currentContext && GL.currentContext.GLctx; // Active WebGL context object.
- return !(contextHandle && !GLctx);
- },getContext:function(contextHandle) {
- return GL.contexts[contextHandle];
- },deleteContext:function(contextHandle) {
- if (GL.currentContext === GL.contexts[contextHandle]) GL.currentContext = null;
- if (typeof JSEvents === 'object') JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas); // Release all JS event handlers on the DOM element that the GL context is associated with since the context is now deleted.
- if (GL.contexts[contextHandle] && GL.contexts[contextHandle].GLctx.canvas) GL.contexts[contextHandle].GLctx.canvas.GLctxObject = undefined; // Make sure the canvas object no longer refers to the context object so there are no GC surprises.
- GL.contexts[contextHandle] = null;
- },initExtensions:function(context) {
- // If this function is called without a specific context object, init the extensions of the currently active context.
- if (!context) context = GL.currentContext;
-
- if (context.initExtensionsDone) return;
- context.initExtensionsDone = true;
-
- var GLctx = context.GLctx;
-
- // Detect the presence of a few extensions manually, this GL interop layer itself will need to know if they exist.
-
- // Extensions that are only available in WebGL 1 (the calls will be no-ops if called on a WebGL 2 context active)
- __webgl_enable_ANGLE_instanced_arrays(GLctx);
- __webgl_enable_OES_vertex_array_object(GLctx);
- __webgl_enable_WEBGL_draw_buffers(GLctx);
- // Extensions that are available from WebGL >= 2 (no-op if called on a WebGL 1 context active)
- __webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance(GLctx);
- __webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance(GLctx);
-
- GLctx.disjointTimerQueryExt = GLctx.getExtension("EXT_disjoint_timer_query");
- __webgl_enable_WEBGL_multi_draw(GLctx);
-
- // .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
- var exts = GLctx.getSupportedExtensions() || [];
- exts.forEach(function(ext) {
- // WEBGL_lose_context, WEBGL_debug_renderer_info and WEBGL_debug_shaders are not enabled by default.
- if (ext.indexOf('lose_context') < 0 && ext.indexOf('debug') < 0) {
- // Call .getExtension() to enable that extension permanently.
- GLctx.getExtension(ext);
- }
- });
- },populateUniformTable:function(program) {
- var p = GL.programs[program];
- var ptable = GL.programInfos[program] = {
- uniforms: {},
- maxUniformLength: 0, // This is eagerly computed below, since we already enumerate all uniforms anyway.
- maxAttributeLength: -1, // This is lazily computed and cached, computed when/if first asked, "-1" meaning not computed yet.
- maxUniformBlockNameLength: -1 // Lazily computed as well
- };
-
- var utable = ptable.uniforms;
- // A program's uniform table maps the string name of an uniform to an integer location of that uniform.
- // The global GL.uniforms map maps integer locations to WebGLUniformLocations.
- var numUniforms = GLctx.getProgramParameter(p, 0x8B86/*GL_ACTIVE_UNIFORMS*/);
- for (var i = 0; i < numUniforms; ++i) {
- var u = GLctx.getActiveUniform(p, i);
-
- var name = u.name;
- ptable.maxUniformLength = Math.max(ptable.maxUniformLength, name.length+1);
-
- // If we are dealing with an array, e.g. vec4 foo[3], strip off the array index part to canonicalize that "foo", "foo[]",
- // and "foo[0]" will mean the same. Loop below will populate foo[1] and foo[2].
- if (name.slice(-1) == ']') {
- name = name.slice(0, name.lastIndexOf('['));
- }
-
- // Optimize memory usage slightly: If we have an array of uniforms, e.g. 'vec3 colors[3];', then
- // only store the string 'colors' in utable, and 'colors[0]', 'colors[1]' and 'colors[2]' will be parsed as 'colors'+i.
- // Note that for the GL.uniforms table, we still need to fetch the all WebGLUniformLocations for all the indices.
- var loc = GLctx.getUniformLocation(p, name);
- if (loc) {
- var id = GL.getNewId(GL.uniforms);
- utable[name] = [u.size, id];
- GL.uniforms[id] = loc;
-
- for (var j = 1; j < u.size; ++j) {
- var n = name + '['+j+']';
- loc = GLctx.getUniformLocation(p, n);
- id = GL.getNewId(GL.uniforms);
-
- GL.uniforms[id] = loc;
- }
- }
- }
- }};
-
- var __emscripten_webgl_power_preferences=['default', 'low-power', 'high-performance'];
- function _emscripten_webgl_do_create_context(target, attributes) {
- var a = attributes >> 2;
- var powerPreference = HEAP32[a + (24>>2)];
- var contextAttributes = {
- 'alpha': !!HEAP32[a + (0>>2)],
- 'depth': !!HEAP32[a + (4>>2)],
- 'stencil': !!HEAP32[a + (8>>2)],
- 'antialias': !!HEAP32[a + (12>>2)],
- 'premultipliedAlpha': !!HEAP32[a + (16>>2)],
- 'preserveDrawingBuffer': !!HEAP32[a + (20>>2)],
- 'powerPreference': __emscripten_webgl_power_preferences[powerPreference],
- 'failIfMajorPerformanceCaveat': !!HEAP32[a + (28>>2)],
- // The following are not predefined WebGL context attributes in the WebGL specification, so the property names can be minified by Closure.
- majorVersion: HEAP32[a + (32>>2)],
- minorVersion: HEAP32[a + (36>>2)],
- enableExtensionsByDefault: HEAP32[a + (40>>2)],
- explicitSwapControl: HEAP32[a + (44>>2)],
- proxyContextToMainThread: HEAP32[a + (48>>2)],
- renderViaOffscreenBackBuffer: HEAP32[a + (52>>2)]
- };
-
- var canvas = findCanvasEventTarget(target);
-
- if (!canvas) {
- return 0;
- }
-
- if (contextAttributes.explicitSwapControl) {
- return 0;
- }
-
- var contextHandle = GL.createContext(canvas, contextAttributes);
- return contextHandle;
- }
- function _emscripten_webgl_create_context(a0,a1
- ) {
- return _emscripten_webgl_do_create_context(a0,a1);
- }
- function _emscripten_webgl_init_context_attributes(attributes) {
- var a = attributes >> 2;
- for(var i = 0; i < (56>>2); ++i) {
- HEAP32[a+i] = 0;
- }
-
- HEAP32[a + (0>>2)] =
- HEAP32[a + (4>>2)] =
- HEAP32[a + (12>>2)] =
- HEAP32[a + (16>>2)] =
- HEAP32[a + (32>>2)] =
- HEAP32[a + (40>>2)] = 1;
-
- }
- function _emscripten_webgl_make_context_current(contextHandle) {
- var success = GL.makeContextCurrent(contextHandle);
- return success ? 0 : -5;
- }
- function flush_NO_FILESYSTEM() {
- // flush anything remaining in the buffers during shutdown
- if (typeof _fflush !== 'undefined') _fflush(0);
- var buffers = SYSCALLS.buffers;
- if (buffers[1].length) SYSCALLS.printChar(1, 10);
- if (buffers[2].length) SYSCALLS.printChar(2, 10);
- }
-
- var SYSCALLS={mappings:{},buffers:[null,[],[]],printChar:function(stream, curr) {
- var buffer = SYSCALLS.buffers[stream];
- if (curr === 0 || curr === 10) {
- (stream === 1 ? out : err)(UTF8ArrayToString(buffer, 0));
- buffer.length = 0;
- } else {
- buffer.push(curr);
- }
- },varargs:undefined,get:function() {
- SYSCALLS.varargs += 4;
- var ret = HEAP32[(((SYSCALLS.varargs)-(4))>>2)];
- return ret;
- },getStr:function(ptr) {
- var ret = UTF8ToString(ptr);
- return ret;
- },get64:function(low, high) {
- return low;
- }};
- function _fd_write(fd, iov, iovcnt, pnum) {
- // hack to support printf in SYSCALLS_REQUIRE_FILESYSTEM=0
- var num = 0;
- for (var i = 0; i < iovcnt; i++) {
- var ptr = HEAP32[(((iov)+(i*8))>>2)];
- var len = HEAP32[(((iov)+(i*8 + 4))>>2)];
- for (var j = 0; j < len; j++) {
- SYSCALLS.printChar(fd, HEAPU8[ptr+j]);
- }
- num += len;
- }
- HEAP32[((pnum)>>2)] = num
- return 0;
- }
- function _glActiveTexture(x0) { GLctx['activeTexture'](x0) }
- function _glAttachShader(program, shader) {
- GLctx.attachShader(GL.programs[program],
- GL.shaders[shader]);
- }
- function _glBindBuffer(target, buffer) {
-
- if (target == 0x88EB /*GL_PIXEL_PACK_BUFFER*/) {
- // In WebGL 2 glReadPixels entry point, we need to use a different WebGL 2 API function call when a buffer is bound to
- // GL_PIXEL_PACK_BUFFER_BINDING point, so must keep track whether that binding point is non-null to know what is
- // the proper API function to call.
- GLctx.currentPixelPackBufferBinding = buffer;
- } else if (target == 0x88EC /*GL_PIXEL_UNPACK_BUFFER*/) {
- // In WebGL 2 gl(Compressed)Tex(Sub)Image[23]D entry points, we need to
- // use a different WebGL 2 API function call when a buffer is bound to
- // GL_PIXEL_UNPACK_BUFFER_BINDING point, so must keep track whether that
- // binding point is non-null to know what is the proper API function to
- // call.
- GLctx.currentPixelUnpackBufferBinding = buffer;
- }
- GLctx.bindBuffer(target, GL.buffers[buffer]);
- }
- function _glBindBufferRange(target, index, buffer, offset, ptrsize) {
- GLctx['bindBufferRange'](target, index, GL.buffers[buffer], offset, ptrsize);
- }
- function _glBindFramebuffer(target, framebuffer) {
-
- GLctx.bindFramebuffer(target, GL.framebuffers[framebuffer]);
-
- }
- function _glBindRenderbuffer(target, renderbuffer) {
- GLctx.bindRenderbuffer(target, GL.renderbuffers[renderbuffer]);
- }
- function _glBindTexture(target, texture) {
- GLctx.bindTexture(target, GL.textures[texture]);
- }
- function _glBindVertexArray(vao) {
- GLctx['bindVertexArray'](GL.vaos[vao]);
- }
- function _glBlendEquation(x0) { GLctx['blendEquation'](x0) }
- function _glBlendFunc(x0, x1) { GLctx['blendFunc'](x0, x1) }
- function _glBufferData(target, size, data, usage) {
-
- if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
- if (data) {
- GLctx.bufferData(target, HEAPU8, usage, data, size);
- } else {
- GLctx.bufferData(target, size, usage);
- }
- } else {
- // N.b. here first form specifies a heap subarray, second form an integer size, so the ?: code here is polymorphic. It is advised to avoid
- // randomly mixing both uses in calling code, to avoid any potential JS engine JIT issues.
- GLctx.bufferData(target, data ? HEAPU8.subarray(data, data+size) : size, usage);
- }
- }
- function _glBufferSubData(target, offset, size, data) {
- if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
- GLctx.bufferSubData(target, offset, HEAPU8, data, size);
- return;
- }
- GLctx.bufferSubData(target, offset, HEAPU8.subarray(data, data+size));
- }
- function _glClear(x0) { GLctx['clear'](x0) }
- function _glClearColor(x0, x1, x2, x3) { GLctx['clearColor'](x0, x1, x2, x3) }
- function _glCompileShader(shader) {
- GLctx.compileShader(GL.shaders[shader]);
- }
- function _glCreateProgram() {
- var id = GL.getNewId(GL.programs);
- var program = GLctx.createProgram();
- program.name = id;
- GL.programs[id] = program;
- return id;
- }
- function _glCreateShader(shaderType) {
- var id = GL.getNewId(GL.shaders);
- GL.shaders[id] = GLctx.createShader(shaderType);
- return id;
- }
- function _glCullFace(x0) { GLctx['cullFace'](x0) }
- function _glDeleteProgram(id) {
- if (!id) return;
- var program = GL.programs[id];
- if (!program) { // glDeleteProgram actually signals an error when deleting a nonexisting object, unlike some other GL delete functions.
- GL.recordError(0x501 /* GL_INVALID_VALUE */);
- return;
- }
- GLctx.deleteProgram(program);
- program.name = 0;
- GL.programs[id] = null;
- GL.programInfos[id] = null;
- }
- function _glDeleteShader(id) {
- if (!id) return;
- var shader = GL.shaders[id];
- if (!shader) { // glDeleteShader actually signals an error when deleting a nonexisting object, unlike some other GL delete functions.
- GL.recordError(0x501 /* GL_INVALID_VALUE */);
- return;
- }
- GLctx.deleteShader(shader);
- GL.shaders[id] = null;
- }
- function _glDepthFunc(x0) { GLctx['depthFunc'](x0) }
- function _glDisable(x0) { GLctx['disable'](x0) }
- function _glDrawArrays(mode, first, count) {
-
- GLctx.drawArrays(mode, first, count);
-
- }
- function _glDrawArraysInstanced(mode, first, count, primcount) {
- GLctx['drawArraysInstanced'](mode, first, count, primcount);
- }
- function _glDrawElements(mode, count, type, indices) {
-
- GLctx.drawElements(mode, count, type, indices);
-
- }
- function _glDrawElementsInstanced(mode, count, type, indices, primcount) {
- GLctx['drawElementsInstanced'](mode, count, type, indices, primcount);
- }
- function _glEnable(x0) { GLctx['enable'](x0) }
- function _glEnableVertexAttribArray(index) {
- GLctx.enableVertexAttribArray(index);
- }
- function _glFramebufferTexture2D(target, attachment, textarget, texture, level) {
- GLctx.framebufferTexture2D(target, attachment, textarget,
- GL.textures[texture], level);
- }
- function _glFrontFace(x0) { GLctx['frontFace'](x0) }
- function __glGenObject(n, buffers, createFunction, objectTable
- ) {
- for (var i = 0; i < n; i++) {
- var buffer = GLctx[createFunction]();
- var id = buffer && GL.getNewId(objectTable);
- if (buffer) {
- buffer.name = id;
- objectTable[id] = buffer;
- } else {
- GL.recordError(0x502 /* GL_INVALID_OPERATION */);
- }
- HEAP32[(((buffers)+(i*4))>>2)] = id;
- }
- }
- function _glGenBuffers(n, buffers) {
- __glGenObject(n, buffers, 'createBuffer', GL.buffers
- );
- }
- function _glGenFramebuffers(n, ids) {
- __glGenObject(n, ids, 'createFramebuffer', GL.framebuffers
- );
- }
- function _glGenTextures(n, textures) {
- __glGenObject(n, textures, 'createTexture', GL.textures
- );
- }
- function _glGenVertexArrays(n, arrays) {
- __glGenObject(n, arrays, 'createVertexArray', GL.vaos
- );
- }
- function _glGenerateMipmap(x0) { GLctx['generateMipmap'](x0) }
- function writeI53ToI64(ptr, num) {
- HEAPU32[ptr>>2] = num;
- HEAPU32[ptr+4>>2] = (num - HEAPU32[ptr>>2])/4294967296;
- }
- function emscriptenWebGLGet(name_, p, type) {
- // Guard against user passing a null pointer.
- // Note that GLES2 spec does not say anything about how passing a null pointer should be treated.
- // Testing on desktop core GL 3, the application crashes on glGetIntegerv to a null pointer, but
- // better to report an error instead of doing anything random.
- if (!p) {
- GL.recordError(0x501 /* GL_INVALID_VALUE */);
- return;
- }
- var ret = undefined;
- switch(name_) { // Handle a few trivial GLES values
- case 0x8DFA: // GL_SHADER_COMPILER
- ret = 1;
- break;
- case 0x8DF8: // GL_SHADER_BINARY_FORMATS
- if (type != 0 && type != 1) {
- GL.recordError(0x500); // GL_INVALID_ENUM
- }
- return; // Do not write anything to the out pointer, since no binary formats are supported.
- case 0x87FE: // GL_NUM_PROGRAM_BINARY_FORMATS
- case 0x8DF9: // GL_NUM_SHADER_BINARY_FORMATS
- ret = 0;
- break;
- case 0x86A2: // GL_NUM_COMPRESSED_TEXTURE_FORMATS
- // WebGL doesn't have GL_NUM_COMPRESSED_TEXTURE_FORMATS (it's obsolete since GL_COMPRESSED_TEXTURE_FORMATS returns a JS array that can be queried for length),
- // so implement it ourselves to allow C++ GLES2 code get the length.
- var formats = GLctx.getParameter(0x86A3 /*GL_COMPRESSED_TEXTURE_FORMATS*/);
- ret = formats ? formats.length : 0;
- break;
- case 0x821D: // GL_NUM_EXTENSIONS
- if (GL.currentContext.version < 2) {
- GL.recordError(0x502 /* GL_INVALID_OPERATION */); // Calling GLES3/WebGL2 function with a GLES2/WebGL1 context
- return;
- }
- // .getSupportedExtensions() can return null if context is lost, so coerce to empty array.
- var exts = GLctx.getSupportedExtensions() || [];
- ret = 2 * exts.length; // each extension is duplicated, first in unprefixed WebGL form, and then a second time with "GL_" prefix.
- break;
- case 0x821B: // GL_MAJOR_VERSION
- case 0x821C: // GL_MINOR_VERSION
- if (GL.currentContext.version < 2) {
- GL.recordError(0x500); // GL_INVALID_ENUM
- return;
- }
- ret = name_ == 0x821B ? 3 : 0; // return version 3.0
- break;
- }
-
- if (ret === undefined) {
- var result = GLctx.getParameter(name_);
- switch (typeof(result)) {
- case "number":
- ret = result;
- break;
- case "boolean":
- ret = result ? 1 : 0;
- break;
- case "string":
- GL.recordError(0x500); // GL_INVALID_ENUM
- return;
- case "object":
- if (result === null) {
- // null is a valid result for some (e.g., which buffer is bound - perhaps nothing is bound), but otherwise
- // can mean an invalid name_, which we need to report as an error
- switch(name_) {
- case 0x8894: // ARRAY_BUFFER_BINDING
- case 0x8B8D: // CURRENT_PROGRAM
- case 0x8895: // ELEMENT_ARRAY_BUFFER_BINDING
- case 0x8CA6: // FRAMEBUFFER_BINDING or DRAW_FRAMEBUFFER_BINDING
- case 0x8CA7: // RENDERBUFFER_BINDING
- case 0x8069: // TEXTURE_BINDING_2D
- case 0x85B5: // WebGL 2 GL_VERTEX_ARRAY_BINDING, or WebGL 1 extension OES_vertex_array_object GL_VERTEX_ARRAY_BINDING_OES
- case 0x8F36: // COPY_READ_BUFFER_BINDING or COPY_READ_BUFFER
- case 0x8F37: // COPY_WRITE_BUFFER_BINDING or COPY_WRITE_BUFFER
- case 0x88ED: // PIXEL_PACK_BUFFER_BINDING
- case 0x88EF: // PIXEL_UNPACK_BUFFER_BINDING
- case 0x8CAA: // READ_FRAMEBUFFER_BINDING
- case 0x8919: // SAMPLER_BINDING
- case 0x8C1D: // TEXTURE_BINDING_2D_ARRAY
- case 0x806A: // TEXTURE_BINDING_3D
- case 0x8E25: // TRANSFORM_FEEDBACK_BINDING
- case 0x8C8F: // TRANSFORM_FEEDBACK_BUFFER_BINDING
- case 0x8A28: // UNIFORM_BUFFER_BINDING
- case 0x8514: { // TEXTURE_BINDING_CUBE_MAP
- ret = 0;
- break;
- }
- default: {
- GL.recordError(0x500); // GL_INVALID_ENUM
- return;
- }
- }
- } else if (result instanceof Float32Array ||
- result instanceof Uint32Array ||
- result instanceof Int32Array ||
- result instanceof Array) {
- for (var i = 0; i < result.length; ++i) {
- switch (type) {
- case 0: HEAP32[(((p)+(i*4))>>2)] = result[i]; break;
- case 2: HEAPF32[(((p)+(i*4))>>2)] = result[i]; break;
- case 4: HEAP8[(((p)+(i))>>0)] = result[i] ? 1 : 0; break;
- }
- }
- return;
- } else {
- try {
- ret = result.name | 0;
- } catch(e) {
- GL.recordError(0x500); // GL_INVALID_ENUM
- err('GL_INVALID_ENUM in glGet' + type + 'v: Unknown object returned from WebGL getParameter(' + name_ + ')! (error: ' + e + ')');
- return;
- }
- }
- break;
- default:
- GL.recordError(0x500); // GL_INVALID_ENUM
- err('GL_INVALID_ENUM in glGet' + type + 'v: Native code calling glGet' + type + 'v(' + name_ + ') and it returns ' + result + ' of type ' + typeof(result) + '!');
- return;
- }
- }
-
- switch (type) {
- case 1: writeI53ToI64(p, ret); break;
- case 0: HEAP32[((p)>>2)] = ret; break;
- case 2: HEAPF32[((p)>>2)] = ret; break;
- case 4: HEAP8[((p)>>0)] = ret ? 1 : 0; break;
- }
- }
- function _glGetIntegerv(name_, p) {
- emscriptenWebGLGet(name_, p, 0);
- }
- function _glGetProgramInfoLog(program, maxLength, length, infoLog) {
- var log = GLctx.getProgramInfoLog(GL.programs[program]);
- if (log === null) log = '(unknown error)';
- var numBytesWrittenExclNull = (maxLength > 0 && infoLog) ? stringToUTF8(log, infoLog, maxLength) : 0;
- if (length) HEAP32[((length)>>2)] = numBytesWrittenExclNull;
- }
- function _glGetProgramiv(program, pname, p) {
- if (!p) {
- // GLES2 specification does not specify how to behave if p is a null pointer. Since calling this function does not make sense
- // if p == null, issue a GL error to notify user about it.
- GL.recordError(0x501 /* GL_INVALID_VALUE */);
- return;
- }
-
- if (program >= GL.counter) {
- GL.recordError(0x501 /* GL_INVALID_VALUE */);
- return;
- }
-
- var ptable = GL.programInfos[program];
- if (!ptable) {
- GL.recordError(0x502 /* GL_INVALID_OPERATION */);
- return;
- }
-
- if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH
- var log = GLctx.getProgramInfoLog(GL.programs[program]);
- if (log === null) log = '(unknown error)';
- HEAP32[((p)>>2)] = log.length + 1;
- } else if (pname == 0x8B87 /* GL_ACTIVE_UNIFORM_MAX_LENGTH */) {
- HEAP32[((p)>>2)] = ptable.maxUniformLength;
- } else if (pname == 0x8B8A /* GL_ACTIVE_ATTRIBUTE_MAX_LENGTH */) {
- if (ptable.maxAttributeLength == -1) {
- program = GL.programs[program];
- var numAttribs = GLctx.getProgramParameter(program, 0x8B89/*GL_ACTIVE_ATTRIBUTES*/);
- ptable.maxAttributeLength = 0; // Spec says if there are no active attribs, 0 must be returned.
- for (var i = 0; i < numAttribs; ++i) {
- var activeAttrib = GLctx.getActiveAttrib(program, i);
- ptable.maxAttributeLength = Math.max(ptable.maxAttributeLength, activeAttrib.name.length+1);
- }
- }
- HEAP32[((p)>>2)] = ptable.maxAttributeLength;
- } else if (pname == 0x8A35 /* GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH */) {
- if (ptable.maxUniformBlockNameLength == -1) {
- program = GL.programs[program];
- var numBlocks = GLctx.getProgramParameter(program, 0x8A36/*GL_ACTIVE_UNIFORM_BLOCKS*/);
- ptable.maxUniformBlockNameLength = 0;
- for (var i = 0; i < numBlocks; ++i) {
- var activeBlockName = GLctx.getActiveUniformBlockName(program, i);
- ptable.maxUniformBlockNameLength = Math.max(ptable.maxUniformBlockNameLength, activeBlockName.length+1);
- }
- }
- HEAP32[((p)>>2)] = ptable.maxUniformBlockNameLength;
- } else {
- HEAP32[((p)>>2)] = GLctx.getProgramParameter(GL.programs[program], pname);
- }
- }
- function _glGetShaderInfoLog(shader, maxLength, length, infoLog) {
- var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
- if (log === null) log = '(unknown error)';
- var numBytesWrittenExclNull = (maxLength > 0 && infoLog) ? stringToUTF8(log, infoLog, maxLength) : 0;
- if (length) HEAP32[((length)>>2)] = numBytesWrittenExclNull;
- }
- function _glGetShaderiv(shader, pname, p) {
- if (!p) {
- // GLES2 specification does not specify how to behave if p is a null pointer. Since calling this function does not make sense
- // if p == null, issue a GL error to notify user about it.
- GL.recordError(0x501 /* GL_INVALID_VALUE */);
- return;
- }
- if (pname == 0x8B84) { // GL_INFO_LOG_LENGTH
- var log = GLctx.getShaderInfoLog(GL.shaders[shader]);
- if (log === null) log = '(unknown error)';
- // The GLES2 specification says that if the shader has an empty info log,
- // a value of 0 is returned. Otherwise the log has a null char appended.
- // (An empty string is falsey, so we can just check that instead of
- // looking at log.length.)
- var logLength = log ? log.length + 1 : 0;
- HEAP32[((p)>>2)] = logLength;
- } else if (pname == 0x8B88) { // GL_SHADER_SOURCE_LENGTH
- var source = GLctx.getShaderSource(GL.shaders[shader]);
- // source may be a null, or the empty string, both of which are falsey
- // values that we report a 0 length for.
- var sourceLength = source ? source.length + 1 : 0;
- HEAP32[((p)>>2)] = sourceLength;
- } else {
- HEAP32[((p)>>2)] = GLctx.getShaderParameter(GL.shaders[shader], pname);
- }
- }
- function _glGetUniformBlockIndex(program, uniformBlockName) {
- return GLctx['getUniformBlockIndex'](GL.programs[program], UTF8ToString(uniformBlockName));
- }
- function _glGetUniformLocation(program, name) {
- name = UTF8ToString(name);
-
- var arrayIndex = 0;
- // If user passed an array accessor "[index]", parse the array index off the accessor.
- if (name[name.length - 1] == ']') {
- var leftBrace = name.lastIndexOf('[');
- arrayIndex = name[leftBrace+1] != ']' ? jstoi_q(name.slice(leftBrace + 1)) : 0; // "index]", parseInt will ignore the ']' at the end; but treat "foo[]" as "foo[0]"
- name = name.slice(0, leftBrace);
- }
-
- var uniformInfo = GL.programInfos[program] && GL.programInfos[program].uniforms[name]; // returns pair [ dimension_of_uniform_array, uniform_location ]
- if (uniformInfo && arrayIndex >= 0 && arrayIndex < uniformInfo[0]) { // Check if user asked for an out-of-bounds element, i.e. for 'vec4 colors[3];' user could ask for 'colors[10]' which should return -1.
- return uniformInfo[1] + arrayIndex;
- } else {
- return -1;
- }
- }
- function _glLinkProgram(program) {
- GLctx.linkProgram(GL.programs[program]);
- GL.populateUniformTable(program);
- }
- function _glScissor(x0, x1, x2, x3) { GLctx['scissor'](x0, x1, x2, x3) }
- function _glShaderSource(shader, count, string, length) {
- var source = GL.getSource(shader, count, string, length);
-
- GLctx.shaderSource(GL.shaders[shader], source);
- }
- function _glStencilFunc(x0, x1, x2) { GLctx['stencilFunc'](x0, x1, x2) }
- function _glStencilMask(x0) { GLctx['stencilMask'](x0) }
- function _glStencilOp(x0, x1, x2) { GLctx['stencilOp'](x0, x1, x2) }
- function computeUnpackAlignedImageSize(width, height, sizePerPixel, alignment) {
- function roundedToNextMultipleOf(x, y) {
- return (x + y - 1) & -y;
- }
- var plainRowSize = width * sizePerPixel;
- var alignedRowSize = roundedToNextMultipleOf(plainRowSize, alignment);
- return height * alignedRowSize;
- }
-
- function __colorChannelsInGlTextureFormat(format) {
- // Micro-optimizations for size: map format to size by subtracting smallest enum value (0x1902) from all values first.
- // Also omit the most common size value (1) from the list, which is assumed by formats not on the list.
- var colorChannels = {
- // 0x1902 /* GL_DEPTH_COMPONENT */ - 0x1902: 1,
- // 0x1906 /* GL_ALPHA */ - 0x1902: 1,
- 5: 3,
- 6: 4,
- // 0x1909 /* GL_LUMINANCE */ - 0x1902: 1,
- 8: 2,
- 29502: 3,
- 29504: 4,
- // 0x1903 /* GL_RED */ - 0x1902: 1,
- 26917: 2,
- 26918: 2,
- // 0x8D94 /* GL_RED_INTEGER */ - 0x1902: 1,
- 29846: 3,
- 29847: 4
- };
- return colorChannels[format - 0x1902]||1;
- }
-
- function heapObjectForWebGLType(type) {
- // Micro-optimization for size: Subtract lowest GL enum number (0x1400/* GL_BYTE */) from type to compare
- // smaller values for the heap, for shorter generated code size.
- // Also the type HEAPU16 is not tested for explicitly, but any unrecognized type will return out HEAPU16.
- // (since most types are HEAPU16)
- type -= 0x1400;
- if (type == 0) return HEAP8;
-
- if (type == 1) return HEAPU8;
-
- if (type == 2) return HEAP16;
-
- if (type == 4) return HEAP32;
-
- if (type == 6) return HEAPF32;
-
- if (type == 5
- || type == 28922
- || type == 28520
- || type == 30779
- || type == 30782
- )
- return HEAPU32;
-
- return HEAPU16;
- }
-
- function heapAccessShiftForWebGLHeap(heap) {
- return 31 - Math.clz32(heap.BYTES_PER_ELEMENT);
- }
- function emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, internalFormat) {
- var heap = heapObjectForWebGLType(type);
- var shift = heapAccessShiftForWebGLHeap(heap);
- var byteSize = 1<<shift;
- var sizePerPixel = __colorChannelsInGlTextureFormat(format) * byteSize;
- var bytes = computeUnpackAlignedImageSize(width, height, sizePerPixel, GL.unpackAlignment);
- return heap.subarray(pixels >> shift, pixels + bytes >> shift);
- }
- function _glTexImage2D(target, level, internalFormat, width, height, border, format, type, pixels) {
- if (GL.currentContext.version >= 2) {
- // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
- if (GLctx.currentPixelUnpackBufferBinding) {
- GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels);
- } else if (pixels) {
- var heap = heapObjectForWebGLType(type);
- GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, heap, pixels >> heapAccessShiftForWebGLHeap(heap));
- } else {
- GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, null);
- }
- return;
- }
- GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels ? emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, internalFormat) : null);
- }
- function _glTexParameteri(x0, x1, x2) { GLctx['texParameteri'](x0, x1, x2) }
- function _glUniform1f(location, v0) {
- GLctx.uniform1f(GL.uniforms[location], v0);
- }
- function _glUniform1i(location, v0) {
- GLctx.uniform1i(GL.uniforms[location], v0);
- }
- function _glUniform2f(location, v0, v1) {
- GLctx.uniform2f(GL.uniforms[location], v0, v1);
- }
- function _glUniform3f(location, v0, v1, v2) {
- GLctx.uniform3f(GL.uniforms[location], v0, v1, v2);
- }
- function _glUniform4f(location, v0, v1, v2, v3) {
- GLctx.uniform4f(GL.uniforms[location], v0, v1, v2, v3);
- }
- function _glUniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding) {
- program = GL.programs[program];
-
- GLctx['uniformBlockBinding'](program, uniformBlockIndex, uniformBlockBinding);
- }
- var miniTempWebGLFloatBuffers=[];
- function _glUniformMatrix4fv(location, count, transpose, value) {
-
- if (GL.currentContext.version >= 2) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
- GLctx.uniformMatrix4fv(GL.uniforms[location], !!transpose, HEAPF32, value>>2, count*16);
- return;
- }
-
- if (count <= 18) {
- // avoid allocation when uploading few enough uniforms
- var view = miniTempWebGLFloatBuffers[16*count-1];
- // hoist the heap out of the loop for size and for pthreads+growth.
- var heap = HEAPF32;
- value >>= 2;
- for (var i = 0; i < 16 * count; i += 16) {
- var dst = value + i;
- view[i] = heap[dst];
- view[i + 1] = heap[dst + 1];
- view[i + 2] = heap[dst + 2];
- view[i + 3] = heap[dst + 3];
- view[i + 4] = heap[dst + 4];
- view[i + 5] = heap[dst + 5];
- view[i + 6] = heap[dst + 6];
- view[i + 7] = heap[dst + 7];
- view[i + 8] = heap[dst + 8];
- view[i + 9] = heap[dst + 9];
- view[i + 10] = heap[dst + 10];
- view[i + 11] = heap[dst + 11];
- view[i + 12] = heap[dst + 12];
- view[i + 13] = heap[dst + 13];
- view[i + 14] = heap[dst + 14];
- view[i + 15] = heap[dst + 15];
- }
- } else
- {
- var view = HEAPF32.subarray((value)>>2, (value+count*64)>>2);
- }
- GLctx.uniformMatrix4fv(GL.uniforms[location], !!transpose, view);
- }
- function _glUseProgram(program) {
- GLctx.useProgram(GL.programs[program]);
- }
- function _glVertexAttribDivisor(index, divisor) {
- GLctx['vertexAttribDivisor'](index, divisor);
- }
- function _glVertexAttribIPointer(index, size, type, stride, ptr) {
- GLctx['vertexAttribIPointer'](index, size, type, stride, ptr);
- }
- function _glVertexAttribPointer(index, size, type, normalized, stride, ptr) {
- GLctx.vertexAttribPointer(index, size, type, !!normalized, stride, ptr);
- }
- function _glViewport(x0, x1, x2, x3) { GLctx['viewport'](x0, x1, x2, x3) }
- function _pthread_create() {
- return 6;
- }
- function _pthread_join() {
- return 28;
- }
- function _setTempRet0($i) {
- setTempRet0(($i) | 0);
- }
- var readAsmConstArgsArray=[];
- function readAsmConstArgs(sigPtr, buf) {
- readAsmConstArgsArray.length = 0;
- var ch;
- // Most arguments are i32s, so shift the buffer pointer so it is a plain
- // index into HEAP32.
- buf >>= 2;
- while (ch = HEAPU8[sigPtr++]) {
- // A double takes two 32-bit slots, and must also be aligned - the backend
- // will emit padding to avoid that.
- var double = ch < 105;
- if (double && (buf & 1)) buf++;
- readAsmConstArgsArray.push(double ? HEAPF64[buf++ >> 1] : HEAP32[buf]);
- ++buf;
- }
- return readAsmConstArgsArray;
- }
- function runAndAbortIfError(func) {
- try {
- return func();
- } catch (e) {
- abort(e);
- }
- }
- var Asyncify={State:{Normal:0,Unwinding:1,Rewinding:2},state:0,StackSize:4096,currData:null,handleSleepReturnValue:0,exportCallStack:[],callStackNameToId:{},callStackIdToName:{},callStackId:0,afterUnwind:null,asyncFinalizers:[],sleepCallbacks:[],getCallStackId:function(funcName) {
- var id = Asyncify.callStackNameToId[funcName];
- if (id === undefined) {
- id = Asyncify.callStackId++;
- Asyncify.callStackNameToId[funcName] = id;
- Asyncify.callStackIdToName[id] = funcName;
- }
- return id;
- },instrumentWasmExports:function(exports) {
- var ret = {};
- for (var x in exports) {
- (function(x) {
- var original = exports[x];
- if (typeof original === 'function') {
- ret[x] = function() {
- Asyncify.exportCallStack.push(x);
- try {
- return original.apply(null, arguments);
- } finally {
- if (ABORT) return;
- var y = Asyncify.exportCallStack.pop();
- assert(y === x);
- Asyncify.maybeStopUnwind();
- }
- };
- } else {
- ret[x] = original;
- }
- })(x);
- }
- return ret;
- },maybeStopUnwind:function() {
- if (Asyncify.currData &&
- Asyncify.state === Asyncify.State.Unwinding &&
- Asyncify.exportCallStack.length === 0) {
- // We just finished unwinding.
- Asyncify.state = Asyncify.State.Normal;
- runAndAbortIfError(Module['_asyncify_stop_unwind']);
- if (typeof Fibers !== 'undefined') {
- Fibers.trampoline();
- }
- if (Asyncify.afterUnwind) {
- Asyncify.afterUnwind();
- Asyncify.afterUnwind = null;
- }
- }
- },allocateData:function() {
- // An asyncify data structure has three fields:
- // 0 current stack pos
- // 4 max stack pos
- // 8 id of function at bottom of the call stack (callStackIdToName[id] == name of js function)
- //
- // The Asyncify ABI only interprets the first two fields, the rest is for the runtime.
- // We also embed a stack in the same memory region here, right next to the structure.
- // This struct is also defined as asyncify_data_t in emscripten/fiber.h
- var ptr = _malloc(12 + Asyncify.StackSize);
- Asyncify.setDataHeader(ptr, ptr + 12, Asyncify.StackSize);
- Asyncify.setDataRewindFunc(ptr);
- return ptr;
- },setDataHeader:function(ptr, stack, stackSize) {
- HEAP32[((ptr)>>2)] = stack;
- HEAP32[(((ptr)+(4))>>2)] = stack + stackSize;
- },setDataRewindFunc:function(ptr) {
- var bottomOfCallStack = Asyncify.exportCallStack[0];
- var rewindId = Asyncify.getCallStackId(bottomOfCallStack);
- HEAP32[(((ptr)+(8))>>2)] = rewindId;
- },getDataRewindFunc:function(ptr) {
- var id = HEAP32[(((ptr)+(8))>>2)];
- var name = Asyncify.callStackIdToName[id];
- var func = Module['asm'][name];
- return func;
- },handleSleep:function(startAsync) {
- if (ABORT) return;
- noExitRuntime = true;
- if (Asyncify.state === Asyncify.State.Normal) {
- // Prepare to sleep. Call startAsync, and see what happens:
- // if the code decided to call our callback synchronously,
- // then no async operation was in fact begun, and we don't
- // need to do anything.
- var reachedCallback = false;
- var reachedAfterCallback = false;
- startAsync(function(handleSleepReturnValue) {
- if (ABORT) return;
- Asyncify.handleSleepReturnValue = handleSleepReturnValue || 0;
- reachedCallback = true;
- if (!reachedAfterCallback) {
- // We are happening synchronously, so no need for async.
- return;
- }
- Asyncify.state = Asyncify.State.Rewinding;
- runAndAbortIfError(function() { Module['_asyncify_start_rewind'](Asyncify.currData) });
- if (typeof Browser !== 'undefined' && Browser.mainLoop.func) {
- Browser.mainLoop.resume();
- }
- var start = Asyncify.getDataRewindFunc(Asyncify.currData);
- var asyncWasmReturnValue = start();
- if (!Asyncify.currData) {
- // All asynchronous execution has finished.
- // `asyncWasmReturnValue` now contains the final
- // return value of the exported async WASM function.
- //
- // Note: `asyncWasmReturnValue` is distinct from
- // `Asyncify.handleSleepReturnValue`.
- // `Asyncify.handleSleepReturnValue` contains the return
- // value of the last C function to have executed
- // `Asyncify.handleSleep()`, where as `asyncWasmReturnValue`
- // contains the return value of the exported WASM function
- // that may have called C functions that
- // call `Asyncify.handleSleep()`.
- var asyncFinalizers = Asyncify.asyncFinalizers;
- Asyncify.asyncFinalizers = [];
- asyncFinalizers.forEach(function(func) {
- func(asyncWasmReturnValue);
- });
- }
- });
- reachedAfterCallback = true;
- if (!reachedCallback) {
- // A true async operation was begun; start a sleep.
- Asyncify.state = Asyncify.State.Unwinding;
- // TODO: reuse, don't alloc/free every sleep
- Asyncify.currData = Asyncify.allocateData();
- runAndAbortIfError(function() { Module['_asyncify_start_unwind'](Asyncify.currData) });
- if (typeof Browser !== 'undefined' && Browser.mainLoop.func) {
- Browser.mainLoop.pause();
- }
- }
- } else if (Asyncify.state === Asyncify.State.Rewinding) {
- // Stop a resume.
- Asyncify.state = Asyncify.State.Normal;
- runAndAbortIfError(Module['_asyncify_stop_rewind']);
- _free(Asyncify.currData);
- Asyncify.currData = null;
- // Call all sleep callbacks now that the sleep-resume is all done.
- Asyncify.sleepCallbacks.forEach(function(func) {
- func();
- });
- } else {
- abort('invalid state: ' + Asyncify.state);
- }
- return Asyncify.handleSleepReturnValue;
- },handleAsync:function(startAsync) {
- return Asyncify.handleSleep(function(wakeUp) {
- // TODO: add error handling as a second param when handleSleep implements it.
- startAsync().then(wakeUp);
- });
- }};
- Module["requestFullscreen"] = function Module_requestFullscreen(lockPointer, resizeCanvas) { Browser.requestFullscreen(lockPointer, resizeCanvas) };
- Module["requestAnimationFrame"] = function Module_requestAnimationFrame(func) { Browser.requestAnimationFrame(func) };
- Module["setCanvasSize"] = function Module_setCanvasSize(width, height, noUpdates) { Browser.setCanvasSize(width, height, noUpdates) };
- Module["pauseMainLoop"] = function Module_pauseMainLoop() { Browser.mainLoop.pause() };
- Module["resumeMainLoop"] = function Module_resumeMainLoop() { Browser.mainLoop.resume() };
- Module["getUserMedia"] = function Module_getUserMedia() { Browser.getUserMedia() }
- Module["createContext"] = function Module_createContext(canvas, useWebGL, setInModule, webGLContextAttributes) { return Browser.createContext(canvas, useWebGL, setInModule, webGLContextAttributes) };
- var GLctx;;
- var miniTempWebGLFloatBuffersStorage = new Float32Array(288);
- for (/**@suppress{duplicate}*/var i = 0; i < 288; ++i) {
- miniTempWebGLFloatBuffers[i] = miniTempWebGLFloatBuffersStorage.subarray(0, i+1);
- }
- ;
- var ASSERTIONS = false;
- /** @type {function(string, boolean=, number=)} */
- function intArrayFromString(stringy, dontAddNull, length) {
- var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
- var u8array = new Array(len);
- var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
- if (dontAddNull) u8array.length = numBytesWritten;
- return u8array;
- }
- function intArrayToString(array) {
- var ret = [];
- for (var i = 0; i < array.length; i++) {
- var chr = array[i];
- if (chr > 0xFF) {
- if (ASSERTIONS) {
- assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.');
- }
- chr &= 0xFF;
- }
- ret.push(String.fromCharCode(chr));
- }
- return ret.join('');
- }
- var asmLibraryArg = {
- "__assert_fail": ___assert_fail,
- "emscripten_asm_const_int": _emscripten_asm_const_int,
- "emscripten_enter_soft_fullscreen": _emscripten_enter_soft_fullscreen,
- "emscripten_exit_fullscreen": _emscripten_exit_fullscreen,
- "emscripten_get_element_css_size": _emscripten_get_element_css_size,
- "emscripten_get_pointerlock_status": _emscripten_get_pointerlock_status,
- "emscripten_memcpy_big": _emscripten_memcpy_big,
- "emscripten_performance_now": _emscripten_performance_now,
- "emscripten_resize_heap": _emscripten_resize_heap,
- "emscripten_set_canvas_element_size": _emscripten_set_canvas_element_size,
- "emscripten_set_click_callback_on_thread": _emscripten_set_click_callback_on_thread,
- "emscripten_set_fullscreenchange_callback_on_thread": _emscripten_set_fullscreenchange_callback_on_thread,
- "emscripten_set_keydown_callback_on_thread": _emscripten_set_keydown_callback_on_thread,
- "emscripten_set_keypress_callback_on_thread": _emscripten_set_keypress_callback_on_thread,
- "emscripten_set_keyup_callback_on_thread": _emscripten_set_keyup_callback_on_thread,
- "emscripten_set_main_loop": _emscripten_set_main_loop,
- "emscripten_set_mousedown_callback_on_thread": _emscripten_set_mousedown_callback_on_thread,
- "emscripten_set_mouseenter_callback_on_thread": _emscripten_set_mouseenter_callback_on_thread,
- "emscripten_set_mouseleave_callback_on_thread": _emscripten_set_mouseleave_callback_on_thread,
- "emscripten_set_mousemove_callback_on_thread": _emscripten_set_mousemove_callback_on_thread,
- "emscripten_set_mouseup_callback_on_thread": _emscripten_set_mouseup_callback_on_thread,
- "emscripten_set_pointerlockchange_callback_on_thread": _emscripten_set_pointerlockchange_callback_on_thread,
- "emscripten_set_resize_callback_on_thread": _emscripten_set_resize_callback_on_thread,
- "emscripten_set_wheel_callback_on_thread": _emscripten_set_wheel_callback_on_thread,
- "emscripten_sleep": _emscripten_sleep,
- "emscripten_webgl_create_context": _emscripten_webgl_create_context,
- "emscripten_webgl_init_context_attributes": _emscripten_webgl_init_context_attributes,
- "emscripten_webgl_make_context_current": _emscripten_webgl_make_context_current,
- "fd_write": _fd_write,
- "glActiveTexture": _glActiveTexture,
- "glAttachShader": _glAttachShader,
- "glBindBuffer": _glBindBuffer,
- "glBindBufferRange": _glBindBufferRange,
- "glBindFramebuffer": _glBindFramebuffer,
- "glBindRenderbuffer": _glBindRenderbuffer,
- "glBindTexture": _glBindTexture,
- "glBindVertexArray": _glBindVertexArray,
- "glBlendEquation": _glBlendEquation,
- "glBlendFunc": _glBlendFunc,
- "glBufferData": _glBufferData,
- "glBufferSubData": _glBufferSubData,
- "glClear": _glClear,
- "glClearColor": _glClearColor,
- "glCompileShader": _glCompileShader,
- "glCreateProgram": _glCreateProgram,
- "glCreateShader": _glCreateShader,
- "glCullFace": _glCullFace,
- "glDeleteProgram": _glDeleteProgram,
- "glDeleteShader": _glDeleteShader,
- "glDepthFunc": _glDepthFunc,
- "glDisable": _glDisable,
- "glDrawArrays": _glDrawArrays,
- "glDrawArraysInstanced": _glDrawArraysInstanced,
- "glDrawElements": _glDrawElements,
- "glDrawElementsInstanced": _glDrawElementsInstanced,
- "glEnable": _glEnable,
- "glEnableVertexAttribArray": _glEnableVertexAttribArray,
- "glFramebufferTexture2D": _glFramebufferTexture2D,
- "glFrontFace": _glFrontFace,
- "glGenBuffers": _glGenBuffers,
- "glGenFramebuffers": _glGenFramebuffers,
- "glGenTextures": _glGenTextures,
- "glGenVertexArrays": _glGenVertexArrays,
- "glGenerateMipmap": _glGenerateMipmap,
- "glGetIntegerv": _glGetIntegerv,
- "glGetProgramInfoLog": _glGetProgramInfoLog,
- "glGetProgramiv": _glGetProgramiv,
- "glGetShaderInfoLog": _glGetShaderInfoLog,
- "glGetShaderiv": _glGetShaderiv,
- "glGetUniformBlockIndex": _glGetUniformBlockIndex,
- "glGetUniformLocation": _glGetUniformLocation,
- "glLinkProgram": _glLinkProgram,
- "glScissor": _glScissor,
- "glShaderSource": _glShaderSource,
- "glStencilFunc": _glStencilFunc,
- "glStencilMask": _glStencilMask,
- "glStencilOp": _glStencilOp,
- "glTexImage2D": _glTexImage2D,
- "glTexParameteri": _glTexParameteri,
- "glUniform1f": _glUniform1f,
- "glUniform1i": _glUniform1i,
- "glUniform2f": _glUniform2f,
- "glUniform3f": _glUniform3f,
- "glUniform4f": _glUniform4f,
- "glUniformBlockBinding": _glUniformBlockBinding,
- "glUniformMatrix4fv": _glUniformMatrix4fv,
- "glUseProgram": _glUseProgram,
- "glVertexAttribDivisor": _glVertexAttribDivisor,
- "glVertexAttribIPointer": _glVertexAttribIPointer,
- "glVertexAttribPointer": _glVertexAttribPointer,
- "glViewport": _glViewport,
- "pthread_create": _pthread_create,
- "pthread_join": _pthread_join,
- "setTempRet0": _setTempRet0
- };
- var asm = createWasm();
- /** @type {function(...*):?} */
- var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() {
- return (___wasm_call_ctors = Module["___wasm_call_ctors"] = Module["asm"]["__wasm_call_ctors"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _malloc = Module["_malloc"] = function() {
- return (_malloc = Module["_malloc"] = Module["asm"]["malloc"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _free = Module["_free"] = function() {
- return (_free = Module["_free"] = Module["asm"]["free"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _main = Module["_main"] = function() {
- return (_main = Module["_main"] = Module["asm"]["main"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var ___errno_location = Module["___errno_location"] = function() {
- return (___errno_location = Module["___errno_location"] = Module["asm"]["__errno_location"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _ma_device_process_pcm_frames_capture__webaudio = Module["_ma_device_process_pcm_frames_capture__webaudio"] = function() {
- return (_ma_device_process_pcm_frames_capture__webaudio = Module["_ma_device_process_pcm_frames_capture__webaudio"] = Module["asm"]["ma_device_process_pcm_frames_capture__webaudio"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _ma_device_process_pcm_frames_playback__webaudio = Module["_ma_device_process_pcm_frames_playback__webaudio"] = function() {
- return (_ma_device_process_pcm_frames_playback__webaudio = Module["_ma_device_process_pcm_frames_playback__webaudio"] = Module["asm"]["ma_device_process_pcm_frames_playback__webaudio"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _emscripten_main_thread_process_queued_calls = Module["_emscripten_main_thread_process_queued_calls"] = function() {
- return (_emscripten_main_thread_process_queued_calls = Module["_emscripten_main_thread_process_queued_calls"] = Module["asm"]["emscripten_main_thread_process_queued_calls"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _emscripten_stack_get_base = Module["_emscripten_stack_get_base"] = function() {
- return (_emscripten_stack_get_base = Module["_emscripten_stack_get_base"] = Module["asm"]["emscripten_stack_get_base"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _emscripten_stack_get_end = Module["_emscripten_stack_get_end"] = function() {
- return (_emscripten_stack_get_end = Module["_emscripten_stack_get_end"] = Module["asm"]["emscripten_stack_get_end"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var stackSave = Module["stackSave"] = function() {
- return (stackSave = Module["stackSave"] = Module["asm"]["stackSave"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var stackRestore = Module["stackRestore"] = function() {
- return (stackRestore = Module["stackRestore"] = Module["asm"]["stackRestore"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var stackAlloc = Module["stackAlloc"] = function() {
- return (stackAlloc = Module["stackAlloc"] = Module["asm"]["stackAlloc"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _emscripten_stack_set_limits = Module["_emscripten_stack_set_limits"] = function() {
- return (_emscripten_stack_set_limits = Module["_emscripten_stack_set_limits"] = Module["asm"]["emscripten_stack_set_limits"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_iiii = Module["dynCall_iiii"] = function() {
- return (dynCall_iiii = Module["dynCall_iiii"] = Module["asm"]["dynCall_iiii"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_v = Module["dynCall_v"] = function() {
- return (dynCall_v = Module["dynCall_v"] = Module["asm"]["dynCall_v"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_viiii = Module["dynCall_viiii"] = function() {
- return (dynCall_viiii = Module["dynCall_viiii"] = Module["asm"]["dynCall_viiii"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_ii = Module["dynCall_ii"] = function() {
- return (dynCall_ii = Module["dynCall_ii"] = Module["asm"]["dynCall_ii"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_vi = Module["dynCall_vi"] = function() {
- return (dynCall_vi = Module["dynCall_vi"] = Module["asm"]["dynCall_vi"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_iiiiii = Module["dynCall_iiiiii"] = function() {
- return (dynCall_iiiiii = Module["dynCall_iiiiii"] = Module["asm"]["dynCall_iiiiii"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_vii = Module["dynCall_vii"] = function() {
- return (dynCall_vii = Module["dynCall_vii"] = Module["asm"]["dynCall_vii"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_iii = Module["dynCall_iii"] = function() {
- return (dynCall_iii = Module["dynCall_iii"] = Module["asm"]["dynCall_iii"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_iiiii = Module["dynCall_iiiii"] = function() {
- return (dynCall_iiiii = Module["dynCall_iiiii"] = Module["asm"]["dynCall_iiiii"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_iidiiii = Module["dynCall_iidiiii"] = function() {
- return (dynCall_iidiiii = Module["dynCall_iidiiii"] = Module["asm"]["dynCall_iidiiii"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var dynCall_jiji = Module["dynCall_jiji"] = function() {
- return (dynCall_jiji = Module["dynCall_jiji"] = Module["asm"]["dynCall_jiji"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _asyncify_start_unwind = Module["_asyncify_start_unwind"] = function() {
- return (_asyncify_start_unwind = Module["_asyncify_start_unwind"] = Module["asm"]["asyncify_start_unwind"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _asyncify_stop_unwind = Module["_asyncify_stop_unwind"] = function() {
- return (_asyncify_stop_unwind = Module["_asyncify_stop_unwind"] = Module["asm"]["asyncify_stop_unwind"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _asyncify_start_rewind = Module["_asyncify_start_rewind"] = function() {
- return (_asyncify_start_rewind = Module["_asyncify_start_rewind"] = Module["asm"]["asyncify_start_rewind"]).apply(null, arguments);
- };
- /** @type {function(...*):?} */
- var _asyncify_stop_rewind = Module["_asyncify_stop_rewind"] = function() {
- return (_asyncify_stop_rewind = Module["_asyncify_stop_rewind"] = Module["asm"]["asyncify_stop_rewind"]).apply(null, arguments);
- };
- // === Auto-generated postamble setup entry stuff ===
- var calledRun;
- /**
- * @constructor
- * @this {ExitStatus}
- */
- function ExitStatus(status) {
- this.name = "ExitStatus";
- this.message = "Program terminated with exit(" + status + ")";
- this.status = status;
- }
- var calledMain = false;
- dependenciesFulfilled = function runCaller() {
- // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
- if (!calledRun) run();
- if (!calledRun) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
- };
- function callMain(args) {
- var entryFunction = Module['_main'];
- args = args || [];
- var argc = args.length+1;
- var argv = stackAlloc((argc + 1) * 4);
- HEAP32[argv >> 2] = allocateUTF8OnStack(thisProgram);
- for (var i = 1; i < argc; i++) {
- HEAP32[(argv >> 2) + i] = allocateUTF8OnStack(args[i - 1]);
- }
- HEAP32[(argv >> 2) + argc] = 0;
- try {
- var ret = entryFunction(argc, argv);
- // In PROXY_TO_PTHREAD builds, we should never exit the runtime below, as
- // execution is asynchronously handed off to a pthread.
- // if we are saving the stack, then do not call exit, we are not
- // really exiting now, just unwinding the JS stack
- if (!noExitRuntime) {
- // if we're not running an evented main loop, it's time to exit
- exit(ret, /* implicit = */ true);
- }
- }
- catch(e) {
- if (e instanceof ExitStatus) {
- // exit() throws this once it's done to make sure execution
- // has been stopped completely
- return;
- } else if (e == 'unwind') {
- // running an evented main loop, don't immediately exit
- noExitRuntime = true;
- return;
- } else {
- var toLog = e;
- if (e && typeof e === 'object' && e.stack) {
- toLog = [e, e.stack];
- }
- err('exception thrown: ' + toLog);
- quit_(1, e);
- }
- } finally {
- calledMain = true;
- }
- }
- /** @type {function(Array=)} */
- function run(args) {
- args = args || arguments_;
- if (runDependencies > 0) {
- return;
- }
- preRun();
- // a preRun added a dependency, run will be called later
- if (runDependencies > 0) {
- return;
- }
- function doRun() {
- // run may have just been called through dependencies being fulfilled just in this very frame,
- // or while the async setStatus time below was happening
- if (calledRun) return;
- calledRun = true;
- Module['calledRun'] = true;
- if (ABORT) return;
- initRuntime();
- preMain();
- if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
- if (shouldRunNow) callMain(args);
- postRun();
- }
- if (Module['setStatus']) {
- Module['setStatus']('Running...');
- setTimeout(function() {
- setTimeout(function() {
- Module['setStatus']('');
- }, 1);
- doRun();
- }, 1);
- } else
- {
- doRun();
- }
- }
- Module['run'] = run;
- /** @param {boolean|number=} implicit */
- function exit(status, implicit) {
- // if this is just main exit-ing implicitly, and the status is 0, then we
- // don't need to do anything here and can just leave. if the status is
- // non-zero, though, then we need to report it.
- // (we may have warned about this earlier, if a situation justifies doing so)
- if (implicit && noExitRuntime && status === 0) {
- return;
- }
- if (noExitRuntime) {
- } else {
- EXITSTATUS = status;
- exitRuntime();
- if (Module['onExit']) Module['onExit'](status);
- ABORT = true;
- }
- quit_(status, new ExitStatus(status));
- }
- if (Module['preInit']) {
- if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
- while (Module['preInit'].length > 0) {
- Module['preInit'].pop()();
- }
- }
- // shouldRunNow refers to calling main(), not run().
- var shouldRunNow = true;
- if (Module['noInitialRun']) shouldRunNow = false;
- noExitRuntime = true;
- run();
|