mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
Merge branch 'next' of github.com:fireball-x/engine into next
# Conflicts: # cocos2d/motion-streak/CCMotionStreak.js
This commit is contained in:
@@ -160,6 +160,7 @@ HashTimerEntry.put = function (entry) {
|
||||
* @extends cc.Class
|
||||
*/
|
||||
function CallbackTimer () {
|
||||
this._lock = false;
|
||||
this._scheduler = null;
|
||||
this._elapsed = -1;
|
||||
this._runForever = false;
|
||||
@@ -176,6 +177,7 @@ function CallbackTimer () {
|
||||
var proto = CallbackTimer.prototype;
|
||||
|
||||
proto.initWithCallback = function (scheduler, callback, target, seconds, repeat, delay) {
|
||||
this._lock = false;
|
||||
this._scheduler = scheduler;
|
||||
this._target = target;
|
||||
this._callback = callback;
|
||||
@@ -241,8 +243,10 @@ proto.getCallback = function(){
|
||||
};
|
||||
|
||||
proto.trigger = function () {
|
||||
if (this._target && this._callback){
|
||||
if (this._target && this._callback) {
|
||||
this._lock = true;
|
||||
this._callback.call(this._target, this._elapsed);
|
||||
this._lock = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -256,7 +260,7 @@ CallbackTimer.get = function () {
|
||||
return _timers.pop() || new CallbackTimer();
|
||||
};
|
||||
CallbackTimer.put = function (timer) {
|
||||
if (_timers.length < MAX_POOL_SIZE) {
|
||||
if (_timers.length < MAX_POOL_SIZE && !timer._lock) {
|
||||
timer._scheduler = timer._target = timer._callback = null;
|
||||
_timers.push(timer);
|
||||
}
|
||||
@@ -572,6 +576,10 @@ cc.Scheduler = cc._Class.extend({
|
||||
timer = CallbackTimer.get();
|
||||
timer.initWithCallback(this, callback, target, interval, repeat, delay);
|
||||
element.timers.push(timer);
|
||||
|
||||
if (this._currentTarget === element && this._currentTargetSalvaged) {
|
||||
this._currentTargetSalvaged = false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -297,13 +297,12 @@ let Mask = cc.Class({
|
||||
|
||||
_hitTest: function (point) {
|
||||
let node = this.node;
|
||||
let size = node.getContentSize(),
|
||||
w = size.width,
|
||||
h = size.height;
|
||||
node.getWorldMatrix(_mat4_temp);
|
||||
|
||||
if (this.type === MaskType.RECT || this.type === MaskType.IMAGE_STENCIL) {
|
||||
let size = node.getContentSize(),
|
||||
w = size.width,
|
||||
h = size.height;
|
||||
|
||||
_rect_temp.x = -node.anchorX * w,
|
||||
_rect_temp.y = -node.anchorX * h;
|
||||
_rect_temp.width = w;
|
||||
@@ -318,8 +317,9 @@ let Mask = cc.Class({
|
||||
return left >= 0 && right >= 0 && top >= 0 && bottom >= 0;
|
||||
}
|
||||
else if (this.type === MaskType.ELLIPSE) {
|
||||
let rx = w / 2, ry = h / 2;
|
||||
let px = point.x - _mat4_temp.m12, py = point.y - _mat4_temp.m13;
|
||||
return px * px / (a * a) + py * py / (b * b) < 1;
|
||||
return px * px / (rx * rx) + py * py / (ry * ry) < 1;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -55,33 +55,10 @@ module.exports = {
|
||||
texh = texture._height;
|
||||
let frame = sprite.spriteFrame;
|
||||
let rect = frame._rect;
|
||||
let l, b, r, t;
|
||||
|
||||
if (sprite.trim) {
|
||||
l = rect.x;
|
||||
t = rect.y;
|
||||
r = rect.x + rect.width;
|
||||
b = rect.y + rect.height;
|
||||
} else {
|
||||
let originalSize = frame._originalSize;
|
||||
let offset = frame._offset;
|
||||
let ow = originalSize.width,
|
||||
oh = originalSize.height,
|
||||
rw = rect.width,
|
||||
rh = rect.height;
|
||||
let ox = rect.x + (rw - ow) / 2 - offset.x;
|
||||
let oy = rect.y + (rh - oh) / 2 - offset.y;
|
||||
|
||||
l = ox;
|
||||
t = oy;
|
||||
r = ox + ow;
|
||||
b = oy + oh;
|
||||
}
|
||||
|
||||
l = texw === 0 ? 0 : l / texw;
|
||||
r = texw === 0 ? 0 : r / texw;
|
||||
b = texh === 0 ? 0 : b / texh;
|
||||
t = texh === 0 ? 0 : t / texh;
|
||||
let l = texw === 0 ? 0 : rect.x / texw;
|
||||
let r = texw === 0 ? 0 : (rect.x + rect.width) / texw;
|
||||
let b = texh === 0 ? 0 : (rect.y + rect.height) / texh;
|
||||
let t = texh === 0 ? 0 : rect.y / texh;
|
||||
|
||||
if (frame._rotated) {
|
||||
data[0].u = l;
|
||||
|
||||
@@ -272,7 +272,8 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
|
||||
var w = texture.width, h = texture.height;
|
||||
|
||||
if (self._rotated && cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
|
||||
self._texture = _ccsg.Sprite.CanvasRenderCmd._createRotatedTexture(texture, self.getRect());
|
||||
// TODO: rotate texture for canvas
|
||||
// self._texture = _ccsg.Sprite.CanvasRenderCmd._createRotatedTexture(texture, self.getRect());
|
||||
self._rotated = false;
|
||||
w = self._texture.width;
|
||||
h = self._texture.height;
|
||||
@@ -382,7 +383,8 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
|
||||
// loading texture
|
||||
var texture = textureOrTextureFile;
|
||||
if (typeof texture === 'string' && texture) {
|
||||
texture = cc.textureCache.addImage(texture);
|
||||
this._textureFilename = texture;
|
||||
this._loadTexture();
|
||||
}
|
||||
if (texture instanceof cc.Texture2D && this._texture !== texture) {
|
||||
this._refreshTexture(texture);
|
||||
@@ -426,8 +428,7 @@ var SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
|
||||
}
|
||||
else if (this._textureFilename) {
|
||||
// load new texture
|
||||
var texture = cc.textureCache.addImage(this._textureFilename);
|
||||
this._refreshTexture(texture);
|
||||
this._loadTexture();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -36,44 +36,12 @@ const gfx = renderEngine.gfx;
|
||||
const TextureImpl = renderEngine.Texture2D;
|
||||
const renderMode = renderEngine.renderMode;
|
||||
|
||||
const GL_ALPHA = 6406; // gl.ALPHA
|
||||
const GL_RGB = 6407; // gl.RGB
|
||||
const GL_RGBA = 6408; // gl.RGBA
|
||||
const GL_LUMINANCE = 6409; // gl.LUMINANCE
|
||||
const GL_LUMINANCE_ALPHA = 6410; // gl.LUMINANCE_ALPHA
|
||||
const GL_UNSIGNED_BYTE = 5121; // gl.UNSIGNED_BYTE
|
||||
const GL_UNSIGNED_SHORT = 5123; // gl.UNSIGNED_SHORT
|
||||
const GL_UNSIGNED_INT = 5125; // gl.UNSIGNED_INT
|
||||
const GL_FLOAT = 5126; // gl.FLOAT
|
||||
const GL_UNSIGNED_SHORT_5_6_5 = 33635; // gl.UNSIGNED_SHORT_5_6_5
|
||||
const GL_UNSIGNED_SHORT_4_4_4_4 = 32819; // gl.UNSIGNED_SHORT_4_4_4_4
|
||||
const GL_UNSIGNED_SHORT_5_5_5_1 = 32820; // gl.UNSIGNED_SHORT_5_5_5_1
|
||||
|
||||
const GL_NEAREST = 9728; // gl.NEAREST
|
||||
const GL_LINEAR = 9729; // gl.LINEAR
|
||||
const GL_REPEAT = 10497; // gl.REPEAT
|
||||
const GL_CLAMP_TO_EDGE = 33071; // gl.CLAMP_TO_EDGE
|
||||
const GL_MIRRORED_REPEAT = 33648; // gl.MIRRORED_REPEAT
|
||||
|
||||
const _textureFmtGL = [
|
||||
// R5_G6_B5: 0
|
||||
{ format: GL_RGB, internalFormat: GL_RGB, pixelType: GL_UNSIGNED_SHORT_5_6_5 },
|
||||
// R5_G5_B5_A1: 1
|
||||
{ format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_SHORT_5_5_5_1 },
|
||||
// R4_G4_B4_A4: 2
|
||||
{ format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_SHORT_4_4_4_4 },
|
||||
// RGB8: 3
|
||||
{ format: GL_RGB, internalFormat: GL_RGB, pixelType: GL_UNSIGNED_BYTE },
|
||||
// RGBA8: 4
|
||||
{ format: GL_RGBA, internalFormat: GL_RGBA, pixelType: GL_UNSIGNED_BYTE },
|
||||
// A8: 5
|
||||
{ format: GL_ALPHA, internalFormat: GL_ALPHA, pixelType: GL_UNSIGNED_BYTE },
|
||||
// L8: 6
|
||||
{ format: GL_LUMINANCE, internalFormat: GL_LUMINANCE, pixelType: GL_UNSIGNED_BYTE },
|
||||
// L8_A8: 7
|
||||
{ format: GL_LUMINANCE_ALPHA, internalFormat: GL_LUMINANCE_ALPHA, pixelType: GL_UNSIGNED_BYTE }
|
||||
];
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class allows to easily create OpenGL or Canvas 2D textures from images, text or raw data. <br/>
|
||||
@@ -243,6 +211,17 @@ var Texture2D = cc.Class({
|
||||
mixins: [EventTarget],
|
||||
|
||||
properties: {
|
||||
_nativeAsset: {
|
||||
get () {
|
||||
// maybe returned to pool in webgl
|
||||
return this._image;
|
||||
},
|
||||
set (image) {
|
||||
this.initWithElement(image);
|
||||
this.handleLoadedTexture();
|
||||
},
|
||||
override: true
|
||||
},
|
||||
_hasMipmap: false,
|
||||
_format: PixelFormat.RGBA8888,
|
||||
_premultiplyAlpha: false,
|
||||
@@ -255,7 +234,9 @@ var Texture2D = cc.Class({
|
||||
statics: {
|
||||
PixelFormat: PixelFormat,
|
||||
WrapMode: WrapMode,
|
||||
Filter: Filter
|
||||
Filter: Filter,
|
||||
// predefined most common extnames
|
||||
extnames: ['.png', '.jpg', '.jpeg', '.bmp', '.webp']
|
||||
},
|
||||
|
||||
ctor () {
|
||||
@@ -305,36 +286,6 @@ var Texture2D = cc.Class({
|
||||
return this._texture;
|
||||
},
|
||||
|
||||
properties: {
|
||||
_nativeAsset: {
|
||||
get () {
|
||||
// maybe returned to pool in webgl
|
||||
return this._image;
|
||||
},
|
||||
set (image) {
|
||||
this.initWithElement(image);
|
||||
this.handleLoadedTexture();
|
||||
},
|
||||
override: true
|
||||
},
|
||||
_hasMipmap: false,
|
||||
_format: PixelFormat.RGBA8888,
|
||||
_compressed: false,
|
||||
_premultiplyAlpha: false,
|
||||
_minFilter: Filter.LINEAR,
|
||||
_magFilter: Filter.LINEAR,
|
||||
_wrapS: WrapMode.CLAMP_TO_EDGE,
|
||||
_wrapT: WrapMode.CLAMP_TO_EDGE
|
||||
},
|
||||
|
||||
statics: {
|
||||
WrapMode: WrapMode,
|
||||
PixelFormat: PixelFormat,
|
||||
Filter: Filter,
|
||||
// predefined most common extnames
|
||||
extnames: ['.png', '.jpg', '.jpeg', '.bmp', '.webp']
|
||||
},
|
||||
|
||||
/**
|
||||
* Update texture options, not available in Canvas render mode.
|
||||
* image, format, premultiplyAlpha can not be updated in native.
|
||||
@@ -549,8 +500,9 @@ var Texture2D = cc.Class({
|
||||
},
|
||||
|
||||
/**
|
||||
* Release texture.
|
||||
* Release texture, please use destroy instead.
|
||||
* @method releaseTexture
|
||||
* @deprecated
|
||||
*/
|
||||
releaseTexture () {
|
||||
this._image = null;
|
||||
|
||||
@@ -159,7 +159,6 @@ var MotionStreak = cc.Class({
|
||||
},
|
||||
set: function (value) {
|
||||
this._texture = value;
|
||||
|
||||
this._material = null;
|
||||
this._activateMaterial();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user