move template to engine (#10844)

This commit is contained in:
Santy-Wang
2022-04-24 14:44:26 +08:00
committed by GitHub
parent 3d9e81eee7
commit 06d5d3522a
32 changed files with 1294 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
require('./libs/wrapper/builtin');
window.DOMParser = require('./libs/common/xmldom/dom-parser').DOMParser;
window.__globalAdapter = {};
require('./libs/wrapper/unify');
require('./libs/wrapper/fs-utils');
<% if(polyfillsBundleFile) { %>
// Polyfills bundle.
require("<%= polyfillsBundleFile %>");
<% } %>
// SystemJS support.
window.self = window;
require("<%= systemJsBundleFile %>");
const info = my.getSystemInfoSync();
if (info.platform == "iOS") {
canvas.width *= info.pixelRatio;
canvas.height *= info.pixelRatio;
} else {
canvas.width = info.screenWidth;
canvas.height = info.screenHeight;
}
const importMap = require("<%= importMapFile%>").default;
System.warmup({
importMap,
importMapUrl: '<%= importMapFile%>',
defaultHandler: (urlNoSchema) => {
require('.' + urlNoSchema);
},
});
System.import('<%= applicationJs %>').then(({ createApplication }) => {
return createApplication({
loadJsListFile: (url) => require(`./${url}`),
fetchWasm: (url) => url,
});
}).then((application) => {
return onApplicationCreated(application);
}).catch((err) => {
console.error(err);
});
function onApplicationCreated(application) {
return application.import('cc').then((cc) => {
require('./libs/common/engine/index.js');
require('./libs/wrapper/engine/index.js');
// not support require twice
// require('./libs/common/cache-manager.js');
// Adjust devicePixelRatio
cc.view._maxPixelRatio = 5;
// Release Image objects after uploaded gl texture
cc.macro.CLEANUP_IMAGE_CACHE = false;
return application.start({
findCanvas: () => {
var container = document.createElement('div');
return { frame: container, canvas: window.canvas, container };
},
});
});
}
+10
View File
@@ -0,0 +1,10 @@
{
"screenOrientation": "landscape",
"networkTimeout": {
"request": 5000,
"connectSocket": 5000,
"download": 500000,
"upload": 5000
},
"showStatusBar": false
}
+84
View File
@@ -0,0 +1,84 @@
require('./libs/wrapper/builtin/index');
window.DOMParser = require('./libs/common/xmldom/dom-parser').DOMParser;
window.__globalAdapter = {};
require('./libs/wrapper/unify');
require('./libs/wrapper/fs-utils');
<% if(polyfillsBundleFile) { %>
// Polyfills bundle.
require("<%= polyfillsBundleFile %>");
<% } %>
// SystemJS support.
require("<%= systemJsBundleFile %>");
// 这句只有百度需要,因为百度的 webpack 提供了假的 System
const System = globalThis.System;
// Adapt for IOS, swap if opposite
if (canvas) {
var _w = canvas.width;
var _h = canvas.height;
if (screen.width < screen.height) {
if (canvas.width > canvas.height) {
_w = canvas.height;
_h = canvas.width;
}
} else {
if (canvas.width < canvas.height) {
_w = canvas.height;
_h = canvas.width;
}
}
canvas.width = _w;
canvas.height = _h;
}
// Adjust initial canvas size
if (canvas && window.devicePixelRatio >= 2) {canvas.width *= 2; canvas.height *= 2;}
const importMap = require("<%= importMapFile%>").default;
System.warmup({
importMap,
importMapUrl: '<%= importMapFile%>',
defaultHandler: (urlNoSchema) => {
require('.' + urlNoSchema);
},
});
System.import('<%= applicationJs %>').then(({ createApplication }) => {
return createApplication({
loadJsListFile: (url) => require(`./${url}`),
fetchWasm: (url) => url,
});
}).then((application) => {
return onApplicationCreated(application);
}).catch((err) => {
console.error(err);
});
function onApplicationCreated(application) {
return application.import('cc').then((cc) => {
require('./libs/common/engine/index.js');
require('./libs/wrapper/engine/index');
require('./libs/common/cache-manager.js');
// Adjust devicePixelRatio
cc.view._maxPixelRatio = 4;
// Release Image objects after uploaded gl texture
cc.macro.CLEANUP_IMAGE_CACHE = false;
// post system info to open data context
swan.getOpenDataContext().postMessage({
type: 'engine',
event: 'systemInfo',
systemInfo: swan.getSystemInfoSync(),
});
return application.start({
findCanvas: () => {
var container = document.createElement('div');
return { frame: container, canvas: window.canvas, container };
},
});
});
}
+11
View File
@@ -0,0 +1,11 @@
{
"deviceOrientation": "landscape",
"openDataContext": "",
"networkTimeout":
{
"request": 5000,
"connectSocket": 5000,
"uploadFile": 5000,
"downloadFile": 500000
}
}
@@ -0,0 +1,14 @@
{
"appid": "",
"compileType": "game",
"libVersion": "1.0.0",
"bundle":
{
"exclude": ["node_moudules"],
"entry": "game.js",
"compilers": [
{
"type": "babel"
}]
}
}
+119
View File
@@ -0,0 +1,119 @@
<%- include(versionCheckTemplate, { version: '1.0.0' }) %>
<% if (isUsePhysX) { %>
const systemInfo = tt.getSystemInfoSync();
// a hack way to load physics provide by bytedance
if (tt.getPhysx) {
tt.getPhysx({
success (physx) {
if (!physx) {
console.error('can not use native PhysX');
} else {
console.info('physics plugin load success, version=' + physx.getVersion());
GameGlobal.nativePhysX = physx;
}
loadCC();
},
fail () {
loadCC();
}
});
} else if (systemInfo.platform === 'android' && tt.getLoader && tt.getLoader()) {
const appid = "<%= appid %>";
const loader = tt.getLoader().loader;
loader.load('physics', appid, "token", message => {
if (message) {
console.error('[tt.loader]:' + message);
} else {
console.info('[tt.loader]: physics plugin load success, version=' + tt.getPhy().getVersion());
GameGlobal.nativePhysX = tt.getPhy();
}
loadCC();
})
} else {
loadCC();
}
<% } %>
<% if (!isUsePhysX) { %>
loadCC();
<% } %>
function loadCC() {
require('./libs/wrapper/builtin/index');
window.DOMParser = require('./libs/common/xmldom/dom-parser').DOMParser;
window.__globalAdapter = {};
require('./libs/wrapper/unify');
require('./libs/wrapper/fs-utils');
// Polyfills bundle.
require("<%= polyfillsBundleFile %>");
// SystemJS support.
require("<%= systemJsBundleFile %>");
// Adapt for IOS, swap if opposite
if (canvas){
var _w = canvas.width;
var _h = canvas.height;
if (screen.width < screen.height) {
if (canvas.width > canvas.height) {
_w = canvas.height;
_h = canvas.width;
}
} else {
if (canvas.width < canvas.height) {
_w = canvas.height;
_h = canvas.width;
}
}
canvas.width = _w;
canvas.height = _h;
}
// Adjust initial canvas size
if (canvas && window.devicePixelRatio >= 2) {canvas.width *= 2; canvas.height *= 2;}
const importMap = require("<%= importMapFile%>").default;
System.warmup({
importMap,
importMapUrl: '<%= importMapFile%>',
defaultHandler: (urlNoSchema) => {
require('.' + urlNoSchema);
},
handlers: {
'plugin:': (urlNoSchema) => {
requirePlugin(urlNoSchema);
},
},
});
System.import('<%= applicationJs %>').then(({ createApplication }) => {
return createApplication({
loadJsListFile: (url) => require(url),
fetchWasm: (url) => url,
});
}).then((application) => {
return onApplicationCreated(application);
}).catch((err) => {
console.error(err);
});
function onApplicationCreated(application) {
return application.import('cc').then((cc) => {
require('./libs/common/engine/index.js');
require('./libs/wrapper/engine/index');
require('./libs/common/cache-manager.js');
// Adjust devicePixelRatio
cc.view._maxPixelRatio = 4;
// Release Image objects after uploaded gl texture
cc.macro.CLEANUP_IMAGE_CACHE = false;
return application.start({
findCanvas: () => {
var container = document.createElement('div');
return { frame: container, canvas: window.canvas, container };
},
});
});
}
}
+11
View File
@@ -0,0 +1,11 @@
{
"deviceOrientation": "portrait",
"showStatusBar": false,
"openDataContext": "",
"networkTimeout": {
"request": 5000,
"connectSocket": 5000,
"uploadFile": 5000,
"downloadFile": 500000
}
}
@@ -0,0 +1,11 @@
{
"setting": {
"urlCheck": true,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true
},
"appid": "testappId",
"projectname": ""
}
@@ -0,0 +1,3 @@
<% if (!customVersion || customVersion !== version) { %>
console.warn(<%= versionTips %>)
<% } %>
+42
View File
@@ -0,0 +1,42 @@
<% if(polyfillsBundleFile) { %>
// Polyfills bundle.
require("<%= polyfillsBundleFile %>");
<% } %>
// SystemJS support.
window.self = window;
require("<%= systemJsBundleFile %>");
const importMapJson = jsb.fileUtils.getStringFromFile("<%= importMapFile%>");
const importMap = JSON.parse(importMapJson);
System.warmup({
importMap,
importMapUrl: '<%= importMapFile%>',
defaultHandler: (urlNoSchema) => {
require(urlNoSchema.startsWith('/') ? urlNoSchema.substr(1) : urlNoSchema);
},
});
System.import('<%= applicationJs %>').then(({ createApplication }) => {
return createApplication({
loadJsListFile: (url) => require(url),
fetchWasm: (url) => url,
});
}).then((application) => {
return application.import('cc').then((cc) => {
require('jsb-adapter/jsb-engine.js');
cc.macro.CLEANUP_IMAGE_CACHE = false;
}).then(() => {
return application.start({
settings: window._CCSettings,
findCanvas: () => {
var container = document.createElement('div');
var frame = document.documentElement;
var canvas = window.__canvas;
return { frame, canvas, container };
},
});
});
}).catch((err) => {
console.error(err.toString());
});
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

+12
View File
@@ -0,0 +1,12 @@
<!-- Polyfills bundle. -->
<script src="<%= polyfillsBundleFile %>" charset="utf-8"> </script>
<!-- SystemJS support. -->
<script src="<%= systemJsBundleFile %>" charset="utf-8"> </script>
<!-- Import map -->
<script src="<%= importMapFile%>" type="systemjs-importmap" charset="utf-8"> </script>
<script>
System.import('./<%= indexJsName %>').catch(function(err) { console.error(err); })
</script>
+35
View File
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Cocos Creator | <%= projectName %></title>
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,minimum-scale=1,maximum-scale=1,minimal-ui=true"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="full-screen" content="yes"/>
<meta name="screen-orientation" content="portrait"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<meta name="renderer" content="webkit"/>
<meta name="force-rendering" content="webkit"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<link rel="stylesheet" type="text/css" href="<%= cssUrl %>"/>
<link rel="icon" href="favicon.ico"/>
</head>
<body>
<h1 class="header"><%= projectName %></h1>
<div id="GameDiv" cc_exact_fit_screen="false" style="width: <%= previewWidth %>px; height: <%= previewHeight %>px;">
<div id="Cocos3dGameContainer">
<canvas id="GameCanvas" width="<%= previewWidth %>" height="<%= previewHeight %>"></canvas>
</div>
</div>
<p class="footer">
Created with <a href="https://www.cocos.com/products" title="Cocos Creator">Cocos Creator</a>
</p>
<%- include(cocosTemplate, {}) %>
</body>
</html>
+69
View File
@@ -0,0 +1,69 @@
import { createApplication } from '<%= applicationJS %>';
createApplication({
loadJsListFile,
fetchWasm,
}).then((application) => {
return application.start({
findCanvas,
});
}).catch((err) => {
console.error(err);
});
function loadJsListFile(url) {
return new Promise(function (resolve, reject) {
var err;
function windowErrorListener(evt) {
if (evt.filename === url) {
err = evt.error;
}
}
window.addEventListener('error', windowErrorListener);
var script = document.createElement('script');
script.charset = 'utf-8';
script.async = true;
script.crossOrigin = 'anonymous';
script.addEventListener('error', function () {
window.removeEventListener('error', windowErrorListener);
reject(Error('Error loading ' + url));
});
script.addEventListener('load', function () {
window.removeEventListener('error', windowErrorListener);
document.head.removeChild(script);
// Note that if an error occurs that isn't caught by this if statement,
// that getRegister will return null and a "did not instantiate" error will be thrown.
if (err) {
reject(err);
} else {
resolve();
}
});
script.src = url;
document.head.appendChild(script);
});
}
function fetchWasm(url) {
return url;
}
function findCanvas() {
const frame = document.querySelector('#GameDiv');
const container = document.querySelector('#Cocos3dGameContainer');
const canvas = document.querySelector('#GameCanvas');
canvas.setAttribute('tabindex', '99');
return { frame, container, canvas };
}
function addClass(element, name) {
var hasClass = (' ' + element.className + ' ').indexOf(' ' + name + ' ') > -1;
if (!hasClass) {
if (element.className) {
element.className += ' ';
}
element.className += name;
}
}
+45
View File
@@ -0,0 +1,45 @@
body {
cursor: default;
padding: 0;
border: 0;
margin: 0;
text-align: center;
background-color: white;
font-family: Helvetica, Verdana, Arial, sans-serif;
}
body, canvas, div {
outline: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
/* Remove spin of input type number */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* display: none; <- Crashes Chrome on hover */
-webkit-appearance: none;
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}
canvas {
background-color: rgba(0, 0, 0, 0);
}
#GameDiv {
margin: 0 auto;
background: black;
position:relative;
border:5px solid black;
border-radius: 10px;
box-shadow: 0 5px 50px #333
}
#Cocos3dGameContainer, #GameCanvas {
width: 100%;
height: 100%;
}
+19
View File
@@ -0,0 +1,19 @@
<% if (webDebuggerSrc) { %>
<script src="<%=webDebuggerSrc%>"></script>
<script type="text/javascript">
// open web debugger console
window.VConsole && (window.vConsole = new VConsole());
</script>
<% } %>
<!-- Polyfills bundle. -->
<script src="<%= polyfillsBundleFile %>" charset="utf-8"> </script>
<!-- SystemJS support. -->
<script src="<%= systemJsBundleFile %>" charset="utf-8"> </script>
<!-- Import map -->
<script src="<%= importMapFile%>" type="systemjs-importmap" charset="utf-8"> </script>
<script>
System.import('./<%= indexJsName %>').catch(function(err) { console.error(err); })
</script>
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Cocos Creator | <%= projectName %></title>
<!--http://www.html5rocks.com/en/mobile/mobifying/-->
<meta name="viewport"
content="width=device-width,user-scalable=no,initial-scale=1,minimum-scale=1,maximum-scale=1,minimal-ui=true"/>
<!--https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html-->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="format-detection" content="telephone=no">
<!-- force webkit on 360 -->
<meta name="renderer" content="webkit"/>
<meta name="force-rendering" content="webkit"/>
<!-- force edge on IE -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="msapplication-tap-highlight" content="no">
<!-- force full screen on some browser -->
<meta name="full-screen" content="yes"/>
<meta name="x5-fullscreen" content="true"/>
<meta name="360-fullscreen" content="true"/>
<!--fix fireball/issues/3568 -->
<!--<meta name="browsermode" content="application">-->
<meta name="x5-page-mode" content="app">
<!--<link rel="apple-touch-icon" href=".png" />-->
<!--<link rel="apple-touch-icon-precomposed" href=".png" />-->
<link rel="stylesheet" type="text/css" href="<%= cssUrl %>"/>
</head>
<body>
<div id="GameDiv" cc_exact_fit_screen="true">
<div id="Cocos3dGameContainer">
<canvas id="GameCanvas" oncontextmenu="event.preventDefault()" tabindex="0"></canvas>
</div>
</div>
<%- include(cocosTemplate, {}) %>
</body>
</html>
+74
View File
@@ -0,0 +1,74 @@
import { createApplication } from '<%= applicationJS %>';
const canvas = document.getElementById('GameCanvas');
const $p = canvas.parentElement;
const bcr = $p.getBoundingClientRect();
canvas.width = bcr.width;
canvas.height = bcr.height;
createApplication({
loadJsListFile,
fetchWasm,
}).then((application) => {
return application.start({
findCanvas,
});
}).catch((err) => {
console.error(err);
});
function loadJsListFile(url) {
return new Promise(function (resolve, reject) {
var err;
function windowErrorListener(evt) {
if (evt.filename === url) {
err = evt.error;
}
}
window.addEventListener('error', windowErrorListener);
var script = document.createElement('script');
script.charset = 'utf-8';
script.async = true;
script.crossOrigin = 'anonymous';
script.addEventListener('error', function () {
window.removeEventListener('error', windowErrorListener);
reject(Error('Error loading ' + url));
});
script.addEventListener('load', function () {
window.removeEventListener('error', windowErrorListener);
document.head.removeChild(script);
// Note that if an error occurs that isn't caught by this if statement,
// that getRegister will return null and a "did not instantiate" error will be thrown.
if (err) {
reject(err);
} else {
resolve();
}
});
script.src = url;
document.head.appendChild(script);
});
}
function fetchWasm(url) {
return url;
}
function findCanvas() {
const frame = document.querySelector('#GameDiv');
const container = document.querySelector('#Cocos3dGameContainer');
const canvas = document.querySelector('#GameCanvas');
canvas.setAttribute('tabindex', '99');
return { frame, container, canvas };
}
function addClass (element, name) {
const hasClass = (' ' + element.className + ' ').indexOf(' ' + name + ' ') > -1;
if (!hasClass) {
if (element.className) {
element.className += ' ';
}
element.className += name;
}
}
+54
View File
@@ -0,0 +1,54 @@
html {
-ms-touch-action: none;
}
body, canvas, div {
display: block;
outline: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
/* Remove spin of input type number */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* display: none; <- Crashes Chrome on hover */
-webkit-appearance: none;
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}
body {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 0;
border: 0;
margin: 0;
cursor: default;
color: #888;
background-color: #333;
text-align: center;
font-family: Helvetica, Verdana, Arial, sans-serif;
display: flex;
flex-direction: column;
}
canvas {
background-color: rgba(0, 0, 0, 0);
}
#GameDiv, #Cocos3dGameContainer, #GameCanvas {
width: 100%;
height: 100%;
}
File diff suppressed because one or more lines are too long
+6
View File
@@ -0,0 +1,6 @@
<% if(polyfillsBundleFile) { %>
// Polyfills bundle.
require("<%= polyfillsBundleFile %>");
<% } %>
// SystemJS support.
require("<%= systemJsBundleFile %>");
+269
View File
@@ -0,0 +1,269 @@
const VS_LOGO = `
attribute vec4 a_Position;
attribute vec2 a_TexCoord;
varying vec2 v_TexCoord;
void main() {
gl_Position = a_Position;
v_TexCoord = a_TexCoord;
}`;
const FS_LOGO = `
precision mediump float;
uniform sampler2D u_Sampler;
varying vec2 v_TexCoord;
void main() {
gl_FragColor = texture2D(u_Sampler, v_TexCoord);
}`;
const VS_PROGRESSBAR = `
precision mediump float;
attribute vec4 a_Position;
attribute float a_Progress;
varying float v_Progress;
void main() {
gl_Position = a_Position;
v_Progress = a_Progress;
}`;
const FS_PROGRESSBAR = `
precision mediump float;
uniform float u_CurrentProgress;
varying float v_Progress;
uniform vec4 u_ProgressBarColor;
uniform vec4 u_ProgressBackground;
void main() {
gl_FragColor = v_Progress <= u_CurrentProgress ? u_ProgressBarColor : u_ProgressBackground;
}`;
const options = {
alpha: false,
antialias: true,
depth: true,
stencil: true,
premultipliedAlpha: false,
preserveDrawingBuffer: false,
powerPreference: 'default',
failIfMajorPerformanceCaveat: false,
};
let gl = null;
let image = null;
let program = null;
let programProgress = null;
let rafHandle = null;
let texture = null;
let vertexBuffer = null;
let vertexBufferProgress = null;
let progress = 0.0;
let progressBarColor = [61 / 255, 197 / 255, 222 / 255, 1];
let progressBackground = [100 / 255, 111 / 255, 118 / 255, 1];
let afterTick = null;
function initShaders(vshader, fshader) {
return createProgram(vshader, fshader);
}
function createProgram(vshader, fshader) {
var vertexShader = loadShader(gl.VERTEX_SHADER, vshader);
var fragmentShader = loadShader(gl.FRAGMENT_SHADER, fshader);
var program = gl.createProgram();
gl.attachShader(program, vertexShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
if (!linked) {
var error = gl.getProgramInfoLog(program);
console.log('Failed to link program: ' + error);
gl.deleteProgram(program);
program = null;
}
gl.deleteShader(fragmentShader);
gl.deleteShader(vertexShader);
return program;
}
function loadShader(type, source) {
var shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
if (!compiled) {
var error = gl.getShaderInfoLog(shader);
console.log('Failed to compile shader: ' + error);
gl.deleteShader(shader);
return null;
}
return shader;
}
function initVertexBuffer() {
const widthRatio = 2 / canvas.width;
const heightRatio = 2 / canvas.height;
const vertices = new Float32Array([
widthRatio, heightRatio, 1.0, 1.0,
widthRatio, heightRatio, 1.0, 0.0,
-widthRatio, heightRatio, 0.0, 1.0,
-widthRatio, heightRatio, 0.0, 0.0,
]);
vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
}
function initProgressVertexBuffer() {
const widthRatio = 0.405;
const heightRatio = (window.devicePixelRatio >= 2 ? 6 : 3) / canvas.height;
const heightOffset = -0.25;
const vertices = new Float32Array([
widthRatio, heightOffset - heightRatio, 1,
widthRatio, heightOffset + heightRatio, 1,
-widthRatio, heightOffset - heightRatio, 0,
-widthRatio, heightOffset + heightRatio, 0,
]);
vertexBufferProgress = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBufferProgress);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
}
function updateVertexBuffer() {
const widthRatio = image.width / canvas.width;
const heightRatio = image.height / canvas.height;
const vertices = new Float32Array([
widthRatio, -heightRatio, 1.0, 1.0,
widthRatio, heightRatio, 1.0, 0.0,
-widthRatio, -heightRatio, 0.0, 1.0,
-widthRatio, heightRatio, 0.0, 0.0,
]);
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
}
function loadImage(imgPath) {
return new Promise((resolve, reject) => {
image = new Image();
image.premultiplyAlpha = false;
image.onload = function() {
resolve(image);
};
image.onerror = function(err) {
reject(err);
};
image.src = imgPath.replace('#', '%23');
});
}
function initTexture() {
texture = gl.createTexture();
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255]));
}
function updateTexture() {
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
function draw() {
gl.clearColor(0.0, 0.0, 0.0, 0.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.useProgram(program);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
var uSampler = gl.getUniformLocation(program, 'u_Sampler');
gl.uniform1i(uSampler, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
var vertexFormatLength = 4;
var aPosition = gl.getAttribLocation(program, 'a_Position');
gl.enableVertexAttribArray(aPosition);
gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, vertexFormatLength * 4, 0);
var aTexCoord = gl.getAttribLocation(program, 'a_TexCoord');
gl.enableVertexAttribArray(aTexCoord);
gl.vertexAttribPointer(aTexCoord, 2, gl.FLOAT, false, vertexFormatLength * 4, vertexFormatLength * 2);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
gl.useProgram(programProgress);
var uCurrentProgress = gl.getUniformLocation(programProgress, 'u_CurrentProgress');
gl.uniform1f(uCurrentProgress, progress);
var uProgressBarColor = gl.getUniformLocation(programProgress, 'u_ProgressBarColor');
gl.uniform4fv(uProgressBarColor, progressBarColor);
var uProgressBackground = gl.getUniformLocation(programProgress, 'u_ProgressBackground');
gl.uniform4fv(uProgressBackground, progressBackground);
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBufferProgress);
aPosition = gl.getAttribLocation(programProgress, 'a_Position');
gl.enableVertexAttribArray(aPosition);
gl.vertexAttribPointer(aPosition, 2, gl.FLOAT, false, vertexFormatLength * 3, 0);
var aProgress = gl.getAttribLocation(programProgress, 'a_Progress');
gl.enableVertexAttribArray(aProgress);
gl.vertexAttribPointer(aProgress, 1, gl.FLOAT, false, vertexFormatLength * 3, vertexFormatLength * 2);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
function tick() {
rafHandle = requestAnimationFrame(() => {
draw();
tick();
if (afterTick) {
afterTick();
afterTick = null;
}
});
}
function end() {
return setProgress(1).then(() => {
cancelAnimationFrame(rafHandle);
gl.useProgram(null);
gl.bindTexture(gl.TEXTURE_2D, null);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.deleteTexture(texture);
gl.deleteBuffer(vertexBuffer);
gl.deleteBuffer(vertexBufferProgress);
gl.deleteProgram(program);
gl.deleteProgram(programProgress);
});
}
function setProgress(val) {
progress = val;
return new Promise((resolve, reject) => {
afterTick = () => {
resolve();
};
});
}
function start(alpha, antialias, useWebgl2) {
options.alpha = alpha === 'true' ? true : false;
options.antialias = antialias === 'false' ? false : true;
if (useWebgl2 === 'true') {
gl = window.canvas.getContext("webgl2", options);
}
// TODO: this is a hack method to detect whether WebGL2RenderingContext is supported
if (gl) {
window.WebGL2RenderingContext = true;
} else {
window.WebGL2RenderingContext = false;
gl = window.canvas.getContext("webgl", options);
}
initVertexBuffer();
initProgressVertexBuffer();
initTexture();
program = initShaders(VS_LOGO, FS_LOGO);
programProgress = initShaders(VS_PROGRESSBAR, FS_PROGRESSBAR);
tick();
return loadImage('splash.png').then(() => {
updateVertexBuffer();
updateTexture();
return setProgress(0);
});
}
module.exports = { start, end, setProgress };
+105
View File
@@ -0,0 +1,105 @@
function __initApp () { // init app
require('./libs/wrapper/builtin/index');
const firstScreen = require('./first-screen');
window.DOMParser = require('./libs/common/xmldom/dom-parser').DOMParser;
window.__globalAdapter = {};
require('./libs/wrapper/unify');
require('./libs/wrapper/fs-utils');
<%- include(cocosTemplate, {}) %>
// Adapt for IOS, swap if opposite
if (canvas){
var _w = canvas.width;
var _h = canvas.height;
if (screen.width < screen.height) {
if (canvas.width > canvas.height) {
_w = canvas.height;
_h = canvas.width;
}
} else {
if (canvas.width < canvas.height) {
_w = canvas.height;
_h = canvas.width;
}
}
canvas.width = _w;
canvas.height = _h;
}
// Adjust initial canvas size
if (canvas && window.devicePixelRatio >= 2) {canvas.width *= 2; canvas.height *= 2;}
const importMap = require("<%= importMapFile%>").default;
System.warmup({
importMap,
importMapUrl: '<%= importMapFile%>',
defaultHandler: (urlNoSchema) => {
require('.' + urlNoSchema);
},
handlers: {
'plugin:': (urlNoSchema) => {
requirePlugin(urlNoSchema);
},
},
});
/**
* Fetch WebAssembly binaries.
*
* Whereas WeChat expects the argument passed to `WebAssembly.instantiate`
* to be file path and the path should be relative from project's root dir,
* we do the path conversion and directly return the converted path.
*
* @param path The path to `.wasm` file **relative from engine's out dir**(no leading `./`).
* See 'assetURLFormat' field of build engine options.
*/
function fetchWasm(path) {
const engineDir = '<%-engineDir%>'; // Relative from project out
return `${engineDir}/${path}`;
}
firstScreen.start('<%= alpha %>', '<%= antialias %>', '<%= useWebgl2 %>').then(() => {
return System.import('<%= applicationJs %>');
}).then((module) => {
return firstScreen.setProgress(0.2).then(() => Promise.resolve(module));
}).then(({ createApplication }) => {
return createApplication({
loadJsListFile: (url) => require(url),
fetchWasm,
});
}).then((application) => {
return firstScreen.setProgress(0.4).then(() => Promise.resolve(application));
}).then((application) => {
return onApplicationCreated(application);
}).catch((err) => {
console.error(err);
});
function onApplicationCreated(application) {
return application.import('cc').then((module) => {
return firstScreen.setProgress(0.6).then(() => Promise.resolve(module));
}).then((cc) => {
require('./libs/common/engine/index.js');
require('./libs/wrapper/engine/index');
require('./libs/common/cache-manager.js');
// Adjust devicePixelRatio
cc.view._maxPixelRatio = 4;
// Release Image objects after uploaded gl texture
cc.macro.CLEANUP_IMAGE_CACHE = false;
return firstScreen.end().then(() => application.start({
findCanvas: () => {
var container = document.createElement('div');
return { frame: container, canvas: window.canvas, container };
},
}));
});
}
} // init app
// NOTE: on WeChat Android end, we can only get the correct screen size at the second tick of game.
var sysInfo = wx.getSystemInfoSync();
if (sysInfo.platform.toLocaleLowerCase() === 'android') {
GameGlobal.requestAnimationFrame (__initApp);
} else {
__initApp();
}
+10
View File
@@ -0,0 +1,10 @@
{
"deviceOrientation": "portrait",
"openDataContext": "",
"networkTimeout": {
"request": 5000,
"connectSocket": 5000,
"uploadFile": 5000,
"downloadFile": 500000
}
}
+3
View File
@@ -0,0 +1,3 @@
{
"_plugin-version": "3.2.2"
}
+35
View File
@@ -0,0 +1,35 @@
{
"description": "项目配置文件。",
"miniprogramRoot": "./",
"setting": {
"urlCheck": true,
"postcss": true,
"minified": true,
"newFeature": false,
"enhance": true,
"useIsolateContext": true
},
"compileType": "game",
"libVersion": "game",
"appid": "",
"projectname": "",
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": [],
"current": -1
},
"miniprogram": {
"current": -1,
"list": []
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

@@ -0,0 +1,8 @@
module.exports = function(api) {
api.cache(true);
return {
presets: ["@babel/preset-env"],
plugins: ["@babel/plugin-transform-modules-commonjs"],
babelrcRoots: [".", "node_modules"]
};
}
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDMTCCAhmgAwIBAgIJAMKpjyszxkDpMA0GCSqGSIb3DQEBCwUAMC4xCzAJBgNV
BAYTAkNOMQwwCgYDVQQKDANSUEsxETAPBgNVBAMMCFJQS0RlYnVnMCAXDTE3MDQx
OTAyMzE0OVoYDzIxMTYwMzI2MDIzMTQ5WjAuMQswCQYDVQQGEwJDTjEMMAoGA1UE
CgwDUlBLMREwDwYDVQQDDAhSUEtEZWJ1ZzCCASIwDQYJKoZIhvcNAQEBBQADggEP
ADCCAQoCggEBAK3kPd9jzvTctTIA3XNZVv9cHHDbAc6nTBfdZp9mtPOTkXFpvyCb
kL0QjOog0+1pv8D7dFeP4ptWXU5CT3ImvaPR+16dAtMRcsxEr5q4zieJzx3O6huL
UBa1k+xrzjXpRzkcOysmc8fTxt0tAwbDgJ2AA5TlXLTcVyb7GmJ+hl5CjnhoG5NN
LrkqI7S29c1U3uokj8Q7hzaj0TURu/uB5ZIMCLZY9KFDugqaEcvmUyJiD0fuV6sA
O/4kpiZUOnhV8/xWpRbMI4WFQsfgLOCV+X9uzUa29D677y//46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MVeUJvewA6/LOBEaqMdwoNwnoptvbR6ehHeE/PPtRtge2cD3bPIM7
U9VlWgfgj9Dxfwhslqb9hmyp
-----END PRIVATE KEY-----
+57
View File
@@ -0,0 +1,57 @@
require('./libs/wrapper/builtin');
window.DOMParser = require('./libs/common/xmldom/dom-parser').DOMParser;
window.__globalAdapter = {};
require('./libs/wrapper/unify');
require('./libs/wrapper/fs-utils');
<% if(polyfillsBundleFile) { %>
// Polyfills bundle.
require("<%= polyfillsBundleFile %>");
<% } %>
// SystemJS support.
require("<%= systemJsBundleFile %>");
// hack for Xiaomi havent screen;
screen = window.screen;
// Adjust initial canvas size
if (canvas && window.devicePixelRatio >= 2) {canvas.width *= 2; canvas.height *= 2;}
const importMap = require("./<%= importMapFile%>").default;
System.warmup({
importMap,
importMapUrl: '<%= importMapFile%>',
defaultHandler: (urlNoSchema) => {
require('.' + urlNoSchema);
},
});
System.import('<%= applicationJs %>').then(({ createApplication }) => {
return createApplication({
loadJsListFile: (url) => require(`./${url}`),
fetchWasm: (url) => url,
});
}).then((application) => {
return onApplicationCreated(application);
}).catch((err) => {
console.error(err);
});
function onApplicationCreated(application) {
return application.import('cc').then((cc) => {
require('./libs/common/engine/index.js');
require('./libs/wrapper/engine/index');
require('./libs/common/cache-manager.js');
// Adjust devicePixelRatio
cc.view._maxPixelRatio = 4;
// Release Image objects after uploaded gl texture
cc.macro.CLEANUP_IMAGE_CACHE = false;
return application.start({
findCanvas: () => {
var container = document.createElement('div');
return { frame: container, canvas: window.canvas, container };
},
});
});
}
+21
View File
@@ -0,0 +1,21 @@
{
"name": "xiaomi-adapter",
"version": "1.0.0",
"build-template": "xiaomigame",
"scripts": {
"build": "quickgame build --cocos-wx-game --include-file-ext .pem,.pkm,.webp,.astc",
"build-ignore-res": "quickgame build --cocos-wx-game --include-file-ext .pem,.pkm,.webp,.astc --ignore remote,res",
"release": "quickgame release --cocos-wx-game --include-file-ext .pem,.pkm,.webp,.astc",
"release-ignore-res": "quickgame release --cocos-wx-game --include-file-ext .pem,.pkm,.webp,.astc --ignore remote,res",
"server": "quickgame server",
"debug": "quickgame debug"
},
"babel": {
"plugins": [
"babel-plugin-transform-remove-strict-mode"
]
},
"dependencies": {
"quickgame-cli": "^0.1.19"
}
}