Skip to content

Commit

Permalink
Moved radar collections to C5
Browse files Browse the repository at this point in the history
Bit of an experiment.  The C5 collections are still better designed
than the .Net ones, even on 3.5.  For instance, List(T) has a Find
method, but IList(T) doesn't.  List(T).AsReadOnly returns an IList,
which means you can't do .Find on it. So if you'd like to have that,
you have to forget about the safety net of AsReadOnly, and end up
writing to the implementation.

C5 allows us to return a GuardedList that behaves consistent with
what you would expect from List, and on top of that the collection
gets us other features.
  • Loading branch information
Ricardo J. Mendez committed Aug 18, 2010
1 parent acf9e2c commit bc2ba44
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
13 changes: 7 additions & 6 deletions Behaviors/Radar.cs
@@ -1,5 +1,5 @@
using System.Linq;
using System.Collections.Generic;
using C5;
using UnityEngine;
using UnitySteer;
using UnitySteer.Helpers;
Expand All @@ -24,9 +24,10 @@ public class Radar: MonoBehaviour, ITick {
[SerializeField]
LayerMask _layersChecked;


IList<Collider> _detected;
List<Vehicle> _vehicles = new List<Vehicle>();
List<Obstacle> _obstacles = new List<Obstacle>();
IList<Vehicle> _vehicles = new ArrayList<Vehicle>();
IList<Obstacle> _obstacles = new ArrayList<Obstacle>();

ObstacleFactory _obstacleFactory = null;

Expand All @@ -51,7 +52,7 @@ public class Radar: MonoBehaviour, ITick {
public IList<Obstacle> Obstacles {
get {
ExecuteRadar();
return _obstacles.AsReadOnly();
return new GuardedList<Obstacle>(_obstacles);
}

}
Expand Down Expand Up @@ -80,7 +81,7 @@ public class Radar: MonoBehaviour, ITick {
public IList<Vehicle> Vehicles {
get {
ExecuteRadar();
return _vehicles.AsReadOnly();
return new GuardedList<Vehicle>(_vehicles);
}
}

Expand Down Expand Up @@ -154,7 +155,7 @@ void ExecuteRadar()

protected virtual IList<Collider> Detect()
{
return new List<Collider>();
return new ArrayList<Collider>();
}

protected virtual void FilterDetected()
Expand Down
5 changes: 3 additions & 2 deletions Behaviors/RadarPing.cs
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using C5;
using UnityEngine;
using UnitySteer.Helpers;

Expand Down Expand Up @@ -47,7 +47,8 @@ void OnDrawGizmos()
protected override IList<Collider> Detect()
{
var detected = Physics.OverlapSphere(Vehicle.Position, _detectionRadius, LayersChecked);
var list = new List<Collider>(detected);
var list = new ArrayList<Collider>();
list.AddAll<Collider>(detected);
return list;
}
#endregion
Expand Down
2 changes: 2 additions & 0 deletions C5.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added C5/C5.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions C5/C5.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions C5/LICENSE.txt
@@ -0,0 +1,32 @@
THE C5 GENERIC COLLECTION LIBRARY FOR C#/CLI

Niels Kokholm and Peter Sestoft
IT University of Copenhagen, Denmark

See http://www.itu.dk/research/c5/
and http://www.itu.dk/research/c5/Release1.0/ITU-TR-2006-76.pdf

--------------------------------------------

LICENSE

Copyright (c) 2003-2007 Niels Kokholm and Peter Sestoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--------------------------------------------
2 changes: 2 additions & 0 deletions C5/LICENSE.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bc2ba44

Please sign in to comment.