Ejemplo n.º 1
0
        //-----------------------------------------------------------------------------------------------
        public void MakeAndRegisterInfluenceTemplate(string influenceID, uint size)
        {
            List <InfluenceTemplate> templateList = null;
            bool isInfluenceIDRegistered          = InfluenceTemplates.TryGetValue(influenceID.ToLower(), out templateList);

            if (isInfluenceIDRegistered)
            {
                // Make sure a template with size not already registered
                foreach (InfluenceTemplate registeredTemplate in templateList)
                {
                    if (registeredTemplate.TemplateSize == size)
                    {
                        return;
                    }
                }

                // Add template with the new size
                InfluenceTemplate newTemplate = new InfluenceTemplate(influenceID.ToLower(), size);
                templateList.Add(newTemplate);
                return;
            }

            // Not registered; make a new list and add to collection
            templateList = new List <InfluenceTemplate>();
            templateList.Add(new InfluenceTemplate(influenceID.ToLower(), size));
            m_registeredInfluenceTemplates.Add(influenceID.ToLower(), templateList);
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------------------------
        public void ApplyTemplate(InfluenceTemplate template, uint locationX, uint locationY)
        {
            float[] templateData      = template.TemplateData;
            uint    templateDimension = template.TemplateTextureDimension;

            uint zeroCoordX = locationX - template.TemplateSize - 1;
            uint zeroCoordY = locationY - template.TemplateSize - 1;

            for (uint rowIndex = 0; rowIndex < templateDimension; ++rowIndex)
            {
                uint mapCoordY = zeroCoordY + rowIndex;
                if (mapCoordY <= 0U || mapCoordY >= INFLUENCE_MAP_RESOLUTION)
                {
                    continue;
                }

                for (uint colIndex = 0; colIndex < templateDimension; ++colIndex)
                {
                    uint mapCoordX = zeroCoordX + colIndex;
                    if (mapCoordX <= 0U || mapCoordX >= INFLUENCE_MAP_RESOLUTION)
                    {
                        continue;
                    }

                    uint templateIndex = (rowIndex * templateDimension) + colIndex;
                    uint mapIndex      = (mapCoordY * INFLUENCE_MAP_RESOLUTION) + mapCoordX;

                    m_mapData[mapIndex] += templateData[templateIndex];
                }
            }
        }
Ejemplo n.º 3
0
        //-----------------------------------------------------------------------------------------------
        public void GenerateInfluenceMaps()
        {
            InfluenceSystem influenceSystemRef = InfluenceSystem.GetInstance();
            List <BaseMap>  baseMapsToGenerate = influenceSystemRef.InfluenceMaps;

            foreach (BaseMap baseMap in baseMapsToGenerate)
            {
                baseMap.Reset();

                List <IInfluenceObject> objectsForMap = influenceSystemRef.GetAllObjectsWithTag(baseMap.ObjectTag);
                if (objectsForMap == null)
                {
                    continue;
                }

                List <InfluenceTemplate> templatesForMap = influenceSystemRef.GetInfluencesTemplatesWithID(baseMap.InfluenceID);
                if (templatesForMap == null)
                {
                    throw new ArgumentNullException("templatesForMap");
                }

                foreach (IInfluenceObject influenceObject in objectsForMap)
                {
                    uint influenceSize = influenceObject.GetTemplateSizeForInfluenceType(baseMap.InfluenceID);
                    InfluenceTemplate templateToApply = GetInfluenceTemplateForSize(templatesForMap, influenceSize);
                    if (templateToApply == null)
                    {
                        throw new ArgumentNullException("templateToApply");
                    }

                    InfluenceObjectWorldPoint objWorldPos = influenceObject.WorldPosition;
                    InfluenceMapPoint         mapPos      = ConvertWorldPosToMapPos(objWorldPos);
                    baseMap.ApplyTemplate(templateToApply, mapPos.x, mapPos.y);
                }
            }
        }