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

View File

@@ -4,43 +4,43 @@ module es {
*
* 它是由一个位向量实现的,但同样可以把它看成是一个非负整数的集合;集合中的每个整数由对应索引处的集合位表示。该结构的大小由集合中的最大整数决定。
*/
export class BitSet{
export class BitSet {
private static LONG_MASK: number = 0x3f;
private _bits: number[];
constructor(nbits: number = 64){
constructor(nbits: number = 64) {
let length = nbits >> 6;
if ((nbits & BitSet.LONG_MASK) != 0)
length ++;
length++;
this._bits = new Array(length);
}
public and(bs: BitSet){
public and(bs: BitSet) {
let max = Math.min(this._bits.length, bs._bits.length);
let i;
for (let i = 0; i < max; ++i)
this._bits[i] &= bs._bits[i];
while (i < this._bits.length)
this._bits[i ++] = 0;
this._bits[i++] = 0;
}
public andNot(bs: BitSet){
public andNot(bs: BitSet) {
let i = Math.min(this._bits.length, bs._bits.length);
while(--i >= 0)
while (--i >= 0)
this._bits[i] &= ~bs._bits[i];
}
public cardinality(): number{
public cardinality(): number {
let card = 0;
for (let i = this._bits.length - 1; i >= 0; i --){
for (let i = this._bits.length - 1; i >= 0; i--) {
let a = this._bits[i];
if (a == 0)
continue;
if (a == -1){
if (a == -1) {
card += 64;
continue;
}
@@ -56,26 +56,18 @@ module es {
return card;
}
public clear(pos?: number){
if (pos != undefined){
public clear(pos?: number) {
if (pos != undefined) {
let offset = pos >> 6;
this.ensure(offset);
this._bits[offset] &= ~(1 << pos);
}else{
for (let i = 0; i < this._bits.length; i ++)
} else {
for (let i = 0; i < this._bits.length; i++)
this._bits[i] = 0;
}
}
private ensure(lastElt: number){
if (lastElt >= this._bits.length){
let nd = new Number[lastElt + 1];
nd = this._bits.copyWithin(0, 0, this._bits.length);
this._bits = nd;
}
}
public get(pos: number): boolean{
public get(pos: number): boolean {
let offset = pos >> 6;
if (offset >= this._bits.length)
return false;
@@ -83,9 +75,9 @@ module es {
return (this._bits[offset] & (1 << pos)) != 0;
}
public intersects(set: BitSet){
public intersects(set: BitSet) {
let i = Math.min(this._bits.length, set._bits.length);
while (--i >= 0){
while (--i >= 0) {
if ((this._bits[i] & set._bits[i]) != 0)
return true;
}
@@ -93,8 +85,8 @@ module es {
return false;
}
public isEmpty(): boolean{
for (let i = this._bits.length - 1; i >= 0; i --){
public isEmpty(): boolean {
for (let i = this._bits.length - 1; i >= 0; i--) {
if (this._bits[i])
return false;
}
@@ -102,34 +94,42 @@ module es {
return true;
}
public nextSetBit(from: number){
public nextSetBit(from: number) {
let offset = from >> 6;
let mask = 1 << from;
while (offset < this._bits.length){
while (offset < this._bits.length) {
let h = this._bits[offset];
do {
if ((h & mask) != 0)
return from;
mask <<= 1;
from ++;
from++;
} while (mask != 0);
mask = 1;
offset ++;
offset++;
}
return -1;
}
public set(pos: number, value: boolean = true){
if (value){
public set(pos: number, value: boolean = true) {
if (value) {
let offset = pos >> 6;
this.ensure(offset);
this._bits[offset] |= 1 << pos;
}else{
} else {
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;
}
}
}
}

View File

@@ -37,7 +37,7 @@ module es {
return this._components;
}
public markEntityListUnsorted(){
public markEntityListUnsorted() {
this._isComponentListUnsorted = true;
}
@@ -76,7 +76,7 @@ module es {
let component = this._components[i];
// 处理渲染层列表
if (component instanceof RenderableComponent){
if (component instanceof RenderableComponent) {
this._entity.scene.removeChild(component.displayObject);
this._entity.scene.renderableComponents.remove(component);
}
@@ -91,7 +91,7 @@ module es {
for (let i = 0; i < this._components.length; i++) {
let component = this._components[i];
if (component instanceof RenderableComponent){
if (component instanceof RenderableComponent) {
this._entity.scene.addChild(component.displayObject);
this._entity.scene.renderableComponents.add(component);
}
@@ -117,7 +117,7 @@ module es {
if (this._componentsToAdd.length > 0) {
for (let i = 0, count = this._componentsToAdd.length; i < count; i++) {
let component = this._componentsToAdd[i];
if (component instanceof RenderableComponent){
if (component instanceof RenderableComponent) {
this._entity.scene.addChild(component.displayObject);
this._entity.scene.renderableComponents.add(component);
}
@@ -148,7 +148,7 @@ module es {
this._tempBufferList.length = 0;
}
if (this._isComponentListUnsorted){
if (this._isComponentListUnsorted) {
this._components.sort(ComponentList.compareUpdatableOrder.compare);
this._isComponentListUnsorted = false;
}
@@ -156,7 +156,7 @@ module es {
public handleRemove(component: Component) {
// 处理渲染层列表
if (component instanceof RenderableComponent){
if (component instanceof RenderableComponent) {
this._entity.scene.removeChild(component.displayObject);
this._entity.scene.renderableComponents.remove(component);
}

View File

@@ -1,15 +1,15 @@
module es {
export class ComponentTypeManager{
export class ComponentTypeManager {
private static _componentTypesMask: Map<any, number> = new Map<any, number>();
public static add(type){
public static add(type) {
if (!this._componentTypesMask.has(type))
this._componentTypesMask[type] = this._componentTypesMask.size;
}
public static getIndexFor(type){
public static getIndexFor(type) {
let v = -1;
if (!this._componentTypesMask.has(type)){
if (!this._componentTypesMask.has(type)) {
this.add(type);
v = this._componentTypesMask.get(type);
}

View File

@@ -1,5 +1,5 @@
module es {
export class EntityList{
export class EntityList {
public scene: Scene;
/**
* 添加到场景中的实体列表
@@ -27,23 +27,23 @@ module es {
*/
public _tempEntityList: Entity[] = [];
constructor(scene: Scene){
constructor(scene: Scene) {
this.scene = scene;
}
public get count(){
public get count() {
return this._entities.length;
}
public get buffer(){
public get buffer() {
return this._entities;
}
public markEntityListUnsorted(){
public markEntityListUnsorted() {
this._isEntityListUnsorted = true;
}
public markTagUnsorted(tag: number){
public markTagUnsorted(tag: number) {
this._unsortedTags.push(tag);
}
@@ -51,7 +51,7 @@ module es {
* 将实体添加到列表中。所有生命周期方法将在下一帧中被调用。
* @param entity
*/
public add(entity: Entity){
public add(entity: Entity) {
if (this._entitiesToAdded.indexOf(entity) == -1)
this._entitiesToAdded.push(entity);
}
@@ -60,14 +60,14 @@ module es {
* 从列表中删除一个实体。所有生命周期方法将在下一帧中被调用。
* @param entity
*/
public remove(entity: Entity){
if (!this._entitiesToRemove.contains(entity)){
public remove(entity: Entity) {
if (!this._entitiesToRemove.contains(entity)) {
console.warn(`You are trying to remove an entity (${entity.name}) that you already removed`);
return;
}
// 防止在同一帧中添加或删除实体
if (this._entitiesToAdded.contains(entity)){
if (this._entitiesToAdded.contains(entity)) {
this._entitiesToAdded.remove(entity);
return;
}
@@ -79,7 +79,7 @@ module es {
/**
* 从实体列表中删除所有实体
*/
public removeAllEntities(){
public removeAllEntities() {
this._unsortedTags.length = 0;
this._entitiesToAdded.length = 0;
this._isEntityListUnsorted = false;
@@ -88,7 +88,7 @@ module es {
// 它们仍然在_entitiesToRemove列表中该列表将由更新列表处理。
this.updateLists();
for (let i = 0; i < this._entities.length; i ++){
for (let i = 0; i < this._entities.length; i++) {
this._entities[i]._isDestroyed = true;
this._entities[i].onRemovedFromScene();
this._entities[i].scene = null;
@@ -106,9 +106,9 @@ module es {
return this._entities.contains(entity) || this._entitiesToAdded.contains(entity);
}
public getTagList(tag: number){
public getTagList(tag: number) {
let list = this._entityDict.get(tag);
if (!list){
if (!list) {
list = [];
this._entityDict.set(tag, list);
}
@@ -116,31 +116,31 @@ module es {
return this._entityDict.get(tag);
}
public addToTagList(entity: Entity){
public addToTagList(entity: Entity) {
let list = this.getTagList(entity.tag);
if (!list.contains(entity)){
if (!list.contains(entity)) {
list.push(entity);
this._unsortedTags.push(entity.tag);
}
}
public removeFromTagList(entity: Entity){
public removeFromTagList(entity: Entity) {
let list = this._entityDict.get(entity.tag);
if (list){
if (list) {
list.remove(entity);
}
}
public update(){
for (let i = 0; i < this._entities.length; i++){
public update() {
for (let i = 0; i < this._entities.length; i++) {
let entity = this._entities[i];
if (entity.enabled && (entity.updateInterval == 1 || Time.frameCount % entity.updateInterval == 0))
entity.update();
}
}
public updateLists(){
if (this._entitiesToRemove.length > 0){
public updateLists() {
if (this._entitiesToRemove.length > 0) {
let temp = this._entitiesToRemove;
this._entitiesToRemove = this._tempEntityList;
this._tempEntityList = temp;
@@ -157,12 +157,12 @@ module es {
this._tempEntityList.length = 0;
}
if (this._entitiesToAdded.length > 0){
if (this._entitiesToAdded.length > 0) {
let temp = this._entitiesToAdded;
this._entitiesToAdded = this._tempEntityList;
this._tempEntityList = temp;
this._tempEntityList.forEach(entity => {
if (!this._entities.contains(entity)){
if (!this._entities.contains(entity)) {
this._entities.push(entity);
entity.scene = this.scene;
@@ -178,12 +178,12 @@ module es {
this._isEntityListUnsorted = true;
}
if (this._isEntityListUnsorted){
if (this._isEntityListUnsorted) {
this._entities.sort();
this._isEntityListUnsorted = false;
}
if (this._unsortedTags.length > 0){
if (this._unsortedTags.length > 0) {
this._unsortedTags.forEach(tag => {
this._entityDict.get(tag).sort();
});
@@ -196,8 +196,8 @@ module es {
* 返回找到的第一个实体的名称。如果没有找到则返回null。
* @param name
*/
public findEntity(name: string){
for (let i = 0; i < this._entities.length; i ++){
public findEntity(name: string) {
for (let i = 0; i < this._entities.length; i++) {
if (this._entities[i].name == name)
return this._entities[i];
}
@@ -209,11 +209,11 @@ module es {
* 返回带有标记的所有实体的列表。如果没有实体具有标记则返回一个空列表。可以通过ListPool.free将返回的列表放回池中。
* @param tag
*/
public entitiesWithTag(tag: number){
public entitiesWithTag(tag: number) {
let list = this.getTagList(tag);
let returnList = ListPool.obtain<Entity>();
for (let i = 0; i < list.length; i ++)
for (let i = 0; i < list.length; i++)
returnList.push(list[i]);
return returnList;
@@ -223,9 +223,9 @@ module es {
* 返回t类型的所有实体的列表。返回的列表可以通过ListPool.free放回池中。
* @param type
*/
public entitiesOfType<T extends Entity>(type): T[]{
public entitiesOfType<T extends Entity>(type): T[] {
let list = ListPool.obtain<T>();
for (let i = 0; i < this._entities.length; i ++){
for (let i = 0; i < this._entities.length; i++) {
if (this._entities[i] instanceof type)
list.push(this._entities[i] as T);
}
@@ -242,17 +242,17 @@ module es {
* @param type
*/
public findComponentOfType<T extends Component>(type): T {
for (let i = 0; i < this._entities.length; i ++){
if (this._entities[i].enabled){
for (let i = 0; i < this._entities.length; i++) {
if (this._entities[i].enabled) {
let comp = this._entities[i].getComponent<T>(type);
if (comp)
return comp;
}
}
for (let i = 0; i < this._entitiesToAdded.length; i ++){
for (let i = 0; i < this._entitiesToAdded.length; i++) {
let entity = this._entitiesToAdded[i];
if (entity.enabled){
if (entity.enabled) {
let comp = entity.getComponent<T>(type);
if (comp)
return comp;
@@ -266,17 +266,17 @@ module es {
* 返回在类型t的场景中找到的所有组件。返回的列表可以通过ListPool.free放回池中。
* @param type
*/
public findComponentsOfType<T extends Component>(type): T[]{
public findComponentsOfType<T extends Component>(type): T[] {
let comps = ListPool.obtain<T>();
for (let i = 0; i < this._entities.length; i ++){
for (let i = 0; i < this._entities.length; i++) {
if (this._entities[i].enabled)
this._entities[i].getComponents(type, comps);
}
for (let i = 0; i < this._entitiesToAdded.length; i ++){
for (let i = 0; i < this._entitiesToAdded.length; i++) {
let entity = this._entitiesToAdded[i];
if (entity.enabled)
entity.getComponents(type,comps);
entity.getComponents(type, comps);
}
return comps;

View File

@@ -2,64 +2,52 @@ module es {
export class EntityProcessorList {
private _processors: EntitySystem[] = [];
public add(processor: EntitySystem){
public add(processor: EntitySystem) {
this._processors.push(processor);
}
public remove(processor: EntitySystem){
public remove(processor: EntitySystem) {
this._processors.remove(processor);
}
public onComponentAdded(entity: Entity){
public onComponentAdded(entity: Entity) {
this.notifyEntityChanged(entity);
}
public onComponentRemoved(entity: Entity){
public onComponentRemoved(entity: Entity) {
this.notifyEntityChanged(entity);
}
public onEntityAdded(entity: Entity){
public onEntityAdded(entity: Entity) {
this.notifyEntityChanged(entity);
}
public onEntityRemoved(entity: Entity){
public onEntityRemoved(entity: Entity) {
this.removeFromProcessors(entity);
}
protected notifyEntityChanged(entity: Entity){
for (let i = 0; i < this._processors.length; i ++){
this._processors[i].onChanged(entity);
}
}
protected removeFromProcessors(entity: Entity){
for (let i = 0; i < this._processors.length; i ++){
this._processors[i].remove(entity);
}
}
public begin(){
public begin() {
}
public update(){
for (let i = 0; i < this._processors.length; i++){
public update() {
for (let i = 0; i < this._processors.length; i++) {
this._processors[i].update();
}
}
public lateUpdate(){
for (let i = 0; i < this._processors.length; i ++){
public lateUpdate() {
for (let i = 0; i < this._processors.length; i++) {
this._processors[i].lateUpdate();
}
}
public end(){
public end() {
}
public getProcessor<T extends EntitySystem>(): T{
for (let i = 0; i < this._processors.length; i ++){
public getProcessor<T extends EntitySystem>(): T {
for (let i = 0; i < this._processors.length; i++) {
let processor = this._processors[i];
if (processor instanceof EntitySystem)
return processor as T;
@@ -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);
}
}
}
}

View File

@@ -1,28 +1,28 @@
module es {
export class Matcher{
export class Matcher {
protected allSet = new BitSet();
protected exclusionSet = new BitSet();
protected oneSet = new BitSet();
public static empty(){
public static empty() {
return new Matcher();
}
public getAllSet(){
public getAllSet() {
return this.allSet;
}
public getExclusionSet(){
public getExclusionSet() {
return this.exclusionSet;
}
public getOneSet(){
public getOneSet() {
return this.oneSet;
}
public IsIntersted(e: Entity){
if (!this.allSet.isEmpty()){
for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)){
public IsIntersted(e: Entity) {
if (!this.allSet.isEmpty()) {
for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
if (!e.componentBits.get(i))
return false;
}
@@ -37,7 +37,7 @@ module es {
return true;
}
public all(...types: any[]): Matcher{
public all(...types: any[]): Matcher {
types.forEach(type => {
this.allSet.set(ComponentTypeManager.getIndexFor(type));
});
@@ -45,7 +45,7 @@ module es {
return this;
}
public exclude(...types: any[]){
public exclude(...types: any[]) {
types.forEach(type => {
this.exclusionSet.set(ComponentTypeManager.getIndexFor(type));
});
@@ -53,7 +53,7 @@ module es {
return this;
}
public one(...types: any[]){
public one(...types: any[]) {
types.forEach(type => {
this.oneSet.set(ComponentTypeManager.getIndexFor(type));
});

View File

@@ -1,17 +1,16 @@
class ObjectUtils {
/**
* 对象深度拷贝
* @param p any 源对象
* @param c any 目标对象, 不传则返回新对象, 传则合并属性, 相同名字的属性则会覆盖
*/
/**
* 对象深度拷贝
* @param p any 源对象
* @param c any 目标对象, 不传则返回新对象, 传则合并属性, 相同名字的属性则会覆盖
*/
public static clone<T>(p: any, c: T = null): T {
var c = c || <T>{};
for (let i in p) {
if (typeof p[i] === 'object') {
c[i] = p[i] instanceof Array ? [] : {};
this.clone(p[i], c[i]);
}
else {
} else {
c[i] = p[i];
}
}

View File

@@ -1,9 +1,23 @@
class StringUtils {
/**
* 匹配中文字符
* @param str 需要匹配的字符串
* @return
*/
* 特殊符号字符
*/
private static specialSigns: string[] = [
'&', '&amp;',
'<', '&lt;',
'>', '&gt;',
'"', '&quot;',
"'", '&apos;',
'®', '&reg;',
'©', '&copy;',
'™', '&trade;',
];
/**
* 匹配中文字符
* @param str 需要匹配的字符串
* @return
*/
public static matchChineseWord(str: string): string[] {
//中文字符的unicode值[\u4E00-\u9FA5]
let patternA: RegExp = /[\u4E00-\u9FA5]+/gim;
@@ -12,7 +26,7 @@ class StringUtils {
/**
* 去除字符串左端的空白字符
* @param target 目标字符串
* @param target 目标字符串
* @return
*/
public static lTrim(target: string): string {
@@ -25,7 +39,7 @@ class StringUtils {
/**
* 去除字符串右端的空白字符
* @param target 目标字符串
* @param target 目标字符串
* @return
*/
public static rTrim(target: string): string {
@@ -36,7 +50,6 @@ class StringUtils {
return target.slice(0, endIndex + 1);
}
/**
* 返回一个去除2段空白字符的字符串
* @param target
@@ -69,7 +82,7 @@ class StringUtils {
* @return 返回执行替换后的字符串
*/
public static replaceMatch(mainStr: string, targetStr: string,
replaceStr: string, caseMark: boolean = false): string {
replaceStr: string, caseMark: boolean = false): string {
let len: number = mainStr.length;
let tempStr: string = "";
let isMatch: boolean = false;
@@ -84,35 +97,18 @@ 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 需要替换的字符串
* @param reversion 是否翻转替换:将转义符号替换为正常的符号
* @return 换掉特殊字符后的字符串
* @param str 需要替换的字符串
* @param reversion 是否翻转替换:将转义符号替换为正常的符号
* @return 换掉特殊字符后的字符串
*/
public static htmlSpecialChars(str: string, reversion: boolean = false): string {
let len: number = this.specialSigns.length;
@@ -133,27 +129,27 @@ class StringUtils {
/**
* 给数字字符前面添 "0"
*
* <pre>
*
* trace( StringFormat.zfill('1') );
* // 01
*
* trace( StringFormat.zfill('16', 5) );
* // 00016
*
* trace( StringFormat.zfill('-3', 3) );
* // -03
*
* </pre>
*
* @param str 要进行处理的字符串
* @param width 处理后字符串的长度,
* 如果str.length >= width将不做任何处理直接返回原始的str。
* @return
*
*/
* 给数字字符前面添 "0"
*
* <pre>
*
* trace( StringFormat.zfill('1') );
* // 01
*
* trace( StringFormat.zfill('16', 5) );
* // 00016
*
* trace( StringFormat.zfill('-3', 3) );
* // -03
*
* </pre>
*
* @param str 要进行处理的字符串
* @param width 处理后字符串的长度,
* 如果str.length >= width将不做任何处理直接返回原始的str。
* @return
*
*/
public static zfill(str: string, width: number = 2): string {
if (!str) {
return str;
@@ -185,7 +181,7 @@ class StringUtils {
/**
* 翻转字符串
* @param str 字符串
* @param str 字符串
* @return 翻转后的字符串
*/
public static reverse(str: string): string {
@@ -198,14 +194,14 @@ class StringUtils {
/**
* 截断某段字符串
* @param str 目标字符串
* @param start 需要截断的起始索引
* @param len 截断长度
* @param order 顺序true从字符串头部开始计算false从字符串尾巴开始结算。
* @return 截断后的字符串
* @param str 目标字符串
* @param start 需要截断的起始索引
* @param len 截断长度
* @param order 顺序true从字符串头部开始计算false从字符串尾巴开始结算。
* @return 截断后的字符串
*/
public static cutOff(str: string, start: number,
len: number, order: boolean = true): string {
len: number, order: boolean = true): string {
start = Math.floor(start);
len = Math.floor(len);
let length: number = str.length;
@@ -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);

View File

@@ -6,15 +6,15 @@ module es {
public static sharedCanvas: HTMLCanvasElement;
public static sharedContext: CanvasRenderingContext2D;
public static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement{
if (!this.sharedCanvas){
public static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement {
if (!this.sharedCanvas) {
this.sharedCanvas = egret.sys.createCanvas();
this.sharedContext = this.sharedCanvas.getContext("2d");
}
let w = texture.$getTextureWidth();
let h = texture.$getTextureHeight();
if (!rect){
if (!rect) {
rect = egret.$TempRectangle;
rect.x = 0;
rect.y = 0;
@@ -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);
}
}

View File

@@ -9,22 +9,21 @@ 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){
public static update(currentTime: number) {
let dt = (currentTime - this._lastTime) / 1000;
this.deltaTime = dt * this.timeScale;
this.unscaledDeltaTime = dt;
this._timeSinceSceneLoad += dt;
this.frameCount ++;
this.frameCount++;
this._lastTime = currentTime;
}
public static sceneChanged(){
public static sceneChanged() {
this._timeSinceSceneLoad = 0;
}
@@ -32,7 +31,7 @@ module es {
* 允许在间隔检查。只应该使用高于delta的间隔值否则它将始终返回true。
* @param interval
*/
public static checkEvery(interval: number){
public static checkEvery(interval: number) {
// 我们减去了delta因为timeSinceSceneLoad已经包含了这个update ticks delta
return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval);
}

View File

@@ -1,9 +1,9 @@
class TimeUtils {
/**
* 计算月份ID
* @param d 指定计算日期
* @returns 月ID
*/
* 计算月份ID
* @param d 指定计算日期
* @returns 月ID
*/
public static monthId(d: Date = null): number {
d = d ? d : new Date();
let y = d.getFullYear();
@@ -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);
}
}
@@ -151,9 +154,9 @@ class TimeUtils {
/**
* 秒数转换为时间形式。
* @param time 秒数
* @param partition 分隔符
* @param showHour 是否显示小时
* @param time 秒数
* @param partition 分隔符
* @param showHour 是否显示小时
* @return 返回一个以分隔符分割的时, 分, 秒
*
* 比如: time = 4351; secondToTime(time)返回字符串01:12:31;