Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Commit 2b94e5b

Browse files
authored
Merge pull request #73 from THU-ASTA/develop
Fix tons of bugs and optimize performance
2 parents f8efbb5 + 6a9a5ad commit 2b94e5b

File tree

6 files changed

+884
-787
lines changed

6 files changed

+884
-787
lines changed

CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,36 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
78
## [Unreleased]
8-
None
9+
10+
11+
## [24.1.0-beta.6]
12+
## Added
13+
- Frame rate displaying by @Futrime
14+
15+
## Changed
16+
- Dramatically improve performance in communication by @Futrime and @Zhangyr2022
17+
18+
## Fixed
19+
- Tons of bugs in communication by @Futrime and @Zhangyr2022
20+
- Timing bug by @Futrime
21+
- Not responding when receiving endless bytes from serial ports by @Futrime
22+
- Slave being able to set four charging piles by @Futrime and @Zhangyr2022
23+
24+
25+
## [24.1.0-beta.5]
26+
## Added
27+
- Exception handling in packet construction by @Zhangyr2022
28+
29+
## Changed
30+
- Adapt to new Communication Protocol by @Zhangyr2022
31+
32+
## Fixed
33+
- Camera index always set to zero when opening settings window by @Futrime
34+
- Main window not responding when applying camera change by @Futrime
35+
- That more than five orders can be carried simultaneously by @Futrime
36+
937

1038
## [24.1.0-beta.4]
1139
### Fixed

Source/Game.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,22 @@ public long? GameTime
270270
}
271271
}
272272

273+
/// <summary>
274+
/// The duration of the last tick
275+
/// </summary>
276+
/// <remarks>
277+
/// Should be update externally.
278+
/// </remarks>
279+
public long LastTickDuration => this._lastTickDuraion;
280+
281+
/// <summary>
282+
/// The time of the last tick
283+
/// </summary>
284+
/// <remarks>
285+
/// Should be update externally.
286+
/// </remarks>
287+
public long LastTickTime => this._lastTickTime;
288+
273289
/// <summary>
274290
/// A list of the generated orders.
275291
/// </summary>
@@ -325,6 +341,8 @@ public long? RemainingTime
325341
// inner court.
326342
private bool? _hasMovedIntoInnerCourt = null;
327343

344+
private long _lastTickDuraion = 1000; // Just a magic default value.
345+
328346
// Minus one to prevent division by zero.
329347
private long _lastTickTime = Utility.SystemTime - 1;
330348

@@ -343,14 +361,6 @@ public long? RemainingTime
343361

344362
private long? _startTime = null;
345363

346-
private long _lastTickDuration
347-
{
348-
get
349-
{
350-
return Utility.SystemTime - this._lastTickTime;
351-
}
352-
}
353-
354364
private Dictionary<CampType, Vehicle> _vehicle = null;
355365

356366
#endregion
@@ -417,6 +427,9 @@ public Game()
417427
/// </summary>
418428
public void Refresh()
419429
{
430+
this._lastTickDuraion = Utility.SystemTime - this._lastTickTime;
431+
this._lastTickTime = Utility.SystemTime;
432+
420433
// The game should only refresh when running.
421434
if (
422435
this._gameState != GameStatusType.Running
@@ -457,8 +470,9 @@ public void Refresh()
457470

458471
this.AutoCharge();
459472

460-
// Update the time of the last tick.
461-
this._lastTickTime = Utility.SystemTime;
473+
// Must generate orders after refreshing the game to avoid interacting with
474+
// orders not processed by the slave.
475+
this.GenerateOrder();
462476
}
463477

464478
/// <summary>
@@ -602,7 +616,7 @@ public void SetChargingPile()
602616
++chargingPileNumber;
603617
}
604618
}
605-
if (chargingPileNumber > Game.ChargingPileMaxNumber)
619+
if (chargingPileNumber >= Game.ChargingPileMaxNumber)
606620
{
607621
return;
608622
}
@@ -651,7 +665,7 @@ private void AutoCharge()
651665
/// <summary>
652666
/// Attempt to generate an order.
653667
/// </summary>
654-
public void GenerateOrder()
668+
private void GenerateOrder()
655669
{
656670
var newOrder = this._orderGenerator.Generate((long)this.GameTime);
657671
if (newOrder != null)
@@ -758,7 +772,7 @@ void ScoreHittingWall()
758772
if (this.IsInWall(vehiclePosition))
759773
{
760774
this._score[(CampType)this._camp] +=
761-
Game.ScoreHittingWallRate * this._lastTickDuration;
775+
Game.ScoreHittingWallRate * this.LastTickDuration;
762776
}
763777
}
764778

@@ -798,11 +812,11 @@ void ScoreMoving()
798812
// Score parking penalty.
799813
if (
800814
vehicle.ParkingDuration != null &&
801-
(long)vehicle.ParkingDuration >= 5000 + this._lastTickDuration
815+
(long)vehicle.ParkingDuration >= 5000 + this.LastTickDuration
802816
)
803817
{
804818
this._score[(CampType)this._camp] +=
805-
Game.ScoreOvertimeParkingRate * this._lastTickDuration;
819+
Game.ScoreOvertimeParkingRate * this.LastTickDuration;
806820
}
807821
}
808822

@@ -823,7 +837,7 @@ void TackleBarriers()
823837
if (this.IsInBarrier(vehiclePosition))
824838
{
825839
vehicle.IncreaseMaxDistance(
826-
(int)Math.Round(Game.BarrierDischargingRate * this._lastTickDuration)
840+
(int)Math.Round(Game.BarrierDischargingRate * this.LastTickDuration)
827841
);
828842
}
829843
}
@@ -848,7 +862,7 @@ void TackleChargingPiles()
848862
))
849863
{
850864
vehicle.IncreaseMaxDistance(
851-
(int)Math.Round(Game.ChargingPileChargingRate * this._lastTickDuration)
865+
(int)Math.Round(Game.ChargingPileChargingRate * this.LastTickDuration)
852866
);
853867
}
854868

@@ -859,7 +873,7 @@ void TackleChargingPiles()
859873
))
860874
{
861875
vehicle.IncreaseMaxDistance(
862-
(int)Math.Round(Game.ChargingPileDischargingRate * this._lastTickDuration)
876+
(int)Math.Round(Game.ChargingPileDischargingRate * this.LastTickDuration)
863877
);
864878
}
865879
}

0 commit comments

Comments
 (0)