实现2.4.11版本

This commit is contained in:
lujun
2023-02-09 17:25:08 +08:00
parent 70c4e8da16
commit 451f431777
210 changed files with 46766 additions and 7089 deletions

View File

@@ -0,0 +1,111 @@
//@ts-ignore
const nodeMemPool = require('./trans-pool/index').NodeMemPool
declare module cc {
export interface Node {
/**
* 排序优先级 - private
*/
_sortingPriority:number;
/**
* 排序优先级
*/
sortingPriority:number;
/**
* 排序优使能 - private
*/
_sortingEnabled:boolean;
/**
* 排序优使能
*/
sortingEnabled:boolean;
}
}
if(!('sortingPriority' in cc.Node.prototype)){
Object.defineProperty(cc.Node.prototype, 'sortingPriority', {
get: function() {
return this._sortingPriority;
},
set: function(value) {
this._sortingPriority = value;
// console.log(`sortingPriority ${this.name} ${value}`);
if(CC_JSB){
this._sortingPriorityProxy[0] = value;
}
},
enumerable: true
});
Object.defineProperty(cc.Node.prototype, 'sortingEnabled', {
get: function() {
return this._sortingEnabled;
},
set: function(value) {
this._sortingEnabled = value;
// console.log(`sortingEnabled ${this.name} ${value}`);
if(CC_JSB){
this._sortingEnabledProxy[0] = value ? 1 : 0;
}
},
enumerable: true
});
}
if(CC_JSB){
//@ts-ignore
cc.Node.prototype._initDataFromPool = function(){
if (!this._spaceInfo) {
if (CC_EDITOR || CC_TEST) {
this._spaceInfo = {
trs: new Float64Array(10),
localMat: new Float64Array(16),
worldMat: new Float64Array(16),
};
} else {
this._spaceInfo = nodeMemPool.pop();
}
}
let spaceInfo = this._spaceInfo;
this._matrix = cc.mat4(spaceInfo.localMat);
cc.Mat4.identity(this._matrix);
this._worldMatrix = cc.mat4(spaceInfo.worldMat);
cc.Mat4.identity(this._worldMatrix);
this._localMatDirty = 0xffff;
this._worldMatDirty = true;
this._sortingPriorityProxy = spaceInfo.sortingPriority;
this._sortingEnabledProxy = spaceInfo.sortingEnabled;
let trs = this._trs = spaceInfo.trs;
trs[0] = 0; // position.x
trs[1] = 0; // position.y
trs[2] = 0; // position.z
trs[3] = 0; // rotation.x
trs[4] = 0; // rotation.y
trs[5] = 0; // rotation.z
trs[6] = 1; // rotation.w
trs[7] = 1; // scale.x
trs[8] = 1; // scale.y
trs[9] = 1; // scale.z
}
//@ts-ignore
cc.Node.prototype._backDataIntoPool = function() {
if (!(CC_EDITOR || CC_TEST)) {
// push back to pool
nodeMemPool.push(this._spaceInfo);
this._sortingPriorityProxy = null;
this._sortingEnabledProxy = null;
this._matrix = null;
this._worldMatrix = null;
this._trs = null;
this._spaceInfo = null;
}
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "f0c38288-db93-4468-ab2a-0e3bc2059d15",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,10 @@
declare module cc {
export interface RenderComponent {
/**
* 渲染优先级
*/
renderPriority:number;
}
}

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "910f4c68-0289-4422-a65c-6dc64f77511e",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,153 @@
let _batcher;
let _cullingMask = 0;
/**
* 当前渲染优先级
*/
let renderPriority = 0;
/**
* 渲染器缓存
*/
let rendererCache:cc.RenderComponent[] = [];
/**
* 渲染器排序
*/
let rendererOrder:boolean = false;
/**
* 刷新渲染缓存
*/
function flushRendererCache(){
if(rendererCache.length > 0){
if(rendererOrder){
rendererCache.sort((a, b)=>{ return a.renderPriority - b.renderPriority; });
}
for(let render of rendererCache){
// console.log(`${render.node.name} - ${render.renderPriority}`);
//@ts-ignore
render._checkBacth(_batcher, render.node._cullingMask);
//@ts-ignore
render._assembler.fillBuffers(render, _batcher);
}
rendererCache.length = 0;
}
rendererOrder = false;
}
//@ts-ignore
cc.RenderFlow.visitRootNode = function (rootNode){
renderPriority = 0;
rendererCache.length = 0;
rendererOrder = false;
//@ts-ignore
_batcher = cc.RenderFlow.getBachther();
//@ts-ignore
cc.RenderFlow.validateRenderers();
let preCullingMask = _cullingMask;
_cullingMask = rootNode._cullingMask;
//@ts-ignore
if (rootNode._renderFlag & cc.RenderFlow.FLAG_WORLD_TRANSFORM) {
_batcher.worldMatDirty ++;
rootNode._calculWorldMatrix();
//@ts-ignore
rootNode._renderFlag &= ~cc.RenderFlow.FLAG_WORLD_TRANSFORM;
//@ts-ignore
cc.RenderFlow.flows[rootNode._renderFlag]._func(rootNode);
flushRendererCache();
_batcher.worldMatDirty --;
}
else {
//@ts-ignore
cc.RenderFlow.flows[rootNode._renderFlag]._func(rootNode);
flushRendererCache();
}
_cullingMask = preCullingMask;
}
//@ts-ignore
cc.RenderFlow.prototype._render = function (node) {
let comp = node._renderComponent;
if(comp instanceof cc.Mask){
flushRendererCache();
//@ts-ignore
comp._checkBacth(_batcher, node._cullingMask);
//@ts-ignore
comp._assembler.fillBuffers(comp, _batcher);
}else{
if (_batcher.worldMatDirty && comp._assembler.updateWorldVerts) {
comp._assembler.updateWorldVerts(comp);
}
rendererCache.push(comp);
comp.renderPriority = node._sortingEnabled ? node._sortingPriority : renderPriority;
if(renderPriority != 0){
rendererOrder = true;
}
}
this._next._func(node);
};
//@ts-ignore
cc.RenderFlow.prototype._postRender = function (node) {
let comp = node._renderComponent;
if(comp instanceof cc.Mask){
flushRendererCache();
}
comp._checkBacth(_batcher, node._cullingMask);
comp._assembler.postFillBuffers(comp, _batcher);
this._next._func(node);
};
//@ts-ignore
cc.RenderFlow.prototype._children = function (node) {
let cullingMask = _cullingMask;
let batcher = _batcher;
let preRenderPriority = renderPriority;
let parentOpacity = batcher.parentOpacity;
let opacity = (batcher.parentOpacity *= (node._opacity / 255));
renderPriority = node._sortingEnabled ? node._sortingPriority : renderPriority;
// console.log(`${node.name} ${renderPriority}`);
//@ts-ignore
let worldTransformFlag = batcher.worldMatDirty ? cc.RenderFlow.FLAG_WORLD_TRANSFORM : 0;
//@ts-ignore
let worldOpacityFlag = batcher.parentOpacityDirty ? cc.RenderFlow.FLAG_OPACITY_COLOR : 0;
let worldDirtyFlag = worldTransformFlag | worldOpacityFlag;
let children = node._children;
for (let i = 0, l = children.length; i < l; i++) {
let c = children[i];
// Advance the modification of the flag to avoid node attribute modification is invalid when opacity === 0.
c._renderFlag |= worldDirtyFlag;
if (!c._activeInHierarchy || c._opacity === 0) continue;
_cullingMask = c._cullingMask = c.groupIndex === 0 ? cullingMask : 1 << c.groupIndex;
// TODO: Maybe has better way to implement cascade opacity
let colorVal = c._color._val;
c._color._fastSetA(c._opacity * opacity);
// @ts-ignore
cc.RenderFlow.flows[c._renderFlag]._func(c);
c._color._val = colorVal;
}
batcher.parentOpacity = parentOpacity;
renderPriority = preRenderPriority;
this._next._func(node);
};

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "d9ee1293-73e0-4588-a058-685d75be1912",
"importer": "typescript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,13 @@
{
"ver": "1.1.3",
"uuid": "10d7cfa4-65ae-4b25-8725-2630ae630cd3",
"importer": "folder",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}

View File

@@ -0,0 +1,31 @@
/****************************************************************************
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let NodeUnit = require('./node-unit');
let NodeMemPool = require('./node-mem-pool');
module.exports = {
NodeMemPool: new NodeMemPool(NodeUnit)
};

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "eb098cc5-0be2-48ee-8103-989d20216bda",
"importer": "javascript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,109 @@
/****************************************************************************
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let MemPool = function (unitClass) {
this._unitClass = unitClass;
this._pool = [];
this._findOrder = [];
if (CC_JSB && CC_NATIVERENDERER) {
this._initNative();
}
};
let proto = MemPool.prototype;
proto._initNative = function () {
this._nativeMemPool = new renderer.MemPool();
};
proto._buildUnit = function (unitID) {
let unit = new this._unitClass(unitID, this);
if (CC_JSB && CC_NATIVERENDERER) {
this._nativeMemPool.updateCommonData(unitID, unit._data, unit._signData);
}
return unit;
};
proto._destroyUnit = function (unitID) {
this._pool[unitID] = null;
for (let idx = 0, n = this._findOrder.length; idx < n; idx++) {
let unit = this._findOrder[idx];
if (unit && unit.unitID == unitID) {
this._findOrder.splice(idx, 1);
break;
}
}
if (CC_JSB && CC_NATIVERENDERER) {
this._nativeMemPool.removeCommonData(unitID);
}
};
proto._findUnitID = function () {
let unitID = 0;
let pool = this._pool;
while (pool[unitID]) unitID++;
return unitID;
};
proto.pop = function () {
let findUnit = null;
let idx = 0;
let findOrder = this._findOrder;
let pool = this._pool;
for (let n = findOrder.length; idx < n; idx++) {
let unit = findOrder[idx];
if (unit && unit.hasSpace()) {
findUnit = unit;
break;
}
}
if (!findUnit) {
let unitID = this._findUnitID();
findUnit = this._buildUnit(unitID);
pool[unitID] = findUnit;
findOrder.push(findUnit);
idx = findOrder.length - 1;
}
// swap has space unit to first position, so next find will fast
let firstUnit = findOrder[0];
if (firstUnit !== findUnit) {
findOrder[0] = findUnit;
findOrder[idx] = firstUnit;
}
return findUnit.pop();
};
proto.push = function (info) {
let unit = this._pool[info.unitID];
unit.push(info.index);
if (this._findOrder.length > 1 && unit.isAllFree()) {
this._destroyUnit(info.unitID);
}
return unit;
};
module.exports = MemPool;

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "13cfc2d4-b859-42dc-917a-561662386b76",
"importer": "javascript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,49 @@
/****************************************************************************
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
let MemPool = require('./mem-pool');
let NodeMemPool = function (unitClass) {
MemPool.call(this, unitClass);
};
(function(){
let Super = function(){};
Super.prototype = MemPool.prototype;
NodeMemPool.prototype = new Super();
})();
let proto = NodeMemPool.prototype;
proto._initNative = function () {
this._nativeMemPool = new renderer.NodeMemPool();
};
proto._destroyUnit = function (unitID) {
MemPool.prototype._destroyUnit.call(this, unitID);
if (CC_JSB && CC_NATIVERENDERER) {
this._nativeMemPool.removeNodeData(unitID);
}
};
module.exports = NodeMemPool;

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "caa4d37a-9df4-4a7b-9407-eafa3c27df76",
"importer": "javascript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,158 @@
/****************************************************************************
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const FLOAT_ARRAY_TYPE = (CC_JSB && CC_NATIVERENDERER) ? Float32Array : Float64Array;
const FLOAT_BYTES = (CC_JSB && CC_NATIVERENDERER) ? 4 : 8;
const Uint32_Bytes = 4;
const Uint8_Bytes = 1;
// Space : [Dirty] [Size:4 Uint32]
const Dirty_Type = Uint32Array;
const Dirty_Members = 1;
const Dirty_Stride = Dirty_Members * Uint32_Bytes;
// Space : [TRS] [Size:4 * 10 Float32|Float64]
const TRS_Members = 10;
const TRS_Stride = TRS_Members * FLOAT_BYTES;
// Space : [LocalMatrix] [Size:4 * 16 Float32|Float64]
const LocalMatrix_Members = 16;
const LocalMatrix_Stride = LocalMatrix_Members * FLOAT_BYTES;
// Space : [WorldMatrix] [Size:4 * 16 Float32|Float64]
const WorldMatrix_Members = 16;
const WorldMatrix_Stride = WorldMatrix_Members * FLOAT_BYTES;
// Space : [sortingPriority] [Size:4 * 1 Float32|Float64]
const SortingPriority_Members = 1;
const SortingPriority_Stride = SortingPriority_Members * FLOAT_BYTES;
// Space : [Parent Unit] [Size:4 Uint32]
// Space : [Parent Index] [Size:4 Uint32]
const Parent_Type = Uint32Array;
const Parent_Members = 2;
const Parent_Stride = Parent_Members * Uint32_Bytes;
// Space : [ZOrder] [Size:4 Uint32]
const ZOrder_Type = Uint32Array;
const ZOrder_Members = 1;
const ZOrder_Stride = ZOrder_Members * Uint32_Bytes;
// Space : [CullingMask] [Size:4 Int32]
const CullingMask_Type = Int32Array;
const CullingMask_Members = 1;
const CullingMask_Stride = CullingMask_Members * Uint32_Bytes;
// Space : [Opacity] [Size:1 Uint8]
const Opacity_Type = Uint8Array;
const Opacity_Members = 1;
const Opacity_Stride = Opacity_Members * Uint8_Bytes;
// Space : [Is3D] [Size:1 Uint8]
const Is3D_Type = Uint8Array;
const Is3D_Members = 1;
const Is3D_Stride = Is3D_Members * Uint8_Bytes;
// Space : [sortingEnabled] [Size:1 Uint8]
const SortingEnabled_Type = Uint8Array;
const SortingEnabled_Members = 1;
const SortingEnabled_Stride = SortingEnabled_Members * Uint8_Bytes;
// Space : [NodePtr] [Size:4 * 2 Uint32]
const Node_Type = Uint32Array;
const Node_Members = 2;
// Space : [Skew] [Size:4 * 2 Float32]
const Skew_Members = 2;
const Skew_Stride = Skew_Members * FLOAT_BYTES;
let UnitBase = require('./unit-base');
let NodeUnit = function (unitID, memPool) {
UnitBase.call(this, unitID, memPool);
let contentNum = this._contentNum;
this.trsList = new FLOAT_ARRAY_TYPE(contentNum * TRS_Members);
this.localMatList = new FLOAT_ARRAY_TYPE(contentNum * LocalMatrix_Members);
this.worldMatList = new FLOAT_ARRAY_TYPE(contentNum * WorldMatrix_Members);
if (CC_JSB && CC_NATIVERENDERER) {
this.dirtyList = new Dirty_Type(contentNum * Dirty_Members);
this.parentList = new Parent_Type(contentNum * Parent_Members);
this.zOrderList = new ZOrder_Type(contentNum * ZOrder_Members);
this.cullingMaskList = new CullingMask_Type(contentNum * CullingMask_Members);
this.opacityList = new Opacity_Type(contentNum * Opacity_Members);
this.is3DList = new Is3D_Type(contentNum * Is3D_Members);
this.nodeList = new Node_Type(contentNum * Node_Members);
this.skewList = new FLOAT_ARRAY_TYPE(contentNum * Skew_Members);
this.sortingPriorityList = new FLOAT_ARRAY_TYPE(contentNum * SortingPriority_Stride);
this.sortingEnabledList = new SortingEnabled_Type(contentNum * SortingEnabled_Stride);
this._memPool._nativeMemPool.updateNodeData(
unitID,
this.dirtyList,
this.trsList,
this.localMatList,
this.worldMatList,
this.parentList,
this.zOrderList,
this.cullingMaskList,
this.opacityList,
this.is3DList,
this.nodeList,
this.skewList,
this.sortingPriorityList,
this.sortingEnabledList
);
}
for (let i = 0; i < contentNum; i ++) {
let space = this._spacesData[i];
space.trs = new FLOAT_ARRAY_TYPE(this.trsList.buffer, i * TRS_Stride, TRS_Members);
space.localMat = new FLOAT_ARRAY_TYPE(this.localMatList.buffer, i * LocalMatrix_Stride, LocalMatrix_Members);
space.worldMat = new FLOAT_ARRAY_TYPE(this.worldMatList.buffer, i * WorldMatrix_Stride, WorldMatrix_Members);
if (CC_JSB && CC_NATIVERENDERER) {
space.dirty = new Dirty_Type(this.dirtyList.buffer, i * Dirty_Stride, Dirty_Members);
space.parent = new Parent_Type(this.parentList.buffer, i * Parent_Stride, Parent_Members);
space.zOrder = new ZOrder_Type(this.zOrderList.buffer, i * ZOrder_Stride, ZOrder_Members);
space.cullingMask = new CullingMask_Type(this.cullingMaskList.buffer, i * CullingMask_Stride, CullingMask_Members);
space.opacity = new Opacity_Type(this.opacityList.buffer, i * Opacity_Stride, Opacity_Members);
space.is3D = new Is3D_Type(this.is3DList.buffer, i * Is3D_Stride, Is3D_Members);
space.skew = new FLOAT_ARRAY_TYPE(this.skewList.buffer, i * Skew_Stride, Skew_Members);
space.sortingPriority = new FLOAT_ARRAY_TYPE(this.sortingPriorityList.buffer, i * SortingPriority_Stride, SortingPriority_Members);
space.sortingEnabled = new SortingEnabled_Type(this.sortingEnabledList.buffer, i * SortingEnabled_Stride, SortingEnabled_Members);
}
}
};
(function(){
let Super = function(){};
Super.prototype = UnitBase.prototype;
NodeUnit.prototype = new Super();
})();
module.exports = NodeUnit;

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "3e3243b6-45a4-4eec-9abb-805de55e8b1f",
"importer": "javascript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,167 @@
/****************************************************************************
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
// Unit has many segment, layout such as :
// Head Free Pointer + Using Segment Num + Segment 1 + Segment 2 + Segment 3 ...
// sign data format
// Space : [If Free Flag] [Size:1 Uint16]
// Space : [Next Free Index] [Size:1 Uint16]
// invalid pointer value
let POINTER_INVALID_FLAG = 0xffff;
let SPACE_FREE_FLAG = 0x0;
let SPACE_USE_FLAG = 0x1;
let POS_NEXT_FREE = 0;
let POS_FREE_FLAG = 1;
let UnitBase = function (unitID, memPool, contentNum) {
contentNum = contentNum || 128;
// set unit id
this.unitID = unitID;
this._memPool = memPool;
this._data = new Uint16Array(2);
// head of the free content index
this._data[0] = 0;
// using segment num
this._data[1] = 0;
this._contentNum = contentNum;
this._signData = new Uint16Array(this._contentNum * 2);
this._spacesData = [];
for (let i = 0; i < contentNum; i++) {
let signIndex = i * 2;
// store content block index but not sign array index
this._signData[signIndex + POS_NEXT_FREE] = i + 1;
this._signData[signIndex + POS_FREE_FLAG] = SPACE_FREE_FLAG;
this._spacesData[i] = {
index: i,
unitID: unitID,
};
}
// last one has no next space;
this._signData[(contentNum - 1) * 2] = POINTER_INVALID_FLAG;
};
let UnitBaseProto = UnitBase.prototype;
UnitBaseProto.hasSpace = function () {
return this._data[0] !== POINTER_INVALID_FLAG;
};
UnitBaseProto.isAllFree = function () {
return this._data[1] == 0;
};
// pop space from unit
UnitBaseProto.pop = function () {
let headFreeIndex = this._data[0];
if (headFreeIndex === POINTER_INVALID_FLAG) return null;
let index = headFreeIndex;
let signIndex = index * 2;
let space = this._spacesData[index];
// set use flag
this._signData[signIndex + POS_FREE_FLAG] = SPACE_USE_FLAG;
// store new next free space index
this._data[0] = this._signData[signIndex + POS_NEXT_FREE];
// add using segment num
this._data[1]++;
return space;
};
// push back to unit
UnitBaseProto.push = function (index) {
let signIndex = index * 2;
// set free flag
this._signData[signIndex + POS_FREE_FLAG] = SPACE_FREE_FLAG;
// store head free index to the space
this._signData[signIndex + POS_NEXT_FREE] = this._data[0];
// update head free index
this._data[0] = index;
// sub using segment num
this._data[1]--;
};
// dump all space info
UnitBaseProto.dump = function () {
let spaceNum = 0;
let index = this._data[0];
let freeStr = "";
while (index != POINTER_INVALID_FLAG) {
spaceNum ++;
freeStr += index + "->";
index = this._signData[index * 2 + POS_NEXT_FREE];
}
let usingNum = 0;
let usingStr = "";
let contentNum = this._contentNum;
for (let i = 0; i < contentNum; i++) {
let freeFlag = this._signData[i * 2 + POS_FREE_FLAG];
if (freeFlag == SPACE_USE_FLAG) {
usingNum ++;
usingStr += i + "->";
}
}
let totalNum = spaceNum + usingNum;
console.log(
"unitID:", this.unitID,
"spaceNum:", spaceNum,
"calc using num:", usingNum,
'store using num:', this._data[1],
'calc total num:', totalNum,
'actually total num:', this._contentNum
);
console.log("free info:", freeStr);
console.log("using info:", usingStr);
if (usingNum != this._data[1]) {
cc.error(
'using num error',
"calc using num:", usingNum,
'store using num:', this._data[1]
);
}
if (spaceNum + usingNum != this._contentNum) {
cc.error(
'total num error',
'calc total num:', totalNum,
'actually total num:', this._contentNum
);
}
};
module.exports = UnitBase;

View File

@@ -0,0 +1,10 @@
{
"ver": "1.1.0",
"uuid": "b1e0a00c-ca02-49ba-9561-19c4ca3078df",
"importer": "javascript",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}