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 {
class AStarPathfinder {
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 getKey;
static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[];
}
class AStarNode<T> extends PriorityQueueNode {
data: T;
@@ -68,9 +68,9 @@ declare module es {
private _nodes;
private _numNodesEverEnqueued;
constructor(maxNodes: number);
clear(): void;
readonly count: number;
readonly maxSize: number;
clear(): void;
contains(node: T): boolean;
enqueue(node: T, priority: number): void;
dequeue(): T;
@@ -103,28 +103,21 @@ declare module es {
}
declare module es {
class Vector2 {
x: number;
y: number;
private static readonly unitYVector;
private static readonly unitXVector;
private static readonly unitVector2;
private static readonly zeroVector2;
x: number;
y: number;
constructor(x?: number, y?: number);
static readonly zero: Vector2;
static readonly one: Vector2;
static readonly unitX: 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 divide(value1: Vector2, value2: Vector2): Vector2;
static multiply(value1: Vector2, value2: Vector2): Vector2;
static subtract(value1: Vector2, value2: Vector2): Vector2;
normalize(): void;
length(): number;
round(): Vector2;
static normalize(value: Vector2): Vector2;
static dot(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 distance(value1: Vector2, value2: Vector2): number;
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;
}
}
@@ -185,9 +185,9 @@ declare module es {
}
class WeightedPathfinder {
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 getKey;
static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[];
}
}
declare module es {
@@ -228,12 +228,12 @@ declare module es {
declare module es {
abstract class Component {
entity: Entity;
readonly transform: Transform;
enabled: boolean;
updateOrder: number;
updateInterval: number;
readonly transform: Transform;
private _enabled;
enabled: boolean;
private _updateOrder;
updateOrder: number;
initialize(): void;
onAddedToEntity(): void;
onRemovedFromEntity(): void;
@@ -252,27 +252,27 @@ declare module es {
static emitter: Emitter<CoreEvents>;
static graphicsDevice: GraphicsDevice;
static content: ContentManager;
static readonly Instance: Core;
static _instance: Core;
_scene: Scene;
_nextScene: Scene;
_sceneTransition: SceneTransition;
_globalManagers: GlobalManager[];
static scene: Scene;
constructor();
private onAddToStage;
onOrientationChanged(): void;
protected onGraphicsDeviceReset(): void;
protected initialize(): void;
protected update(): Promise<void>;
draw(): Promise<void>;
startDebugUpdate(): void;
endDebugUpdate(): void;
onSceneChanged(): void;
static readonly Instance: Core;
_scene: Scene;
static scene: Scene;
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
static registerGlobalManager(manager: es.GlobalManager): void;
static unregisterGlobalManager(manager: es.GlobalManager): void;
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 {
@@ -290,16 +290,17 @@ declare module es {
readonly id: number;
readonly transform: Transform;
readonly components: ComponentList;
tag: number;
updateInterval: number;
enabled: boolean;
updateOrder: number;
componentBits: BitSet;
constructor(name: string);
_isDestroyed: boolean;
readonly isDestroyed: boolean;
componentBits: BitSet;
private _tag;
tag: number;
private _enabled;
enabled: boolean;
private _updateOrder;
updateOrder: number;
parent: Transform;
readonly childCount: number;
position: Vector2;
@@ -313,7 +314,6 @@ declare module es {
readonly worldInverseTransform: Matrix2D;
readonly localToWorldTransform: Matrix2D;
readonly worldToLocalTransform: Matrix2D;
constructor(name: string);
onTransformChanged(comp: transform.Component): void;
setTag(tag: number): Entity;
setEnabled(isEnabled: boolean): this;
@@ -322,7 +322,6 @@ declare module es {
detachFromScene(): void;
attachToScene(newScene: Scene): void;
clone(position?: Vector2): Entity;
protected copyFrom(entity: Entity): void;
onAddedToScene(): void;
onRemovedFromScene(): void;
update(): void;
@@ -336,6 +335,7 @@ declare module es {
removeAllComponents(): void;
compareTo(other: Entity): number;
toString(): string;
protected copyFrom(entity: Entity): void;
}
}
declare module es {
@@ -349,8 +349,8 @@ declare module es {
_renderers: Renderer[];
readonly _postProcessors: PostProcessor[];
_didSceneBegin: any;
static createWithDefaultRenderer(): Scene;
constructor();
static createWithDefaultRenderer(): Scene;
initialize(): void;
onStart(): Promise<void>;
unload(): void;
@@ -397,20 +397,6 @@ declare module es {
}
class Transform extends HashObject {
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;
_localDirty: boolean;
_localPositionDirty: boolean;
@@ -421,19 +407,33 @@ declare module es {
_worldInverseDirty: boolean;
_localTransform: Matrix2D;
_worldTransform: Matrix2D;
_worldToLocalTransform: Matrix2D;
_worldInverseTransform: Matrix2D;
_rotationMatrix: Matrix2D;
_translationMatrix: Matrix2D;
_scaleMatrix: Matrix2D;
_position: Vector2;
_scale: Vector2;
_rotation: number;
_localPosition: Vector2;
_localScale: Vector2;
_localRotation: number;
_children: Transform[];
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;
setParent(parent: Transform): Transform;
setPosition(x: number, y: number): Transform;
@@ -465,23 +465,7 @@ declare module es {
bottom: number;
}
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;
_transformMatrix: Matrix2D;
_inverseTransformMatrix: Matrix2D;
_origin: Vector2;
_areMatrixedDirty: boolean;
_areBoundsDirty: boolean;
_isProjectionMatrixDirty: boolean;
@@ -496,8 +480,23 @@ declare module es {
_cameraStyle: CameraStyle;
_worldSpaceDeadZone: Rectangle;
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;
protected updateMatrixes(): void;
setInset(left: number, right: number, top: number, bottom: number): Camera;
setPosition(position: Vector2): this;
setRotation(rotation: number): Camera;
@@ -516,6 +515,7 @@ declare module es {
updateFollow(): void;
follow(targetEntity: Entity, cameraStyle?: CameraStyle): void;
setCenteredDeadzone(width: number, height: number): void;
protected updateMatrixes(): void;
}
}
declare module es {
@@ -540,28 +540,28 @@ declare module es {
declare module es {
abstract class RenderableComponent extends Component implements IRenderable {
displayObject: egret.DisplayObject;
color: number;
protected _areBoundsDirty: boolean;
readonly width: number;
readonly height: number;
readonly bounds: Rectangle;
renderLayer: number;
color: number;
localOffset: Vector2;
isVisible: boolean;
protected _localOffset: Vector2;
localOffset: Vector2;
protected _renderLayer: number;
renderLayer: number;
protected _bounds: Rectangle;
readonly bounds: Rectangle;
private _isVisible;
protected _areBoundsDirty: boolean;
isVisible: boolean;
onEntityTransformChanged(comp: transform.Component): void;
abstract render(camera: Camera): any;
protected onBecameVisible(): void;
protected onBecameInvisible(): void;
isVisibleFromCamera(camera: Camera): boolean;
setRenderLayer(renderLayer: number): RenderableComponent;
setColor(color: number): RenderableComponent;
setLocalOffset(offset: Vector2): RenderableComponent;
sync(camera: Camera): void;
toString(): string;
protected onBecameVisible(): void;
protected onBecameInvisible(): void;
}
}
declare module es {
@@ -575,13 +575,13 @@ declare module es {
}
declare module es {
class SpriteRenderer extends RenderableComponent {
readonly bounds: Rectangle;
origin: Vector2;
originNormalized: Vector2;
sprite: Sprite;
protected _origin: Vector2;
protected _sprite: Sprite;
constructor(sprite?: Sprite | egret.Texture);
readonly bounds: Rectangle;
originNormalized: Vector2;
protected _origin: Vector2;
origin: Vector2;
protected _sprite: Sprite;
sprite: Sprite;
setSprite(sprite: Sprite): SpriteRenderer;
setOrigin(origin: Vector2): SpriteRenderer;
setOriginNormalized(value: Vector2): SpriteRenderer;
@@ -593,9 +593,9 @@ declare module es {
protected sourceRect: Rectangle;
protected leftTexture: egret.Bitmap;
protected rightTexture: egret.Bitmap;
constructor(sprite: Sprite);
scrollX: number;
scrollY: number;
constructor(sprite: Sprite);
render(camera: es.Camera): void;
}
}
@@ -647,12 +647,12 @@ declare module es {
currentAnimation: SpriteAnimation;
currentAnimationName: string;
currentFrame: number;
readonly isRunning: boolean;
readonly animations: Map<string, SpriteAnimation>;
private _animations;
_elapsedTime: number;
_loopMode: LoopMode;
constructor(sprite?: Sprite);
readonly isRunning: boolean;
private _animations;
readonly animations: Map<string, SpriteAnimation>;
update(): void;
addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator;
play(name: string, loopMode?: LoopMode): void;
@@ -689,22 +689,22 @@ declare module es {
declare module es {
abstract class Collider extends Component {
shape: Shape;
localOffset: Vector2;
readonly absolutePosition: Vector2;
readonly rotation: number;
isTrigger: boolean;
physicsLayer: number;
collidesWithLayers: number;
shouldColliderScaleAndRotateWithTransform: boolean;
readonly bounds: Rectangle;
registeredPhysicsBounds: Rectangle;
protected _colliderRequiresAutoSizing: any;
protected _localOffset: Vector2;
_localOffsetLength: number;
protected _isParentEntityAddedToScene: any;
protected _isColliderRegistered: any;
_isPositionDirty: 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;
setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider;
onAddedToEntity(): void;
@@ -721,9 +721,9 @@ declare module es {
}
declare module es {
class BoxCollider extends Collider {
constructor();
width: number;
height: number;
constructor();
setSize(width: number, height: number): this;
setWidth(width: number): BoxCollider;
setHeight(height: number): void;
@@ -732,8 +732,8 @@ declare module es {
}
declare module es {
class CircleCollider extends Collider {
radius: number;
constructor(radius?: number);
radius: number;
setRadius(radius: number): CircleCollider;
toString(): string;
}
@@ -745,12 +745,12 @@ declare module es {
}
declare module es {
class EntitySystem {
private _scene;
private _entities;
constructor(matcher?: Matcher);
private _scene;
scene: Scene;
private _matcher;
readonly matcher: Matcher;
scene: Scene;
constructor(matcher?: Matcher);
initialize(): void;
onChanged(entity: Entity): void;
add(entity: Entity): void;
@@ -783,8 +783,8 @@ declare module es {
declare module es {
abstract class ProcessingSystem extends EntitySystem {
onChanged(entity: Entity): void;
protected process(entities: Entity[]): void;
abstract processSystem(): any;
protected process(entities: Entity[]): void;
}
}
declare module es {
@@ -796,12 +796,12 @@ declare module es {
andNot(bs: BitSet): void;
cardinality(): number;
clear(pos?: number): void;
private ensure;
get(pos: number): boolean;
intersects(set: BitSet): boolean;
isEmpty(): boolean;
nextSetBit(from: number): number;
set(pos: number, value?: boolean): void;
private ensure;
}
}
declare module es {
@@ -879,13 +879,13 @@ declare module es {
onComponentRemoved(entity: Entity): void;
onEntityAdded(entity: Entity): void;
onEntityRemoved(entity: Entity): void;
protected notifyEntityChanged(entity: Entity): void;
protected removeFromProcessors(entity: Entity): void;
begin(): void;
update(): void;
lateUpdate(): void;
end(): void;
getProcessor<T extends EntitySystem>(): T;
protected notifyEntityChanged(entity: Entity): void;
protected removeFromProcessors(entity: Entity): void;
}
}
declare module es {
@@ -939,13 +939,13 @@ declare module es {
}
}
declare class StringUtils {
private static specialSigns;
static matchChineseWord(str: string): string[];
static lTrim(target: string): string;
static rTrim(target: string): string;
static trim(target: string): string;
static isWhiteSpace(str: string): boolean;
static replaceMatch(mainStr: string, targetStr: string, replaceStr: string, caseMark?: boolean): string;
private static specialSigns;
static htmlSpecialChars(str: string, reversion?: boolean): string;
static zfill(str: string, width?: number): string;
static reverse(str: string): string;
@@ -969,8 +969,8 @@ declare module es {
static deltaTime: number;
static timeScale: number;
static frameCount: number;
private static _lastTime;
static _timeSinceSceneLoad: any;
private static _lastTime;
static update(currentTime: number): void;
static sceneChanged(): void;
static checkEvery(interval: number): boolean;
@@ -998,10 +998,10 @@ declare module es {
}
declare module es {
class GraphicsDevice {
private _viewport;
readonly viewport: Viewport;
graphicsCapabilities: GraphicsCapabilities;
constructor();
private _viewport;
readonly viewport: Viewport;
private setup;
}
}
@@ -1009,15 +1009,15 @@ declare module es {
class Viewport {
private _x;
private _y;
private _width;
private _height;
private _minDepth;
private _maxDepth;
height: number;
constructor(x: number, y: number, width: number, height: number);
private _width;
width: number;
private _height;
height: number;
readonly aspectRatio: number;
bounds: Rectangle;
constructor(x: number, y: number, width: number, height: number);
}
}
declare module es {
@@ -1035,17 +1035,17 @@ declare module es {
}
declare module es {
class PostProcessor {
static default_vert: string;
enabled: boolean;
effect: egret.Filter;
scene: Scene;
shape: egret.Shape;
static default_vert: string;
constructor(effect?: egret.Filter);
onAddedToScene(scene: Scene): void;
process(): void;
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
protected drawFullscreenQuad(): void;
unload(): void;
protected drawFullscreenQuad(): void;
}
}
declare module es {
@@ -1060,11 +1060,11 @@ declare module es {
protected constructor(renderOrder: number, camera?: Camera);
onAddedToScene(scene: Scene): void;
unload(): void;
protected beginRender(cam: Camera): void;
abstract render(scene: Scene): any;
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void;
compareTo(other: Renderer): number;
protected beginRender(cam: Camera): void;
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
}
}
declare module es {
@@ -1081,33 +1081,33 @@ declare module es {
declare module es {
class PolyLight extends RenderableComponent {
power: number;
protected _radius: number;
private _lightEffect;
private _indices;
radius: number;
constructor(radius: number, color: number, power: number);
private computeTriangleIndices;
protected _radius: number;
radius: number;
setRadius(radius: number): void;
render(camera: Camera): void;
reset(): void;
private computeTriangleIndices;
}
}
declare module es {
abstract class SceneTransition {
private _hasPreviousSceneRender;
loadsNewScene: boolean;
isNewSceneLoaded: boolean;
protected sceneLoadAction: Function;
onScreenObscured: Function;
onTransitionCompleted: Function;
readonly hasPreviousSceneRender: boolean;
protected sceneLoadAction: Function;
constructor(sceneLoadAction: Function);
private _hasPreviousSceneRender;
readonly hasPreviousSceneRender: boolean;
preRender(): void;
render(): void;
onBeginTransition(): Promise<void>;
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<boolean>;
protected transitionComplete(): void;
protected loadNextScene(): Promise<void>;
tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise<boolean>;
}
}
declare module es {
@@ -1125,13 +1125,13 @@ declare module es {
}
declare module es {
class WindTransition extends SceneTransition {
duration: number;
easeType: (t: number) => number;
private _mask;
private _windEffect;
duration: number;
constructor(sceneLoadAction: Function);
windSegments: number;
size: number;
easeType: (t: number) => number;
constructor(sceneLoadAction: Function);
onBeginTransition(): Promise<void>;
}
}
@@ -1202,14 +1202,14 @@ declare module es {
readonly center: Vector2;
location: Vector2;
size: Vector2;
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
static rectEncompassingPoints(points: Vector2[]): Rectangle;
intersects(value: egret.Rectangle): boolean;
containsRect(value: Rectangle): boolean;
getHalfSize(): Vector2;
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2;
getClosestPointOnBoundsToOrigin(): Vector2;
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
static rectEncompassingPoints(points: Vector2[]): Rectangle;
}
}
declare module es {
@@ -1259,9 +1259,9 @@ declare module es {
}
declare module es {
class Physics {
private static _spatialHash;
static spatialHashCellSize: number;
static readonly allLayers: number;
private static _spatialHash;
static reset(): void;
static clear(): void;
static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number;
@@ -1288,21 +1288,21 @@ declare module es {
declare module es {
class Polygon extends Shape {
points: Vector2[];
readonly edgeNormals: Vector2[];
_areEdgeNormalsDirty: boolean;
_edgeNormals: Vector2[];
_originalPoints: Vector2[];
_polygonCenter: Vector2;
isBox: boolean;
isUnrotated: boolean;
constructor(points: Vector2[], isBox?: boolean);
setPoints(points: Vector2[]): void;
recalculateCenterAndEdgeNormals(): void;
buildEdgeNormals(): void;
_edgeNormals: Vector2[];
readonly edgeNormals: Vector2[];
static buildSymmetricalPolygon(vertCount: number, radius: number): any[];
static recenterPolygonVerts(points: Vector2[]): void;
static findPolygonCenter(points: 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;
overlaps(other: Shape): any;
collidesWithShape(other: Shape, result: CollisionResult): boolean;
@@ -1370,24 +1370,24 @@ declare module es {
_cellDict: NumberDictionary;
_tempHashSet: Collider[];
constructor(cellSize?: number);
private cellCoords;
private cellAtPosition;
register(collider: Collider): void;
remove(collider: Collider): void;
removeWithBruteForce(obj: Collider): void;
clear(): void;
debugDraw(secondsToDisplay: number, textScale?: number): void;
private debugDrawCellDetails;
aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[];
overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number;
private cellCoords;
private cellAtPosition;
private debugDrawCellDetails;
}
class NumberDictionary {
_store: Map<string, Collider[]>;
private getKey;
add(x: number, y: number, list: Collider[]): void;
remove(obj: Collider): void;
tryGetValue(x: number, y: number): Collider[];
clear(): void;
private getKey;
}
class RaycastResultParser {
}
@@ -1412,8 +1412,8 @@ declare class Base64Utils {
private static _keyStr;
private static _keyAll;
static encode: (input: any) => string;
private static _utf8_encode;
static decode(input: any, isNotStr?: boolean): string;
private static _utf8_encode;
private static _utf8_decode;
private static getConfKey;
}
@@ -1450,9 +1450,9 @@ declare module es {
}
declare module es {
class GlobalManager {
_enabled: boolean;
enabled: boolean;
setEnabled(isEnabled: boolean): void;
_enabled: boolean;
onEnabled(): void;
onDisabled(): void;
update(): void;
@@ -1470,31 +1470,29 @@ declare module es {
class Input {
private static _init;
private static _previousTouchState;
private static _gameTouchs;
private static _resolutionOffset;
private static _resolutionScale;
private static _touchIndex;
private static _gameTouchs;
static readonly gameTouchs: TouchState[];
private static _resolutionScale;
static readonly resolutionScale: Vector2;
private static _totalTouchCount;
static readonly totalTouchCount: number;
static readonly touchPosition: Vector2;
static maxSupportedTouch: number;
static readonly resolutionScale: Vector2;
static readonly totalTouchCount: number;
static readonly gameTouchs: TouchState[];
static readonly touchPositionDelta: Vector2;
static initialize(): void;
static scaledPosition(position: Vector2): Vector2;
private static initTouchCache;
private static touchBegin;
private static touchMove;
private static touchEnd;
private static setpreviousTouchState;
static scaledPosition(position: Vector2): Vector2;
}
}
declare class KeyboardUtils {
static TYPE_KEY_DOWN: number;
static TYPE_KEY_UP: number;
private static keyDownDict;
private static keyUpDict;
static A: string;
static B: string;
static C: string;
@@ -1566,13 +1564,15 @@ declare class KeyboardUtils {
static NUM_LOCK: string;
static SCROLL_LOCK: string;
static WINDOWS: string;
private static keyDownDict;
private static keyUpDict;
static init(): void;
private static onKeyDonwHander;
private static onKeyUpHander;
static registerKey(key: string, fun: Function, thisObj: any, type?: number, ...args: any[]): void;
static unregisterKey(key: string, type?: number): void;
private static keyCodeToString;
static destroy(): void;
private static onKeyDonwHander;
private static onKeyUpHander;
private static keyCodeToString;
}
declare module es {
class ListPool {
@@ -1609,11 +1609,11 @@ declare class RandomUtils {
static randint(a: number, b: number): number;
static randnum(a: number, b: number): number;
static shuffle(array: any[]): any[];
private static _randomCompare;
static choice(sequence: any): any;
static sample(sequence: any[], num: number): any[];
static random(): number;
static boolean(chance?: number): boolean;
private static _randomCompare;
}
declare module es {
class RectangleExt {
@@ -1625,9 +1625,9 @@ declare module es {
triangleIndices: number[];
private _triPrev;
private _triNext;
static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean;
triangulate(points: Vector2[], arePointsCCW?: boolean): void;
private initialize;
static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean;
}
}
declare module es {
@@ -1689,12 +1689,12 @@ declare namespace stopwatch {
getCompletedAndPendingSlices(): Slice[];
getPendingSlice(): Slice;
getTime(): number;
private calculatePendingSlice;
private caculateStopwatchTime;
private getSystemTimeOfCurrentStopwatchTime;
reset(): void;
start(forceReset?: boolean): void;
stop(recordPendingSlice?: boolean): number;
private calculatePendingSlice;
private caculateStopwatchTime;
private getSystemTimeOfCurrentStopwatchTime;
private recordPendingSlice;
}
type GetTimeFunc = () => number;
@@ -1721,14 +1721,14 @@ declare module es {
static readonly barPadding: number;
static readonly autoAdjustDelay: number;
private static _instance;
static readonly Instance: TimeRuler;
targetSampleFrames: number;
width: number;
enabled: true;
showLog: boolean;
private _frameKey;
private _logKey;
private _logs;
private sampleFrames;
targetSampleFrames: number;
width: number;
enabled: true;
private _position;
private _prevLog;
private _curLog;
@@ -1737,16 +1737,16 @@ declare module es {
private stopwacth;
private _markerNameToIdMap;
private _updateCount;
showLog: boolean;
private _frameAdjust;
constructor();
private onGraphicsDeviceReset;
static readonly Instance: TimeRuler;
startFrame(): void;
beginMark(markerName: string, color: number, barIndex?: number): void;
endMark(markerName: string, barIndex?: number): void;
getAverageTime(barIndex: number, markerName: string): number;
resetLog(): void;
render(position?: Vector2, width?: number): void;
private onGraphicsDeviceReset;
}
class FrameLog {
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;
}
/**
* 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) {
let iterator = map.keys();
let r: IteratorResult<T>;
@@ -66,27 +87,6 @@ module es {
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
*/
getNeighbors(node: T): Array<T>;
/**
* from到to的成本
* @param from
* @param to
*/
cost(from: T, to: T): number;
/**
* node到to的启发式WeightedGridGraph了解常用的Manhatten方法
* @param node
@@ -19,15 +19,6 @@ module es {
this._numNodesEverEnqueued = 0;
}
/**
*
* O(n)
*/
public clear() {
this._nodes.splice(1, this._numNodes);
this._numNodes = 0;
}
/**
*
* O(1)
@@ -44,6 +35,15 @@ module es {
return this._nodes.length - 1;
}
/**
*
* O(n)
*/
public clear() {
this._nodes.splice(1, this._numNodes);
this._numNodes = 0;
}
/**
* (O(1))
* O (1)
@@ -43,6 +43,21 @@ module es {
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) {
let iterator = map.keys();
let r: IteratorResult<T>;
@@ -66,20 +81,5 @@ module es {
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 updateInterval: number = 1;
/**
* 访 this.entity.transform
@@ -20,6 +24,8 @@ module es {
return this.entity.transform;
}
private _enabled: boolean = true;
/**
* onEnabled/onDisable
*/
@@ -35,6 +41,8 @@ module es {
this.setEnabled(value);
}
private _updateOrder = 0;
/** 更新此实体上组件的顺序 */
public get updateOrder() {
return this._updateOrder;
@@ -45,14 +53,6 @@ module es {
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 {
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的快速访问
*/
@@ -42,6 +82,8 @@ module es {
this.entity.transform.rotation = value;
}
public _zoom;
/**
* -11minimumZoom转换为maximumZoom
* /使-11
@@ -65,6 +107,8 @@ module es {
this.setZoom(value);
}
public _minimumZoom = 0.3;
/**
* 0-number.max0.3
*/
@@ -80,6 +124,8 @@ module es {
this.setMinimumZoom(value);
}
public _maximumZoom = 3;
/**
* 0-number.max3
*/
@@ -95,6 +141,8 @@ module es {
this.setMaximumZoom(value);
}
public _bounds: Rectangle = new Rectangle();
/**
* -
*/
@@ -135,6 +183,8 @@ module es {
return this._bounds;
}
public _transformMatrix: Matrix2D = new Matrix2D().identity();
/**
*
*/
@@ -144,6 +194,8 @@ module es {
return this._transformMatrix;
}
public _inverseTransformMatrix: Matrix2D = new Matrix2D().identity();
/**
*
*/
@@ -153,6 +205,8 @@ module es {
return this._inverseTransformMatrix;
}
public _origin: Vector2 = Vector2.zero;
public get 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
@@ -226,33 +230,6 @@ module es {
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
@@ -476,5 +453,32 @@ module es {
public setCenteredDeadzone(width: number, height: number) {
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" />
module es {
export class BoxCollider extends Collider {
/**
* RenderableComponent在实体上
*/
constructor() {
super();
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
this.shape = new Box(1, 1);
this._colliderRequiresAutoSizing = true;
}
public get width() {
return (this.shape as Box).width;
}
@@ -17,17 +28,6 @@ module es {
this.setHeight(value);
}
/**
* RenderableComponent在实体上
*/
constructor(){
super();
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
this.shape = new Box(1, 1);
this._colliderRequiresAutoSizing = true;
}
/**
* BoxCollider的大小
* @param width
@@ -1,13 +1,5 @@
module es {
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);
}
public get radius(): number {
return (this.shape as Circle).radius;
}
public set radius(value: number) {
this.setRadius(value);
}
/**
*
* @param radius
@@ -4,23 +4,40 @@ module es {
*
*/
public shape: Shape;
/**
* localOffset添加到实体
* /
*
*/
public get localOffset(): Vector2 {
return this._localOffset;
}
public isTrigger: boolean;
/**
* localOffset添加到实体
* /
* @param value
* physicsLayer可以用作过滤器Flags类有帮助位掩码的方法
*/
public set localOffset(value: Vector2) {
this.setLocalOffset(value);
}
public physicsLayer = 1 << 0;
/**
* 使
*
*/
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;
}
/**
*
*/
public isTrigger: boolean;
/**
* physicsLayer可以用作过滤器Flags类有帮助位掩码的方法
*/
public physicsLayer = 1 << 0;
/**
* 使
*
*/
public collidesWithLayers = Physics.allLayers;
/**
* true
*/
public shouldColliderScaleAndRotateWithTransform = true;
public get bounds(): Rectangle {
if (this._isPositionDirty || this._isRotationDirty) {
this.shape.recalculateBounds(this);
@@ -67,26 +65,24 @@ module es {
return this.shape.bounds;
}
/**
*
* 使
*/
public registeredPhysicsBounds: Rectangle = new Rectangle();
protected _colliderRequiresAutoSizing;
protected _localOffset: Vector2 = Vector2.zero;
public _localOffsetLength: number;
/**
*
* localOffset添加到实体
* /
*/
protected _isParentEntityAddedToScene;
/**
*
*/
protected _isColliderRegistered;
public get localOffset(): Vector2 {
return this._localOffset;
}
public _isPositionDirty: boolean = true;
public _isRotationDirty: boolean = true;
/**
* localOffset添加到实体
* /
* @param value
*/
public set localOffset(value: Vector2) {
this.setLocalOffset(value);
}
/**
* localOffset添加到实体
@@ -8,6 +8,12 @@ module es {
* egret显示对象
*/
public displayObject: egret.DisplayObject = new egret.DisplayObject();
/**
*
*/
public color: number = 0x000000;
protected _areBoundsDirty = true;
/**
* renderableComponent的宽度
* bounds属性则需要实现这个
@@ -24,34 +30,7 @@ module es {
return this.bounds.height;
}
/**
* 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;
protected _localOffset: Vector2 = Vector2.zero;
/**
*
@@ -68,6 +47,36 @@ module es {
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方法
*/
@@ -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) {
this._areBoundsDirty = true;
}
@@ -106,22 +109,6 @@ module es {
*/
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
* isVisible标志的状态开关
@@ -185,5 +172,21 @@ module es {
public toString() {
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 _elapsedTime: number = 0;
public _loopMode: LoopMode;
constructor(sprite?: Sprite) {
super(sprite);
}
/**
*
@@ -53,19 +59,13 @@ module es {
return this.animationState == State.running;
}
private _animations: Map<string, SpriteAnimation> = new Map<string, SpriteAnimation>();
/** 提供对可用动画列表的访问 */
public get 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() {
if (this.animationState != State.running || !this.currentAnimation) return;
+27 -26
View File
@@ -2,6 +2,14 @@ module es {
import Bitmap = egret.Bitmap;
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() {
if (this._areBoundsDirty) {
if (this._sprite) {
@@ -15,21 +23,6 @@ module es {
return this._bounds;
}
/**
*
*/
public get origin(): Vector2 {
return this._origin;
}
/**
*
* @param value
*/
public set origin(value: Vector2) {
this.setOrigin(value);
}
/**
*
* x/y 0-1
@@ -49,6 +42,25 @@ module es {
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
@@ -66,17 +78,6 @@ module es {
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
* @param sprite
@@ -8,19 +8,6 @@ module es {
protected leftTexture: 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) {
super(sprite);
@@ -33,6 +20,22 @@ module es {
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) {
if (!this.sprite)
return;
+109 -109
View File
@@ -15,6 +15,26 @@ module es {
*
*/
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;
}
/**
* 访
*/
public static _instance: Core;
public _scene: Scene;
public _nextScene: Scene;
public _sceneTransition: SceneTransition;
/**
* 访
*/
public _globalManagers: GlobalManager[] = [];
/**
*
@@ -65,31 +75,98 @@ module es {
}
}
constructor() {
super();
Core._instance = this;
Core.emitter = new Emitter<CoreEvents>();
Core.content = new ContentManager();
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
/**
* SceneTransition
* @param sceneTransition
*/
public static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T {
if (this._instance._sceneTransition) {
console.warn("在前一个场景完成之前,不能开始一个新的场景转换。");
return;
}
private onAddToStage(){
Core.graphicsDevice = new GraphicsDevice();
this._instance._sceneTransition = sceneTransition;
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() {
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();
}
public async draw() {
if (this._sceneTransition){
this._sceneTransition.preRender();
private onAddToStage() {
Core.graphicsDevice = new GraphicsDevice();
// 如果我们有场景转换的特殊处理。我们要么渲染场景过渡,要么渲染场景
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.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);
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();
}
/**
* 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;
Input.initialize();
this.initialize();
}
}
}
+54 -53
View File
@@ -22,6 +22,31 @@ module es {
*
*/
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);
}
/**
* entity update方法的频率12
*/
public updateInterval: number = 1;
private _enabled: boolean = true;
/**
* /
@@ -58,6 +80,8 @@ module es {
this.setEnabled(value);
}
private _updateOrder: number = 0;
/**
* updateOrder还用于对scene.entities上的标签列表进行排序
*/
@@ -73,20 +97,6 @@ module es {
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 {
return this.transform.parent;
}
@@ -175,15 +185,6 @@ module es {
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) {
// 通知我们的子项改变了位置
this.components.onEntityTransformChanged(comp);
@@ -293,32 +294,6 @@ module es {
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 {
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 _didSceneBegin;
/**
* DefaultRenderer附加并准备使用
*/
public static createWithDefaultRenderer(){
let scene = new Scene();
scene.addRenderer(new DefaultRenderer());
return scene;
}
constructor() {
super();
this.entities = new EntityList(this);
@@ -51,31 +42,45 @@ module es {
this.initialize();
}
/**
* DefaultRenderer附加并准备使用
*/
public static createWithDefaultRenderer() {
let scene = new Scene();
scene.addRenderer(new DefaultRenderer());
return scene;
}
/**
* begin之前
*/
public initialize(){}
public initialize() {
}
/**
* SceneManager将此场景设置为活动场景时
*/
public async onStart() {}
public async onStart() {
}
/**
* SceneManager从活动槽中删除此场景时调用
*/
public unload() { }
public unload() {
}
/**
*
*/
public onActive() {}
public onActive() {
}
/**
*
*/
public onDeactive() {}
public onDeactive() {
}
public async begin() {
if (this._renderers.length == 0) {
+8 -6
View File
@@ -1,13 +1,13 @@
module es {
export class EntitySystem {
private _scene: Scene;
private _entities: Entity[] = [];
private _matcher: Matcher;
public get matcher(){
return this._matcher;
constructor(matcher?: Matcher) {
this._matcher = matcher ? matcher : Matcher.empty();
}
private _scene: Scene;
public get scene() {
return this._scene;
}
@@ -17,8 +17,10 @@ module es {
this._entities = [];
}
constructor(matcher?: Matcher){
this._matcher = matcher ? matcher : Matcher.empty();
private _matcher: Matcher;
public get matcher() {
return this._matcher;
}
public initialize() {
+3 -3
View File
@@ -5,13 +5,13 @@ module es {
}
/** 处理我们的系统 每帧调用 */
public abstract processSystem();
protected process(entities: Entity[]) {
this.begin();
this.processSystem();
this.end();
}
/** 处理我们的系统 每帧调用 */
public abstract processSystem();
}
}
+153 -150
View File
@@ -19,6 +19,78 @@ module es {
export class Transform extends HashObject {
/** 与此转换关联的实体 */
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);
}
/**
*
*/
public get childCount() {
return this._children.length;
public _worldToLocalTransform = Matrix2D.create().identity();
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 _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);
}
/**
* 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);
}
public _scale: Vector2 = Vector2.one;
/**
*
@@ -162,6 +182,44 @@ module es {
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相同
*/
@@ -178,77 +236,22 @@ module es {
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 _children: Transform[];
/**
* transform.rotation相同
*/
public get localRotation(): number {
this.updateTransform();
return this._localRotation;
}
constructor(entity: Entity) {
super();
this.entity = entity;
this.scale = Vector2.one;
this._children = [];
/**
* transform.rotation相同
* @param value
*/
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 {
let offset = pos >> 6;
if (offset >= this._bits.length)
@@ -131,5 +123,13 @@ module es {
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);
}
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() {
}
@@ -67,5 +55,17 @@ module es {
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') {
c[i] = p[i] instanceof Array ? [] : {};
this.clone(p[i], c[i]);
}
else {
} else {
c[i] = p[i];
}
}
+16 -21
View File
@@ -1,4 +1,18 @@
class StringUtils {
/**
*
*/
private static specialSigns: string[] = [
'&', '&amp;',
'<', '&lt;',
'>', '&gt;',
'"', '&quot;',
"'", '&apos;',
'®', '&reg;',
'©', '&copy;',
'™', '&trade;',
];
/**
*
* @param str
@@ -36,7 +50,6 @@ class StringUtils {
return target.slice(0, endIndex + 1);
}
/**
* 2
* @param target
@@ -84,30 +97,13 @@ class StringUtils {
if (isMatch) {
tempStr += replaceStr;
i = i + tempTarget.length - 1;
}
else {
} else {
tempStr += mainStr.charAt(i);
}
}
return tempStr;
}
/**
*
*/
private static specialSigns: string[] = [
'&', '&amp;',
'<', '&lt;',
'>', '&gt;',
'"', '&quot;',
"'", '&apos;',
'®', '&reg;',
'©', '&copy;',
'™', '&trade;',
];
/**
* html实体换掉字符窜中的特殊字符
* @param str
@@ -215,8 +211,7 @@ class StringUtils {
let newStr: string;
if (order) {
newStr = str.substring(0, s) + str.substr(e, length);
}
else {
} else {
s = length - 1 - start - len;
e = s + len;
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.drawToTexture(new egret.Bitmap(texture));
}
else {
} else {
renderTexture = <egret.RenderTexture>texture;
}
//从RenderTexture中读取像素数据,填入canvas
@@ -71,8 +70,7 @@ module es {
}
return surface;
}
else {
} else {
let bitmapData = texture;
let offsetX: number = Math.round(bitmapData.$offsetX);
let offsetY: number = Math.round(bitmapData.$offsetY);
@@ -90,8 +88,7 @@ module es {
let surface = this.convertImageToCanvas(texture, rect);
let result = surface.toDataURL(type, encoderOptions);
return result;
}
catch (e) {
} catch (e) {
egret.$error(1033);
}
return null;
@@ -117,7 +114,7 @@ module es {
success: function (res) {
//todo
}
})
});
return result;
}
@@ -135,8 +132,7 @@ module es {
if (!(<egret.RenderTexture>texture).$renderBuffer) {
renderTexture = new egret.RenderTexture();
renderTexture.drawToTexture(new egret.Bitmap(texture));
}
else {
} else {
renderTexture = <egret.RenderTexture>texture;
}
//从RenderTexture中读取像素数据
@@ -147,8 +143,7 @@ module es {
let surface = this.convertImageToCanvas(texture);
let result = this.sharedContext.getImageData(x, y, width, height).data;
return <number[]><any>result;
}
catch (e) {
} catch (e) {
egret.$error(1039);
}
}
+1 -2
View File
@@ -9,10 +9,9 @@ module es {
public static timeScale = 1;
/** 已传递的帧总数 */
public static frameCount = 0;
private static _lastTime = 0;
/** 自场景加载以来的总时间 */
public static _timeSinceSceneLoad;
private static _lastTime = 0;
public static update(currentTime: number) {
let dt = (currentTime - this._lastTime) / 1000;
+6 -3
View File
@@ -35,7 +35,8 @@ class TimeUtils {
d = d ? d : new Date();
let c: Date = new Date();
c.setTime(d.getTime());
c.setDate(1); c.setMonth(0);//当年第一天
c.setDate(1);
c.setMonth(0);//当年第一天
let year: number = c.getFullYear();
let firstDay: number = c.getDay();
@@ -51,7 +52,8 @@ class TimeUtils {
}
let num: number = this.diffDay(d, c, false);
if (num < 0) {
c.setDate(1); c.setMonth(0);//当年第一天
c.setDate(1);
c.setMonth(0);//当年第一天
c.setDate(c.getDate() - 1);
return this.weekId(c, false);
}
@@ -66,7 +68,8 @@ class TimeUtils {
}
if (first && (!max || endDay < 4)) {
c.setFullYear(c.getFullYear() + 1);
c.setDate(1); c.setMonth(0);//当年第一天
c.setDate(1);
c.setMonth(0);//当年第一天
return this.weekId(c, false);
}
}
+1 -1
View File
@@ -309,7 +309,7 @@ Array.prototype.groupBy = function (keySelector) {
if (typeof (array.reduce) === "function") {
let keys = [];
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) {
return x === key;
});
+6 -5
View File
@@ -1,10 +1,5 @@
module es {
export class GraphicsDevice {
private _viewport: Viewport;
public get viewport(): Viewport{
return this._viewport;
}
public graphicsCapabilities: GraphicsCapabilities;
constructor() {
@@ -13,6 +8,12 @@ module es {
this.graphicsCapabilities.initialize(this);
}
private _viewport: Viewport;
public get viewport(): Viewport {
return this._viewport;
}
private setup() {
this._viewport = new Viewport(0, 0, Core._instance.stage.stageWidth, Core._instance.stage.stageHeight);
}
@@ -1,10 +1,5 @@
module es {
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" +
"attribute vec2 aTextureCoord;\n" +
"attribute vec2 aColor;\n" +
@@ -22,6 +17,10 @@ module es {
"vTextureCoord = aTextureCoord;\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) {
this.enabled = true;
@@ -41,11 +40,7 @@ module es {
this.drawFullscreenQuad();
}
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){}
protected drawFullscreenQuad(){
this.scene.filters = [this.effect];
// this.shape.filters = [this.effect];
public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number) {
}
public unload() {
@@ -56,5 +51,10 @@ module es {
this.scene.removeChild(this.shape);
this.scene = null;
}
protected drawFullscreenQuad() {
this.scene.filters = [this.effect];
// this.shape.filters = [this.effect];
}
}
}
@@ -1,17 +1,9 @@
module es {
export class PolyLight extends RenderableComponent {
public power: number;
protected _radius: number;
private _lightEffect;
private _indices: number[] = [];
public get radius(){
return this._radius;
}
public set radius(value: number){
this.setRadius(value);
}
constructor(radius: number, color: number, power: number) {
super();
@@ -21,14 +13,14 @@ module es {
this.computeTriangleIndices();
}
private computeTriangleIndices(totalTris: number = 20){
this._indices.length = 0;
protected _radius: number;
for (let i = 0; i < totalTris; i += 2){
this._indices.push(0);
this._indices.push(i + 2);
this._indices.push(i + 1);
public get radius() {
return this._radius;
}
public set radius(value: number) {
this.setRadius(value);
}
public setRadius(radius: number) {
@@ -44,5 +36,15 @@ module es {
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
*/
public onAddedToScene(scene: Scene){}
public onAddedToScene(scene: Scene) {
}
/**
* 使
*/
public unload(){ }
/**
*
* @param cam
*/
protected beginRender(cam: Camera){ }
public unload() {
}
public abstract render(scene: Scene);
/**
*
* @param renderable
* @param cam
*/
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera){
renderable.render(cam);
}
/**
*
* @param newWidth
@@ -59,5 +46,21 @@ module es {
public compareTo(other: Renderer): number {
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用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
*/
export abstract class SceneTransition {
private _hasPreviousSceneRender: boolean;
/** 是否加载新场景的标志 */
public loadsNewScene: boolean;
/**
@@ -11,12 +10,19 @@ module es {
* isNewSceneLoaded应该在中点设置为true
*/
public isNewSceneLoaded: boolean;
/** 返回新加载场景的函数 */
protected sceneLoadAction: Function;
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
public onScreenObscured: Function;
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
public onTransitionCompleted: Function;
/** 返回新加载场景的函数 */
protected sceneLoadAction: Function;
constructor(sceneLoadAction: Function) {
this.sceneLoadAction = sceneLoadAction;
this.loadsNewScene = sceneLoadAction != null;
}
private _hasPreviousSceneRender: boolean;
public get hasPreviousSceneRender() {
if (!this._hasPreviousSceneRender) {
@@ -27,13 +33,9 @@ module es {
return true;
}
constructor(sceneLoadAction: Function) {
this.sceneLoadAction = sceneLoadAction;
this.loadsNewScene = sceneLoadAction != null;
public preRender() {
}
public preRender() { }
public render() {
}
@@ -43,6 +45,17 @@ module es {
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() {
Core._instance._sceneTransition = null;
@@ -62,16 +75,5 @@ module es {
Core.scene = await this.sceneLoadAction();
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 {
export class WindTransition extends SceneTransition {
public duration = 1;
public easeType = egret.Ease.quadOut;
private _mask: egret.Shape;
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) {
super(sceneLoadAction);
@@ -56,6 +50,14 @@ module es {
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() {
this.loadNextScene();
await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType);
+21 -16
View File
@@ -2,25 +2,38 @@ module es {
export class Viewport {
private _x: number;
private _y: number;
private _width: number;
private _height: number;
private _minDepth: number;
private _maxDepth: number;
public get height(){
return this._height;
}
public set height(value: number){
this._height = value;
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;
}
private _width: number;
public get width() {
return this._width;
}
public set width(value: number) {
this._width = value;
}
private _height: number;
public get height() {
return this._height;
}
public set height(value: number) {
this._height = value;
}
public get aspectRatio() {
if ((this._height != 0) && (this._width != 0))
return (this._width / this._height);
@@ -30,6 +43,7 @@ module es {
public get bounds() {
return new Rectangle(this._x, this._y, this._width, this._height);
}
public set bounds(value: Rectangle) {
this._x = value.x;
this._y = value.y;
@@ -37,14 +51,5 @@ module es {
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 {
export var matrixPool = [];
/**
* 3 * 3
*/
@@ -7,36 +8,47 @@ module es {
public get m11(): number {
return this.a;
}
public set m11(value: number) {
this.a = value;
}
public get m12(): number {
return this.b;
}
public set m12(value: number) {
this.b = value;
}
public get m21(): number {
return this.c;
}
public set m21(value: number) {
this.c = value;
}
public get m22(): number {
return this.d;
}
public set m22(value: number) {
this.d = value;
}
public get m31(): number {
return this.tx;
}
public set m31(value: number) {
this.tx = value;
}
public get m32(): number {
return this.ty;
}
public set m32(value: number) {
this.ty = value;
}
+37 -35
View File
@@ -2,6 +2,7 @@ module es {
export class Rectangle extends egret.Rectangle {
public _tempMat: Matrix2D;
public _transformMat: Matrix2D;
/**
*
*/
@@ -18,6 +19,7 @@ module es {
public get location() {
return new Vector2(this.x, this.y);
}
/** 左上角的坐标 */
public set location(value: Vector2) {
this.x = value.x;
@@ -33,6 +35,41 @@ module es {
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
@@ -58,17 +95,6 @@ module es {
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
@@ -183,29 +209,5 @@ module es {
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 {
/** 2d 向量 */
export class Vector2 {
public x: number = 0;
public y: number = 0;
private static readonly unitYVector = new Vector2(0, 1);
private static readonly unitXVector = new Vector2(1, 0);
private static readonly unitVector2 = new Vector2(1, 1);
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() {
return Vector2.zeroVector2;
}
@@ -24,56 +34,6 @@ module es {
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
@@ -122,23 +82,6 @@ module es {
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
*
@@ -223,6 +166,63 @@ module es {
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) {
return other.x == this.x && other.y == this.y;
}
+1 -1
View File
@@ -1,10 +1,10 @@
module es {
export class Physics {
private static _spatialHash: SpatialHash;
/** 调用reset并创建一个新的SpatialHash时使用的单元格大小 */
public static spatialHashCellSize = 100;
/** 接受layerMask的所有方法的默认值 */
public static readonly allLayers: number = -1;
private static _spatialHash: SpatialHash;
public static reset() {
this._spatialHash = new SpatialHash(this.spatialHashCellSize);
+54 -55
View File
@@ -9,19 +9,7 @@ module es {
*
*/
public points: Vector2[];
/**
* 线SAT碰撞检测squareRoots
* box只有两个边缘
*/
public get edgeNormals(){
if (this._areEdgeNormalsDirty)
this.buildEdgeNormals();
return this._edgeNormals;
}
public _areEdgeNormalsDirty = true;
public _edgeNormals: Vector2[];
/**
*
*/
@@ -46,54 +34,18 @@ module es {
this.isBox = isBox;
}
/**
* 线
* @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 _edgeNormals: Vector2[];
/**
*
*
* 线SAT碰撞检测squareRoots
* box只有两个边缘
*/
public recalculateCenterAndEdgeNormals() {
this._polygonCenter = Polygon.findPolygonCenter(this.points);
this._areEdgeNormalsDirty = true;
public get edgeNormals() {
if (this._areEdgeNormalsDirty)
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角形)
* @param vertCount
@@ -173,6 +125,53 @@ module es {
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) {
// 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始
this.center = collider.localOffset;
+3
View File
@@ -16,8 +16,11 @@ module es {
public bounds: Rectangle;
public abstract recalculateBounds(collider: Collider);
public abstract overlaps(other: Shape): boolean;
public abstract collidesWithShape(other: Shape, collisionResult: CollisionResult): boolean;
public abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
public clone(): Shape {
+40 -40
View File
@@ -30,33 +30,6 @@ module es {
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
* @param collider
@@ -134,10 +107,6 @@ module es {
}
}
private debugDrawCellDetails(x: number, y: number, cellCount: number, secondsToDisplay = 0.5, textScale = 1){
}
/**
*
* @param bounds
@@ -216,6 +185,37 @@ module es {
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 {
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[]) {
this._store.set(this.getKey(x, y), list);
}
@@ -259,6 +250,15 @@ module es {
public 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 {
+44 -43
View File
@@ -25,7 +25,8 @@ namespace stopwatch {
*/
private _completeSlices: Slice[] = [];
constructor(private readonly getSystemTime = _defaultSystemTimeGetter) { }
constructor(private readonly getSystemTime = _defaultSystemTimeGetter) {
}
public getState() {
if (this._startSystemTime === undefined) {
@@ -84,48 +85,6 @@ namespace stopwatch {
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();
}
/**
*
* @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
+18 -18
View File
@@ -18,23 +18,19 @@ module es {
public static readonly barPadding = 2;
public static readonly autoAdjustDelay = 30;
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 width: number;
public enabled: true;
/** */
public showLog = false;
private _frameKey = 'frame';
private _logKey = 'log';
/** 每帧的日志 */
private _logs: FrameLog[];
/** 当前显示帧计数 */
private sampleFrames: number;
/** TimerRuler画的位置。 */
private _position: Vector2;
/** 上一帧日志 */
@@ -56,8 +52,6 @@ module es {
* StartFrame调用的次数Draw被调用
*/
private _updateCount: number;
/** */
public showLog = false;
private _frameAdjust: number;
constructor() {
@@ -72,9 +66,10 @@ module es {
this.onGraphicsDeviceReset();
}
private onGraphicsDeviceReset() {
let layout = new Layout();
this._position = layout.place(new Vector2(this.width, TimeRuler.barHeight), 0, 0.01, Alignment.bottomCenter).location;
public static get Instance(): TimeRuler {
if (!this._instance)
this._instance = new TimeRuler();
return this._instance;
}
/**
@@ -273,7 +268,7 @@ module es {
height += TimeRuler.barHeight + TimeRuler.barPadding * 2;
maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime);
}
})
});
const frameSpan = 1 / 60 * 1000;
let sampleSpan = this.sampleFrames * frameSpan;
@@ -297,6 +292,11 @@ module es {
// 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);
aryB = this.getUniqueAry(aryB);
let ary: number[] = aryA.concat(aryB);
let uObj: Object = new Object();
let uObj: Object = {};
let newAry: number[] = [];
let count: number = ary.length;
for (let j: number = 0; j < count; ++j) {
if (!uObj[ary[j]]) {
uObj[ary[j]] = new Object();
uObj[ary[j]] = {};
uObj[ary[j]].count = 0;
uObj[ary[j]].key = ary[j];
uObj[ary[j]].count++;
}
else {
} else {
if (uObj[ary[j]] instanceof Object) {
uObj[ary[j]].count++;
}
+21 -21
View File
@@ -29,27 +29,7 @@ class Base64Utils {
this._keyAll.charAt(enc3) + this._keyAll.charAt(enc4);
}
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;
}
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) {
let string = "";
let i = 0;
+1
View File
@@ -13,6 +13,7 @@ module es {
this.context = context;
}
}
/**
*
*/
+8 -4
View File
@@ -1,5 +1,7 @@
module es {
export class GlobalManager {
public _enabled: boolean;
/**
* true则启用了GlobalManager
* OnEnabled/OnDisable
@@ -31,21 +33,23 @@ module es {
}
}
}
public _enabled: boolean;
/**
* GlobalManager启用时调用
*/
public onEnabled(){}
public onEnabled() {
}
/**
* GlobalManager禁用时调用
*/
public onDisabled(){}
public onDisabled() {
}
/**
* frame .update之前调用每一帧
*/
public update(){}
public update() {
}
}
}
+43 -33
View File
@@ -4,6 +4,7 @@ module es {
public y = 0;
public touchPoint: number = -1;
public touchDown: boolean = false;
public get position() {
return new Vector2(this.x, this.y);
}
@@ -19,36 +20,11 @@ module es {
export class Input {
private static _init: boolean = false;
private static _previousTouchState: TouchState = new TouchState();
private static _gameTouchs: TouchState[] = [];
private static _resolutionOffset: Vector2 = new Vector2();
private static _resolutionScale: Vector2 = Vector2.one;
private static _touchIndex: number = 0;
private static _totalTouchCount: number = 0;
/** 返回第一个触摸点的坐标 */
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;
}
private static _gameTouchs: TouchState[] = [];
/**
*
* touchPoint是否为-1
@@ -58,6 +34,40 @@ module es {
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() {
let delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position);
@@ -81,6 +91,11 @@ module es {
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() {
this._totalTouchCount = 0;
this._touchIndex = 0;
@@ -138,10 +153,5 @@ module es {
this._previousTouchState.touchPoint = touchState.touchPoint;
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_UP: number = 1;
//存放按下注册数据的字典
private static keyDownDict: Object;
//存放按起注册数据的字典
private static keyUpDict: Object;
/**
*
*/
@@ -39,7 +33,6 @@ class KeyboardUtils {
public static X: string = "X";
public static Y: string = "Y";
public static Z: string = "Z";
public static ESC: string = "Esc";
public static F1: string = "F1";
public static F2: string = "F2";
@@ -53,7 +46,6 @@ class KeyboardUtils {
public static F10: string = "F10";
public static F11: string = "F11";
public static F12: string = "F12";
public static NUM_1: string = "1";
public static NUM_2: string = "2";
public static NUM_3: string = "3";
@@ -64,7 +56,6 @@ class KeyboardUtils {
public static NUM_8: string = "8";
public static NUM_9: string = "9";
public static NUM_0: string = "0";
public static TAB: string = "Tab";
public static CTRL: string = "Ctrl";
public static ALT: string = "Alt";
@@ -73,25 +64,24 @@ class KeyboardUtils {
public static ENTER: string = "Enter";
public static SPACE: string = "Space";
public static BACK_SPACE: string = "Back Space";
public static INSERT: string = "Insert";
public static DELETE: string = "Page Down";
public static HOME: string = "Home";
public static END: string = "Page Down";
public static PAGE_UP: string = "Page Up";
public static PAGE_DOWN: string = "Page Down";
public static LEFT: string = "Left";
public static RIGHT: string = "Right";
public static UP: string = "Up";
public static DOWN: string = "Down";
public static PAUSE_BREAK: string = "Pause Break";
public static NUM_LOCK: string = "Num Lock";
public static SCROLL_LOCK: string = "Scroll Lock";
public static WINDOWS: string = "Windows";
//存放按下注册数据的字典
private static keyDownDict: Object;
//存放按起注册数据的字典
private static keyUpDict: Object;
public static init(): void {
this.keyDownDict = {};
@@ -100,32 +90,6 @@ class KeyboardUtils {
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
@@ -147,6 +111,39 @@ class KeyboardUtils {
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获取相应的字符串代号
@@ -225,15 +222,4 @@ class KeyboardUtils {
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 {
private _keyX: string;
private _keyY: string;
constructor(key) {
this._keyX = `mutex_key_${key}_X`;
this._keyY = `mutex_key_${key}_Y`;
+4 -5
View File
@@ -62,10 +62,6 @@ class RandomUtils {
return array;
}
private static _randomCompare(a: Object, b: Object): number {
return (this.random() > .5) ? 1 : -1;
}
/**
*
* @param sequence vectorlength属性
@@ -83,7 +79,6 @@ class RandomUtils {
return sequence[index];
}
/**
* æ ?
* <pre>
@@ -131,4 +126,8 @@ class RandomUtils {
public static boolean(chance: number = .5): boolean {
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 _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
* @param points
@@ -96,18 +109,5 @@ module es {
this._triPrev[0] = count - 1;
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",
"dom",
"es2015.promise",
"es6",
] ,
"es6"
]
},
"include": [
"src",