Browse Source

Performance: Bolt state cache

bolt_update
laurids 3 years ago
parent
commit
d071588d6f
8 changed files with 158 additions and 129 deletions
  1. +12
    -12
      Assets/GWConquest/Scripts/Battle.cs
  2. +17
    -17
      Assets/GWConquest/Scripts/BattleFlank.cs
  3. +12
    -12
      Assets/GWConquest/Scripts/District.cs
  4. +21
    -21
      Assets/GWConquest/Scripts/DistrictFactory.cs
  5. +56
    -56
      Assets/GWConquest/Scripts/Formation.cs
  6. +18
    -0
      Assets/GWConquest/Scripts/GWBoltBehaviour.cs
  7. +11
    -0
      Assets/GWConquest/Scripts/GWBoltBehaviour.cs.meta
  8. +11
    -11
      Assets/GWConquest/Scripts/Player.cs

+ 12
- 12
Assets/GWConquest/Scripts/Battle.cs View File

@ -4,7 +4,7 @@ using System.Linq;
namespace GWConquest namespace GWConquest
{ {
public class Battle : Bolt.EntityBehaviour<IBattleState>
public class Battle : GWBoltBehaviour<IBattleState>
{ {
public EntityList FormationList; public EntityList FormationList;
@ -31,24 +31,24 @@ namespace GWConquest
} }
public int FlankCount { public int FlankCount {
get => state.FlankCount;
set => state.FlankCount = value;
get => State.FlankCount;
set => State.FlankCount = value;
} }
public void SetFlank(int index, BattleFlank flank) public void SetFlank(int index, BattleFlank flank)
{ {
state.Flanks[index] = flank?.entity;
State.Flanks[index] = flank?.entity;
} }
public BattleFlank GetFlank(int index) public BattleFlank GetFlank(int index)
{ {
return state.Flanks[index].GetComponent<BattleFlank>();
return State.Flanks[index].GetComponent<BattleFlank>();
} }
public Zone Zone { public Zone Zone {
get => Zone.GetFromId(state.Zone);
get => Zone.GetFromId(State.Zone);
set { set {
state.Zone = Zone.GetZoneId(value);
State.Zone = Zone.GetZoneId(value);
transform.position = value.transform.position; transform.position = value.transform.position;
} }
} }
@ -59,10 +59,10 @@ namespace GWConquest
public override void Attached() public override void Attached()
{ {
FormationList = new EntityList(state, "FormationList");
FormationList = new EntityList(State, "FormationList");
state.AddCallback("Zone", () => {
if(state.Zone != -1)
State.AddCallback("Zone", () => {
if(State.Zone != -1)
{ {
Zone.CurrentBattle = this; Zone.CurrentBattle = this;
} }
@ -79,13 +79,13 @@ namespace GWConquest
} }
public void Init() { public void Init() {
state.FlankCount = Zone.zoneType == ZoneType.Ground ? 6 : 2;
State.FlankCount = Zone.zoneType == ZoneType.Ground ? 6 : 2;
int maxUnitPerFlank = Zone.zoneType == ZoneType.Ground ? 9 : 30; int maxUnitPerFlank = Zone.zoneType == ZoneType.Ground ? 9 : 30;
var allPlayers = AllPlayers.ToList(); var allPlayers = AllPlayers.ToList();
if(allPlayers.Count() >= 2) if(allPlayers.Count() >= 2)
{ {
for(int i = 0; i < state.FlankCount; i += 2)
for(int i = 0; i < State.FlankCount; i += 2)
{ {
var flank1 = InstantiateNewFlank(maxUnitPerFlank); var flank1 = InstantiateNewFlank(maxUnitPerFlank);
var flank2 = InstantiateNewFlank(maxUnitPerFlank); var flank2 = InstantiateNewFlank(maxUnitPerFlank);


+ 17
- 17
Assets/GWConquest/Scripts/BattleFlank.cs View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace GWConquest { namespace GWConquest {
public class BattleFlank : Bolt.EntityBehaviour<IBattleFlankState>
public class BattleFlank : GWBoltBehaviour<IBattleFlankState>
{ {
public const int SlotsPerRow = 3; public const int SlotsPerRow = 3;
@ -12,51 +12,51 @@ namespace GWConquest {
public BattleFlankUI CurrentUI; public BattleFlankUI CurrentUI;
public Battle Battle { public Battle Battle {
get => state.Battle?.GetComponent<Battle>();
set => state.Battle = value?.entity;
get => State.Battle?.GetComponent<Battle>();
set => State.Battle = value?.entity;
} }
public bool IsSpace => Battle.IsSpaceBattle; public bool IsSpace => Battle.IsSpaceBattle;
public int MaxUnitCount { public int MaxUnitCount {
get => state.MaxUnitCount;
set => state.MaxUnitCount = value;
get => State.MaxUnitCount;
set => State.MaxUnitCount = value;
} }
public BattleFlank OpposingFlank { public BattleFlank OpposingFlank {
get => state.OpposingFlank?.GetComponent<BattleFlank>();
set => state.OpposingFlank = value?.entity;
get => State.OpposingFlank?.GetComponent<BattleFlank>();
set => State.OpposingFlank = value?.entity;
} }
public Player Player { public Player Player {
get => state.Player?.GetComponent<Player>();
set => state.Player = value?.entity;
get => State.Player?.GetComponent<Player>();
set => State.Player = value?.entity;
} }
public Unit GetUnit(int index) { public Unit GetUnit(int index) {
return state.Units[index]?.GetComponent<Unit>();
return State.Units[index]?.GetComponent<Unit>();
} }
public void SetUnit(int index, Unit unit) public void SetUnit(int index, Unit unit)
{ {
state.Units[index] = unit?.entity;
State.Units[index] = unit?.entity;
} }
public float GetDeathCooldown(int index) public float GetDeathCooldown(int index)
{ {
return state.DeathCooldowns[index];
return State.DeathCooldowns[index];
} }
public void SetDeathCooldown(int index, float cooldown) public void SetDeathCooldown(int index, float cooldown)
{ {
state.DeathCooldowns[index] = cooldown;
State.DeathCooldowns[index] = cooldown;
} }
public int GetUnitIndex(Unit unit) public int GetUnitIndex(Unit unit)
{ {
for(int i = 0; i < state.MaxUnitCount; i++)
for(int i = 0; i < State.MaxUnitCount; i++)
{ {
if(state.Units[i] == unit.entity)
if(State.Units[i] == unit.entity)
{ {
return i; return i;
} }
@ -90,7 +90,7 @@ namespace GWConquest {
public IEnumerable<Unit> Units { public IEnumerable<Unit> Units {
get { get {
return state.Units.Where(e => e != null).Select((e,i) => e.GetComponent<Unit>());
return State.Units.Where(e => e != null).Select((e,i) => e.GetComponent<Unit>());
} }
} }
@ -100,7 +100,7 @@ namespace GWConquest {
{ {
if(GetDeathCooldown(i) > 0) if(GetDeathCooldown(i) > 0)
{ {
state.DeathCooldowns[i] -= BoltNetwork.FrameDeltaTime;
State.DeathCooldowns[i] -= BoltNetwork.FrameDeltaTime;
if(GetDeathCooldown(i) <= 0) if(GetDeathCooldown(i) <= 0)
{ {
var unit = GetUnit(i); var unit = GetUnit(i);


+ 12
- 12
Assets/GWConquest/Scripts/District.cs View File

@ -2,7 +2,7 @@
namespace GWConquest namespace GWConquest
{ {
public class District : Bolt.EntityBehaviour<IDistrictState>
public class District : GWBoltBehaviour<IDistrictState>
{ {
public Sprite DefaultSprite; public Sprite DefaultSprite;
public string DistrictName; public string DistrictName;
@ -18,23 +18,23 @@ namespace GWConquest
public Player ControllingPlayer { public Player ControllingPlayer {
get { get {
if(state.ControllingPlayerId == -1)
if(State.ControllingPlayerId == -1)
{ {
return null; return null;
} }
else else
{ {
return Player.PlayerList[state.ControllingPlayerId];
return Player.PlayerList[State.ControllingPlayerId];
} }
} }
set { set {
if(value == null) if(value == null)
{ {
state.ControllingPlayerId = -1;
State.ControllingPlayerId = -1;
} }
else { else {
state.ControllingPlayerId = value.PlayerId;
State.ControllingPlayerId = value.PlayerId;
} }
} }
} }
@ -42,16 +42,16 @@ namespace GWConquest
public Inventory Inventory; public Inventory Inventory;
public int StorageCapacity { public int StorageCapacity {
get => state.StorageCapacity;
set => state.StorageCapacity = value;
get => State.StorageCapacity;
set => State.StorageCapacity = value;
} }
public override void Attached() public override void Attached()
{ {
StorageCapacity = GameManager.Instance.DefaultStorageCapacity; StorageCapacity = GameManager.Instance.DefaultStorageCapacity;
Inventory = new Inventory(state, "Inventory");
Inventory = new Inventory(State, "Inventory");
Inventory.StorageCapacity = StorageCapacity; Inventory.StorageCapacity = StorageCapacity;
state.ControllingPlayerId = -1;
State.ControllingPlayerId = -1;
} }
public void Initialize(Planet _planet) public void Initialize(Planet _planet)
@ -115,7 +115,7 @@ namespace GWConquest
bool producesCredits = DistrictType == DistrictType.Civil && ControllingPlayer != null; bool producesCredits = DistrictType == DistrictType.Civil && ControllingPlayer != null;
if(producingItem != null || producesCredits) { if(producingItem != null || producesCredits) {
if(state.ItemProductionCooldown <= 0f)
if(State.ItemProductionCooldown <= 0f)
{ {
if(producingItem != null) if(producingItem != null)
{ {
@ -127,10 +127,10 @@ namespace GWConquest
ControllingPlayer.Credits++; ControllingPlayer.Credits++;
} }
state.ItemProductionCooldown = ProducingCooldown;
State.ItemProductionCooldown = ProducingCooldown;
} }
else { else {
state.ItemProductionCooldown -= BoltNetwork.FrameDeltaTime;
State.ItemProductionCooldown -= BoltNetwork.FrameDeltaTime;
} }
} }
} }


+ 21
- 21
Assets/GWConquest/Scripts/DistrictFactory.cs View File

@ -4,7 +4,7 @@ using System.Linq;
namespace GWConquest namespace GWConquest
{ {
public class DistrictFactory : Bolt.EntityBehaviour<IFactoryState>
public class DistrictFactory : GWBoltBehaviour<IFactoryState>
{ {
public int Tier = 1; public int Tier = 1;
public FactoryType FactoryType; public FactoryType FactoryType;
@ -22,7 +22,7 @@ namespace GWConquest
{ {
get get
{ {
return state.ProductionQueue.Length;
return State.ProductionQueue.Length;
} }
} }
@ -32,7 +32,7 @@ namespace GWConquest
{ {
for(int i = 0; i < MaxQueueLength; i++) for(int i = 0; i < MaxQueueLength; i++)
{ {
if(Util.IsStringEmpty(state.ProductionQueue[i].UnitClass))
if(Util.IsStringEmpty(State.ProductionQueue[i].UnitClass))
{ {
return i; return i;
} }
@ -45,18 +45,18 @@ namespace GWConquest
{ {
get get
{ {
return !Util.IsStringEmpty(state.ProductionQueue[0].UnitClass);
return !Util.IsStringEmpty(State.ProductionQueue[0].UnitClass);
} }
} }
public UnitClass GetProductionQueueEntry(int i) public UnitClass GetProductionQueueEntry(int i)
{ {
return UnitClass.FromName(state.ProductionQueue[i].UnitClass);
return UnitClass.FromName(State.ProductionQueue[i].UnitClass);
} }
public float GetProductionTime(int i) public float GetProductionTime(int i)
{ {
return state.ProductionQueue[i].TimeProduced;
return State.ProductionQueue[i].TimeProduced;
} }
public float GetProductionPercentage(int i) public float GetProductionPercentage(int i)
@ -73,26 +73,26 @@ namespace GWConquest
{ {
if(index == MaxQueueLength - 1) if(index == MaxQueueLength - 1)
{ {
state.ProductionQueue[index].UnitClass = null;
state.ProductionQueue[index].TimeProduced = 0f;
state.ProductionQueue[index].Player = null;
State.ProductionQueue[index].UnitClass = null;
State.ProductionQueue[index].TimeProduced = 0f;
State.ProductionQueue[index].Player = null;
} }
else else
{ {
for (int i = index; i < MaxQueueLength - 1; i++) for (int i = index; i < MaxQueueLength - 1; i++)
{ {
var nextEntry = state.ProductionQueue[i + 1];
state.ProductionQueue[i].UnitClass = nextEntry.UnitClass;
state.ProductionQueue[i].TimeProduced = nextEntry.TimeProduced;
state.ProductionQueue[i].Player = nextEntry.Player;
var nextEntry = State.ProductionQueue[i + 1];
State.ProductionQueue[i].UnitClass = nextEntry.UnitClass;
State.ProductionQueue[i].TimeProduced = nextEntry.TimeProduced;
State.ProductionQueue[i].Player = nextEntry.Player;
if (Util.IsStringEmpty(nextEntry.UnitClass)) if (Util.IsStringEmpty(nextEntry.UnitClass))
{ {
return; return;
} }
} }
state.ProductionQueue[MaxQueueLength - 1].UnitClass = null;
state.ProductionQueue[MaxQueueLength - 1].TimeProduced = 0f;
state.ProductionQueue[MaxQueueLength - 1].Player = null;
State.ProductionQueue[MaxQueueLength - 1].UnitClass = null;
State.ProductionQueue[MaxQueueLength - 1].TimeProduced = 0f;
State.ProductionQueue[MaxQueueLength - 1].Player = null;
} }
} }
@ -103,9 +103,9 @@ namespace GWConquest
if(length < MaxQueueLength) if(length < MaxQueueLength)
{ {
BoltLog.Info("Adding unit {0} to production queue on district {1}", uc, gameObject.name); BoltLog.Info("Adding unit {0} to production queue on district {1}", uc, gameObject.name);
state.ProductionQueue[length].UnitClass = uc;
state.ProductionQueue[length].TimeProduced = 0f;
state.ProductionQueue[length].Player = player.entity;
State.ProductionQueue[length].UnitClass = uc;
State.ProductionQueue[length].TimeProduced = 0f;
State.ProductionQueue[length].Player = player.entity;
} }
} }
@ -115,14 +115,14 @@ namespace GWConquest
{ {
if(IsProducing) if(IsProducing)
{ {
state.ProductionQueue[0].TimeProduced += BoltNetwork.FrameDeltaTime;
State.ProductionQueue[0].TimeProduced += BoltNetwork.FrameDeltaTime;
UnitClass uc = GetProductionQueueEntry(0); UnitClass uc = GetProductionQueueEntry(0);
if (GetProductionTime(0) >= uc.BuildTime) if (GetProductionTime(0) >= uc.BuildTime)
{ {
Zone zone = GetComponent<Zone>(); Zone zone = GetComponent<Zone>();
if(zone != null) if(zone != null)
{ {
Unit.SpawnUnit(zone, uc, state.ProductionQueue[0].Player.GetComponent<Player>());
Unit.SpawnUnit(zone, uc, State.ProductionQueue[0].Player.GetComponent<Player>());
} }
else else
{ {


+ 56
- 56
Assets/GWConquest/Scripts/Formation.cs View File

@ -6,25 +6,25 @@ using System.Collections;
namespace GWConquest namespace GWConquest
{ {
public class Formation : Bolt.EntityBehaviour<IFormationState>, IMovable<Zone>
public class Formation : GWBoltBehaviour<IFormationState>, IMovable<Zone>
{ {
private Zone lastZone; private Zone lastZone;
public Zone currentZone public Zone currentZone
{ {
get get
{ {
return Zone.GetFromId(state.CurrentZone);
return Zone.GetFromId(State.CurrentZone);
} }
set set
{ {
state.CurrentZone = Zone.GetZoneId(value);
State.CurrentZone = Zone.GetZoneId(value);
OnZoneChanged(); OnZoneChanged();
} }
} }
private void OnZoneChanged() private void OnZoneChanged()
{ {
Zone newZone = Zone.GetFromId(state.CurrentZone);
Zone newZone = Zone.GetFromId(State.CurrentZone);
if(lastZone != newZone) if(lastZone != newZone)
{ {
if(lastZone != null) if(lastZone != null)
@ -42,27 +42,27 @@ namespace GWConquest
} }
public ZoneType ZoneType { public ZoneType ZoneType {
get => state.IsSpace ? ZoneType.Space : ZoneType.Ground;
set => state.IsSpace = value == ZoneType.Space;
get => State.IsSpace ? ZoneType.Space : ZoneType.Ground;
set => State.IsSpace = value == ZoneType.Space;
} }
public Player Player public Player Player
{ {
get get
{ {
return state.Player?.GetComponent<Player>();
return State.Player?.GetComponent<Player>();
} }
set set
{ {
state.Player = value.entity;
State.Player = value.entity;
} }
} }
public string FormationName public string FormationName
{ {
get => state.FormationName;
get => State.FormationName;
set { set {
state.FormationName = value;
State.FormationName = value;
keepFormationName = true; keepFormationName = true;
} }
} }
@ -82,8 +82,8 @@ namespace GWConquest
public Unit HeroUnit public Unit HeroUnit
{ {
get => state.HeroUnit?.GetComponent<Unit>();
set => state.HeroUnit = value.entity;
get => State.HeroUnit?.GetComponent<Unit>();
set => State.HeroUnit = value.entity;
} }
public IEnumerable<ItemStack> AllItems public IEnumerable<ItemStack> AllItems
@ -99,18 +99,18 @@ namespace GWConquest
public ZoneList PathQueue; public ZoneList PathQueue;
public Formation MovementTargetFormation { public Formation MovementTargetFormation {
get => state.MovementTargetFormation?.GetComponent<Formation>();
set => state.MovementTargetFormation = value?.entity;
get => State.MovementTargetFormation?.GetComponent<Formation>();
set => State.MovementTargetFormation = value?.entity;
} }
public bool IsEmbarked { public bool IsEmbarked {
get => state.IsEmbarked;
set => state.IsEmbarked = value;
get => State.IsEmbarked;
set => State.IsEmbarked = value;
} }
public Formation ParentFormation { public Formation ParentFormation {
get => state.ParentFormation?.GetComponent<Formation>();
set => state.ParentFormation = value?.entity;
get => State.ParentFormation?.GetComponent<Formation>();
set => State.ParentFormation = value?.entity;
} }
public GameObject fleetIcon; public GameObject fleetIcon;
@ -128,12 +128,12 @@ namespace GWConquest
public bool CanMove public bool CanMove
{ {
get => !state.IsInTransit;
get => !State.IsInTransit;
} }
public void TryMoveToPlanet(Planet planet) public void TryMoveToPlanet(Planet planet)
{ {
if(entity.IsControlled && !state.IsInTransit
if(entity.IsControlled && !State.IsInTransit
&& currentZone.planet.IsConnectedTo(planet)) && currentZone.planet.IsConnectedTo(planet))
{ {
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer); MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer);
@ -144,13 +144,13 @@ namespace GWConquest
else else
{ {
BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2}) to planet {3}", BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2}) to planet {3}",
this, entity.IsControlled, state.IsInTransit, planet);
this, entity.IsControlled, State.IsInTransit, planet);
} }
} }
public void StartMovingOnPath(List<Zone> path, Formation targetFormation=null) public void StartMovingOnPath(List<Zone> path, Formation targetFormation=null)
{ {
if (path.Count > 1 && entity.IsControlled && !state.IsInTransit)
if (path.Count > 1 && entity.IsControlled && !State.IsInTransit)
{ {
MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer); MoveFormationEvent evnt = MoveFormationEvent.Create(Bolt.GlobalTargets.OnlyServer);
@ -172,13 +172,13 @@ namespace GWConquest
else else
{ {
BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2})", BoltLog.Info("Could not move formation {0} (controlled: {1}, in transit: {2})",
this, entity.IsControlled, state.IsInTransit);
this, entity.IsControlled, State.IsInTransit);
} }
} }
public void MoveToZone(Zone target) public void MoveToZone(Zone target)
{ {
if(entity.IsOwner && !state.IsInTransit)
if(entity.IsOwner && !State.IsInTransit)
{ {
if(IsEmbarked) if(IsEmbarked)
{ {
@ -188,8 +188,8 @@ namespace GWConquest
} }
} }
state.CurrentTransition.OriginZone = Zone.GetZoneId(currentZone);
state.CurrentTransition.TargetZone = Zone.GetZoneId(target);
State.CurrentTransition.OriginZone = Zone.GetZoneId(currentZone);
State.CurrentTransition.TargetZone = Zone.GetZoneId(target);
bool isGroundTransition = target.zoneType == ZoneType.Ground || currentZone.zoneType == ZoneType.Ground; bool isGroundTransition = target.zoneType == ZoneType.Ground || currentZone.zoneType == ZoneType.Ground;
//float lengthFactor = isGroundTransition ? GameManager.Instance.GroundTransitionLengthFactor : GameManager.Instance.SpaceTransitionLengthFactor; //float lengthFactor = isGroundTransition ? GameManager.Instance.GroundTransitionLengthFactor : GameManager.Instance.SpaceTransitionLengthFactor;
float lengthFactor; float lengthFactor;
@ -212,29 +212,29 @@ namespace GWConquest
lengthFactor = GameManager.Instance.SpaceTransitionLengthFactor; lengthFactor = GameManager.Instance.SpaceTransitionLengthFactor;
} }
} }
state.CurrentTransition.TransitionLength
State.CurrentTransition.TransitionLength
= Vector3.Distance(currentZone.transform.position, target.transform.position) * lengthFactor; = Vector3.Distance(currentZone.transform.position, target.transform.position) * lengthFactor;
state.CurrentTransition.IsCurved = isGroundTransition;
State.CurrentTransition.IsCurved = isGroundTransition;
CoveredDistance = 0; CoveredDistance = 0;
currentZone = null; currentZone = null;
state.IsInTransit = true;
State.IsInTransit = true;
} }
else else
{ {
BoltLog.Warn("Ignoring MoveFormationEvent on {0} (in transit: {1})", this, state.IsInTransit);
BoltLog.Warn("Ignoring MoveFormationEvent on {0} (in transit: {1})", this, State.IsInTransit);
} }
} }
private void OnTransitStateChanged() private void OnTransitStateChanged()
{ {
animDistanceCovered = 0; animDistanceCovered = 0;
if(state.IsInTransit)
if(State.IsInTransit)
{ {
var originZone = Zone.GetFromId(state.CurrentTransition.OriginZone);
var targetZone = Zone.GetFromId(state.CurrentTransition.TargetZone);
var originZone = Zone.GetFromId(State.CurrentTransition.OriginZone);
var targetZone = Zone.GetFromId(State.CurrentTransition.TargetZone);
if(state.CurrentTransition.IsCurved) {
if(State.CurrentTransition.IsCurved) {
movingArmyIcon = Instantiate(movingArmyPrefab); movingArmyIcon = Instantiate(movingArmyPrefab);
movingArmyIcon.transform.SetParent(FindObjectOfType<IngameUI>().PlanetView.DistrictIcons); movingArmyIcon.transform.SetParent(FindObjectOfType<IngameUI>().PlanetView.DistrictIcons);
movingArmyIcon.transform.localRotation = Quaternion.identity; movingArmyIcon.transform.localRotation = Quaternion.identity;
@ -294,18 +294,18 @@ namespace GWConquest
IsEmbarked = false; IsEmbarked = false;
} }
} }
if(state.IsInTransit)
if(State.IsInTransit)
{ {
CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime; CoveredDistance += movementSpeed * BoltNetwork.FrameDeltaTime;
if (CoveredDistance >= state.CurrentTransition.TransitionLength)
if (CoveredDistance >= State.CurrentTransition.TransitionLength)
{ {
currentZone = Zone.GetFromId(state.CurrentTransition.TargetZone);
state.CurrentTransition.OriginZone = -1;
state.CurrentTransition.TargetZone = -1;
state.CurrentTransition.TransitionLength = 0;
currentZone = Zone.GetFromId(State.CurrentTransition.TargetZone);
State.CurrentTransition.OriginZone = -1;
State.CurrentTransition.TargetZone = -1;
State.CurrentTransition.TransitionLength = 0;
CoveredDistance = 0; CoveredDistance = 0;
state.IsInTransit = false;
State.IsInTransit = false;
if(PathQueue.Count > 0) if(PathQueue.Count > 0)
{ {
@ -354,24 +354,24 @@ namespace GWConquest
private void Update() private void Update()
{ {
//Debug.LogFormat("Current state: IsInTransit {0}; CurrentZone {1}; CoveredDistance {2}", state.IsInTransit, state.CurrentZone, CoveredDistance);
//Debug.LogFormat("Current state: IsInTransit {0}; CurrentZone {1}; CoveredDistance {2}", State.IsInTransit, State.CurrentZone, CoveredDistance);
if (state.IsInTransit)
if (State.IsInTransit)
{ {
animDistanceCovered += movementSpeed * Time.deltaTime; animDistanceCovered += movementSpeed * Time.deltaTime;
Zone originZone = Zone.GetFromId(state.CurrentTransition.OriginZone);
Zone targetZone = Zone.GetFromId(state.CurrentTransition.TargetZone);
Zone originZone = Zone.GetFromId(State.CurrentTransition.OriginZone);
Zone targetZone = Zone.GetFromId(State.CurrentTransition.TargetZone);
Vector3 oldPos = transform.position; Vector3 oldPos = transform.position;
Vector3 newPos; Vector3 newPos;
Quaternion newRot; Quaternion newRot;
//if(state.CurrentTransition.IsCurved)
//if(State.CurrentTransition.IsCurved)
//{ //{
Vector3 planetPos = targetZone.planet.transform.position; Vector3 planetPos = targetZone.planet.transform.position;
Vector3 originPos = originZone.transform.position - planetPos; Vector3 originPos = originZone.transform.position - planetPos;
Vector3 targetPos = targetZone.transform.position - planetPos; Vector3 targetPos = targetZone.transform.position - planetPos;
newPos = Vector3.Slerp(originPos, targetPos, newPos = Vector3.Slerp(originPos, targetPos,
animDistanceCovered / state.CurrentTransition.TransitionLength);
animDistanceCovered / State.CurrentTransition.TransitionLength);
newPos += planetPos; newPos += planetPos;
newRot = Quaternion.LookRotation(newPos - oldPos, newPos - planetPos); newRot = Quaternion.LookRotation(newPos - oldPos, newPos - planetPos);
//} //}
@ -379,7 +379,7 @@ namespace GWConquest
//{ //{
newPos = Vector3.Lerp(originZone.transform.position, newPos = Vector3.Lerp(originZone.transform.position,
targetZone.transform.position, targetZone.transform.position,
animDistanceCovered / state.CurrentTransition.TransitionLength);
animDistanceCovered / State.CurrentTransition.TransitionLength);
newRot = Quaternion.LookRotation(newPos - oldPos, Vector3.up); newRot = Quaternion.LookRotation(newPos - oldPos, Vector3.up);
//} //}
@ -396,23 +396,23 @@ namespace GWConquest
public override void Attached() public override void Attached()
{ {
BoltLog.Info("Formation attached: {0}", this); BoltLog.Info("Formation attached: {0}", this);
UnitEntities = new EntityList(state, "Units");
SubFormationEntities = new EntityList(state, "SubFormations");
UnitEntities = new EntityList(State, "Units");
SubFormationEntities = new EntityList(State, "SubFormations");
PathQueue = new ZoneList(state, "PathQueue");
PathQueue = new ZoneList(State, "PathQueue");
if(entity.IsOwner) if(entity.IsOwner)
{ {
state.CurrentZone = -1;
state.IsInTransit = false;
State.CurrentZone = -1;
State.IsInTransit = false;
CoveredDistance = 0; CoveredDistance = 0;
formationNumber = UnityEngine.Random.Range(1, 100); formationNumber = UnityEngine.Random.Range(1, 100);
} }
state.AddCallback("IsInTransit", OnTransitStateChanged);
state.AddCallback("CurrentZone", OnZoneChanged);
State.AddCallback("IsInTransit", OnTransitStateChanged);
State.AddCallback("CurrentZone", OnZoneChanged);
} }
@ -563,7 +563,7 @@ namespace GWConquest
} }
} }
state.FormationName = name;
State.FormationName = name;
} }


+ 18
- 0
Assets/GWConquest/Scripts/GWBoltBehaviour.cs View File

@ -0,0 +1,18 @@
using Bolt;
namespace GWConquest {
public abstract class GWBoltBehaviour<T> : EntityBehaviour<T> where T : class, IState
{
private T _state = null;
public T State {
get {
if(_state == null)
{
_state = state;
}
return _state;
}
}
}
}

+ 11
- 0
Assets/GWConquest/Scripts/GWBoltBehaviour.cs.meta View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f48b9c6bc6be7154e809c78208e38787
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 11
- 11
Assets/GWConquest/Scripts/Player.cs View File

@ -4,7 +4,7 @@ using System.Linq;
namespace GWConquest namespace GWConquest
{ {
public class Player : Bolt.EntityBehaviour<IPlayerState>
public class Player : GWBoltBehaviour<IPlayerState>
{ {
public static List<Player> PlayerList = new List<Player>(); public static List<Player> PlayerList = new List<Player>();
@ -12,7 +12,7 @@ namespace GWConquest
public Faction Faction public Faction Faction
{ {
get => GameManager.Instance.Factions[state.FactionIndex];
get => GameManager.Instance.Factions[State.FactionIndex];
} }
public Color Color public Color Color
@ -22,13 +22,13 @@ namespace GWConquest
public int Credits public int Credits
{ {
get => state.Credits;
set => state.Credits = value;
get => State.Credits;
set => State.Credits = value;
} }
public int PlayerId public int PlayerId
{ {
get => state.PlayerId;
get => State.PlayerId;
} }
public override void Attached() public override void Attached()
@ -37,7 +37,7 @@ namespace GWConquest
PlayerList.Add(this); PlayerList.Add(this);
if(entity.IsOwner) if(entity.IsOwner)
{ {
state.PlayerId = PlayerList.IndexOf(this);
State.PlayerId = PlayerList.IndexOf(this);
} }
} }
@ -49,31 +49,31 @@ namespace GWConquest
public override void ControlGained() public override void ControlGained()
{ {
CurrentPlayer = this; CurrentPlayer = this;
BoltLog.Info("Current player is {0} with connection ID {1}", this, state.ConnectionId);
BoltLog.Info("Current player is {0} with connection ID {1}", this, State.ConnectionId);
} }
public BoltConnection Connection public BoltConnection Connection
{ {
get get
{ {
if(state.IsAI || state.IsHost)
if(State.IsAI || State.IsHost)
{ {
return null; return null;
} }
else else
{ {
return BoltNetwork.Connections.FirstOrDefault(conn => conn.ConnectionId == state.ConnectionId);
return BoltNetwork.Connections.FirstOrDefault(conn => conn.ConnectionId == State.ConnectionId);
} }
} }
} }
public void AssignControl(BoltEntity entity) public void AssignControl(BoltEntity entity)
{ {
if(state.IsHost)
if(State.IsHost)
{ {
entity.TakeControl(); entity.TakeControl();
} }
else if(!state.IsAI)
else if(!State.IsAI)
{ {
entity.AssignControl(Connection); entity.AssignControl(Connection);
} }


Loading…
Cancel
Save