Exemple #1
0
        private AST createFromNodeType(int nodeTypeIndex)
        {
            Debug.Assert((nodeTypeIndex >= 0) && (nodeTypeIndex <= heteroList_.Length), "Invalid AST node type!");
            AST newNode = null;

            FactoryEntry entry = heteroList_[nodeTypeIndex];

            if ((entry != null) && (entry.Creator != null))
            {
                newNode = entry.Creator.Create();
            }
            else
            {
                if ((entry == null) || (entry.NodeTypeObject == null))
                {
                    if (defaultCreator_ == null)
                    {
                        newNode = createFromNodeTypeObject(defaultASTNodeTypeObject_);
                    }
                    else
                    {
                        newNode = defaultCreator_.Create();
                    }
                }
                else
                {
                    newNode = createFromNodeTypeObject(entry.NodeTypeObject);
                }
            }
            return(newNode);
        }
Exemple #2
0
        /// <summary>
        /// Register an ASTNodeCreator for a given Token type ID.
        /// </summary>
        /// <param name="NodeType">The Token type ID.</param>
        /// <param name="creator">The creater to register.</param>
        public void setTokenTypeASTNodeCreator(int NodeType, ASTNodeCreator creator)
        {
            // check validity of arguments...
            if (NodeType < Token.MIN_USER_TYPE)
            {
                throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + NodeType + "'");
            }

            // resize up to and including 'type' and initialize any gaps to default
            // factory.
            if (NodeType > (heteroList_.Length + 1))
            {
                setMaxNodeType(NodeType);
            }
            // And add new thing..
            if (heteroList_[NodeType] == null)
            {
                heteroList_[NodeType] = new FactoryEntry(creator);
            }
            else
            {
                heteroList_[NodeType].Creator = creator;
            }

            //typename2creator_[NodeType.ToString()]		= creator;
            typename2creator_[creator.ASTNodeTypeName] = creator;
        }
Exemple #3
0
        /// <summary>
        /// Pre-expands the internal list of TokenTypeID-to-ASTNodeType mappings
        /// to the specified size.
        /// This is primarily a convenience method that can be used to prevent
        /// unnecessary and costly re-org of the mappings list.
        /// </summary>
        /// <param name="NodeType">Maximum Token Type ID.</param>
        public void setMaxNodeType(int NodeType)
        {
            //Debug.WriteLine(this, "NodeType = " + NodeType + " and NodeList.Length = " + nodeTypeList_.Length);
            if (heteroList_ == null)
            {
                heteroList_ = new FactoryEntry[NodeType + 1];
            }
            else
            {
                int length = heteroList_.Length;

                if (NodeType > (length + 1))
                {
                    FactoryEntry[] newList = new FactoryEntry[NodeType + 1];
                    Array.Copy(heteroList_, 0, newList, 0, heteroList_.Length);
                    heteroList_ = newList;
                }
                else if (NodeType < (length + 1))
                {
                    FactoryEntry[] newList = new FactoryEntry[NodeType + 1];
                    Array.Copy(heteroList_, 0, newList, 0, (NodeType + 1));
                    heteroList_ = newList;
                }
            }
            //Debug.WriteLine(this, "NodeType = " + NodeType + " and NodeList.Length = " + nodeTypeList_.Length);
        }
Exemple #4
0
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject entity in _cells)
        {
            Cell cell = entity.GetComponent <Cell>();
            if (!cell.state.Equals(CellState.DEAD))
            {
                GameObject[] targets = entity.GetComponent <InCollision3D>().Targets;
                foreach (GameObject target in targets)
                {
                    if (target.activeSelf && target.GetComponent <Removed>() == null && target.GetComponent <Infectious>() != null)
                    {
                        FactoryEntry infection = new FactoryEntry(target)
                        {
                            originalNb = 1,
                            nb         = 1
                        };

                        cell.infections.Add(infection);
                        target.SetActive(false);
                        target.transform.parent = entity.transform;
                    }
                }
            }
        }
    }
Exemple #5
0
 /// <summary>
 /// Constructs an <c>ASTFactory</c> and use the specified AST node type
 /// as the default.
 /// </summary>
 /// <param name="defaultASTNodeType">Node type for this factory.</param>
 public ASTFactory(Type defaultASTNodeType)
 {
     heteroList_ = new FactoryEntry[Token.MIN_USER_TYPE + 1];
     defaultASTNodeTypeObject_            = defaultASTNodeType;
     defaultCreator_                      = null;
     typename2creator_                    = new Hashtable(32, (float)0.3);
     typename2creator_["antlr.CommonAST"] = CommonAST.Creator;
     typename2creator_["antlr.CommonASTWithHiddenTokens"] = CommonASTWithHiddenTokens.Creator;
 }
Exemple #6
0
		/// <summary>
		/// Constructs an <c>ASTFactory</c> and use the specified AST node type
		/// as the default.
		/// </summary>
		/// <param name="defaultASTNodeType">Node type for this factory.</param>
		public ASTFactory(Type defaultASTNodeType)
		{
			heteroList_					= new FactoryEntry[Token.MIN_USER_TYPE+1];
			defaultASTNodeTypeObject_	= defaultASTNodeType;
			defaultCreator_				= null;
			typename2creator_			= new Hashtable(32, (float) 0.3);
			typename2creator_["antlr.CommonAST"]					= CommonAST.Creator;
			typename2creator_["antlr.CommonASTWithHiddenTokens"]	= CommonASTWithHiddenTokens.Creator;

		}
Exemple #7
0
        //---------------------------------------------------------------------
        // FUNCTION MEMBERS
        //---------------------------------------------------------------------

        /// <summary>
        /// Specify an "override" for the <see cref="AST"/> type created for
        /// the specified Token type.
        /// </summary>
        /// <remarks>
        /// This method is useful for situations that ANTLR cannot oridinarily deal
        /// with (i.e., when you  create a token based upon a nonliteral token symbol
        /// like #[LT(1)].  This is a runtime value and ANTLR cannot determine the token
        /// type (and hence the AST) statically.
        /// </remarks>
        /// <param name="tokenType">Token type to override.</param>
        /// <param name="NodeTypeName">
        ///		Fully qualified AST typename (or null to specify
        ///		the factory's default AST type).
        /// </param>
        public void setTokenTypeASTNodeType(int tokenType, string NodeTypeName)
        {
            // check validity of arguments...
            if (tokenType < Token.MIN_USER_TYPE)
            {
                throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + tokenType + "'");
            }

            // resize up to and including 'type' and initialize any gaps to default
            // factory.
            if (tokenType > (heteroList_.Length + 1))
            {
                setMaxNodeType(tokenType);
            }
            // And add new thing..
            if (heteroList_[tokenType] == null)
            {
                heteroList_[tokenType] = new FactoryEntry(loadNodeTypeObject(NodeTypeName));
            }
            else
            {
                heteroList_[tokenType].NodeTypeObject = loadNodeTypeObject(NodeTypeName);
            }
        }
Exemple #8
0
		/// <summary>
		/// Pre-expands the internal list of TokenTypeID-to-ASTNodeType mappings
		/// to the specified size.
		/// This is primarily a convenience method that can be used to prevent 
		/// unnecessary and costly re-org of the mappings list.
		/// </summary>
		/// <param name="NodeType">Maximum Token Type ID.</param>
		public void setMaxNodeType( int NodeType )
		{
			//Debug.WriteLine(this, "NodeType = " + NodeType + " and NodeList.Length = " + nodeTypeList_.Length);
			if (heteroList_ == null)
			{
				heteroList_ = new FactoryEntry[NodeType+1];
			}
			else
			{
				int length = heteroList_.Length;

				if ( NodeType >= length )
				{
					FactoryEntry[] newList = new FactoryEntry[NodeType+1];
					Array.Copy(heteroList_, 0, newList, 0, length);
					heteroList_ = newList;
				}
				else if ( NodeType < length )
				{
					FactoryEntry[] newList = new FactoryEntry[NodeType+1];
					Array.Copy(heteroList_, 0, newList, 0, (NodeType+1));
					heteroList_ = newList;
				}
			}
			//Debug.WriteLine(this, "NodeType = " + NodeType + " and NodeList.Length = " + nodeTypeList_.Length);
		}
Exemple #9
0
		/// <summary>
		/// Register an ASTNodeCreator for a given Token type ID.
		/// </summary>
		/// <param name="NodeType">The Token type ID.</param>
		/// <param name="creator">The creater to register.</param>
		public void setTokenTypeASTNodeCreator(int NodeType, ASTNodeCreator creator)
		{
			// check validity of arguments...
			if( NodeType < Token.MIN_USER_TYPE )
				throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + NodeType + "'");

			// resize up to and including 'type' and initialize any gaps to default
			// factory.
			if (NodeType > (heteroList_.Length+1))
				setMaxNodeType(NodeType);
			// And add new thing..
			if (heteroList_[NodeType] == null)
				heteroList_[NodeType] = new FactoryEntry(creator);
			else
				heteroList_[NodeType].Creator = creator;

			//typename2creator_[NodeType.ToString()]		= creator;
			typename2creator_[creator.ASTNodeTypeName]	= creator;
		}
Exemple #10
0
		//---------------------------------------------------------------------
		// FUNCTION MEMBERS
		//---------------------------------------------------------------------

		/// <summary>
		/// Specify an "override" for the <see cref="AST"/> type created for
		/// the specified Token type.
		/// </summary>
		/// <remarks>
		/// This method is useful for situations that ANTLR cannot oridinarily deal 
		/// with (i.e., when you  create a token based upon a nonliteral token symbol 
		/// like #[LT(1)].  This is a runtime value and ANTLR cannot determine the token 
		/// type (and hence the AST) statically.
		/// </remarks>
		/// <param name="tokenType">Token type to override.</param>
		/// <param name="NodeTypeName">
		///		Fully qualified AST typename (or null to specify 
		///		the factory's default AST type).
		/// </param>
		public void setTokenTypeASTNodeType(int tokenType, string NodeTypeName)
		{
			// check validity of arguments...
			if( tokenType < Token.MIN_USER_TYPE )
				throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + tokenType + "'");

			// resize up to and including 'type' and initialize any gaps to default
			// factory.
			if (tokenType > (heteroList_.Length+1))
				setMaxNodeType(tokenType);
			// And add new thing..
			if (heteroList_[tokenType] == null)
                heteroList_[tokenType] = new FactoryEntry(loadNodeTypeObject(NodeTypeName));
			else
				heteroList_[tokenType].NodeTypeObject = loadNodeTypeObject(NodeTypeName);
		}
Exemple #11
0
 public void SetInterceptedComponentModel(ComponentModel target)
 {
     entry = (FactoryEntry)target.ExtendedProperties["typed.fac.entry"];
 }
		public void SetInterceptedComponentModel(ComponentModel target)
		{
			entry = (FactoryEntry) target.ExtendedProperties["typed.fac.entry"];
		}
Exemple #13
0
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject go in _factories)
        {
            Factory factory = go.GetComponent <Factory>();

            // Is the factory working ? Should it be destroyed ?
            if (!AtLeastOneThingToInstanciate(factory.entries))
            {
                GameObjectManager.unbind(go);
                Object.Destroy(go);
                continue;
            }
            if (factory.paused)
            {
                continue;
            }

            // Update remaining time and skip instanciation process if we still have to wait
            factory.remaining -= Time.deltaTime;
            if (factory.remaining > 0)
            {
                continue;
            }

            // Select the entity that will be created (according to factory's mode)
            FactoryEntry entry = null;
            if (factory.useRandomSpawning)
            {
                do
                {
                    entry = factory.entries[Random.Range(0, factory.entries.Count)];
                } while (entry.nb == 0);
            }
            else
            {
                int i = 0;
                do
                {
                    entry = factory.entries[i];
                    ++i;
                } while (entry.nb == 0);
            }

            // Instanciate the GameObject
            GameObject clone = Object.Instantiate(entry.prefab);
            clone.SetActive(true);

            //clone.layer = entry.layer;
            clone.layer = LayerMask.NameToLayer("Pathogene");

            // Bind it to FYFY
            GameObjectManager.bind(clone);

            // Set GameObject's position
            clone.transform.position = go.transform.position;

            // Decrease the number of remaining object to instanciate (for this prefab)
            --entry.nb;

            // Reset remaining time to rate
            factory.remaining = factory.rate;
        }
    }