Skip to content

Commit

Permalink
Merge 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jareguo committed Jan 9, 2018
2 parents 1204fa7 + df36e5d commit b31566d
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 68 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
node:
version: 5.8.0
version: 6.12.3

dependencies:
pre:
Expand Down
5 changes: 5 additions & 0 deletions cocos2d/core/CCGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,11 @@ var game = {
win.onfocus = onShown;
}

if (CC_WECHATGAME) {
wx.onShow = onShow;
wx.onHide = onHidden;
}

if ("onpageshow" in window && "onpagehide" in window) {
win.addEventListener("pagehide", onHidden);
win.addEventListener("pageshow", onShown);
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/assets/CCPrefab.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var Prefab = cc.Class({

_instantiate: function () {
var node, useJit = false;
if (cc.supportJit) {
if (CC_SUPPORT_JIT) {
if (this.optimizationPolicy === OptimizationPolicy.SINGLE_INSTANCE) {
useJit = false;
}
Expand Down
7 changes: 3 additions & 4 deletions cocos2d/core/component-scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ var callUpdateInTryCatch = CC_EDITOR && callerFunctor('update', 'dt');
var callLateUpdateInTryCatch = CC_EDITOR && callerFunctor('lateUpdate', 'dt');
var callOnDisableInTryCatch = CC_EDITOR && callerFunctor('onDisable');

var supportJit = cc.supportJit;
var callStart = supportJit ? 'c.start();c._objFlags|=' + IsStartCalled : function (c) {
var callStart = CC_SUPPORT_JIT ? 'c.start();c._objFlags|=' + IsStartCalled : function (c) {
c.start();
c._objFlags |= IsStartCalled;
};
var callUpdate = supportJit ? 'c.update(dt)' : function (c, dt) {
var callUpdate = CC_SUPPORT_JIT ? 'c.update(dt)' : function (c, dt) {
c.update(dt);
};
var callLateUpdate = supportJit ? 'c.lateUpdate(dt)' : function (c, dt) {
var callLateUpdate = CC_SUPPORT_JIT ? 'c.lateUpdate(dt)' : function (c, dt) {
c.lateUpdate(dt);
};

Expand Down
7 changes: 3 additions & 4 deletions cocos2d/core/node-activator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ var callResetInTryCatch = CC_EDITOR && callerFunctor('resetInEditor');
var callOnFocusInTryCatch = CC_EDITOR && callerFunctor('onFocusInEditor');
var callOnLostFocusInTryCatch = CC_EDITOR && callerFunctor('onLostFocusInEditor');

var supportJit = cc.supportJit;
var callPreload = supportJit ? 'c.__preload();' : function (c) { c.__preload(); }
var callOnLoad = supportJit ? ('c.onLoad();c._objFlags|=' + IsOnLoadCalled) : function (c) {
var callPreload = CC_SUPPORT_JIT ? 'c.__preload();' : function (c) { c.__preload(); };
var callOnLoad = CC_SUPPORT_JIT ? ('c.onLoad();c._objFlags|=' + IsOnLoadCalled) : function (c) {
c.onLoad();
c._objFlags |= IsOnLoadCalled;
}
};

// for __preload: use internally, no sort
var UnsortedInvoker = cc.Class({
Expand Down
14 changes: 7 additions & 7 deletions cocos2d/core/platform/CCClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,15 @@ function compileProps (actualClass) {
}

// Overwite __initProps__ to avoid compile again.
var initProps = cc.supportJit ? getInitPropsJit(attrs, propList) : getInitProps(attrs, propList);
var initProps = CC_SUPPORT_JIT ? getInitPropsJit(attrs, propList) : getInitProps(attrs, propList);
actualClass.prototype.__initProps__ = initProps;

// call instantiateProps immediately, no need to pass actualClass into it anymore
// (use call to manually bind `this` because `this` may not instanceof actualClass)
initProps.call(this);
}

var _createCtor = cc.supportJit ? function (ctors, baseClass, className, options) {
var _createCtor = CC_SUPPORT_JIT ? function (ctors, baseClass, className, options) {
var superCallBounded = baseClass && boundSuperCalls(baseClass, options, className);

var ctorName = CC_DEV ? normalizeClassName_DEV(className) : 'CCClass';
Expand Down Expand Up @@ -633,8 +633,8 @@ var _createCtor = cc.supportJit ? function (ctors, baseClass, className, options
cs[0].apply(this, arguments);
}
else {
for (var i = 0; i < ctorLen; i++) {
cs[i].apply(this, arguments);;
for (let i = 0; i < ctorLen; i++) {
cs[i].apply(this, arguments);
}
}
}
Expand All @@ -647,8 +647,8 @@ var _createCtor = cc.supportJit ? function (ctors, baseClass, className, options
cs[0].apply(this, arguments);
}
else {
for (var i = 0; i < ctorLen; i++) {
cs[i].apply(this, arguments);;
for (let i = 0; i < ctorLen; i++) {
cs[i].apply(this, arguments);
}
}
}
Expand Down Expand Up @@ -832,7 +832,7 @@ function declareProperties (cls, className, properties, baseClass, mixins, es6)
* @param {String} [options.name] - The class name used for serialization.
* @param {Function} [options.extends] - The base class.
* @param {Function} [options.ctor] - The constructor.
* @param {Function} [options.&#95;&#95;ctor&#95;&#95;] - The same as ctor, but less encapsulated.
* @param {Function} [options.__ctor__] - The same as ctor, but less encapsulated.
* @param {Object} [options.properties] - The property definitions.
* @param {Object} [options.statics] - The static members.
* @param {Function[]} [options.mixins]
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/platform/CCObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function compileDestruct (obj, ctor) {
// compile code
var skipId = obj instanceof cc._BaseNode || obj instanceof cc.Component;

if (cc.supportJit) {
if (CC_SUPPORT_JIT) {
var func = '';
for (key in propsToReset) {
if (skipId && key === '_id') {
Expand Down
9 changes: 3 additions & 6 deletions cocos2d/core/platform/CCSys.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,6 @@ sys.BROWSER_TYPE_SOUGOU = "sogou";
*/
sys.BROWSER_TYPE_UNKNOWN = "unknown";

function isWeChatGame () {
return window['wx'];
}

/**
* Is native ? This is set to be true in jsb auto.
Expand All @@ -503,7 +500,7 @@ sys.isNative = false;
* Is web browser ?
* @property {Boolean} isBrowser
*/
sys.isBrowser = typeof window === 'object' && typeof document === 'object' && !isWeChatGame();
sys.isBrowser = typeof window === 'object' && typeof document === 'object' && !CC_WECHATGAME;

cc.create3DContext = function (canvas, opt_attribs, opt_contextType) {
if (opt_contextType) {
Expand Down Expand Up @@ -539,7 +536,7 @@ if (CC_EDITOR && Editor.isMainProcess) {
};
sys.__audioSupport = {};
}
else if (isWeChatGame()) {
else if (CC_WECHATGAME) {
var env = wx.getSystemInfoSync();
sys.isMobile = true;
sys.platform = sys.WECHAT_GAME;
Expand Down Expand Up @@ -667,7 +664,7 @@ else {
var browserTypes = typeReg1.exec(ua);
if(!browserTypes) browserTypes = typeReg2.exec(ua);
var browserType = browserTypes ? browserTypes[0].toLowerCase() : sys.BROWSER_TYPE_UNKNOWN;
if (isWeChatGame())
if (CC_WECHATGAME)
browserType = sys.BROWSER_TYPE_WECHAT_GAME;
else if (browserType === 'micromessenger')
browserType = sys.BROWSER_TYPE_WECHAT;
Expand Down
6 changes: 1 addition & 5 deletions cocos2d/core/platform/CCView.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
****************************************************************************/
var eventManager = require('../event-manager');

function isWeChatGame () {
return window['wx'];
}

var __BrowserGetter = {
init: function(){
if (cc.sys.platform !== cc.sys.WECHAT_GAME) {
Expand Down Expand Up @@ -59,7 +55,7 @@ if (window.navigator.userAgent.indexOf("OS 8_1_") > -1) //this mistake like MIUI
if (cc.sys.os === cc.sys.OS_IOS) // All browsers are WebView
__BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_SAFARI;

if (isWeChatGame()) {
if (CC_WECHATGAME) {
__BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_WECHAT_GAME;
}

Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/platform/_CCClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Class.extend = function (props) {

// The dummy Class constructor
var TheClass;
if (cc.supportJit && cc.game && cc.game.config && cc.game.config[cc.game.CONFIG_KEY.exposeClassName]) {
if (CC_SUPPORT_JIT && cc.game && cc.game.config && cc.game.config[cc.game.CONFIG_KEY.exposeClassName]) {
var ctor =
"return (function " + (props._className || "Class") + "(arg0,arg1,arg2,arg3,arg4) {\n" +
"this.__instanceId = cc.ClassManager.getNewInstanceId();\n" +
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/platform/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const DELIMETER = '$_$';

function createAttrsSingle (owner, ownerCtor, superAttrs) {
var AttrsCtor;
if (CC_DEV && cc.supportJit) {
if (CC_DEV && CC_SUPPORT_JIT) {
var ctorName = ownerCtor.name;
if (owner === ownerCtor) {
ctorName += '_ATTRS';
Expand Down
4 changes: 2 additions & 2 deletions cocos2d/core/platform/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ var _Deserializer = (function () {
}
};

var compileObjectType = cc.supportJit ? function (sources, defaultValue, accessorToSet, propNameLiteralToSet, assumeHavePropIfIsValue, stillUseUrl) {
var compileObjectType = CC_SUPPORT_JIT ? function (sources, defaultValue, accessorToSet, propNameLiteralToSet, assumeHavePropIfIsValue, stillUseUrl) {
if (defaultValue instanceof cc.ValueType) {
// fast case
if (!assumeHavePropIfIsValue) {
Expand Down Expand Up @@ -484,7 +484,7 @@ var _Deserializer = (function () {
}
};

var compileDeserialize = cc.supportJit ? function (self, klass) {
var compileDeserialize = CC_SUPPORT_JIT ? function (self, klass) {
var EDITOR_ONLY = Attr.DELIMETER + 'editorOnly';
var SERIALIZABLE = Attr.DELIMETER + 'serializable';
var DEFAULT = Attr.DELIMETER + 'default';
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/utils/prefab-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = {

// instantiate prefab
cc.game._isCloning = true;
if (cc.supportJit) {
if (CC_SUPPORT_JIT) {
_prefab.asset._doInstantiate(node);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ if (CC_DEV) {
});

function deprecateEnum (obj, oldPath, newPath, hasTypePrefixBefore) {
if (!cc.supportJit) {
if (!CC_SUPPORT_JIT) {
return;
}
hasTypePrefixBefore = hasTypePrefixBefore !== false;
Expand Down
52 changes: 40 additions & 12 deletions gulp/tasks/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ var jsbSkipModules = [
'../../cocos2d/core/CCDrawingPrimitives.js',
// '../../cocos2d/core/textures/CCTexture2D',
// '../../cocos2d/core/sprites/CCSpriteFrame',
'../../cocos2d/core/event-manager/CCTouch.js',
'../../cocos2d/core/event-manager/CCEventListener.js',
'../../cocos2d/core/event-manager/CCEventManager.js',
'../../cocos2d/core/load-pipeline/audio-downloader',
'../../cocos2d/core/physics/platform/CCPhysicsDebugDraw.js',
'../../cocos2d/core/physics/platform/CCPhysicsUtils.js',
'../../cocos2d/core/physics/platform/CCPhysicsContactListner.js',
'../../cocos2d/core/physics/platform/CCPhysicsAABBQueryCallback.js',
'../../cocos2d/core/physics/platform/CCPhysicsRayCastCallback.js',
'../../cocos2d/core/physics/platform/CCPhysicsContactListner.js',
'../../cocos2d/core/platform/CCInputManager.js',
'../../cocos2d/core/platform/CCVisibleRect.js',
'../../cocos2d/core/camera/CCSGCameraNode.js',
'../../cocos2d/core/label/CCSGLabel.js',
'../../cocos2d/core/label/CCSGLabelCanvasRenderCmd.js',
Expand All @@ -61,6 +66,7 @@ var jsbSkipModules = [
'../../cocos2d/core/graphics/graphics-canvas-cmd.js',
'../../cocos2d/core/graphics/earcut.js',
'../../cocos2d/core/graphics/helper.js',
'../../cocos2d/actions/index.js',
'../../cocos2d/audio/CCAudio',
'../../cocos2d/shape-nodes/CCDrawNode.js',
'../../cocos2d/clipping-nodes/CCClippingNode.js',
Expand All @@ -81,20 +87,27 @@ var jsbSkipModules = [
'../../cocos2d/render-texture/CCRenderTexture.js',
'../../cocos2d/render-texture/CCRenderTextureCanvasRenderCmd.js',
'../../cocos2d/render-texture/CCRenderTextureWebGLRenderCmd.js',
'../../extensions/spine/SGSkeletonTexture',
'../../extensions/spine/SGSkeleton',
'../../extensions/spine/SGSkeletonAnimation',
'../../extensions/spine/SGSkeletonCanvasRenderCmd',
'../../extensions/spine/SGSkeletonWebGLRenderCmd',
'../../extensions/spine/lib/spine',
'../../extensions/dragonbones/lib/dragonBones',
'../../extensions/dragonbones/CCFactory',
'../../extensions/dragonbones/CCArmatureDisplay',
'../../extensions/dragonbones/CCSlot',
'../../extensions/dragonbones/CCTextureData',
'../../extensions/dragonbones/CCArmatureDisplay',
'../../external/box2d/box2d.js',
'../../external/chipmunk/chipmunk.js',
];

exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) {
exports.buildCocosJs = function (sourceFile, outputFile, excludes, opt_macroFlags, callback) {
if (typeof opt_macroFlags === 'function') {
callback = opt_macroFlags;
opt_macroFlags = null;
}

var outDir = Path.dirname(outputFile);
var outFile = Path.basename(outputFile);
var bundler = createBundler(sourceFile);
Expand All @@ -107,7 +120,7 @@ exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) {
bundler = bundler.pipe(Source(outFile));
bundler = bundler.pipe(Buffer());
bundler = bundler.pipe(Sourcemaps.init({loadMaps: true}));
bundler = bundler.pipe(Utils.uglify('build', false, true));
bundler = bundler.pipe(Utils.uglify('build', Object.assign({ debug: true }, opt_macroFlags)));
bundler = bundler.pipe(Optimizejs({
sourceMap: false
}));
Expand All @@ -120,7 +133,12 @@ exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) {
return bundler.on('end', callback);
};

exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, callback, createMap) {
exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, opt_macroFlags, callback, createMap) {
if (typeof opt_macroFlags === 'function') {
callback = opt_macroFlags;
opt_macroFlags = null;
}

var outDir = Path.dirname(outputFile);
var outFile = Path.basename(outputFile);
var bundler = createBundler(sourceFile);
Expand Down Expand Up @@ -148,7 +166,7 @@ exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, callback,
console.error('Can not use sourcemap with optimize-js');
bundler = bundler.pipe(Sourcemaps.init({loadMaps: true}));
}
bundler = bundler.pipe(Utils.uglify('build', false, false));
bundler = bundler.pipe(Utils.uglify('build', opt_macroFlags));
bundler = bundler.pipe(Optimizejs({
sourceMap: false
}));
Expand Down Expand Up @@ -193,7 +211,7 @@ exports.buildPreview = function (sourceFile, outputFile, callback, devMode) {
if (!devMode) {
bundler = bundler
.pipe(Sourcemaps.init({loadMaps: true}))
.pipe(Utils.uglify('preview', false, false))
.pipe(Utils.uglify('preview'))
.pipe(Optimizejs({
sourceMap: false
}))
Expand Down Expand Up @@ -228,15 +246,20 @@ exports.buildJsbPreview = function (sourceFile, outputFile, excludes, callback)
.pipe(Source(outFile))
.pipe(Buffer())
.pipe(FixJavaScriptCore())
.pipe(Utils.uglify('preview', true, false))
.pipe(Utils.uglify('preview', { jsb: true }))
.pipe(Optimizejs({
sourceMap: false
}))
.pipe(Gulp.dest(outDir))
.on('end', callback);
};

exports.buildJsb = function (sourceFile, outputFile, excludes, callback) {
exports.buildJsb = function (sourceFile, outputFile, excludes, opt_macroFlags, callback) {
if (typeof opt_macroFlags === 'function') {
callback = opt_macroFlags;
opt_macroFlags = null;
}

var FixJavaScriptCore = require('../util/fix-jsb-javascriptcore');

var outFile = Path.basename(outputFile);
Expand All @@ -254,15 +277,20 @@ exports.buildJsb = function (sourceFile, outputFile, excludes, callback) {
.pipe(Source(outFile))
.pipe(Buffer())
.pipe(FixJavaScriptCore())
.pipe(Utils.uglify('build', true, true))
.pipe(Utils.uglify('build', Object.assign({ jsb: true, debug: true }, opt_macroFlags)))
.pipe(Optimizejs({
sourceMap: false
}))
.pipe(Gulp.dest(outDir))
.on('end', callback);
};

exports.buildJsbMin = function (sourceFile, outputFile, excludes, callback) {
exports.buildJsbMin = function (sourceFile, outputFile, excludes, opt_macroFlags, callback) {
if (typeof opt_macroFlags === 'function') {
callback = opt_macroFlags;
opt_macroFlags = null;
}

var FixJavaScriptCore = require('../util/fix-jsb-javascriptcore');

var outFile = Path.basename(outputFile);
Expand All @@ -280,7 +308,7 @@ exports.buildJsbMin = function (sourceFile, outputFile, excludes, callback) {
.pipe(Source(outFile))
.pipe(Buffer())
.pipe(FixJavaScriptCore())
.pipe(Utils.uglify('build', true, false))
.pipe(Utils.uglify('build', Object.assign({ jsb: true }, opt_macroFlags)))
.pipe(Optimizejs({
sourceMap: false
}))
Expand Down
2 changes: 1 addition & 1 deletion gulp/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ exports.build = function (sourceFile, outputFile, sourceFileForExtends, outputFi
}

// remove `...args` used in CC_JSB
engine = engine.pipe(Utils.uglify('test', false, false));
engine = engine.pipe(Utils.uglify('test'));

if (sourcemaps) {
engine = engine.pipe(Sourcemaps.write('./', {
Expand Down
Loading

0 comments on commit b31566d

Please sign in to comment.