Skip to content

Commit

Permalink
Improve performance (#103)
Browse files Browse the repository at this point in the history
* [add] Add comment for acceptance of maps.

* [fix] Fix a bug for the blocking animation.

* [update] Improve the game performance in fog of war.

* [fxi] Fix #102.
  • Loading branch information
Babygogogo committed Mar 21, 2020
1 parent db77910 commit 0b4bca9
Show file tree
Hide file tree
Showing 32 changed files with 575 additions and 377 deletions.
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"bin-debug/modules/mapEditor/view/MeWarPanel.js",
"bin-debug/modules/mapEditor/view/MeWarRulePanel.js",
"bin-debug/modules/mapEditor/view/MeWarView.js",
"bin-debug/modules/mapManagement/view/MmAcceptMapPanel.js",
"bin-debug/modules/mapManagement/view/MmAvailabilityChangePanel.js",
"bin-debug/modules/mapManagement/view/MmAvailabilityListPanel.js",
"bin-debug/modules/mapManagement/view/MmAvailabilitySearchPanel.js",
Expand Down Expand Up @@ -152,8 +153,8 @@
"bin-debug/modules/multiCustomWar/model/McwTurnManager.js",
"bin-debug/modules/multiCustomWar/model/McwUnit.js",
"bin-debug/modules/multiCustomWar/model/McwUnitMap.js",
"bin-debug/modules/multiCustomWar/model/McwWar.js",
"bin-debug/Platform.js",
"bin-debug/modules/multiCustomWar/view/McwActionPlannerView.js",
"bin-debug/modules/multiCustomWar/view/McwBackgroundPanel.js",
"bin-debug/modules/multiCustomWar/view/McwCoListPanel.js",
"bin-debug/modules/multiCustomWar/view/McwCursorView.js",
Expand Down Expand Up @@ -292,6 +293,6 @@
"bin-debug/modules/mapEditor/model/MeUnit.js",
"bin-debug/modules/mapEditor/model/MeUnitMap.js",
"bin-debug/modules/mapEditor/model/MeUtility.js",
"bin-debug/modules/multiCustomWar/view/McwActionPlannerView.js"
"bin-debug/modules/multiCustomWar/model/McwWar.js"
]
}
2 changes: 1 addition & 1 deletion resource/config/NetMessageProto.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resource/default.thm.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"resource/skins/mapEditor/MeWarMenuPanel.exml",
"resource/skins/mapEditor/MeWarPanel.exml",
"resource/skins/mapEditor/MeWarRulePanel.exml",
"resource/skins/mapManagement/MmAcceptMapPanel.exml",
"resource/skins/mapManagement/MmAvailabilityChangePanel.exml",
"resource/skins/mapManagement/MmAvailabilityListPanel.exml",
"resource/skins/mapManagement/MmAvailabilitySearchPanel.exml",
Expand Down
42 changes: 42 additions & 0 deletions resource/skins/mapManagement/MmAcceptMapPanel.exml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<e:Skin width="960" height="540" xmlns:e="http://ns.egret.com/eui" xmlns:GameUi="TinyWars.GameUi.*"
xmlns:w="http://ns.egret.com/wing">
<GameUi:UiImage left="0" right="0" top="0" bottom="0" source="semi_transparent" />
<e:Group width="430" height="300" horizontalCenter="0" verticalCenter="0">
<GameUi:UiImage source="c04_t01_s02_f01" scale9Grid="9,9,2,2" anchorOffsetX="0" anchorOffsetY="0" alpha="0.8"
left="0" right="0" top="0" bottom="0" />
<GameUi:UiLabel id="_labelTitle" text="过审" textColor="0xffffff" y="12" horizontalCenter="0" size="24" />
<GameUi:UiLabel id="_labelTips" text="请输入您的评价和改进意见,可留空" textColor="0xFFFFFF" size="18" left="10" right="10"
top="50" wordWrap="true" />
<GameUi:UiTextInput id="_inputReason" anchorOffsetX="0" anchorOffsetY="0" maxChars="200" left="10" right="10"
height="160" top="90">
<GameUi:skinName>
<e:Skin width="100" height="30">
<e:Image source="c08_t06_s01_f01" left="0" right="0" bottom="0" />
<e:EditableText id="textDisplay" size="24" left="0" right="0" textColor="0xffffff" top="0"
bottom="0" multiline="true" text="" />
<e:Label id="promptDisplay" size="24" touchEnabled="false" left="0" right="0" text="" height="30"
textColor="0x808080" />
</e:Skin>
</GameUi:skinName>
</GameUi:UiTextInput>
<GameUi:UiButton id="_btnCancel" label="取消" horizontalCenter="-80" bottom="15">
<GameUi:skinName>
<e:Skin states="up,down,disabled">
<e:Image width="100%" height="100%" />
<e:Label id="labelDisplay" horizontalCenter="0" verticalCenter="0" size="25" bold="true"
textColor="0xff0000" />
</e:Skin>
</GameUi:skinName>
</GameUi:UiButton>
<GameUi:UiButton id="_btnConfirm" label="确定" horizontalCenter="80" bottom="15">
<e:skinName>
<e:Skin states="up,down,disabled">
<e:Image width="100%" height="100%" />
<e:Label id="labelDisplay" horizontalCenter="0" verticalCenter="0" size="25" bold="true"
textColor="0x00ff00" />
</e:Skin>
</e:skinName>
</GameUi:UiButton>
</e:Group>
</e:Skin>
106 changes: 106 additions & 0 deletions src/modules/baseWar/model/BwFogMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,34 @@ namespace TinyWars.BaseWar {
return this._mapsFromPaths.get(playerIndex)![gridIndex.x][gridIndex.y];
}
}
public getVisibilityMapFromPathsForTeam(teamIndex: number): Visibility[][] {
return this.getVisibilityMapFromPathsForTeams(new Set([teamIndex]));
}
public getVisibilityMapFromPathsForTeams(teamIndexes: Set<number>): Visibility[][] {
const { width, height } = this.getMapSize();
const resultMap = Helpers.createEmptyMap<Visibility>(width, height, Visibility.OutsideVision);
if (!this.checkHasFogCurrently()) {
resultMap.forEach(column => column.fill(Visibility.TrueVision));
} else {
const mapFromPaths = this._mapsFromPaths;
const playerIndexes = this._getWar().getPlayerManager().getPlayerIndexesInTeams(teamIndexes);
for (let x = 0; x < width; ++x) {
for (let y = 0; y < height; ++y) {
for (const playerIndex of playerIndexes) {
resultMap[x][y] = Math.max(
resultMap[x][y],
mapFromPaths.get(playerIndex)[x][y] || Visibility.OutsideVision
);
}
}
}
}
return resultMap;
}
public getVisibilityMapFromPathsForUser(userId: number): Visibility[][] {
return this.getVisibilityMapFromPathsForTeams(this._getWar().getWatcherTeamIndexes(userId));
}

public getVisibilityFromTilesForPlayer(gridIndex: GridIndex, playerIndex: number): Visibility {
if (!this.checkHasFogCurrently()) {
return Visibility.TrueVision;
Expand All @@ -161,6 +189,42 @@ namespace TinyWars.BaseWar {
}
}
}
public getVisibilityMapFromTilesForTeam(teamIndex: number): Visibility[][] {
return this.getVisibilityMapFromTilesForTeams(new Set([teamIndex]));
}
public getVisibilityMapFromTilesForTeams(teamIndexes: Set<number>): Visibility[][] {
const mapSize = this.getMapSize();
const { width, height } = mapSize;
const resultMap = Helpers.createEmptyMap<Visibility>(width, height, Visibility.OutsideVision);
if (!this.checkHasFogCurrently()) {
resultMap.forEach(column => column.fill(Visibility.TrueVision));
} else {
const tileMap = this._getWar().getTileMap();
for (let x = 0; x < width; ++x) {
for (let y = 0; y < height; ++y) {
const tileGridIndex : GridIndex = { x, y };
const tile = tileMap.getTile(tileGridIndex);
if (teamIndexes.has(tile.getTeamIndex())) {
resultMap[x][y] = Visibility.TrueVision;
}

const visionRange = tile.getVisionRangeForTeamIndexes(teamIndexes);
if (visionRange != null) {
for (const g of GridIndexHelpers.getGridsWithinDistance(tileGridIndex, 0, visionRange, mapSize)) {
if (resultMap[g.x][g.y] === Visibility.OutsideVision) {
resultMap[g.x][g.y] = Visibility.InsideVision;
}
}
}
}
}
}
return resultMap;
}
public getVisibilityMapFromTilesForUser(userId: number): Visibility[][] {
return this.getVisibilityMapFromTilesForTeams(this._getWar().getWatcherTeamIndexes(userId));
}

public getVisibilityFromUnitsForPlayer(gridIndex: GridIndex, playerIndex: number): Visibility {
if (!this.checkHasFogCurrently()) {
return Visibility.TrueVision;
Expand Down Expand Up @@ -192,6 +256,48 @@ namespace TinyWars.BaseWar {
return isInside ? Visibility.InsideVision : Visibility.OutsideVision;
}
}
public getVisibilityMapFromUnitsForTeam(teamIndex: number): Visibility[][] {
return this.getVisibilityMapFromUnitsForTeams(new Set([teamIndex]));
}
public getVisibilityMapFromUnitsForTeams(teamIndexes: Set<number>): Visibility[][] {
const mapSize = this.getMapSize();
const { width, height } = mapSize;
const resultMap = Helpers.createEmptyMap<Visibility>(width, height, Visibility.OutsideVision);
if (!this.checkHasFogCurrently()) {
resultMap.forEach(column => column.fill(Visibility.TrueVision));
} else {
const unitMap = this._getWar().getUnitMap();
for (let x = 0; x < width; ++x) {
for (let y = 0; y < height; ++y) {
const unitGridIndex : GridIndex = { x, y };
const unit = unitMap.getUnitOnMap(unitGridIndex);
if (unit) {
const visionRange = unit.getVisionRangeForTeamIndexes(teamIndexes, unitGridIndex);
if (visionRange != null) {
for (const g of GridIndexHelpers.getGridsWithinDistance(unitGridIndex, 0, 1, mapSize)) {
resultMap[g.x][g.y] = Visibility.TrueVision;
}

const isTrueVision = unit.checkIsTrueVision();
for (const g of GridIndexHelpers.getGridsWithinDistance(unitGridIndex, 2, visionRange, mapSize)) {
if (isTrueVision) {
resultMap[g.x][g.y] = Visibility.TrueVision;
} else {
if (resultMap[g.x][g.y] === Visibility.OutsideVision) {
resultMap[g.x][g.y] = Visibility.InsideVision;
}
}
}
}
}
}
}
}
return resultMap;
}
public getVisibilityMapFromUnitsForUser(userId: number): Visibility[][] {
return this.getVisibilityMapFromUnitsForTeams(this._getWar().getWatcherTeamIndexes(userId));
}
}

function createEmptyMaps<T extends (number | Visibility)>(mapSize: MapSize, maxPlayerIndex: number): Map<number, T[][]> {
Expand Down
7 changes: 7 additions & 0 deletions src/modules/baseWar/model/BwTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ namespace TinyWars.BaseWar {
return Math.max(0, this.getCfgVisionRange() + this._getWar().getSettingsVisionRangeModifier());
}
}
public getVisionRangeForTeamIndexes(teamIndexes: Set<number>): number | null {
if ((!this.checkIsVisionEnabledForAllPlayers()) && (!teamIndexes.has(this.getTeamIndex()))) {
return null;
} else {
return Math.max(0, this.getCfgVisionRange() + this._getWar().getSettingsVisionRangeModifier());
}
}

////////////////////////////////////////////////////////////////////////////////
// Functions for global attack/defense bonus.
Expand Down
11 changes: 11 additions & 0 deletions src/modules/baseWar/model/BwUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,17 @@ namespace TinyWars.BaseWar {
);
}
}
public getVisionRangeForTeamIndexes(teamIndexes: Set<number>, gridIndex: GridIndex): number | undefined {
let vision = null;
for (const playerIndex of this.getWar().getPlayerManager().getPlayerIndexesInTeams(teamIndexes)) {
const v = this.getVisionRangeForPlayer(playerIndex, gridIndex);
if ((vision == null) || (v > vision)) {
vision = v;
}
}
return vision;
}

public checkIsTrueVision(): boolean {
const version = this.getWar()!.getConfigVersion();
const unitType = this.getType();
Expand Down
6 changes: 3 additions & 3 deletions src/modules/mapEditor/model/MeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace TinyWars.MapEditor.MeModel {
const slotIndex = data.slotIndex;
MAP_DICT.set(slotIndex, {
slotIndex,
reviewStatus: data.reviewStatus,
mapRawData : data.mapRawData,
rejectReason: data.rejectReason,
reviewStatus : data.reviewStatus,
mapRawData : data.mapRawData,
reviewComment : data.reviewComment,
});
}
for (let i = 0; i < ConfigManager.COMMON_CONSTANTS.MapEditorSlotMaxCount; ++i) {
Expand Down
22 changes: 16 additions & 6 deletions src/modules/mapEditor/view/MeMapListPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,28 @@ namespace TinyWars.MapEditor {
}

private _onTouchTapBtnNext(e: egret.TouchEvent): void {
const data = this.data as DataForMapRenderer;
const mapData = data.mapData;
if (mapData.reviewStatus !== Types.MapReviewStatus.Rejected) {
Utility.FlowManager.gotoMapEditor(mapData.mapRawData as Types.MapRawData, mapData.slotIndex, false);
} else {
const data = this.data as DataForMapRenderer;
const mapData = data.mapData;
const reviewStatus = mapData.reviewStatus;

if (reviewStatus === Types.MapReviewStatus.Rejected) {
Common.AlertPanel.show({
title : Lang.getText(Lang.Type.B0305),
content : mapData.rejectReason || Lang.getText(Lang.Type.B0001),
content : mapData.reviewComment || Lang.getText(Lang.Type.B0001),
callback: () => {
Utility.FlowManager.gotoMapEditor(mapData.mapRawData as Types.MapRawData, mapData.slotIndex, false);
},
});
} else if (reviewStatus === Types.MapReviewStatus.Accepted) {
Common.AlertPanel.show({
title : Lang.getText(Lang.Type.B0326),
content : mapData.reviewComment || Lang.getText(Lang.Type.B0001),
callback: () => {
Utility.FlowManager.gotoMapEditor(mapData.mapRawData as Types.MapRawData, mapData.slotIndex, false);
},
});
} else {
Utility.FlowManager.gotoMapEditor(mapData.mapRawData as Types.MapRawData, mapData.slotIndex, false);
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/modules/mapEditor/view/MeWarMenuPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,7 @@ namespace TinyWars.MapEditor {
return {
name : Lang.getText(Lang.Type.B0296),
callback: () => {
Common.ConfirmPanel.show({
title : Lang.getText(Lang.Type.B0088),
content : Lang.getText(Lang.Type.A0090),
callback: () => {
const war = this._war;
WarMap.WarMapProxy.reqReviewMap(war.getDesignerUserId(), war.getSlotIndex(), war.getModifiedTime(), true, null);
},
});
MapManagement.MmAcceptMapPanel.show();
},
};
}
Expand Down
62 changes: 62 additions & 0 deletions src/modules/mapManagement/view/MmAcceptMapPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

namespace TinyWars.MapManagement {
import Lang = Utility.Lang;

export class MmAcceptMapPanel extends GameUi.UiPanel {
protected readonly _LAYER_TYPE = Utility.Types.LayerType.Hud3;
protected readonly _IS_EXCLUSIVE = true;

private static _instance: MmAcceptMapPanel;

private _labelTitle : GameUi.UiLabel;
private _labelTips : GameUi.UiLabel;
private _inputReason : GameUi.UiTextInput;
private _btnCancel : GameUi.UiButton;
private _btnConfirm : GameUi.UiButton;

public static show(): void {
if (!MmAcceptMapPanel._instance) {
MmAcceptMapPanel._instance = new MmAcceptMapPanel();
}
MmAcceptMapPanel._instance.open();
}

public static hide(): void {
if (MmAcceptMapPanel._instance) {
MmAcceptMapPanel._instance.close();
}
}

public constructor() {
super();

this.skinName = "resource/skins/mapManagement/MmAcceptMapPanel.exml";
this._setAutoAdjustHeightEnabled();
this._setTouchMaskEnabled();
}

protected _onFirstOpened(): void {
this._uiListeners = [
{ ui: this._btnCancel, callback: this._onTouchedBtnCancel, },
{ ui: this._btnConfirm, callback: this._onTouchedBtnConfirm, },
];
}

protected _onOpened(): void {
this._btnConfirm.label = Lang.getText(Lang.Type.B0026);
this._btnCancel.label = Lang.getText(Lang.Type.B0154);
this._labelTitle.text = Lang.getText(Lang.Type.B0296);
this._labelTips.text = Lang.getText(Lang.Type.A0105);
}

private _onTouchedBtnCancel(e: egret.TouchEvent): void {
MmAcceptMapPanel.hide();
}

private _onTouchedBtnConfirm(e: egret.TouchEvent): void {
const war = MapEditor.MeManager.getWar();
WarMap.WarMapProxy.reqReviewMap(war.getDesignerUserId(), war.getSlotIndex(), war.getModifiedTime(), true, this._inputReason.text);
this.close();
}
}
}
4 changes: 2 additions & 2 deletions src/modules/multiCustomWar/model/McwFogMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ namespace TinyWars.MultiCustomWar {
public startRunning(war: McwWar): void {
super.startRunning(war);

const teamIndexes = war.getWatcherTeamIndexes(User.UserModel.getSelfUserId());
const visibleTiles = VisibilityHelpers.getAllTilesVisibleToUser(war, User.UserModel.getSelfUserId());
war.getTileMap().forEachTile(tile => {
if (!VisibilityHelpers.checkIsTileVisibleToTeams(war, tile.getGridIndex(), teamIndexes)) {
if (!visibleTiles.has(tile)) {
tile.setFogEnabled();
}
});
Expand Down

0 comments on commit 0b4bca9

Please sign in to comment.