root/src/BRAINSFramework/AIEngine.cs

User picture

Author: conkerjo

Revision: 30 («Previous)


File Size: 2.34 KB

(November 01, 2009 14:48 UTC) Over 2 years ago

Added Zune HD support and simple sample

 
Show/hide line numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.IO;
using System.Reflection;

namespace Brains.Framework
{
    /// <summary>
    /// Represents the main AI Engine. 
    /// Create an instance of this class and call update every frame to stimulate the world
    /// </summary>
    public class AIEngine
    {
        
        private World _world;
        internal List<Assembly> Assemblies = new List<Assembly>();

        /// <summary>
        /// The main game world
        /// </summary>
        public World World { get { return _world; } }

        /// <summary>
        /// Default Constructor
        /// </summary>
        public AIEngine()
        {
        }

        /// <summary>
        /// The main engine update method
        /// </summary>
        /// <param name="gameTime">The GameTime elapsed since the last update</param>
        /// <remarks>Call this every frame</remarks>
        public void Update(GameTime gameTime)
        {
            World.Update(gameTime);
        }

        /// <summary>
        /// Creates an empty world
        /// </summary>
        public void CreateWorld()
        {
            _world = new World();
            _world.Engine = this;
        }
        
        /// <summary>
        /// Sets the world to the specified world
        /// </summary>
        /// <param name="world">The world to set as the active world</param>
        /// <remarks>Can be used when extending the World class</remarks>
        public void CreateWorld(World world)
        {
            _world = world;
            _world.Engine = this;
        }

        /// <summary>
        /// Loads an assembly ready for use with loading from file.
        /// </summary>
        /// <param name="path">The full file path of the assembly</param>
        /// <remarks>Will automatically load the engine assembly if not already loaded</remarks>
        public void LoadAssembly(string path)
        {
            if (Assemblies.Count == 0)
            {
                Assemblies.Add(typeof(AIEngine).Assembly);// Assembly.LoadFrom(typeof(AIEngine).Assembly.Location));
            }

            //Cache all the assemblies 
            Assemblies.Add(Assembly.LoadFrom(path));
        }
        
    }
}