Skip to content

Commit

Permalink
Kill INode & IBaseNode (cocos#5893)
Browse files Browse the repository at this point in the history
* Remove INode, IBaseNode

* Fix

* Fix types error

* Update
  • Loading branch information
shrinktofit authored and pandamicro committed Dec 19, 2019
1 parent 6779889 commit 8663644
Show file tree
Hide file tree
Showing 41 changed files with 169 additions and 919 deletions.
5 changes: 2 additions & 3 deletions cocos/core/3d/framework/skinning-model-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { Skeleton } from '../../assets/skeleton';
import { ccclass, executeInEditMode, executionOrder, menu, property } from '../../data/class-decorator';
import { SkinningModel } from '../../renderer/models/skinning-model';
import { Node } from '../../scene-graph/node';
import { INode } from '../../utils/interfaces';
import { builtinResMgr } from '../builtin';
import { ModelComponent } from './model-component';

Expand All @@ -51,7 +50,7 @@ export class SkinningModelComponent extends ModelComponent {
protected _skeleton: Skeleton | null = null;

@property(Node)
protected _skinningRoot: INode | null = null;
protected _skinningRoot: Node | null = null;

protected _clip: AnimationClip | null = null;

Expand All @@ -77,7 +76,7 @@ export class SkinningModelComponent extends ModelComponent {
@property({
type: Node,
})
get skinningRoot (): INode | null {
get skinningRoot () {
return this._skinningRoot;
}

Expand Down
7 changes: 3 additions & 4 deletions cocos/core/animation/animation-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import { EventArgumentsOf, EventCallbackOf } from '../event/defines';
import { Node } from '../scene-graph/node';
import { INode } from '../utils/interfaces';
import { AnimationBlendState, PropertyBlendState } from './animation-blend-state';
import { AnimationClip, IRuntimeCurve } from './animation-clip';
import { AnimCurve, ICurveValueProxy, RatioSampler } from './animation-curve';
Expand Down Expand Up @@ -346,8 +345,8 @@ export class AnimationState extends Playable {
protected _lastWrapInfo: WrappedInfo | null = null;
protected _lastWrapInfoEvent: WrappedInfo | null = null;
protected _process = this.process;
protected _target: INode | null = null;
protected _targetNode: INode | null = null;
protected _target: Node | null = null;
protected _targetNode: Node | null = null;
protected _clip: AnimationClip;
protected _name: string;
protected _lastIterations?: number;
Expand All @@ -365,7 +364,7 @@ export class AnimationState extends Playable {
return this._curveLoaded;
}

public initialize (root: INode, propertyCurves?: readonly IRuntimeCurve[]) {
public initialize (root: Node, propertyCurves?: readonly IRuntimeCurve[]) {
if (this._curveLoaded) { return; }
this._curveLoaded = true;
this._samplerSharedGroups.length = 0;
Expand Down
11 changes: 5 additions & 6 deletions cocos/core/animation/skeletal-animation-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { ccclass, executeInEditMode, executionOrder, menu, property } from '../d
import { Mat4 } from '../math';
import { IAnimInfo, JointsAnimationInfo } from '../renderer/models/skeletal-animation-utils';
import { Node } from '../scene-graph/node';
import { INode } from '../utils/interfaces';
import { AnimationClip } from './animation-clip';
import { AnimationComponent } from './animation-component';
import { SkelAnimDataHub } from './skeletal-animation-data-hub';
Expand All @@ -43,8 +42,8 @@ export class Socket {
@property
public path: string = '';
@property(Node)
public target: INode | null = null;
constructor (path = '', target: INode | null = null) {
public target: Node | null = null;
constructor (path = '', target: Node | null = null) {
this.path = path;
this.target = target;
}
Expand All @@ -53,7 +52,7 @@ export class Socket {
const m4_1 = new Mat4();
const m4_2 = new Mat4();

function collectRecursively (node: INode, prefix = '', out: string[] = []) {
function collectRecursively (node: Node, prefix = '', out: string[] = []) {
for (let i = 0; i < node.children.length; i++) {
const child = node.children[i];
if (!child) { continue; }
Expand Down Expand Up @@ -167,12 +166,12 @@ export class SkeletalAnimationComponent extends AnimationComponent {
}
}

public createSocket (path: string): INode | null {
public createSocket (path: string) {
const socket = this._sockets.find((s) => s.path === path);
if (socket) { return socket.target; }
const joint = this.node.getChildByPath(path);
if (!joint) { console.warn('illegal socket path'); return null; }
const target = new Node() as INode;
const target = new Node();
target.parent = this.node;
this._sockets.push(new Socket(path, target));
this.rebuildSocketAnimations();
Expand Down
4 changes: 2 additions & 2 deletions cocos/core/animation/skeletal-animation-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@

import { SkinningModelComponent } from '../3d/framework/skinning-model-component';
import { Mat4 } from '../math';
import { INode } from '../utils/interfaces';
import { AnimationClip, IObjectCurveData } from './animation-clip';
import { AnimCurve } from './animation-curve';
import { AnimationState, ICurveInstance } from './animation-state';
import { Socket } from './skeletal-animation-component';
import { SkelAnimDataHub } from './skeletal-animation-data-hub';
import { ComponentModifier, HierachyModifier, TargetModifier } from './target-modifier';
import { getPathFromRoot, getWorldTransformUntilRoot } from './transform-utils';
import { Node } from '../scene-graph';

const m4_1 = new Mat4();

Expand All @@ -56,7 +56,7 @@ export class SkeletalAnimationState extends AnimationState {
this._preSample = preSample;
}

public initialize (root: INode) {
public initialize (root: Node) {
if (this._preSample) {
const info = SkelAnimDataHub.getOrExtract(this.clip).info;
super.initialize(root, info.curves);
Expand Down
5 changes: 2 additions & 3 deletions cocos/core/animation/target-modifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

import { ccclass, property } from '../data/class-decorator';
import { INode } from '../utils/interfaces';
import { CurveValueAdapter, ICurveValueProxy } from './animation-curve';
import { Node } from '../scene-graph/node';

Expand Down Expand Up @@ -41,7 +40,7 @@ export class HierachyModifier implements ICustomTargetModifier {
this.path = path || '';
}

get(target: INode) {
get(target: Node) {
if (!(target instanceof Node)) {
throw new Error(`Target of hierachy modifier shall be Node.`);
}
Expand All @@ -63,7 +62,7 @@ export class ComponentModifier implements ICustomTargetModifier {
this.component = component || '';
}

get (target: INode) {
get (target: Node) {
if (!(target instanceof Node)) {
throw new Error(`Target of hierachy modifier shall be Node.`);
}
Expand Down
8 changes: 4 additions & 4 deletions cocos/core/animation/transform-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
*/

import { Mat4 } from '../math';
import { INode } from '../utils/interfaces';
import { Node } from '../scene-graph';

const m4_1 = new Mat4();

export function getPathFromRoot (target: INode | null, root: INode) {
let node: INode | null = target;
export function getPathFromRoot (target: Node | null, root: Node) {
let node: Node | null = target;
let path = '';
while (node !== null && node !== root) {
path = `${node.name}/${path}`;
Expand All @@ -42,7 +42,7 @@ export function getPathFromRoot (target: INode | null, root: INode) {
return path.slice(0, -1);
}

export function getWorldTransformUntilRoot (target: INode, root: INode, outMatrix: Mat4) {
export function getWorldTransformUntilRoot (target: Node, root: Node, outMatrix: Mat4) {
Mat4.identity(outMatrix);
while (target !== root) {
Mat4.fromRTS(m4_1, target.rotation, target.position, target.scale);
Expand Down
4 changes: 2 additions & 2 deletions cocos/core/assets/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import { Event } from '../event';
import { CallbacksInvoker } from '../event/callbacks-invoker';
import { EventTarget } from '../event/event-target';
import { applyMixins, IEventTarget } from '../event/event-target-factory';
import { INode } from '../utils/interfaces';
import { createMap } from '../utils/js-typed';
import { RawAsset } from './raw-asset';
import { Node } from '../scene-graph';

/**
* @en
Expand Down Expand Up @@ -271,7 +271,7 @@ applyMixins(Asset, [CallbacksInvoker, EventTarget]);
* @param error - null or the error info
* @param node - the created node or null
*/
type CreateNodeCallback = (error: Error | null, node: INode) => void;
type CreateNodeCallback = (error: Error | null, node: Node) => void;

// @ts-ignore
Asset.prototype.createNode = null;
Expand Down
6 changes: 3 additions & 3 deletions cocos/core/components/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ import { getClassName, value } from '../utils/js';
import { RenderScene } from '../renderer/scene/render-scene';
import { Rect } from '../math';
import * as RF from '../data/utils/requiring-frame';
import { INode } from '../utils/interfaces';
import { Node } from '../scene-graph';

const idGenerator = new IDGenerator('Comp');
// @ts-ignore
const IsOnEnableCalled = CCObject.Flags.IsOnEnableCalled;
// @ts-ignore
const IsOnLoadCalled = CCObject.Flags.IsOnLoadCalled;

const NullNode = null as unknown as INode;
const NullNode = null as unknown as Node;

/**
* @en
Expand Down Expand Up @@ -188,7 +188,7 @@ class Component extends CCObject {
@property({
visible: false,
})
public node: INode = NullNode;
public node: Node = NullNode;

/**
* @property _enabled
Expand Down
3 changes: 1 addition & 2 deletions cocos/core/components/ui-base/canvas-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { ResolutionPolicy, view } from '../../platform/view';
import visibleRect from '../../platform/visible-rect';
import { Camera } from '../../renderer';
import { Node } from '../../scene-graph/node';
import { INode } from '../../utils/interfaces';
import { Enum } from '../../value-types';
import { Component } from '../component';
import { UITransformComponent } from './ui-transform-component';
Expand Down Expand Up @@ -219,7 +218,7 @@ export class CanvasComponent extends Component {
this._camera = director.root!.createCamera();
this._camera.initialize({
name: 'ui_' + this.node.name,
node: cameraNode as INode,
node: cameraNode,
projection: CameraComponent.ProjectionType.ORTHO,
priority: this._getViewPriority(),
flows: ['UIFlow'],
Expand Down
4 changes: 2 additions & 2 deletions cocos/core/components/ui-base/ui-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
*/

import { ccclass, disallowMultiple, executeInEditMode, executionOrder, property, requireComponent } from '../../../core/data/class-decorator';
import { INode } from '../../../core/utils/interfaces';
import { UI } from '../../renderer/ui/ui';
import { Component } from '../component';
import { UITransformComponent } from './ui-transform-component';
import { Node } from '../../scene-graph';

/**
* @zh
Expand All @@ -44,7 +44,7 @@ import { UITransformComponent } from './ui-transform-component';
@executeInEditMode
export class UIComponent extends Component {

protected _lastParent: INode | null = null;
protected _lastParent: Node | null = null;

public __preload () {
this.node._uiComp = this;
Expand Down
6 changes: 3 additions & 3 deletions cocos/core/components/ui-base/ui-render-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { RenderableComponent } from '../../../core/3d/framework/renderable-compo
import { IAssembler, IAssemblerManager } from '../../renderer/ui/base';
import { UIComponent } from './ui-component';
import { TransformBit } from '../../scene-graph/node-enum';
import { INode } from '../../utils/interfaces';
import { Node } from '../../scene-graph';

// hack
ccenum(GFXBlendFactor);
Expand Down Expand Up @@ -202,7 +202,7 @@ export class UIRenderComponent extends UIComponent {
}

// Render data can be submitted even if it is not on the node tree
set delegateSrc (value: INode) {
set delegateSrc (value: Node) {
this._delegateSrc = value;
}

Expand All @@ -225,7 +225,7 @@ export class UIRenderComponent extends UIComponent {
protected _renderDataFlag = true;
protected _renderFlag = true;
// 特殊渲染节点,给一些不在节点树上的组件做依赖渲染(例如 mask 组件内置两个 graphics 来渲染)
protected _delegateSrc: INode | null = null;
protected _delegateSrc: Node | null = null;
protected _material: Material | null = null;
protected _instanceMaterialType = InstanceMaterialType.ADDCOLORANDTEXTURE;
protected _blendTemplate = {
Expand Down
8 changes: 4 additions & 4 deletions cocos/core/components/ui-base/ui-transform-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { EventListener, IListenerMask } from '../../platform/event-manager/event
import { Mat4, Rect, Size, Vec2, Vec3 } from '../../math';
import { aabb } from '../../geom-utils';
import { CanvasComponent } from './canvas-component';
import { INode } from '../../utils/interfaces';
import { Node } from '../../scene-graph';

const _vec2a = new Vec2();
const _vec2b = new Vec2();
Expand Down Expand Up @@ -571,7 +571,7 @@ export class UITransformComponent extends Component {
}
}

protected _parentChanged(node: INode) {
protected _parentChanged(node: Node) {
if (this._canvas && this._canvas.node === this.node) {
return;
}
Expand All @@ -580,9 +580,9 @@ export class UITransformComponent extends Component {
}

protected _sortSiblings() {
const siblings = this.node.parent && this.node.parent.children as Mutable<INode[]>;
const siblings = this.node.parent && this.node.parent.children as Mutable<Node[]>;
if (siblings) {
siblings.sort((a: INode, b: INode) => {
siblings.sort((a, b) => {
const aComp = a.uiTransformComp;
const bComp = b.uiTransformComp;
const ca = aComp ? aComp.priority : 0;
Expand Down
14 changes: 8 additions & 6 deletions cocos/core/platform/SubContextView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/

import { Component } from '../components/component';
import { property, ccclass, menu, executionOrder } from '../data/class-decorator';
import { property, ccclass, menu, executionOrder, requireComponent } from '../data/class-decorator';
import { view } from './view';
import { SpriteComponent } from '../../ui/components/sprite-component';
import { Node } from '../scene-graph';
Expand Down Expand Up @@ -60,6 +60,7 @@ import { Rect } from '../math';
*/
@ccclass('cc.SubContextView')
@executionOrder(110)
@requireComponent(UITransformComponent)
@menu('Components/SubContextView')
export class SubContextView extends Component {
@property({
Expand Down Expand Up @@ -136,8 +137,8 @@ export class SubContextView extends Component {
}

public update (dt: number) {
let calledUpdateMannually = (dt === undefined);
if (calledUpdateMannually) {
let calledUpdateManually = (dt === undefined);
if (calledUpdateManually) {
this._context && this._context.postMessage({
fromEngine: true,
event: 'step',
Expand All @@ -162,9 +163,10 @@ export class SubContextView extends Component {
if (this._context) {
this.updateSubContextViewport();
let sharedCanvas = this._context.canvas;
const transformComp = this.node.getComponent(UITransformComponent)!;
if (sharedCanvas) {
sharedCanvas.width = this.node.getComponent(UITransformComponent).width;
sharedCanvas.height = this.node.getComponent(UITransformComponent).height;
sharedCanvas.width = transformComp.width;
sharedCanvas.height = transformComp.height;
}
}
}
Expand All @@ -175,7 +177,7 @@ export class SubContextView extends Component {
*/
public updateSubContextViewport () {
if (this._context) {
let box = this.node.getComponent(UITransformComponent).getBoundingBoxToWorld() as Rect;
let box = this.node.getComponent(UITransformComponent)!.getBoundingBoxToWorld() as Rect;
let sx = view.getScaleX();
let sy = view.getScaleY();
const rect = view.getViewportRect();
Expand Down
4 changes: 2 additions & 2 deletions cocos/core/platform/event-manager/event-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* @category event
*/

import { INode } from '../../utils/interfaces';
import { EventKeyboard, EventAcceleration, EventMouse } from './events';
import { Node } from '../../scene-graph';

export interface IEventListenerCreateInfo {
event?: number;
Expand All @@ -40,7 +40,7 @@ export interface IEventListenerCreateInfo {

export interface IListenerMask {
index: number;
node: INode;
node: Node;
}

/**
Expand Down
Loading

0 comments on commit 8663644

Please sign in to comment.