Ejemplo n.º 1
0
 protected virtual void TrackNewGroups()
 {
   this.firstAvailableVolumeId = IdentifierPool.FirstAvailable<Volume>(this.LevelManager.Volumes);
   this.enablingVolumes.Clear();
   this.trackedGroups.Clear();
   foreach (TrileGroup group in (IEnumerable<TrileGroup>) this.LevelManager.Groups.Values)
   {
     if (group.Path != null)
     {
       MovingGroupsHost.MovingGroupState movingGroupState = new MovingGroupsHost.MovingGroupState(group, false);
       this.trackedGroups.Add(movingGroupState);
       if (this.LevelManager.IsPathRecorded(group.Id) || this.LevelManager.WasPathSupposedToBeRecorded(group.Id))
         movingGroupState.MoveToEnd();
     }
   }
 }
Ejemplo n.º 2
0
    private void TrackGroupConnectivePath(int groupId)
    {
      Vector3 vector3_1 = FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint);
      Vector3 b = FezMath.Abs(FezMath.ForwardVector(this.CameraManager.Viewpoint));
      this.connectedAos.Clear();
      foreach (ArtObjectInstance artObjectInstance in this.LevelMaterializer.LevelArtObjects)
      {
        int? attachedGroup = artObjectInstance.ActorSettings.AttachedGroup;
        int num = groupId;
        if ((attachedGroup.GetValueOrDefault() != num ? 0 : (attachedGroup.HasValue ? 1 : 0)) != 0)
          this.connectedAos.Add(artObjectInstance);
      }
      foreach (ArtObjectInstance artObjectInstance1 in this.connectedAos)
      {
        if (artObjectInstance1.ActorSettings.NextNode.HasValue)
          artObjectInstance1.ActorSettings.NextNodeAo = this.LevelManager.ArtObjects[artObjectInstance1.ActorSettings.NextNode.Value];
        foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
        {
          if (artObjectInstance2.ActorSettings.NextNode.HasValue && artObjectInstance2.ActorSettings.NextNode.Value == artObjectInstance1.Id)
            artObjectInstance1.ActorSettings.PrecedingNodeAo = artObjectInstance2;
        }
      }
      TrileGroup group;
      if (!this.LevelManager.Groups.TryGetValue(groupId, out group))
      {
        Logger.Log("MovingGroupsHost::TrackGroupConnectivePath", LogSeverity.Warning, "Node is connected to a group that doesn't exist!");
      }
      else
      {
        if (group.MoveToEnd)
        {
          ArtObjectInstance artObjectInstance1 = (ArtObjectInstance) null;
          foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
          {
            if (!artObjectInstance2.ActorSettings.NextNode.HasValue && artObjectInstance2.ArtObject.ActorType == ActorType.ConnectiveRail)
            {
              artObjectInstance1 = artObjectInstance2;
              break;
            }
          }
          if (artObjectInstance1 == null)
            throw new InvalidOperationException("No end-node! Can't move to end.");
          Vector3 zero = Vector3.Zero;
          foreach (TrileInstance trileInstance in group.Triles)
            zero += trileInstance.Center;
          Vector3 vector3_2 = zero / (float) group.Triles.Count;
          Vector3 ordering = artObjectInstance1.Position - vector3_2;
          group.Triles.Sort((IComparer<TrileInstance>) new MovingTrileInstanceComparer(ordering));
          foreach (TrileInstance instance in group.Triles)
          {
            instance.Position += ordering;
            this.LevelManager.UpdateInstance(instance);
          }
        }
        BoundingBox boundingBox1 = new BoundingBox(new Vector3(float.MaxValue), new Vector3(float.MinValue));
        Vector3 zero1 = Vector3.Zero;
        foreach (TrileInstance trileInstance in group.Triles)
        {
          Vector3 vector3_2 = trileInstance.TransformedSize / 2f;
          boundingBox1.Min = Vector3.Min(boundingBox1.Min, (trileInstance.Center - vector3_2) * vector3_1);
          boundingBox1.Max = Vector3.Max(boundingBox1.Max, (trileInstance.Center + vector3_2) * vector3_1 + b);
          zero1 += trileInstance.Center;
        }
        Vector3 vector3_3 = zero1 / (float) group.Triles.Count;
        BoundingBox boundingBox2 = new BoundingBox();
        foreach (ArtObjectInstance artObjectInstance in this.connectedAos)
        {
          if (artObjectInstance.ArtObject.ActorType == ActorType.None)
          {
            Vector3 vector3_2 = artObjectInstance.Scale * artObjectInstance.ArtObject.Size / 2f;
            boundingBox2 = new BoundingBox(artObjectInstance.Position - vector3_2, artObjectInstance.Position + vector3_2);
            Quaternion rotation = artObjectInstance.Rotation;
            FezMath.RotateOnCenter(ref boundingBox2, ref rotation);
            boundingBox2.Min *= vector3_1;
            boundingBox2.Max = boundingBox2.Max * vector3_1 + b;
            if (boundingBox1.Intersects(boundingBox2))
              break;
          }
        }
        ArtObjectInstance artObjectInstance3 = (ArtObjectInstance) null;
        foreach (ArtObjectInstance artObjectInstance1 in this.connectedAos)
        {
          if (artObjectInstance1.ArtObject.ActorType == ActorType.ConnectiveRail)
          {
            Vector3 vector3_2 = artObjectInstance1.Scale * artObjectInstance1.ArtObject.Size / 2f;
            BoundingBox box = new BoundingBox((artObjectInstance1.Position - vector3_2) * vector3_1, (artObjectInstance1.Position + vector3_2) * vector3_1 + b);
            if (boundingBox2.Intersects(box))
            {
              artObjectInstance3 = artObjectInstance1;
              break;
            }
          }
        }
        if (artObjectInstance3 == null)
        {
          InvalidOperationException operationException = new InvalidOperationException("Nodeless branch!");
          Logger.Log("Connective Groups", LogSeverity.Warning, operationException.Message);
          throw operationException;
        }
        else
        {
          ArtObjectInstance artObjectInstance1;
          for (; artObjectInstance3.ActorSettings.PrecedingNodeAo != null; artObjectInstance3 = artObjectInstance3.ActorSettings.PrecedingNodeAo)
          {
            Vector3 a = artObjectInstance3.ActorSettings.PrecedingNodeAo.Position - artObjectInstance3.Position;
            if ((double) Math.Abs(FezMath.Dot(a, b)) <= (double) Math.Abs(FezMath.Dot(a, FezMath.XZMask - b)))
            {
              bool flag = false;
              Vector3 point = a / 2f + artObjectInstance3.Position;
              foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
              {
                if (artObjectInstance2.ArtObject.ActorType == ActorType.None)
                {
                  Vector3 vector3_2 = artObjectInstance2.Scale * artObjectInstance2.ArtObject.Size / 2f;
                  BoundingBox boundingBox3 = new BoundingBox(artObjectInstance2.Position - vector3_2, artObjectInstance2.Position + vector3_2);
                  Quaternion rotation = artObjectInstance2.Rotation;
                  FezMath.RotateOnCenter(ref boundingBox3, ref rotation);
                  if (boundingBox3.Contains(point) != ContainmentType.Disjoint)
                  {
                    flag = true;
                    break;
                  }
                }
              }
              if (!flag)
              {
                artObjectInstance1 = artObjectInstance3;
                goto label_72;
              }
            }
          }
          artObjectInstance1 = artObjectInstance3;
label_72:
          Vector3 ordering = artObjectInstance1.Position - vector3_3;
          group.Triles.Sort((IComparer<TrileInstance>) new MovingTrileInstanceComparer(ordering));
          foreach (TrileInstance instance in group.Triles)
          {
            instance.Position += ordering;
            this.LevelManager.UpdateInstance(instance);
          }
          MovementPath movementPath = new MovementPath()
          {
            EndBehavior = PathEndBehavior.Bounce
          };
          ArtObjectInstance artObjectInstance4 = artObjectInstance1;
          PathSegment pathSegment1 = (PathSegment) null;
          while (true)
          {
            ArtObjectInstance nextNodeAo = artObjectInstance4.ActorSettings.NextNodeAo;
            if (nextNodeAo != null)
            {
              Vector3 a = nextNodeAo.Position - artObjectInstance4.Position;
              bool flag1 = (double) Math.Abs(FezMath.Dot(a, b)) > (double) Math.Abs(FezMath.Dot(a, FezMath.XZMask - b));
              bool flag2 = false;
              Vector3 point = a / 2f + artObjectInstance4.Position;
              foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
              {
                if (artObjectInstance2.ArtObject.ActorType == ActorType.None)
                {
                  Vector3 vector3_2 = artObjectInstance2.Scale * artObjectInstance2.ArtObject.Size / 2f;
                  BoundingBox boundingBox3 = new BoundingBox(artObjectInstance2.Position - vector3_2, artObjectInstance2.Position + vector3_2);
                  Quaternion rotation = artObjectInstance2.Rotation;
                  FezMath.RotateOnCenter(ref boundingBox3, ref rotation);
                  if (boundingBox3.Contains(point) != ContainmentType.Disjoint)
                  {
                    flag2 = true;
                    break;
                  }
                }
              }
              if (flag2 || flag1)
              {
                PathSegment pathSegment2 = nextNodeAo.ActorSettings.Segment.Clone();
                pathSegment2.Destination = (pathSegment1 == null ? Vector3.Zero : pathSegment1.Destination) + nextNodeAo.Position - artObjectInstance4.Position;
                if (!flag2)
                  pathSegment2.Duration = TimeSpan.Zero;
                movementPath.Segments.Add(pathSegment2);
                pathSegment1 = pathSegment2;
                artObjectInstance4 = nextNodeAo;
              }
              else
                break;
            }
            else
              break;
          }
          group.Path = movementPath;
          MovingGroupsHost.MovingGroupState movingGroupState = new MovingGroupsHost.MovingGroupState(group, true)
          {
            Enabled = false
          };
          this.trackedGroups.Add(movingGroupState);
          if (group.MoveToEnd)
          {
            group.MoveToEnd = false;
            movingGroupState.MoveToEnd();
          }
          foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
            artObjectInstance2.Enabled = true;
        }
      }
    }