Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions C7/AnimationTracker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using System;
using System.Collections.Generic;
using System.Threading;
Expand All @@ -21,18 +20,11 @@ public struct ActiveAnimation {
public C7Animation anim;
}

public Dictionary<string, ActiveAnimation> activeAnims = new Dictionary<string, ActiveAnimation>();
private Dictionary<ID, ActiveAnimation> activeAnims = new Dictionary<ID, ActiveAnimation>();

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

private string getTileID(Tile tile)
{
// 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
// all game objects. Use that here instead.
return String.Format("Tile.{0}.{1}", tile.xCoordinate, tile.yCoordinate);
}

private void startAnimation(string id, C7Animation anim, AutoResetEvent completionEvent, AnimationEnding ending)
private void startAnimation(ID id, C7Animation anim, AutoResetEvent completionEvent, AnimationEnding ending)
{
long currentTimeMS = getCurrentTimeMS();
long animDurationMS = (long)(1000.0 * anim.getDuration());
Expand All @@ -55,30 +47,30 @@ private void startAnimation(string id, C7Animation anim, AutoResetEvent completi

public void startAnimation(MapUnit unit, MapUnit.AnimatedAction action, AutoResetEvent completionEvent, AnimationEnding ending)
{
startAnimation(unit.guid, civ3AnimData.forUnit(unit.unitType, action), completionEvent, ending);
startAnimation(unit.id, civ3AnimData.forUnit(unit.unitType, action), completionEvent, ending);
}

public void startAnimation(Tile tile, AnimatedEffect effect, AutoResetEvent completionEvent, AnimationEnding ending)
{
startAnimation(getTileID(tile), civ3AnimData.forEffect(effect), completionEvent, ending);
startAnimation(tile.id, civ3AnimData.forEffect(effect), completionEvent, ending);
}

public void endAnimation(MapUnit unit)
{
ActiveAnimation aa;
if (activeAnims.TryGetValue(unit.guid, out aa)) {
if (activeAnims.TryGetValue(unit.id, out aa)) {
if (aa.completionEvent != null)
aa.completionEvent.Set();
activeAnims.Remove(unit.guid);
activeAnims.Remove(unit.id);
}
}

public bool hasCurrentAction(MapUnit unit)
{
return activeAnims.ContainsKey(unit.guid);
return activeAnims.ContainsKey(unit.id);
}

public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(string id)
public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(ID id)
{
ActiveAnimation aa = activeAnims[id];

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

public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(MapUnit unit)
{
return getCurrentActionAndProgress(unit.guid);
return getCurrentActionAndProgress(unit.id);
}

public (MapUnit.AnimatedAction, float) getCurrentActionAndProgress(Tile tile)
{
return getCurrentActionAndProgress(getTileID(tile));
return getCurrentActionAndProgress(tile.id);
}

public void update()
{
long currentTimeMS = !endAllImmediately ? getCurrentTimeMS() : long.MaxValue;
var keysToRemove = new List<string>();
long currentTimeMS = (! endAllImmediately) ? getCurrentTimeMS() : long.MaxValue;
List<ID> keysToRemove = new List<ID>();
foreach (var guidAAPair in activeAnims.Where(guidAAPair => guidAAPair.Value.endTimeMS <= currentTimeMS)) {
var (id, aa) = (guidAAPair.Key, guidAAPair.Value);
if (aa.completionEvent is not null) {
Expand Down Expand Up @@ -155,6 +147,6 @@ public MapUnit.Appearance getUnitAppearance(MapUnit unit)
public C7Animation getTileEffect(Tile tile)
{
ActiveAnimation aa;
return activeAnims.TryGetValue(getTileID(tile), out aa) ? aa.anim : null;
return activeAnims.TryGetValue(tile.id, out aa) ? aa.anim : null;
}
}
20 changes: 10 additions & 10 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void processEngineMessages(GameData gameData) {
while (EngineStorage.messagesToUI.TryDequeue(out msg)) {
switch (msg) {
case MsgStartUnitAnimation mSUA:
MapUnit unit = gameData.GetUnit(mSUA.unitGUID);
MapUnit unit = gameData.GetUnit(mSUA.unitID);
if (unit != null && (controller.tileKnowledge.isTileKnown(unit.location) || controller.tileKnowledge.isTileKnown(unit.previousLocation))) {
// TODO: This needs to be extended so that the player is shown when AIs found cities, when they move units
// (optionally, depending on preferences) and generalized so that modders can specify whether custom
Expand Down Expand Up @@ -333,7 +333,7 @@ public override void _UnhandledInput(InputEvent @event) {
using (var gameDataAccess = new UIGameDataAccess()) {
var tile = mapView.tileAt(gameDataAccess.gameData.map, globalMousePosition);
if (tile != null) {
new MsgSetUnitPath(CurrentlySelectedUnit.guid, tile).send();
new MsgSetUnitPath(CurrentlySelectedUnit.id, tile).send();
}
}
} else {
Expand Down Expand Up @@ -441,7 +441,7 @@ private void processActions() {
moveUnit = false;
}
if (moveUnit) {
new MsgMoveUnit(CurrentlySelectedUnit.guid, dir).send();
new MsgMoveUnit(CurrentlySelectedUnit.id, dir).send();
setSelectedUnit(CurrentlySelectedUnit); //also triggers updating the lower-left info box
}
}
Expand All @@ -468,18 +468,18 @@ private void processActions() {

// actions with unit buttons
if (Input.IsActionJustPressed(C7Action.UnitHold)) {
new MsgSkipUnitTurn(CurrentlySelectedUnit.guid).send();
new MsgSkipUnitTurn(CurrentlySelectedUnit.id).send();
}

if (Input.IsActionJustPressed(C7Action.UnitWait)) {
using (var gameDataAccess = new UIGameDataAccess()) {
UnitInteractions.waitUnit(gameDataAccess.gameData, CurrentlySelectedUnit.guid);
UnitInteractions.waitUnit(gameDataAccess.gameData, CurrentlySelectedUnit.id);
GetNextAutoselectedUnit(gameDataAccess.gameData);
}
}

if (Input.IsActionJustPressed(C7Action.UnitFortify)) {
new MsgSetFortification(CurrentlySelectedUnit.guid, true).send();
new MsgSetFortification(CurrentlySelectedUnit.id, true).send();
}

if (Input.IsActionJustPressed(C7Action.UnitDisband)) {
Expand Down Expand Up @@ -508,7 +508,7 @@ private void processActions() {

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

if (Input.IsActionJustPressed(C7Action.UnitBuildRoad) && CurrentlySelectedUnit.canBuildRoad()) {
new MsgBuildRoad(CurrentlySelectedUnit.guid).send();
new MsgBuildRoad(CurrentlySelectedUnit.id).send();
}
}

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

// Called by the disband popup
private void OnUnitDisbanded() {
new MsgDisbandUnit(CurrentlySelectedUnit.guid).send();
new MsgDisbandUnit(CurrentlySelectedUnit.id).send();
}

/**
Expand All @@ -555,6 +555,6 @@ public override void _Notification(int what) {
}

private void OnBuildCity(string name) {
new MsgBuildCity(CurrentlySelectedUnit.guid, name).send();
new MsgBuildCity(CurrentlySelectedUnit.id, name).send();
}
}
Loading