Skip to content

Commit

Permalink
Merge pull request cocos#52 from dumganhar/v3.3.0-native
Browse files Browse the repository at this point in the history
Update root.jsb.js, node.jsb.ts
  • Loading branch information
minggo authored Oct 27, 2021
2 parents 0148032 + 95846e3 commit 9d036f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
32 changes: 18 additions & 14 deletions cocos/core/root.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ export interface IRootInfo {
enableHDR?: boolean;
}

Root.prototype._ctor = function() {
const rootProto: any = Root.prototype;

rootProto._ctor = function() {
this._modelPools = new Map();
this._lightPools = new Map();
this._batcher = null;
this._registerListeners();
};

Root.prototype.initialize = function (info: IRootInfo) {
//TODO:
rootProto.initialize = function (info: IRootInfo) {
// TODO:
this._initialize();
return Promise.resolve();
};

Root.prototype.createModel = function (ModelCtor) {
rootProto.createModel = function (ModelCtor) {
let p = this._modelPools.get(ModelCtor);
if (!p) {
this._modelPools.set(ModelCtor, new Pool(() => new ModelCtor(), 10));
Expand All @@ -44,7 +46,7 @@ Root.prototype.createModel = function (ModelCtor) {
return model;
};

Root.prototype.removeModel = function (m) {
rootProto.removeModel = function (m) {
const p = this._modelPools.get(m.constructor);
if (p) {
p.free(m);
Expand All @@ -57,7 +59,7 @@ Root.prototype.removeModel = function (m) {
}
};

Root.prototype.createLight = function (LightCtor) {
rootProto.createLight = function (LightCtor) {
let l = this._lightPools.get(LightCtor);
if (!l) {
this._lightPools.set(LightCtor, new Pool(() => new LightCtor(), 4));
Expand All @@ -68,7 +70,7 @@ Root.prototype.createLight = function (LightCtor) {
return light;
};

Root.prototype.destroyLight = function(l) {
rootProto.destroyLight = function(l) {
const p = this._lightPools.get(l.constructor);
l.destroy();
if (p) {
Expand All @@ -88,7 +90,7 @@ Root.prototype.destroyLight = function(l) {
}
};

Root.prototype._onBatch2DInit = function() {
rootProto._onBatch2DInit = function() {
if (!this._batcher && legacyCC.internal.Batcher2D) {
this._batcher = new legacyCC.internal.Batcher2D(this) as Batcher2D;
if (!this._batcher.initialize()) {
Expand All @@ -98,17 +100,19 @@ Root.prototype._onBatch2DInit = function() {
}
};

Root.prototype._onBatch2DUpdate = function() {
for (let i = 0; i < this._scenes.length; ++i) {
this._scenes[i].removeBatches();
}
rootProto._onBatch2DUpdate = function() {
if (this._batcher) this._batcher.update();
};

Root.prototype._onBatch2DUploadBuffers = function () {
rootProto._onBatch2DUploadBuffers = function () {
if (this._batcher) this._batcher.uploadBuffers();
};

Root.prototype._onBatch2DReset = function () {
rootProto._onBatch2DReset = function () {
if (this._batcher) this._batcher.reset();
};

const oldFrameMove = rootProto.frameMove;
rootProto.frameMove = function (deltaTime: number) {
oldFrameMove.call(this, deltaTime, legacyCC.director.getTotalFrames());
};
19 changes: 18 additions & 1 deletion cocos/core/scene-graph/node.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { NodeEventType } from './node-event';
import { CCObject } from '../data/object';
import { NodeUIProperties } from './node-ui-properties';
import { NodeSpace, TransformBit } from './node-enum';
import {Quat, Vec3} from "../math";
import { Quat, Vec3 } from '../math';
import { NodeEventProcessor } from './node-event-processor';

export const Node = jsb.Node;

Expand Down Expand Up @@ -469,6 +470,22 @@ Object.defineProperty(nodeProto, 'scale', {
},
});

Object.defineProperty(nodeProto, 'eventProcessor', {
configurable: true,
enumerable: true,
get () : NodeEventProcessor {
return this._eventProcessor;
},
});

Object.defineProperty(nodeProto, 'components', {
configurable: true,
enumerable: true,
get () : ReadonlyArray<Component> {
return this._components;
},
});

export type Node = jsb.Node;

legacyCC.Node = Node;

0 comments on commit 9d036f3

Please sign in to comment.