Exemplo n.º 1
0
        public static void Rule(Term lhs, Atom atom, OptionalTermBody optionalTermBody)
        {
            CodeCompoundTerm codeCompoundTerm;

            if (optionalTermBody.CodeTerms == null)
            {
                CodeFunctor codeFunctor = new CodeFunctor(atom.Text);

                codeCompoundTerm = new CodeCompoundTerm(codeFunctor);
            }
            else
            {
                CodeFunctor codeFunctor = new CodeFunctor(atom.Text, optionalTermBody.CodeTerms.Count);

                if (codeFunctor.Arity == 0)
                {
                    codeCompoundTerm = new CodeCompoundTerm(codeFunctor);
                }
                else
                {
                    codeCompoundTerm = new CodeCompoundTerm(codeFunctor, optionalTermBody.CodeTerms);
                }
            }

            lhs.CodeCompoundTerm = codeCompoundTerm;
        }
Exemplo n.º 2
0
 static public async Task WriteAsync(this Stream stream, Atom atom, CancellationToken cancel_token)
 {
   var bufstream = new MemoryStream();
   bufstream.Write(atom);
   var buf = bufstream.ToArray();
   await stream.WriteAsync(buf, 0, buf.Length, cancel_token);
 }
Exemplo n.º 3
0
    public void displayAtom(Atom a,float scale)
    {
        a.Gameobject[frame] = (GameObject)Instantiate (Resources.Load("Prefabs/Atom") as GameObject, a.Location[frame], Quaternion.identity);
        a.Gameobject[frame].name = a.AtomFullName;
        a.Gameobject[frame].transform.localScale = new Vector3(scale,scale,scale);

        /* cut sphere
        Vector3[] vertices =a.Gameobject.GetComponent<MeshFilter>().mesh.vertices;
        List<int> indices = new List<int>(a.Gameobject.GetComponent<MeshFilter>().mesh.triangles);
        int count = indices.Count / 3;
        Vector3 norm = a.Gameobject.transform.position.normalized;
        float d = 0.1f;
            for (int j = count-1; j >= 0; j--)
            {
                Vector3 V1 = vertices[indices[j*3 + 0]];
                Vector3 V2 = vertices[indices[j*3 + 1]];
                Vector3 V3 = vertices[indices[j*3 + 2]];
                float t1 = V1.x*norm.x+V1.y*norm.y+V1.z*norm.z;
                float t2 = V2.x*norm.x+V2.y*norm.y+V2.z*norm.z;
                float t3 = V3.x*norm.x+V3.y*norm.y+V3.z*norm.z;
                if(norm != Vector3.zero){
                    if (t1 < d && t2 < d && t3 < d)
                        indices.RemoveRange(j*3, 3);

                }
            }

        a.Gameobject.GetComponent<MeshFilter>().mesh.triangles = indices.ToArray();
        */

        a.Gameobject[frame].GetComponent<Renderer>().material = setMaterialAtm(a,color);
    }
Exemplo n.º 4
0
        protected override bool SensingProcess(Character sensor, Atom sensed, int CD)
        {
            var res = Dice.Throws(20)
                        + sensor.Stats[StatsType.Mental].ModifierOfStat()
                        + sensor.TempModifiers.GetBonus<int>(TemporaryModifier.ModFor.SpotPerception,
                                                                (a, b) => a + b); ;

            var isSensed = res >= CD;

            var sensorType = sensor.GetType();
            var pgType = typeof(Pg);
            var sensedType = sensed.GetType();

            if (isSensed)
            {
                if (typeof(HiddenAtom).IsAssignableFrom(sensedType))
                {
                    var _sensed = (HiddenAtom)sensed;
                    if (_sensed.Hidden)
                    {
                        _sensed.NotifyIndividuation();
                    }
                }
                else
                {
                    if (sensorType == pgType || sensorType.IsSubclassOf(pgType))
                    {
                        var msg = "Noises in the area...";
                        sensor.NotifyListeners(msg);
                    }
                }
            }

            return isSensed;
        }
    public override Vector3 deltaPosition(Atom firstAtom, Atom secondAtom)
    {
        Vector3 boxDimension = new Vector3 (CreateEnvironment.myEnvironment.width-2.0f * CreateEnvironment.myEnvironment.errorBuffer, CreateEnvironment.myEnvironment.height-2.0f * CreateEnvironment.myEnvironment.errorBuffer , CreateEnvironment.myEnvironment.depth-2.0f * CreateEnvironment.myEnvironment.errorBuffer);

        Vector3 deltaR = firstAtom.position - secondAtom.position;
        if (Mathf.Abs(deltaR.x) > boxDimension.x / 2.0f)
        {
            float sign = Mathf.Sign(deltaR.x);
            deltaR.x = deltaR.x - sign * boxDimension.x;
        }

        if (Mathf.Abs(deltaR.y) > boxDimension.y / 2.0f)
        {
            float sign = Mathf.Sign(deltaR.y);
            deltaR.y = deltaR.y- sign * boxDimension.y;
        }

        if (Mathf.Abs(deltaR.z) > boxDimension.z / 2.0f)
        {
            float sign = Mathf.Sign(deltaR.z);
            deltaR.z = deltaR.z- sign * boxDimension.z;
        }

        return deltaR;
    }
Exemplo n.º 6
0
    /**
     * Evaluates a CTL-FO+ formula by replacing an atom by another in it. You
     * can actually replace an atom by a whole formula.
     * <p>
     * In the case of a Minus operator, evaluates the subtraction if both sides
     * are numerical. Otherwise, the operation cannot be resolved to a constant
     * and is returned partially evaluated.
     * <p>
     * The values in the left- and right-hand side are first evaluated as
     * numbers (floats), if they can both be parsed as numbers. Otherwise, they
     * are compared using alphabetical order.
     *
     * @param variable
     *            The atom to look for.
     * @param value
     *            The value to replace it with.
     * @return The evaluated formula
     */
    public override Operator evaluate(Atom variable, Operator val)
    {
        Operator leftPart = m_left.evaluate(variable, val);
        Operator rightPart = m_right.evaluate(variable, val);
        float num_left = 0.0f, num_right = 0.0f;

        if (leftPart.GetType() == (new Constant()).GetType() &&
            rightPart.GetType() == (new Constant()).GetType())
        {
            try
            {
                num_left = float.Parse(leftPart.ToString());
                num_right = float.Parse(rightPart.ToString());

                return new Constant(((float)(num_left - num_right)).ToString());
            }

            catch (System.FormatException fe)
            {
                System.Diagnostics.Debug.Print (fe.ToString());
            }

            // We are here: LHS and RHS are not both numbers
            // (Do nothing)
        }

        return new OperatorMinus(leftPart, rightPart);
    }
Exemplo n.º 7
0
		public static void Execute(Atom parent)
		{

			var nb =new NavList ();

			nb.Add ("Tables");
			nb.Add ("Forms");
			nb.Add ("Modals");
			nb.Add ("Panels");
			nb.AddDivider ();
			nb.Add ("Exit");


			var log = new Div ();
			var code = new Div ();

			new Div (d=>{
				d.ClassName="bs-docs-example";
				d.JQuery.Append(nb).Append(log).Append("C# code".Header(4)).Append(code);
				parent.Append(d);
			});

			nb.Selected += (e) => {
				var i = e.CurrentTarget.As<NavItem> ();
				log.Text=  "{0} Clicked".Fmt(i.Text); 
			};

			var rq =jQuery.GetData<string> ("code/demonavlist.html");
			rq.Done (s=> code.Text=s);

		}
Exemplo n.º 8
0
		public static void Execute (Atom parent){

			var nb =new NavList ();
					
			nb.Add ("Simple Bootbox Dialog", handler: e=> Bootbox.Dialog("cayita is awesome"));
			nb.Add ("Custom Bootbox.Dialog I", handler:  CustomDialog_1);
			nb.Add ("Custom Bootbox.Dialog 2", handler:  CustomDialog_2);
			nb.Add ("Custom Bootbox.Dialog 3", handler:  CustomDialog_3);
			nb.AddDivider ();

			nb.Add ("Alert", handler: e=> Bootbox.Alert("Alert!",()=> "Alert callback...".LogInfo()));
			nb.Add ("Confirm", handler: e=> Bootbox.Confirm("Confirm...",(c)=> ("Confirm callback "+c).LogInfo()));
			nb.Add ("Prompt", handler: e=> Bootbox.Prompt("Pormpt...",(s)=> ("Prompt callback "+s).LogInfo()));

			var code = new Div ();

			new Div (d=>{
				d.ClassName="bs-docs-example";
				d.JQuery.Append(nb).Append("C# code".Header(4)).Append(code);
				parent.Append(d);
			});

			var rq =jQuery.GetData<string> ("code/demomodals.html");
			rq.Done (s=> code.InnerHTML=s);

		}
Exemplo n.º 9
0
		public static void Execute(Atom parent)
		{
			var nb =new NavBar ();
			nb.BrandText="App Title";
			nb.Add ("Home");
			nb.Add ("License");
			nb.Add ("Contact");

			var dd = new DropdownMenu ();
			dd.Text = "Config";
			dd.Nav.Add ("Users");
			dd.Nav.Add ("Groups");

			nb.Add (dd);

			var log = new Div ();
			var code = new Div ();

			new Div (d=>{
				d.ClassName="bs-docs-example";
				d.JQuery.Append(nb).Append(log).Append("C# code".Header(4)).Append(code);
				parent.Append(d);
			});

			nb.Selected += (e) => {
				var i = e.CurrentTarget.As<NavItem> ();
				log.Text=  "{0} Clicked".Fmt(i.Text); 
			};

			var rq =jQuery.GetData<string> ("code/demonavbar.html");
			rq.Done (s=> code.Text=s);

		}
Exemplo n.º 10
0
        protected override string GetProperMoleculeDescription(Atom[] atoms)
        {
            string content = "";

            int atomsInLine = 0;
            foreach (var atom in atoms)
            {
                content += String.Format("{0,-3}", atom.Element);

                atomsInLine = (atomsInLine + 1) % 26;
                if (atomsInLine == 0)
                    content += Environment.NewLine;
            }

            bool even = false;
            foreach (var atom in atoms)
            {
                if (!even)
                    content += Environment.NewLine;

                content += String.Format(CultureInfo.InvariantCulture, "{0,10:F5}{1,10:F5}{2,10:F5}",
                    atom.X, atom.Y, atom.Z);

                even = !even;
            }

            return content.Trim();
        }
Exemplo n.º 11
0
		public static void Execute(Atom parent)
		{

			var fp = new Div ("bs-docs-example");
			var ff = new FileField (fp);
			var ufb = CreateUploadButton (fp);
			var logf = new Div (fp);

			var imp = new Div ("bs-docs-example");
			var imf = new ImgField (imp);
			var imb = CreateUploadButton (imp);
			var logim = new Div (imp);

			parent.JQuery
				.Append ("File Upload".Header(3))
					.Append (fp)
					.Append ("Image Upload".Header(3))
					.Append (imp);


			var rq =jQuery.GetData<string> ("code/demofileupload.html");
			rq.Done (s=> {
				var code=new Div();
				code.InnerHTML= s;
				parent.JQuery.Append ("C# code".Header(3)).Append(code);
			});



			ff.Changed+= (e) => ShowFileInfo(ufb, logf,ff.Input);
			imf.Changed+= (e) => ShowFileInfo(imb, logim, imf.Input);

			ufb.Clicked+= (e) => SendFile(ufb, ff.Input);
			imb.Clicked+= (e) => SendFile(imb, imf.Input);
		}
        public void SetUp()
        {
            var atom = new Atom(
                "atom",
                new[] { new Property("property-name", "property-type", new InheritedPropertyValue("property-alias")) });

            var containerSpecification = new ContainerSpecification("container");
            var container = containerSpecification.Create();
            container.Insert(0, atom);

            var widgetSpecification = new WidgetSpecification(
                "widget",
                new[] { new PropertySpecification("property-alias", "property-type", string.Empty) },
                new[] { container });

            var buildContext = new BuildData(Enumerable.Empty<IContextItem>());

            var widget = widgetSpecification.Create();
            widget.FindOrCreateProperty(new PropertySpecification("property-alias", "property-type", string.Empty));
            widget.Properties.Single().Value = new FixedPropertyValue("property-value");

            var builder = new Builder(RenderingInstructions.BuildForPreview(), w => widgetSpecification, null);

            this.instance = widget.Build(builder, new[] { 0 }, buildContext);
        }
 public AtomInstance Build(Atom atom, IEnumerable<int> path, IBuildData buildData)
 {
     return new AtomInstance(
         path,
         this.renderingInstructions,
         atom.Name,
         atom.Properties.Select(p => p.Build(buildData)).ToList());
 }
Exemplo n.º 14
0
		static ButtonIcon CreateUploadButton(Atom parent){
			return  new ButtonIcon (parent, imb=>{ 
				imb.IconClass="icon-upload";
				imb.Text = "Upload";
				imb.AddClass ("btn-info"); 
				imb.Disabled=true;
			});
		}
Exemplo n.º 15
0
 protected void Bound(Atom[] args) 
 { 
     float f1 = (float)args[0];
     float f2 = (float)args[1];
     
     this.i_down = (int)((f1<f2)?f1:f2);
     this.i_up = (int)((f1>f2)?f1:f2);
 }
Exemplo n.º 16
0
 public void Visit(Atom atom)
 {
     var specification = this.componentLibrary.Lookup(atom.Name);
     foreach (var propertySpecification in specification.Properties)
     {
         atom.FindOrCreateProperty(propertySpecification);
     }
 }
        public void SetUp()
        {
            var atomSpecification = new AtomSpecification("atom 1");
            atomSpecification.AddProperty(new PropertySpecification("property 1 name", "property 1 type", string.Empty));
            atomSpecification.AddProperty(new PropertySpecification("property 2 name", "property 2 type", "property 2 default"));

            this.atom = atomSpecification.Create();
        }
        public void SetUp()
        {
            var templatePath = new[] { "test", "path" };
            this.template = new Template(templatePath);

            var newComponent = new Atom("component1", null);
            this.template.Insert(0, newComponent);
        }
Exemplo n.º 19
0
        public static RuleData ToRules(List<Token> input)
        {
            var output = new RuleData();
            var currentTerm = new Term();
            output.Terms.Add(currentTerm);
            currentTerm.Id = output.Terms.Count;

            while (input.Count > 0)
            {
                var currentAtom = new Atom();
                currentTerm.Atoms.Add(currentAtom);

                //negativeness
                if (input[0].Type == TokenType.Negate)
                {
                    currentAtom.Truthfulness = false;
                    TokenPop(input);
                }

                //name
                var nameToken = TokenPop(input);
                Expect(nameToken, TokenType.String);
                currentAtom.Name = nameToken.Name;

                //arguments
                Expect(TokenPop(input), TokenType.ParenBegin);
                GetArguments(input, currentAtom.Arguments);

                var orOrPeriodOrQuestionMark = TokenPop(input);
                switch (orOrPeriodOrQuestionMark.Type)
                {
                    case TokenType.Or:
                        continue;
                    case TokenType.Period:
                        if (input.Count > 0)
                        {
                            currentTerm = new Term();
                            output.Terms.Add(currentTerm);
                            currentTerm.Id = output.Terms.Count;
                        }
                        continue;
                    case TokenType.QuestionMark:
                        output.Terms.Remove(currentTerm);
                        output.Goal = currentTerm.Atoms[0];
                        if (input.Count > 0)
                        {
                            currentTerm = new Term();
                            output.Terms.Add(currentTerm);
                            currentTerm.Id = output.Terms.Count;
                        }
                        continue;
                }
                throw new Exception("Not the right input: " + orOrPeriodOrQuestionMark.Name);
            }

            return output;
        }
Exemplo n.º 20
0
        public override bool Interaction(Atom interactor)
        {
            if (interactor.GetType() == typeof(Pg))
            {
                interactor.NotifyListeners(String.Format("It's a {0}", this.Name));
            }

            return false;
        }
Exemplo n.º 21
0
 public FOQuantifier()
     : base()
 {
     m_symbolLeft = "";
     m_symbolRight = "";
     m_quantifiedVariable = null;
     m_operand = null;
     m_qualifier = "";
     m_domain = null;
 }
Exemplo n.º 22
0
        protected override string GetProperMoleculeDescription(Atom[] atoms)
        {
            string content = "";
            foreach (var atom in atoms)
            {
                content += String.Format(CultureInfo.InvariantCulture, "{0,-5} {2:F10} {3:F10} {4:F10}\n",
                    atom.Element, atom.Number, atom.X, atom.Y, atom.Z);
            }

            return content.Trim();
        }
Exemplo n.º 23
0
 public override bool Interaction(Atom interactor)
 {
     if (typeof(IGoldDealer).IsAssignableFrom(interactor.GetType()))
     {
         ((IGoldDealer)interactor).PickUpGold(this);
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 24
0
        public IDisposable Push(Atom atom)
        {
            Stack.Push(atom);
            CorePush(atom);

            return new DisposableAction(() =>
            {
                (Stack.Peek() == atom).AssertTrue();
                Stack.Pop();
                CorePop(atom);
            });
        }
Exemplo n.º 25
0
    //the function returns the Lennard-Jones force on the atom given the list of all the atoms in the simulation
    public override void getForce(Atom firstAtom, Atom secondAtom)
    {
        Vector3 deltaR = Boundary.myBoundary.deltaPosition(firstAtom,secondAtom);
        float distanceSqr = deltaR.sqrMagnitude;

        //only get the forces of the atoms that are within the cutoff range
        if (distanceSqr <= cutoffSqr)
        {
            int iR = (int)(Mathf.Sqrt(distanceSqr) / (dR));
            firstAtom.accelerationNew = firstAtom.accelerationNew+ preBuckinghamAcceleration[firstAtom.atomID, secondAtom.atomID,iR] * deltaR;
            secondAtom.accelerationNew = secondAtom.accelerationNew - preBuckinghamAcceleration[secondAtom.atomID, firstAtom.atomID,iR] * deltaR;
        }
    }
Exemplo n.º 26
0
    public test(Atom[] args)
    {
        Post("Test.ctor "+args.ToString());

        // save args
        this.args = args;

        //        AddInlet(s_list,new PureData.Symbol("list2"));
        AddInlet();
        AddInlet(ref farg);
        AddInlet();
        AddOutletAnything();
    }
Exemplo n.º 27
0
    public OPlus(string qualifier, Atom a)
        : this()
    {
        if (qualifier != null)
        {
            m_qualifier = qualifier;
        }

        if (a != null)
        {
            m_operand = a;
        }
    }
Exemplo n.º 28
0
 public void TestAtomHashing()
 {
     var a = new Atom("a");
     var b1 = new Atom("b");
     var b2 = new Atom("b");
     var c1 = new Atom("ccccccccccccccccccccccccccccccccccc");
     var c2 = new Atom("ccccccccccccccccccccccccccccccccccc");
     Assert.That(a, Is.EqualTo(a));
     Assert.That(a, Is.Not.EqualTo(b1));
     Assert.That(b1, Is.EqualTo(b2));
     Assert.That(b1.GetHashCode(), Is.EqualTo(b2.GetHashCode()));
     Assert.That(c1.GetHashCode(), Is.EqualTo(c2.GetHashCode()));
 }
        public void SetUp()
        {
            this.container = new Container("existing container", null);
            this.Template.Insert(0, this.container);

            var newComponent = new Atom("new atom", null);

            this.ComponentSpecification.Stub(s => s.Create()).Return(newComponent);

            var amendment = new AddComponentAmendment(new[] { 0, 0 }, "new atom");

            this.Visitor.Visit(amendment);
        }
Exemplo n.º 30
0
        public Mill(List<uint> entries)
        {
            _entries = new List<uint>();
            _entries.AddRange(entries);

            var inscription = StyxWoW.Me.GetSkill(SkillLine.Inscription);
            if (inscription == null || inscription.CurrentValue <= 0)
            {
                _craftMortar = new CraftDraenicMortarAtNpc();
                Dependencies.Add(_craftMortar);
            }

            Dependencies.Add(new Stack(_entries, 5));
        }
Exemplo n.º 31
0
        // FixedUpdate is called with each physics simulation frame by Unity
        protected void FixedUpdate()
        {
            if (updateTimer > 1.0f)
            {
                try
                {
                    // Updates the position and rotation of every target for every 'other' player and sends the current position and rotation data to the server for the main player
                    foreach (string playerName in playerList)
                    {
                        if (playerName != playerChooser.val)
                        {
                            // Find correct player in the List
                            int    playerIndex = players.FindIndex(p => p.playerName == playerName);
                            Player player      = players[playerIndex];

                            // Update only target positions and rotations for the 'other' players
                            foreach (Player.TargetData target in player.playerTargets)
                            {
                                if ((target.targetName == "control") || (target.targetName == "headControl") || (target.targetName == "chestControl") || (target.targetName == "hipControl") || (target.targetName == "lFootControl") || (target.targetName == "rFootControl") || (target.targetName == "lHandControl") || (target.targetName == "rHandControl"))
                                {
                                    // If server connection is live
                                    if (client != null)
                                    {
                                        //string response = SendToServer(player + "," + target.targetName + "," + target.position.x.ToString() + "," + target.position.y.ToString() + "," + target.position.z.ToString() + "|");
                                        string response = SendToServer(player.playerName + "," + target.targetName + "|");

                                        if (response != "none|")
                                        {
                                            // Parse the response from the server and assign the position and rotation data to the target
                                            string[] targetData = response.Split(',');

                                            Atom             playerAtom   = SuperController.singleton.GetAtomByUid(targetData[0]);
                                            FreeControllerV3 targetObject = playerAtom.GetStorableByID(target.targetName) as FreeControllerV3;

                                            Vector3 tempPosition = targetObject.transform.position;
                                            tempPosition.x = float.Parse(targetData[2]);
                                            tempPosition.y = float.Parse(targetData[3]);
                                            tempPosition.z = float.Parse(targetData[4]);

                                            Quaternion tempRotation = targetObject.transform.rotation;
                                            tempRotation.w = float.Parse(targetData[5]);
                                            tempRotation.x = float.Parse(targetData[6]);
                                            tempRotation.y = float.Parse(targetData[7]);
                                            tempRotation.z = float.Parse(targetData[8]);

                                            targetObject.transform.position = tempPosition;
                                            targetObject.transform.rotation = tempRotation;
                                        }

                                        // SuperController.LogMessage(response);
                                    }
                                }
                            }
                        }
                        else
                        {
                            Atom playerAtom = SuperController.singleton.GetAtomByUid(playerName);

                            // Find correct player in the List
                            int    playerIndex = players.FindIndex(p => p.playerName == playerName);
                            Player player      = players[playerIndex];

                            // Update only changed target positions and rotations for the main player
                            foreach (Player.TargetData target in player.playerTargets)
                            {
                                if ((target.targetName == "control") || (target.targetName == "headControl") || (target.targetName == "chestControl") || (target.targetName == "hipControl") || (target.targetName == "lFootControl") || (target.targetName == "rFootControl") || (target.targetName == "lHandControl") || (target.targetName == "rHandControl"))
                                {
                                    FreeControllerV3 targetObject = playerAtom.GetStorableByID(target.targetName) as FreeControllerV3;
                                    //SuperController.LogError((playerName + "," + target.targetName + "," + target.position.x.ToString() + "," + target.position.y.ToString() + "," + target.position.z.ToString() + "," + target.rotation.w.ToString() + "," + target.rotation.x.ToString() + "," + target.rotation.y.ToString() + "," + target.rotation.z.ToString() + "|"));
                                    //SuperController.LogError((playerName + "," + target.targetName + "," + target.positionOld.x.ToString() + "," + target.positionOld.y.ToString() + "," + target.positionOld.z.ToString() + "," + target.rotationOld.w.ToString() + "," + target.rotationOld.x.ToString() + "," + target.rotationOld.y.ToString() + "," + target.rotationOld.z.ToString() + "|"));

                                    if (Vector3.Distance(targetObject.transform.position, target.positionOld) > 0.05f || Mathf.Abs(Quaternion.Angle(targetObject.transform.rotation, target.rotationOld)) > 0.05f)
                                    {
                                        // if (target.updateTimer > 0.5f)
                                        // {
                                        // If server connection is live
                                        if (client != null)
                                        {
                                            // Send main player's target position and rotation data to the server to be recorded
                                            string response = SendToServer(playerName + "," + target.targetName + "," + targetObject.transform.position.x.ToString() + "," + targetObject.transform.position.y.ToString() + "," + targetObject.transform.position.z.ToString() + "," + targetObject.transform.rotation.w.ToString() + "," + targetObject.transform.rotation.x.ToString() + "," + targetObject.transform.rotation.y.ToString() + "," + targetObject.transform.rotation.z.ToString() + "|");
                                        }
                                        // target.updateTimer = 0.0f;
                                        // }
                                    }

                                    // Update the 'Old' position and rotation data
                                    // target.updateTimer += Time.fixedDeltaTime;
                                    target.positionOld = targetObject.transform.position;
                                    target.rotationOld = targetObject.transform.rotation;
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    SuperController.LogError("Exception caught: " + e);
                }
                updateTimer = 0.0f;
            }
            updateTimer += Time.fixedDeltaTime;
        }
Exemplo n.º 32
0
        public void CreateElementCharacters(Atom atom, Options options)
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            //Point atomCentre = new Point((double)atom.X2, (double)atom.Y2);
            string atomLabel = atom.Element.Symbol;
            Rect   labelBounds;

            // Get Charge and Isotope values for use later on
            int iCharge    = atom.FormalCharge ?? 0;
            int iAbsCharge = Math.Abs(iCharge);
            int isoValue   = atom.IsotopeNumber ?? 0;

            // Get Implicit Hydrogen Count for use later on
            int implicitHCount = atom.ImplicitHydrogenCount;

            Point cursorPosition        = atom.Position;
            Point chargeCursorPosition  = atom.Position;
            Point isotopeCursorPosition = atom.Position;

            double lastOffset = 0;

            int bondCount = atom.Bonds.ToList().Count;

            #region Decide if atom label is to be displayed

            bool showLabel = true;
            if (atomLabel == "C")
            {
                if (atom.ShowSymbol.HasValue)
                {
                    showLabel = atom.ShowSymbol.Value;
                }
                else
                {
                    if (atom.IsInRing || bondCount > 1)
                    {
                        showLabel = false;
                    }

                    if (bondCount == 2)
                    {
                        Point p1 = atom.Bonds.ToList()[0].OtherAtom(atom).Position;
                        Point p2 = atom.Bonds.ToList()[1].OtherAtom(atom).Position;

                        double angle1 = Vector.AngleBetween(-(atom.Position - p1), atom.Position - p2);

                        if (Math.Abs(angle1) < 8)
                        {
                            showLabel = true;
                        }
                    }
                }

                // Force on if atom has charge
                if (iAbsCharge > 0)
                {
                    showLabel = true;
                }
                // Force on if atom has isotope value
                if (isoValue > 0)
                {
                    showLabel = true;
                }
            }

            #endregion Decide if atom label is to be displayed

            if (showLabel)
            {
                #region Set Up Atom Colours

                string atomColour = "000000";
                if (options.ColouredAtoms)
                {
                    if (atom.Element.Colour != null)
                    {
                        atomColour = atom.Element.Colour;
                        // Strip out # as OoXml does not use it
                        atomColour = atomColour.Replace("#", "");
                    }
                }

                #endregion Set Up Atom Colours

                #region Step 1 - Measure Bounding Box for all Characters of label

                double xMin = double.MaxValue;
                double yMin = double.MaxValue;
                double xMax = double.MinValue;
                double yMax = double.MinValue;

                Point thisCharacterPosition;
                for (int idx = 0; idx < atomLabel.Length; idx++)
                {
                    char         chr = atomLabel[idx];
                    TtfCharacter c   = _TtfCharacterSet[chr];
                    if (c != null)
                    {
                        thisCharacterPosition = GetCharacterPosition(cursorPosition, c);

                        xMin = Math.Min(xMin, thisCharacterPosition.X);
                        yMin = Math.Min(yMin, thisCharacterPosition.Y);
                        xMax = Math.Max(xMax, thisCharacterPosition.X + OoXmlHelper.ScaleCsTtfToCml(c.Width, _meanBondLength));
                        yMax = Math.Max(yMax, thisCharacterPosition.Y + OoXmlHelper.ScaleCsTtfToCml(c.Height, _meanBondLength));

                        if (idx < atomLabel.Length - 1)
                        {
                            // Move to next Character position
                            cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength), 0);
                        }
                    }
                }

                #endregion Step 1 - Measure Bounding Box for all Characters of label

                #region Step 2 - Reset Cursor such that the text is centered about the atom's co-ordinates

                double width  = xMax - xMin;
                double height = yMax - yMin;
                cursorPosition        = new Point(atom.Position.X - width / 2, atom.Position.Y + height / 2);
                chargeCursorPosition  = new Point(cursorPosition.X, cursorPosition.Y);
                isotopeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                labelBounds           = new Rect(cursorPosition, new Size(width, height));

                #endregion Step 2 - Reset Cursor such that the text is centered about the atom's co-ordinates

                #region Step 3 - Place the characters

                foreach (char chr in atomLabel)
                {
                    TtfCharacter c = _TtfCharacterSet[chr];
                    if (c != null)
                    {
                        thisCharacterPosition = GetCharacterPosition(cursorPosition, c);
                        AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, c, atomColour, chr, atom.Path, atom.Parent.Path);
                        _AtomLabelCharacters.Add(alc);

                        // Move to next Character position
                        lastOffset = OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength);
                        cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength), 0);
                        chargeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                    }
                }

                #endregion Step 3 - Place the characters

                #region Determine NESW

                double        baFromNorth = Vector.AngleBetween(BasicGeometry.ScreenNorth, atom.BalancingVector(true));
                CompassPoints nesw        = CompassPoints.East;

                if (bondCount == 1)
                {
                    nesw = BasicGeometry.SnapTo2EW(baFromNorth);
                }
                else
                {
                    nesw = BasicGeometry.SnapTo4NESW(baFromNorth);
                }

                #endregion Determine NESW

                #region Step 4 - Add Charge if required

                if (iCharge != 0)
                {
                    TtfCharacter hydrogenCharacter = _TtfCharacterSet['H'];

                    char         sign = '.';
                    TtfCharacter chargeSignCharacter = null;
                    if (iCharge >= 1)
                    {
                        sign = '+';
                        chargeSignCharacter = _TtfCharacterSet['+'];
                    }
                    else if (iCharge <= 1)
                    {
                        sign = '-';
                        chargeSignCharacter = _TtfCharacterSet['-'];
                    }

                    if (iAbsCharge > 1)
                    {
                        string digits = iAbsCharge.ToString();
                        // Insert digits
                        foreach (char chr in digits)
                        {
                            TtfCharacter chargeValueCharacter = _TtfCharacterSet[chr];
                            thisCharacterPosition = GetCharacterPosition(chargeCursorPosition, chargeValueCharacter);

                            // Raise the superscript Character
                            thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(chargeValueCharacter.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));

                            AtomLabelCharacter alcc = new AtomLabelCharacter(thisCharacterPosition, chargeValueCharacter, atomColour, chr, atom.Path, atom.Parent.Path);
                            alcc.IsSmaller   = true;
                            alcc.IsSubScript = true;
                            _AtomLabelCharacters.Add(alcc);

                            // Move to next Character position
                            chargeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(chargeValueCharacter.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                            cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(chargeValueCharacter.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                        }
                    }

                    // Insert sign at raised position
                    thisCharacterPosition = GetCharacterPosition(chargeCursorPosition, chargeSignCharacter);
                    thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));
                    thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(chargeSignCharacter.Height / 2 * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));

                    AtomLabelCharacter alcs = new AtomLabelCharacter(thisCharacterPosition, chargeSignCharacter, atomColour, sign, atom.Path, atom.Parent.Path);
                    alcs.IsSmaller   = true;
                    alcs.IsSubScript = true;
                    _AtomLabelCharacters.Add(alcs);

                    if (iAbsCharge != 0)
                    {
                        cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(chargeSignCharacter.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                    }
                }

                #endregion Step 4 - Add Charge if required

                #region Step 5 - Add Implicit H if required

                if (options.ShowHydrogens && implicitHCount > 0)
                {
                    TtfCharacter hydrogenCharacter      = _TtfCharacterSet['H'];
                    string       numbers                = "012345";
                    TtfCharacter implicitValueCharacter = _TtfCharacterSet[numbers[implicitHCount]];

                    #region Add H

                    if (hydrogenCharacter != null)
                    {
                        switch (nesw)
                        {
                        case CompassPoints.North:
                            if (atom.Bonds.ToList().Count > 1)
                            {
                                cursorPosition.X = labelBounds.X
                                                   + (labelBounds.Width / 2)
                                                   - (OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width, _meanBondLength) / 2);
                                cursorPosition.Y = cursorPosition.Y
                                                   + OoXmlHelper.ScaleCsTtfToCml(-hydrogenCharacter.Height, _meanBondLength)
                                                   - OoXmlHelper.CHARACTER_VERTICAL_SPACING;
                                if (iCharge > 0)
                                {
                                    if (implicitHCount > 1)
                                    {
                                        cursorPosition.Offset(0,
                                                              OoXmlHelper.ScaleCsTtfToCml(
                                                                  -implicitValueCharacter.Height *
                                                                  OoXmlHelper.SUBSCRIPT_SCALE_FACTOR / 2, _meanBondLength)
                                                              - OoXmlHelper.CHARACTER_VERTICAL_SPACING);
                                    }
                                }
                            }
                            break;

                        case CompassPoints.East:
                            // Leave as is
                            break;

                        case CompassPoints.South:
                            if (atom.Bonds.ToList().Count > 1)
                            {
                                cursorPosition.X = labelBounds.X + (labelBounds.Width / 2)
                                                   - (OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width, _meanBondLength) / 2);
                                cursorPosition.Y = cursorPosition.Y
                                                   + OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height, _meanBondLength)
                                                   + OoXmlHelper.CHARACTER_VERTICAL_SPACING;
                            }
                            break;

                        case CompassPoints.West:
                            if (implicitHCount == 1)
                            {
                                if (iAbsCharge == 0)
                                {
                                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-(hydrogenCharacter.IncrementX * 2), _meanBondLength), 0);
                                }
                                else
                                {
                                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-((hydrogenCharacter.IncrementX * 2 + implicitValueCharacter.IncrementX * 1.25)), _meanBondLength), 0);
                                }
                            }
                            else
                            {
                                if (iAbsCharge == 0)
                                {
                                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-(hydrogenCharacter.IncrementX * 2.5), _meanBondLength), 0);
                                }
                                else
                                {
                                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(-((hydrogenCharacter.IncrementX * 2 + implicitValueCharacter.IncrementX * 1.25)), _meanBondLength), 0);
                                }
                            }
                            break;
                        }

                        thisCharacterPosition = GetCharacterPosition(cursorPosition, hydrogenCharacter);
                        AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, hydrogenCharacter, atomColour, 'H', atom.Path, atom.Parent.Path);
                        _AtomLabelCharacters.Add(alc);

                        // Move to next Character position
                        cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.IncrementX, _meanBondLength), 0);

                        if (nesw == CompassPoints.East)
                        {
                            chargeCursorPosition = new Point(cursorPosition.X, cursorPosition.Y);
                        }
                        if (nesw == CompassPoints.West)
                        {
                            isotopeCursorPosition = new Point(thisCharacterPosition.X, isotopeCursorPosition.Y);
                        }
                    }

                    #endregion Add H

                    #region Add number

                    if (implicitHCount > 1)
                    {
                        if (implicitValueCharacter != null)
                        {
                            thisCharacterPosition = GetCharacterPosition(cursorPosition, implicitValueCharacter);

                            // Drop the subscript Character
                            thisCharacterPosition.Offset(0, OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Width * OoXmlHelper.SUBSCRIPT_DROP_FACTOR, _meanBondLength));

                            AtomLabelCharacter alc = new AtomLabelCharacter(thisCharacterPosition, implicitValueCharacter, atomColour, numbers[implicitHCount], atom.Path, atom.Parent.Path);
                            alc.IsSmaller   = true;
                            alc.IsSubScript = true;
                            _AtomLabelCharacters.Add(alc);

                            // Move to next Character position
                            cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(implicitValueCharacter.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                        }
                    }

                    #endregion Add number
                }

                #endregion Step 5 - Add Implicit H if required

                #region Step 6 - Add IsoTope Number if required

                if (isoValue > 0)
                {
                    string digits = isoValue.ToString();

                    xMin = double.MaxValue;
                    yMin = double.MaxValue;
                    xMax = double.MinValue;
                    yMax = double.MinValue;

                    Point isoOrigin = isotopeCursorPosition;

                    // Calculate width of digits
                    foreach (char chr in digits)
                    {
                        TtfCharacter c = _TtfCharacterSet[chr];
                        thisCharacterPosition = GetCharacterPosition(isotopeCursorPosition, c);

                        // Raise the superscript Character
                        thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(c.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));

                        xMin = Math.Min(xMin, thisCharacterPosition.X);
                        yMin = Math.Min(yMin, thisCharacterPosition.Y);
                        xMax = Math.Max(xMax, thisCharacterPosition.X + OoXmlHelper.ScaleCsTtfToCml(c.Width, _meanBondLength));
                        yMax = Math.Max(yMax, thisCharacterPosition.Y + OoXmlHelper.ScaleCsTtfToCml(c.Height, _meanBondLength));

                        // Move to next Character position
                        isotopeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                    }

                    // Re-position Isotope Cursor
                    width = xMax - xMin;
                    isotopeCursorPosition = new Point(isoOrigin.X - width, isoOrigin.Y);

                    // Insert digits
                    foreach (char chr in digits)
                    {
                        TtfCharacter c = _TtfCharacterSet[chr];
                        thisCharacterPosition = GetCharacterPosition(isotopeCursorPosition, c);

                        // Raise the superscript Character
                        thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(c.Height * OoXmlHelper.CS_SUPERSCRIPT_RAISE_FACTOR, _meanBondLength));

                        AtomLabelCharacter alcc = new AtomLabelCharacter(thisCharacterPosition, c, atomColour, chr, atom.Path, atom.Parent.Path);
                        alcc.IsSmaller   = true;
                        alcc.IsSubScript = true;
                        _AtomLabelCharacters.Add(alcc);

                        // Move to next Character position
                        isotopeCursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(c.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                    }
                }

                #endregion Step 6 - Add IsoTope Number if required

                #region Step 7 - Create Convex Hull

                _convexhHulls.Add(atom.Path, ConvexHull(atom.Path));

                #endregion Step 7 - Create Convex Hull
            }
        }
Exemplo n.º 33
0
        public void CreateFunctionalGroupCharacters(Atom atom, Options options)
        {
            FunctionalGroup fg          = atom.Element as FunctionalGroup;
            double          baFromNorth = Vector.AngleBetween(BasicGeometry.ScreenNorth, atom.BalancingVector(true));

            CompassPoints nesw    = BasicGeometry.SnapTo2EW(baFromNorth);
            bool          reverse = nesw == CompassPoints.West;

            #region Set Up Atom Colours

            string atomColour = "000000";
            if (options.ColouredAtoms)
            {
                atomColour = fg.Colour;
                // Strip out # as OoXml does not use it
                atomColour = atomColour.Replace("#", "");
            }

            #endregion Set Up Atom Colours

            List <FunctionalGroupTerm> terms = fg.ExpandIntoTerms(reverse);

            #region Step 1 - Generate the characters and measure Bounding Boxes

            var cursorPosition = atom.Position;

            List <AtomLabelCharacter> fgCharacters = new List <AtomLabelCharacter>();
            TtfCharacter hydrogenCharacter         = _TtfCharacterSet['H'];

            Rect fgBoundingBox     = Rect.Empty;
            Rect anchorBoundingBox = Rect.Empty;

            foreach (var term in terms)
            {
                foreach (var part in term.Parts)
                {
                    foreach (char c in part.Text)
                    {
                        Rect bb = AddCharacter(c, part.Type);
                        fgBoundingBox.Union(bb);
                        if (term.IsAnchor)
                        {
                            anchorBoundingBox.Union(bb);
                        }
                    }
                }
            }

            #endregion Step 1 - Generate the characters and measure Bounding Boxes

            #region Step 2 - Move all characters such that the anchor term is centered on the atom position

            double offsetX;
            double offsetY;
            if (reverse)
            {
                offsetX = fgBoundingBox.Width - anchorBoundingBox.Width / 2;
                offsetY = anchorBoundingBox.Height / 2;
            }
            else
            {
                offsetX = anchorBoundingBox.Width / 2;
                offsetY = anchorBoundingBox.Height / 2;
            }

            offsetY = offsetY + anchorBoundingBox.Top - atom.Position.Y;

            foreach (var alc in fgCharacters)
            {
                alc.Position = new Point(alc.Position.X - offsetX, alc.Position.Y - offsetY);
            }

            #endregion Step 2 - Move all characters such that the anchor term is centered on the atom position

            #region Step 3 - Transfer characters into main list

            foreach (var alc in fgCharacters)
            {
                _AtomLabelCharacters.Add(alc);
            }

            #endregion Step 3 - Transfer characters into main list

            #region Step 4 - Convex Hull

            _convexhHulls.Add(atom.Path, ConvexHull(atom.Path));

            #endregion Step 4 - Convex Hull

            // Local Function
            Rect AddCharacter(char c, FunctionalGroupPartType type)
            {
                TtfCharacter ttf = _TtfCharacterSet[c];
                var          thisCharacterPosition = GetCharacterPosition(cursorPosition, ttf);
                var          alc = new AtomLabelCharacter(thisCharacterPosition, ttf, atomColour, c, atom.Path, atom.Parent.Path);

                alc.IsSubScript   = type == FunctionalGroupPartType.Subscript;
                alc.IsSuperScript = type == FunctionalGroupPartType.Superscript;
                alc.IsSmaller     = alc.IsSubScript || alc.IsSuperScript;

                Rect thisBoundingBox;

                if (alc.IsSmaller)
                {
                    // Start by assuming it's SubScript
                    thisCharacterPosition.Offset(0, OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height * OoXmlHelper.SUBSCRIPT_DROP_FACTOR, _meanBondLength));
                    if (alc.IsSuperScript)
                    {
                        // Shift up by height of H to make it SuperScript
                        thisCharacterPosition.Offset(0, -OoXmlHelper.ScaleCsTtfToCml(hydrogenCharacter.Height, _meanBondLength));
                    }

                    // Reset the character's position
                    alc.Position = thisCharacterPosition;

                    thisBoundingBox = new Rect(alc.Position,
                                               new Size(OoXmlHelper.ScaleCsTtfToCml(alc.Character.Width, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR,
                                                        OoXmlHelper.ScaleCsTtfToCml(alc.Character.Height, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR));

                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(alc.Character.IncrementX, _meanBondLength) * OoXmlHelper.SUBSCRIPT_SCALE_FACTOR, 0);
                }
                else
                {
                    thisBoundingBox = new Rect(alc.Position,
                                               new Size(OoXmlHelper.ScaleCsTtfToCml(alc.Character.Width, _meanBondLength),
                                                        OoXmlHelper.ScaleCsTtfToCml(alc.Character.Height, _meanBondLength)));

                    cursorPosition.Offset(OoXmlHelper.ScaleCsTtfToCml(alc.Character.IncrementX, _meanBondLength), 0);
                }

                fgCharacters.Add(alc);

                return(thisBoundingBox);
            }
        }
Exemplo n.º 34
0
 public idiso(ContentId id, Atom isoLang)
 {
     Id      = id;
     IsoLang = isoLang;
 }
Exemplo n.º 35
0
 public Block(Atom atomicData, Image image)
 {
     AtomicData = atomicData;
     Image      = image;
 }
Exemplo n.º 36
0
 private void DeleteAsSubatom(JobStorageTransaction jst, string atomId, string subatomId)
 {
     jst.RemoveFromSet(Atom.GenerateSubAtomKeys(atomId), subatomId);
     jst.RemoveFromSet(Atom.GenerateSubAtomRemainingKeys(atomId), subatomId);
 }
Exemplo n.º 37
0
 public Block(byte x, byte y, Transform transform, Image image)
 {
     AtomicData = new Atom(x, y, 1.0f, 0.0f, transform);
     Image      = image;
 }
Exemplo n.º 38
0
            public IEnumerator <TaskStatus> OntopElabProc(MentalTask bwxTask, Atom x, Atom y)
            {
                Task       _bwxTask    = null;
                Context    _bwxContext = null;
                Message    _bwxMsg;
                Clause     _bwxClause  = null;
                Atom       _bwxSubject = null;
                TaskResult _bwxResult  = null;

                Begin(bwxTask);
                {
                    if (y.TypeCheck(Ent_Block) && bwxTask.Context.Exists(y, Ent_isClear, true))
                    {
                        {
                            _bwxMsg = new Message(MessageKind.Remove, null, null, new Clause(Ent_Belief, y, Ent_isClear, true));
                            Post(bwxTask.Process, _bwxMsg);
                        }
                    }
                }
                {
                    if (bwxTask.Context.Exists(x, Ent_onTop, y))
                    {
                        {
                            _bwxMsg = new Message(MessageKind.Add, null, null, new Clause(Ent_Belief, y, Ent_beneath, x));
                            Post(bwxTask.Process, _bwxMsg);
                        }
                    }
                }
                yield return(Succeed(bwxTask.Process, bwxTask.Message));
            }
Exemplo n.º 39
0
        protected void ConnectToServerCallback()
        {
            //  Close any established socket server connection
            if (client != null)
            {
                DisconnectFromServerCallback();
            }

            try
            {
                // Connects to the UI selected server:port with the corresponding selected protocol
                IPHostEntry ipHostEntry = Dns.GetHostEntry(serverChooser.val);
                IPAddress   ipAddress   = Array.Find(ipHostEntry.AddressList, ip => ip.AddressFamily == AddressFamily.InterNetwork);
                // SuperController.LogMessage(ipHostEntry.AddressList[0].ToString());
                IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, int.Parse(portChooser.val));

                if (protocolChooser.val == "TCP")
                {
                    client = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                    client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                }
                else if (protocolChooser.val == "UDP")
                {
                    client = new Socket(ipAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
                }

                client.Connect(ipEndPoint);

                SuperController.LogMessage("Connected to server: " + serverChooser.val + ":" + portChooser.val + ".");

                // Send initial player data to the server
                foreach (string playerName in playerList)
                {
                    string response = SendToServer(playerName + "|");

                    SuperController.LogMessage(response);

                    Atom playerAtom = SuperController.singleton.GetAtomByUid(playerName);

                    // Find correct player in the List
                    int    playerIndex = players.FindIndex(p => p.playerName == playerName);
                    Player player      = players[playerIndex];

                    // Update only changed target positions and rotations for the main player
                    foreach (Player.TargetData target in player.playerTargets)
                    {
                        if ((target.targetName == "control") || (target.targetName == "headControl") || (target.targetName == "chestControl") || (target.targetName == "hipControl") || (target.targetName == "lFootControl") || (target.targetName == "rFootControl") || (target.targetName == "lHandControl") || (target.targetName == "rHandControl"))
                        {
                            FreeControllerV3 targetObject = playerAtom.GetStorableByID(target.targetName) as FreeControllerV3;

                            // Send main player's target position and rotation data to the server to be recorded
                            response = SendToServer(playerName + "," + target.targetName + "," + target.position.x.ToString() + "," + target.position.y.ToString() + "," + target.position.z.ToString() + "," + target.rotation.w.ToString() + "," + target.rotation.x.ToString() + "," + target.rotation.y.ToString() + "," + target.rotation.z.ToString() + "|");

                            SuperController.LogMessage(response);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }
Exemplo n.º 40
0
            public IEnumerator <TaskStatus> NotOnTopElabProc(MentalTask bwxTask, Atom x, Atom y)
            {
                Task       _bwxTask    = null;
                Context    _bwxContext = null;
                Message    _bwxMsg;
                Clause     _bwxClause  = null;
                Atom       _bwxSubject = null;
                TaskResult _bwxResult  = null;

                Begin(bwxTask);
                _bwxMsg = new Message(MessageKind.Remove, null, null, new Clause(Ent_Belief, y, Ent_beneath, x));
                Post(bwxTask.Process, _bwxMsg);
                _bwxMsg = new Message(MessageKind.Add, null, null, new Clause(Ent_Belief, y, Ent_isClear, true));
                Post(bwxTask.Process, _bwxMsg);
                yield return(Succeed(bwxTask.Process, bwxTask.Message));
            }
Exemplo n.º 41
0
            public IEnumerator <TaskStatus> AchieveXonYProc(MentalTask bwxTask, Atom g, Atom x, Atom y)
            {
                Task       _bwxTask    = null;
                Context    _bwxContext = null;
                Message    _bwxMsg;
                Clause     _bwxClause  = null;
                Atom       _bwxSubject = null;
                TaskResult _bwxResult  = null;

                Begin(bwxTask);
                _bwxMsg = new Message(MessageKind.Attempt, null, null, new Clause(Ent_Perform, Ent_Self, Ent_stack, x)
                {
                    { Ent_on, y }
                });
                Post(bwxTask.Process, _bwxMsg);
                _bwxMsg = new Message(MessageKind.Remove, null, null, (Clause)g);
                Post(bwxTask.Process, _bwxMsg);
                yield return(Succeed(bwxTask.Process, bwxTask.Message));
            }
Exemplo n.º 42
0
            public IEnumerator <TaskStatus> StackProc(MentalTask bwxTask, Atom x, Atom y)
            {
                Task       _bwxTask    = null;
                Context    _bwxContext = null;
                Message    _bwxMsg;
                Clause     _bwxClause  = null;
                Atom       _bwxSubject = null;
                TaskResult _bwxResult  = null;

                Begin(bwxTask);
                {
                    ControlFlags _bwxQflags = ControlFlags.None;
                    {
                        if (!bwxTask.Context.Exists(x, Ent_isClear, true))
                        {
                            _bwxQflags |= ControlFlags.PartialSuccess;
                            {
                                _bwxMsg = new Message(MessageKind.Attempt, null, null, new Clause(Ent_Perform, Ent_Self, Ent_clear, x));
                                Post(bwxTask.Process, _bwxMsg);
                            }
                        }
                        else
                        {
                            _bwxQflags |= ControlFlags.PartialFailure;
                        }
                    }
                    if (_bwxQflags == ControlFlags.PartialSuccess)
                    {
                        {
                            yield return(Fail(bwxTask.Process, bwxTask.Message));
                        }
                    }
                }
                {
                    ControlFlags _bwxQflags = ControlFlags.None;
                    {
                        if (!bwxTask.Context.Exists(y, Ent_isClear, true))
                        {
                            _bwxQflags |= ControlFlags.PartialSuccess;
                            {
                                _bwxMsg = new Message(MessageKind.Attempt, null, null, new Clause(Ent_Perform, Ent_Self, Ent_clear, y));
                                Post(bwxTask.Process, _bwxMsg);
                            }
                        }
                        else
                        {
                            _bwxQflags |= ControlFlags.PartialFailure;
                        }
                    }
                    if (_bwxQflags == ControlFlags.PartialSuccess)
                    {
                        {
                            yield return(Fail(bwxTask.Process, bwxTask.Message));
                        }
                    }
                }
                {
                    foreach (Atom z in bwxTask.Context.QuerySubjPred <Atom>(x, Ent_onTop))
                    {
                        {
                            _bwxMsg = new Message(MessageKind.Remove, null, null, new Clause(Ent_Belief, x, Ent_onTop, z));
                            Post(bwxTask.Process, _bwxMsg);
                        }
                    }
                }
                _bwxMsg = new Message(MessageKind.Add, null, null, new Clause(Ent_Belief, x, Ent_onTop, y));
                Post(bwxTask.Process, _bwxMsg);
                yield return(Succeed(bwxTask.Process, bwxTask.Message));
            }