Controller.cs :  » Game » RealmForge » Axiom » Controllers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » Axiom » Controllers » Controller.cs
#region LGPL License
/*
Axiom Game Engine Library
Copyright (C) 2003  Axiom Project Team

The overall design, and a majority of the core engine and rendering code 
contained within this library is a derivative of the open source Object Oriented 
Graphics Engine OGRE, which can be found at http://ogre.sourceforge.net.  
Many thanks to the OGRE team for maintaining such a high quality project.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#endregion

using System;

namespace Axiom.Controllers{
    /// <summary>
    ///    Instances of this class 'control' the value of another object in the system.
    ///  </summary>
    ///   <remarks>
    ///    Controller classes are used to manage the values of object automatically based
    ///    on the value of some input. For example, a Controller could animate a texture
    ///    by controlling the current frame of the texture based on time, or a different Controller
    ///    could change the color of a material used for a spaceship shield mesh based on the remaining
    ///    shield power level of the ship.
    ///    <p/>
    ///    The Controller is an intentionally abstract concept - it can generate values
    ///    based on input and a function, which can either be one of the standard ones
    ///    supplied, or a function can be 'plugged in' for custom behavior - see the <see cref="ControllerFunction"/> class for details.
    ///    Both the input and output values are via <see cref="ControllerValue"/> objects, meaning that any value can be both
    ///    input and output of the controller.
    ///    <p/>
    ///    While this is very flexible, it can be a little bit confusing so to make it simpler the most often used
    ///    controller setups are available by calling methods on the ControllerManager object.
    /// </remarks>
    public class Controller {
        #region Member variables
    
        /// <summary>
        /// 
        /// </summary>
        protected IControllerValue source;

        /// <summary>
        /// 
        /// </summary>
        protected IControllerValue destination;

        /// <summary>
        ///    Local reference to the function to be used for this controller.
        /// </summary>
        protected IControllerFunction function;

        /// <summary>
        ///    States whether or not this controller is enabled.
        /// </summary>
        protected bool isEnabled;
    
        #endregion

        #region Constructors

        /// <summary>
        ///    Main constructor.  Should not be used directly, rather a controller should be created using the
        ///    ControllerManager so it can keep track of them.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="function"></param>
        internal Controller(IControllerValue source, IControllerValue destination, IControllerFunction function) {
            this.source = source;
            this.destination = destination;
            this.function = function;

            // enabled by default, of course
            isEnabled = true;
        }

        #endregion

        #region Methods

        /// <summary>
        ///    Called to update the destination value for this controller.  Will be called during
        ///    the render loop by ControllerManager.
        /// </summary>
        public void Update() {
            // if we are enabled, set the destination value based on the return value of the
            // controller function ran using the source value
            if(isEnabled)
                destination.Value = function.Execute(source.Value);
        }

        #endregion

        #region Properties

        /// <summary>
        ///    The value that returns the source data for this controller.
        /// </summary>
        public IControllerValue Source {
            get { return source; }
            set { source = value; }
        }

        /// <summary>
        ///    The object the sets the destination objects value.
        /// </summary>
        public IControllerValue Destination {
            get { return destination; }
            set { destination = value; }
        }

        /// <summary>
        ///    Gets/Sets the eference to the function to be used for this controller.
        /// </summary>
        public IControllerFunction Function {
            get { return function; }
            set { function = value; }
        }

        /// <summary>
        ///    Gets/Sets whether this controller is active or not.
        /// </summary>
        public bool IsEnabled {
            get { return isEnabled; }
            set { isEnabled = value; }
        }

        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.