Exemplo n.º 1
0
        private static bool UsesFun(Axiom axiom, Function fun)
        {
            var visitor = new FunctionIsReferencedVisitor(fun);

            visitor.VisitAxiom(axiom);
            return(visitor.Found);
        }
Exemplo n.º 2
0
        public void AddAxiom(Axiom axiom)
        {
            string axiomName = QKeyValue.FindStringAttribute(axiom.Attributes, "name");

            if (axiomName == null)
            {
                return;
            }
            var previous = (Axiom)axioms[axiomName];

            if (previous == null)
            {
                axioms.Add(axiomName, axiom);
            }
            else
            {
                var r = (Axiom)SelectNonExtern(axiom, previous);
                if (r == null)
                {
                    Error(axiom, "more than one declaration of axiom name: {0}", axiomName);
                }
                else
                {
                    axioms[axiomName] = r;
                }
            }
        }
Exemplo n.º 3
0
        public void TestAddCardAddsTheCardToThePalette()
        {
            // ARRANGE
            IAxiom        axiom = new Axiom();
            IList <ICard> cards = new List <ICard>
            {
                new Card(Colour.Orange, Number.Three, axiom),
                new Card(Colour.Blue, Number.Seven, axiom),
                new Card(Colour.Red, Number.One, axiom)
            };
            ICard    card    = new Card(Colour.Violet, Number.Four, axiom);
            IPalette palette = new Palette(cards);

            // ACT
            palette.AddCard(card);

            // ASSERT
            Assert.AreEqual(expected: cards.Count + 1, actual: palette.Cards.Count);

            bool found = palette.Cards
                         .Where(c => c.Colour == card.Colour)
                         .Any(c => c.Number == card.Number);

            Assert.IsTrue(found, "Card exists");
        }
Exemplo n.º 4
0
        public override void AddAxiom(Axiom ax, string attributes)
        {
            //Contract.Requires(ax != null);
            base.AddAxiom(ax, attributes);

            axiomConjuncts.Add(translator.Translate(ax.Expr));
        }
Exemplo n.º 5
0
        public void AssertParseMethod042()
        {
            // Arrange
            const string text = @"Awaiting authorization permits with work Description ""Some description"".";

            var sentences = SentenceParser.Parse(new Parser(text));

            // Act
            var actual = EvisionLanguageProcessor.Processor.Parse(sentences.First());

            // Assert
            var expected = new QueryDefinition
            {
                Target     = "permit",
                Properties = new List <AttributeDefinition>
                {
                    new AttributeDefinition(Create(TokenKind.None, "state", -1), new MultipartToken
                    {
                        CreateToken(TokenKind.None, "Awaiting", 0),
                        CreateToken(TokenKind.None, "authorization", 1),
                    }),
                    new AttributeDefinition(new MultipartToken
                    {
                        CreateToken(TokenKind.None, "work", 4),
                        CreateToken(TokenKind.None, "Description", 5),
                    }, Create(TokenKind.None, "\"Some description\"", 6)),
                },
            };

            Axiom.AssertAreEqual(expected, actual);
        }
Exemplo n.º 6
0
        public void AssertParseMethod018()
        {
            // Arrange
            const string text = @"permits of type Cold worK .";

            var sentences = SentenceParser.Parse(new Parser(text));

            // Act
            var actual = EvisionLanguageProcessor.Processor.Parse(sentences.First());

            // Assert
            var expected = new QueryDefinition
            {
                Target     = "permit",
                Properties = new List <AttributeDefinition>
                {
                    new AttributeDefinition(Create(TokenKind.None, "type", 2), new MultipartToken
                    {
                        CreateToken(TokenKind.None, "Cold", 3),
                        CreateToken(TokenKind.None, "worK", 4),
                    }),
                },
            };

            Axiom.AssertAreEqual(expected, actual);
        }
Exemplo n.º 7
0
        public void AssertParseMethod034()
        {
            // Arrange
            const string text = @"awaiting authorization Permits signEd last week.";

            var sentences = SentenceParser.Parse(new Parser(text));

            // Act
            var actual = EvisionLanguageProcessor.Processor.Parse(sentences.First());

            // Assert
            var expected = new QueryDefinition
            {
                Target     = "permit",
                Properties = new List <AttributeDefinition>
                {
                    new AttributeDefinition(Create(TokenKind.None, "state", -1), new MultipartToken
                    {
                        CreateToken(TokenKind.None, "awaiting", 0),
                        CreateToken(TokenKind.None, "authorization", 1),
                    }),
                    new AttributeDefinition(Create(TokenKind.None, "signEd", 3), new MultipartToken
                    {
                        CreateToken(TokenKind.None, "last", 4),
                        CreateToken(TokenKind.None, "week", 5),
                    }),
                },
            };

            Axiom.AssertAreEqual(expected, actual);
        }
Exemplo n.º 8
0
        public void AssertParseMethod041()
        {
            // Arrange
            const string text = @"awaiting authorization Isolations signEd one year ago titled a.";

            var sentences = SentenceParser.Parse(new Parser(text));

            // Act
            var actual = EvisionLanguageProcessor.Processor.Parse(sentences.First());

            // Assert
            var expected = new QueryDefinition
            {
                Target     = "isolation",
                Properties = new List <AttributeDefinition>
                {
                    new AttributeDefinition(Create(TokenKind.None, "state", -1), new MultipartToken
                    {
                        CreateToken(TokenKind.None, "awaiting", 0),
                        CreateToken(TokenKind.None, "authorization", 1),
                    }),
                    new AttributeDefinition(Create(TokenKind.None, "signEd", 3), new MultipartToken
                    {
                        CreateToken(TokenKind.None, "one", 4),
                        CreateToken(TokenKind.None, "year", 5),
                        CreateToken(TokenKind.None, "ago", 6),
                    }),
                    new AttributeDefinition(Create(TokenKind.None, "titled", 7), Create(TokenKind.None, "a", 8)),
                },
            };

            Axiom.AssertAreEqual(expected, actual);
        }
Exemplo n.º 9
0
        public void TestAddNullCardThrowsArgumentNullException()
        {
            // ARRANGE
            IAxiom  axiom  = new Axiom();
            ICanvas canvas = new Canvas(axiom);

            // ACT
            ArgumentNullException argumentNullException = null;

            try
            {
                canvas.AddCard(null);
            }
            catch (ArgumentNullException ex)
            {
                argumentNullException = ex;
            }

            if (argumentNullException != null)
            {
                Console.WriteLine(argumentNullException.ToString());
            }

            // ASSERT
            Assert.IsNotNull(argumentNullException);
        }
Exemplo n.º 10
0
 private static void GenAxioms(Formula target, HashSet <Formula> formulas, Axiom a, Inference inference, HashSet <Formula> newF)
 {
     foreach (var f1 in formulas)
     {
         foreach (var f2 in formulas)
         {
             foreach (var f3 in formulas)
             {
                 var f = SubstituteInFormula(a, f1, f2, f3);
                 if (f.Equals(target) == false)
                 {
                     var ok = true;
                     lock (inference)
                     {
                         ok = inference.Push(f);
                     }
                     if (ok)
                     {
                         ParseFormula(f, newF);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
        public void TestScoringCards()
        {
            // ARRANGE
            IAxiom axiom = new Axiom();

            IList <ICard> cards = new List <ICard>
            {
                new Card(Colour.Blue, Number.Five, axiom),
                new Card(Colour.Red, Number.Seven, axiom),
                new Card(Colour.Green, Number.Seven, axiom),
                new Card(Colour.Blue, Number.Two, axiom),
            };

            IRule redRule = new RedRule();

            IPalette palette = new Palette(cards);

            // ACT
            IList <ICard> scoringCards = redRule.ScoringCards(palette);

            // ASSERT
            Assert.IsNotNull(scoringCards);
            Assert.AreEqual(expected: 1, scoringCards.Count);
            ICard card = scoringCards.Single();

            Assert.AreEqual(Colour.Red, card.Colour);
            Assert.AreEqual(Number.Seven, card.Number);
        }
Exemplo n.º 12
0
        public void AssertParseMethod033()
        {
            // Arrange
            const string text = @"coLd woRk Permits signEd five days ago.";

            var sentences = SentenceParser.Parse(new Parser(text));

            // Act
            var actual = EvisionLanguageProcessor.Processor.Parse(sentences.First());

            // Assert
            var expected = new QueryDefinition
            {
                Target     = "permit",
                Properties = new List <AttributeDefinition>
                {
                    new AttributeDefinition(Create(TokenKind.None, "type", -1), new MultipartToken
                    {
                        CreateToken(TokenKind.None, "coLd", 0),
                        CreateToken(TokenKind.None, "woRk", 1),
                    }),
                    new AttributeDefinition(Create(TokenKind.None, "signEd", 3), new MultipartToken
                    {
                        CreateToken(TokenKind.None, "five", 4),
                        CreateToken(TokenKind.None, "days", 5),
                        CreateToken(TokenKind.None, "ago", 6),
                    }),
                },
            };

            Axiom.AssertAreEqual(expected, actual);
        }
Exemplo n.º 13
0
        public void AssertParseMethod003()
        {
            // Arrange
            const string text = @"Permits with title ""Some Title"" signed by evision and in state ""c""";

            var sentences = SentenceParser.Parse(new Parser(text));

            // Act
            var actual = EvisionLanguageProcessor.Processor.Parse(sentences.First());

            // Assert
            var expected = new QueryDefinition
            {
                Target     = "permit",
                Properties = new List <AttributeDefinition>
                {
                    new AttributeDefinition(Create(TokenKind.None, "title", 2), Create(TokenKind.None, "\"Some Title\"", 3)),
                    new AttributeDefinition(new MultipartToken
                    {
                        CreateToken(TokenKind.None, "signed", 4),
                        CreateToken(TokenKind.Owner, "by", 5),
                    }, Create(TokenKind.None, "evision", 6)),
                    new AttributeDefinition(Create(TokenKind.None, "state", 9), Create(TokenKind.None, "\"c\"", 10)),
                },
            };

            Axiom.AssertAreEqual(expected, actual);
        }
Exemplo n.º 14
0
        public void TestScore()
        {
            // ARRANGE
            IAxiom axiom = new Axiom();

            IList <ICard> cards = new List <ICard>
            {
                new Card(Colour.Blue, Number.Five, axiom),
                new Card(Colour.Red, Number.Seven, axiom),
                new Card(Colour.Red, Number.Six, axiom),
                new Card(Colour.Red, Number.Two, axiom),
                new Card(Colour.Green, Number.Seven, axiom),
                new Card(Colour.Blue, Number.Two, axiom),
            };

            IRule greenRule = new GreenRule(axiom);

            IPalette palette = new Palette(cards);

            // ACT
            IRuleScore ruleScore = greenRule.Score(palette);

            // ASSERT
            Assert.IsNotNull(ruleScore);
            Assert.AreEqual(expected: 3, actual: ruleScore.NumberOfCards);
            Assert.IsNotNull(ruleScore.TopCard);
            Assert.AreEqual(Colour.Red, ruleScore.TopCard.Colour);
            Assert.AreEqual(Number.Six, ruleScore.TopCard.Number);
        }
Exemplo n.º 15
0
        public void TestScoringCards()
        {
            // ARRANGE
            IAxiom axiom = new Axiom();

            IList <ICard> cards = new List <ICard>
            {
                new Card(Colour.Blue, Number.Five, axiom),
                new Card(Colour.Red, Number.Four, axiom),
                new Card(Colour.Green, Number.Four, axiom),
                new Card(Colour.Blue, Number.Two, axiom),
            };

            IList <ICard> expectedScoringCards = new List <ICard>
            {
                new Card(Colour.Red, Number.Four, axiom),
                new Card(Colour.Green, Number.Four, axiom),
            };

            IRule orangeRule = new OrangeRule();

            IPalette palette = new Palette(cards);

            // ACT
            IList <ICard> scoringCards = orangeRule.ScoringCards(palette);

            // ASSERT
            Assert.IsNotNull(scoringCards);
            Assert.AreEqual(expected: 2, scoringCards.Count);

            foreach (ICard card in expectedScoringCards)
            {
                Assert.IsTrue(scoringCards.Any(c => c.CompareTo(card) == 0), card.ToString());
            }
        }
Exemplo n.º 16
0
        private static void GenAxiom(Inference inference, List <Formula> formulas, HashSet <Formula> allFormulas,
                                     Formula target, Axiom a)
        {
            foreach (var f1 in formulas)
            {
                foreach (var f2 in formulas)
                {
                    foreach (var f3 in formulas)
                    {
                        var f = SubstituteInFormula(a, f1, f2, f3);
                        if (f.Equals(target))
                        {
                            continue;
                        }
                        bool ok;
                        lock (inference)
                        {
                            if (inference.Contains(target))
                            {
                                return;
                            }
                            ok = inference.Push(f);
                        }

                        lock (allFormulas)
                        {
                            if (ok)
                            {
                                ParseFormula(f, allFormulas);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void TestAddDuplicateCardThrowsAnException()
        {
            // ARRANGE
            IAxiom        axiom = new Axiom();
            IList <ICard> cards = new List <ICard>
            {
                new Card(Colour.Orange, Number.Three, axiom),
                new Card(Colour.Blue, Number.Seven, axiom),
                new Card(Colour.Red, Number.One, axiom)
            };
            ICard    duplicateCard = new Card(Colour.Orange, Number.Three, axiom);
            IPalette palette       = new Palette(cards);

            // ACT
            ArgumentException argumentException = null;

            try
            {
                palette.AddCard(duplicateCard);
            }
            catch (ArgumentException ex)
            {
                argumentException = ex;
            }

            // ASSERT
            if (argumentException != null)
            {
                Console.WriteLine(argumentException.ToString());
            }

            Assert.IsNotNull(argumentException, "Expected exception not thrown");
        }
Exemplo n.º 18
0
 public virtual Axiom VisitAxiom(Axiom node)
 {
     Contract.Requires(node != null);
     Contract.Ensures(Contract.Result <Axiom>() != null);
     node.Expr = this.VisitExpr(node.Expr);
     return(node);
 }
Exemplo n.º 19
0
    void Start()
    {
        vector       = new Vector();
        savedVectors = new List <Vector>();

        allRules = new List <RuleSet>();

        axiom = Rule.GetRulesFromString("I");

        sizeLine         = Random.Range(2f, 7.5f);
        widthLine        = Random.Range(sizeLine / 2, sizeLine * 2);
        angle            = Random.Range(40f, 80f);
        widthScaleFactor = Random.Range(0.9f, 0.98f);

        rules = new RuleSet();
        rules.AddRule('I', "FS");
        rules.AddRule('S', "[[F-F+&SF*]F&[^F+F-FS]]");
        allRules.Add(rules);

        rules = new RuleSet();
        rules.AddRule('I', "FFS");
        rules.AddRule('S', "F[+F&-F+F-F^F*][-^&F+[F-F^F&+^F*]*]");
        allRules.Add(rules);

        foreach (Rule r in axiom)
        {
            r.Run(this);
        }
    }
Exemplo n.º 20
0
    /// <summary>method <c>CacheGenerationalInstructions</c> Final generation string is calculated and cached globally in the script  </summary>
    void CacheGenerationalInstructions()
    {
        currentString = Axiom.ToString(); //start with the base axiom
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < CurrentIteration; i++)
        {
            foreach (char c in currentString)
            {
                if (isStochastic)
                {
                    sb.Append(ApplyStochasticProbablity(c)); //append randomised character set
                }
                else
                {
                    sb.Append(parcelableRules.ContainsKey(c) ? parcelableRules[c] : c.ToString()); //append default character
                }
            }

            currentString = sb.ToString();
            sb.Clear(); //temp string to add is cleared
        }

        preloadedInstructions = currentString; //instructions are updated

        if (isStochastic)
        {
            isStochastic = false; //to stop continual generation this value is stopped until clicked from the HUD script
        }
    }
Exemplo n.º 21
0
        public void TestCompareToNullThrowsException()
        {
            // ARRANGE
            IAxiom     axiom         = new Axiom();
            ICard      topCard       = new Card(Colour.Green, Number.Four, axiom);
            const int  numberOfCards = 4;
            IRuleScore ruleScore     = new RuleScore(numberOfCards, topCard);

            // ACT
            ArgumentNullException argumentNullException = null;
            int comparison = 99;

            try
            {
                comparison = ruleScore.CompareTo(null);
            }
            catch (ArgumentNullException exception)
            {
                argumentNullException = exception;
            }

            // ASSERT
            if (argumentNullException != null)
            {
                Console.WriteLine(argumentNullException.ToString());
            }

            Assert.IsNotNull(argumentNullException);
            Assert.AreEqual(expected: 99, actual: comparison);
        }
        public static Expr Extract(Expr expr, Program program, List <Axiom> axioms)
        {
            Contract.Requires(expr != null && program != null && !program.TopLevelDeclarationsAreFrozen && axioms != null);

            if (expr is LiteralExpr)
            {
                return(expr);
            }

            var extractor = new FunctionExtractor();

            var body = extractor.VisitExpr(expr);

            var name         = program.FreshExtractedFunctionName();
            var originalVars = extractor.Substitutions.Keys.ToList();
            var formalInArgs = originalVars.Select(v => new Formal(Token.NoToken, new TypedIdent(Token.NoToken, extractor.Substitutions[v].Name, extractor.Substitutions[v].TypedIdent.Type), true)).ToList <Variable>();
            var formalOutArg = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, name + "$result$", expr.Type), false);
            var func         = new Function(Token.NoToken, name, formalInArgs, formalOutArg);

            func.AddAttribute("never_pattern");

            var boundVars = originalVars.Select(k => extractor.Substitutions[k]);
            var axiomCall = new NAryExpr(Token.NoToken, new FunctionCall(func), boundVars.Select(b => new IdentifierExpr(Token.NoToken, b)).ToList <Expr>());

            axiomCall.Type           = expr.Type;
            axiomCall.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
            var eq = LiteralExpr.Eq(axiomCall, body);

            eq.Type           = body.Type;
            eq.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
            if (0 < formalInArgs.Count)
            {
                var forallExpr = new ForallExpr(Token.NoToken, boundVars.ToList <Variable>(), new Trigger(Token.NoToken, true, new List <Expr> {
                    axiomCall
                }), eq);
                body = forallExpr;
                forallExpr.Attributes = new QKeyValue(Token.NoToken, "weight", new List <object> {
                    new LiteralExpr(Token.NoToken, Basetypes.BigNum.FromInt(30))
                }, null);
                body.Type = Type.Bool;
            }
            else
            {
                body = eq;
            }

            var axiom = new Axiom(Token.NoToken, body);

            func.DefinitionAxiom = axiom;
            program.AddTopLevelDeclaration(func);
            program.AddTopLevelDeclaration(axiom);
            axioms.Add(axiom);

            var call = new NAryExpr(Token.NoToken, new FunctionCall(func), originalVars.Select(v => new IdentifierExpr(Token.NoToken, v)).ToList <Expr>());

            call.Type           = expr.Type;
            call.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
            return(call);
        }
Exemplo n.º 23
0
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         axiom = LSystem.Iterate(axiom, this);
         Debug.Log(axiom);
     }
 }
Exemplo n.º 24
0
        public void TestRunsAreOfCorrectLength(int index, int expectedLength)
        {
            // ACT
            IAxiom axiom = new Axiom();

            // ASSERT
            Assert.IsTrue(index < axiom.Runs.Count);
            Assert.AreEqual(expectedLength, axiom.Runs[index].Length);
        }
Exemplo n.º 25
0
		void Input_KeyDown(object sender, Axiom.Input.KeyEventArgs e)
		{
			if (e.Key == KeyCodes.Escape)
			{
				Environment.Exit(Environment.ExitCode);
			}


			Core.BrowserManager[_browserId].KeyDown(CreateWebKeyboardEvent(e, WebKeyType.KeyDown));
		}
Exemplo n.º 26
0
        public override void CheckMouseButtonPressed( Axiom.Input.MouseButtons button, out bool isPressed )
        {
            isPressed = false;

            if ( button == Axiom.Input.MouseButtons.Left || _gpState.IsButtonDown( XInput.Buttons.A ) )
                isPressed = true;

            if ( button == Axiom.Input.MouseButtons.Right || _gpState.IsButtonDown( XInput.Buttons.B ) )
                isPressed = true;
        }
Exemplo n.º 27
0
 private Microsoft.Xna.Framework.Input.Keys Convert( Axiom.Input.KeyCodes key )
 {
     switch ( key )
     {
         case Axiom.Input.KeyCodes.G:
             return Microsoft.Xna.Framework.Input.Keys.G;
         default:
             return Microsoft.Xna.Framework.Input.Keys.BrowserFavorites;
     }
 }
Exemplo n.º 28
0
        public override void CheckMouseButtonPressed( Axiom.Input.MouseButtons button, out bool isPressed )
        {
            isPressed = false;

            if ( button == Axiom.Input.MouseButtons.Left && _mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed )
                isPressed = true;

            if ( button == Axiom.Input.MouseButtons.Right && _mouseState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed )
                isPressed = true;
        }
Exemplo n.º 29
0
		WebKeyboardEvent CreateWebKeyboardEvent(Axiom.Input.KeyEventArgs e, WebKeyType type)
		{
			return new WebKeyboardEvent()
			{
				IsSystemKey = false,
				Type = type,
				Modifiers = AwesomiumUtil.ConvertModifierKeys(e.Modifiers),
				VirtualKeyCode = AwesomiumUtil.ConvertKeyCodesToVirtualKey(e.Key)
			};

		}
Exemplo n.º 30
0
        public void TestConstructor()
        {
            // ARRANGE
            IAxiom axiom = new Axiom();

            // ACT
            ICanvas actualCanvas = new Canvas(axiom);

            // ASSERT
            Assert.IsNotNull(actualCanvas);
        }
        private FilterViewModel CreateFilterViewModel(string propertyName, string startValue, string endValue = "", Axiom.Common.Enumerations.FilterCondition condition = Axiom.Common.Enumerations.FilterCondition.Equals)
        {
            FilterViewModel filter = new FilterViewModel();
            filter.PropertyName = propertyName;
            filter.StartValue = startValue;
            if (!string.IsNullOrEmpty(endValue))
                filter.EndValue = endValue;
            filter.WhereCondition = Axiom.Common.Enumerations.PredicateCondition.And;
            filter.FilterCondition = condition;

            return filter;
        }
Exemplo n.º 32
0
        public void TestConstructor()
        {
            // ARRANGE
            IAxiom axiom = new Axiom();

            // ACT
            IRule greenRule = new GreenRule(axiom);

            // ASSERT
            Assert.AreEqual("Most even cards wins", greenRule.Description);
            Assert.AreEqual(Colour.Green, greenRule.Colour);
        }
Exemplo n.º 33
0
		WebKeyboardEvent CreateWebKeyboardEvent(Axiom.Input.KeyEventArgs e)
		{
			return new WebKeyboardEvent()
			{
				IsSystemKey = false,
				Text = new ushort[] { (ushort)e.KeyChar, 0, 0, 0 },
				Type = WebKeyType.Char,
				Modifiers = AwesomiumUtil.ConvertModifierKeys(e.Modifiers),
				VirtualKeyCode = VirtualKey.UNKNOWN
			};

		}
Exemplo n.º 34
0
        public void TestConstructor()
        {
            // ARRANGE
            IAxiom axiom = new Axiom();

            // ACT
            IRule indigoRule = new IndigoRule(axiom);

            // ASSERT
            Assert.AreEqual("Most cards in a run", indigoRule.Description);
            Assert.AreEqual(Colour.Indigo, indigoRule.Colour);
        }
		protected void CompleteDefInfo( GLenum glType, Axiom.Graphics.GpuProgramParameters.GpuConstantDefinition defToUpdate )
		{
			//Decode unifrom size and type
			//Note GLSL ES never packs rows into float4's (from an API perspective anyway)
			//therefore all values are tight in the buffer
			switch ( glType )
			{
				case GLenum.Float:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float1;
					break;
				case GLenum.FloatVec2:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float2;
					break;
				case GLenum.FloatVec3:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float3;
					break;
				case GLenum.FloatVec4:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Float4;
					break;
				case GLenum.Sampler2D:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Sampler2D;
					break;
				case GLenum.SamplerCube:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.SamplerCube;
					break;
				case GLenum.Int:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int1;
					break;
				case GLenum.IntVec2:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int2;
					break;
				case GLenum.IntVec3:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int3;
					break;
				case GLenum.IntVec4:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Int4;
					break;
				case GLenum.FloatMat2:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X2;
					break;
				case GLenum.FloatMat3:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X3;
					break;
				case GLenum.FloatMat4:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Unknown;
					break;
				default:
					defToUpdate.ConstantType = GpuProgramParameters.GpuConstantType.Unknown;
					break;
			}
			//GL doesn't pad
			defToUpdate.ElementSize = Axiom.Graphics.GpuProgramParameters.GpuConstantDefinition.GetElementSize( defToUpdate.ConstantType, false );
		}
Exemplo n.º 36
0
        public void TestRunsPopulated()
        {
            // ARRANGE
            const int expectedRunCount = 21;

            // ACT
            IAxiom axiom = new Axiom();

            // ASSERT
            Assert.IsTrue(axiom.Runs.Any());
            Assert.AreEqual(expectedRunCount, axiom.Runs.Count);
        }
        public void TestInitialNumberOfCardsInPalette()
        {
            // ASSERT
            const int expectedInitialNumberOfCardsInPalette = 1;

            // ACT
            IAxiom axiom = new Axiom();
            int    actualInitialNumberOfCardsInPalette = axiom.InitialNumberOfCardsInPalette;

            // ASSERT
            Assert.AreEqual(expectedInitialNumberOfCardsInPalette, actualInitialNumberOfCardsInPalette);
        }
Exemplo n.º 38
0
        public void TestForEachColourReturnsCorrectRule(Colour colour)
        {
            // ARRANGE
            IAxiom axiom = new Axiom();

            // ACT
            IRule actualRule = axiom.GetRule(colour);

            // ASSERT
            Assert.IsNotNull(actualRule);
            Assert.AreEqual(colour, actualRule.Colour);
        }
Exemplo n.º 39
0
        public override void CheckKeyPressed( Axiom.Input.KeyCodes key, out bool isPressed )
        {
            isPressed = false;

            if ( key == Axiom.Input.KeyCodes.Escape || ( _gpState.IsButtonDown( XInput.Buttons.Back ) ) )
            {
                isPressed = true;
                return;
            }

            XFG.Input.Keys xnaKey = Convert( key );

            isPressed = !_keyboardState.IsKeyUp( xnaKey );
        }
        ///<summary>
        ///    Should be called by HardwareBufferManager
        ///</summary>
        public HardwarePixelBuffer(int width, int height, int depth,
								   Axiom.Media.PixelFormat format, BufferUsage usage, 
								   bool useSystemMemory, bool useShadowBuffer)
            : base(usage, useSystemMemory, useShadowBuffer)
        {
            this.width = width;
            this.height = height;
            this.depth = depth;
            this.format = format;
            // Default
            rowPitch = width;
            slicePitch = height * width;
            sizeInBytes = height * width * depth * PixelUtil.GetNumElemBytes(format);
        }
Exemplo n.º 41
0
		void Input_KeyUp(object sender, Axiom.Input.KeyEventArgs e)
		{
			Core.BrowserManager[_browserId].KeyUp(CreateWebKeyboardEvent(e, WebKeyType.KeyUp));
			Core.BrowserManager[_browserId].KeyPress(CreateWebKeyboardEvent(e));

            if (e.Key == KeyCodes.A)
            {
                _sceneNode.Rotate(new Vector3(0, 1, 0), 10f);
            }
            if ( e.Key == KeyCodes.D)
            {
                _sceneNode.Rotate(new Vector3(0, 1, 0), -1f);
            }

		}
Exemplo n.º 42
0
 private Microsoft.Xna.Framework.Input.Keys Convert( Axiom.Input.KeyCodes key )
 {
     switch ( key )
     {
         case Axiom.Input.KeyCodes.Escape:
             return Microsoft.Xna.Framework.Input.Keys.Escape;
         case Axiom.Input.KeyCodes.G:
             return Microsoft.Xna.Framework.Input.Keys.G;
         case Axiom.Input.KeyCodes.A:
             return Microsoft.Xna.Framework.Input.Keys.A;
         case Axiom.Input.KeyCodes.S:
             return Microsoft.Xna.Framework.Input.Keys.S;
         case Axiom.Input.KeyCodes.D:
             return Microsoft.Xna.Framework.Input.Keys.D;
         case Axiom.Input.KeyCodes.W:
             return Microsoft.Xna.Framework.Input.Keys.W;
             
         default:
             return Microsoft.Xna.Framework.Input.Keys.Execute;
     }
 }
Exemplo n.º 43
0
		/// <summary>
		///   Resolve uniform auto constant parameter with associated real data of this program
		/// </summary>
		/// <param name="autoType"> The auto type of the desired parameter </param>
		/// <param name="type"> The desried data type of the auto parameter </param>
		/// <param name="data"> The data to associate with the auto parameter </param>
		/// <param name="size"> number of elements in the parameter </param>
		/// <returns> parameter instance in case of that resolve operation succeeded, otherwise null </returns>
		public UniformParameter ResolveAutoParameterReal( GpuProgramParameters.AutoConstantType autoType,
		                                                  Axiom.Graphics.GpuProgramParameters.GpuConstantType type,
		                                                  Real data, int size )
		{
			UniformParameter param = null;

			//check if parameter already exists
			param = GetParameterByAutoType( autoType );
			if ( param != null )
			{
				if ( param.IsAutoConstantRealParameter && param.AutoConstantRealData == data )
				{
					param.Size = Axiom.Math.Utility.Max( size, param.Size );
					return param;
				}
			}

			//Create new parameter
			param = new UniformParameter( autoType, data, size, type );
			AddParameter( param );

			return param;
		}
Exemplo n.º 44
0
		public void OnUpdateInput(Axiom.Input.InputReader inputReader)
		{

		}
Exemplo n.º 45
0
		public void Initialise(Axiom.Core.Root item)
		{

			_root = item;
		}
Exemplo n.º 46
0
		public override void NotifyCurrentCamera( Axiom.Core.Camera camera )
		{
			// Do nothing
		}
Exemplo n.º 47
0
 /** Updates the level of detail to be used for rendering this PagingLandScapeRenderable based on the passed in Camera
 */
 public override void NotifyCurrentCamera( Axiom.Core.Camera cam )
 {
     PagingLandscape.Camera plsmcam = (PagingLandscape.Camera) (cam);
     this.isVisible = (init && loaded && plsmcam.GetVisibility(tileSceneNode.WorldAABB));
     //			this.isVisible = (init && loaded );
 }
 public abstract void GetWorldTransforms(Axiom.MathLib.Matrix4[] matrices);
Exemplo n.º 49
0
		protected void _setProgramParameter( GpuProgramType type, String paramName, Axiom.Math.Vector3 value )
		{
			_setProgramParameter( type, paramName, value, sizeof( float ) * 3 );
		}
Exemplo n.º 50
0
        public override void NotifyCurrentCamera(Axiom.Core.Camera cam)
        {
            Debug.Assert(inBoundary);

            if (((Camera)(cam)).IsObjectVisible(this.worldAABB))
            {
                isVisible = true;
            }
            else
            {
                isVisible = false;
                return;
            }
        }
Exemplo n.º 51
0
 protected override void SetPosition(Axiom.MathLib.Vector3 newposition)
 {
     threeDsound.Position = new Vector3(newposition.x, newposition.y, newposition.z);
 }
Exemplo n.º 52
0
 protected override void SetConeDirection(Axiom.MathLib.Vector3 direction)
 {
     Axiom.MathLib.Vector3 vector = direction;
     threeDsound.ConeOrientation = new Vector3(vector.x, vector.y, vector.z);
 }
Exemplo n.º 53
0
		protected override Resource _create( string name, ulong handle, string group, bool isManual, IManualResourceLoader loader, Axiom.Collections.NameValuePairList createParams )
		{
			return new Mesh( this, name, handle, group, isManual, loader );
		}
Exemplo n.º 54
0
		private void _getVertices( ref Vector3[] points, Axiom.Animating.Bone bone )
		{
			Vector3 boneBase = bone.DerivedPosition;
			foreach ( Axiom.Animating.Bone childBone in bone.Children )
			{
				// The tip of the bone:
				Vector3 boneTip = childBone.DerivedPosition;
				// the base of the bone
				Vector3 arm = boneTip - boneBase;
				Vector3 perp1 = arm.Perpendicular();
				Vector3 perp2 = arm.Cross( perp1 );
				perp1.Normalize();
				perp2.Normalize();
				float boneLen = arm.Length;
				int offset = 6 * childBone.Handle;
				points[ offset + 0 ] = boneTip;
				points[ offset + 1 ] = boneBase;
				points[ offset + 2 ] = boneBase + boneLen / 10 * perp1;
				points[ offset + 3 ] = boneBase + boneLen / 10 * perp2;
				points[ offset + 4 ] = boneBase - boneLen / 10 * perp1;
				points[ offset + 5 ] = boneBase - boneLen / 10 * perp2;
				_getVertices( ref points, childBone );
			}
		}
Exemplo n.º 55
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="terrain"></param>
		private void InitBlendMaps( Axiom.Components.Terrain.Terrain terrain )
		{

			TerrainLayerBlendMap blendMap0 = terrain.GetLayerBlendMap( 1 );
			TerrainLayerBlendMap blendMap1 = terrain.GetLayerBlendMap( 2 );
			Real minHeight0 = 70;
			Real fadeDist0 = 40;
			Real minHeight1 = 70;
			Real fadeDist1 = 15;

			float[] pBlend1 = blendMap1.BlendPointer;
			int blendIdx = 0;
			for ( ushort y = 0; y < terrain.LayerBlendMapSize; y++ )
			{
				for ( ushort x = 0; x < terrain.LayerBlendMapSize; x++ )
				{
					float tx = 0;
					float ty = 0;
					blendMap0.ConvertImageToTerrainSpace( x, y, ref tx, ref ty );
					Real height = terrain.GetHeightAtTerrainPosition( tx, ty );
					Real val = ( height - minHeight0 ) / fadeDist0;
					val = Utility.Clamp( val, 0, 1 );

					val = ( height - minHeight1 ) / fadeDist1;
					val = Utility.Clamp( val, 0, 1 );
					pBlend1[ blendIdx++ ] = val;
				}
			}
			blendMap0.Dirty();
			blendMap1.Dirty();
			blendMap0.Update();
			blendMap1.Update();

		}
Exemplo n.º 56
0
 public override void CheckKeyPressed( Axiom.Input.KeyCodes key, out bool isPressed )
 {
     isPressed = false;
     XFG.Input.Keys xnaKey = Convert( key );
     isPressed = _keyboardState.IsKeyDown( xnaKey );
 }
Exemplo n.º 57
0
 public override float GetSquaredViewDepth(Axiom.Core.Camera camera)
 {
     // Use squared length to avoid square root
     return (this.ParentNode.DerivedPosition - camera.DerivedPosition).LengthSquared;
 }
Exemplo n.º 58
0
		public static bool GetReal( AbstractNode node, out Axiom.Math.Real retVal )
		{
			return Scripting.Compiler.ScriptCompiler.Translator.getReal( node, out retVal );
		}
Exemplo n.º 59
0
		public override void GetWorldTransforms( Axiom.Math.Matrix4[] matrices )
		{
			// return identity matrix to prevent parent transforms
			matrices[ 0 ] = Matrix4.Identity;
		}
		/// <summary>
		///   Populate a list of uniforms based on GLSL ES source.
		/// </summary>
		/// <param name="src"> Reference to the source code </param>
		/// <param name="constantDefs"> The defs to populate (will not be cleared before adding, clear it yourself before calling this if that's what you want). </param>
		/// <param name="fileName"> The file name this came from, for logging errors </param>
		public void ExtractConstantDefs( string src, Axiom.Graphics.GpuProgramParameters.GpuNamedConstants constantDefs, string fileName )
		{
			// Parse the output string and collect all uniforms
			// NOTE this relies on the source already having been preprocessed
			// which is done in GLSLESProgram::loadFromSource
			string line;
			int currPos = src.IndexOf( "uniform" );
			while ( currPos != -1 )
			{
				var def = new GpuProgramParameters.GpuConstantDefinition();
				string paramName = string.Empty;

				//Now check for using the word 'uniform' in a larger string & ignore
				bool inLargerString = false;
				if ( currPos != 0 )
				{
					char prev = src[ currPos - 1 ];
					if ( prev != ' ' && prev != '\t' && prev != '\r' && prev != '\n' && prev != ';' )
					{
						inLargerString = true;
					}
				}
				if ( !inLargerString && currPos + 7 < src.Length )
				{
					char next = src[ currPos + 7 ];
					if ( next != ' ' && next != '\t' && next != '\r' && next != '\n' )
					{
						inLargerString = true;
					}
				}

				//skip uniform 
				currPos += 7;

				if ( !inLargerString )
				{
					//find terminatiing semicolon
					int endPos = -1;
					for ( int i = 0; i < src.Length; i++ )
					{
						if ( src[ i ] == ';' )
						{
							endPos = i;
							break;
						}
					}
					if ( endPos == -1 )
					{
						//problem, missing semicolon, abort
						break;
					}
					line = src.Substring( currPos, endPos - currPos );

					//remove spaces before opening square braces, otherwise the following split() can split the line at inapppropriate
					//places (e.g. "vec3 sometihng [3]" won't work).

					for ( int sqp = line.IndexOf( "[" ); sqp != -1; sqp = line.IndexOf( " [" ) )
					{
						line.Remove( sqp, 1 );
					}
					string[] parts = line.Split( '\t', '\r', '\n' );

					foreach ( string i in parts )
					{
						//Is this a type
						if ( this.typeEnumMap.ContainsKey( i ) )
						{
							this.CompleteDefInfo( this.typeEnumMap[ i ], def );
						}
						else
						{
							//If this is not a type, and not empty, it should be a name
							string trim = i.Trim();
							if ( trim.Length == 0 )
							{
								continue;
							}

							//Skip over precision keywords
							if ( trim == "lowp" || trim == "mediump" || trim == "highp" )
							{
								continue;
							}

							int arrayStart = -1;
							for ( int j = 0; j < trim.Length; j++ )
							{
								if ( trim[ j ] == '[' )
								{
									arrayStart = j;
									break;
								}
							}
							if ( arrayStart != -1 )
							{
								//potential name (if butted up to array)
								string name = trim.Substring( 0, arrayStart );
								name = name.Trim();
								if ( name.Length > 0 )
								{
									paramName = name;
								}

								int arrayEnd = -1;
								for ( int k = 0; k < trim.Length; k++ )
								{
									if ( trim[ k ] == ']' )
									{
										arrayEnd = k;
										break;
									}
								}
								string arrayDimTerm = trim.Substring( arrayStart + 1, arrayEnd - arrayStart - 1 );
								arrayDimTerm = arrayDimTerm.Trim();
								// the array term might be a simple number or it might be
								// an expression (e.g. 24*3) or refer to a constant expression
								// we'd have to evaluate the expression which could get nasty
								// Ogre TODO
								def.ArraySize = int.Parse( arrayDimTerm );
							}
							else
							{
								paramName = trim;
								def.ArraySize = 1;
							}

							//Name should be after the type, so complete def and add
							//We do this now so that comma-seperated params will do
							//this part once for each name mentioned
							if ( def.ConstantType == GpuProgramParameters.GpuConstantType.Unknown )
							{
								Axiom.Core.LogManager.Instance.Write( "Problem parsing the following GLSL Uniform: " + line + " in file " + fileName );
								//next uniform
								break;
							}

							//Complete def and add
							//increment physical buffer location
							def.LogicalIndex = 0; // not valid in GLSL
							if ( def.IsFloat )
							{
								def.PhysicalIndex = constantDefs.FloatBufferSize;
								constantDefs.FloatBufferSize += def.ArraySize * def.ElementSize;
							}
							else
							{
								def.PhysicalIndex = constantDefs.IntBufferSize;
								constantDefs.IntBufferSize += def.ArraySize * def.ElementSize;
							}
							constantDefs.Map.Add( paramName, def );
						}
					}
				}
				//Find next one
				currPos = src.IndexOf( "uniform" );
			}
		}