From 11890d6c4b68dc035182f43130eb4e0065c0e8d0 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sun, 18 Oct 2015 00:19:02 +0800 Subject: [PATCH 1/2] Fix issue for web engine upgrade --- cocos/scripting/js-bindings/manual/ScriptingCore.cpp | 2 +- tests/js-tests/src/tests_resources.js | 1 + web | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index 03a0be87c5..99ecec5fad 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -757,7 +757,7 @@ bool ScriptingCore::runScript(const char *path, JS::HandleObject global, JSConte JSAutoCompartment ac(cx, global); evaluatedOK = JS_ExecuteScript(cx, global, script, &rval); if (false == evaluatedOK) { - cocos2d::log("(evaluatedOK == JS_FALSE)"); + cocos2d::log("Evaluating %s failed (evaluatedOK == JS_FALSE)", path); JS_ReportPendingException(cx); } } diff --git a/tests/js-tests/src/tests_resources.js b/tests/js-tests/src/tests_resources.js index 2ad096ee25..b41f7d1e6f 100644 --- a/tests/js-tests/src/tests_resources.js +++ b/tests/js-tests/src/tests_resources.js @@ -6,6 +6,7 @@ var ccbjs = ""; // so the respath will modify to res, if (!cc.sys.isNative) { + cc.game._loadConfig(); if (cc.game.config[cc.game.CONFIG_KEY.engineDir] !== "frameworks/cocos2d-html5") { ccbjs = "../../js-tests/resjs/"; } diff --git a/web b/web index a9f493ae53..6e3797aac9 160000 --- a/web +++ b/web @@ -1 +1 @@ -Subproject commit a9f493ae53d20945d8796660363da4e060a68ee2 +Subproject commit 6e3797aac97c2dd772fda54996c5677f1acb65bc From cfb1ee2b1163c979b2ad96a8099a2887520fbe7a Mon Sep 17 00:00:00 2001 From: pandamicro Date: Sun, 18 Oct 2015 22:45:53 +0800 Subject: [PATCH 2/2] Improved logic of jsb_boot.js to sync with the web engine behavior --- .../scripting/js-bindings/script/jsb_boot.js | 117 +++++++++++++----- 1 file changed, 88 insertions(+), 29 deletions(-) diff --git a/cocos/scripting/js-bindings/script/jsb_boot.js b/cocos/scripting/js-bindings/script/jsb_boot.js index 11daaaa1c4..c946fc8df1 100644 --- a/cocos/scripting/js-bindings/script/jsb_boot.js +++ b/cocos/scripting/js-bindings/script/jsb_boot.js @@ -1054,6 +1054,15 @@ var _initSys = function () { */ sys.LANGUAGE_POLISH = "pl"; + /** + * Unknown language code + * @memberof cc.sys + * @name LANGUAGE_UNKNOWN + * @constant + * @type {Number} + */ + sys.LANGUAGE_UNKNOWN = "unkonwn"; + /** * @memberof cc.sys * @name OS_IOS @@ -1575,11 +1584,12 @@ cc.game = /** @lends cc.game# */{ jsList: "jsList" }, + // states + _paused: false,//whether the game is paused _prepareCalled: false,//whether the prepare function has been called _prepared: false,//whether the engine has prepared - _paused: true,//whether the game is paused + _intervalId: null,//interval target of main - /** * Config of game @@ -1599,6 +1609,9 @@ cc.game = /** @lends cc.game# */{ */ onStop: null, +//@Public Methods + +// @Game play control /** * Set frameRate of game. * @param frameRate @@ -1620,6 +1633,7 @@ cc.game = /** @lends cc.game# */{ * Pause the game. */ pause: function () { + this._paused = true; cc.director.pause(); }, @@ -1627,9 +1641,17 @@ cc.game = /** @lends cc.game# */{ * Resume the game from pause. */ resume: function () { + this._paused = false; cc.director.resume(); }, + /** + * Check whether the game is paused. + */ + isPaused: function () { + return this._paused; + }, + /** * Restart game. */ @@ -1637,6 +1659,7 @@ cc.game = /** @lends cc.game# */{ __restartVM(); }, +// @Game loading /** * Prepare game. * @param cb @@ -1662,12 +1685,17 @@ cc.game = /** @lends cc.game# */{ this._prepareCalled = true; // Load game scripts - var jsList = config[CONFIG_KEY.jsList] || []; - cc.loader.loadJsWithImg("", jsList, function (err) { - if (err) throw new Error(err); - self._prepared = true; + var jsList = config[CONFIG_KEY.jsList]; + if (jsList) { + cc.loader.loadJsWithImg(jsList, function (err) { + if (err) throw new Error(err); + self._prepared = true; + if (cb) cb(); + }); + } + else { if (cb) cb(); - }); + } return; } @@ -1679,30 +1707,61 @@ cc.game = /** @lends cc.game# */{ }, /** - * Run game. + * Run game with configuration object and onStart function. + * @param {Object|Function} [config] Pass configuration object or onStart function + * @param {onStart} [onStart] onStart function to be executed after game initialized */ - run: function () { - this.prepare(cc.game.onStart.bind(cc.game)); - }, - - _loadConfig: function () { - var self = this, CONFIG_KEY = self.CONFIG_KEY; - var _init = function(cfg){ - cfg[CONFIG_KEY.engineDir] = cfg[CONFIG_KEY.engineDir] || "frameworks/cocos2d-html5"; - cfg[CONFIG_KEY.debugMode] = cfg[CONFIG_KEY.debugMode] || 0; - cfg[CONFIG_KEY.frameRate] = cfg[CONFIG_KEY.frameRate] || 60; - cfg[CONFIG_KEY.renderMode] = cfg[CONFIG_KEY.renderMode] || 0; - cfg[CONFIG_KEY.showFPS] = cfg[CONFIG_KEY.showFPS] === false ? false : true; - return cfg; - }; - try{ - var txt = jsb.fileUtils.getStringFromFile("project.json"); - var data = JSON.parse(txt); - this.config = _init(data || {}); - }catch(e){ - cc.log("Failed to read or parse project.json"); - this.config = _init({}); + run: function (config, onStart) { + if (typeof config === 'function') { + cc.game.onStart = config; } + else { + if (config) { + cc.game.config = config; + } + if (typeof onStart === 'function') { + cc.game.onStart = onStart; + } + } + + this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game)); + }, + +//@Private Methods + + _loadConfig: function () { + // Load config + // Already loaded + if (this.config) { + this._initConfig(this.config); + } + // Load from project.json + else { + try { + var txt = jsb.fileUtils.getStringFromFile("project.json"); + var data = JSON.parse(txt); + this._initConfig(data || {}); + } catch (e) { + console.log("Failed to read or parse project.json"); + this._initConfig({}); + } + } + }, + + _initConfig: function (config) { + var CONFIG_KEY = this.CONFIG_KEY; + + // Configs adjustment + config[CONFIG_KEY.showFPS] = config[CONFIG_KEY.showFPS] || true; + config[CONFIG_KEY.engineDir] = config[CONFIG_KEY.engineDir] || "frameworks/cocos2d-html5"; + if (config[CONFIG_KEY.debugMode] == null) + config[CONFIG_KEY.debugMode] = 0; + config[CONFIG_KEY.frameRate] = config[CONFIG_KEY.frameRate] || 60; + if (config[CONFIG_KEY.renderMode] == null) + config[CONFIG_KEY.renderMode] = 0; + + this.config = config; + cc.director.setDisplayStats(this.config[CONFIG_KEY.showFPS]); cc.director.setAnimationInterval(1.0/this.config[CONFIG_KEY.frameRate]); }