migrate app to director (#3259)

This commit is contained in:
zxg0622
2018-09-18 14:03:44 +08:00
committed by pandamicro
parent f05972489c
commit 423132c567
6 changed files with 68 additions and 104 deletions
+6 -3
View File
@@ -99,6 +99,9 @@ class AnimationCtrl {
}
}
@executionOrder(200)
@ccclass('AnimationComponent')
export default class AnimationComponent extends Component {
onInit() {
this._name2states = {};
@@ -110,7 +113,7 @@ export default class AnimationComponent extends Component {
*/
this.clips = this._clips;
this._system.add(this);
AnimationComponent.system.add(this);
if (this._playAutomatically != undefined &&
this._playAutomatically &&
@@ -121,7 +124,7 @@ export default class AnimationComponent extends Component {
}
onDestroy() {
this._system.remove(this);
AnimationComponent.system.remove(this);
}
get skeleton () {
@@ -194,4 +197,4 @@ AnimationComponent.schema = {
this._playAutomatically = val;
}
}
};
};
+2 -2
View File
@@ -17,7 +17,7 @@ export default class AnimationSystem extends System {
this._anims.fastRemove(this._anims.indexOf(comp));
}
tick() {
update() {
for (let i = 0; i < this._anims.length; ++i) {
let anim = this._anims.data[i];
if (!anim.enabled) {
@@ -33,4 +33,4 @@ export default class AnimationSystem extends System {
}
}
}
}
}
@@ -5,6 +5,8 @@ import utils from '../misc/utils';
let _m4_tmp = mat4.create();
@executionOrder(100)
@ccclass('SkinningModelComponent')
export default class SkinningModelComponent extends ModelComponent {
onInit() {
this._models = [];
@@ -17,13 +19,13 @@ export default class SkinningModelComponent extends ModelComponent {
this._updateCastShadow();
this._updateReceiveShadow();
this._system.add(this);
SkinningModelComponent.system.add(this);
this.joints = this._joints;
}
onDestroy() {
this._system.remove(this);
SkinningModelComponent.system.remove(this);
}
_updateMatrices() {
+2 -2
View File
@@ -16,7 +16,7 @@ export default class SkinningModelSystem extends System {
this._comps.fastRemove(this._comps.indexOf(comp));
}
tick() {
update() {
for (let i = 0; i < this._comps.length; ++i) {
let comp = this._comps.data[i];
if (comp.enabled === false) {
@@ -26,4 +26,4 @@ export default class SkinningModelSystem extends System {
comp._updateMatrices();
}
}
}
}
+52 -93
View File
@@ -31,6 +31,11 @@ import ccobject from './data/object';
import game from './CCGame';
import Scheduler from './CCScheduler';
import {autoRelease} from '../load-pipeline/auto-release-utils';
import ComponentScheduler from '../scene-graph/component-scheduler';
import NodeActivator from '../scene-graph/node-activator';
import AnimationSystem from '../3d/framework/animation-system';
import SkinningModelSystem from '../3d/framework/skinning-model-system';
import { getClassByName } from './utils/js';
// const ComponentScheduler = require('./component-scheduler');
// const NodeActivator = require('./node-activator');
@@ -115,8 +120,6 @@ class Director extends EventTarget {
// purge?
this._purgeDirectorInNextLoop = false;
this._winSizeInPoints = null;
// scenes
this._loadingScene = '';
this._scene = null;
@@ -135,6 +138,8 @@ class Director extends EventTarget {
// Action manager
this._actionManager = null;
this._systems = [];
var self = this;
game.on(game.EVENT_SHOW, function () {
self._lastUpdate = performance.now();
@@ -148,7 +153,6 @@ class Director extends EventTarget {
this._lastUpdate = performance.now();
this._paused = false;
this._purgeDirectorInNextLoop = false;
this._winSizeInPoints = cc.size(0, 0);
this._scheduler = new Scheduler();
if (cc.ActionManager) {
@@ -170,42 +174,8 @@ class Director extends EventTarget {
this._compScheduler = new ComponentScheduler();
this._nodeActivator = new NodeActivator();
// Event manager
if (eventManager) {
eventManager.setEnabled(true);
}
// Animation manager
if (cc.AnimationManager) {
this._animationManager = new cc.AnimationManager();
this._scheduler.scheduleUpdate(this._animationManager, Scheduler.PRIORITY_SYSTEM, false);
}
else {
this._animationManager = null;
}
// collision manager
if (cc.CollisionManager) {
this._collisionManager = new cc.CollisionManager();
this._scheduler.scheduleUpdate(this._collisionManager, Scheduler.PRIORITY_SYSTEM, false);
}
else {
this._collisionManager = null;
}
// physics manager
if (cc.PhysicsManager) {
this._physicsManager = new cc.PhysicsManager();
this._scheduler.scheduleUpdate(this._physicsManager, Scheduler.PRIORITY_SYSTEM, false);
}
else {
this._physicsManager = null;
}
// WidgetManager
if (cc._widgetManager) {
cc._widgetManager.init(this);
}
this.registerSystem('animation', AnimationSystem, ['AnimationComponent'], 200);
this.registerSystem('skinning-model', SkinningModelSystem, ['SkinningModelComponent'], 100);
cc.loader.init(this);
}
@@ -315,7 +285,7 @@ class Director extends EventTarget {
/**
* !#en Pause the director's ticker, only involve the game logic execution.
* It won't pause the rendering process nor the event manager.
* If you want to pause the entier game including rendering, audio and event,
* If you want to pause the entier game including rendering, audio and event,
* please use {{#crossLink "Game.pause"}}cc.game.pause{{/crossLink}}
* !#zh 暂停正在运行的场景,该暂停只会停止游戏逻辑执行,但是不会停止渲染和 UI 响应。
* 如果想要更彻底得暂停游戏,包含渲染,音频和事件,请使用 {{#crossLink "Game.pause"}}cc.game.pause{{/crossLink}}。
@@ -373,25 +343,9 @@ class Director extends EventTarget {
if (eventManager)
eventManager.setEnabled(true);
// Action manager
if (this._actionManager){
this._scheduler.scheduleUpdate(this._actionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
// Animation manager
if (this._animationManager) {
this._scheduler.scheduleUpdate(this._animationManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
// Collider manager
if (this._collisionManager) {
this._scheduler.scheduleUpdate(this._collisionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
// Physics manager
if (this._physicsManager) {
this._scheduler.scheduleUpdate(this._physicsManager, cc.Scheduler.PRIORITY_SYSTEM, false);
}
this._systems.forEach((sys) => {
this._scheduler.scheduleUpdate(sys, sys._priority, false);
});
this.startAnimation();
}
@@ -588,8 +542,8 @@ class Director extends EventTarget {
var info = this._getSceneUuid(sceneName);
if (info) {
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
cc.loader.load({ uuid: info.uuid, type: 'uuid' },
onProgress,
cc.loader.load({ uuid: info.uuid, type: 'uuid' },
onProgress,
function (error, asset) {
if (error) {
cc.errorID(1210, sceneName, error.message);
@@ -597,7 +551,7 @@ class Director extends EventTarget {
if (onLoaded) {
onLoaded(error, asset);
}
});
});
}
else {
var error = 'Can not preload the scene "' + sceneName + '" because it is not in the build settings.';
@@ -821,6 +775,41 @@ class Director extends EventTarget {
}
}
/**
* !#en register a system.
* !#zh 注册一个system。
* @method registerSystem
* @param {string} name
* @param {function} cls
* @param {Array} compClsNames
* @param {number} priority
* @return {System}
*/
registerSystem(name, cls, compClsNames, priority) {
let sys = new cls();
sys._id = name;
sys._priority = priority;
compClsNames.forEach((compName) => {
getClassByName(compName).system = sys;
});
this._scheduler.scheduleUpdate(sys, priority, false);
sys.init();
this._systems.push(sys);
return sys;
}
/**
* !#en get a system.
* !#zh 获取一个system。
* @param {string} name
* @return {System}
*/
getSystem(name) {
return this._systems.find((sys) => {
return sys._id === name;
});
}
/**
* !#en Returns the cc.ActionManager associated with this director.
* !#zh 获取和 director 相关联的 cc.ActionManager(动作管理器)。
@@ -846,36 +835,6 @@ class Director extends EventTarget {
}
}
/*
* !#en Returns the cc.AnimationManager associated with this director.
* !#zh 获取和 director 相关联的 cc.AnimationManager(动画管理器)。
* @method getAnimationManager
* @return {AnimationManager}
*/
getAnimationManager () {
return this._animationManager;
}
/**
* !#en Returns the cc.CollisionManager associated with this director.
* !#zh 获取和 director 相关联的 cc.CollisionManager (碰撞管理器)。
* @method getCollisionManager
* @return {CollisionManager}
*/
getCollisionManager () {
return this._collisionManager;
}
/**
* !#en Returns the cc.PhysicsManager associated with this director.
* !#zh 返回与 director 相关联的 cc.PhysicsManager (物理管理器)。
* @method getPhysicsManager
* @return {PhysicsManager}
*/
getPhysicsManager () {
return this._physicsManager;
}
// Loop management
/*
* Starts Animation
@@ -1056,4 +1015,4 @@ Director.EVENT_AFTER_DRAW = "director_after_draw";
let director = cc.director = new Director();
cc.Director = Director;
cc.director = director;
export default director;
export default director;
+2 -2
View File
@@ -32,7 +32,7 @@ const { ccclass, property } = _decorator;
const Destroying = CCObject.Flags.Destroying;
const DontDestroy = CCObject.Flags.DontDestroy;
const Deactivating = CCObject.Flags.Deactivating;
const Deactivating = CCObject.Flags.Deactivating;
const CHILD_ADDED = 'child-added';
const CHILD_REMOVED = 'child-removed';
@@ -591,7 +591,7 @@ export default class BaseNode extends CCObject {
// post call
postfunc(curr);
}
// Avoid memory leak
stack[index] = null;
// Do not repeatly visit child tree, just do post call and continue walk