Files
UnrealEngineUWP/Engine/Source/Runtime/HTML5/HTML5JS/Private/HTML5JavaScriptFx.js

173 lines
5.7 KiB
JavaScript
Raw Normal View History

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
var UE_JavaScriptLibary = {
UE_SendAndRecievePayLoad: function (url, indata, insize, outdataptr, outsizeptr) {
var _url = Pointer_stringify(url);
var request = new XMLHttpRequest();
if (insize && indata) {
var postData = Module.HEAP8.subarray(indata, indata + insize);
request.open('POST', _url, false);
request.overrideMimeType('text\/plain; charset=x-user-defined');
request.send(postData);
} else {
request.open('GET', _url, false);
request.send();
}
if (request.status != 200) {
console.log("Fetching " + _url + " failed: " + request.responseText);
Module.HEAP32[outsizeptr >> 2] = 0;
Module.HEAP32[outdataptr >> 2] = 0;
return;
}
// we got the XHR result as a string. We need to write this to Module.HEAP8[outdataptr]
var replyString = request.responseText;
var replyLength = replyString.length;
var outdata = Module._malloc(replyLength);
if (!outdata) {
console.log("Failed to allocate " + replyLength + " bytes in heap for reply");
Module.HEAP32[outsizeptr >> 2] = 0;
Module.HEAP32[outdataptr >> 2] = 0;
return;
}
// tears and crying. Copy from the result-string into the heap.
var replyDest = Module.HEAP8.subarray(outdata, outdata + replyLength);
for (var i = 0; i < replyLength; ++i) {
replyDest[i] = replyString.charCodeAt(i) & 0xff;
}
Module.HEAP32[outsizeptr >> 2] = replyLength;
Module.HEAP32[outdataptr >> 2] = outdata;
},
UE_SaveGame: function (name, userIndex, indata, insize){
// user index is not used.
var _name = Pointer_stringify(name);
var gamedata = Module.HEAP8.subarray(indata, indata + insize);
// local storage only takes strings, we need to convert string to base64 before storing.
var b64encoded = base64EncArr(gamedata);
$.jStorage.set(_name, b64encoded);
return true;
},
UE_LoadGame: function (name, userIndex, outdataptr, outsizeptr){
var _name = Pointer_stringify(name);
// local storage only takes strings, we need to convert string to base64 before storing.
var b64encoded = $.jStorage.get(_name);
if (b64encoded === null)
return false;
var decodedArray = base64DecToArr(b64encoded);
// copy back the decoded array.
var outdata = Module._malloc(decodedArray.length);
// view the allocated data as a HEAP8.
var dest = Module.HEAP8.subarray(outdata, outdata + decodedArray.length);
// copy back.
for (var i = 0; i < decodedArray.length; ++i) {
dest[i] = decodedArray[i];
}
Module.HEAP32[outsizeptr >> 2] = decodedArray.length;
Module.HEAP32[outdataptr >> 2] = outdata;
return true;
},
UE_DoesSaveGameExist: function (name, userIndex){
var _name = Pointer_stringify(name);
var b64encoded = $.jStorage.get(_name);
if (b64encoded === null)
return false;
return true;
},
UE_MessageBox: function (type, message, caption ) {
// type maps to EAppMsgType::Type
var text;
if ( type === 0 ) {
text = Pointer_stringify(message);
if (!confirm(text))
return 0;
} else {
text = Pointer_stringify(message);
alert(text);
}
return 1;
},
UE_GetCurrentCultureName: function (address, outsize) {
var culture_name = navigator.language || navigator.browserLanguage;
if (culture_name.lenght >= outsize)
return 0;
Module.writeAsciiToMemory(culture_name, address);
return 1;
},
UE_MakeHTTPDataRequest: function (ctx, url, verb, payload, payloadsize, headers, freeBuffer, onload, onerror, onprogress) {
var _url = Pointer_stringify(url);
var _verb = Pointer_stringify(verb);
var _headers = Pointer_stringify(headers);
var xhr = new XMLHttpRequest();
xhr.open(_verb, _url, true);
xhr.responseType = 'arraybuffer';
Change 2898947 on 2016/03/08 by Mark.Satterthwaite Move the Apple Driver Monitor stats into their own stat groups, DriverMonitor has the common stats, DriverMonitorAMD/Intel/Nvidia have the vendor/GPU specific stats. The Metal and OpenGL RHIs update the driver monitor stats group for the current GPU at the appropriate time. Change 2898950 on 2016/03/08 by Mark.Satterthwaite More shader cache code documentation. Change 2898952 on 2016/03/08 by Michael.Trepka Check GPU driver version and warn of bad drivers only on Windows Change 2898964 on 2016/03/08 by Mark.Satterthwaite Only verify the vertex attribute layout for Metal in debug builds or when using development with the debug layer turned on. It reduces performance significantly and isn't all that helpful unless you are attempting to debug a mismatch. Change 2898973 on 2016/03/08 by Mark.Satterthwaite Switch uniform buffers to managed memory on Mac as this is more appropriate for AMD & Nvidia GPUs. Change 2898988 on 2016/03/08 by Mark.Satterthwaite Simplify MetalContext by having only one SubmitCommandsHint implementation. Change 2899011 on 2016/03/08 by Mark.Satterthwaite Duplicate 4.11 CL #2898988: Proper fix for UE-25804 - we have to manually expand PF_G8 + SRGB to RGBA8_sRGB - this then fixes UE-27483. #jira UE-25804 #jira UE-27483 Change 2899024 on 2016/03/08 by Mark.Satterthwaite Duplicate 4.11 CL #2887365 & CL #2887583: Allow InfiltratorDemoEditor under Metal to issue a query buffer reset without crashing - the function that switches to the new query buffer needs to reapply some of the draw-state so that future commands don't dereference nil. #jira UE-27513 My earlier fix for UE-27513 overlooked various internal details that meant it wouldn't restore state correctly, would fail validation and could crash in a new place. This version will ensure that cached state is only reset when it is appropriate to do so and will restore it correct when doing a query buffer reset. #jira UE-27513 Change 2899418 on 2016/03/08 by Daniel.Lamb Added support for textboxes in the editor to convert uasset filenames into long package names. As this is more useful to the cooker and more portable for projects. #codereview Matt.Kuhlenschmidt #jira UE-27785 Change 2899419 on 2016/03/08 by Daniel.Lamb Added support for passing -opengl command through to launch on if the editor is started with it. #codereview Michael.Trepka Change 2900846 on 2016/03/09 by Mark.Satterthwaite Reimplement Metal object lifetime tracking as stats in the stat-group, though the old system is maintained as a debug-only tool that could (and probably should) be extended to track over/under-release bugs. Currently the texture count will be distorted by texture SRVs so will need improvement but other stats should be reliable. In order to properly report the number of buffers the TResourcePool policy class must now define a FreeResource function, so I've added them to the appropriate places too. Change 2900853 on 2016/03/09 by Mark.Satterthwaite Optimise away empty encoders that don't perform a clear operation on AMD & Intel, but not Nvidia or non-Mac Metal devices. This should slightly improve performance. Change 2900927 on 2016/03/09 by Mark.Satterthwaite Implemented operation threshold submission of Metal command buffers to keep the GPU busier and not just idle waiting for the CPU. Whenever rhi.Metal.CommandBufferCommitThreshold is set to a value >0 and the current command buffer has >= draw/dispatch operations outstanding then the command-buffer will be committed at the next encoder boundary. The default value is 100 operations which is currently arbitrary and the feature can be disabled by setting the value to <= 0 in which case only explicit submissions will occur as previously. Change 2901310 on 2016/03/09 by Mark.Satterthwaite Change OneColor clear shader setup so that it works with parallel encoding in Metal. Change 2903002 on 2016/03/10 by Mark.Satterthwaite Instantiate the OneColor shaders once in Metal. Change 2903274 on 2016/03/10 by Mark.Satterthwaite Remove more unnecessary parallel execution stalls from MetalRHI. Change 2903402 on 2016/03/10 by Mark.Satterthwaite Implement Metal support for index buffer SRVs. Change 2903419 on 2016/03/10 by Mark.Satterthwaite Always use Managed memory on Mac Metal for buffers. Change 2905206 on 2016/03/11 by Mark.Satterthwaite Worked around UE-27818 "ElementalDemo Causes Invalid Rendering on AMD GPUs" - recent changes to allow mesh particles to write to velocity leave a texture-buffer unbound & then use a uniform value & an if-branch to guard against access but AMD's Mac GL driver notices that the buffer is referenced in the shader but not bound & promptly tries to fallback to Apple's S/W renderer regardless of what the uniform value is. That's legal behaviour for an OpenGL implementation so the C++ code has been changed to allocate and write the current transforms into the buffer for OpenGL when they wouldn't otherwise be provided. This is sufficient to avoid the problem without affecting any other API. Change 2906217 on 2016/03/11 by Nick.Shin re-enabled http network file server it was disabled in CL: #2790193 #jira UE-22166 HTML5 Cook on the fly will launch and then close browser Change 2908203 on 2016/03/14 by Michael.Trepka Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform). Everything but SSF lib. Change 2908553 on 2016/03/14 by Mark.Satterthwaite Force a submit & wait in Metal when contexts are being destroyed to prevent kernel panics in drivers which continue to process the now abandoned command-queue and encounter invalid resources (because we destroy them on shutdown). Change 2908595 on 2016/03/14 by Michael.Trepka Fixed iOS compile error in MetalUniformBuffer.cpp #codereview Mark.Satterthwaite Change 2910106 on 2016/03/15 by Mark.Satterthwaite Use a dispatch_semaphore not an FEvent for Metal free-list synchronisation as the dispatch_worker threads can't be properly setup for FStats and this causes problems. Change 2910107 on 2016/03/15 by Mark.Satterthwaite Fix Metal reporting of GPU memory through the RHI as it is in bytes, not MB. Change 2910138 on 2016/03/15 by Mark.Satterthwaite Properly retain/release dispatch_semaphore for Metal command buffer completion block & allow uniform buffer creation on parallel encoding thread. Change 2911735 on 2016/03/16 by Nick.Shin housekeeping removing extra and inconsistant whitespace as well as making tabs & spaces consistant [CL 2936662 by Josh Adams in Main branch]
2016-04-07 12:59:50 -04:00
// set all headers.
var _headerArray = _headers.split("%");
for(var headerArrayidx = 0; headerArrayidx < _headerArray.length; headerArrayidx++){
var header = _headerArray[headerArrayidx].split(":");
// NOTE: as of Safari 9.0 -- no leading whitespace is allowed on setRequestHeader's 2nd parameter: "value"
xhr.setRequestHeader(header[0], header[1].trim());
}
// Onload event handler
xhr.addEventListener('load', function (e) {
if (xhr.status === 200 || _url.substr(0, 4).toLowerCase() !== "http") {
var byteArray = new Uint8Array(xhr.response);
var buffer = _malloc(byteArray.length);
HEAPU8.set(byteArray, buffer);
if (onload)
Runtime.dynCall('viii', onload, [ctx, buffer, byteArray.length]);
if (freeBuffer)
_free(buffer);
} else {
if (onerror)
Runtime.dynCall('viii', onerror, [ctx, xhr.status, xhr.statusText]);
}
});
// Onerror event handler
xhr.addEventListener('error', function (e) {
if (onerror)
Runtime.dynCall('viii', onerror, [ctx, xhr.status, xhr.statusText]);
});
// Onprogress event handler
xhr.addEventListener('progress', function (e) {
if (onprogress)
Runtime.dynCall('viii', onprogress, [ctx, e.loaded, e.lengthComputable || e.lengthComputable === undefined ? e.total : 0]);
});
// Bypass possible browser redirection limit
try {
if (xhr.channel instanceof Ci.nsIHttpChannel)
xhr.channel.redirectionLimit = 0;
} catch (ex) { }
if (_verb === "POST") {
var postData = Module.HEAP8.subarray(payload, payload + payloadsize);
Copying //UE4/Dev-Platform to Dev-Main (//UE4/Dev-Main) Change 2783376 on 2015/11/30 by Nick.Shin upgrading emscripten SDK to 1.35.9 following instruction from the README file Change 2787414 on 2015/12/02 by Nick.Shin upgrading emscripten to 1.35.0 removing old SDK and tools for Mac and Win64 Change 2790218 on 2015/12/04 by Nick.Shin merge (CL: #2790164) from //UE4/Dev-Physics to //UE4/Dev-Platform PhysX HTML5 bc files Change 2794786 on 2015/12/08 by Nick.Shin merge CL #2794757 part 1 of 2 from //UE4/Dev-Physics/PhysX/PhysX_3.3/Lib/html5 to //UE4/Dev-Platform/Engine/Source/ThirdParty/PhysX/PhysX-3.3/lib/HTML5/ Change 2794789 on 2015/12/08 by Nick.Shin merge CL #2794758 part 2 of 2 from //UE4/Dev-Physics/PhysX/PhysX_3.3/Lib/html5 to //UE4/Dev-Platform/Engine/Source/ThirdParty/PhysX/PhysX-3.3/lib/HTML5/ Change 2799151 on 2015/12/10 by Dmitry.Rekman Guarantee XGE.xml sorting order for 10+ builds. - A licensee pointed out the problem that AutomationTool.UE4Build.FindXGEFiles() sorts the files by filename, so e.g. UBTExport.10.xge.xml takes priority over UBTExport.2.xge.xml. #codereview Ben.Marsh Change 2799440 on 2015/12/11 by Mark.Satterthwaite Duplicate CL #2790251: Temporarily revert some of the changes for Mac mouse cursor locking as they were causing more problems than they solved. Change 2799441 on 2015/12/11 by Mark.Satterthwaite Duplicate CL #2796111 & #2796158: Fix cooking shader cache files - it wasn't being enabled despite a cached shader format being listed. Change 2799442 on 2015/12/11 by Mark.Satterthwaite Duplicate CL #2797758: Defer calls to AUGraphUpdate into FCoreAudioDevice::UpdateHardware - this call will synchronise the calling thread with the CoreAudio thread/run-loop so that the CoreAudio graph is safe to modify and this may incur a significant stall. This means it is far more efficient to amortise the cost of all changes to the graph with a single call. To ensure correctness the audio format conversion components are cached and disposed of after the call to AUGraphUpdate so that any existing operations on the CoreAudio thread are completed prior to disposal. Change 2799601 on 2015/12/11 by Mark.Satterthwaite Implement background reading of NSPipe's in Mac ExecProcess to avoid the sub-process blocking trying to write to the meagre 8kb internal buffers. This may fix problems with SVN on Mac. Change 2799657 on 2015/12/11 by Mark.Satterthwaite Remove the hlslcc major version from the Metal and OpenGL shader formats to ensure that there are enough bits to represent the different version components. There's no expectation that the major version of hlslcc will change and it will soon be removed entirely. Change 2799691 on 2015/12/11 by Mark.Satterthwaite Merging final internal-only changes from WWDC. Change 2800182 on 2015/12/11 by Mark.Satterthwaite Capture the system.log contents from the moment we boot to the point we crash to report GPU restarts and other system errors not written into our own logs. Change 2801395 on 2015/12/14 by Mark.Satterthwaite Fix the Metal shader compiler so that it properly reports the number of sampler objects in use, not the number of textures as Metal separates its 16 samplers and up-to 128 textures in a single shader stage, like D3D and unlike OpenGL. This fixes a lot of material compile errors in newer projects which aren't being designed for obsolete OpenGL. Change 2801653 on 2015/12/14 by Daniel.Lamb Load package differ can now diff header part of packages. Changed the way IsChildCooker is handled improves performance of multiprocess cooker. Change 2801655 on 2015/12/14 by Daniel.Lamb Added cooker warning to resave packages if they don't have collision data for their static meshes. Added NavCollision creation on static mesh import so that we save out the NavCollision. Change 2801923 on 2015/12/14 by Daniel.Lamb Fix compilation error with CreateLoader. Change 2802076 on 2015/12/14 by Daniel.Lamb Remove some debugging assistance code. Change 2803207 on 2015/12/15 by Mark.Satterthwaite Add missing Metal formats for PF_R16_SINT/UINT. Change 2803254 on 2015/12/15 by Mark.Satterthwaite Add additional uint/2/3/4 overrides for SV_Target(x) to MetalUtils and when generating the output variable look for an exact type match before restoring to the first match with the correct number of elements. This ensures that we generate uint/2/3/4 writes when required for CopyStencilToLightingChannelsPS without breaking anything else. Change 2803259 on 2015/12/15 by Mark.Satterthwaite Fix stencil texture swizzle for Metal which uses .x not .g for stencil value. Change 2803262 on 2015/12/15 by Mark.Satterthwaite Fix FMetalRHICommandContext::RHISetScissorRect handling 0 sized rects when RHISetScissorRect is called before RHISetViewport. Change 2803321 on 2015/12/15 by Mark.Satterthwaite Duplicate CL #2786291: Fix Metal validation errors caused by incorrect instance count and also a crash-bug caused by accessing a defunct depth-stencil texture. This should be enough to ensure Metal works even if you've been playing previously with OpenGL. Change 2803413 on 2015/12/15 by Mark.Satterthwaite Workaround the Material Editor's unfortunate habit of rendering tiles without a depth/stencil-buffer attached despite tiles wanting to write to depth - in Metal we have to create a temporary Depth-Stencil texture so that we don't crash the driver because it won't rewrite the shaders for us (unlike D3D/GL). Change 2806247 on 2015/12/16 by Daniel.Lamb Fixed UParticleRequiredModule deterministic cook issue. #codereview Olaf.Piesche Change 2806834 on 2015/12/17 by Mark.Satterthwaite Temporarily work around absence of Checked & Shipping APEX/PhysX binaries on Mac. Change 2807017 on 2015/12/17 by Mark.Satterthwaite Handle the shader cache being initialised for cooking multiple times until I can sort out the implementation properly. Change 2807027 on 2015/12/17 by Daniel.Lamb Enabled DDC stats.
2016-01-19 09:54:25 -05:00
// xhr.setRequestHeader("Connection", "close"); // NOTE: this now errors as of chrome 47.0.2526.80
xhr.send(postData);
} else {
xhr.send(null);
}
}
};
mergeInto(LibraryManager.library, UE_JavaScriptLibary);