Skip to content

Commit 62c2795

Browse files
Merge pull request #423 from C7-Game/pcen/incrementing-id
Incrementing IDs
2 parents 48aecb4 + 34df044 commit 62c2795

22 files changed

+413006
-400117
lines changed

C7/AnimationTracker.cs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
using System;
32
using System.Collections.Generic;
43
using System.Threading;
@@ -21,18 +20,11 @@ public struct ActiveAnimation {
2120
public C7Animation anim;
2221
}
2322

24-
public Dictionary<string, ActiveAnimation> activeAnims = new Dictionary<string, ActiveAnimation>();
23+
private Dictionary<ID, ActiveAnimation> activeAnims = new Dictionary<ID, ActiveAnimation>();
2524

2625
public long getCurrentTimeMS() => DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
2726

28-
private string getTileID(Tile tile)
29-
{
30-
// Generate a string to ID this tile that won't conflict with the unit GUIDs. TODO: Eventually we'll implement a common way of ID'ing
31-
// all game objects. Use that here instead.
32-
return String.Format("Tile.{0}.{1}", tile.xCoordinate, tile.yCoordinate);
33-
}
34-
35-
private void startAnimation(string id, C7Animation anim, AutoResetEvent completionEvent, AnimationEnding ending)
27+
private void startAnimation(ID id, C7Animation anim, AutoResetEvent completionEvent, AnimationEnding ending)
3628
{
3729
long currentTimeMS = getCurrentTimeMS();
3830
long animDurationMS = (long)(1000.0 * anim.getDuration());
@@ -55,30 +47,30 @@ private void startAnimation(string id, C7Animation anim, AutoResetEvent completi
5547

5648
public void startAnimation(MapUnit unit, MapUnit.AnimatedAction action, AutoResetEvent completionEvent, AnimationEnding ending)
5749
{
58-
startAnimation(unit.guid, civ3AnimData.forUnit(unit.unitType, action), completionEvent, ending);
50+
startAnimation(unit.id, civ3AnimData.forUnit(unit.unitType, action), completionEvent, ending);
5951
}
6052

6153
public void startAnimation(Tile tile, AnimatedEffect effect, AutoResetEvent completionEvent, AnimationEnding ending)
6254
{
63-
startAnimation(getTileID(tile), civ3AnimData.forEffect(effect), completionEvent, ending);
55+
startAnimation(tile.id, civ3AnimData.forEffect(effect), completionEvent, ending);
6456
}
6557

6658
public void endAnimation(MapUnit unit)
6759
{
6860
ActiveAnimation aa;
69-
if (activeAnims.TryGetValue(unit.guid, out aa)) {
61+
if (activeAnims.TryGetValue(unit.id, out aa)) {
7062
if (aa.completionEvent != null)
7163
aa.completionEvent.Set();
72-
activeAnims.Remove(unit.guid);
64+
activeAnims.Remove(unit.id);
7365
}
7466
}
7567

7668
public bool hasCurrentAction(MapUnit unit)
7769
{
78-
return activeAnims.ContainsKey(unit.guid);
70+
return activeAnims.ContainsKey(unit.id);
7971
}
8072

81-
public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(string id)
73+
public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(ID id)
8274
{
8375
ActiveAnimation aa = activeAnims[id];
8476

@@ -97,18 +89,18 @@ public bool hasCurrentAction(MapUnit unit)
9789

9890
public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(MapUnit unit)
9991
{
100-
return getCurrentActionAndProgress(unit.guid);
92+
return getCurrentActionAndProgress(unit.id);
10193
}
10294

10395
public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(Tile tile)
10496
{
105-
return getCurrentActionAndProgress(getTileID(tile));
97+
return getCurrentActionAndProgress(tile.id);
10698
}
10799

108100
public void update()
109101
{
110-
long currentTimeMS = !endAllImmediately ? getCurrentTimeMS() : long.MaxValue;
111-
var keysToRemove = new List<string>();
102+
long currentTimeMS = (! endAllImmediately) ? getCurrentTimeMS() : long.MaxValue;
103+
List<ID> keysToRemove = new List<ID>();
112104
foreach (var guidAAPair in activeAnims.Where(guidAAPair => guidAAPair.Value.endTimeMS <= currentTimeMS)) {
113105
var (id, aa) = (guidAAPair.Key, guidAAPair.Value);
114106
if (aa.completionEvent is not null) {
@@ -155,6 +147,6 @@ public MapUnit.Appearance getUnitAppearance(MapUnit unit)
155147
public C7Animation getTileEffect(Tile tile)
156148
{
157149
ActiveAnimation aa;
158-
return activeAnims.TryGetValue(getTileID(tile), out aa) ? aa.anim : null;
150+
return activeAnims.TryGetValue(tile.id, out aa) ? aa.anim : null;
159151
}
160152
}

C7/Game.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void processEngineMessages(GameData gameData) {
121121
while (EngineStorage.messagesToUI.TryDequeue(out msg)) {
122122
switch (msg) {
123123
case MsgStartUnitAnimation mSUA:
124-
MapUnit unit = gameData.GetUnit(mSUA.unitGUID);
124+
MapUnit unit = gameData.GetUnit(mSUA.unitID);
125125
if (unit != null && (controller.tileKnowledge.isTileKnown(unit.location) || controller.tileKnowledge.isTileKnown(unit.previousLocation))) {
126126
// TODO: This needs to be extended so that the player is shown when AIs found cities, when they move units
127127
// (optionally, depending on preferences) and generalized so that modders can specify whether custom
@@ -333,7 +333,7 @@ public override void _UnhandledInput(InputEvent @event) {
333333
using (var gameDataAccess = new UIGameDataAccess()) {
334334
var tile = mapView.tileAt(gameDataAccess.gameData.map, globalMousePosition);
335335
if (tile != null) {
336-
new MsgSetUnitPath(CurrentlySelectedUnit.guid, tile).send();
336+
new MsgSetUnitPath(CurrentlySelectedUnit.id, tile).send();
337337
}
338338
}
339339
} else {
@@ -441,7 +441,7 @@ private void processActions() {
441441
moveUnit = false;
442442
}
443443
if (moveUnit) {
444-
new MsgMoveUnit(CurrentlySelectedUnit.guid, dir).send();
444+
new MsgMoveUnit(CurrentlySelectedUnit.id, dir).send();
445445
setSelectedUnit(CurrentlySelectedUnit); //also triggers updating the lower-left info box
446446
}
447447
}
@@ -468,18 +468,18 @@ private void processActions() {
468468

469469
// actions with unit buttons
470470
if (Input.IsActionJustPressed(C7Action.UnitHold)) {
471-
new MsgSkipUnitTurn(CurrentlySelectedUnit.guid).send();
471+
new MsgSkipUnitTurn(CurrentlySelectedUnit.id).send();
472472
}
473473

474474
if (Input.IsActionJustPressed(C7Action.UnitWait)) {
475475
using (var gameDataAccess = new UIGameDataAccess()) {
476-
UnitInteractions.waitUnit(gameDataAccess.gameData, CurrentlySelectedUnit.guid);
476+
UnitInteractions.waitUnit(gameDataAccess.gameData, CurrentlySelectedUnit.id);
477477
GetNextAutoselectedUnit(gameDataAccess.gameData);
478478
}
479479
}
480480

481481
if (Input.IsActionJustPressed(C7Action.UnitFortify)) {
482-
new MsgSetFortification(CurrentlySelectedUnit.guid, true).send();
482+
new MsgSetFortification(CurrentlySelectedUnit.id, true).send();
483483
}
484484

485485
if (Input.IsActionJustPressed(C7Action.UnitDisband)) {
@@ -508,7 +508,7 @@ private void processActions() {
508508

509509
if (Input.IsActionJustPressed(C7Action.UnitBuildCity) && CurrentlySelectedUnit.canBuildCity()) {
510510
using (var gameDataAccess = new UIGameDataAccess()) {
511-
MapUnit currentUnit = gameDataAccess.gameData.GetUnit(CurrentlySelectedUnit.guid);
511+
MapUnit currentUnit = gameDataAccess.gameData.GetUnit(CurrentlySelectedUnit.id);
512512
log.Debug(currentUnit.Describe());
513513
if (currentUnit.canBuildCity()) {
514514
PopupOverlay popupOverlay = GetNode<PopupOverlay>(PopupOverlay.NodePath);
@@ -519,7 +519,7 @@ private void processActions() {
519519
}
520520

521521
if (Input.IsActionJustPressed(C7Action.UnitBuildRoad) && CurrentlySelectedUnit.canBuildRoad()) {
522-
new MsgBuildRoad(CurrentlySelectedUnit.guid).send();
522+
new MsgBuildRoad(CurrentlySelectedUnit.id).send();
523523
}
524524
}
525525

@@ -541,7 +541,7 @@ private void _on_SlideToggle_toggled(bool buttonPressed) {
541541

542542
// Called by the disband popup
543543
private void OnUnitDisbanded() {
544-
new MsgDisbandUnit(CurrentlySelectedUnit.guid).send();
544+
new MsgDisbandUnit(CurrentlySelectedUnit.id).send();
545545
}
546546

547547
/**
@@ -555,6 +555,6 @@ public override void _Notification(int what) {
555555
}
556556

557557
private void OnBuildCity(string name) {
558-
new MsgBuildCity(CurrentlySelectedUnit.guid, name).send();
558+
new MsgBuildCity(CurrentlySelectedUnit.id, name).send();
559559
}
560560
}

0 commit comments

Comments
 (0)