reformat code

This commit is contained in:
yhh
2020-07-28 16:25:20 +08:00
parent 5994f0bee3
commit 514572f291
103 changed files with 2896 additions and 2839 deletions
+167 -167
View File
@@ -27,9 +27,9 @@ declare module es {
declare module es { declare module es {
class AStarPathfinder { class AStarPathfinder {
static search<T>(graph: IAstarGraph<T>, start: T, goal: T): T[]; static search<T>(graph: IAstarGraph<T>, start: T, goal: T): T[];
static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[];
private static hasKey; private static hasKey;
private static getKey; private static getKey;
static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[];
} }
class AStarNode<T> extends PriorityQueueNode { class AStarNode<T> extends PriorityQueueNode {
data: T; data: T;
@@ -68,9 +68,9 @@ declare module es {
private _nodes; private _nodes;
private _numNodesEverEnqueued; private _numNodesEverEnqueued;
constructor(maxNodes: number); constructor(maxNodes: number);
clear(): void;
readonly count: number; readonly count: number;
readonly maxSize: number; readonly maxSize: number;
clear(): void;
contains(node: T): boolean; contains(node: T): boolean;
enqueue(node: T, priority: number): void; enqueue(node: T, priority: number): void;
dequeue(): T; dequeue(): T;
@@ -103,28 +103,21 @@ declare module es {
} }
declare module es { declare module es {
class Vector2 { class Vector2 {
x: number;
y: number;
private static readonly unitYVector; private static readonly unitYVector;
private static readonly unitXVector; private static readonly unitXVector;
private static readonly unitVector2; private static readonly unitVector2;
private static readonly zeroVector2; private static readonly zeroVector2;
x: number;
y: number;
constructor(x?: number, y?: number);
static readonly zero: Vector2; static readonly zero: Vector2;
static readonly one: Vector2; static readonly one: Vector2;
static readonly unitX: Vector2; static readonly unitX: Vector2;
static readonly unitY: Vector2; static readonly unitY: Vector2;
constructor(x?: number, y?: number);
add(value: Vector2): Vector2;
divide(value: Vector2): Vector2;
multiply(value: Vector2): Vector2;
subtract(value: Vector2): this;
static add(value1: Vector2, value2: Vector2): Vector2; static add(value1: Vector2, value2: Vector2): Vector2;
static divide(value1: Vector2, value2: Vector2): Vector2; static divide(value1: Vector2, value2: Vector2): Vector2;
static multiply(value1: Vector2, value2: Vector2): Vector2; static multiply(value1: Vector2, value2: Vector2): Vector2;
static subtract(value1: Vector2, value2: Vector2): Vector2; static subtract(value1: Vector2, value2: Vector2): Vector2;
normalize(): void;
length(): number;
round(): Vector2;
static normalize(value: Vector2): Vector2; static normalize(value: Vector2): Vector2;
static dot(value1: Vector2, value2: Vector2): number; static dot(value1: Vector2, value2: Vector2): number;
static distanceSquared(value1: Vector2, value2: Vector2): number; static distanceSquared(value1: Vector2, value2: Vector2): number;
@@ -133,6 +126,13 @@ declare module es {
static transform(position: Vector2, matrix: Matrix2D): Vector2; static transform(position: Vector2, matrix: Matrix2D): Vector2;
static distance(value1: Vector2, value2: Vector2): number; static distance(value1: Vector2, value2: Vector2): number;
static negate(value: Vector2): Vector2; static negate(value: Vector2): Vector2;
add(value: Vector2): Vector2;
divide(value: Vector2): Vector2;
multiply(value: Vector2): Vector2;
subtract(value: Vector2): this;
normalize(): void;
length(): number;
round(): Vector2;
equals(other: Vector2): boolean; equals(other: Vector2): boolean;
} }
} }
@@ -185,9 +185,9 @@ declare module es {
} }
class WeightedPathfinder { class WeightedPathfinder {
static search<T>(graph: IWeightedGraph<T>, start: T, goal: T): T[]; static search<T>(graph: IWeightedGraph<T>, start: T, goal: T): T[];
static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[];
private static hasKey; private static hasKey;
private static getKey; private static getKey;
static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[];
} }
} }
declare module es { declare module es {
@@ -228,12 +228,12 @@ declare module es {
declare module es { declare module es {
abstract class Component { abstract class Component {
entity: Entity; entity: Entity;
readonly transform: Transform;
enabled: boolean;
updateOrder: number;
updateInterval: number; updateInterval: number;
readonly transform: Transform;
private _enabled; private _enabled;
enabled: boolean;
private _updateOrder; private _updateOrder;
updateOrder: number;
initialize(): void; initialize(): void;
onAddedToEntity(): void; onAddedToEntity(): void;
onRemovedFromEntity(): void; onRemovedFromEntity(): void;
@@ -252,27 +252,27 @@ declare module es {
static emitter: Emitter<CoreEvents>; static emitter: Emitter<CoreEvents>;
static graphicsDevice: GraphicsDevice; static graphicsDevice: GraphicsDevice;
static content: ContentManager; static content: ContentManager;
static readonly Instance: Core;
static _instance: Core; static _instance: Core;
_scene: Scene;
_nextScene: Scene; _nextScene: Scene;
_sceneTransition: SceneTransition; _sceneTransition: SceneTransition;
_globalManagers: GlobalManager[]; _globalManagers: GlobalManager[];
static scene: Scene;
constructor(); constructor();
private onAddToStage; static readonly Instance: Core;
onOrientationChanged(): void; _scene: Scene;
protected onGraphicsDeviceReset(): void; static scene: Scene;
protected initialize(): void;
protected update(): Promise<void>;
draw(): Promise<void>;
startDebugUpdate(): void;
endDebugUpdate(): void;
onSceneChanged(): void;
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T; static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
static registerGlobalManager(manager: es.GlobalManager): void; static registerGlobalManager(manager: es.GlobalManager): void;
static unregisterGlobalManager(manager: es.GlobalManager): void; static unregisterGlobalManager(manager: es.GlobalManager): void;
static getGlobalManager<T extends es.GlobalManager>(type: any): T; static getGlobalManager<T extends es.GlobalManager>(type: any): T;
onOrientationChanged(): void;
draw(): Promise<void>;
startDebugUpdate(): void;
endDebugUpdate(): void;
onSceneChanged(): void;
protected onGraphicsDeviceReset(): void;
protected initialize(): void;
protected update(): Promise<void>;
private onAddToStage;
} }
} }
declare module es { declare module es {
@@ -290,16 +290,17 @@ declare module es {
readonly id: number; readonly id: number;
readonly transform: Transform; readonly transform: Transform;
readonly components: ComponentList; readonly components: ComponentList;
tag: number;
updateInterval: number; updateInterval: number;
enabled: boolean; componentBits: BitSet;
updateOrder: number; constructor(name: string);
_isDestroyed: boolean; _isDestroyed: boolean;
readonly isDestroyed: boolean; readonly isDestroyed: boolean;
componentBits: BitSet;
private _tag; private _tag;
tag: number;
private _enabled; private _enabled;
enabled: boolean;
private _updateOrder; private _updateOrder;
updateOrder: number;
parent: Transform; parent: Transform;
readonly childCount: number; readonly childCount: number;
position: Vector2; position: Vector2;
@@ -313,7 +314,6 @@ declare module es {
readonly worldInverseTransform: Matrix2D; readonly worldInverseTransform: Matrix2D;
readonly localToWorldTransform: Matrix2D; readonly localToWorldTransform: Matrix2D;
readonly worldToLocalTransform: Matrix2D; readonly worldToLocalTransform: Matrix2D;
constructor(name: string);
onTransformChanged(comp: transform.Component): void; onTransformChanged(comp: transform.Component): void;
setTag(tag: number): Entity; setTag(tag: number): Entity;
setEnabled(isEnabled: boolean): this; setEnabled(isEnabled: boolean): this;
@@ -322,7 +322,6 @@ declare module es {
detachFromScene(): void; detachFromScene(): void;
attachToScene(newScene: Scene): void; attachToScene(newScene: Scene): void;
clone(position?: Vector2): Entity; clone(position?: Vector2): Entity;
protected copyFrom(entity: Entity): void;
onAddedToScene(): void; onAddedToScene(): void;
onRemovedFromScene(): void; onRemovedFromScene(): void;
update(): void; update(): void;
@@ -336,6 +335,7 @@ declare module es {
removeAllComponents(): void; removeAllComponents(): void;
compareTo(other: Entity): number; compareTo(other: Entity): number;
toString(): string; toString(): string;
protected copyFrom(entity: Entity): void;
} }
} }
declare module es { declare module es {
@@ -349,8 +349,8 @@ declare module es {
_renderers: Renderer[]; _renderers: Renderer[];
readonly _postProcessors: PostProcessor[]; readonly _postProcessors: PostProcessor[];
_didSceneBegin: any; _didSceneBegin: any;
static createWithDefaultRenderer(): Scene;
constructor(); constructor();
static createWithDefaultRenderer(): Scene;
initialize(): void; initialize(): void;
onStart(): Promise<void>; onStart(): Promise<void>;
unload(): void; unload(): void;
@@ -397,20 +397,6 @@ declare module es {
} }
class Transform extends HashObject { class Transform extends HashObject {
readonly entity: Entity; readonly entity: Entity;
parent: Transform;
readonly childCount: number;
position: Vector2;
localPosition: Vector2;
rotation: number;
rotationDegrees: number;
localRotation: number;
localRotationDegrees: number;
scale: Vector2;
localScale: Vector2;
readonly worldInverseTransform: Matrix2D;
readonly localToWorldTransform: Matrix2D;
readonly worldToLocalTransform: Matrix2D;
_parent: Transform;
hierarchyDirty: DirtyType; hierarchyDirty: DirtyType;
_localDirty: boolean; _localDirty: boolean;
_localPositionDirty: boolean; _localPositionDirty: boolean;
@@ -421,19 +407,33 @@ declare module es {
_worldInverseDirty: boolean; _worldInverseDirty: boolean;
_localTransform: Matrix2D; _localTransform: Matrix2D;
_worldTransform: Matrix2D; _worldTransform: Matrix2D;
_worldToLocalTransform: Matrix2D;
_worldInverseTransform: Matrix2D;
_rotationMatrix: Matrix2D; _rotationMatrix: Matrix2D;
_translationMatrix: Matrix2D; _translationMatrix: Matrix2D;
_scaleMatrix: Matrix2D; _scaleMatrix: Matrix2D;
_position: Vector2;
_scale: Vector2;
_rotation: number;
_localPosition: Vector2;
_localScale: Vector2;
_localRotation: number;
_children: Transform[]; _children: Transform[];
constructor(entity: Entity); constructor(entity: Entity);
readonly childCount: number;
rotationDegrees: number;
localRotationDegrees: number;
readonly localToWorldTransform: Matrix2D;
_parent: Transform;
parent: Transform;
_worldToLocalTransform: Matrix2D;
readonly worldToLocalTransform: Matrix2D;
_worldInverseTransform: Matrix2D;
readonly worldInverseTransform: Matrix2D;
_position: Vector2;
position: Vector2;
_scale: Vector2;
scale: Vector2;
_rotation: number;
rotation: number;
_localPosition: Vector2;
localPosition: Vector2;
_localScale: Vector2;
localScale: Vector2;
_localRotation: number;
localRotation: number;
getChild(index: number): Transform; getChild(index: number): Transform;
setParent(parent: Transform): Transform; setParent(parent: Transform): Transform;
setPosition(x: number, y: number): Transform; setPosition(x: number, y: number): Transform;
@@ -465,23 +465,7 @@ declare module es {
bottom: number; bottom: number;
} }
class Camera extends Component { class Camera extends Component {
position: Vector2;
rotation: number;
zoom: number;
minimumZoom: number;
maximumZoom: number;
readonly bounds: Rectangle;
readonly transformMatrix: Matrix2D;
readonly inverseTransformMatrix: Matrix2D;
origin: Vector2;
_zoom: any;
_minimumZoom: number;
_maximumZoom: number;
_bounds: Rectangle;
_inset: CameraInset; _inset: CameraInset;
_transformMatrix: Matrix2D;
_inverseTransformMatrix: Matrix2D;
_origin: Vector2;
_areMatrixedDirty: boolean; _areMatrixedDirty: boolean;
_areBoundsDirty: boolean; _areBoundsDirty: boolean;
_isProjectionMatrixDirty: boolean; _isProjectionMatrixDirty: boolean;
@@ -496,8 +480,23 @@ declare module es {
_cameraStyle: CameraStyle; _cameraStyle: CameraStyle;
_worldSpaceDeadZone: Rectangle; _worldSpaceDeadZone: Rectangle;
constructor(targetEntity?: Entity, cameraStyle?: CameraStyle); constructor(targetEntity?: Entity, cameraStyle?: CameraStyle);
position: Vector2;
rotation: number;
_zoom: any;
zoom: number;
_minimumZoom: number;
minimumZoom: number;
_maximumZoom: number;
maximumZoom: number;
_bounds: Rectangle;
readonly bounds: Rectangle;
_transformMatrix: Matrix2D;
readonly transformMatrix: Matrix2D;
_inverseTransformMatrix: Matrix2D;
readonly inverseTransformMatrix: Matrix2D;
_origin: Vector2;
origin: Vector2;
onSceneSizeChanged(newWidth: number, newHeight: number): void; onSceneSizeChanged(newWidth: number, newHeight: number): void;
protected updateMatrixes(): void;
setInset(left: number, right: number, top: number, bottom: number): Camera; setInset(left: number, right: number, top: number, bottom: number): Camera;
setPosition(position: Vector2): this; setPosition(position: Vector2): this;
setRotation(rotation: number): Camera; setRotation(rotation: number): Camera;
@@ -516,6 +515,7 @@ declare module es {
updateFollow(): void; updateFollow(): void;
follow(targetEntity: Entity, cameraStyle?: CameraStyle): void; follow(targetEntity: Entity, cameraStyle?: CameraStyle): void;
setCenteredDeadzone(width: number, height: number): void; setCenteredDeadzone(width: number, height: number): void;
protected updateMatrixes(): void;
} }
} }
declare module es { declare module es {
@@ -540,28 +540,28 @@ declare module es {
declare module es { declare module es {
abstract class RenderableComponent extends Component implements IRenderable { abstract class RenderableComponent extends Component implements IRenderable {
displayObject: egret.DisplayObject; displayObject: egret.DisplayObject;
color: number;
protected _areBoundsDirty: boolean;
readonly width: number; readonly width: number;
readonly height: number; readonly height: number;
readonly bounds: Rectangle;
renderLayer: number;
color: number;
localOffset: Vector2;
isVisible: boolean;
protected _localOffset: Vector2; protected _localOffset: Vector2;
localOffset: Vector2;
protected _renderLayer: number; protected _renderLayer: number;
renderLayer: number;
protected _bounds: Rectangle; protected _bounds: Rectangle;
readonly bounds: Rectangle;
private _isVisible; private _isVisible;
protected _areBoundsDirty: boolean; isVisible: boolean;
onEntityTransformChanged(comp: transform.Component): void; onEntityTransformChanged(comp: transform.Component): void;
abstract render(camera: Camera): any; abstract render(camera: Camera): any;
protected onBecameVisible(): void;
protected onBecameInvisible(): void;
isVisibleFromCamera(camera: Camera): boolean; isVisibleFromCamera(camera: Camera): boolean;
setRenderLayer(renderLayer: number): RenderableComponent; setRenderLayer(renderLayer: number): RenderableComponent;
setColor(color: number): RenderableComponent; setColor(color: number): RenderableComponent;
setLocalOffset(offset: Vector2): RenderableComponent; setLocalOffset(offset: Vector2): RenderableComponent;
sync(camera: Camera): void; sync(camera: Camera): void;
toString(): string; toString(): string;
protected onBecameVisible(): void;
protected onBecameInvisible(): void;
} }
} }
declare module es { declare module es {
@@ -575,13 +575,13 @@ declare module es {
} }
declare module es { declare module es {
class SpriteRenderer extends RenderableComponent { class SpriteRenderer extends RenderableComponent {
readonly bounds: Rectangle;
origin: Vector2;
originNormalized: Vector2;
sprite: Sprite;
protected _origin: Vector2;
protected _sprite: Sprite;
constructor(sprite?: Sprite | egret.Texture); constructor(sprite?: Sprite | egret.Texture);
readonly bounds: Rectangle;
originNormalized: Vector2;
protected _origin: Vector2;
origin: Vector2;
protected _sprite: Sprite;
sprite: Sprite;
setSprite(sprite: Sprite): SpriteRenderer; setSprite(sprite: Sprite): SpriteRenderer;
setOrigin(origin: Vector2): SpriteRenderer; setOrigin(origin: Vector2): SpriteRenderer;
setOriginNormalized(value: Vector2): SpriteRenderer; setOriginNormalized(value: Vector2): SpriteRenderer;
@@ -593,9 +593,9 @@ declare module es {
protected sourceRect: Rectangle; protected sourceRect: Rectangle;
protected leftTexture: egret.Bitmap; protected leftTexture: egret.Bitmap;
protected rightTexture: egret.Bitmap; protected rightTexture: egret.Bitmap;
constructor(sprite: Sprite);
scrollX: number; scrollX: number;
scrollY: number; scrollY: number;
constructor(sprite: Sprite);
render(camera: es.Camera): void; render(camera: es.Camera): void;
} }
} }
@@ -647,12 +647,12 @@ declare module es {
currentAnimation: SpriteAnimation; currentAnimation: SpriteAnimation;
currentAnimationName: string; currentAnimationName: string;
currentFrame: number; currentFrame: number;
readonly isRunning: boolean;
readonly animations: Map<string, SpriteAnimation>;
private _animations;
_elapsedTime: number; _elapsedTime: number;
_loopMode: LoopMode; _loopMode: LoopMode;
constructor(sprite?: Sprite); constructor(sprite?: Sprite);
readonly isRunning: boolean;
private _animations;
readonly animations: Map<string, SpriteAnimation>;
update(): void; update(): void;
addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator; addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator;
play(name: string, loopMode?: LoopMode): void; play(name: string, loopMode?: LoopMode): void;
@@ -689,22 +689,22 @@ declare module es {
declare module es { declare module es {
abstract class Collider extends Component { abstract class Collider extends Component {
shape: Shape; shape: Shape;
localOffset: Vector2;
readonly absolutePosition: Vector2;
readonly rotation: number;
isTrigger: boolean; isTrigger: boolean;
physicsLayer: number; physicsLayer: number;
collidesWithLayers: number; collidesWithLayers: number;
shouldColliderScaleAndRotateWithTransform: boolean; shouldColliderScaleAndRotateWithTransform: boolean;
readonly bounds: Rectangle;
registeredPhysicsBounds: Rectangle; registeredPhysicsBounds: Rectangle;
protected _colliderRequiresAutoSizing: any;
protected _localOffset: Vector2;
_localOffsetLength: number; _localOffsetLength: number;
protected _isParentEntityAddedToScene: any;
protected _isColliderRegistered: any;
_isPositionDirty: boolean; _isPositionDirty: boolean;
_isRotationDirty: boolean; _isRotationDirty: boolean;
protected _colliderRequiresAutoSizing: any;
protected _isParentEntityAddedToScene: any;
protected _isColliderRegistered: any;
readonly absolutePosition: Vector2;
readonly rotation: number;
readonly bounds: Rectangle;
protected _localOffset: Vector2;
localOffset: Vector2;
setLocalOffset(offset: Vector2): Collider; setLocalOffset(offset: Vector2): Collider;
setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider; setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider;
onAddedToEntity(): void; onAddedToEntity(): void;
@@ -721,9 +721,9 @@ declare module es {
} }
declare module es { declare module es {
class BoxCollider extends Collider { class BoxCollider extends Collider {
constructor();
width: number; width: number;
height: number; height: number;
constructor();
setSize(width: number, height: number): this; setSize(width: number, height: number): this;
setWidth(width: number): BoxCollider; setWidth(width: number): BoxCollider;
setHeight(height: number): void; setHeight(height: number): void;
@@ -732,8 +732,8 @@ declare module es {
} }
declare module es { declare module es {
class CircleCollider extends Collider { class CircleCollider extends Collider {
radius: number;
constructor(radius?: number); constructor(radius?: number);
radius: number;
setRadius(radius: number): CircleCollider; setRadius(radius: number): CircleCollider;
toString(): string; toString(): string;
} }
@@ -745,12 +745,12 @@ declare module es {
} }
declare module es { declare module es {
class EntitySystem { class EntitySystem {
private _scene;
private _entities; private _entities;
constructor(matcher?: Matcher);
private _scene;
scene: Scene;
private _matcher; private _matcher;
readonly matcher: Matcher; readonly matcher: Matcher;
scene: Scene;
constructor(matcher?: Matcher);
initialize(): void; initialize(): void;
onChanged(entity: Entity): void; onChanged(entity: Entity): void;
add(entity: Entity): void; add(entity: Entity): void;
@@ -783,8 +783,8 @@ declare module es {
declare module es { declare module es {
abstract class ProcessingSystem extends EntitySystem { abstract class ProcessingSystem extends EntitySystem {
onChanged(entity: Entity): void; onChanged(entity: Entity): void;
protected process(entities: Entity[]): void;
abstract processSystem(): any; abstract processSystem(): any;
protected process(entities: Entity[]): void;
} }
} }
declare module es { declare module es {
@@ -796,12 +796,12 @@ declare module es {
andNot(bs: BitSet): void; andNot(bs: BitSet): void;
cardinality(): number; cardinality(): number;
clear(pos?: number): void; clear(pos?: number): void;
private ensure;
get(pos: number): boolean; get(pos: number): boolean;
intersects(set: BitSet): boolean; intersects(set: BitSet): boolean;
isEmpty(): boolean; isEmpty(): boolean;
nextSetBit(from: number): number; nextSetBit(from: number): number;
set(pos: number, value?: boolean): void; set(pos: number, value?: boolean): void;
private ensure;
} }
} }
declare module es { declare module es {
@@ -879,13 +879,13 @@ declare module es {
onComponentRemoved(entity: Entity): void; onComponentRemoved(entity: Entity): void;
onEntityAdded(entity: Entity): void; onEntityAdded(entity: Entity): void;
onEntityRemoved(entity: Entity): void; onEntityRemoved(entity: Entity): void;
protected notifyEntityChanged(entity: Entity): void;
protected removeFromProcessors(entity: Entity): void;
begin(): void; begin(): void;
update(): void; update(): void;
lateUpdate(): void; lateUpdate(): void;
end(): void; end(): void;
getProcessor<T extends EntitySystem>(): T; getProcessor<T extends EntitySystem>(): T;
protected notifyEntityChanged(entity: Entity): void;
protected removeFromProcessors(entity: Entity): void;
} }
} }
declare module es { declare module es {
@@ -939,13 +939,13 @@ declare module es {
} }
} }
declare class StringUtils { declare class StringUtils {
private static specialSigns;
static matchChineseWord(str: string): string[]; static matchChineseWord(str: string): string[];
static lTrim(target: string): string; static lTrim(target: string): string;
static rTrim(target: string): string; static rTrim(target: string): string;
static trim(target: string): string; static trim(target: string): string;
static isWhiteSpace(str: string): boolean; static isWhiteSpace(str: string): boolean;
static replaceMatch(mainStr: string, targetStr: string, replaceStr: string, caseMark?: boolean): string; static replaceMatch(mainStr: string, targetStr: string, replaceStr: string, caseMark?: boolean): string;
private static specialSigns;
static htmlSpecialChars(str: string, reversion?: boolean): string; static htmlSpecialChars(str: string, reversion?: boolean): string;
static zfill(str: string, width?: number): string; static zfill(str: string, width?: number): string;
static reverse(str: string): string; static reverse(str: string): string;
@@ -969,8 +969,8 @@ declare module es {
static deltaTime: number; static deltaTime: number;
static timeScale: number; static timeScale: number;
static frameCount: number; static frameCount: number;
private static _lastTime;
static _timeSinceSceneLoad: any; static _timeSinceSceneLoad: any;
private static _lastTime;
static update(currentTime: number): void; static update(currentTime: number): void;
static sceneChanged(): void; static sceneChanged(): void;
static checkEvery(interval: number): boolean; static checkEvery(interval: number): boolean;
@@ -998,10 +998,10 @@ declare module es {
} }
declare module es { declare module es {
class GraphicsDevice { class GraphicsDevice {
private _viewport;
readonly viewport: Viewport;
graphicsCapabilities: GraphicsCapabilities; graphicsCapabilities: GraphicsCapabilities;
constructor(); constructor();
private _viewport;
readonly viewport: Viewport;
private setup; private setup;
} }
} }
@@ -1009,15 +1009,15 @@ declare module es {
class Viewport { class Viewport {
private _x; private _x;
private _y; private _y;
private _width;
private _height;
private _minDepth; private _minDepth;
private _maxDepth; private _maxDepth;
height: number; constructor(x: number, y: number, width: number, height: number);
private _width;
width: number; width: number;
private _height;
height: number;
readonly aspectRatio: number; readonly aspectRatio: number;
bounds: Rectangle; bounds: Rectangle;
constructor(x: number, y: number, width: number, height: number);
} }
} }
declare module es { declare module es {
@@ -1035,17 +1035,17 @@ declare module es {
} }
declare module es { declare module es {
class PostProcessor { class PostProcessor {
static default_vert: string;
enabled: boolean; enabled: boolean;
effect: egret.Filter; effect: egret.Filter;
scene: Scene; scene: Scene;
shape: egret.Shape; shape: egret.Shape;
static default_vert: string;
constructor(effect?: egret.Filter); constructor(effect?: egret.Filter);
onAddedToScene(scene: Scene): void; onAddedToScene(scene: Scene): void;
process(): void; process(): void;
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
protected drawFullscreenQuad(): void;
unload(): void; unload(): void;
protected drawFullscreenQuad(): void;
} }
} }
declare module es { declare module es {
@@ -1060,11 +1060,11 @@ declare module es {
protected constructor(renderOrder: number, camera?: Camera); protected constructor(renderOrder: number, camera?: Camera);
onAddedToScene(scene: Scene): void; onAddedToScene(scene: Scene): void;
unload(): void; unload(): void;
protected beginRender(cam: Camera): void;
abstract render(scene: Scene): any; abstract render(scene: Scene): any;
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
compareTo(other: Renderer): number; compareTo(other: Renderer): number;
protected beginRender(cam: Camera): void;
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
} }
} }
declare module es { declare module es {
@@ -1081,33 +1081,33 @@ declare module es {
declare module es { declare module es {
class PolyLight extends RenderableComponent { class PolyLight extends RenderableComponent {
power: number; power: number;
protected _radius: number;
private _lightEffect; private _lightEffect;
private _indices; private _indices;
radius: number;
constructor(radius: number, color: number, power: number); constructor(radius: number, color: number, power: number);
private computeTriangleIndices; protected _radius: number;
radius: number;
setRadius(radius: number): void; setRadius(radius: number): void;
render(camera: Camera): void; render(camera: Camera): void;
reset(): void; reset(): void;
private computeTriangleIndices;
} }
} }
declare module es { declare module es {
abstract class SceneTransition { abstract class SceneTransition {
private _hasPreviousSceneRender;
loadsNewScene: boolean; loadsNewScene: boolean;
isNewSceneLoaded: boolean; isNewSceneLoaded: boolean;
protected sceneLoadAction: Function;
onScreenObscured: Function; onScreenObscured: Function;
onTransitionCompleted: Function; onTransitionCompleted: Function;
readonly hasPreviousSceneRender: boolean; protected sceneLoadAction: Function;
constructor(sceneLoadAction: Function); constructor(sceneLoadAction: Function);
private _hasPreviousSceneRender;
readonly hasPreviousSceneRender: boolean;
preRender(): void; preRender(): void;
render(): void; render(): void;
onBeginTransition(): Promise<void>; onBeginTransition(): Promise<void>;
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<boolean>;
protected transitionComplete(): void; protected transitionComplete(): void;
protected loadNextScene(): Promise<void>; protected loadNextScene(): Promise<void>;
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<boolean>;
} }
} }
declare module es { declare module es {
@@ -1125,13 +1125,13 @@ declare module es {
} }
declare module es { declare module es {
class WindTransition extends SceneTransition { class WindTransition extends SceneTransition {
duration: number;
easeType: (t: number) => number;
private _mask; private _mask;
private _windEffect; private _windEffect;
duration: number; constructor(sceneLoadAction: Function);
windSegments: number; windSegments: number;
size: number; size: number;
easeType: (t: number) => number;
constructor(sceneLoadAction: Function);
onBeginTransition(): Promise<void>; onBeginTransition(): Promise<void>;
} }
} }
@@ -1202,14 +1202,14 @@ declare module es {
readonly center: Vector2; readonly center: Vector2;
location: Vector2; location: Vector2;
size: Vector2; size: Vector2;
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
static rectEncompassingPoints(points: Vector2[]): Rectangle;
intersects(value: egret.Rectangle): boolean; intersects(value: egret.Rectangle): boolean;
containsRect(value: Rectangle): boolean; containsRect(value: Rectangle): boolean;
getHalfSize(): Vector2; getHalfSize(): Vector2;
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2; getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2;
getClosestPointOnBoundsToOrigin(): Vector2; getClosestPointOnBoundsToOrigin(): Vector2;
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void; calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
static rectEncompassingPoints(points: Vector2[]): Rectangle;
} }
} }
declare module es { declare module es {
@@ -1259,9 +1259,9 @@ declare module es {
} }
declare module es { declare module es {
class Physics { class Physics {
private static _spatialHash;
static spatialHashCellSize: number; static spatialHashCellSize: number;
static readonly allLayers: number; static readonly allLayers: number;
private static _spatialHash;
static reset(): void; static reset(): void;
static clear(): void; static clear(): void;
static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number;
@@ -1288,21 +1288,21 @@ declare module es {
declare module es { declare module es {
class Polygon extends Shape { class Polygon extends Shape {
points: Vector2[]; points: Vector2[];
readonly edgeNormals: Vector2[];
_areEdgeNormalsDirty: boolean; _areEdgeNormalsDirty: boolean;
_edgeNormals: Vector2[];
_originalPoints: Vector2[]; _originalPoints: Vector2[];
_polygonCenter: Vector2; _polygonCenter: Vector2;
isBox: boolean; isBox: boolean;
isUnrotated: boolean; isUnrotated: boolean;
constructor(points: Vector2[], isBox?: boolean); constructor(points: Vector2[], isBox?: boolean);
setPoints(points: Vector2[]): void; _edgeNormals: Vector2[];
recalculateCenterAndEdgeNormals(): void; readonly edgeNormals: Vector2[];
buildEdgeNormals(): void;
static buildSymmetricalPolygon(vertCount: number, radius: number): any[]; static buildSymmetricalPolygon(vertCount: number, radius: number): any[];
static recenterPolygonVerts(points: Vector2[]): void; static recenterPolygonVerts(points: Vector2[]): void;
static findPolygonCenter(points: Vector2[]): Vector2; static findPolygonCenter(points: Vector2[]): Vector2;
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2; static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2;
setPoints(points: Vector2[]): void;
recalculateCenterAndEdgeNormals(): void;
buildEdgeNormals(): void;
recalculateBounds(collider: Collider): void; recalculateBounds(collider: Collider): void;
overlaps(other: Shape): any; overlaps(other: Shape): any;
collidesWithShape(other: Shape, result: CollisionResult): boolean; collidesWithShape(other: Shape, result: CollisionResult): boolean;
@@ -1370,24 +1370,24 @@ declare module es {
_cellDict: NumberDictionary; _cellDict: NumberDictionary;
_tempHashSet: Collider[]; _tempHashSet: Collider[];
constructor(cellSize?: number); constructor(cellSize?: number);
private cellCoords;
private cellAtPosition;
register(collider: Collider): void; register(collider: Collider): void;
remove(collider: Collider): void; remove(collider: Collider): void;
removeWithBruteForce(obj: Collider): void; removeWithBruteForce(obj: Collider): void;
clear(): void; clear(): void;
debugDraw(secondsToDisplay: number, textScale?: number): void; debugDraw(secondsToDisplay: number, textScale?: number): void;
private debugDrawCellDetails;
aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[]; aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[];
overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number;
private cellCoords;
private cellAtPosition;
private debugDrawCellDetails;
} }
class NumberDictionary { class NumberDictionary {
_store: Map<string, Collider[]>; _store: Map<string, Collider[]>;
private getKey;
add(x: number, y: number, list: Collider[]): void; add(x: number, y: number, list: Collider[]): void;
remove(obj: Collider): void; remove(obj: Collider): void;
tryGetValue(x: number, y: number): Collider[]; tryGetValue(x: number, y: number): Collider[];
clear(): void; clear(): void;
private getKey;
} }
class RaycastResultParser { class RaycastResultParser {
} }
@@ -1412,8 +1412,8 @@ declare class Base64Utils {
private static _keyStr; private static _keyStr;
private static _keyAll; private static _keyAll;
static encode: (input: any) => string; static encode: (input: any) => string;
private static _utf8_encode;
static decode(input: any, isNotStr?: boolean): string; static decode(input: any, isNotStr?: boolean): string;
private static _utf8_encode;
private static _utf8_decode; private static _utf8_decode;
private static getConfKey; private static getConfKey;
} }
@@ -1450,9 +1450,9 @@ declare module es {
} }
declare module es { declare module es {
class GlobalManager { class GlobalManager {
_enabled: boolean;
enabled: boolean; enabled: boolean;
setEnabled(isEnabled: boolean): void; setEnabled(isEnabled: boolean): void;
_enabled: boolean;
onEnabled(): void; onEnabled(): void;
onDisabled(): void; onDisabled(): void;
update(): void; update(): void;
@@ -1470,31 +1470,29 @@ declare module es {
class Input { class Input {
private static _init; private static _init;
private static _previousTouchState; private static _previousTouchState;
private static _gameTouchs;
private static _resolutionOffset; private static _resolutionOffset;
private static _resolutionScale;
private static _touchIndex; private static _touchIndex;
private static _gameTouchs;
static readonly gameTouchs: TouchState[];
private static _resolutionScale;
static readonly resolutionScale: Vector2;
private static _totalTouchCount; private static _totalTouchCount;
static readonly totalTouchCount: number;
static readonly touchPosition: Vector2; static readonly touchPosition: Vector2;
static maxSupportedTouch: number; static maxSupportedTouch: number;
static readonly resolutionScale: Vector2;
static readonly totalTouchCount: number;
static readonly gameTouchs: TouchState[];
static readonly touchPositionDelta: Vector2; static readonly touchPositionDelta: Vector2;
static initialize(): void; static initialize(): void;
static scaledPosition(position: Vector2): Vector2;
private static initTouchCache; private static initTouchCache;
private static touchBegin; private static touchBegin;
private static touchMove; private static touchMove;
private static touchEnd; private static touchEnd;
private static setpreviousTouchState; private static setpreviousTouchState;
static scaledPosition(position: Vector2): Vector2;
} }
} }
declare class KeyboardUtils { declare class KeyboardUtils {
static TYPE_KEY_DOWN: number; static TYPE_KEY_DOWN: number;
static TYPE_KEY_UP: number; static TYPE_KEY_UP: number;
private static keyDownDict;
private static keyUpDict;
static A: string; static A: string;
static B: string; static B: string;
static C: string; static C: string;
@@ -1566,13 +1564,15 @@ declare class KeyboardUtils {
static NUM_LOCK: string; static NUM_LOCK: string;
static SCROLL_LOCK: string; static SCROLL_LOCK: string;
static WINDOWS: string; static WINDOWS: string;
private static keyDownDict;
private static keyUpDict;
static init(): void; static init(): void;
private static onKeyDonwHander;
private static onKeyUpHander;
static registerKey(key: string, fun: Function, thisObj: any, type?: number, ...args: any[]): void; static registerKey(key: string, fun: Function, thisObj: any, type?: number, ...args: any[]): void;
static unregisterKey(key: string, type?: number): void; static unregisterKey(key: string, type?: number): void;
private static keyCodeToString;
static destroy(): void; static destroy(): void;
private static onKeyDonwHander;
private static onKeyUpHander;
private static keyCodeToString;
} }
declare module es { declare module es {
class ListPool { class ListPool {
@@ -1609,11 +1609,11 @@ declare class RandomUtils {
static randint(a: number, b: number): number; static randint(a: number, b: number): number;
static randnum(a: number, b: number): number; static randnum(a: number, b: number): number;
static shuffle(array: any[]): any[]; static shuffle(array: any[]): any[];
private static _randomCompare;
static choice(sequence: any): any; static choice(sequence: any): any;
static sample(sequence: any[], num: number): any[]; static sample(sequence: any[], num: number): any[];
static random(): number; static random(): number;
static boolean(chance?: number): boolean; static boolean(chance?: number): boolean;
private static _randomCompare;
} }
declare module es { declare module es {
class RectangleExt { class RectangleExt {
@@ -1625,9 +1625,9 @@ declare module es {
triangleIndices: number[]; triangleIndices: number[];
private _triPrev; private _triPrev;
private _triNext; private _triNext;
static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean;
triangulate(points: Vector2[], arePointsCCW?: boolean): void; triangulate(points: Vector2[], arePointsCCW?: boolean): void;
private initialize; private initialize;
static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean;
} }
} }
declare module es { declare module es {
@@ -1689,12 +1689,12 @@ declare namespace stopwatch {
getCompletedAndPendingSlices(): Slice[]; getCompletedAndPendingSlices(): Slice[];
getPendingSlice(): Slice; getPendingSlice(): Slice;
getTime(): number; getTime(): number;
private calculatePendingSlice;
private caculateStopwatchTime;
private getSystemTimeOfCurrentStopwatchTime;
reset(): void; reset(): void;
start(forceReset?: boolean): void; start(forceReset?: boolean): void;
stop(recordPendingSlice?: boolean): number; stop(recordPendingSlice?: boolean): number;
private calculatePendingSlice;
private caculateStopwatchTime;
private getSystemTimeOfCurrentStopwatchTime;
private recordPendingSlice; private recordPendingSlice;
} }
type GetTimeFunc = () => number; type GetTimeFunc = () => number;
@@ -1721,14 +1721,14 @@ declare module es {
static readonly barPadding: number; static readonly barPadding: number;
static readonly autoAdjustDelay: number; static readonly autoAdjustDelay: number;
private static _instance; private static _instance;
static readonly Instance: TimeRuler; targetSampleFrames: number;
width: number;
enabled: true;
showLog: boolean;
private _frameKey; private _frameKey;
private _logKey; private _logKey;
private _logs; private _logs;
private sampleFrames; private sampleFrames;
targetSampleFrames: number;
width: number;
enabled: true;
private _position; private _position;
private _prevLog; private _prevLog;
private _curLog; private _curLog;
@@ -1737,16 +1737,16 @@ declare module es {
private stopwacth; private stopwacth;
private _markerNameToIdMap; private _markerNameToIdMap;
private _updateCount; private _updateCount;
showLog: boolean;
private _frameAdjust; private _frameAdjust;
constructor(); constructor();
private onGraphicsDeviceReset; static readonly Instance: TimeRuler;
startFrame(): void; startFrame(): void;
beginMark(markerName: string, color: number, barIndex?: number): void; beginMark(markerName: string, color: number, barIndex?: number): void;
endMark(markerName: string, barIndex?: number): void; endMark(markerName: string, barIndex?: number): void;
getAverageTime(barIndex: number, markerName: string): number; getAverageTime(barIndex: number, markerName: string): number;
resetLog(): void; resetLog(): void;
render(position?: Vector2, width?: number): void; render(position?: Vector2, width?: number): void;
private onGraphicsDeviceReset;
} }
class FrameLog { class FrameLog {
bars: MarkerCollection[]; bars: MarkerCollection[];
+547 -533
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -43,6 +43,27 @@ module es {
return foundPath ? this.recontructPath(cameFrom, start, goal) : null; return foundPath ? this.recontructPath(cameFrom, start, goal) : null;
} }
/**
* 从cameFrom字典重新构造路径
* @param cameFrom
* @param start
* @param goal
*/
public static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[] {
let path = [];
let current = goal;
path.push(goal);
while (current != start) {
current = this.getKey(cameFrom, current);
path.push(current);
}
path.reverse();
return path;
}
private static hasKey<T>(map: Map<T, number>, compareKey: T) { private static hasKey<T>(map: Map<T, number>, compareKey: T) {
let iterator = map.keys(); let iterator = map.keys();
let r: IteratorResult<T>; let r: IteratorResult<T>;
@@ -66,27 +87,6 @@ module es {
return null; return null;
} }
/**
* 从cameFrom字典重新构造路径
* @param cameFrom
* @param start
* @param goal
*/
public static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[]{
let path = [];
let current = goal;
path.push(goal);
while (current != start){
current = this.getKey(cameFrom, current);
path.push(current);
}
path.reverse();
return path;
}
} }
/** /**
@@ -8,12 +8,14 @@ module es {
* @param node * @param node
*/ */
getNeighbors(node: T): Array<T>; getNeighbors(node: T): Array<T>;
/** /**
* 计算从从from到to的成本 * 计算从从from到to的成本
* @param from * @param from
* @param to * @param to
*/ */
cost(from: T, to: T): number; cost(from: T, to: T): number;
/** /**
* 计算从node到to的启发式。参见WeightedGridGraph了解常用的Manhatten方法。 * 计算从node到to的启发式。参见WeightedGridGraph了解常用的Manhatten方法。
* @param node * @param node
@@ -19,15 +19,6 @@ module es {
this._numNodesEverEnqueued = 0; this._numNodesEverEnqueued = 0;
} }
/**
* 从队列中删除每个节点。
* O(n)复杂度 所有尽可能少调用该方法
*/
public clear() {
this._nodes.splice(1, this._numNodes);
this._numNodes = 0;
}
/** /**
* 返回队列中的节点数。 * 返回队列中的节点数。
* O(1)复杂度 * O(1)复杂度
@@ -44,6 +35,15 @@ module es {
return this._nodes.length - 1; return this._nodes.length - 1;
} }
/**
* 从队列中删除每个节点。
* O(n)复杂度 所有尽可能少调用该方法
*/
public clear() {
this._nodes.splice(1, this._numNodes);
this._numNodes = 0;
}
/** /**
* 返回(在O(1)中)给定节点是否在队列中 * 返回(在O(1)中)给定节点是否在队列中
* O (1)复杂度 * O (1)复杂度
@@ -43,6 +43,21 @@ module es {
return foundPath ? this.recontructPath(cameFrom, start, goal) : null; return foundPath ? this.recontructPath(cameFrom, start, goal) : null;
} }
public static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[] {
let path = [];
let current = goal;
path.push(goal);
while (current != start) {
current = this.getKey(cameFrom, current);
path.push(current);
}
path.reverse();
return path;
}
private static hasKey<T>(map: Map<T, number>, compareKey: T) { private static hasKey<T>(map: Map<T, number>, compareKey: T) {
let iterator = map.keys(); let iterator = map.keys();
let r: IteratorResult<T>; let r: IteratorResult<T>;
@@ -66,20 +81,5 @@ module es {
return null; return null;
} }
public static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[]{
let path = [];
let current = goal;
path.push(goal);
while (current != start){
current = this.getKey(cameFrom, current);
path.push(current);
}
path.reverse();
return path;
}
} }
} }
+8 -8
View File
@@ -12,6 +12,10 @@ module es {
* 此组件附加的实体 * 此组件附加的实体
*/ */
public entity: Entity; public entity: Entity;
/**
* 更新该组件的时间间隔。这与实体的更新间隔无关。
*/
public updateInterval: number = 1;
/** /**
* 快速访问 this.entity.transform * 快速访问 this.entity.transform
@@ -20,6 +24,8 @@ module es {
return this.entity.transform; return this.entity.transform;
} }
private _enabled: boolean = true;
/** /**
* 如果组件和实体都已启用,则为。当启用该组件时,将调用该组件的生命周期方法。状态的改变会导致调用onEnabled/onDisable。 * 如果组件和实体都已启用,则为。当启用该组件时,将调用该组件的生命周期方法。状态的改变会导致调用onEnabled/onDisable。
*/ */
@@ -35,6 +41,8 @@ module es {
this.setEnabled(value); this.setEnabled(value);
} }
private _updateOrder = 0;
/** 更新此实体上组件的顺序 */ /** 更新此实体上组件的顺序 */
public get updateOrder() { public get updateOrder() {
return this._updateOrder; return this._updateOrder;
@@ -45,14 +53,6 @@ module es {
this.setUpdateOrder(value); this.setUpdateOrder(value);
} }
/**
* 更新该组件的时间间隔。这与实体的更新间隔无关。
*/
public updateInterval: number = 1;
private _enabled: boolean = true;
private _updateOrder = 0;
/** /**
* 当此组件已分配其实体,但尚未添加到实体的活动组件列表时调用。有用的东西,如物理组件,需要访问转换来修改碰撞体的属性。 * 当此组件已分配其实体,但尚未添加到实体的活动组件列表时调用。有用的东西,如物理组件,需要访问转换来修改碰撞体的属性。
*/ */
+81 -77
View File
@@ -12,6 +12,46 @@ module es {
} }
export class Camera extends Component { export class Camera extends Component {
public _inset: CameraInset = new CameraInset();
public _areMatrixedDirty: boolean = true;
public _areBoundsDirty: boolean = true;
public _isProjectionMatrixDirty = true;
/**
* 如果相机模式为cameraWindow 则会进行缓动移动
* 该值为移动速度
*/
public followLerp = 0.1;
/**
* 在cameraWindow模式下,宽度/高度被用做边界框,允许在不移动相机的情况下移动
* 在lockOn模式下,只使用deadZone的x/y值 你可以通过直接setCenteredDeadzone重写它来自定义deadZone
*/
public deadzone: Rectangle = new Rectangle();
/**
* 相机聚焦于屏幕中心的偏移
*/
public focusOffset: Vector2 = Vector2.zero;
/**
* 如果为true 相机位置则不会超出地图矩形(0, 0, mapwidth, mapheight
*/
public mapLockEnabled: boolean = false;
/**
* 當前地圖映射的寬度和高度
*/
public mapSize: Vector2 = Vector2.zero;
public _targetEntity: Entity;
public _targetCollider: Collider;
public _desiredPositionDelta: Vector2 = new Vector2();
public _cameraStyle: CameraStyle;
public _worldSpaceDeadZone: Rectangle = new Rectangle();
constructor(targetEntity: Entity = null, cameraStyle: CameraStyle = CameraStyle.lockOn) {
super();
this._targetEntity = targetEntity;
this._cameraStyle = cameraStyle;
this.setZoom(0);
}
/** /**
* 对entity.transform.position的快速访问 * 对entity.transform.position的快速访问
*/ */
@@ -42,6 +82,8 @@ module es {
this.entity.transform.rotation = value; this.entity.transform.rotation = value;
} }
public _zoom;
/** /**
* 缩放值应该在-1和1之间、然后将该值从minimumZoom转换为maximumZoom。 * 缩放值应该在-1和1之间、然后将该值从minimumZoom转换为maximumZoom。
* 允许你设置适当的最小/最大值,然后使用更直观的-1到1的映射来更改缩放 * 允许你设置适当的最小/最大值,然后使用更直观的-1到1的映射来更改缩放
@@ -65,6 +107,8 @@ module es {
this.setZoom(value); this.setZoom(value);
} }
public _minimumZoom = 0.3;
/** /**
* 相机变焦可以达到的最小非缩放值(0-number.max)。默认为0.3 * 相机变焦可以达到的最小非缩放值(0-number.max)。默认为0.3
*/ */
@@ -80,6 +124,8 @@ module es {
this.setMinimumZoom(value); this.setMinimumZoom(value);
} }
public _maximumZoom = 3;
/** /**
* 相机变焦可以达到的最大非缩放值(0-number.max)。默认为3 * 相机变焦可以达到的最大非缩放值(0-number.max)。默认为3
*/ */
@@ -95,6 +141,8 @@ module es {
this.setMaximumZoom(value); this.setMaximumZoom(value);
} }
public _bounds: Rectangle = new Rectangle();
/** /**
* 相机的世界-空间边界 * 相机的世界-空间边界
*/ */
@@ -135,6 +183,8 @@ module es {
return this._bounds; return this._bounds;
} }
public _transformMatrix: Matrix2D = new Matrix2D().identity();
/** /**
* 用于从世界坐标转换到屏幕 * 用于从世界坐标转换到屏幕
*/ */
@@ -144,6 +194,8 @@ module es {
return this._transformMatrix; return this._transformMatrix;
} }
public _inverseTransformMatrix: Matrix2D = new Matrix2D().identity();
/** /**
* 用于从屏幕坐标到世界的转换 * 用于从屏幕坐标到世界的转换
*/ */
@@ -153,6 +205,8 @@ module es {
return this._inverseTransformMatrix; return this._inverseTransformMatrix;
} }
public _origin: Vector2 = Vector2.zero;
public get origin() { public get origin() {
return this._origin; return this._origin;
} }
@@ -164,56 +218,6 @@ module es {
} }
} }
public _zoom;
public _minimumZoom = 0.3;
public _maximumZoom = 3;
public _bounds: Rectangle = new Rectangle();
public _inset: CameraInset = new CameraInset();
public _transformMatrix: Matrix2D = new Matrix2D().identity();
public _inverseTransformMatrix: Matrix2D = new Matrix2D().identity();
public _origin: Vector2 = Vector2.zero;
public _areMatrixedDirty: boolean = true;
public _areBoundsDirty: boolean = true;
public _isProjectionMatrixDirty = true;
/**
* 如果相机模式为cameraWindow 则会进行缓动移动
* 该值为移动速度
*/
public followLerp = 0.1;
/**
* 在cameraWindow模式下,宽度/高度被用做边界框,允许在不移动相机的情况下移动
* 在lockOn模式下,只使用deadZone的x/y值 你可以通过直接setCenteredDeadzone重写它来自定义deadZone
*/
public deadzone: Rectangle = new Rectangle();
/**
* 相机聚焦于屏幕中心的偏移
*/
public focusOffset: Vector2 = Vector2.zero;
/**
* 如果为true 相机位置则不会超出地图矩形(0, 0, mapwidth, mapheight
*/
public mapLockEnabled: boolean = false;
/**
* 當前地圖映射的寬度和高度
*/
public mapSize: Vector2 = Vector2.zero;
public _targetEntity: Entity;
public _targetCollider: Collider;
public _desiredPositionDelta: Vector2 = new Vector2();
public _cameraStyle: CameraStyle;
public _worldSpaceDeadZone: Rectangle = new Rectangle();
constructor(targetEntity: Entity = null, cameraStyle: CameraStyle = CameraStyle.lockOn) {
super();
this._targetEntity = targetEntity;
this._cameraStyle = cameraStyle;
this.setZoom(0);
}
/** /**
* 当场景渲染目标的大小发生变化时,我们会更新相机的原点并调整它的位置以保持它原来的位置 * 当场景渲染目标的大小发生变化时,我们会更新相机的原点并调整它的位置以保持它原来的位置
* @param newWidth * @param newWidth
@@ -226,33 +230,6 @@ module es {
this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin)); this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin));
} }
protected updateMatrixes(){
if (!this._areMatrixedDirty)
return;
let tempMat: Matrix2D;
this._transformMatrix = Matrix2D.create().translate(-this.entity.transform.position.x, -this.entity.transform.position.y);
if (this._zoom != 1){
tempMat = Matrix2D.create().scale(this._zoom, this._zoom);
this._transformMatrix = this._transformMatrix.multiply(tempMat);
}
if (this.entity.transform.rotation != 0){
tempMat = Matrix2D.create().rotate(this.entity.transform.rotation);
this._transformMatrix = this._transformMatrix.multiply(tempMat);
}
tempMat = Matrix2D.create().translate(this._origin.x, this._origin.y);
this._transformMatrix =this._transformMatrix.multiply(tempMat);
this._inverseTransformMatrix = this._transformMatrix.invert();
// 无论何时矩阵改变边界都是无效的
this._areBoundsDirty = true;
this._areMatrixedDirty = false;
}
/** /**
* 设置用于从视口边缘插入摄像机边界的量 * 设置用于从视口边缘插入摄像机边界的量
* @param left * @param left
@@ -476,5 +453,32 @@ module es {
public setCenteredDeadzone(width: number, height: number) { public setCenteredDeadzone(width: number, height: number) {
this.deadzone = new Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height); this.deadzone = new Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height);
} }
protected updateMatrixes() {
if (!this._areMatrixedDirty)
return;
let tempMat: Matrix2D;
this._transformMatrix = Matrix2D.create().translate(-this.entity.transform.position.x, -this.entity.transform.position.y);
if (this._zoom != 1) {
tempMat = Matrix2D.create().scale(this._zoom, this._zoom);
this._transformMatrix = this._transformMatrix.multiply(tempMat);
}
if (this.entity.transform.rotation != 0) {
tempMat = Matrix2D.create().rotate(this.entity.transform.rotation);
this._transformMatrix = this._transformMatrix.multiply(tempMat);
}
tempMat = Matrix2D.create().translate(this._origin.x, this._origin.y);
this._transformMatrix = this._transformMatrix.multiply(tempMat);
this._inverseTransformMatrix = this._transformMatrix.invert();
// 无论何时矩阵改变边界都是无效的
this._areBoundsDirty = true;
this._areMatrixedDirty = false;
}
} }
} }
@@ -1,6 +1,17 @@
///<reference path="./Collider.ts" /> ///<reference path="./Collider.ts" />
module es { module es {
export class BoxCollider extends Collider { export class BoxCollider extends Collider {
/**
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
*/
constructor() {
super();
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
this.shape = new Box(1, 1);
this._colliderRequiresAutoSizing = true;
}
public get width() { public get width() {
return (this.shape as Box).width; return (this.shape as Box).width;
} }
@@ -17,17 +28,6 @@ module es {
this.setHeight(value); this.setHeight(value);
} }
/**
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
*/
constructor(){
super();
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
this.shape = new Box(1, 1);
this._colliderRequiresAutoSizing = true;
}
/** /**
* 设置BoxCollider的大小 * 设置BoxCollider的大小
* @param width * @param width
@@ -1,13 +1,5 @@
module es { module es {
export class CircleCollider extends Collider { export class CircleCollider extends Collider {
public get radius(): number {
return (this.shape as Circle).radius;
}
public set radius(value: number) {
this.setRadius(value);
}
/** /**
* 创建一个有半径的圆 * 创建一个有半径的圆
* *
@@ -23,6 +15,14 @@ module es {
this.shape = new Circle(radius ? radius : 1); this.shape = new Circle(radius ? radius : 1);
} }
public get radius(): number {
return (this.shape as Circle).radius;
}
public set radius(value: number) {
this.setRadius(value);
}
/** /**
* 设置圆的半径 * 设置圆的半径
* @param radius * @param radius
@@ -4,23 +4,40 @@ module es {
* 对撞机的基本形状 * 对撞机的基本形状
*/ */
public shape: Shape; public shape: Shape;
/** /**
* 将localOffset添加到实体。获取碰撞器几何图形的最终位置。 * 如果这个碰撞器是一个触发器,它将不会引起碰撞,但它仍然会触发事件
* 允许向一个实体添加多个碰撞器并分别定位,还允许你设置缩放/旋转
*/ */
public get localOffset(): Vector2 { public isTrigger: boolean;
return this._localOffset;
}
/** /**
* 将localOffset添加到实体。获取碰撞器几何图形的最终位置。 * 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法
* 允许向一个实体添加多个碰撞器并分别定位,还允许你设置缩放/旋转
* @param value
*/ */
public set localOffset(value: Vector2) { public physicsLayer = 1 << 0;
this.setLocalOffset(value); /**
} * 碰撞器在使用移动器移动时应该碰撞的层
* 默认为所有层
*/
public collidesWithLayers = Physics.allLayers;
/**
* 如果为true,碰撞器将根据附加的变换缩放和旋转
*/
public shouldColliderScaleAndRotateWithTransform = true;
/**
* 这个对撞机在物理系统注册时的边界。
* 存储这个允许我们始终能够安全地从物理系统中移除对撞机,即使它在试图移除它之前已经被移动了。
*/
public registeredPhysicsBounds: Rectangle = new Rectangle();
public _localOffsetLength: number;
public _isPositionDirty: boolean = true;
public _isRotationDirty: boolean = true;
protected _colliderRequiresAutoSizing;
/**
* 标记来跟踪我们的实体是否被添加到场景中
*/
protected _isParentEntityAddedToScene;
/**
* 标记来记录我们是否注册了物理系统
*/
protected _isColliderRegistered;
/** /**
* 镖师碰撞器的绝对位置 * 镖师碰撞器的绝对位置
@@ -39,25 +56,6 @@ module es {
return 0; return 0;
} }
/**
* 如果这个碰撞器是一个触发器,它将不会引起碰撞,但它仍然会触发事件
*/
public isTrigger: boolean;
/**
* 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法
*/
public physicsLayer = 1 << 0;
/**
* 碰撞器在使用移动器移动时应该碰撞的层
* 默认为所有层
*/
public collidesWithLayers = Physics.allLayers;
/**
* 如果为true,碰撞器将根据附加的变换缩放和旋转
*/
public shouldColliderScaleAndRotateWithTransform = true;
public get bounds(): Rectangle { public get bounds(): Rectangle {
if (this._isPositionDirty || this._isRotationDirty) { if (this._isPositionDirty || this._isRotationDirty) {
this.shape.recalculateBounds(this); this.shape.recalculateBounds(this);
@@ -67,26 +65,24 @@ module es {
return this.shape.bounds; return this.shape.bounds;
} }
/**
* 这个对撞机在物理系统注册时的边界。
* 存储这个允许我们始终能够安全地从物理系统中移除对撞机,即使它在试图移除它之前已经被移动了。
*/
public registeredPhysicsBounds: Rectangle = new Rectangle();
protected _colliderRequiresAutoSizing;
protected _localOffset: Vector2 = Vector2.zero; protected _localOffset: Vector2 = Vector2.zero;
public _localOffsetLength: number;
/** /**
* 标记来跟踪我们的实体是否被添加到场景中 * 将localOffset添加到实体。获取碰撞器几何图形的最终位置。
* 允许向一个实体添加多个碰撞器并分别定位,还允许你设置缩放/旋转
*/ */
protected _isParentEntityAddedToScene; public get localOffset(): Vector2 {
/** return this._localOffset;
* 标记来记录我们是否注册了物理系统 }
*/
protected _isColliderRegistered;
public _isPositionDirty: boolean = true; /**
public _isRotationDirty: boolean = true; * 将localOffset添加到实体。获取碰撞器几何图形的最终位置。
* 允许向一个实体添加多个碰撞器并分别定位,还允许你设置缩放/旋转
* @param value
*/
public set localOffset(value: Vector2) {
this.setLocalOffset(value);
}
/** /**
* 将localOffset添加到实体。获取碰撞器的最终位置。 * 将localOffset添加到实体。获取碰撞器的最终位置。
@@ -8,6 +8,12 @@ module es {
* 用于装载egret显示对象 * 用于装载egret显示对象
*/ */
public displayObject: egret.DisplayObject = new egret.DisplayObject(); public displayObject: egret.DisplayObject = new egret.DisplayObject();
/**
* 用于着色器处理精灵
*/
public color: number = 0x000000;
protected _areBoundsDirty = true;
/** /**
* renderableComponent的宽度 * renderableComponent的宽度
* 如果你不重写bounds属性则需要实现这个 * 如果你不重写bounds属性则需要实现这个
@@ -24,34 +30,7 @@ module es {
return this.bounds.height; return this.bounds.height;
} }
/** protected _localOffset: Vector2 = Vector2.zero;
* 这个物体的AABB, 用于相机剔除
*/
public get bounds(): Rectangle {
if (this._areBoundsDirty){
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, Vector2.zero,
this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
}
/**
* 较低的渲染层在前面,较高的在后面
*/
public get renderLayer(): number{
return this._renderLayer;
}
public set renderLayer(value: number){
}
/**
* 用于着色器处理精灵
*/
public color: number = 0x000000;
/** /**
* 从父实体的偏移量。用于向需要特定定位的实体 * 从父实体的偏移量。用于向需要特定定位的实体
@@ -68,6 +47,36 @@ module es {
this.setLocalOffset(value); this.setLocalOffset(value);
} }
protected _renderLayer: number = 0;
/**
* 较低的渲染层在前面,较高的在后面
*/
public get renderLayer(): number {
return this._renderLayer;
}
public set renderLayer(value: number) {
}
protected _bounds: Rectangle = new Rectangle();
/**
* 这个物体的AABB, 用于相机剔除
*/
public get bounds(): Rectangle {
if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, Vector2.zero,
this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
}
private _isVisible: boolean;
/** /**
* 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法 * 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法
*/ */
@@ -90,12 +99,6 @@ module es {
} }
} }
protected _localOffset: Vector2 = Vector2.zero;
protected _renderLayer: number = 0;
protected _bounds: Rectangle = new Rectangle();
private _isVisible: boolean;
protected _areBoundsDirty = true;
public onEntityTransformChanged(comp: transform.Component) { public onEntityTransformChanged(comp: transform.Component) {
this._areBoundsDirty = true; this._areBoundsDirty = true;
} }
@@ -106,22 +109,6 @@ module es {
*/ */
public abstract render(camera: Camera); public abstract render(camera: Camera);
/**
* 当renderableComponent进入相机框架时调用
* 如果渲染器不适用isVisibleFromCamera进行剔除检查 这些方法不会被调用
*/
protected onBecameVisible() {
this.displayObject.visible = this.isVisible;
}
/**
* 当renderableComponent离开相机框架时调用
* 如果渲染器不适用isVisibleFromCamera进行剔除检查 这些方法不会被调用
*/
protected onBecameInvisible() {
this.displayObject.visible = this.isVisible;
}
/** /**
* 如果renderableComponent的边界与camera.bounds相交 返回true * 如果renderableComponent的边界与camera.bounds相交 返回true
* 用于处理isVisible标志的状态开关 * 用于处理isVisible标志的状态开关
@@ -185,5 +172,21 @@ module es {
public toString() { public toString() {
return `[RenderableComponent] renderLayer: ${this.renderLayer}`; return `[RenderableComponent] renderLayer: ${this.renderLayer}`;
} }
/**
* 当renderableComponent进入相机框架时调用
* 如果渲染器不适用isVisibleFromCamera进行剔除检查 这些方法不会被调用
*/
protected onBecameVisible() {
this.displayObject.visible = this.isVisible;
}
/**
* 当renderableComponent离开相机框架时调用
* 如果渲染器不适用isVisibleFromCamera进行剔除检查 这些方法不会被调用
*/
protected onBecameInvisible() {
this.displayObject.visible = this.isVisible;
}
} }
} }
+8 -8
View File
@@ -45,6 +45,12 @@ module es {
* 当前动画的精灵数组中当前帧的索引 * 当前动画的精灵数组中当前帧的索引
*/ */
public currentFrame: number; public currentFrame: number;
public _elapsedTime: number = 0;
public _loopMode: LoopMode;
constructor(sprite?: Sprite) {
super(sprite);
}
/** /**
* 检查当前动画是否正在运行 * 检查当前动画是否正在运行
@@ -53,19 +59,13 @@ module es {
return this.animationState == State.running; return this.animationState == State.running;
} }
private _animations: Map<string, SpriteAnimation> = new Map<string, SpriteAnimation>();
/** 提供对可用动画列表的访问 */ /** 提供对可用动画列表的访问 */
public get animations() { public get animations() {
return this._animations; return this._animations;
} }
private _animations: Map<string, SpriteAnimation> = new Map<string, SpriteAnimation>();
public _elapsedTime: number = 0;
public _loopMode: LoopMode;
constructor(sprite?: Sprite) {
super(sprite);
}
public update() { public update() {
if (this.animationState != State.running || !this.currentAnimation) return; if (this.animationState != State.running || !this.currentAnimation) return;
+27 -26
View File
@@ -2,6 +2,14 @@ module es {
import Bitmap = egret.Bitmap; import Bitmap = egret.Bitmap;
export class SpriteRenderer extends RenderableComponent { export class SpriteRenderer extends RenderableComponent {
constructor(sprite: Sprite | egret.Texture = null) {
super();
if (sprite instanceof Sprite)
this.setSprite(sprite);
else if (sprite instanceof egret.Texture)
this.setSprite(new Sprite(sprite));
}
public get bounds() { public get bounds() {
if (this._areBoundsDirty) { if (this._areBoundsDirty) {
if (this._sprite) { if (this._sprite) {
@@ -15,21 +23,6 @@ module es {
return this._bounds; return this._bounds;
} }
/**
* 精灵的原点。这是在设置精灵时自动设置的
*/
public get origin(): Vector2 {
return this._origin;
}
/**
* 精灵的原点。这是在设置精灵时自动设置的
* @param value
*/
public set origin(value: Vector2) {
this.setOrigin(value);
}
/** /**
* 用归一化方法设置原点 * 用归一化方法设置原点
* x/y 均为 0-1 * x/y 均为 0-1
@@ -49,6 +42,25 @@ module es {
value.y * this.height / this.entity.transform.scale.y)); value.y * this.height / this.entity.transform.scale.y));
} }
protected _origin: Vector2;
/**
* 精灵的原点。这是在设置精灵时自动设置的
*/
public get origin(): Vector2 {
return this._origin;
}
/**
* 精灵的原点。这是在设置精灵时自动设置的
* @param value
*/
public set origin(value: Vector2) {
this.setOrigin(value);
}
protected _sprite: Sprite;
/** /**
* 应该由这个精灵显示的精灵 * 应该由这个精灵显示的精灵
* 当设置时,精灵的原点也被设置为精灵的origin * 当设置时,精灵的原点也被设置为精灵的origin
@@ -66,17 +78,6 @@ module es {
this.setSprite(value); this.setSprite(value);
} }
protected _origin: Vector2;
protected _sprite: Sprite;
constructor(sprite: Sprite | egret.Texture = null) {
super();
if (sprite instanceof Sprite)
this.setSprite(sprite);
else if (sprite instanceof egret.Texture)
this.setSprite(new Sprite(sprite));
}
/** /**
* 设置精灵并更新精灵的原点以匹配sprite.origin * 设置精灵并更新精灵的原点以匹配sprite.origin
* @param sprite * @param sprite
@@ -8,19 +8,6 @@ module es {
protected leftTexture: egret.Bitmap; protected leftTexture: egret.Bitmap;
protected rightTexture: egret.Bitmap; protected rightTexture: egret.Bitmap;
public get scrollX() {
return this.sourceRect.x;
}
public set scrollX(value: number) {
this.sourceRect.x = value;
}
public get scrollY() {
return this.sourceRect.y;
}
public set scrollY(value: number) {
this.sourceRect.y = value;
}
constructor(sprite: Sprite) { constructor(sprite: Sprite) {
super(sprite); super(sprite);
@@ -33,6 +20,22 @@ module es {
this.sourceRect = sprite.sourceRect; this.sourceRect = sprite.sourceRect;
} }
public get scrollX() {
return this.sourceRect.x;
}
public set scrollX(value: number) {
this.sourceRect.x = value;
}
public get scrollY() {
return this.sourceRect.y;
}
public set scrollY(value: number) {
this.sourceRect.y = value;
}
public render(camera: es.Camera) { public render(camera: es.Camera) {
if (!this.sprite) if (!this.sprite)
return; return;
+109 -109
View File
@@ -15,6 +15,26 @@ module es {
* *
*/ */
public static content: ContentManager; public static content: ContentManager;
/**
* 访
*/
public static _instance: Core;
public _nextScene: Scene;
public _sceneTransition: SceneTransition;
/**
* 访
*/
public _globalManagers: GlobalManager[] = [];
constructor() {
super();
Core._instance = this;
Core.emitter = new Emitter<CoreEvents>();
Core.content = new ContentManager();
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
}
/** /**
* /访 * /访
@@ -24,17 +44,7 @@ module es {
return this._instance; return this._instance;
} }
/**
* 访
*/
public static _instance: Core;
public _scene: Scene; public _scene: Scene;
public _nextScene: Scene;
public _sceneTransition: SceneTransition;
/**
* 访
*/
public _globalManagers: GlobalManager[] = [];
/** /**
* *
@@ -65,31 +75,98 @@ module es {
} }
} }
constructor() { /**
super(); * SceneTransition
* @param sceneTransition
Core._instance = this; */
Core.emitter = new Emitter<CoreEvents>(); public static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T {
Core.content = new ContentManager(); if (this._instance._sceneTransition) {
console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); return;
} }
private onAddToStage(){ this._instance._sceneTransition = sceneTransition;
Core.graphicsDevice = new GraphicsDevice(); return sceneTransition;
}
this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); /**
this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); *
this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); * @param manager
*/
public static registerGlobalManager(manager: es.GlobalManager) {
this._instance._globalManagers.push(manager);
manager.enabled = true;
}
Input.initialize(); /**
this.initialize(); *
* @param manager
*/
public static unregisterGlobalManager(manager: es.GlobalManager) {
this._instance._globalManagers.remove(manager);
manager.enabled = false;
}
/**
* T的全局管理器
* @param type
*/
public static getGlobalManager<T extends es.GlobalManager>(type): T {
for (let i = 0; i < this._instance._globalManagers.length; i++) {
if (this._instance._globalManagers[i] instanceof type)
return this._instance._globalManagers[i] as T;
}
return null;
} }
public onOrientationChanged() { public onOrientationChanged() {
Core.emitter.emit(CoreEvents.OrientationChanged); Core.emitter.emit(CoreEvents.OrientationChanged);
} }
public async draw() {
if (this._sceneTransition) {
this._sceneTransition.preRender();
// 如果我们有场景转换的特殊处理。我们要么渲染场景过渡,要么渲染场景
if (this._scene && !this._sceneTransition.hasPreviousSceneRender) {
this._scene.render();
this._scene.postRender();
await this._sceneTransition.onBeginTransition();
} else if (this._sceneTransition) {
if (this._scene && this._sceneTransition.isNewSceneLoaded) {
this._scene.render();
this._scene.postRender();
}
this._sceneTransition.render();
}
} else if (this._scene) {
this._scene.render();
Debug.render();
// 如果我们没有一个活跃的场景转换,就像平常一样渲染
this._scene.postRender();
}
}
public startDebugUpdate() {
TimeRuler.Instance.startFrame();
TimeRuler.Instance.beginMark("update", 0x00FF00);
}
public endDebugUpdate() {
TimeRuler.Instance.endMark("update");
}
/**
*
*/
public onSceneChanged() {
Core.emitter.emit(CoreEvents.SceneChanged);
Time.sceneChanged();
}
/** /**
* *
*/ */
@@ -139,92 +216,15 @@ module es {
await this.draw(); await this.draw();
} }
public async draw() { private onAddToStage() {
if (this._sceneTransition){ Core.graphicsDevice = new GraphicsDevice();
this._sceneTransition.preRender();
// 如果我们有场景转换的特殊处理。我们要么渲染场景过渡,要么渲染场景 this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this);
if (this._scene && !this._sceneTransition.hasPreviousSceneRender){ this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this);
this._scene.render(); this.addEventListener(egret.Event.ENTER_FRAME, this.update, this);
this._scene.postRender();
await this._sceneTransition.onBeginTransition();
} else if (this._sceneTransition) {
if (this._scene && this._sceneTransition.isNewSceneLoaded) {
this._scene.render();
this._scene.postRender();
}
this._sceneTransition.render(); Input.initialize();
} this.initialize();
} else if (this._scene) {
this._scene.render();
Debug.render();
// 如果我们没有一个活跃的场景转换,就像平常一样渲染
this._scene.postRender();
}
}
public startDebugUpdate(){
TimeRuler.Instance.startFrame();
TimeRuler.Instance.beginMark("update", 0x00FF00);
}
public endDebugUpdate(){
TimeRuler.Instance.endMark("update");
}
/**
*
*/
public onSceneChanged(){
Core.emitter.emit(CoreEvents.SceneChanged);
Time.sceneChanged();
}
/**
* SceneTransition
* @param sceneTransition
*/
public static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T {
if (this._instance._sceneTransition) {
console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
return;
}
this._instance._sceneTransition = sceneTransition;
return sceneTransition;
}
/**
*
* @param manager
*/
public static registerGlobalManager(manager: es.GlobalManager){
this._instance._globalManagers.push(manager);
manager.enabled = true;
}
/**
*
* @param manager
*/
public static unregisterGlobalManager(manager: es.GlobalManager){
this._instance._globalManagers.remove(manager);
manager.enabled = false;
}
/**
* T的全局管理器
* @param type
*/
public static getGlobalManager<T extends es.GlobalManager>(type): T {
for (let i = 0; i < this._instance._globalManagers.length; i ++){
if (this._instance._globalManagers[i] instanceof type)
return this._instance._globalManagers[i] as T;
}
return null;
} }
} }
} }
+54 -53
View File
@@ -22,6 +22,31 @@ module es {
* *
*/ */
public readonly components: ComponentList; public readonly components: ComponentList;
/**
* entity update方法的频率12
*/
public updateInterval: number = 1;
public componentBits: BitSet;
constructor(name: string) {
this.components = new ComponentList(this);
this.transform = new Transform(this);
this.name = name;
this.id = Entity._idGenerator++;
this.componentBits = new BitSet();
}
public _isDestroyed: boolean;
/**
* destroytrue
*/
public get isDestroyed() {
return this._isDestroyed;
}
private _tag: number = 0;
/** /**
* 使使 * 使使
@@ -38,10 +63,7 @@ module es {
this.setTag(value); this.setTag(value);
} }
/** private _enabled: boolean = true;
* entity update方法的频率12
*/
public updateInterval: number = 1;
/** /**
* / * /
@@ -58,6 +80,8 @@ module es {
this.setEnabled(value); this.setEnabled(value);
} }
private _updateOrder: number = 0;
/** /**
* updateOrder还用于对scene.entities上的标签列表进行排序 * updateOrder还用于对scene.entities上的标签列表进行排序
*/ */
@@ -73,20 +97,6 @@ module es {
this.setUpdateOrder(value); this.setUpdateOrder(value);
} }
public _isDestroyed: boolean;
/**
* destroytrue
*/
public get isDestroyed() {
return this._isDestroyed;
}
public componentBits: BitSet;
private _tag: number = 0;
private _enabled: boolean = true;
private _updateOrder: number = 0;
public get parent(): Transform { public get parent(): Transform {
return this.transform.parent; return this.transform.parent;
} }
@@ -175,15 +185,6 @@ module es {
return this.transform.worldToLocalTransform; return this.transform.worldToLocalTransform;
} }
constructor(name: string) {
this.components = new ComponentList(this);
this.transform = new Transform(this);
this.name = name;
this.id = Entity._idGenerator++;
this.componentBits = new BitSet();
}
public onTransformChanged(comp: transform.Component) { public onTransformChanged(comp: transform.Component) {
// 通知我们的子项改变了位置 // 通知我们的子项改变了位置
this.components.onEntityTransformChanged(comp); this.components.onEntityTransformChanged(comp);
@@ -293,32 +294,6 @@ module es {
return entity; return entity;
} }
/**
*
* @param entity
*/
protected copyFrom(entity: Entity) {
this.tag = entity.tag;
this.updateInterval = entity.updateInterval;
this.updateOrder = entity.updateOrder;
this.enabled = entity.enabled;
this.transform.scale = entity.transform.scale;
this.transform.rotation = entity.transform.rotation;
for (let i = 0; i < entity.components.count; i++)
this.addComponent(entity.components.buffer[i].clone());
for (let i = 0; i < entity.components._componentsToAdd.length; i++)
this.addComponent(entity.components._componentsToAdd[i].clone());
for (let i = 0; i < entity.transform.childCount; i++) {
let child = entity.transform.getChild(i).entity;
let childClone = child.clone();
childClone.transform.copyFrom(child.transform);
childClone.transform.parent = this.transform;
}
}
/** /**
* *
*/ */
@@ -431,5 +406,31 @@ module es {
public toString(): string { public toString(): string {
return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`; return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`;
} }
/**
*
* @param entity
*/
protected copyFrom(entity: Entity) {
this.tag = entity.tag;
this.updateInterval = entity.updateInterval;
this.updateOrder = entity.updateOrder;
this.enabled = entity.enabled;
this.transform.scale = entity.transform.scale;
this.transform.rotation = entity.transform.rotation;
for (let i = 0; i < entity.components.count; i++)
this.addComponent(entity.components.buffer[i].clone());
for (let i = 0; i < entity.components._componentsToAdd.length; i++)
this.addComponent(entity.components._componentsToAdd[i].clone());
for (let i = 0; i < entity.transform.childCount; i++) {
let child = entity.transform.getChild(i).entity;
let childClone = child.clone();
childClone.transform.copyFrom(child.transform);
childClone.transform.parent = this.transform;
}
}
} }
} }
+19 -14
View File
@@ -31,15 +31,6 @@ module es {
public readonly _postProcessors: PostProcessor[] = []; public readonly _postProcessors: PostProcessor[] = [];
public _didSceneBegin; public _didSceneBegin;
/**
* DefaultRenderer附加并准备使用
*/
public static createWithDefaultRenderer(){
let scene = new Scene();
scene.addRenderer(new DefaultRenderer());
return scene;
}
constructor() { constructor() {
super(); super();
this.entities = new EntityList(this); this.entities = new EntityList(this);
@@ -51,31 +42,45 @@ module es {
this.initialize(); this.initialize();
} }
/**
* DefaultRenderer附加并准备使用
*/
public static createWithDefaultRenderer() {
let scene = new Scene();
scene.addRenderer(new DefaultRenderer());
return scene;
}
/** /**
* begin之前 * begin之前
*/ */
public initialize(){} public initialize() {
}
/** /**
* SceneManager将此场景设置为活动场景时 * SceneManager将此场景设置为活动场景时
*/ */
public async onStart() {} public async onStart() {
}
/** /**
* SceneManager从活动槽中删除此场景时调用 * SceneManager从活动槽中删除此场景时调用
*/ */
public unload() { } public unload() {
}
/** /**
* *
*/ */
public onActive() {} public onActive() {
}
/** /**
* *
*/ */
public onDeactive() {} public onDeactive() {
}
public async begin() { public async begin() {
if (this._renderers.length == 0) { if (this._renderers.length == 0) {
+8 -6
View File
@@ -1,13 +1,13 @@
module es { module es {
export class EntitySystem { export class EntitySystem {
private _scene: Scene;
private _entities: Entity[] = []; private _entities: Entity[] = [];
private _matcher: Matcher;
public get matcher(){ constructor(matcher?: Matcher) {
return this._matcher; this._matcher = matcher ? matcher : Matcher.empty();
} }
private _scene: Scene;
public get scene() { public get scene() {
return this._scene; return this._scene;
} }
@@ -17,8 +17,10 @@ module es {
this._entities = []; this._entities = [];
} }
constructor(matcher?: Matcher){ private _matcher: Matcher;
this._matcher = matcher ? matcher : Matcher.empty();
public get matcher() {
return this._matcher;
} }
public initialize() { public initialize() {
+3 -3
View File
@@ -5,13 +5,13 @@ module es {
} }
/** 处理我们的系统 每帧调用 */
public abstract processSystem();
protected process(entities: Entity[]) { protected process(entities: Entity[]) {
this.begin(); this.begin();
this.processSystem(); this.processSystem();
this.end(); this.end();
} }
/** 处理我们的系统 每帧调用 */
public abstract processSystem();
} }
} }
+153 -150
View File
@@ -19,6 +19,78 @@ module es {
export class Transform extends HashObject { export class Transform extends HashObject {
/** 与此转换关联的实体 */ /** 与此转换关联的实体 */
public readonly entity: Entity; public readonly entity: Entity;
public hierarchyDirty: DirtyType;
public _localDirty: boolean;
public _localPositionDirty: boolean;
public _localScaleDirty: boolean;
public _localRotationDirty: boolean;
public _positionDirty: boolean;
public _worldToLocalDirty: boolean;
public _worldInverseDirty: boolean;
/**
*
*/
public _localTransform: Matrix2D = Matrix2D.create();
/**
*
*/
public _worldTransform = Matrix2D.create().identity();
public _rotationMatrix: Matrix2D = Matrix2D.create();
public _translationMatrix: Matrix2D = Matrix2D.create();
public _scaleMatrix: Matrix2D = Matrix2D.create();
public _children: Transform[];
constructor(entity: Entity) {
super();
this.entity = entity;
this.scale = Vector2.one;
this._children = [];
}
/**
*
*/
public get childCount() {
return this._children.length;
}
/**
*
*/
public get rotationDegrees(): number {
return MathHelper.toDegrees(this._rotation);
}
/**
*
* @param value
*/
public set rotationDegrees(value: number) {
this.setRotation(MathHelper.toRadians(value));
}
/**
*
*/
public get localRotationDegrees(): number {
return MathHelper.toDegrees(this._localRotation);
}
/**
*
* @param value
*/
public set localRotationDegrees(value: number) {
this.localRotation = MathHelper.toRadians(value);
}
public get localToWorldTransform(): Matrix2D {
this.updateTransform();
return this._worldTransform;
}
public _parent: Transform;
/** /**
* *
*/ */
@@ -34,13 +106,37 @@ module es {
this.setParent(value); this.setParent(value);
} }
/** public _worldToLocalTransform = Matrix2D.create().identity();
*
*/ public get worldToLocalTransform(): Matrix2D {
public get childCount() { if (this._worldToLocalDirty) {
return this._children.length; if (!this.parent) {
this._worldToLocalTransform = Matrix2D.create().identity();
} else {
this.parent.updateTransform();
this._worldToLocalTransform = this.parent._worldTransform.invert();
} }
this._worldToLocalDirty = false;
}
return this._worldToLocalTransform;
}
public _worldInverseTransform = Matrix2D.create().identity();
public get worldInverseTransform(): Matrix2D {
this.updateTransform();
if (this._worldInverseDirty) {
this._worldInverseTransform = this._worldTransform.invert();
this._worldInverseDirty = false;
}
return this._worldInverseTransform;
}
public _position: Vector2 = Vector2.zero;
/** /**
* *
*/ */
@@ -68,83 +164,7 @@ module es {
this.setPosition(value.x, value.y); this.setPosition(value.x, value.y);
} }
/** public _scale: Vector2 = Vector2.one;
* transform.position相同
*/
public get localPosition(): Vector2 {
this.updateTransform();
return this._localPosition;
}
/**
* transform.position相同
* @param value
*/
public set localPosition(value: Vector2){
this.setLocalPosition(value);
}
/**
*
*/
public get rotation(): number {
this.updateTransform();
return this._rotation;
}
/**
*
*/
public get rotationDegrees(): number {
return MathHelper.toDegrees(this._rotation);
}
/**
*
* @param value
*/
public set rotationDegrees(value: number){
this.setRotation(MathHelper.toRadians(value));
}
/**
*
* @param value
*/
public set rotation(value: number){
this.setRotation(value);
}
/**
* transform.rotation相同
*/
public get localRotation(): number {
this.updateTransform();
return this._localRotation;
}
/**
* transform.rotation相同
* @param value
*/
public set localRotation(value: number){
this.setLocalRotation(value);
}
/**
*
*/
public get localRotationDegrees(): number {
return MathHelper.toDegrees(this._localRotation);
}
/**
*
* @param value
*/
public set localRotationDegrees(value: number){
this.localRotation = MathHelper.toRadians(value);
}
/** /**
* *
@@ -162,6 +182,44 @@ module es {
this.setScale(value); this.setScale(value);
} }
public _rotation: number = 0;
/**
*
*/
public get rotation(): number {
this.updateTransform();
return this._rotation;
}
/**
*
* @param value
*/
public set rotation(value: number) {
this.setRotation(value);
}
public _localPosition: Vector2 = Vector2.zero;
/**
* transform.position相同
*/
public get localPosition(): Vector2 {
this.updateTransform();
return this._localPosition;
}
/**
* transform.position相同
* @param value
*/
public set localPosition(value: Vector2) {
this.setLocalPosition(value);
}
public _localScale: Vector2 = Vector2.one;
/** /**
* transform.scale相同 * transform.scale相同
*/ */
@@ -178,77 +236,22 @@ module es {
this.setLocalScale(value); this.setLocalScale(value);
} }
public get worldInverseTransform(): Matrix2D {
this.updateTransform();
if (this._worldInverseDirty){
this._worldInverseTransform = this._worldTransform.invert();
this._worldInverseDirty = false;
}
return this._worldInverseTransform;
}
public get localToWorldTransform(): Matrix2D {
this.updateTransform();
return this._worldTransform;
}
public get worldToLocalTransform(): Matrix2D {
if (this._worldToLocalDirty){
if (!this.parent){
this._worldToLocalTransform = Matrix2D.create().identity();
}else{
this.parent.updateTransform();
this._worldToLocalTransform = this.parent._worldTransform.invert();
}
this._worldToLocalDirty = false;
}
return this._worldToLocalTransform;
}
public _parent: Transform;
public hierarchyDirty: DirtyType;
public _localDirty: boolean;
public _localPositionDirty: boolean;
public _localScaleDirty: boolean;
public _localRotationDirty: boolean;
public _positionDirty: boolean;
public _worldToLocalDirty: boolean;
public _worldInverseDirty: boolean;
/**
*
*/
public _localTransform: Matrix2D = Matrix2D.create();
/**
*
*/
public _worldTransform = Matrix2D.create().identity();
public _worldToLocalTransform = Matrix2D.create().identity();
public _worldInverseTransform = Matrix2D.create().identity();
public _rotationMatrix: Matrix2D = Matrix2D.create();
public _translationMatrix: Matrix2D = Matrix2D.create();
public _scaleMatrix: Matrix2D = Matrix2D.create();
public _position: Vector2 = Vector2.zero;
public _scale: Vector2 = Vector2.one;
public _rotation: number = 0;
public _localPosition: Vector2 = Vector2.zero;
public _localScale: Vector2 = Vector2.one;
public _localRotation: number = 0; public _localRotation: number = 0;
public _children: Transform[]; /**
* transform.rotation相同
*/
public get localRotation(): number {
this.updateTransform();
return this._localRotation;
}
constructor(entity: Entity) { /**
super(); * transform.rotation相同
this.entity = entity; * @param value
this.scale = Vector2.one; */
this._children = []; public set localRotation(value: number) {
this.setLocalRotation(value);
} }
/** /**
+8 -8
View File
@@ -67,14 +67,6 @@ module es {
} }
} }
private ensure(lastElt: number){
if (lastElt >= this._bits.length){
let nd = new Number[lastElt + 1];
nd = this._bits.copyWithin(0, 0, this._bits.length);
this._bits = nd;
}
}
public get(pos: number): boolean { public get(pos: number): boolean {
let offset = pos >> 6; let offset = pos >> 6;
if (offset >= this._bits.length) if (offset >= this._bits.length)
@@ -131,5 +123,13 @@ module es {
this.clear(pos); this.clear(pos);
} }
} }
private ensure(lastElt: number) {
if (lastElt >= this._bits.length) {
let nd = new Number[lastElt + 1];
nd = this._bits.copyWithin(0, 0, this._bits.length);
this._bits = nd;
}
}
} }
} }
+12 -12
View File
@@ -26,18 +26,6 @@ module es {
this.removeFromProcessors(entity); this.removeFromProcessors(entity);
} }
protected notifyEntityChanged(entity: Entity){
for (let i = 0; i < this._processors.length; i ++){
this._processors[i].onChanged(entity);
}
}
protected removeFromProcessors(entity: Entity){
for (let i = 0; i < this._processors.length; i ++){
this._processors[i].remove(entity);
}
}
public begin() { public begin() {
} }
@@ -67,5 +55,17 @@ module es {
return null; return null;
} }
protected notifyEntityChanged(entity: Entity) {
for (let i = 0; i < this._processors.length; i++) {
this._processors[i].onChanged(entity);
}
}
protected removeFromProcessors(entity: Entity) {
for (let i = 0; i < this._processors.length; i++) {
this._processors[i].remove(entity);
}
}
} }
} }
+1 -2
View File
@@ -10,8 +10,7 @@ class ObjectUtils {
if (typeof p[i] === 'object') { if (typeof p[i] === 'object') {
c[i] = p[i] instanceof Array ? [] : {}; c[i] = p[i] instanceof Array ? [] : {};
this.clone(p[i], c[i]); this.clone(p[i], c[i]);
} } else {
else {
c[i] = p[i]; c[i] = p[i];
} }
} }
+16 -21
View File
@@ -1,4 +1,18 @@
class StringUtils { class StringUtils {
/**
*
*/
private static specialSigns: string[] = [
'&', '&amp;',
'<', '&lt;',
'>', '&gt;',
'"', '&quot;',
"'", '&apos;',
'®', '&reg;',
'©', '&copy;',
'™', '&trade;',
];
/** /**
* *
* @param str * @param str
@@ -36,7 +50,6 @@ class StringUtils {
return target.slice(0, endIndex + 1); return target.slice(0, endIndex + 1);
} }
/** /**
* 2 * 2
* @param target * @param target
@@ -84,30 +97,13 @@ class StringUtils {
if (isMatch) { if (isMatch) {
tempStr += replaceStr; tempStr += replaceStr;
i = i + tempTarget.length - 1; i = i + tempTarget.length - 1;
} } else {
else {
tempStr += mainStr.charAt(i); tempStr += mainStr.charAt(i);
} }
} }
return tempStr; return tempStr;
} }
/**
*
*/
private static specialSigns: string[] = [
'&', '&amp;',
'<', '&lt;',
'>', '&gt;',
'"', '&quot;',
"'", '&apos;',
'®', '&reg;',
'©', '&copy;',
'™', '&trade;',
];
/** /**
* html实体换掉字符窜中的特殊字符 * html实体换掉字符窜中的特殊字符
* @param str * @param str
@@ -215,8 +211,7 @@ class StringUtils {
let newStr: string; let newStr: string;
if (order) { if (order) {
newStr = str.substring(0, s) + str.substr(e, length); newStr = str.substring(0, s) + str.substr(e, length);
} } else {
else {
s = length - 1 - start - len; s = length - 1 - start - len;
e = s + len; e = s + len;
newStr = str.substring(0, s + 1) + str.substr(e + 1, length); newStr = str.substring(0, s + 1) + str.substr(e + 1, length);
+6 -11
View File
@@ -44,8 +44,7 @@ module es {
} }
renderTexture = new egret.RenderTexture(); renderTexture = new egret.RenderTexture();
renderTexture.drawToTexture(new egret.Bitmap(texture)); renderTexture.drawToTexture(new egret.Bitmap(texture));
} } else {
else {
renderTexture = <egret.RenderTexture>texture; renderTexture = <egret.RenderTexture>texture;
} }
//从RenderTexture中读取像素数据,填入canvas //从RenderTexture中读取像素数据,填入canvas
@@ -71,8 +70,7 @@ module es {
} }
return surface; return surface;
} } else {
else {
let bitmapData = texture; let bitmapData = texture;
let offsetX: number = Math.round(bitmapData.$offsetX); let offsetX: number = Math.round(bitmapData.$offsetX);
let offsetY: number = Math.round(bitmapData.$offsetY); let offsetY: number = Math.round(bitmapData.$offsetY);
@@ -90,8 +88,7 @@ module es {
let surface = this.convertImageToCanvas(texture, rect); let surface = this.convertImageToCanvas(texture, rect);
let result = surface.toDataURL(type, encoderOptions); let result = surface.toDataURL(type, encoderOptions);
return result; return result;
} } catch (e) {
catch (e) {
egret.$error(1033); egret.$error(1033);
} }
return null; return null;
@@ -117,7 +114,7 @@ module es {
success: function (res) { success: function (res) {
//todo //todo
} }
}) });
return result; return result;
} }
@@ -135,8 +132,7 @@ module es {
if (!(<egret.RenderTexture>texture).$renderBuffer) { if (!(<egret.RenderTexture>texture).$renderBuffer) {
renderTexture = new egret.RenderTexture(); renderTexture = new egret.RenderTexture();
renderTexture.drawToTexture(new egret.Bitmap(texture)); renderTexture.drawToTexture(new egret.Bitmap(texture));
} } else {
else {
renderTexture = <egret.RenderTexture>texture; renderTexture = <egret.RenderTexture>texture;
} }
//从RenderTexture中读取像素数据 //从RenderTexture中读取像素数据
@@ -147,8 +143,7 @@ module es {
let surface = this.convertImageToCanvas(texture); let surface = this.convertImageToCanvas(texture);
let result = this.sharedContext.getImageData(x, y, width, height).data; let result = this.sharedContext.getImageData(x, y, width, height).data;
return <number[]><any>result; return <number[]><any>result;
} } catch (e) {
catch (e) {
egret.$error(1039); egret.$error(1039);
} }
} }
+1 -2
View File
@@ -9,10 +9,9 @@ module es {
public static timeScale = 1; public static timeScale = 1;
/** 已传递的帧总数 */ /** 已传递的帧总数 */
public static frameCount = 0; public static frameCount = 0;
private static _lastTime = 0;
/** 自场景加载以来的总时间 */ /** 自场景加载以来的总时间 */
public static _timeSinceSceneLoad; public static _timeSinceSceneLoad;
private static _lastTime = 0;
public static update(currentTime: number) { public static update(currentTime: number) {
let dt = (currentTime - this._lastTime) / 1000; let dt = (currentTime - this._lastTime) / 1000;
+6 -3
View File
@@ -35,7 +35,8 @@ class TimeUtils {
d = d ? d : new Date(); d = d ? d : new Date();
let c: Date = new Date(); let c: Date = new Date();
c.setTime(d.getTime()); c.setTime(d.getTime());
c.setDate(1); c.setMonth(0);//当年第一天 c.setDate(1);
c.setMonth(0);//当年第一天
let year: number = c.getFullYear(); let year: number = c.getFullYear();
let firstDay: number = c.getDay(); let firstDay: number = c.getDay();
@@ -51,7 +52,8 @@ class TimeUtils {
} }
let num: number = this.diffDay(d, c, false); let num: number = this.diffDay(d, c, false);
if (num < 0) { if (num < 0) {
c.setDate(1); c.setMonth(0);//当年第一天 c.setDate(1);
c.setMonth(0);//当年第一天
c.setDate(c.getDate() - 1); c.setDate(c.getDate() - 1);
return this.weekId(c, false); return this.weekId(c, false);
} }
@@ -66,7 +68,8 @@ class TimeUtils {
} }
if (first && (!max || endDay < 4)) { if (first && (!max || endDay < 4)) {
c.setFullYear(c.getFullYear() + 1); c.setFullYear(c.getFullYear() + 1);
c.setDate(1); c.setMonth(0);//当年第一天 c.setDate(1);
c.setMonth(0);//当年第一天
return this.weekId(c, false); return this.weekId(c, false);
} }
} }
+1 -1
View File
@@ -309,7 +309,7 @@ Array.prototype.groupBy = function (keySelector) {
if (typeof (array.reduce) === "function") { if (typeof (array.reduce) === "function") {
let keys = []; let keys = [];
return array.reduce(function (groups, element, index) { return array.reduce(function (groups, element, index) {
let key = JSON.stringify(keySelector.call(arguments[1], element, index, array)) let key = JSON.stringify(keySelector.call(arguments[1], element, index, array));
let index2 = keys.findIndex(function (x) { let index2 = keys.findIndex(function (x) {
return x === key; return x === key;
}); });
+6 -5
View File
@@ -1,10 +1,5 @@
module es { module es {
export class GraphicsDevice { export class GraphicsDevice {
private _viewport: Viewport;
public get viewport(): Viewport{
return this._viewport;
}
public graphicsCapabilities: GraphicsCapabilities; public graphicsCapabilities: GraphicsCapabilities;
constructor() { constructor() {
@@ -13,6 +8,12 @@ module es {
this.graphicsCapabilities.initialize(this); this.graphicsCapabilities.initialize(this);
} }
private _viewport: Viewport;
public get viewport(): Viewport {
return this._viewport;
}
private setup() { private setup() {
this._viewport = new Viewport(0, 0, Core._instance.stage.stageWidth, Core._instance.stage.stageHeight); this._viewport = new Viewport(0, 0, Core._instance.stage.stageWidth, Core._instance.stage.stageHeight);
} }
@@ -1,10 +1,5 @@
module es { module es {
export class PostProcessor { export class PostProcessor {
public enabled: boolean;
public effect: egret.Filter;
public scene: Scene;
public shape: egret.Shape;
public static default_vert = "attribute vec2 aVertexPosition;\n" + public static default_vert = "attribute vec2 aVertexPosition;\n" +
"attribute vec2 aTextureCoord;\n" + "attribute vec2 aTextureCoord;\n" +
"attribute vec2 aColor;\n" + "attribute vec2 aColor;\n" +
@@ -22,6 +17,10 @@ module es {
"vTextureCoord = aTextureCoord;\n" + "vTextureCoord = aTextureCoord;\n" +
"vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" +
"}"; "}";
public enabled: boolean;
public effect: egret.Filter;
public scene: Scene;
public shape: egret.Shape;
constructor(effect: egret.Filter = null) { constructor(effect: egret.Filter = null) {
this.enabled = true; this.enabled = true;
@@ -41,11 +40,7 @@ module es {
this.drawFullscreenQuad(); this.drawFullscreenQuad();
} }
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){} public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number) {
protected drawFullscreenQuad(){
this.scene.filters = [this.effect];
// this.shape.filters = [this.effect];
} }
public unload() { public unload() {
@@ -56,5 +51,10 @@ module es {
this.scene.removeChild(this.shape); this.scene.removeChild(this.shape);
this.scene = null; this.scene = null;
} }
protected drawFullscreenQuad() {
this.scene.filters = [this.effect];
// this.shape.filters = [this.effect];
}
} }
} }
@@ -1,17 +1,9 @@
module es { module es {
export class PolyLight extends RenderableComponent { export class PolyLight extends RenderableComponent {
public power: number; public power: number;
protected _radius: number;
private _lightEffect; private _lightEffect;
private _indices: number[] = []; private _indices: number[] = [];
public get radius(){
return this._radius;
}
public set radius(value: number){
this.setRadius(value);
}
constructor(radius: number, color: number, power: number) { constructor(radius: number, color: number, power: number) {
super(); super();
@@ -21,14 +13,14 @@ module es {
this.computeTriangleIndices(); this.computeTriangleIndices();
} }
private computeTriangleIndices(totalTris: number = 20){ protected _radius: number;
this._indices.length = 0;
for (let i = 0; i < totalTris; i += 2){ public get radius() {
this._indices.push(0); return this._radius;
this._indices.push(i + 2);
this._indices.push(i + 1);
} }
public set radius(value: number) {
this.setRadius(value);
} }
public setRadius(radius: number) { public setRadius(radius: number) {
@@ -44,5 +36,15 @@ module es {
public reset() { public reset() {
} }
private computeTriangleIndices(totalTris: number = 20) {
this._indices.length = 0;
for (let i = 0; i < totalTris; i += 2) {
this._indices.push(0);
this._indices.push(i + 2);
this._indices.push(i + 1);
}
}
} }
} }
+20 -17
View File
@@ -23,30 +23,17 @@ module es {
* *
* @param scene * @param scene
*/ */
public onAddedToScene(scene: Scene){} public onAddedToScene(scene: Scene) {
}
/** /**
* 使 * 使
*/ */
public unload(){ } public unload() {
}
/**
*
* @param cam
*/
protected beginRender(cam: Camera){ }
public abstract render(scene: Scene); public abstract render(scene: Scene);
/**
*
* @param renderable
* @param cam
*/
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera){
renderable.render(cam);
}
/** /**
* *
* @param newWidth * @param newWidth
@@ -59,5 +46,21 @@ module es {
public compareTo(other: Renderer): number { public compareTo(other: Renderer): number {
return this.renderOrder - other.renderOrder; return this.renderOrder - other.renderOrder;
} }
/**
*
* @param cam
*/
protected beginRender(cam: Camera) {
}
/**
*
* @param renderable
* @param cam
*/
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera) {
renderable.render(cam);
}
} }
} }
@@ -3,7 +3,6 @@ module es {
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡 * SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
*/ */
export abstract class SceneTransition { export abstract class SceneTransition {
private _hasPreviousSceneRender: boolean;
/** 是否加载新场景的标志 */ /** 是否加载新场景的标志 */
public loadsNewScene: boolean; public loadsNewScene: boolean;
/** /**
@@ -11,12 +10,19 @@ module es {
* isNewSceneLoaded应该在中点设置为true * isNewSceneLoaded应该在中点设置为true
*/ */
public isNewSceneLoaded: boolean; public isNewSceneLoaded: boolean;
/** 返回新加载场景的函数 */
protected sceneLoadAction: Function;
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */ /** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
public onScreenObscured: Function; public onScreenObscured: Function;
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */ /** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
public onTransitionCompleted: Function; public onTransitionCompleted: Function;
/** 返回新加载场景的函数 */
protected sceneLoadAction: Function;
constructor(sceneLoadAction: Function) {
this.sceneLoadAction = sceneLoadAction;
this.loadsNewScene = sceneLoadAction != null;
}
private _hasPreviousSceneRender: boolean;
public get hasPreviousSceneRender() { public get hasPreviousSceneRender() {
if (!this._hasPreviousSceneRender) { if (!this._hasPreviousSceneRender) {
@@ -27,13 +33,9 @@ module es {
return true; return true;
} }
constructor(sceneLoadAction: Function) { public preRender() {
this.sceneLoadAction = sceneLoadAction;
this.loadsNewScene = sceneLoadAction != null;
} }
public preRender() { }
public render() { public render() {
} }
@@ -43,6 +45,17 @@ module es {
this.transitionComplete(); this.transitionComplete();
} }
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise<boolean> {
return new Promise((resolve) => {
let start = reverseDirection ? 1 : 0;
let end = reverseDirection ? 0 : 1;
egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(() => {
resolve();
});
});
}
protected transitionComplete() { protected transitionComplete() {
Core._instance._sceneTransition = null; Core._instance._sceneTransition = null;
@@ -62,16 +75,5 @@ module es {
Core.scene = await this.sceneLoadAction(); Core.scene = await this.sceneLoadAction();
this.isNewSceneLoaded = true; this.isNewSceneLoaded = true;
} }
public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise<boolean>{
return new Promise((resolve)=>{
let start = reverseDirection ? 1 : 0;
let end = reverseDirection ? 0 : 1;
egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(()=>{
resolve();
});
});
}
} }
} }
@@ -1,16 +1,10 @@
module es { module es {
export class WindTransition extends SceneTransition { export class WindTransition extends SceneTransition {
public duration = 1;
public easeType = egret.Ease.quadOut;
private _mask: egret.Shape; private _mask: egret.Shape;
private _windEffect: egret.CustomFilter; private _windEffect: egret.CustomFilter;
public duration = 1;
public set windSegments(value: number) {
this._windEffect.uniforms._windSegments = value;
}
public set size(value: number) {
this._windEffect.uniforms._size = value;
}
public easeType = egret.Ease.quadOut;
constructor(sceneLoadAction: Function) { constructor(sceneLoadAction: Function) {
super(sceneLoadAction); super(sceneLoadAction);
@@ -56,6 +50,14 @@ module es {
this._mask.filters = [this._windEffect]; this._mask.filters = [this._windEffect];
} }
public set windSegments(value: number) {
this._windEffect.uniforms._windSegments = value;
}
public set size(value: number) {
this._windEffect.uniforms._size = value;
}
public async onBeginTransition() { public async onBeginTransition() {
this.loadNextScene(); this.loadNextScene();
await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType); await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType);
+21 -16
View File
@@ -2,25 +2,38 @@ module es {
export class Viewport { export class Viewport {
private _x: number; private _x: number;
private _y: number; private _y: number;
private _width: number;
private _height: number;
private _minDepth: number; private _minDepth: number;
private _maxDepth: number; private _maxDepth: number;
public get height(){ constructor(x: number, y: number, width: number, height: number) {
return this._height; this._x = x;
} this._y = y;
public set height(value: number){ this._width = width;
this._height = value; this._height = height;
this._minDepth = 0;
this._maxDepth = 1;
} }
private _width: number;
public get width() { public get width() {
return this._width; return this._width;
} }
public set width(value: number) { public set width(value: number) {
this._width = value; this._width = value;
} }
private _height: number;
public get height() {
return this._height;
}
public set height(value: number) {
this._height = value;
}
public get aspectRatio() { public get aspectRatio() {
if ((this._height != 0) && (this._width != 0)) if ((this._height != 0) && (this._width != 0))
return (this._width / this._height); return (this._width / this._height);
@@ -30,6 +43,7 @@ module es {
public get bounds() { public get bounds() {
return new Rectangle(this._x, this._y, this._width, this._height); return new Rectangle(this._x, this._y, this._width, this._height);
} }
public set bounds(value: Rectangle) { public set bounds(value: Rectangle) {
this._x = value.x; this._x = value.x;
this._y = value.y; this._y = value.y;
@@ -37,14 +51,5 @@ module es {
this._height = value.height; this._height = value.height;
} }
constructor(x: number, y: number, width: number, height: number){
this._x = x;
this._y = y;
this._width = width;
this._height = height;
this._minDepth = 0;
this._maxDepth = 1;
}
} }
} }
+12
View File
@@ -1,5 +1,6 @@
module es { module es {
export var matrixPool = []; export var matrixPool = [];
/** /**
* 3 * 3 * 3 * 3
*/ */
@@ -7,36 +8,47 @@ module es {
public get m11(): number { public get m11(): number {
return this.a; return this.a;
} }
public set m11(value: number) { public set m11(value: number) {
this.a = value; this.a = value;
} }
public get m12(): number { public get m12(): number {
return this.b; return this.b;
} }
public set m12(value: number) { public set m12(value: number) {
this.b = value; this.b = value;
} }
public get m21(): number { public get m21(): number {
return this.c; return this.c;
} }
public set m21(value: number) { public set m21(value: number) {
this.c = value; this.c = value;
} }
public get m22(): number { public get m22(): number {
return this.d; return this.d;
} }
public set m22(value: number) { public set m22(value: number) {
this.d = value; this.d = value;
} }
public get m31(): number { public get m31(): number {
return this.tx; return this.tx;
} }
public set m31(value: number) { public set m31(value: number) {
this.tx = value; this.tx = value;
} }
public get m32(): number { public get m32(): number {
return this.ty; return this.ty;
} }
public set m32(value: number) { public set m32(value: number) {
this.ty = value; this.ty = value;
} }
+37 -35
View File
@@ -2,6 +2,7 @@ module es {
export class Rectangle extends egret.Rectangle { export class Rectangle extends egret.Rectangle {
public _tempMat: Matrix2D; public _tempMat: Matrix2D;
public _transformMat: Matrix2D; public _transformMat: Matrix2D;
/** /**
* *
*/ */
@@ -18,6 +19,7 @@ module es {
public get location() { public get location() {
return new Vector2(this.x, this.y); return new Vector2(this.x, this.y);
} }
/** 左上角的坐标 */ /** 左上角的坐标 */
public set location(value: Vector2) { public set location(value: Vector2) {
this.x = value.x; this.x = value.x;
@@ -33,6 +35,41 @@ module es {
this.height = value.y; this.height = value.y;
} }
/**
* /()
* @param minX
* @param minY
* @param maxX
* @param maxY
*/
public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) {
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
}
/**
*
* @param points
*/
public static rectEncompassingPoints(points: Vector2[]) {
// 我们需要求出x/y的最小值/最大值
let minX = Number.POSITIVE_INFINITY;
let minY = Number.POSITIVE_INFINITY;
let maxX = Number.NEGATIVE_INFINITY;
let maxY = Number.NEGATIVE_INFINITY;
for (let i = 0; i < points.length; i++) {
let pt = points[i];
if (pt.x < minX) minX = pt.x;
if (pt.x > maxX) maxX = pt.x;
if (pt.y < minY) minY = pt.y;
if (pt.y > maxY) maxY = pt.y;
}
return this.fromMinMax(minX, minY, maxX, maxY);
}
/** /**
* *
* @param value * @param value
@@ -58,17 +95,6 @@ module es {
return new Vector2(this.width * 0.5, this.height * 0.5); return new Vector2(this.width * 0.5, this.height * 0.5);
} }
/**
* /()
* @param minX
* @param minY
* @param maxX
* @param maxY
*/
public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) {
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
}
/** /**
* *
* @param point * @param point
@@ -183,29 +209,5 @@ module es {
this.height = maxY - minY; this.height = maxY - minY;
} }
} }
/**
*
* @param points
*/
public static rectEncompassingPoints(points: Vector2[]) {
// 我们需要求出x/y的最小值/最大值
let minX = Number.POSITIVE_INFINITY;
let minY = Number.POSITIVE_INFINITY;
let maxX = Number.NEGATIVE_INFINITY;
let maxY = Number.NEGATIVE_INFINITY;
for (let i = 0; i < points.length; i++) {
let pt = points[i];
if (pt.x < minX) minX = pt.x;
if (pt.x > maxX) maxX = pt.x;
if (pt.y < minY) minY = pt.y;
if (pt.y > maxY) maxY = pt.y;
}
return this.fromMinMax(minX, minY, maxX, maxY);
}
} }
} }
+70 -70
View File
@@ -1,13 +1,23 @@
module es { module es {
/** 2d 向量 */ /** 2d 向量 */
export class Vector2 { export class Vector2 {
public x: number = 0;
public y: number = 0;
private static readonly unitYVector = new Vector2(0, 1); private static readonly unitYVector = new Vector2(0, 1);
private static readonly unitXVector = new Vector2(1, 0); private static readonly unitXVector = new Vector2(1, 0);
private static readonly unitVector2 = new Vector2(1, 1); private static readonly unitVector2 = new Vector2(1, 1);
private static readonly zeroVector2 = new Vector2(0, 0); private static readonly zeroVector2 = new Vector2(0, 0);
public x: number = 0;
public y: number = 0;
/**
* X和Y的二维向量
* @param x x坐标
* @param y y坐标
*/
constructor(x?: number, y?: number) {
this.x = x ? x : 0;
this.y = y ? y : this.x;
}
public static get zero() { public static get zero() {
return Vector2.zeroVector2; return Vector2.zeroVector2;
} }
@@ -24,56 +34,6 @@ module es {
return Vector2.unitYVector; return Vector2.unitYVector;
} }
/**
* X和Y的二维向量
* @param x x坐标
* @param y y坐标
*/
constructor(x? : number, y?: number){
this.x = x ? x : 0;
this.y = y ? y : this.x;
}
/**
*
* @param value
*/
public add(value: Vector2): Vector2{
this.x += value.x;
this.y += value.y;
return this;
}
/**
*
* @param value
*/
public divide(value: Vector2): Vector2{
this.x /= value.x;
this.y /= value.y;
return this;
}
/**
*
* @param value
*/
public multiply(value: Vector2): Vector2{
this.x *= value.x;
this.y *= value.y;
return this;
}
/**
*
* @param value
*/
public subtract(value: Vector2){
this.x -= value.x;
this.y -= value.y;
return this;
}
/** /**
* *
* @param value1 * @param value1
@@ -122,23 +82,6 @@ module es {
return result; return result;
} }
/** 变成一个方向相同的单位向量 */
public normalize(){
let val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
this.x *= val;
this.y *= val;
}
/** 返回它的长度 */
public length(){
return Math.sqrt((this.x * this.x) + (this.y * this.y));
}
/** 对x和y值四舍五入 */
public round(): Vector2{
return new Vector2(Math.round(this.x), Math.round(this.y));
}
/** /**
* Vector2 * Vector2
* *
@@ -223,6 +166,63 @@ module es {
return result; return result;
} }
/**
*
* @param value
*/
public add(value: Vector2): Vector2 {
this.x += value.x;
this.y += value.y;
return this;
}
/**
*
* @param value
*/
public divide(value: Vector2): Vector2 {
this.x /= value.x;
this.y /= value.y;
return this;
}
/**
*
* @param value
*/
public multiply(value: Vector2): Vector2 {
this.x *= value.x;
this.y *= value.y;
return this;
}
/**
*
* @param value
*/
public subtract(value: Vector2) {
this.x -= value.x;
this.y -= value.y;
return this;
}
/** 变成一个方向相同的单位向量 */
public normalize() {
let val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
this.x *= val;
this.y *= val;
}
/** 返回它的长度 */
public length() {
return Math.sqrt((this.x * this.x) + (this.y * this.y));
}
/** 对x和y值四舍五入 */
public round(): Vector2 {
return new Vector2(Math.round(this.x), Math.round(this.y));
}
public equals(other: Vector2) { public equals(other: Vector2) {
return other.x == this.x && other.y == this.y; return other.x == this.x && other.y == this.y;
} }
+1 -1
View File
@@ -1,10 +1,10 @@
module es { module es {
export class Physics { export class Physics {
private static _spatialHash: SpatialHash;
/** 调用reset并创建一个新的SpatialHash时使用的单元格大小 */ /** 调用reset并创建一个新的SpatialHash时使用的单元格大小 */
public static spatialHashCellSize = 100; public static spatialHashCellSize = 100;
/** 接受layerMask的所有方法的默认值 */ /** 接受layerMask的所有方法的默认值 */
public static readonly allLayers: number = -1; public static readonly allLayers: number = -1;
private static _spatialHash: SpatialHash;
public static reset() { public static reset() {
this._spatialHash = new SpatialHash(this.spatialHashCellSize); this._spatialHash = new SpatialHash(this.spatialHashCellSize);
+54 -55
View File
@@ -9,19 +9,7 @@ module es {
* *
*/ */
public points: Vector2[]; public points: Vector2[];
/**
* 线SAT碰撞检测squareRoots
* box只有两个边缘
*/
public get edgeNormals(){
if (this._areEdgeNormalsDirty)
this.buildEdgeNormals();
return this._edgeNormals;
}
public _areEdgeNormalsDirty = true; public _areEdgeNormalsDirty = true;
public _edgeNormals: Vector2[];
/** /**
* *
*/ */
@@ -46,54 +34,18 @@ module es {
this.isBox = isBox; this.isBox = isBox;
} }
/** public _edgeNormals: Vector2[];
* 线
* @param points
*/
public setPoints(points: Vector2[]) {
this.points = points;
this.recalculateCenterAndEdgeNormals();
this._originalPoints = [];
for (let i = 0; i < this.points.length; i ++){
this._originalPoints.push(this.points[i]);
}
}
/** /**
* * 线SAT碰撞检测squareRoots
* * box只有两个边缘
*/ */
public recalculateCenterAndEdgeNormals() { public get edgeNormals() {
this._polygonCenter = Polygon.findPolygonCenter(this.points); if (this._areEdgeNormalsDirty)
this._areEdgeNormalsDirty = true; this.buildEdgeNormals();
return this._edgeNormals;
} }
/**
* 线
* edgeNormals getter惰性创建和更新
*/
public buildEdgeNormals(){
// 对于box 我们只需要两条边,因为另外两条边是平行的
let totalEdges = this.isBox ? 2 : this.points.length;
if (this._edgeNormals == null || this._edgeNormals.length != totalEdges)
this._edgeNormals = new Array(totalEdges);
let p2: Vector2;
for (let i = 0; i < totalEdges; i ++){
let p1 = this.points[i];
if (i + 1 >= this.points.length)
p2 = this.points[0];
else
p2 = this.points[i + 1];
let perp = Vector2Ext.perpendicular(p1, p2);
perp = Vector2.normalize(perp);
this._edgeNormals[i] = perp;
}
}
/** /**
* (n角形) * (n角形)
* @param vertCount * @param vertCount
@@ -173,6 +125,53 @@ module es {
return closestPoint; return closestPoint;
} }
/**
* 线
* @param points
*/
public setPoints(points: Vector2[]) {
this.points = points;
this.recalculateCenterAndEdgeNormals();
this._originalPoints = [];
for (let i = 0; i < this.points.length; i++) {
this._originalPoints.push(this.points[i]);
}
}
/**
*
*
*/
public recalculateCenterAndEdgeNormals() {
this._polygonCenter = Polygon.findPolygonCenter(this.points);
this._areEdgeNormalsDirty = true;
}
/**
* 线
* edgeNormals getter惰性创建和更新
*/
public buildEdgeNormals() {
// 对于box 我们只需要两条边,因为另外两条边是平行的
let totalEdges = this.isBox ? 2 : this.points.length;
if (this._edgeNormals == null || this._edgeNormals.length != totalEdges)
this._edgeNormals = new Array(totalEdges);
let p2: Vector2;
for (let i = 0; i < totalEdges; i++) {
let p1 = this.points[i];
if (i + 1 >= this.points.length)
p2 = this.points[0];
else
p2 = this.points[i + 1];
let perp = Vector2Ext.perpendicular(p1, p2);
perp = Vector2.normalize(perp);
this._edgeNormals[i] = perp;
}
}
public recalculateBounds(collider: Collider) { public recalculateBounds(collider: Collider) {
// 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始 // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始
this.center = collider.localOffset; this.center = collider.localOffset;
+3
View File
@@ -16,8 +16,11 @@ module es {
public bounds: Rectangle; public bounds: Rectangle;
public abstract recalculateBounds(collider: Collider); public abstract recalculateBounds(collider: Collider);
public abstract overlaps(other: Shape): boolean; public abstract overlaps(other: Shape): boolean;
public abstract collidesWithShape(other: Shape, collisionResult: CollisionResult): boolean; public abstract collidesWithShape(other: Shape, collisionResult: CollisionResult): boolean;
public abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean; public abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
public clone(): Shape { public clone(): Shape {
+40 -40
View File
@@ -30,33 +30,6 @@ module es {
this._raycastParser = new RaycastResultParser(); this._raycastParser = new RaycastResultParser();
} }
/**
* x,y值作为世界空间的x,y值
* @param x
* @param y
*/
private cellCoords(x: number, y: number): Vector2 {
return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
}
/**
* x,y值的单元格
* createCellIfEmpty为true
* @param x
* @param y
* @param createCellIfEmpty
*/
private cellAtPosition(x: number, y: number, createCellIfEmpty: boolean = false) {
let cell: Collider[] = this._cellDict.tryGetValue(x, y);
if (!cell) {
if (createCellIfEmpty) {
cell = [];
this._cellDict.add(x, y, cell);
}
}
return cell;
}
/** /**
* SpatialHash * SpatialHash
* @param collider * @param collider
@@ -134,10 +107,6 @@ module es {
} }
} }
private debugDrawCellDetails(x: number, y: number, cellCount: number, secondsToDisplay = 0.5, textScale = 1){
}
/** /**
* *
* @param bounds * @param bounds
@@ -216,6 +185,37 @@ module es {
return resultCounter; return resultCounter;
} }
/**
* x,y值作为世界空间的x,y值
* @param x
* @param y
*/
private cellCoords(x: number, y: number): Vector2 {
return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
}
/**
* x,y值的单元格
* createCellIfEmpty为true
* @param x
* @param y
* @param createCellIfEmpty
*/
private cellAtPosition(x: number, y: number, createCellIfEmpty: boolean = false) {
let cell: Collider[] = this._cellDict.tryGetValue(x, y);
if (!cell) {
if (createCellIfEmpty) {
cell = [];
this._cellDict.add(x, y, cell);
}
}
return cell;
}
private debugDrawCellDetails(x: number, y: number, cellCount: number, secondsToDisplay = 0.5, textScale = 1) {
}
} }
/** /**
@@ -225,15 +225,6 @@ module es {
export class NumberDictionary { export class NumberDictionary {
public _store: Map<string, Collider[]> = new Map<string, Collider[]>(); public _store: Map<string, Collider[]> = new Map<string, Collider[]>();
/**
* x和y值计算并返回散列键
* @param x
* @param y
*/
private getKey(x: number, y: number): string {
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
}
public add(x: number, y: number, list: Collider[]) { public add(x: number, y: number, list: Collider[]) {
this._store.set(this.getKey(x, y), list); this._store.set(this.getKey(x, y), list);
} }
@@ -259,6 +250,15 @@ module es {
public clear() { public clear() {
this._store.clear(); this._store.clear();
} }
/**
* x和y值计算并返回散列键
* @param x
* @param y
*/
private getKey(x: number, y: number): string {
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
}
} }
export class RaycastResultParser { export class RaycastResultParser {
+44 -43
View File
@@ -25,7 +25,8 @@ namespace stopwatch {
*/ */
private _completeSlices: Slice[] = []; private _completeSlices: Slice[] = [];
constructor(private readonly getSystemTime = _defaultSystemTimeGetter) { } constructor(private readonly getSystemTime = _defaultSystemTimeGetter) {
}
public getState() { public getState() {
if (this._startSystemTime === undefined) { if (this._startSystemTime === undefined) {
@@ -84,48 +85,6 @@ namespace stopwatch {
return this.caculateStopwatchTime(); return this.caculateStopwatchTime();
} }
/**
*
* @param endStopwatchTime
*/
private calculatePendingSlice(endStopwatchTime?: number): Slice {
if (this._pendingSliceStartStopwatchTime === undefined){
return Object.freeze({startTime: 0, endTime: 0, duration: 0});
}
if (endStopwatchTime === undefined){
endStopwatchTime = this.getTime();
}
return Object.freeze({
startTime: this._pendingSliceStartStopwatchTime,
endTime: endStopwatchTime,
duration: endStopwatchTime - this._pendingSliceStartStopwatchTime
});
}
/**
*
* @param endSystemTime
*/
private caculateStopwatchTime(endSystemTime?: number){
if (this._startSystemTime === undefined)
return 0;
if (endSystemTime === undefined)
endSystemTime = this.getSystemTimeOfCurrentStopwatchTime();
return endSystemTime - this._startSystemTime - this._stopDuration;
}
/**
*
*
*/
private getSystemTimeOfCurrentStopwatchTime(){
return this._stopSystemTime === undefined ? this.getSystemTime() : this._stopSystemTime;
}
/** /**
* *
*/ */
@@ -176,6 +135,48 @@ namespace stopwatch {
return this.getTime(); return this.getTime();
} }
/**
*
* @param endStopwatchTime
*/
private calculatePendingSlice(endStopwatchTime?: number): Slice {
if (this._pendingSliceStartStopwatchTime === undefined) {
return Object.freeze({startTime: 0, endTime: 0, duration: 0});
}
if (endStopwatchTime === undefined) {
endStopwatchTime = this.getTime();
}
return Object.freeze({
startTime: this._pendingSliceStartStopwatchTime,
endTime: endStopwatchTime,
duration: endStopwatchTime - this._pendingSliceStartStopwatchTime
});
}
/**
*
* @param endSystemTime
*/
private caculateStopwatchTime(endSystemTime?: number) {
if (this._startSystemTime === undefined)
return 0;
if (endSystemTime === undefined)
endSystemTime = this.getSystemTimeOfCurrentStopwatchTime();
return endSystemTime - this._startSystemTime - this._stopDuration;
}
/**
*
*
*/
private getSystemTimeOfCurrentStopwatchTime() {
return this._stopSystemTime === undefined ? this.getSystemTime() : this._stopSystemTime;
}
/** /**
* / * /
* @param endStopwatchTime * @param endStopwatchTime
+18 -18
View File
@@ -18,23 +18,19 @@ module es {
public static readonly barPadding = 2; public static readonly barPadding = 2;
public static readonly autoAdjustDelay = 30; public static readonly autoAdjustDelay = 30;
private static _instance; private static _instance;
public static get Instance(): TimeRuler{
if (!this._instance)
this._instance = new TimeRuler();
return this._instance;
}
private _frameKey = 'frame';
private _logKey = 'log';
/** 每帧的日志 */
private _logs: FrameLog[];
/** 当前显示帧计数 */
private sampleFrames: number;
/** 获取/设置目标样本帧。 */ /** 获取/设置目标样本帧。 */
public targetSampleFrames: number; public targetSampleFrames: number;
/** 获取/设置计时器标尺宽度。 */ /** 获取/设置计时器标尺宽度。 */
public width: number; public width: number;
public enabled: true; public enabled: true;
/** */
public showLog = false;
private _frameKey = 'frame';
private _logKey = 'log';
/** 每帧的日志 */
private _logs: FrameLog[];
/** 当前显示帧计数 */
private sampleFrames: number;
/** TimerRuler画的位置。 */ /** TimerRuler画的位置。 */
private _position: Vector2; private _position: Vector2;
/** 上一帧日志 */ /** 上一帧日志 */
@@ -56,8 +52,6 @@ module es {
* StartFrame调用的次数Draw被调用 * StartFrame调用的次数Draw被调用
*/ */
private _updateCount: number; private _updateCount: number;
/** */
public showLog = false;
private _frameAdjust: number; private _frameAdjust: number;
constructor() { constructor() {
@@ -72,9 +66,10 @@ module es {
this.onGraphicsDeviceReset(); this.onGraphicsDeviceReset();
} }
private onGraphicsDeviceReset() { public static get Instance(): TimeRuler {
let layout = new Layout(); if (!this._instance)
this._position = layout.place(new Vector2(this.width, TimeRuler.barHeight), 0, 0.01, Alignment.bottomCenter).location; this._instance = new TimeRuler();
return this._instance;
} }
/** /**
@@ -273,7 +268,7 @@ module es {
height += TimeRuler.barHeight + TimeRuler.barPadding * 2; height += TimeRuler.barHeight + TimeRuler.barPadding * 2;
maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime); maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime);
} }
}) });
const frameSpan = 1 / 60 * 1000; const frameSpan = 1 / 60 * 1000;
let sampleSpan = this.sampleFrames * frameSpan; let sampleSpan = this.sampleFrames * frameSpan;
@@ -297,6 +292,11 @@ module es {
// TODO: draw // TODO: draw
} }
private onGraphicsDeviceReset() {
let layout = new Layout();
this._position = layout.place(new Vector2(this.width, TimeRuler.barHeight), 0, 0.01, Alignment.bottomCenter).location;
}
} }
/** /**
+3 -4
View File
@@ -139,17 +139,16 @@ class ArrayUtils {
aryA = this.getUniqueAry(aryA); aryA = this.getUniqueAry(aryA);
aryB = this.getUniqueAry(aryB); aryB = this.getUniqueAry(aryB);
let ary: number[] = aryA.concat(aryB); let ary: number[] = aryA.concat(aryB);
let uObj: Object = new Object(); let uObj: Object = {};
let newAry: number[] = []; let newAry: number[] = [];
let count: number = ary.length; let count: number = ary.length;
for (let j: number = 0; j < count; ++j) { for (let j: number = 0; j < count; ++j) {
if (!uObj[ary[j]]) { if (!uObj[ary[j]]) {
uObj[ary[j]] = new Object(); uObj[ary[j]] = {};
uObj[ary[j]].count = 0; uObj[ary[j]].count = 0;
uObj[ary[j]].key = ary[j]; uObj[ary[j]].key = ary[j];
uObj[ary[j]].count++; uObj[ary[j]].count++;
} } else {
else {
if (uObj[ary[j]] instanceof Object) { if (uObj[ary[j]] instanceof Object) {
uObj[ary[j]].count++; uObj[ary[j]].count++;
} }
+21 -21
View File
@@ -29,27 +29,7 @@ class Base64Utils {
this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4); this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4);
} }
return this._keyStr.charAt(Math.floor((Math.random() * this._keyStr.length))) + output; return this._keyStr.charAt(Math.floor((Math.random() * this._keyStr.length))) + output;
} };
private static _utf8_encode(string) {
string = string.replace(/\r\n/g, "\n");
let utftext = "";
for (let n = 0; n < string.length; n++) {
let c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
/** /**
* *
@@ -92,6 +72,26 @@ class Base64Utils {
return output; return output;
} }
private static _utf8_encode(string) {
string = string.replace(/\r\n/g, "\n");
let utftext = "";
for (let n = 0; n < string.length; n++) {
let c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
private static _utf8_decode(utftext) { private static _utf8_decode(utftext) {
let string = ""; let string = "";
let i = 0; let i = 0;
+1
View File
@@ -13,6 +13,7 @@ module es {
this.context = context; this.context = context;
} }
} }
/** /**
* *
*/ */
+8 -4
View File
@@ -1,5 +1,7 @@
module es { module es {
export class GlobalManager { export class GlobalManager {
public _enabled: boolean;
/** /**
* true则启用了GlobalManager * true则启用了GlobalManager
* OnEnabled/OnDisable * OnEnabled/OnDisable
@@ -31,21 +33,23 @@ module es {
} }
} }
} }
public _enabled: boolean;
/** /**
* GlobalManager启用时调用 * GlobalManager启用时调用
*/ */
public onEnabled(){} public onEnabled() {
}
/** /**
* GlobalManager禁用时调用 * GlobalManager禁用时调用
*/ */
public onDisabled(){} public onDisabled() {
}
/** /**
* frame .update之前调用每一帧 * frame .update之前调用每一帧
*/ */
public update(){} public update() {
}
} }
} }
+43 -33
View File
@@ -4,6 +4,7 @@ module es {
public y = 0; public y = 0;
public touchPoint: number = -1; public touchPoint: number = -1;
public touchDown: boolean = false; public touchDown: boolean = false;
public get position() { public get position() {
return new Vector2(this.x, this.y); return new Vector2(this.x, this.y);
} }
@@ -19,36 +20,11 @@ module es {
export class Input { export class Input {
private static _init: boolean = false; private static _init: boolean = false;
private static _previousTouchState: TouchState = new TouchState(); private static _previousTouchState: TouchState = new TouchState();
private static _gameTouchs: TouchState[] = [];
private static _resolutionOffset: Vector2 = new Vector2(); private static _resolutionOffset: Vector2 = new Vector2();
private static _resolutionScale: Vector2 = Vector2.one;
private static _touchIndex: number = 0; private static _touchIndex: number = 0;
private static _totalTouchCount: number = 0;
/** 返回第一个触摸点的坐标 */ private static _gameTouchs: TouchState[] = [];
public static get touchPosition(){
if (!this._gameTouchs[0])
return Vector2.zero;
return this._gameTouchs[0].position;
}
/** 获取最大触摸数 */
public static get maxSupportedTouch(){
return Core._instance.stage.maxTouches;
}
/**
*
*/
public static set maxSupportedTouch(value: number){
Core._instance.stage.maxTouches = value;
this.initTouchCache();
}
/** 获取缩放值 默认为1 */
public static get resolutionScale(){
return this._resolutionScale;
}
/** 当前触摸点数量 */
public static get totalTouchCount(){
return this._totalTouchCount;
}
/** /**
* *
* touchPoint是否为-1 * touchPoint是否为-1
@@ -58,6 +34,40 @@ module es {
return this._gameTouchs; return this._gameTouchs;
} }
private static _resolutionScale: Vector2 = Vector2.one;
/** 获取缩放值 默认为1 */
public static get resolutionScale() {
return this._resolutionScale;
}
private static _totalTouchCount: number = 0;
/** 当前触摸点数量 */
public static get totalTouchCount() {
return this._totalTouchCount;
}
/** 返回第一个触摸点的坐标 */
public static get touchPosition() {
if (!this._gameTouchs[0])
return Vector2.zero;
return this._gameTouchs[0].position;
}
/** 获取最大触摸数 */
public static get maxSupportedTouch() {
return Core._instance.stage.maxTouches;
}
/**
*
*/
public static set maxSupportedTouch(value: number) {
Core._instance.stage.maxTouches = value;
this.initTouchCache();
}
/** 获取第一个触摸点距离上次距离的增量 */ /** 获取第一个触摸点距离上次距离的增量 */
public static get touchPositionDelta() { public static get touchPositionDelta() {
let delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position); let delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position);
@@ -81,6 +91,11 @@ module es {
this.initTouchCache(); this.initTouchCache();
} }
public static scaledPosition(position: Vector2) {
let scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y);
return Vector2.multiply(scaledPos, this.resolutionScale);
}
private static initTouchCache() { private static initTouchCache() {
this._totalTouchCount = 0; this._totalTouchCount = 0;
this._touchIndex = 0; this._touchIndex = 0;
@@ -138,10 +153,5 @@ module es {
this._previousTouchState.touchPoint = touchState.touchPoint; this._previousTouchState.touchPoint = touchState.touchPoint;
this._previousTouchState.touchDown = touchState.touchDown; this._previousTouchState.touchDown = touchState.touchDown;
} }
public static scaledPosition(position: Vector2){
let scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y);
return Vector2.multiply(scaledPos, this.resolutionScale);
}
} }
} }
+37 -51
View File
@@ -4,12 +4,6 @@ class KeyboardUtils {
*/ */
public static TYPE_KEY_DOWN: number = 0; public static TYPE_KEY_DOWN: number = 0;
public static TYPE_KEY_UP: number = 1; public static TYPE_KEY_UP: number = 1;
//存放按下注册数据的字典
private static keyDownDict: Object;
//存放按起注册数据的字典
private static keyUpDict: Object;
/** /**
* *
*/ */
@@ -39,7 +33,6 @@ class KeyboardUtils {
public static X: string = "X"; public static X: string = "X";
public static Y: string = "Y"; public static Y: string = "Y";
public static Z: string = "Z"; public static Z: string = "Z";
public static ESC: string = "Esc"; public static ESC: string = "Esc";
public static F1: string = "F1"; public static F1: string = "F1";
public static F2: string = "F2"; public static F2: string = "F2";
@@ -53,7 +46,6 @@ class KeyboardUtils {
public static F10: string = "F10"; public static F10: string = "F10";
public static F11: string = "F11"; public static F11: string = "F11";
public static F12: string = "F12"; public static F12: string = "F12";
public static NUM_1: string = "1"; public static NUM_1: string = "1";
public static NUM_2: string = "2"; public static NUM_2: string = "2";
public static NUM_3: string = "3"; public static NUM_3: string = "3";
@@ -64,7 +56,6 @@ class KeyboardUtils {
public static NUM_8: string = "8"; public static NUM_8: string = "8";
public static NUM_9: string = "9"; public static NUM_9: string = "9";
public static NUM_0: string = "0"; public static NUM_0: string = "0";
public static TAB: string = "Tab"; public static TAB: string = "Tab";
public static CTRL: string = "Ctrl"; public static CTRL: string = "Ctrl";
public static ALT: string = "Alt"; public static ALT: string = "Alt";
@@ -73,25 +64,24 @@ class KeyboardUtils {
public static ENTER: string = "Enter"; public static ENTER: string = "Enter";
public static SPACE: string = "Space"; public static SPACE: string = "Space";
public static BACK_SPACE: string = "Back Space"; public static BACK_SPACE: string = "Back Space";
public static INSERT: string = "Insert"; public static INSERT: string = "Insert";
public static DELETE: string = "Page Down"; public static DELETE: string = "Page Down";
public static HOME: string = "Home"; public static HOME: string = "Home";
public static END: string = "Page Down"; public static END: string = "Page Down";
public static PAGE_UP: string = "Page Up"; public static PAGE_UP: string = "Page Up";
public static PAGE_DOWN: string = "Page Down"; public static PAGE_DOWN: string = "Page Down";
public static LEFT: string = "Left"; public static LEFT: string = "Left";
public static RIGHT: string = "Right"; public static RIGHT: string = "Right";
public static UP: string = "Up"; public static UP: string = "Up";
public static DOWN: string = "Down"; public static DOWN: string = "Down";
public static PAUSE_BREAK: string = "Pause Break"; public static PAUSE_BREAK: string = "Pause Break";
public static NUM_LOCK: string = "Num Lock"; public static NUM_LOCK: string = "Num Lock";
public static SCROLL_LOCK: string = "Scroll Lock"; public static SCROLL_LOCK: string = "Scroll Lock";
public static WINDOWS: string = "Windows"; public static WINDOWS: string = "Windows";
//存放按下注册数据的字典
private static keyDownDict: Object;
//存放按起注册数据的字典
private static keyUpDict: Object;
public static init(): void { public static init(): void {
this.keyDownDict = {}; this.keyDownDict = {};
@@ -100,32 +90,6 @@ class KeyboardUtils {
document.addEventListener("keyup", this.onKeyUpHander); document.addEventListener("keyup", this.onKeyUpHander);
} }
private static onKeyDonwHander(event: KeyboardEvent): void {
if (!this.keyDownDict) return;
var key: string = this.keyCodeToString(event.keyCode);
var o: Object = this.keyDownDict[key];
if (o) {
var fun: Function = o["fun"];
var thisObj: any = o["thisObj"];
var args: any = o["args"];
fun.apply(thisObj, args);
}
}
private static onKeyUpHander(event: KeyboardEvent): void {
if (!this.keyUpDict) return;
var key: string = this.keyCodeToString(event.keyCode);
var o: Object = this.keyUpDict[key];
if (o) {
var fun: Function = o["fun"];
var thisObj: any = o["thisObj"];
var args: any = o["args"];
fun.apply(thisObj, args);
}
}
/** /**
* *
* @param key * @param key
@@ -147,6 +111,39 @@ class KeyboardUtils {
delete keyDict[key]; delete keyDict[key];
} }
/**
*
*/
public static destroy(): void {
this.keyDownDict = null;
this.keyUpDict = null;
document.removeEventListener("keydown", this.onKeyDonwHander);
document.removeEventListener("keyup", this.onKeyUpHander);
}
private static onKeyDonwHander(event: KeyboardEvent): void {
if (!this.keyDownDict) return;
var key: string = this.keyCodeToString(event.keyCode);
var o: Object = this.keyDownDict[key];
if (o) {
var fun: Function = o["fun"];
var thisObj: any = o["thisObj"];
var args: any = o["args"];
fun.apply(thisObj, args);
}
}
private static onKeyUpHander(event: KeyboardEvent): void {
if (!this.keyUpDict) return;
var key: string = this.keyCodeToString(event.keyCode);
var o: Object = this.keyUpDict[key];
if (o) {
var fun: Function = o["fun"];
var thisObj: any = o["thisObj"];
var args: any = o["args"];
fun.apply(thisObj, args);
}
}
/** /**
* keyCode或charCode获取相应的字符串代号 * keyCode或charCode获取相应的字符串代号
@@ -225,15 +222,4 @@ class KeyboardUtils {
return String.fromCharCode(keyCode); return String.fromCharCode(keyCode);
} }
} }
/**
*
*/
public static destroy(): void {
this.keyDownDict = null;
this.keyUpDict = null;
document.removeEventListener("keydown", this.onKeyDonwHander);
document.removeEventListener("keyup", this.onKeyUpHander);
}
} }
+1
View File
@@ -13,6 +13,7 @@ const nextTick = fn => {
class LockUtils { class LockUtils {
private _keyX: string; private _keyX: string;
private _keyY: string; private _keyY: string;
constructor(key) { constructor(key) {
this._keyX = `mutex_key_${key}_X`; this._keyX = `mutex_key_${key}_X`;
this._keyY = `mutex_key_${key}_Y`; this._keyY = `mutex_key_${key}_Y`;
+4 -5
View File
@@ -62,10 +62,6 @@ class RandomUtils {
return array; return array;
} }
private static _randomCompare(a: Object, b: Object): number {
return (this.random() > .5) ? 1 : -1;
}
/** /**
* *
* @param sequence vectorlength属性 * @param sequence vectorlength属性
@@ -83,7 +79,6 @@ class RandomUtils {
return sequence[index]; return sequence[index];
} }
/** /**
* æ ? * æ ?
* <pre> * <pre>
@@ -131,4 +126,8 @@ class RandomUtils {
public static boolean(chance: number = .5): boolean { public static boolean(chance: number = .5): boolean {
return (this.random() < chance) ? true : false; return (this.random() < chance) ? true : false;
} }
private static _randomCompare(a: Object, b: Object): number {
return (this.random() > .5) ? 1 : -1;
}
} }
+13 -13
View File
@@ -11,6 +11,19 @@ module es {
private _triPrev: number[] = new Array<number>(12); private _triPrev: number[] = new Array<number>(12);
private _triNext: number[] = new Array<number>(12); private _triNext: number[] = new Array<number>(12);
public static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean {
if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0)
return false;
if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0)
return false;
if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0)
return false;
return true;
}
/** /**
* CCWarePointsCCW参数传递为false * CCWarePointsCCW参数传递为false
* @param points * @param points
@@ -96,18 +109,5 @@ module es {
this._triPrev[0] = count - 1; this._triPrev[0] = count - 1;
this._triNext[count - 1] = 0; this._triNext[count - 1] = 0;
} }
public static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean{
if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0)
return false;
if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0)
return false;
if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0)
return false;
return true;
}
} }
} }
+2 -2
View File
@@ -11,8 +11,8 @@
"es5", "es5",
"dom", "dom",
"es2015.promise", "es2015.promise",
"es6", "es6"
] , ]
}, },
"include": [ "include": [
"src", "src",