Skip to content

Commit

Permalink
Merge pull request cocos2d#12 from pandamicro/develop
Browse files Browse the repository at this point in the history
Update 3.0 from develop
  • Loading branch information
pandamicro committed Jan 25, 2014
2 parents cf78b57 + 508816f commit 2a8b375
Show file tree
Hide file tree
Showing 37 changed files with 861 additions and 369 deletions.
2 changes: 0 additions & 2 deletions HelloHTML5World/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<file name="core/platform/CCEGLView.js"/>
<file name="core/platform/CCScreen.js"/>
<file name="core/platform/CCVisibleRect.js"/>
<file name="core/cocoa/CCNS.js"/>
<file name="core/cocoa/CCAffineTransform.js"/>
<file name="core/support/CCPointExtension.js"/>
<file name="core/support/CCVertex.js"/>
Expand Down Expand Up @@ -98,7 +97,6 @@
<file name="compress/base64.js"/>
<file name="compress/gzip.js"/>
<file name="compress/zlib.min.js"/>
<file name="particle_nodes/CCFormatHelper.js"/>
<file name="particle_nodes/CCPNGReader.js"/>
<file name="particle_nodes/CCTIFFReader.js"/>
<file name="particle_nodes/CCParticleSystem.js"/>
Expand Down
5 changes: 3 additions & 2 deletions HelloHTML5World/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ var cocos2dApp = cc.Application.extend({
alert("Browser doesn't support WebGL");
return false;
}
// initialize director
var director = cc.Director.getInstance();

cc.EGLView.getInstance().resizeWithBrowserSize(true);
cc.EGLView.getInstance().setDesignResolutionSize(800, 450, cc.RESOLUTION_POLICY.SHOW_ALL);

// initialize director
var director = cc.Director.getInstance();

// turn on display FPS
director.setDisplayStats(this.config['showFPS']);

Expand Down
2 changes: 1 addition & 1 deletion cocos2d/actions/CCAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ cc.Action = cc.Class.extend(/** @lends cc.Action# */{
* @return {object}
*/
copy:function () {
return cc.clone(this);
return this.clone();
},

/**
Expand Down
126 changes: 123 additions & 3 deletions cocos2d/audio/SimpleAudioEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
_effectsVolume:1, // the volume applied to all effects
_playingMusic:null, // the music being played, when null, no music is being played; when not null, it may be playing or paused
_resPath : "", //root path for resources
_pausedPlayings: null,

ctor:function(){
this._audioIDList = {};
this._supportedFormat = [];
this._pausedPlayings = [];
},

/**
Expand Down Expand Up @@ -642,6 +644,55 @@ cc.SimpleAudioEngine = cc.AudioEngine.extend(/** @lends cc.SimpleAudioEngine# */
locEffectList[elt] = [];
return locEffectList[elt];
}
},

_pausePlaying: function(){
var locPausedPlayings = this._pausedPlayings, locSoundList = this._soundList;
var tmpArr, au;
if (!this._musicIsStopped && locSoundList.hasOwnProperty(this._playingMusic)) {
au = locSoundList[this._playingMusic].audio;
if (!au.paused) {
au.pause();
cc.AudioEngine.isMusicPlaying = false;
locPausedPlayings.push(au);
}
}

var locEffectList = this._effectList;
for (var selKey in locEffectList) {
tmpArr = locEffectList[selKey];
for (var j = 0; j < tmpArr.length; j++) {
au = tmpArr[j];
if (!au.ended && !au.paused) {
au.pause();
locPausedPlayings.push(au);
}
}
}
},

_resumePlaying: function(){
var locPausedPlayings = this._pausedPlayings, locSoundList = this._soundList;
var tmpArr, au;
if (!this._musicIsStopped && locSoundList.hasOwnProperty(this._playingMusic)) {
au = locSoundList[this._playingMusic].audio;
if (locPausedPlayings.indexOf(au) !== -1) {
au.play();
au.addEventListener("pause", this._musicListenerBound, false);
cc.AudioEngine.isMusicPlaying = true;
}
}

var locEffectList = this._effectList;
for (var selKey in locEffectList) {
tmpArr = locEffectList[selKey];
for (var j = 0; j < tmpArr.length; j++) {
au = tmpArr[j];
if (!au.ended && locPausedPlayings.indexOf(au) !== -1)
au.play();
}
}
locPausedPlayings.length = 0;
}
});

Expand Down Expand Up @@ -1102,6 +1153,32 @@ cc.SimpleAudioEngineForMobile = cc.SimpleAudioEngine.extend({
this._isPauseForList = false;
this.resumeMusic();
}
},

_pausePlaying: function(){
var locPausedPlayings = this._pausedPlayings, locSoundList = this._soundList, au;
if (!this._musicIsStopped && locSoundList.hasOwnProperty(this._playingMusic)) {
au = locSoundList[this._playingMusic].audio;
if (!au.paused) {
au.pause();
cc.AudioEngine.isMusicPlaying = false;
locPausedPlayings.push(au);
}
}
this.stopAllEffects();
},

_resumePlaying: function(){
var locPausedPlayings = this._pausedPlayings, locSoundList = this._soundList, au;
if (!this._musicIsStopped && locSoundList.hasOwnProperty(this._playingMusic)) {
au = locSoundList[this._playingMusic].audio;
if (locPausedPlayings.indexOf(au) !== -1) {
au.play();
au.addEventListener("pause", this._musicListenerBound, false);
cc.AudioEngine.isMusicPlaying = true;
}
}
locPausedPlayings.length = 0;
}
});

Expand Down Expand Up @@ -1414,6 +1491,8 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{
* @private
*/
_endSound: function(sfxCache) {
if (sfxCache.sourceNode.playbackState && sfxCache.sourceNode.playbackState == 3)
return;
if (sfxCache.sourceNode.stop) {
sfxCache.sourceNode.stop(0);
} else {
Expand Down Expand Up @@ -1823,6 +1902,48 @@ cc.WebAudioEngine = cc.AudioEngine.extend(/** @lends cc.WebAudioEngine# */{

if (keyName in this._audioData)
delete this._audioData[keyName];
},

_pausePlaying: function(){
var locPausedPlayings = this._pausedPlayings;
if (this.isMusicPlaying()){
locPausedPlayings.push(this._playingMusic);
this._pauseSound(this._playingMusic);
}

var locEffects = this._effects;
for (var selKey in locEffects) {
var selEffectList = locEffects[selKey];
for (var idx = 0, len = selEffectList.length; idx < len; idx++) {
var sfxCache = selEffectList[idx];
if (sfxCache && this._isSoundPlaying(sfxCache)) {
locPausedPlayings.push(sfxCache);
this._pauseSound(sfxCache);
}
}
}
},

_resumePlaying: function(){
var locPausedPlayings = this._pausedPlayings, locVolume = this.getMusicVolume();

var locMusic = this._playingMusic;
// can resume only when it's paused
if (locMusic && this._isSoundPaused(locMusic) && locPausedPlayings.indexOf(locMusic) != -1)
this._playingMusic = this._resumeSound(locMusic, locVolume);

var locEffects = this._effects;
for (var selKey in locEffects){
var selEffects = locEffects[selKey];
for (var idx = 0, len = selEffects.length; idx < len; idx++) {
var sfxCache = selEffects[idx];
if (this._isSoundPaused(sfxCache) &&locPausedPlayings.indexOf(sfxCache) != -1) {
selEffects[idx] = this._resumeSound(sfxCache, locVolume);
this._updateEffectsList(sfxCache, selEffects[idx]);
}
}
}
locPausedPlayings.length = 0;
}
});

Expand All @@ -1836,11 +1957,10 @@ cc.AudioEngine.isMusicPlaying = false;
*/
cc.AudioEngine.getInstance = function () {
if (!this._instance) {
var ua = navigator.userAgent;
if (cc.Browser.supportWebAudio && !(/iPhone OS/.test(ua)||/iPad/.test(ua))) {
if (cc.Browser.supportWebAudio) {
this._instance = new cc.WebAudioEngine();
} else {
if(cc.Browser.isMobile) // TODO construct a supported list for mobile browser
if (cc.Browser.isMobile) // TODO construct a supported list for mobile browser
this._instance = new cc.SimpleAudioEngineForMobile();
else
this._instance = new cc.SimpleAudioEngine();
Expand Down
2 changes: 0 additions & 2 deletions cocos2d/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<file name="core/platform/CCEGLView.js"/>
<file name="core/platform/CCScreen.js"/>
<file name="core/platform/CCVisibleRect.js"/>
<file name="core/cocoa/CCNS.js"/>
<file name="core/cocoa/CCAffineTransform.js"/>
<file name="core/support/CCPointExtension.js"/>
<file name="core/support/CCVertex.js"/>
Expand Down Expand Up @@ -98,7 +97,6 @@
<file name="compress/base64.js"/>
<file name="compress/gzip.js"/>
<file name="compress/zlib.min.js"/>
<file name="particle_nodes/CCFormatHelper.js"/>
<file name="particle_nodes/CCPNGReader.js"/>
<file name="particle_nodes/CCTIFFReader.js"/>
<file name="particle_nodes/CCParticleSystem.js"/>
Expand Down
42 changes: 30 additions & 12 deletions cocos2d/core/cocoa/CCGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@
//--------------------------------------------------------
/**
* @class
* @param {Number} _x
* @param {Number|cc.Point} _x
* @param {Number} _y
* Constructor
*/
cc.Point = function (_x, _y) {
this.x = _x || 0;
this.y = _y || 0;
if(arguments.length === 1){
this.x = _x.x;
this.y = _x.y;
} else {
this.x = _x || 0;
this.y = _y || 0;
}
};

cc._PointConst = function (x, y) {
Expand Down Expand Up @@ -83,6 +88,7 @@ Object.defineProperties(cc._PointConst.prototype, {
* @param {Number} x
* @param {Number} y
* @return {cc.Point}
* @deprecated
*/
cc.PointMake = function (x, y) {
cc.log("cc.PointMake will be deprecated sooner or later. Use cc.p instead.");
Expand All @@ -91,17 +97,20 @@ cc.PointMake = function (x, y) {

/**
* Helper macro that creates a cc.Point.
* @param {Number} x
* @param {Number|cc.Point} x
* @param {Number} y
*/
cc.p = function (x, y) {
// This can actually make use of "hidden classes" in JITs and thus decrease
// memory usage and overall performance drastically
//return new cc.Point(x, y);
// return new cc.Point(x, y);
// but this one will instead flood the heap with newly allocated hash maps
// giving little room for optimization by the JIT,
// note: we have tested this item on Chrome and firefox, it is faster than new cc.Point(x, y)
return {x: x, y: y};
if(arguments.length === 1)
return {x: x.x, y: x.y};
else
return {x: x || 0, y: y || 0};
};

// JSB compatbility: in JSB, cc._p reuses objects instead of creating new ones
Expand Down Expand Up @@ -140,13 +149,18 @@ cc.pointEqualToPoint = function (point1, point2) {

/**
* @class
* @param {Number} _width
* @param {Number|cc.Size} _width
* @param {Number} _height
* Constructor
*/
cc.Size = function (_width, _height) {
this.width = _width || 0;
this.height = _height || 0;
if(arguments.length === 1){
this.width = _width.width;
this.height = _width.height;
} else {
this.width = _width || 0;
this.height = _height || 0;
}
};

cc._SizeConst = function (width, height) {
Expand Down Expand Up @@ -192,6 +206,7 @@ Object.defineProperties(cc._SizeConst.prototype, {
* @param {Number} width
* @param {Number} height
* @return {cc.Size}
* @deprecated
*/
cc.SizeMake = function (width, height) {
cc.log("cc.SizeMake will be deprecated sooner or later. Use cc.size instead.");
Expand All @@ -200,18 +215,21 @@ cc.SizeMake = function (width, height) {

/**
* @function
* @param {Number} w width
* @param {Number|cc.Size} w width or a size object
* @param {Number} h height
* @return {cc.Size}
*/
cc.size = function (w, h) {
// This can actually make use of "hidden classes" in JITs and thus decrease
// memory usage and overall peformance drastically
// memory usage and overall performance drastically
//return new cc.Size(w, h);
// but this one will instead flood the heap with newly allocated hash maps
// giving little room for optimization by the JIT
// note: we have tested this item on Chrome and firefox, it is faster than new cc.Size(w, h)
return { width: w, height: h};
if(arguments.length === 1)
return { width: w.width, height: w.height};
else
return { width: w || 0, height: h || 0};
};

// JSB compatbility: in JSB, cc._size reuses objects instead of creating new ones
Expand Down
Loading

0 comments on commit 2a8b375

Please sign in to comment.