Only sync projectiles and future synced effects.

This commit is contained in:
Matthias Mailänder
2016-06-04 19:35:26 +02:00
parent 9def6b0f70
commit 71743b3b4a
11 changed files with 56 additions and 41 deletions

View File

@@ -14,6 +14,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
using OpenRA.FileFormats;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Network;
using OpenRA.Orders;
@@ -30,6 +31,8 @@ namespace OpenRA
internal readonly TraitDictionary TraitDict = new TraitDictionary();
readonly SortedDictionary<uint, Actor> actors = new SortedDictionary<uint, Actor>();
readonly List<IEffect> effects = new List<IEffect>();
readonly List<ISync> syncedEffects = new List<ISync>();
readonly Queue<Action<World>> frameEndActions = new Queue<Action<World>>();
public int Timestep;
@@ -272,9 +275,27 @@ namespace OpenRA
t.RemovedFromWorld(a);
}
public void Add(IEffect b) { effects.Add(b); }
public void Remove(IEffect b) { effects.Remove(b); }
public void RemoveAll(Predicate<IEffect> predicate) { effects.RemoveAll(predicate); }
public void Add(IEffect e)
{
effects.Add(e);
var se = e as ISync;
if (se != null)
syncedEffects.Add(se);
}
public void Remove(IEffect e)
{
effects.Remove(e);
var se = e as ISync;
if (se != null)
syncedEffects.Remove(se);
}
public void RemoveAll(Predicate<IEffect> predicate)
{
effects.RemoveAll(predicate);
syncedEffects.RemoveAll(e => predicate((IEffect)e));
}
public void AddFrameEndTask(Action<World> a) { frameEndActions.Enqueue(a); }
@@ -334,6 +355,7 @@ namespace OpenRA
public IEnumerable<Actor> Actors { get { return actors.Values; } }
public IEnumerable<IEffect> Effects { get { return effects; } }
public IEnumerable<ISync> SyncedEffects { get { return syncedEffects; } }
public Actor GetActorById(uint actorId)
{
@@ -356,24 +378,20 @@ namespace OpenRA
var n = 0;
var ret = 0;
// hash all the actors
// Hash all the actors.
foreach (var a in Actors)
ret += n++ * (int)(1 + a.ActorID) * Sync.HashActor(a);
// hash all the traits that tick
// Hash all the traits that tick.
foreach (var actor in ActorsHavingTrait<ISync>())
foreach (var syncHash in actor.SyncHashes)
ret += n++ * (int)(1 + actor.ActorID) * syncHash.Hash;
// TODO: don't go over all effects
foreach (var e in Effects)
{
var sync = e as ISync;
if (sync != null)
ret += n++ * Sync.Hash(sync);
}
// Hash game state relevant effects such as projectiles.
foreach (var sync in SyncedEffects)
ret += n++ * Sync.Hash(sync);
// Hash the shared rng
// Hash the shared random number generator.
ret += SharedRandom.Last;
return ret;