Skip to content

Commit 362b613

Browse files
committed
small performance stuff
1 parent 8e370d3 commit 362b613

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

src/main/java/bwapi/Unit.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public class Unit {
2828
private final Position initialPosition;
2929
private final TilePosition initialTilePosition;
3030

31+
private final int id;
32+
private final int replayID;
33+
3134
// variable
3235
private int lastCommandFrame = 0;
3336
private UnitCommand lastCommand;
@@ -41,10 +44,13 @@ public class Unit {
4144
initialHitPoints = getHitPoints();
4245
initialPosition = getPosition();
4346
initialTilePosition = getTilePosition();
47+
48+
id = unitData.id();
49+
replayID = unitData.replayID();
4450
}
4551

4652
public int getID() {
47-
return unitData.id();
53+
return id;
4854
}
4955

5056

@@ -53,7 +59,7 @@ public boolean exists() {
5359
}
5460

5561
public int getReplayID() {
56-
return unitData.replayID();
62+
return replayID;
5763
}
5864

5965
public Player getPlayer() {

src/main/java/bwapi/UnitCommand.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,40 @@ public TilePosition getTargetTilePosition() {
5757
return posComs.contains(type) ? new TilePosition(x, y) : new TilePosition(x / 32, y / 32);
5858
}
5959

60-
private static Set<UnitCommandType> unitTypeComs = new HashSet<>(
61-
Arrays.asList(Build, Build_Addon, Train, Morph)
62-
);
6360
public UnitType getUnitType() {
64-
return unitTypeComs.contains(type) ? UnitType.unitTypes[extra] : UnitType.None;
61+
if (type == Build || type == Build_Addon || type == Train || type == Morph) {
62+
return UnitType.unitTypes[extra];
63+
}
64+
return UnitType.None;
6565
}
6666

67-
private static Set<UnitCommandType> techComs = new HashSet<>(
68-
Arrays.asList(Research, Use_Tech, Use_Tech_Position, Use_Tech_Unit)
69-
);
70-
7167
public TechType getTechType() {
72-
return techComs.contains(type) ? TechType.techTypes[extra] : TechType.None;
68+
if (type == Research || type == Use_Tech || type == Use_Tech_Position || type == Use_Tech_Unit) {
69+
return TechType.techTypes[extra];
70+
}
71+
return TechType.None;
7372
}
7473

7574
public UpgradeType getUpgradeType() {
7675
return type == UnitCommandType.Upgrade ? UpgradeType.upgradeTypes[extra] : UpgradeType.None;
7776
}
7877

79-
private static Set<UnitCommandType> queuables = new HashSet<>(
80-
Arrays.asList(Attack_Move, Attack_Unit, Move, Patrol, Hold_Position, Stop, Follow, Gather, Return_Cargo,
81-
Repair, Load, Unload_All, Unload_All_Position, Right_Click_Position, Right_Click_Unit)
82-
);
83-
8478
public boolean isQueued() {
85-
return queuables.contains(type) && extra != 0;
79+
return (type == Attack_Move ||
80+
type == Attack_Unit ||
81+
type == Move ||
82+
type == Patrol ||
83+
type == Hold_Position ||
84+
type == Stop ||
85+
type == Follow ||
86+
type == Gather ||
87+
type == Return_Cargo ||
88+
type == Load ||
89+
type == Unload_All ||
90+
type == Unload_All_Position ||
91+
type == Right_Click_Position ||
92+
type == Right_Click_Unit)
93+
&& extra != 0;
8694
}
8795

8896
@Override

0 commit comments

Comments
 (0)