Browse Source

fix memory leaks

master
laurids 5 months ago
parent
commit
a3a1a8de20
8 changed files with 64 additions and 16 deletions
  1. +8
    -2
      Assets/GWConquest/Scripts/Battle.cs
  2. +8
    -2
      Assets/GWConquest/Scripts/BattleFlank.cs
  3. +10
    -3
      Assets/GWConquest/Scripts/District.cs
  4. +6
    -1
      Assets/GWConquest/Scripts/DistrictFactory.cs
  5. +10
    -3
      Assets/GWConquest/Scripts/Formation.cs
  6. +6
    -1
      Assets/GWConquest/Scripts/Planet.cs
  7. +8
    -2
      Assets/GWConquest/Scripts/Player.cs
  8. +8
    -2
      Assets/GWConquest/Scripts/Unit.cs

+ 8
- 2
Assets/GWConquest/Scripts/Battle.cs View File

@ -8,10 +8,10 @@ namespace GWConquest
{
public class Battle : NetworkBehaviour
{
private GWNetworkList<NetworkBehaviourReference> formations = new GWNetworkList<NetworkBehaviourReference>();
private GWNetworkList<NetworkBehaviourReference> formations;
private NetworkVariable<int> zoneID = new NetworkVariable<int>();
private NetworkVariable<FixedString128Bytes> battleName = new NetworkVariable<FixedString128Bytes>();
private GWNetworkList<NullableNetworkBehaviourReference> flanks = new GWNetworkList<NullableNetworkBehaviourReference>();
private GWNetworkList<NullableNetworkBehaviourReference> flanks;
private NetworkVariable<int> flankCount = new NetworkVariable<int>();
private NetworkVariable<int> victorID = new NetworkVariable<int>();
private NetworkVariable<float> phaseCooldown = new NetworkVariable<float>();
@ -171,6 +171,12 @@ namespace GWConquest
base.OnNetworkSpawn();
}
private void Awake()
{
formations = new();
flanks = new();
}
private BattleFlank InstantiateNewFlank(int maxUnitCount, int rowCount)
{
GameObject go = Instantiate(BattleFlankPrefab);


+ 8
- 2
Assets/GWConquest/Scripts/BattleFlank.cs View File

@ -13,8 +13,8 @@ namespace GWConquest
private NetworkVariable<ushort> flankID = new NetworkVariable<ushort>();
private NetworkVariable<int> maxUnitCount = new NetworkVariable<int>();
private NetworkVariable<int> rowCount = new NetworkVariable<int>();
private GWNetworkList<NullableNetworkBehaviourReference> units = new GWNetworkList<NullableNetworkBehaviourReference>();
private GWNetworkList<float> deathCooldowns = new GWNetworkList<float>();
private GWNetworkList<NullableNetworkBehaviourReference> units;
private GWNetworkList<float> deathCooldowns;
private NetworkVariable<float> defenderStartingCols = new();
private NetworkVariable<float> attackerStartingCols = new();
@ -68,6 +68,12 @@ namespace GWConquest
defenderStartingCols.Value = _defenderStartingCols;
}
private void Awake()
{
units = new();
deathCooldowns = new();
}
public Unit GetUnit(int index)
{
return units[index].GetBehaviour<Unit>();


+ 10
- 3
Assets/GWConquest/Scripts/District.cs View File

@ -13,7 +13,7 @@ namespace GWConquest
private NetworkVariable<int> storageCapacity = new NetworkVariable<int>();
private NetworkVariable<int> controllingPlayerID = new NetworkVariable<int>();
public Inventory Inventory = new Inventory();
public Inventory Inventory;
private NetworkVariable<float> itemProductionCooldown = new NetworkVariable<float>();
private NetworkVariable<int> zoneID = new NetworkVariable<int>();
private NetworkVariable<NetworkBehaviourReference> planet = new NetworkVariable<NetworkBehaviourReference>();
@ -21,8 +21,8 @@ namespace GWConquest
private NetworkVariable<DistrictType> districtType = new NetworkVariable<DistrictType>();
private NetworkVariable<FixedString128Bytes> districtName = new NetworkVariable<FixedString128Bytes>();
private NetworkVariable<Vector3> relativePosition = new NetworkVariable<Vector3>();
private GWNetworkList<NetworkBehaviourReference> connectedDistricts = new GWNetworkList<NetworkBehaviourReference>();
private GWNetworkList<ushort> upgrades = new GWNetworkList<ushort>();
private GWNetworkList<NetworkBehaviourReference> connectedDistricts;
private GWNetworkList<ushort> upgrades;
private NetworkVariable<float> captureCooldown = new NetworkVariable<float>();
public bool DistrictStatic;
@ -98,6 +98,13 @@ namespace GWConquest
get => captureCooldown.Value;
}
void Awake()
{
connectedDistricts = new();
upgrades = new();
Inventory = new();
}
public override void OnNetworkSpawn()
{


+ 6
- 1
Assets/GWConquest/Scripts/DistrictFactory.cs View File

@ -39,7 +39,7 @@ namespace GWConquest
}
public class DistrictFactory : NetworkBehaviour
{
public GWNetworkList<ProductionQueueEntry> productionQueue = new GWNetworkList<ProductionQueueEntry>();
public GWNetworkList<ProductionQueueEntry> productionQueue;
public bool StartsBroken = false;
public string[] SpecialUnits;
@ -83,6 +83,11 @@ namespace GWConquest
}
}
private void Awake()
{
productionQueue = new();
}
public IBuildable GetProductionQueueEntry(int i)
{
if (productionQueue[i].IsUpgrade)


+ 10
- 3
Assets/GWConquest/Scripts/Formation.cs View File

@ -33,10 +33,10 @@ namespace GWConquest
private NetworkVariable<bool> isSpace = new NetworkVariable<bool>();
private NetworkVariable<Transition> currentTransition = new NetworkVariable<Transition>();
private NetworkVariable<NetworkBehaviourReference> player = new NetworkVariable<NetworkBehaviourReference>();
private GWNetworkList<NetworkBehaviourReference> units = new GWNetworkList<NetworkBehaviourReference>();
private GWNetworkList<int> pathQueue = new GWNetworkList<int>();
private GWNetworkList<NetworkBehaviourReference> units;
private GWNetworkList<int> pathQueue;
private NetworkVariable<NullableNetworkBehaviourReference> heroUnit = new NetworkVariable<NullableNetworkBehaviourReference>();
private GWNetworkList<NetworkBehaviourReference> subFormations = new GWNetworkList<NetworkBehaviourReference>();
private GWNetworkList<NetworkBehaviourReference> subFormations;
private NetworkVariable<FixedString128Bytes> formationName = new NetworkVariable<FixedString128Bytes>();
private NetworkVariable<int> formationNumber = new NetworkVariable<int>();
private NetworkVariable<NullableNetworkBehaviourReference> movementTargetFormation = new NetworkVariable<NullableNetworkBehaviourReference>();
@ -270,6 +270,13 @@ namespace GWConquest
public IInventory FormationInventory;
private void Awake()
{
units = new();
pathQueue = new();
subFormations = new();
}
public void TryMoveToPlanet(Planet planet)
{
if (currentZone.zoneType == ZoneType.Space)


+ 6
- 1
Assets/GWConquest/Scripts/Planet.cs View File

@ -35,7 +35,7 @@ namespace GWConquest
private NetworkVariable<FixedString128Bytes> planetNameVar = new NetworkVariable<FixedString128Bytes>();
private NetworkVariable<int> spaceZoneID = new NetworkVariable<int>();
private NetworkVariable<int> attackZoneID = new NetworkVariable<int>();
private GWNetworkList<NetworkBehaviourReference> connectedPlanets = new GWNetworkList<NetworkBehaviourReference>();
private GWNetworkList<NetworkBehaviourReference> connectedPlanets;
private NetworkVariable<ushort> planetPrefab = new NetworkVariable<ushort>();
private NetworkVariable<Quaternion> prefabRotation = new NetworkVariable<Quaternion>();
private NetworkVariable<float> prefabScale = new NetworkVariable<float>();
@ -153,6 +153,11 @@ namespace GWConquest
{
get => connectedPlanets.Select(r => r.GetBehaviour<Planet>());
}
private void Awake()
{
connectedPlanets = new();
}
public override void OnNetworkSpawn()
{


+ 8
- 2
Assets/GWConquest/Scripts/Player.cs View File

@ -13,8 +13,8 @@ namespace GWConquest
private NetworkVariable<ushort> factionIndex = new NetworkVariable<ushort>();
private NetworkVariable<bool> isAI = new NetworkVariable<bool>();
private NetworkVariable<int> credits = new NetworkVariable<int>();
private GWNetworkList<NetworkBehaviourReference> knownPlanetsList = new GWNetworkList<NetworkBehaviourReference>();
private GWNetworkList<NetworkBehaviourReference> visiblePlanetsList = new GWNetworkList<NetworkBehaviourReference>();
private GWNetworkList<NetworkBehaviourReference> knownPlanetsList;
private GWNetworkList<NetworkBehaviourReference> visiblePlanetsList;
public static List<Player> PlayerList = new List<Player>();
@ -59,6 +59,12 @@ namespace GWConquest
}
}
private void Awake()
{
knownPlanetsList = new();
visiblePlanetsList = new();
}
public override void OnNetworkSpawn()
{
Debug.Log("Attaching player...");


+ 8
- 2
Assets/GWConquest/Scripts/Unit.cs View File

@ -20,8 +20,8 @@ namespace GWConquest
private NetworkVariable<BattleUnitState> battleState = new NetworkVariable<BattleUnitState>();
private NetworkVariable<float> actionCooldown = new NetworkVariable<float>();
private NetworkVariable<float> actionCooldownMax = new NetworkVariable<float>();
private Inventory inventory = new Inventory();
private Inventory equipment = new Inventory();
private Inventory inventory;
private Inventory equipment;
private NetworkVariable<int> flankTarget = new NetworkVariable<int>();
private NetworkVariable<float> morale = new NetworkVariable<float>();
private NetworkVariable<int> supplies = new NetworkVariable<int>();
@ -255,6 +255,12 @@ namespace GWConquest
}
}
private void Awake()
{
inventory = new();
equipment = new();
}
public override void OnNetworkSpawn()
{
formation.OnValueChanged += OnFormationChanged;


Loading…
Cancel
Save