Changeset 20

User picture

Author: conkerjo

(2009/07/01 23:47) Over 2 years ago

Documentation comments

Affected files

Updated src/BRAINSFramework/Agent.cs Download diff

1920
32
        private IBehavior _rootBehavior;
32
        private IBehavior _rootBehavior;
33
        private LocomotionController _motionController;
33
        private LocomotionController _motionController;
34
34
35
        /// <summary>
36
        /// Gets or sets the Feelers on the agent.
37
        /// </summary>
35
        public List<Feeler> Feelers { get; set; }
38
        public List<Feeler> Feelers { get; set; }
36
39
40
        /// <summary>
41
        /// Gets or sets the name of the Agent
42
        /// </summary>
37
        public string Name { get; set; }
43
        public string Name { get; set; }
38
44
39
        public int NextID
45
        private int NextID
40
        {
46
        {
41
            get
47
            get
42
            {
48
            {
...
...
44
            }
50
            }
45
        }
51
        }
46
52
53
        /// <summary>
54
        /// Gets the cells the agent is in
55
        /// </summary>
56
        /// <remarks>Current implementation only supports 1</remarks>
47
        public List<GridCell> CellsIAmIn { get; set; }
57
        public List<GridCell> CellsIAmIn { get; set; }
48
58
49
        /// <summary>
59
        /// <summary>
50
        /// The position of the Actor
60
        /// The position of the Actor
51
        /// </summary>
61
        /// </summary>
52
        public Vector2 Position { get; set; }
62
        public Vector2 Position { get; set; }
53
63
        /// <summary>
64
        /// Gets or sets the previous position of the agent
65
        /// </summary>
54
        public Vector2 PreviousPosition{ get; set; }
66
        public Vector2 PreviousPosition{ get; set; }
55
67
56
        /// <summary>
68
        /// <summary>
...
...
141
            Feelers.Add(new Feeler(new Vector2(x, y),length,this));
153
            Feelers.Add(new Feeler(new Vector2(x, y),length,this));
142
        }
154
        }
143
155
156
        /// <summary>
157
        /// Update the agent every frame. 
158
        /// </summary>
159
        /// <param name="gameTime">The time elapsed since the last update</param>
144
        public virtual void Update(GameTime gameTime)
160
        public virtual void Update(GameTime gameTime)
145
        {
161
        {
146
            if (RootBehavior != null &&
162
            if (RootBehavior != null &&
...
...
160
        /// Every time an actor changes its position, it remembers all map's nodes
176
        /// Every time an actor changes its position, it remembers all map's nodes
161
        /// he is in.
177
        /// he is in.
162
        /// </summary>
178
        /// </summary>
163
        public void UpdateLocationData()
179
        private void UpdateLocationData()
164
        {
180
        {
165
            // 1. remove itself from all previous AINodes
181
            // 1. remove itself from all previous AINodes
166
            for (int index = 0; index < CellsIAmIn.Count; index++)
182
            for (int index = 0; index < CellsIAmIn.Count; index++)
...
...
193
            int indexY = (int)yComponent;
209
            int indexY = (int)yComponent;
194
            indexX = indexX % map.Cols;
210
            indexX = indexX % map.Cols;
195
            indexY = indexY % map.Rows;
211
            indexY = indexY % map.Rows;
196
            map = GetGridAtPosition(Position);
212
            map = ParentWorld.Map.ClusterGrid.GetGridAtPosition(Position);
197
            if (map != null)
213
            if (map != null)
198
            {
214
            {
199
                GridCell desiredNode = map.GetCell(indexX, indexY);
215
                GridCell desiredNode = map.GetCell(indexX, indexY);
...
...
213
                Console.Write("");
229
                Console.Write("");
214
            }
230
            }
215
        }
231
        }
216
        public Grid GetGridAtPosition(Vector2 position)
217
        {
218
            foreach (var item in ParentWorld.Map.ClusterGrid.Grids)
219
            {
220
                if (
221
                    (position.X > item.Position.X && position.X < (item.Position.X + item.Width)) &&
222
                    (position.Y > item.Position.Y && position.Y < (item.Position.Y + item.Height))
223
                    )
224
                {
225
                    return item;
226
                }
227
            }
228
            return null;
229
        }
230
        /// <summary>
232
        /// <summary>
231
        /// Loads a Behavior from a file
233
        /// Loads a Behavior from a file
232
        /// </summary>
234
        /// </summary>

Updated src/BRAINSFramework/Map/Cluster.cs Download diff

1920
3
using System.Linq;
3
using System.Linq;
4
using System.Text;
4
using System.Text;
5
using Brains.Framework;
5
using Brains.Framework;
6
using Microsoft.Xna.Framework;
6
7
7
namespace Brains.Framework.Map
8
namespace Brains.Framework.Map
8
{
9
{
...
...
41
            //HACK: should support different sized grids
42
            //HACK: should support different sized grids
42
            get { return Grids[0].Rows* Rows; }
43
            get { return Grids[0].Rows* Rows; }
43
        }
44
        }
45
46
        public Grid GetGridAtPosition(Vector2 position)
47
        {
48
            foreach (var item in Grids)
49
            {
50
                if (
51
                    (position.X > item.Position.X && position.X < (item.Position.X + item.Width)) &&
52
                    (position.Y > item.Position.Y && position.Y < (item.Position.Y + item.Height))
53
                    )
54
                {
55
                    return item;
56
                }
57
            }
58
            return null;
59
        }
60
        
44
    }
61
    }
45
}
62
}

Updated src/BRAINSFramework/Map/GridCell.cs Download diff

1920
19
        private int  _type;
19
        private int  _type;
20
        private Vector2 _position;
20
        private Vector2 _position;
21
21
22
        /// <summary>
23
        /// Gets or sets the annotation labels on the cell
24
        /// </summary>
22
        public Dictionary<uint, int> Labels;
25
        public Dictionary<uint, int> Labels;
26
        
27
        /// <summary>
28
        /// Gets the agents currently occupying this cell
29
        /// </summary>
23
        public List<Agent> Agents;
30
        public List<Agent> Agents;
24
        
31
        
25
        /// <summary>
32
        /// <summary>

Updated src/BRAINSFramework/Map/WorldMap.cs Download diff

1920
14
    /// </summary>
14
    /// </summary>
15
    public class WorldMap
15
    public class WorldMap
16
    {
16
    {
17
        /// <summary>
18
        /// Gets the Quadtree of all cells in the map
19
        /// </summary>
17
        public QuadTree<GridCell> GridCellTree;
20
        public QuadTree<GridCell> GridCellTree;
21
22
        /// <summary>
23
        /// Gets the cluster of grids
24
        /// </summary>
18
        public Cluster ClusterGrid { get { return _clusterGrid; } }
25
        public Cluster ClusterGrid { get { return _clusterGrid; } }
19
26
20
        private Cluster _clusterGrid;
27
        private Cluster _clusterGrid;
...
...
22
        private int _height;
29
        private int _height;
23
        private List<GridCell> _allCells=new List<GridCell>();
30
        private List<GridCell> _allCells=new List<GridCell>();
24
        
31
        
32
        /// <summary>
33
        /// Gets all of the cells in the map
34
        /// </summary>
25
        public List<GridCell> AllCells
35
        public List<GridCell> AllCells
26
        {
36
        {
27
            get { return _allCells; }
37
            get { return _allCells; }
28
            set { _allCells = value; }
38
            set { _allCells = value; }
29
        }
39
        }
30
40
41
        /// <summary>
42
        /// Gets the top left position of the world
43
        /// </summary>
31
        public Vector2 TopLeft
44
        public Vector2 TopLeft
32
        {
45
        {
33
            get { return _clusterGrid.Grids[0].Position; }
46
            get { return _clusterGrid.Grids[0].Position; }
34
        }
47
        }
35
48
49
        /// <summary>
50
        /// Gets the bottom right position of the world
51
        /// </summary>
36
        public Vector2 BottomRight
52
        public Vector2 BottomRight
37
        {
53
        {
38
            get { return _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Position + _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Size; }
54
            get { return _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Position + _clusterGrid.Grids[_clusterGrid.Grids.Count - 1].Size; }
39
        }
55
        }
56
40
        internal WorldMap(int width, int height)
57
        internal WorldMap(int width, int height)
41
        {
58
        {
42
            _clusterGrid = new Cluster();
59
            _clusterGrid = new Cluster();

Updated src/BRAINSFramework/World.cs Download diff

1920
20
        //
20
        //
21
        //privates
21
        //privates
22
        //
22
        //
23
        private List<Agent> _agentsToRemove = new List<Agent>();
23
        private Texture2D _mapTexture;
24
        private Texture2D _mapTexture;
24
        private WorldMap _map;
25
        private WorldMap _map;
25
        //
26
        //
...
...
35
        /// </summary>
36
        /// </summary>
36
        public List<Agent> Actors = new List<Agent>();
37
        public List<Agent> Actors = new List<Agent>();
37
38
39
        /// <summary>
40
        /// Gets the world map
41
        /// </summary>
38
        public WorldMap Map { get { return _map; } }
42
        public WorldMap Map { get { return _map; } }
39
43
40
        //
44
        //
...
...
60
            }
64
            }
61
        }
65
        }
62
66
67
        /// <summary>
68
        /// Initializes a new world map with the provides parameters
69
        /// </summary>
70
        /// <param name="width">The width of the map in pixels</param>
71
        /// <param name="height">The height of the map in pixels</param>
72
        /// <param name="cellsize">The size of a cells width or height</param>
63
        public void SetupMap(int width, int height, int cellsize)
73
        public void SetupMap(int width, int height, int cellsize)
64
        {
74
        {
65
            SetupMap(width, height, cellsize, width / cellsize, height / cellsize,typeof(Grid));
75
            SetupMap(width, height, cellsize, width / cellsize, height / cellsize,typeof(Grid));
...
...
287
            actor.ParentWorld = this;
297
            actor.ParentWorld = this;
288
            Actors.Add(actor);
298
            Actors.Add(actor);
289
        }
299
        }
300
        /// <summary>
301
        /// Loads Map data from a texture
302
        /// </summary>
303
        /// <param name="texture">The texture to use</param>
304
        /// <param name="cellSize">The size of a cells width or height</param>
305
        /// <param name="grid">The type of grid to create</param>
290
        public void LoadMapDataFromTexture(Texture2D texture, int cellSize,Type grid)
306
        public void LoadMapDataFromTexture(Texture2D texture, int cellSize,Type grid)
291
        {
307
        {
292
            LoadMapDataFromTexture(texture, 1, 1, cellSize, grid);
308
            LoadMapDataFromTexture(texture, 1, 1, cellSize, grid);
293
        }
309
        }
310
        /// <summary>
311
        /// Loads Map data from a texture
312
        /// </summary>
313
        /// <param name="texture">The texture to use</param>
314
        /// <param name="cellSize">The size of a cells width or height</param>
294
        public void LoadMapDataFromTexture(Texture2D texture, int cellSize)
315
        public void LoadMapDataFromTexture(Texture2D texture, int cellSize)
295
        {
316
        {
296
            LoadMapDataFromTexture(texture, 1, 1, cellSize, typeof(Grid));
317
            LoadMapDataFromTexture(texture, 1, 1, cellSize, typeof(Grid));
297
        }
318
        }
319
        /// <summary>
320
        /// Loads Map data from a texture
321
        /// </summary>
322
        /// <param name="texture">The texture to use</param>
323
        /// <param name="cellSize">The size of a cells width or height</param>
324
        /// <param name="cols">The number of cols to split the map into</param>
325
        /// <param name="rows">The number of rows to split the map into</param>
326
        /// <param name="gridType">The type of grid to create</param>
298
        public void LoadMapDataFromTexture(Texture2D texture, int cols, int rows, int cellSize, Type gridType)
327
        public void LoadMapDataFromTexture(Texture2D texture, int cols, int rows, int cellSize, Type gridType)
299
        {
328
        {
300
            _mapTexture = texture;
329
            _mapTexture = texture;
...
...
370
            AddActor(_actor);
399
            AddActor(_actor);
371
            return _actor;
400
            return _actor;
372
        }
401
        }
373
        List<Agent> _agentsToRemove = new List<Agent>();
402
        
403
        /// <summary>
404
        /// Removes an Agent from the world
405
        /// </summary>
406
        /// <param name="agent"></param>
374
        public void RemoveAgent(Agent agent)
407
        public void RemoveAgent(Agent agent)
375
        {
408
        {
376
            _agentsToRemove.Add(agent);
409
            _agentsToRemove.Add(agent);