open source
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,93 @@
|
||||
function async(gen) {
|
||||
"use strict";
|
||||
var log = console.log;
|
||||
var g = gen();
|
||||
let nr = null;
|
||||
function cast(value) {
|
||||
return value instanceof Promise && value.constructor === Promise ? value : new Promise(function () { });
|
||||
}
|
||||
function thennext(v) {
|
||||
nr = g.next(v);
|
||||
var p = nr.value;
|
||||
nr.done ? (0) : cast(p).then(thennext, function (e) { console.log('async reject:' + e); thennext(null); }).catch(function (r) {
|
||||
alert(`${r}
|
||||
${r.stack}`);
|
||||
});
|
||||
}
|
||||
thennext(void 0);
|
||||
}
|
||||
exports.async = async;
|
||||
//延时
|
||||
function delay(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
exports.delay = delay;
|
||||
//下载图片
|
||||
function loadImage(src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var img = new Image();
|
||||
img.src = src;
|
||||
img.onload = () => { resolve(img); };
|
||||
img.onerror = () => {
|
||||
//reject('file load err:' + src);
|
||||
resolve(null);
|
||||
};
|
||||
});
|
||||
}
|
||||
exports.loadImage = loadImage;
|
||||
//下载文本文件
|
||||
function loadText(src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', src);
|
||||
xhr.onload = () => { resolve(xhr.responseText); };
|
||||
xhr.onerror = (e) => {
|
||||
//if (reject)
|
||||
// reject('download xhr error:' + src + '. e=' + e);
|
||||
resolve(null);
|
||||
};
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
exports.loadText = loadText;
|
||||
function downloadSync(url, bin, onprog) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var f = new conch_File(url);
|
||||
var fr = new conch_FileReader();
|
||||
fr.setIgnoreError(true);
|
||||
fr.onload = () => {
|
||||
console.log('download end');
|
||||
resolve(fr.result);
|
||||
};
|
||||
fr.onerror = (e) => { console.log('onerror ' + e);
|
||||
//if (reject)
|
||||
// reject(e);
|
||||
resolve(null);
|
||||
};
|
||||
fr.onprogress = onprog;
|
||||
if (bin)
|
||||
fr.readAsArrayBuffer(f);
|
||||
else
|
||||
fr.readAsText(f);
|
||||
});
|
||||
}
|
||||
exports.downloadSync = downloadSync;
|
||||
//直到func返回true,tm是间隔
|
||||
function check(func, tm) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
function checkFunc() {
|
||||
if (func()) {
|
||||
clearInterval(chker);
|
||||
resolve(1);
|
||||
}
|
||||
}
|
||||
var chker = setInterval(checkFunc, tm);
|
||||
});
|
||||
}
|
||||
function regGlobal(window) {
|
||||
}
|
||||
exports.regGlobal = regGlobal;
|
||||
window['async'] = async;
|
||||
window['delay'] = delay;
|
||||
window['downloadSync'] = downloadSync;
|
||||
window['asynccheck'] = check;
|
||||
@@ -0,0 +1,109 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const test = require("./unitTest");
|
||||
function AllTest() {
|
||||
this.test_clone = function (test) {
|
||||
try {
|
||||
var b = document.createElement('audio');
|
||||
var c = b.cloneNode(false);
|
||||
c.addEventListener('', null);
|
||||
}
|
||||
catch (e) {
|
||||
test.err(`
|
||||
cloneNode之后,应该有 addEventListener 函数。
|
||||
`);
|
||||
}
|
||||
};
|
||||
this.testEventDispatch = function (test) {
|
||||
var called = false;
|
||||
var canv = document.createElement('canvas');
|
||||
document.body.appendChild(canv);
|
||||
canv.addEventListener('mmousemove', (evt) => {
|
||||
called = true;
|
||||
});
|
||||
var evt = new MouseEvent('mmousemove');
|
||||
evt.clientX = 100;
|
||||
evt.clientY = 100;
|
||||
canv.dispatchEvent(evt);
|
||||
test.eq(called, true, '事件应该能正确发送给canvas');
|
||||
document.removeChild(canv);
|
||||
test.neq(window.document._topElement, canv, 'removeChild之后,应该维护_topElement');
|
||||
};
|
||||
this.testEvent_phase = function (test) {
|
||||
var canv = document.createElement('canvas');
|
||||
var result = [];
|
||||
document.body.appendChild(canv);
|
||||
document.addEventListener('mousedown', (evt) => {
|
||||
result.push(1);
|
||||
}, true);
|
||||
document.body.addEventListener('mousedown', (evt) => {
|
||||
result.push(2);
|
||||
}, true);
|
||||
canv.addEventListener('mousedown', (evt) => {
|
||||
result.push(3);
|
||||
});
|
||||
document.body.addEventListener('mousedown', (evt) => {
|
||||
result.push(4);
|
||||
});
|
||||
document.addEventListener('mousedown', (evt) => {
|
||||
result.push(5);
|
||||
});
|
||||
window.addEventListener('mousedown', (evt) => {
|
||||
result.push(6);
|
||||
});
|
||||
var evt = new MouseEvent('mousedown');
|
||||
evt.clientX = 100;
|
||||
evt.clientY = 100;
|
||||
canv.dispatchEvent(evt);
|
||||
document.removeChild(canv);
|
||||
};
|
||||
this.testRuntimeVersion = function (test) {
|
||||
var rv = conchConfig.getRuntimeVersion();
|
||||
var b = rv.indexOf('conch');
|
||||
};
|
||||
this.testABToC = function (test) {
|
||||
};
|
||||
this.testZip = function (test) {
|
||||
var zf = new ZipFile();
|
||||
zf.setSrc('');
|
||||
zf.forEach((id, name, dir, sz) => {
|
||||
var ab = zf.readFile(id);
|
||||
});
|
||||
zf.close();
|
||||
};
|
||||
this.testFile = function (test) {
|
||||
var abv = new Uint32Array([1, 2, 3]);
|
||||
fs_writeFileSync('d:/temp/ddd.d', abv.buffer);
|
||||
var ab = fs_readFileSync('d:/temp/ddd.d');
|
||||
var v1 = new Uint32Array(ab);
|
||||
if (v1.byteLength != 12 || v1[0] != 1 || v1[1] != 2 || v1[2] != 3)
|
||||
alert('error:' + arguments.callee.name);
|
||||
alert(fs_readdirSync('d:/temp'));
|
||||
};
|
||||
this.testWebSocket = function (test) {
|
||||
var ws = new WebSocket('');
|
||||
};
|
||||
this.testMD5 = function (test) {
|
||||
var result = '2a1dd1e1e59d0a384c26951e316cd7e6';
|
||||
test.eq(result, calcmd5(new Uint32Array([1, 2, 3]).buffer), 'md5计算不正确');
|
||||
};
|
||||
this.testPost = function (test) {
|
||||
var ab = new Uint32Array([0, 1, 2]);
|
||||
conch._postUrl('http://localhost:8888/testpost', 1, ab.buffer, null, (buf) => {
|
||||
}, (e) => {
|
||||
}, () => {
|
||||
return 0;
|
||||
});
|
||||
};
|
||||
this.testUrlEncode = function () {
|
||||
};
|
||||
this.testFileReader = function (test) {
|
||||
var f = new File('file:///d:/temp/test.sh');
|
||||
var fr = new FileReader();
|
||||
fr.onload = function () {
|
||||
alert('ok ' + fr.result);
|
||||
};
|
||||
fr.readAsText(f);
|
||||
};
|
||||
}
|
||||
test.testall(new AllTest(), "");
|
||||
@@ -0,0 +1,115 @@
|
||||
class loadingView
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.sOS = conchConfig.getOS();
|
||||
if (this.sOS == "Conch-ios")
|
||||
{
|
||||
this.bridge = PlatformClass.createClass("JSBridge");
|
||||
}
|
||||
else if (this.sOS == "Conch-android")
|
||||
{
|
||||
this.bridge = PlatformClass.createClass("demo.JSBridge");
|
||||
}
|
||||
}
|
||||
set loadingAutoClose(value)
|
||||
{
|
||||
this._loadingAutoClose = value;
|
||||
}
|
||||
get loadingAutoClose()
|
||||
{
|
||||
return this._loadingAutoClose;
|
||||
}
|
||||
set showTextInfo(value)
|
||||
{
|
||||
this._showTextInfo = value;
|
||||
if(this.bridge)
|
||||
{
|
||||
if (this.sOS == "Conch-ios")
|
||||
{
|
||||
this.bridge.call("showTextInfo:",value);
|
||||
}
|
||||
else if(this.sOS == "Conch-android")
|
||||
{
|
||||
this.bridge.call("showTextInfo",value);
|
||||
}
|
||||
}
|
||||
}
|
||||
get showTextInfo()
|
||||
{
|
||||
return this._showTextInfo;
|
||||
}
|
||||
bgColor(value)
|
||||
{
|
||||
if(this.bridge)
|
||||
{
|
||||
if (this.sOS == "Conch-ios")
|
||||
{
|
||||
this.bridge.call("bgColor:",value);
|
||||
}
|
||||
else if(this.sOS == "Conch-android")
|
||||
{
|
||||
this.bridge.call("bgColor",value);
|
||||
}
|
||||
}
|
||||
}
|
||||
setFontColor(value)
|
||||
{
|
||||
if(this.bridge)
|
||||
{
|
||||
if (this.sOS == "Conch-ios")
|
||||
{
|
||||
this.bridge.call("setFontColor:",value);
|
||||
}
|
||||
else if(this.sOS == "Conch-android")
|
||||
{
|
||||
this.bridge.call("setFontColor",value);
|
||||
}
|
||||
}
|
||||
}
|
||||
setTips(value)
|
||||
{
|
||||
if(this.bridge)
|
||||
{
|
||||
if (this.sOS == "Conch-ios")
|
||||
{
|
||||
this.bridge.call("setTips:",value);
|
||||
}
|
||||
else if(this.sOS == "Conch-android")
|
||||
{
|
||||
this.bridge.call("setTips",value);
|
||||
}
|
||||
}
|
||||
}
|
||||
loading(value)
|
||||
{
|
||||
if(this.bridge)
|
||||
{
|
||||
if (this.sOS == "Conch-ios")
|
||||
{
|
||||
this.bridge.call("loading:",value);
|
||||
}
|
||||
else if(this.sOS == "Conch-android")
|
||||
{
|
||||
this.bridge.call("loading",value);
|
||||
}
|
||||
}
|
||||
}
|
||||
hideLoadingView()
|
||||
{
|
||||
this.bridge.call("hideSplash");
|
||||
}
|
||||
}
|
||||
window.loadingView = new loadingView();
|
||||
if(window.loadingView)
|
||||
{
|
||||
window.loadingView.loadingAutoClose=true;//true代表当动画播放完毕,自动进入游戏。false为开发者手动控制
|
||||
window.loadingView.bgColor("#000000");//设置背景颜色
|
||||
window.loadingView.setFontColor("#ffffff");//设置字体颜色
|
||||
window.loadingView.setTips(["新世界的大门即将打开","敌军还有30秒抵达战场","妈妈说,心急吃不了热豆腐"]);//设置tips数组,会随机出现
|
||||
}
|
||||
window.onLayaInitError=function(e)
|
||||
{
|
||||
console.log("onLayaInitError error=" + e);
|
||||
alert("加载游戏失败,可能由于您的网络不稳定,请退出重进");
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
window._conchInfo = { version: '2.1.3.1' };
|
||||
var _inline = !conchConfig.localizable;
|
||||
console.log('====================================================== ');
|
||||
console.log(' LAYA CONCH ');
|
||||
console.log(' runtimeversion:' + conchConfig.getRuntimeVersion());
|
||||
console.log(' jsversion:' + window._conchInfo.version);
|
||||
console.log(' isplug:' + conchConfig.getIsPlug());
|
||||
console.log('======================================================');
|
||||
function log(m) {
|
||||
console.log(m);
|
||||
}
|
||||
if (conchConfig.getOS() == "Conch-ios") {
|
||||
require('promise');
|
||||
}
|
||||
function loadLib(url) {
|
||||
var script = document.createElement("script");
|
||||
if (url.indexOf("laya.physics3D.js") >= 0) {
|
||||
url = url.replace("laya.physics3D.js", "laya.physics3D.runtime.js");
|
||||
}
|
||||
script.src = url;
|
||||
script.onerror = function () {
|
||||
if (window["onLayaInitError"]) {
|
||||
window["onLayaInitError"]("Load script error");
|
||||
}
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
window['loadLib'] = loadLib;
|
||||
const asyncs = require("async");
|
||||
function initFreeType() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var sOS = conchConfig.getOS();
|
||||
var bRet = false;
|
||||
var sTempFontPath = conch.getCachePath() + "/runtimeFont/";
|
||||
if (!fs_exists(sTempFontPath)) {
|
||||
fs_mkdir(sTempFontPath);
|
||||
}
|
||||
sTempFontPath += "layabox.ttf";
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(sTempFontPath);
|
||||
if (bRet == false) {
|
||||
var assetFontData = conch.readFileFromAsset('font/layabox.ttf', 'raw');
|
||||
if (assetFontData) {
|
||||
fs_writeFileSync(sTempFontPath, assetFontData);
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(sTempFontPath);
|
||||
}
|
||||
}
|
||||
if (!bRet) {
|
||||
if (sOS == "Conch-window") {
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile("C:/Windows/Fonts/simhei.ttf");
|
||||
}
|
||||
else if (sOS == "Conch-android") {
|
||||
var fSystemVersion = navigator.sv;
|
||||
if (fSystemVersion >= 2.0 && fSystemVersion < 5.0) {
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile("/system/fonts/DFHEIA5A.ttf");
|
||||
if (bRet == false) {
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile("/system/fonts/DroidSansFallback.ttf");
|
||||
}
|
||||
}
|
||||
else if (fSystemVersion >= 5.0 && fSystemVersion < 6.0) {
|
||||
var vDefaultStrings = [];
|
||||
vDefaultStrings.push("/system/fonts/NotoSansHans-Regular.otf");
|
||||
vDefaultStrings.push("/system/fonts/Roboto-Regular.ttf");
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(vDefaultStrings.join('|'));
|
||||
}
|
||||
else if (fSystemVersion >= 6.0 && fSystemVersion < 7.0) {
|
||||
var vDefaultStrings = [];
|
||||
vDefaultStrings.push("/system/fonts/NotoSansSC-Regular.otf");
|
||||
vDefaultStrings.push("/system/fonts/Roboto-Regular.ttf");
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(vDefaultStrings.join('|'));
|
||||
}
|
||||
else if (fSystemVersion >= 7.0 && fSystemVersion < 8.0) {
|
||||
bRet = false;
|
||||
}
|
||||
}
|
||||
else if (sOS == "Conch-ios") {
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile("");
|
||||
}
|
||||
}
|
||||
if (bRet == false) {
|
||||
log('字体初始化失败,从网络下载字体...');
|
||||
var data = (yield asyncs.downloadSync(location.fullpath + '/font/simhei.ttf', true, null));
|
||||
if (!data) {
|
||||
data = (yield asyncs.downloadSync('http://runtime.layabox.com/font/simhei.ttf', true, null));
|
||||
}
|
||||
if (!data) {
|
||||
alert('下载字体失败。 ');
|
||||
return;
|
||||
}
|
||||
fs_writeFileSync(sTempFontPath, data);
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(sTempFontPath);
|
||||
}
|
||||
if (!bRet) {
|
||||
log('字体初始化失败。');
|
||||
}
|
||||
});
|
||||
}
|
||||
function setOrientation(s) {
|
||||
var nameToVal = {
|
||||
landscape: 0, portrait: 1, user: 2, behind: 3, sensor: 4, nosensor: 5, sensor_landscape: 6, sensorLandscape: 6,
|
||||
sensor_portrait: 7, sensorPortrait: 7, reverse_landscape: 8, reverseLandscape: 8, reverse_portrait: 9, reversePortrait: 9, full_sensor: 10, fullSensor: 10,
|
||||
};
|
||||
var nOri = (function (name) {
|
||||
try {
|
||||
var n = nameToVal[name];
|
||||
return n || 0;
|
||||
}
|
||||
catch (e) {
|
||||
return 0;
|
||||
}
|
||||
})(s);
|
||||
conchConfig.setScreenOrientation(nOri);
|
||||
;
|
||||
}
|
||||
Object.defineProperty(window, 'screenOrientation', {
|
||||
get: function () {
|
||||
return window.___screenOri;
|
||||
},
|
||||
set: function (v) {
|
||||
window.___screenOri = v;
|
||||
setOrientation(v);
|
||||
}
|
||||
});
|
||||
function startApp(data) {
|
||||
var jsonobj = null;
|
||||
try {
|
||||
jsonobj = JSON.parse(data);
|
||||
}
|
||||
catch (e) {
|
||||
console.log("Error:start page parse error! \n " + data);
|
||||
return;
|
||||
}
|
||||
jsonobj.scripts.forEach((v) => {
|
||||
var t = document.createElement("script");
|
||||
t["src"] = v;
|
||||
t.onerror = function () {
|
||||
if (window["onLayaInitError"]) {
|
||||
window["onLayaInitError"]("Load script error");
|
||||
}
|
||||
};
|
||||
document.head.appendChild(t);
|
||||
});
|
||||
if (jsonobj.screenOrientation)
|
||||
setOrientation(jsonobj.screenOrientation);
|
||||
else if (jsonobj.screenorientation)
|
||||
setOrientation(jsonobj.screenorientation);
|
||||
else
|
||||
setOrientation("sensor_landscape");
|
||||
document.createElement("script").text = "window.onload&&window.onload()";
|
||||
}
|
||||
function loadApp(url) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var urllen = url.length;
|
||||
if (urllen < 2)
|
||||
return;
|
||||
url = url.trim();
|
||||
if (url.substring(urllen - 1) === '/')
|
||||
url = url + 'runtime.json';
|
||||
url = url.replace(/.html$/i, '.json');
|
||||
if (url.indexOf('http://stand.alone.version') == 0)
|
||||
_inline = false;
|
||||
if (!_inline) {
|
||||
url = 'http://stand.alone.version/index.js';
|
||||
}
|
||||
console.log("loadApp:" + url);
|
||||
if (history.length <= 0) {
|
||||
history._push(url);
|
||||
}
|
||||
if (url.length < 2)
|
||||
return;
|
||||
location.setHref(url);
|
||||
var urlpath = location.fullpath + '/';
|
||||
var cache = window.appcache = new AppCache(urlpath);
|
||||
document.loadCookie();
|
||||
yield initFreeType();
|
||||
try {
|
||||
require("config");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
var isDccOk = true;
|
||||
function updateDcc() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
cache.setResourceID('appurl', urlpath);
|
||||
var curassets = cache.getResourceID('netassetsid');
|
||||
var assetsidStr = (yield asyncs.downloadSync(urlpath + 'update/assetsid.txt?rand=' + Math.random() * Date.now(), false, null));
|
||||
console.log("assetsid old:" + curassets + " new:" + assetsidStr);
|
||||
if (!assetsidStr) {
|
||||
if (curassets && curassets != "") {
|
||||
if (window["onLayaInitError"]) {
|
||||
isDccOk = false;
|
||||
window["onLayaInitError"]("Update DCC get assetsid error");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (curassets != assetsidStr) {
|
||||
log('need update;');
|
||||
var txtdcc = '';
|
||||
var bindcc = yield asyncs.downloadSync(urlpath + 'update/filetable.bin?' + assetsidStr, true, null);
|
||||
if (!bindcc || !(bindcc instanceof ArrayBuffer)) {
|
||||
txtdcc = (yield asyncs.downloadSync(urlpath + 'update/filetable.txt?' + assetsidStr, false, null));
|
||||
}
|
||||
else {
|
||||
if (bindcc.byteLength % 8 != 0) {
|
||||
log('下载的的filetable.bin的长度不对。是不是错了。');
|
||||
}
|
||||
else {
|
||||
var v = new Uint32Array(bindcc);
|
||||
if (v[0] != 0xffeeddcc || v[1] != 1) {
|
||||
log('dcc.bin file err!');
|
||||
}
|
||||
else {
|
||||
if (v[2] == 0x00ffffff) {
|
||||
var stp = (4 + 8) / 2;
|
||||
var md5int = v.slice(4, 12);
|
||||
var md5char = new Uint8Array(md5int.buffer);
|
||||
var so = String.fromCharCode.apply(null, md5char);
|
||||
console.log('--------------------------------------------');
|
||||
console.log('so=' + so);
|
||||
console.log('netid=' + assetsidStr);
|
||||
if (so == assetsidStr) {
|
||||
for (var ii = stp, isz = v.length / 2; ii < isz; ii++)
|
||||
txtdcc += v[ii * 2].toString(16) + ' ' + v[ii * 2 + 1].toString(16) + '\n';
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('----------------old format');
|
||||
for (var ii = 1, isz = v.length / 2; ii < isz; ii++)
|
||||
txtdcc += v[ii * 2].toString(16) + ' ' + v[ii * 2 + 1].toString(16) + '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (txtdcc && txtdcc.length > 0) {
|
||||
cache.saveFileTable(txtdcc);
|
||||
window.appcache = cache = new AppCache(urlpath);
|
||||
cache.setResourceID('netassetsid', assetsidStr);
|
||||
}
|
||||
else {
|
||||
if (window["onLayaInitError"]) {
|
||||
isDccOk = false;
|
||||
window["onLayaInitError"]("Update DCC get filetable error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (_inline) {
|
||||
yield updateDcc();
|
||||
if (!isDccOk) {
|
||||
console.log("init dcc fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
var data = yield asyncs.loadText(url);
|
||||
for (var n = 0; n < 3 && !data; n++) {
|
||||
data = yield asyncs.loadText(url);
|
||||
}
|
||||
if (!data) {
|
||||
if (window["loadingView"]) {
|
||||
window["loadingView"].setFontColor("#FF0000");
|
||||
window["loadingView"].setTips(['网络异常,请检查您的网络或与开发商联系。']);
|
||||
}
|
||||
data = cache.loadCachedURL(url);
|
||||
if (!data || data.length <= 0)
|
||||
if (window["onLayaInitError"]) {
|
||||
window["onLayaInitError"]("Load start url error");
|
||||
}
|
||||
return;
|
||||
}
|
||||
console.log("");
|
||||
var qpos = url.indexOf('?');
|
||||
if (qpos < 0)
|
||||
qpos = url.length;
|
||||
if (url.substr(qpos - 3, 3) === '.js') {
|
||||
window.eval(data + `
|
||||
//@ sourceURL=${url}
|
||||
`);
|
||||
document.createElement("script").text = "window.onload&&window.onload()";
|
||||
}
|
||||
else {
|
||||
startApp(data);
|
||||
}
|
||||
if (window["loadingView"] && window["loadingView"].loadingAutoClose) {
|
||||
window["loadingView"].hideLoadingView();
|
||||
}
|
||||
});
|
||||
}
|
||||
window.document.addEventListener('keydown', function (e) {
|
||||
switch (e.keyCode) {
|
||||
case 116:
|
||||
reloadJS(true);
|
||||
break;
|
||||
case 117:
|
||||
history.back();
|
||||
break;
|
||||
case 118:
|
||||
break;
|
||||
case 119:
|
||||
break;
|
||||
case 120:
|
||||
gc();
|
||||
break;
|
||||
}
|
||||
});
|
||||
window.loadConchUrl = loadApp;
|
||||
window['updateByZip'] = function (url, onEvent, onEnd) {
|
||||
let cachePath = conch.getCachePath();
|
||||
let localfile = cachePath + url.substr(url.lastIndexOf('/'));
|
||||
downloadBigFile(url, localfile, (total, now, speed) => {
|
||||
onEvent('downloading', Math.floor((now / total) * 100), null);
|
||||
return false;
|
||||
}, (curlret, httpret) => {
|
||||
if (curlret != 0 || httpret < 200 || httpret >= 300) {
|
||||
onEvent('downloadError');
|
||||
}
|
||||
else {
|
||||
onEvent('downloadOK');
|
||||
let zip = new ZipFile();
|
||||
if (zip.setSrc(localfile)) {
|
||||
zip.forEach((id, name, dir, sz) => {
|
||||
if (!dir) {
|
||||
let buf = zip.readFile(id);
|
||||
let fid = window.appcache.hashstr('/' + name);
|
||||
if (window.appcache.updateFile(fid, 0, buf, false)) {
|
||||
onEvent('updating', null, name);
|
||||
}
|
||||
else {
|
||||
onEvent("updateError", null, name);
|
||||
}
|
||||
}
|
||||
});
|
||||
zip.close();
|
||||
if (onEnd)
|
||||
onEnd(localfile);
|
||||
}
|
||||
else {
|
||||
console.log("set zip src error!");
|
||||
onEvent('unknownError');
|
||||
}
|
||||
}
|
||||
}, 10, 100000000);
|
||||
};
|
||||
loadApp(conch.presetUrl || "http://nativetest.layabox.com/layaplayer2.0.1/index.js");
|
||||
@@ -0,0 +1,64 @@
|
||||
window = this;
|
||||
window.conch_File=File;
|
||||
window.conch_FileReader = FileReader;
|
||||
|
||||
(function () {
|
||||
function file2path(p) {
|
||||
if (!p) return null;
|
||||
var lastpos = Math.max(p.lastIndexOf('/'),
|
||||
p.lastIndexOf('\\'));
|
||||
var ret = lastpos < 0 ? p : p.substr(0, lastpos);
|
||||
return ret.replace(/\\/g, '/');
|
||||
}
|
||||
var mcache = {};
|
||||
/*起始路径总是这里,如果需要改变的话,就在这里通过require跳转。*/
|
||||
window.requireOrig = function (file) {
|
||||
function evalreq(fc, fid) {/*return function*/
|
||||
if (!fc || fc.length <= 0) return null;
|
||||
/*注意:并不是window.eval所以脚本中不能假设当前是在window上下文*/
|
||||
try {
|
||||
//注意 fc后面要加\n来关掉行注释
|
||||
var func = eval('(function(exports,global,require,__dirname,__filename){' + fc + ';\nreturn exports;})\n//@ sourceURL=' + fid);
|
||||
mcache[fid] = func;
|
||||
return func;
|
||||
}
|
||||
catch (e) {
|
||||
_console.log(1,'require error:' + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var mod = { dir: this.dir, file: file };
|
||||
if (file.substr(file.length - 3) != '.js')
|
||||
file += '.js';
|
||||
/*优先读取外部的*/
|
||||
var extfile = null;
|
||||
if (file.charAt(1) === ':' || file.charAt(0) === '/') { extfile = file; }
|
||||
else extfile = this.dir ? (this.dir + '/' + file) : null;
|
||||
var extfunc = null;
|
||||
_console.log(3,'require(' + extfile + ')');
|
||||
var reqresult = mcache[extfile] ||
|
||||
(extfunc = evalreq(readFileSync(extfile, 'utf8'), extfile)) ||
|
||||
mcache[file] ||
|
||||
evalreq(readTextAsset('scripts/' + file), file);
|
||||
if (extfunc) {
|
||||
mod.dir = file2path(extfile);/*使用window的或者当前模块的*/
|
||||
mod.file = extfile;
|
||||
}
|
||||
if (!reqresult) {
|
||||
throw ('require failed:' + file);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
var ret = reqresult({}, window, window.requireOrig.bind(mod), mod.dir, mod.file);
|
||||
return ret;
|
||||
}
|
||||
catch (e) {
|
||||
var err = 'eval script error in require:\n ' + file + '\n' + e.stack;
|
||||
_console.log(1,err);
|
||||
throw err;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
var exepath = file2path(getExePath());
|
||||
window.require = window.requireOrig.bind({ dir: exepath ? (exepath + '/scripts') : '/sdcard/layabox/scripts', file: null })
|
||||
})();
|
||||
@@ -0,0 +1,453 @@
|
||||
var UNIFORM_TYPE;
|
||||
(function (UNIFORM_TYPE) {
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM1F"] = 0] = "INTERIOR_UNIFORM1F";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM1FV"] = 1] = "INTERIOR_UNIFORM1FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM1I"] = 2] = "INTERIOR_UNIFORM1I";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM1IV"] = 3] = "INTERIOR_UNIFORM1IV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM2F"] = 4] = "INTERIOR_UNIFORM2F";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM2FV"] = 5] = "INTERIOR_UNIFORM2FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM2I"] = 6] = "INTERIOR_UNIFORM2I";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM2IV"] = 7] = "INTERIOR_UNIFORM2IV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM3F"] = 8] = "INTERIOR_UNIFORM3F";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM3FV"] = 9] = "INTERIOR_UNIFORM3FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM3I"] = 10] = "INTERIOR_UNIFORM3I";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM3IV"] = 11] = "INTERIOR_UNIFORM3IV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM4F"] = 12] = "INTERIOR_UNIFORM4F";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM4FV"] = 13] = "INTERIOR_UNIFORM4FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM4I"] = 14] = "INTERIOR_UNIFORM4I";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM4IV"] = 15] = "INTERIOR_UNIFORM4IV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMMATRIX2FV"] = 16] = "INTERIOR_UNIFORMMATRIX2FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMMATRIX3FV"] = 17] = "INTERIOR_UNIFORMMATRIX3FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMMATRIX4FV"] = 18] = "INTERIOR_UNIFORMMATRIX4FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMSAMPLER_2D"] = 19] = "INTERIOR_UNIFORMSAMPLER_2D";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMSAMPLER_CUBE"] = 20] = "INTERIOR_UNIFORMSAMPLER_CUBE";
|
||||
})(UNIFORM_TYPE || (UNIFORM_TYPE = {}));
|
||||
var ARRAY_BUFFER_PARAM_TYPE;
|
||||
(function (ARRAY_BUFFER_PARAM_TYPE) {
|
||||
ARRAY_BUFFER_PARAM_TYPE[ARRAY_BUFFER_PARAM_TYPE["ARRAY_BUFFER_REF_REFERENCE"] = 0] = "ARRAY_BUFFER_REF_REFERENCE";
|
||||
ARRAY_BUFFER_PARAM_TYPE[ARRAY_BUFFER_PARAM_TYPE["ARRAY_BUFFER_REF_COPY"] = 1] = "ARRAY_BUFFER_REF_COPY";
|
||||
})(ARRAY_BUFFER_PARAM_TYPE || (ARRAY_BUFFER_PARAM_TYPE = {}));
|
||||
var UPLOAD_SHADER_UNIFORM_TYPE;
|
||||
(function (UPLOAD_SHADER_UNIFORM_TYPE) {
|
||||
UPLOAD_SHADER_UNIFORM_TYPE[UPLOAD_SHADER_UNIFORM_TYPE["UPLOAD_SHADER_UNIFORM_TYPE_ID"] = 0] = "UPLOAD_SHADER_UNIFORM_TYPE_ID";
|
||||
UPLOAD_SHADER_UNIFORM_TYPE[UPLOAD_SHADER_UNIFORM_TYPE["UPLOAD_SHADER_UNIFORM_TYPE_DATA"] = 1] = "UPLOAD_SHADER_UNIFORM_TYPE_DATA";
|
||||
})(UPLOAD_SHADER_UNIFORM_TYPE || (UPLOAD_SHADER_UNIFORM_TYPE = {}));
|
||||
var ARRAY_BUFFER_TYPE;
|
||||
(function (ARRAY_BUFFER_TYPE) {
|
||||
ARRAY_BUFFER_TYPE[ARRAY_BUFFER_TYPE["ARRAY_BUFFER_TYPE_DATA"] = 0] = "ARRAY_BUFFER_TYPE_DATA";
|
||||
ARRAY_BUFFER_TYPE[ARRAY_BUFFER_TYPE["ARRAY_BUFFER_TYPE_CMD"] = 1] = "ARRAY_BUFFER_TYPE_CMD";
|
||||
})(ARRAY_BUFFER_TYPE || (ARRAY_BUFFER_TYPE = {}));
|
||||
class conchFloatArrayKeyframe {
|
||||
constructor() {
|
||||
this._nativeObj = new _conchFloatArrayKeyframe();
|
||||
}
|
||||
set time(value) {
|
||||
this._nativeObj.setTime(value);
|
||||
}
|
||||
get time() {
|
||||
return this._nativeObj.getTime();
|
||||
}
|
||||
set data(value) {
|
||||
this._data = value;
|
||||
this._nativeObj.setData(value);
|
||||
}
|
||||
get data() {
|
||||
return this._data;
|
||||
}
|
||||
set inTangent(value) {
|
||||
this._inTangent = value;
|
||||
this._nativeObj.setInTangent(this._inTangent);
|
||||
}
|
||||
get inTangent() {
|
||||
return this._inTangent;
|
||||
}
|
||||
set outTangent(value) {
|
||||
this._outTangent = value;
|
||||
this._nativeObj.setOutTangent(this._outTangent);
|
||||
}
|
||||
get outTangent() {
|
||||
return this._outTangent;
|
||||
}
|
||||
set value(v) {
|
||||
this._value = v;
|
||||
this._nativeObj.setValue(this._value);
|
||||
}
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
clone() {
|
||||
let pDestObj = new conchFloatArrayKeyframe();
|
||||
this.cloneTo(pDestObj);
|
||||
return pDestObj;
|
||||
}
|
||||
cloneTo(destObj) {
|
||||
destObj.inTangent = this._inTangent.slice();
|
||||
destObj.outTangent = this._outTangent.slice();
|
||||
destObj.value = this._value.slice();
|
||||
destObj.data = this._data.slice();
|
||||
}
|
||||
}
|
||||
window["conchFloatArrayKeyframe"] = conchFloatArrayKeyframe;
|
||||
class conchKeyframeNode {
|
||||
constructor() {
|
||||
this._keyFrameArray = [];
|
||||
this._type = 0;
|
||||
this._setKeyframeByIndex = function (index, keyframe) {
|
||||
this._keyFrameArray[index] = keyframe;
|
||||
if (keyframe instanceof (conchFloatArrayKeyframe)) {
|
||||
this._nativeObj._setKeyframeByIndex1(index, keyframe._nativeObj);
|
||||
}
|
||||
else {
|
||||
this._nativeObj._setKeyframeByIndex0(index, keyframe);
|
||||
}
|
||||
};
|
||||
this._nativeObj = new _conchKeyframeNode();
|
||||
}
|
||||
set data(value) {
|
||||
this._data = value;
|
||||
this._nativeObj.setFloat32ArrayData(this._data.elements);
|
||||
}
|
||||
get data() {
|
||||
return this._type == 0 ? this._nativeObj.getFloatData() : this._data;
|
||||
}
|
||||
get indexInList() {
|
||||
return this._nativeObj._indexInList;
|
||||
}
|
||||
set indexInList(value) {
|
||||
this._nativeObj._indexInList = value;
|
||||
}
|
||||
get type() {
|
||||
return this._type;
|
||||
}
|
||||
set type(type) {
|
||||
this._type = type;
|
||||
this._nativeObj.type = type;
|
||||
}
|
||||
get fullPath() {
|
||||
return this._nativeObj.fullPath;
|
||||
}
|
||||
set fullPath(path) {
|
||||
this._nativeObj.fullPath = path;
|
||||
}
|
||||
get propertyOwner() {
|
||||
return this._nativeObj.propertyOwner;
|
||||
}
|
||||
set propertyOwner(value) {
|
||||
this._nativeObj.propertyOwner = value;
|
||||
}
|
||||
get ownerPathCount() {
|
||||
return this._nativeObj.ownerPathCount;
|
||||
}
|
||||
set ownerPathCount(value) {
|
||||
this._nativeObj.ownerPathCount = value;
|
||||
}
|
||||
get propertyCount() {
|
||||
return this._nativeObj.propertyCount;
|
||||
}
|
||||
set propertyCount(value) {
|
||||
this._nativeObj.propertyCount = value;
|
||||
}
|
||||
get keyFramesCount() {
|
||||
return this._keyFrameArray.length;
|
||||
}
|
||||
set keyFramesCount(value) {
|
||||
this._keyFrameArray.length = value;
|
||||
this._nativeObj.keyFramesCount = value;
|
||||
}
|
||||
getOwnerPathCount() {
|
||||
return this._nativeObj.getOwnerPathCount();
|
||||
}
|
||||
_setOwnerPathCount(value) {
|
||||
this._nativeObj._setOwnerPathCount(value);
|
||||
}
|
||||
getPropertyCount() {
|
||||
return this._nativeObj.getPropertyCount();
|
||||
}
|
||||
_setPropertyCount(value) {
|
||||
this._nativeObj._setPropertyCount(value);
|
||||
}
|
||||
getKeyFramesCount() {
|
||||
return this._keyFrameArray.length;
|
||||
}
|
||||
_setKeyframeCount(value) {
|
||||
this._keyFrameArray.length = value;
|
||||
this._nativeObj._setKeyframeCount(value);
|
||||
}
|
||||
getOwnerPathByIndex(index) {
|
||||
return this._nativeObj.getOwnerPathByIndex(index);
|
||||
}
|
||||
_setOwnerPathByIndex(index, value) {
|
||||
this._nativeObj._setOwnerPathByIndex(index, value);
|
||||
}
|
||||
getPropertyByIndex(index) {
|
||||
return this._nativeObj.getPropertyByIndex(index);
|
||||
}
|
||||
_setPropertyByIndex(index, value) {
|
||||
this._nativeObj._setPropertyByIndex(index, value);
|
||||
}
|
||||
getKeyframeByIndex(index) {
|
||||
return this._nativeObj.getKeyframeByIndex(index);
|
||||
}
|
||||
_joinOwnerPath(sep) {
|
||||
return this._nativeObj._joinOwnerPath(sep);
|
||||
}
|
||||
_joinProperty(sep) {
|
||||
return this._nativeObj._joinProperty(sep);
|
||||
}
|
||||
}
|
||||
window["conchKeyframeNode"] = conchKeyframeNode;
|
||||
class conchKeyframeNodeList {
|
||||
constructor() {
|
||||
this._nodes = [];
|
||||
this._nativeObj = new _conchKeyframeNodeList();
|
||||
}
|
||||
set count(value) {
|
||||
this._nodes.length = value;
|
||||
this._nativeObj.setCount(value);
|
||||
}
|
||||
get count() {
|
||||
return this._nodes.length;
|
||||
}
|
||||
getNodeByIndex(index) {
|
||||
return this._nodes[index];
|
||||
}
|
||||
setNodeByIndex(index, node) {
|
||||
this._nodes[index] = node;
|
||||
this._nativeObj.setNodeByIndex(index, node._nativeObj);
|
||||
}
|
||||
}
|
||||
window["conchKeyframeNodeList"] = conchKeyframeNodeList;
|
||||
class _GLCommandEncoder {
|
||||
constructor(gl, reserveSize, adjustSize, isSyncToRenderThread) {
|
||||
this._adjustSize = 0;
|
||||
this._byteLen = 0;
|
||||
this._isSyncToRenderThread = false;
|
||||
this._isSyncToRenderThread = isSyncToRenderThread;
|
||||
this._layagl = gl;
|
||||
this._byteLen = reserveSize;
|
||||
this._adjustSize = adjustSize;
|
||||
this._init(isSyncToRenderThread);
|
||||
}
|
||||
_init(isSyncToRenderThread) {
|
||||
this._buffer = new ArrayBuffer(this._byteLen);
|
||||
this._idata = new Int32Array(this._buffer);
|
||||
this._fdata = new Float32Array(this._buffer);
|
||||
this._byteArray = new Uint8Array(this._buffer);
|
||||
this._layagl.createArrayBufferRef(this._buffer, ARRAY_BUFFER_TYPE.ARRAY_BUFFER_TYPE_CMD, isSyncToRenderThread);
|
||||
this._idata[0] = 1;
|
||||
}
|
||||
getAlignLength(data) {
|
||||
var byteLength = data.byteLength;
|
||||
return (byteLength + 3) & 0xfffffffc;
|
||||
}
|
||||
getPtrID() {
|
||||
return this._buffer["_ptrID"];
|
||||
}
|
||||
clearEncoding() {
|
||||
this._idata[0] = 1;
|
||||
}
|
||||
getCount() {
|
||||
return this._idata[0];
|
||||
}
|
||||
_need(sz) {
|
||||
if ((this._byteLen - (this._idata[0] << 2)) >= sz)
|
||||
return;
|
||||
this._byteLen += (sz > this._adjustSize) ? sz : this._adjustSize;
|
||||
var pre = this._idata;
|
||||
var preConchRef = this._buffer["conchRef"];
|
||||
var prePtrID = this._buffer["_ptrID"];
|
||||
this._buffer = new ArrayBuffer(this._byteLen);
|
||||
this._idata = new Int32Array(this._buffer);
|
||||
this._fdata = new Float32Array(this._buffer);
|
||||
this._byteArray = new Uint8Array(this._buffer);
|
||||
this._buffer["conchRef"] = preConchRef;
|
||||
this._buffer["_ptrID"] = prePtrID;
|
||||
pre && this._idata.set(pre, 0);
|
||||
webglPlus.updateArrayBufferRef(this._buffer["_ptrID"], preConchRef.isSyncToRender(), this._buffer);
|
||||
}
|
||||
addShaderUniform(one) {
|
||||
var funID = 0;
|
||||
var isArray = one.isArray;
|
||||
switch (one.type) {
|
||||
case _GLCommandEncoder.INT:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM1IV : UNIFORM_TYPE.INTERIOR_UNIFORM1I;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM1FV : UNIFORM_TYPE.INTERIOR_UNIFORM1F;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_VEC2:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM2FV : UNIFORM_TYPE.INTERIOR_UNIFORM2F;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_VEC3:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM3FV : UNIFORM_TYPE.INTERIOR_UNIFORM3F;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_VEC4:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM4FV : UNIFORM_TYPE.INTERIOR_UNIFORM4F;
|
||||
break;
|
||||
case _GLCommandEncoder.SAMPLER_2D:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMSAMPLER_2D;
|
||||
break;
|
||||
case _GLCommandEncoder.SAMPLER_CUBE:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMSAMPLER_CUBE;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_MAT4:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMMATRIX4FV;
|
||||
break;
|
||||
case _GLCommandEncoder.BOOL:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORM1I;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_MAT2:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMMATRIX2FV;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_MAT3:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMMATRIX3FV;
|
||||
break;
|
||||
default:
|
||||
throw new Error("compile shader err!");
|
||||
}
|
||||
this._layagl.syncBufferToRenderThread(this._buffer);
|
||||
this.add_iiiiii(3, funID, one.location.id, one.type, one.dataOffset, one.textureID);
|
||||
}
|
||||
add_iiiiii(a, b, c, d, e, f) {
|
||||
this._need(24);
|
||||
var idata = this._idata;
|
||||
var i = idata[0];
|
||||
idata[i++] = a;
|
||||
idata[i++] = b;
|
||||
idata[i++] = c;
|
||||
idata[i++] = d;
|
||||
idata[i++] = e;
|
||||
idata[i++] = f;
|
||||
idata[0] = i;
|
||||
}
|
||||
}
|
||||
_GLCommandEncoder.INT = 0x1404;
|
||||
_GLCommandEncoder.FLOAT = 0x1406;
|
||||
_GLCommandEncoder.FLOAT_VEC2 = 0x8B50;
|
||||
_GLCommandEncoder.FLOAT_VEC3 = 0x8B51;
|
||||
_GLCommandEncoder.FLOAT_VEC4 = 0x8B52;
|
||||
_GLCommandEncoder.INT_VEC2 = 0x8B53;
|
||||
_GLCommandEncoder.INT_VEC3 = 0x8B54;
|
||||
_GLCommandEncoder.INT_VEC4 = 0x8B55;
|
||||
_GLCommandEncoder.BOOL = 0x8B56;
|
||||
_GLCommandEncoder.BOOL_VEC2 = 0x8B57;
|
||||
_GLCommandEncoder.BOOL_VEC3 = 0x8B58;
|
||||
_GLCommandEncoder.BOOL_VEC4 = 0x8B59;
|
||||
_GLCommandEncoder.FLOAT_MAT2 = 0x8B5A;
|
||||
_GLCommandEncoder.FLOAT_MAT3 = 0x8B5B;
|
||||
_GLCommandEncoder.FLOAT_MAT4 = 0x8B5C;
|
||||
_GLCommandEncoder.SAMPLER_2D = 0x8B5E;
|
||||
_GLCommandEncoder.SAMPLER_CUBE = 0x8B60;
|
||||
function extendWebGLPlusToWebGLContext(gl) {
|
||||
gl.prototype.createArrayBufferRef = function (arrayBuffer, type, syncRender) {
|
||||
var bufferConchRef = webglPlus.createArrayBufferRef(arrayBuffer, type, syncRender, ARRAY_BUFFER_PARAM_TYPE.ARRAY_BUFFER_REF_REFERENCE);
|
||||
arrayBuffer["conchRef"] = bufferConchRef;
|
||||
arrayBuffer["_ptrID"] = bufferConchRef.id;
|
||||
return bufferConchRef;
|
||||
};
|
||||
gl.prototype.createArrayBufferRefs = function (arrayBuffer, type, syncRender, refType) {
|
||||
if (!arrayBuffer._refArray) {
|
||||
arrayBuffer._refArray = [];
|
||||
arrayBuffer._refNum = 1;
|
||||
arrayBuffer._refArray.length = 1;
|
||||
arrayBuffer.getRefNum = function () {
|
||||
return this._refNum;
|
||||
};
|
||||
arrayBuffer.clearRefNum = function () {
|
||||
this._refNum = 1;
|
||||
};
|
||||
arrayBuffer.getRefSize = function () {
|
||||
return this._refArray.length;
|
||||
};
|
||||
arrayBuffer.getPtrID = function (index) {
|
||||
index = index ? index : 0;
|
||||
return this._refArray[index].ptrID;
|
||||
};
|
||||
}
|
||||
var bufferConchRef = null;
|
||||
if (refType == ARRAY_BUFFER_PARAM_TYPE.ARRAY_BUFFER_REF_REFERENCE) {
|
||||
var refArray = arrayBuffer._refArray;
|
||||
if (!refArray[0]) {
|
||||
bufferConchRef = webglPlus.createArrayBufferRef(arrayBuffer, type, syncRender, refType);
|
||||
refArray[0] = { "ref": bufferConchRef, "ptrID": bufferConchRef.id };
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (arrayBuffer._refNum < arrayBuffer._refArray.length) {
|
||||
bufferConchRef = arrayBuffer._refArray[arrayBuffer._refNum].ref;
|
||||
var nPtrID = arrayBuffer.getPtrID(arrayBuffer._refNum);
|
||||
webglPlus.syncArrayBufferDataToRuntime(nPtrID, bufferConchRef.isSyncToRender(), arrayBuffer);
|
||||
}
|
||||
else {
|
||||
bufferConchRef = webglPlus.createArrayBufferRef(arrayBuffer, type, syncRender, refType);
|
||||
arrayBuffer._refArray.push({ "ref": bufferConchRef, "ptrID": bufferConchRef.id });
|
||||
}
|
||||
arrayBuffer._refNum++;
|
||||
}
|
||||
return bufferConchRef;
|
||||
};
|
||||
gl.prototype.updateArrayBufferRef = function (bufferID, isSyncToRender, buffer) {
|
||||
return webglPlus.updateArrayBufferRef(bufferID, isSyncToRender, buffer);
|
||||
};
|
||||
gl.prototype.updateAnimationNodeWorldMatix = function (locPosition, locRotation, locScaling, parentIndices, outWorldMatrix) {
|
||||
return webglPlus.updateAnimationNodeWorldMatix(locPosition, locRotation, locScaling, parentIndices, outWorldMatrix);
|
||||
};
|
||||
gl.prototype.computeSubSkinnedData = function (worldMatrixs, worldMatrixIndex, inverseBindPoses, boneIndices, bindPoseInices, resultData) {
|
||||
return webglPlus.computeSubSkinnedData(worldMatrixs, worldMatrixIndex, inverseBindPoses, boneIndices, bindPoseInices, resultData);
|
||||
};
|
||||
gl.prototype.evaluateClipDatasRealTime = function (nodes, playCurTime, realTimeCurrentFrameIndexs, addtive, frontPlay) {
|
||||
webglPlus.evaluateClipDatasRealTime(nodes, playCurTime, realTimeCurrentFrameIndexs, addtive, frontPlay);
|
||||
};
|
||||
gl.prototype.culling = function (boundFrustumBuffer, cullingBuffer, cullingBufferIndices, cullingCount, cullingBufferResult) {
|
||||
return webglPlus.culling(boundFrustumBuffer, cullingBuffer, cullingBufferIndices, cullingCount, cullingBufferResult);
|
||||
};
|
||||
if (!window["conch"]) {
|
||||
gl.prototype.createCommandEncoder = function (reserveSize, adjustSize, isSyncToRenderThread) {
|
||||
reserveSize = reserveSize ? reserveSize : 128;
|
||||
adjustSize = adjustSize ? adjustSize : 64;
|
||||
isSyncToRenderThread = isSyncToRenderThread ? isSyncToRenderThread : false;
|
||||
var cmd = new _GLCommandEncoder(this, reserveSize, adjustSize, isSyncToRenderThread);
|
||||
if (isSyncToRenderThread) {
|
||||
this.syncBufferToRenderThread(cmd);
|
||||
}
|
||||
return cmd;
|
||||
};
|
||||
window["GLCommandEncoder"] = _GLCommandEncoder;
|
||||
gl.prototype.syncBufferToRenderThread = function (value, index = 0) {
|
||||
};
|
||||
}
|
||||
if (!window["conch"]) {
|
||||
gl.prototype.uploadShaderUniforms = function (commandEncoder, data, type) {
|
||||
if (type == UPLOAD_SHADER_UNIFORM_TYPE.UPLOAD_SHADER_UNIFORM_TYPE_ID) {
|
||||
var dataID = data["_ptrID"];
|
||||
this.syncBufferToRenderThread(data);
|
||||
}
|
||||
else {
|
||||
var nAlignLength = this.getAlignLength(data);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
gl.prototype.uniformMatrix2fvEx = function (location, transpose, value) {
|
||||
if (!value["_ptrID"]) {
|
||||
this.createArrayBufferRef(value, ARRAY_BUFFER_TYPE.ARRAY_BUFFER_TYPE_DATA, true);
|
||||
}
|
||||
var nID = value["_ptrID"];
|
||||
this.syncBufferToRenderThread(value);
|
||||
};
|
||||
gl.prototype.uniformMatrix3fvEx = function (location, transpose, value) {
|
||||
if (!value["_ptrID"]) {
|
||||
this.createArrayBufferRef(value, ARRAY_BUFFER_TYPE.ARRAY_BUFFER_TYPE_DATA, true);
|
||||
}
|
||||
var nID = value["_ptrID"];
|
||||
this.syncBufferToRenderThread(value);
|
||||
};
|
||||
gl.prototype.uniformMatrix4fvEx = function (location, transpose, value) {
|
||||
if (!value["_ptrID"]) {
|
||||
this.createArrayBufferRef(value, ARRAY_BUFFER_TYPE.ARRAY_BUFFER_TYPE_DATA, true);
|
||||
}
|
||||
var nID = value["_ptrID"];
|
||||
this.syncBufferToRenderThread(value);
|
||||
};
|
||||
}
|
||||
}
|
||||
window["extendWebGLPlusToWebGLContext"] = extendWebGLPlusToWebGLContext;
|
||||
Reference in New Issue
Block a user