public static void SetForUnityMode() { //Environment.SetEnvironmentVariable("POSHUnityMode","True"); if (instance == null || !instance.GetType().IsSubclassOf(typeof(EmbeddedControl))) instance = new EmbeddedControl(); }
public static void SetForUnityMode() { //Environment.SetEnvironmentVariable("POSHUnityMode","True"); if (instance == null || !instance.GetType().IsSubclassOf(typeof(EmbeddedControl))) { instance = new EmbeddedControl(); } }
public static AssemblyControl GetControl() { if (instance is AssemblyControl || ( instance != null && instance.GetType().IsSubclassOf(typeof(AssemblyControl)))) return instance; else { //Environment.SetEnvironmentVariable("POSHUnityMode", "False"); instance = new AssemblyControl(); return instance; } }
public static AssemblyControl GetControl() { if (instance is AssemblyControl || (instance != null && instance.GetType().IsSubclassOf(typeof(AssemblyControl)))) { return(instance); } else { //Environment.SetEnvironmentVariable("POSHUnityMode", "False"); instance = new AssemblyControl(); return(instance); } }
/// <summary> /// Returns all behaviours of the agent's library as a behaviour /// dictionary. /// </summary> /// <returns>Behaviour dictionary with all behaviours in the library</returns> internal BehaviourDict LoadBehaviours() { BehaviourDict dict = AssemblyControl.GetControl().GetBehaviours(library, log, this); // TODO: Profiler needs to be included later on. // self.log.info("Creating instance of behaviour '%s'" % \ // behaviour_class.__name__) // if (self.profiler is not None): // try: // behaviour = behaviour_class(self,self.profiler) // except TypeError: // behaviour = behaviour_class(self) // else: // behaviour = behaviour_class(self) return(dict); }
/// <summary> /// Initialises the agent to use the given library and plan. /// /// The plan has to be given as the plan name without the '.lap' extension. /// The attributes are the ones that are assigned to the behaviours /// when they are initialised. The world is the one that can be accessed /// by the behaviours by the L{AgentBase.getWorld} method. /// /// Note that when the behaviours are loaded from the given library, then /// they are reflected onto the agent object. That means, given that /// there is a behaviour called 'bot', then it can be accessed from another /// behaviour either by self.agent.getBehaviour("bot"), or by /// self.agent.bot. Consequently, behaviour names that clash with already /// existing agent attributes cause an AttributeError to be raise upon /// initialising the behaviours. /// /// The attributes are to be given in the same format as for the /// method L{AgentBase.assignAttributes}. /// </summary> /// <param name="library">The behaviour library to use.</param> /// <param name="plan">The plan to use (without the '.lap' ending).</param> /// <param name="attributes">The attributes to be assigned to the behaviours</param> /// <param name="world"></param> public AgentBase(string library, string plan, Dictionary <Tuple <string, string>, object> attributes, World world) : base("") { // get unique id for agent first, as constructor of LogBase accesses it id = AssemblyControl.GetControl().UniqueAgendId(); this.Init(id); // store library for use when spawning new agents this.library = library; this.world = world; linkedPlanName = plan; _listeners = new List <IListener>(); // we need to set the random number generator before we // load the behaviours, as they might access it upon // construction this.random = new Random(); // if you are profiling, you need to fix this in your init_world. see library/latchTest for an example & documentation // do this before loading Behaviours // TODO: disabled profiler // profiler= Profiler.initProfile(this); // load and register the behaviours, and reflect back onto agent this._bdict = LoadBehaviours(); ReflectBehaviours(); //# more for the profiler // FIXME: PR -- is there another place to do this? will it succeed without MASON? JJB 1 March 2008 //try: // other.profiler.set_second_name(other._bdict._behaviours['MASON'].name) //except: // # may want this for debugging: print "profiler is off and/or MASON is not being used" // pass # normally don't expect profiling, nor necessarily MASON // assign the initial attributes to the behaviours this.AssignAttributes(attributes); // load the plan LoadPlan(plan); // loop thread control _execLoop = false; _loopPause = false; }
/// <summary> /// Returns a sequence of newly created agents using the given behaviour /// library. /// /// The type of agents are determined by their plan type, using the /// getPlanType() function. If a world object is given, it is given to the /// agent upon initialisation. /// /// The function must be given either a plan file of an agents_init structure, /// but not both. If a plan is given, then a single agent is created and /// returned as a sequence of one element. agents_init is a structure as /// returned by the agentinitparser module and allows creating and /// initialisation of several agents. The agents are created one by one /// and returned as a sequence. If both a plan and agents_init are given, /// then the plan is ignored. /// </summary> /// <param name="assemblyName">name of the library</param> /// <param name="plan">name of the plan (without path and file ending)</param> /// <param name="agentsInit">data structure for agent initialisation /// as returned by AgentInitParser.initAgentFile. The first element is the plan file name the second element is an attribute dictionary</param> /// <param name="world">world object, given to agents at construction</param> /// <returns>List of Agents</returns> public static AgentBase[] CreateAgents(string assemblyName, string plan, List <Tuple <string, object> > agentsInit, World world) { // build initialisation structure if (agentsInit == null) { if (plan == string.Empty) { throw new TypeLoadException("create_agent() requires either plan or agents_init to be specified"); } agentsInit = new List <Tuple <string, object> >(); /// string for the plan and a dictionary for the /// (behaviour, attribute) -> value assignment. agentsInit.Add(new Tuple <string, object>(plan, new Dictionary <Tuple <string, string>, object>())); } // create the agents List <AgentBase> agents = new List <AgentBase>(); foreach (Tuple <string, object> pair in agentsInit) { string agentPlan = pair.First; Dictionary <Tuple <string, string>, object> agentAttributes = (Dictionary <Tuple <string, string>, object>)pair.Second; // determine agent type from plan PLANTYPE planType = getPlanType(AssemblyControl.GetControl().GetPlanFile(assemblyName, agentPlan)); if (planType == PLANTYPE.NONE) { throw new KeyNotFoundException(string.Format("plan type of plan {0} not recognised", agentPlan)); } Type agentType = AGENTTYPE.getType(planType); // create agent and append to sequence Type[] constructorTypes = new Type[4]; constructorTypes[0] = assemblyName.GetType(); constructorTypes[1] = agentPlan.GetType(); constructorTypes[2] = agentAttributes.GetType(); constructorTypes[3] = (world != null) ? world.GetType() : typeof(World); System.Reflection.ConstructorInfo constructor = agentType.GetConstructor(constructorTypes); agents.Add((AgentBase)constructor.Invoke(new object[] { assemblyName, agentPlan, agentAttributes, world })); } return(agents.ToArray()); }
public Launcher() { control = AssemblyControl.GetControl(); }