コード例 #1
0
        private void OnTransformStructureRequested(CSteamID instigator, byte x, byte y, uint instanceID,
                                                   ref Vector3 point, ref byte angle_x, ref byte angle_y, ref byte angle_z, ref bool shouldAllow)
        {
            StructureRegion region = StructureManager.regions[x, y];
            int             index  = region.structures.FindIndex(k => k.instanceID == instanceID);

            StructureData data = region.structures[index];
            StructureDrop drop = region.drops[index];

            Player nativePlayer = Provider.clients.FirstOrDefault(x => x?.playerID.steamID == instigator)?.player;

            UnturnedPlayer player = nativePlayer == null ? null : new UnturnedPlayer(nativePlayer);

            UnturnedStructureTransformingEvent @event = new UnturnedStructureTransformingEvent(
                new UnturnedStructureBuildable(data, drop), player, instigator, point,
                Quaternion.Euler(angle_x * 2, angle_y * 2, angle_z * 2));

            Emit(@event);

            shouldAllow = [email protected];
            point       = @event.Point;

            Vector3 eulerAngles = @event.Rotation.eulerAngles;

            angle_x = MeasurementTool.angleToByte(Mathf.RoundToInt(eulerAngles.x / 2f) * 2);
            angle_y = MeasurementTool.angleToByte(Mathf.RoundToInt(eulerAngles.y / 2f) * 2);
            angle_z = MeasurementTool.angleToByte(Mathf.RoundToInt(eulerAngles.z / 2f) * 2);
        }
コード例 #2
0
        private static void TestDisconnect(StructureData str, Element e)
        {
            while (e.Cubes.Count > 1)
            {
                try
                {
                    var first = e.Cubes.First();
                    AddNeighbors(m_disconnectHelper, first, e);

                    // All cubes added
                    if (e.Cubes.Count == m_disconnectHelper.Count)
                    {
                        return;
                    }
                    else
                    {
                        var newEl = new Element(false)
                        {
                            CurrentOffset = e.CurrentOffset
                        };
                        foreach (var c in m_disconnectHelper)
                        {
                            e.Cubes.Remove(c);
                            newEl.Cubes.Add(c);
                            str.Lookup[c] = newEl;
                        }
                        str.Elements.Add(newEl);
                    }
                }
                finally
                {
                    m_disconnectHelper.Clear();
                }
            }
        }
コード例 #3
0
        public void Execute(IRocketPlayer caller, string[] command)
        {
            for (byte i = 0; i < Regions.WORLD_SIZE; i += 1)
            {
                for (byte j = 0; j < Regions.WORLD_SIZE; j += 1)
                {
                    BarricadeRegion br = BarricadeManager.regions[i, j];
                    for (int index = 0; index < br.barricades.Count; index++)
                    {
                        BarricadeData b = br.barricades[index];
                        if (Assets.find(EAssetType.ITEM, b.barricade.id) is ItemBarricadeAsset asset && asset.build != EBuild.FARM)
                        {
                            b.barricade.health = asset.health;
                            //BarricadeManager.instance.channel.send("tellBarricadeHealth", ESteamCall.ALL,
                            //    ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { i, j, ushort.MaxValue, index, b.asset.quality });
                        }
                    }

                    StructureRegion sr = StructureManager.regions[i, j];
                    for (int index = 0; index < sr.structures.Count; index++)
                    {
                        StructureData s = sr.structures[index];
                        if (Assets.find(EAssetType.ITEM, s.structure.id) is ItemStructureAsset asset)
                        {
                            s.structure.health = asset.health;
                            //BarricadeManager.instance.channel.send("tellStructureHealth", ESteamCall.ALL,
                            //    ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { i, j, ushort.MaxValue, index, s.asset.quality });
                        }
                    }
                }
            }
            UnturnedChat.Say(caller, "repaired all buildings");
        }
コード例 #4
0
 public void LoadData(StructureSystemSaveData structureSystemData)
 {
     StructuresLearned.Clear();
     StructureInformation[] structureInfos = Resources.LoadAll <StructureInformation>("Configuration");
     foreach (string learned in structureSystemData.learneds)
     {
         StructureInformation find = Array.Find(structureInfos, x => x.ID == learned);
         if (find)
         {
             StructuresLearned.Add(find);
         }
     }
     foreach (StructureSaveData saveData in structureSystemData.structureDatas)
     {
         StructureInformation find = Array.Find(structureInfos, x => x.ID == saveData.modelID);
         if (find)
         {
             StructureData data = new StructureData(find, new Vector3(saveData.posX, saveData.posY, saveData.posZ));
             data.LoadBuild(find, saveData);
             if (data.leftBuildTime <= 0)
             {
                 DoneBuild(data);
             }
             else if (saveData.scene == UnityEngine.SceneManagement.SceneManager.GetActiveScene().name)
             {
                 StructurePreview2D preview = Instantiate(find.Preview);
                 preview.StartBuild(data);
                 MakeFlag(preview);
             }
             AddStructure(data);
         }
     }
     AStarManager.Instance.UpdateGraphs();
 }
コード例 #5
0
 public void DestroyStructure(StructureData structure)
 {
     if (!structure)
     {
         return;
     }
     ConfirmWindow.StartConfirm(string.Format("确定拆毁{0}{1}吗?", structure.Name, (Vector2)transform.position),
                                delegate
     {
         if (structure)
         {
             if (this.structures.TryGetValue(structure.Info.ID, out var structures))
             {
                 structures.Remove(structure);
                 if (structures.Count < 1)
                 {
                     this.structures.Remove(structure.Info.ID);
                 }
             }
             if (structure.entity && structure.entity.gameObject)
             {
                 UpdateAStar(structure.entity);
                 structure.entity.Destroy();
             }
             else if (structure.preview && structure.preview.gameObject)
             {
                 UpdateAStar(structure.preview);
                 structure.preview.Destroy();
             }
             NotifyCenter.PostNotify(StructureDestroy, structure, structures);
         }
     });
コード例 #6
0
 public UnturnedStructureBuildable(StructureData data, StructureDrop drop) : this(drop)
 {
     if (data != drop.GetServersideData())
     {
         throw new Exception($"{nameof(data)} is incorrect structure data for {nameof(drop)}");
     }
 }
コード例 #7
0
 public StructureRenderer(StructureData newData, MeshFilter newMeshFilter)
 {
     data       = newData;
     meshFilter = newMeshFilter;
     meshFilter.mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
     materials = new MaterialData();
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: pumaatlarge/BookStore
 static void Main(string[] args)
 {
     StructureData m = new StructureData();
     m.ReadData("Benzene");
     m.List();
     Console.ReadLine();
 }
コード例 #9
0
    public void SetActiveStructure(string prototype)
    {
        activeStructure = GridData.GetStructurePrototype(prototype);
        creationMode    = CreationMode.Structure;

        UpdateToolInfo(activeStructure.instructionSetID);
    }
コード例 #10
0
        private void OnDamageStructureRequested(CSteamID instigatorSteamID, Transform structureTransform, ref ushort pendingTotalDamage, ref bool shouldAllow, EDamageOrigin damageOrigin)
        {
            if (StructureManager.tryGetInfo(structureTransform, out byte x, out byte y, out ushort index,
                                            out StructureRegion region, out StructureDrop drop))
            {
                StructureData data = region.structures[index];

                UnturnedStructureBuildable buildable = new UnturnedStructureBuildable(data, drop);

                Player nativePlayer = Provider.clients.FirstOrDefault(x => x?.playerID.steamID == instigatorSteamID)?.player;

                UnturnedPlayer player = nativePlayer == null ? null : new UnturnedPlayer(nativePlayer);

                UnturnedBuildableDamagingEvent @event;

                if (pendingTotalDamage >= buildable.State.Health)
                {
                    @event = new UnturnedStructureDestroyingEvent(buildable, pendingTotalDamage, damageOrigin, player, instigatorSteamID);
                }
                else
                {
                    @event = new UnturnedStructureDamagingEvent(buildable, pendingTotalDamage, damageOrigin, player, instigatorSteamID);
                }

                Emit(@event);

                pendingTotalDamage = @event.DamageAmount;
                shouldAllow        = [email protected];
            }
        }
コード例 #11
0
        public Structure(Grid buildGrid, StructureData data)
        {
            this._grid = buildGrid;
            RectangleBody rect;

            if (data.X1 < 0 || data.Y1 < 0)
            {
                rect            = new RectangleBody(buildGrid.TileToPixelRect(0, 0));
                rect.Position.X = -10000;
                rect.Position.Y = -10000;
            }
            else
            {
                rect = new RectangleBody(buildGrid.TileToPixelRect(data.X1, data.Y1));
            }
            this.Collision = rect;
            rect.Size      = new Vector2(rect.Region().Width *data.Width, rect.Region().Height *data.Height);
            this.Data      = data;

            Collision        = rect;
            Collision.Parent = this;

            Velocity     = new Vector2(0f);
            Acceleration = new Vector2(0f);
        }
コード例 #12
0
        private void Events_OnStructureDestroyed(StructureData data, StructureDrop drop)
        {
            UnturnedStructureDestroyedEvent @event =
                new UnturnedStructureDestroyedEvent(new UnturnedStructureBuildable(data, drop));

            Emit(@event);
        }
コード例 #13
0
        static void SumConstraints(Element me, Vector3I myPos, StructureData str, Vector3I neighbourPos, float myOffset, ref float sum, ref float absSum, ref float count, ref float max, float disconnectThreshold)
        {
            Element cube;

            if (str.Lookup.TryGetValue(neighbourPos, out cube) && cube != me)
            {
                var diff = myOffset - cube.TmpOffset;

                //if (diff < 0.00001f && !cube.IsStatic && !me.IsStatic)
                //{
                //    me.Merged = true;
                //    cubes[neighbourPos] = me;
                //}

                max     = Math.Max(diff, max);
                sum    += diff * cube.Cubes.Count;
                absSum += Math.Abs(diff);
                count  += cube.Cubes.Count;

                if (diff > disconnectThreshold)
                {
                    str.TmpDisconnectList.Add(myPos);
                }
            }
        }
コード例 #14
0
        static void DrawMe(StructureData str)
        {
            var cubes = str.Lookup;

            float totalMax;

            Solve_Iterative(str, 0.9f, out totalMax);

            totalMax = Math.Max(totalMax, 0.2f);
            //totalMax = 1.0f;

            var size = str.m_grid.GridSize;

            float sum = 0;

            foreach (var c in cubes)
            {
                if (!c.Value.IsStatic)
                {
                    var color = GetTension(c.Value.MaxDiff, totalMax);
                    sum += c.Value.AbsSum;
                    string text = c.Value.AbsSum.ToString("0.00");

                    DrawCube(str, size, c, ref color, text);
                }
            }

            var stat = cubes.Where(s => s.Value.IsStatic);

            if (stat.Any())
            {
                Color color = Color.Black;
                //DrawCube(str, size, stat.First(), ref color, sum.ToString());
            }
        }
コード例 #15
0
        static void Disconnect(StructureData str)
        {
            while (str.TmpDisconnectList.Count > 0)
            {
                var first = str.TmpDisconnectList.First();
                str.TmpDisconnectList.Remove(first);

                var e = str.Lookup[first];
                if (e.Cubes.Count == 1)
                {
                    continue;
                }

                e.Cubes.Remove(first);

                var newEl = new Element(false)
                {
                    CurrentOffset = e.CurrentOffset
                };
                newEl.Cubes.Add(first);
                str.Elements.Add(newEl);
                str.Lookup[first] = newEl;

                TestDisconnect(str, e);
            }
        }
コード例 #16
0
        static void Main(string[] args)
        {
            CambridgeSoft.ChemScript14.Environment.SetVerbosity(true);
            CambridgeSoft.ChemScript14.Environment.SetThrowExceptions(true);

            string oldDir = SetCurrentDirectory();

            if (!IsInputFilesReady())
            {
                return;
            }

            try
            {
                StreamReader sr = new StreamReader("smiles.input", Encoding.Default);
                String       line;
                line = sr.ReadToEnd();
                Console.WriteLine(line);
                StructureData m = StructureData.LoadData(line, "smiles");
                sr.Close();
                FileStream   fs = new FileStream("cdx.output", FileMode.Create);
                StreamWriter sw = new StreamWriter(fs);
                Console.WriteLine(m.WriteData("cdx", true));
                sw.Write(m.WriteData("cdx", true));
                sw.Flush();
                sw.Close();
                fs.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #17
0
        public Structure CreateStructure(StructureData structureData)
        {
            Structure structure = null;

            // TODO: Ensure unique IDs.
            switch ((StructureTypes)structureData.StructureType)
            {
            case (StructureTypes.LaserTurret):
                structure = CreateTurret(new Vector2(structureData.XPos, structureData.YPos), structureData.CurrentHealth, structureData.Id, (TurretTypes)((TurretData)structureData).TurretType, ((TurretData)structureData).OwnerTeamIDs);
                break;

            case (StructureTypes.CommandCenter):
                structure = CreateCommandCenter(structureData.XPos, structureData.YPos, structureData.CurrentHealth, structureData.Id, structureData.OwnerTeamIDs);
                break;

            case (StructureTypes.DefensiveMine):
                structure = CreateDefensiveMine(structureData.XPos, structureData.YPos, 100, structureData.Id,
                                                structureData.OwnerTeamIDs);
                break;

            default:
                // Need to move this
                structure = CreateGenericStructure(structureData.XPos, structureData.YPos, (StructureTypes)structureData.StructureType, structureData.CurrentHealth, 0, structureData.Id, structureData.OwnerTeamIDs);
                break;
            }

            structure.IsLocalSim = _simulateStructures;
            return(structure);
        }
コード例 #18
0
    void ReadItemsFromDatabase()
    {
        XmlDocument doc = new XmlDocument();

        using (StringReader s = new StringReader(database.text)) {
            doc.Load(s);
        }

        XmlNodeList struList = doc.GetElementsByTagName("Structure");

        foreach (XmlNode stru in struList)
        {
            XmlNodeList children = stru.ChildNodes;
            Dictionary <string, string> contents = new Dictionary <string, string>();
            string name = null;

            foreach (XmlNode thing in children)
            {
                if (thing.Name == "Name")
                {
                    name = thing.InnerText;
                }
                contents[thing.Name] = thing.InnerText;
            }

            if (name != null)
            {
                structureData[name] = new StructureData(contents);
            }
        }
    }
コード例 #19
0
        private void Events_OnStructureTransformed(StructureData data, StructureDrop drop)
        {
            var @event =
                new UnturnedStructureTransformedEvent(new UnturnedStructureBuildable(data, drop));

            Emit(@event);
        }
コード例 #20
0
    void DragPreview()
    {
        Dictionary <Node, Action> actionLocations = actionController.actionLocations;

        foreach (Node n in actionLocations.Keys)
        {
            int x = n.x;
            int y = n.y;

            Action act = actionLocations[n];

            //display preview of action at tile
            GameObject go = actionController.GetPreview(act);
            go.transform.position = new Vector3(x, worldController.GetObjectFloat(x, y), y);                    //don't for
            dragPreviewGameObjects.Add(go);

            //align preview
            StructureData data = StructureDatabase.GetData(act.What);
            if (data != null)
            {
                float alignx = data.Alignx;
                float aligny = data.Aligny;
                go.transform.position += new Vector3(alignx, 0, aligny);
            }

            //change color of preview
            Material mat = new Material(canDo);

            //if can do, make it white
            if (actionController.CanDo(act, x, y) && act.Do != "demolish")
            {
                mat.color = new Color(1, 1, 1, .5f);
            }
            //else, if it's paint, make it invisible
            else if (act.Do == "paint")
            {
                go.SetActive(false);
            }
            //else if we're demolishing but we can't here
            else if (act.Do == "demolish" && !actionController.CanDo(act, x, y))
            {
                go.SetActive(false);
            }
            //else, make it red
            else
            {
                mat.color = new Color(1, 0, 0, .5f);
            }

            foreach (Transform child in go.transform)
            {
                Material[] mats = child.GetComponent <MeshRenderer>().materials;
                for (int a = 0; a < mats.Length; a++)
                {
                    mats[a] = mat;
                }
                child.GetComponent <MeshRenderer>().materials = mats;
            }
        }
    }
コード例 #21
0
ファイル: Structure.cs プロジェクト: Philip-S-Martin/Reforge
 public void SetData(StructureData newData)
 {
     thisData = newData;
     thisRenderer.Data = thisData;
     thisRenderer.SteppedRenderStructure();
     thisObject.GetComponent<MeshCollider>().sharedMesh = thisObject.GetComponent<MeshFilter>().mesh;
 }
コード例 #22
0
        /// <summary>
        /// Creates a Structure object and initializes it from level data.
        /// </summary>
        /// <param name="level"></param>
        /// <param name="index"></param>
        public Structure(Level level, int index)
        {
            this.level = level;
            this.Index = index;

            data = new StructureData(this);
        }
コード例 #23
0
 internal Form(int primaryRail, int secondaryRail, int formType, int roofType, StructureData structure)
 {
     PrimaryRail   = primaryRail;
     SecondaryRail = secondaryRail;
     FormType      = formType;
     RoofType      = roofType;
     Structure     = structure;
 }
コード例 #24
0
    public static StructureData Prototype(string instructionSetID)
    {
        StructureData newData = new StructureData();

        newData.instructionSetID = instructionSetID;

        return(newData);
    }
コード例 #25
0
    public StructureController(StructureMaster structureMaster, StructureConfig structureConfig, StructureData structureData)
    {
        this.structureMaster = structureMaster;
        this.structureConfig = structureConfig;
        this.structureData   = structureData;

        Initialize();
    }
コード例 #26
0
 public void Init(StructureData data)
 {
     Data               = data;
     Data.entity        = this;
     gameObject.name    = Data.Name;
     transform.position = Data.position;
     OnInit();
 }
コード例 #27
0
        /// <summary>
        /// The unturned structure instance
        /// </summary>
        /// <param name="data">The structure data</param>
        private UnturnedStructure(StructureData data)
        {
            // Set the variables
            this.Data = data;

            // Run code
            UnturnedServer.AddStructure(this);
        }
コード例 #28
0
ファイル: Structure.cs プロジェクト: Philip-S-Martin/Reforge
    bool MergeBuffer()
    {
        //copy bufferData into local tempData
        StructureData tempData = bufferData;
        GameObject tempObject = bufferObject;
        StructureRenderer tempRenderer = bufferRenderer;

        return true;
    }
コード例 #29
0
 //public bool IsEmpty { get { return level == null; } }
 /// <summary>
 /// Creates a new empty structure object.
 /// </summary>
 /// <param name="level"></param>
 private Structure(int index, Level level)
 {
     this.level = level;
     this.Index = index;
     data       = new StructureData(this);
     data.ClearToEmpty();
     data[0, 0] = 0x00;
     CalculateRomBytes();
 }
コード例 #30
0
 public void StartBuild(StructureData data)
 {
     Data         = data;
     data.preview = this;
     ZetanUtility.SetActive(preview, false);
     ZetanUtility.SetActive(structure, true);
     transform.position = data.position;
     gameObject.name    = Data.Name;
 }
コード例 #31
0
            private static void DestroyStructure(StructureRegion region, ushort index)
            {
                ThreadUtil.assertIsGameThread();

                StructureData data = region.structures[index];
                StructureDrop drop = region.drops[index];

                OnStructureDestroyed?.Invoke(data, drop);
            }
コード例 #32
0
 public StructureTag(Structure structure)
 {
     for (byte x = 0; x < Regions.WORLD_SIZE; x++)
     {
         for (byte y = 0; y < Regions.WORLD_SIZE; y++)
         {
             StructureRegion region = StructureManager.regions[x, y];
             for (int i = 0; i < region.structures.Count; i++)
             {
                 if (structure == region.structures[i].structure)
                 {
                     Internal = region.models[i];
                     InternalData = region.structures[i];
                     return;
                 }
             }
         }
     }
 }
コード例 #33
0
        static void SumConstraints(Element me, Vector3I myPos, StructureData str, Vector3I neighbourPos, float myOffset, ref float sum, ref float absSum, ref float count, ref float max, float disconnectThreshold)
        {
            Element cube;
            if (str.Lookup.TryGetValue(neighbourPos, out cube) && cube != me)
            {
                var diff = myOffset - cube.TmpOffset;

                //if (diff < 0.00001f && !cube.IsStatic && !me.IsStatic)
                //{
                //    me.Merged = true;
                //    cubes[neighbourPos] = me;
                //}

                max = Math.Max(diff, max);
                sum += diff * cube.Cubes.Count;
                absSum += Math.Abs(diff);
                count += cube.Cubes.Count;

                if (diff > disconnectThreshold)
                    str.TmpDisconnectList.Add(myPos);
            }
        }
コード例 #34
0
        public List<StructureData> GetStructures()
        {

            // Structure attribute type
            Assembly everestCoreAssembly = Array.Find<Assembly>(AppDomain.CurrentDomain.GetAssemblies(), o => o.GetName().Name == "MARC.Everest");

            if (everestCoreAssembly == null)
                return null;

            Type structureAttributeType = everestCoreAssembly.GetType("MARC.Everest.Attributes.StructureAttribute");


            // Return value
            List<StructureData> retVal = new List<StructureData>();

            foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                foreach(Type t in asm.GetTypes())
                    // IGraphable
                    if (t.GetInterface("MARC.Everest.Interfaces.IGraphable") != null)
                    {
                        object[] descriptionAttributes = t.GetCustomAttributes(typeof(DescriptionAttribute), true);
                        object[] structureAttributes = t.GetCustomAttributes(structureAttributeType, true);

                        // Get struct and description attribute values
                        if (descriptionAttributes.Length == 0 || structureAttributes.Length == 0)
                            continue;

                        StructureData data = new StructureData();
                        data.assemblyName = asm.FullName;
                        data.typeName = t.Name;
                        data.typeNamespace = t.Namespace;
                        data.displayName = (descriptionAttributes[0] as DescriptionAttribute).Description;
                        data.structureType = structureAttributeType.GetProperty("StructureType").GetValue(structureAttributes[0], null).ToString();
                        retVal.Add(data); 
                    }

            return retVal; // return retVal
        }
コード例 #35
0
        private void Refresh()
        {
            var time = (Stopwatch.GetTimestamp() - startTimestamp) / (double)Stopwatch.Frequency;
            Stats.Timing.Write("IntegrityRunTime: {0}s", (float)time, VRage.Stats.MyStatTypeEnum.CurrentValue | VRage.Stats.MyStatTypeEnum.FormatFlag, 100, 1);

            var grids = MyEntities.GetEntities().OfType<MyCubeGrid>();

            if (m_grids.Count == 0)
            {
                startTimestamp = Stopwatch.GetTimestamp();
            }

            foreach (var gr in m_grids.ToArray())
            {
                if (gr.Value.m_grid.Closed)
                {
                    m_grids.Remove(gr.Value.m_grid);
                }
            }

            foreach (var g in grids)
            {
                StructureData structure;
                if (!m_grids.TryGetValue(g, out structure))
                {
                    structure = new StructureData();
                    structure.m_grid = g;
                    m_grids[g] = structure;
                }

                bool cubeChanged = false;

                foreach (var c in structure.Lookup)
                {
                    if (g.GetCubeBlock(c.Key) == null)
                    {
                        cubeChanged = true;
                        m_removeList.Add(c.Key);
                    }
                }

                foreach (var x in m_removeList)
                {
                    structure.Lookup.Remove(x);
                }
                m_removeList.Clear();

                foreach (var b in g.GetBlocks())
                {
                    bool isStatic;

                    if (b.BlockDefinition.DisplayNameEnum == MyStringId.GetOrCompute("DisplayName_Block_HeavyArmorBlock"))
                        isStatic = true;
                    else if (b.BlockDefinition.DisplayNameEnum == MyStringId.GetOrCompute("DisplayName_Block_LightArmorBlock"))
                        isStatic = false;
                    else
                        continue;

                    Element cube;
                    if (!structure.Lookup.TryGetValue(b.Position, out cube))
                    {
                        cubeChanged = true;
                        cube = new Element(isStatic);
                        if (!isStatic)
                            cube.CurrentOffset = 0.05f;
                        structure.Lookup[b.Position] = cube;
                    }
                }

                if (cubeChanged)
                {
                    var copy = structure.Lookup.ToDictionary(s => s.Key, v => v.Value);
                    structure.Lookup.Clear();

                    Stack<KeyValuePair<Vector3I, Element>> tmp = new Stack<KeyValuePair<Vector3I, Element>>();

                    // Merge everything possible
                    while (copy.Count > 0)
                    {
                        var first = copy.First();
                        copy.Remove(first.Key);

                        if (!first.Value.IsStatic)
                            structure.Elements.Add(first.Value);

                        tmp.Push(first);
                        while (tmp.Count > 0)
                        {
                            var item = tmp.Pop();
                            first.Value.Cubes.Add(item.Key);
                            structure.Lookup.Add(item.Key, first.Value);

                            if (first.Value.IsStatic)
                                continue;

                            AddNeighbor(tmp, copy, item.Key + Vector3I.UnitX);
                            AddNeighbor(tmp, copy, item.Key + Vector3I.UnitY);
                            AddNeighbor(tmp, copy, item.Key + Vector3I.UnitZ);
                            AddNeighbor(tmp, copy, item.Key - Vector3I.UnitX);
                            AddNeighbor(tmp, copy, item.Key - Vector3I.UnitY);
                            AddNeighbor(tmp, copy, item.Key - Vector3I.UnitZ);
                        }
                    }
                }
            }
        }
コード例 #36
0
        private static void TestDisconnect(StructureData str, Element e)
        {
            while (e.Cubes.Count > 1)
            {
                try
                {
                    var first = e.Cubes.First();
                    AddNeighbors(m_disconnectHelper, first, e);

                    // All cubes added
                    if (e.Cubes.Count == m_disconnectHelper.Count)
                    {
                        return;
                    }
                    else
                    {
                        var newEl = new Element(false) { CurrentOffset = e.CurrentOffset };
                        foreach (var c in m_disconnectHelper)
                        {
                            e.Cubes.Remove(c);
                            newEl.Cubes.Add(c);
                            str.Lookup[c] = newEl;
                        }
                        str.Elements.Add(newEl);
                    }

                }
                finally
                {
                    m_disconnectHelper.Clear();
                }
            }
        }
コード例 #37
0
        static void Disconnect(StructureData str)
        {
            while (str.TmpDisconnectList.Count > 0)
            {
                var first = str.TmpDisconnectList.First();
                str.TmpDisconnectList.Remove(first);

                var e = str.Lookup[first];
                if (e.Cubes.Count == 1)
                    continue;

                e.Cubes.Remove(first);

                var newEl = new Element(false) { CurrentOffset = e.CurrentOffset };
                newEl.Cubes.Add(first);
                str.Elements.Add(newEl);
                str.Lookup[first] = newEl;

                TestDisconnect(str, e);
            }
        }
コード例 #38
0
        private static void Solve_Iterative(StructureData str, float ratio, out float maxError)
        {
            // Apply force, tmp offset is current offset + movement
            foreach (var c in str.Elements)
            {
                Debug.Assert(!c.IsStatic);

                float move;
                move = 0.05f;

                c.TmpOffset = c.CurrentOffset + move;
            }

            maxError = 0;

            float threshold = 0.055f;

            // Solve, calculate new current offset
            foreach (var c in str.Elements)
            {
                Debug.Assert(!c.IsStatic);

                float sum = 0;
                float absSum = 0;
                float count = 0;
                float maxDiff = 0;

                // Calculates sum of neighbour tmp offsets
                foreach (var item in c.Cubes)
                {
                    SumConstraints(c, item, str, item + Vector3I.UnitX, c.TmpOffset, ref sum, ref absSum, ref count, ref maxDiff, threshold);
                    SumConstraints(c, item, str, item + Vector3I.UnitY, c.TmpOffset, ref sum, ref absSum, ref count, ref maxDiff, threshold);
                    SumConstraints(c, item, str, item + Vector3I.UnitZ, c.TmpOffset, ref sum, ref absSum, ref count, ref maxDiff, threshold);
                    SumConstraints(c, item, str, item - Vector3I.UnitX, c.TmpOffset, ref sum, ref absSum, ref count, ref maxDiff, threshold);
                    SumConstraints(c, item, str, item - Vector3I.UnitY, c.TmpOffset, ref sum, ref absSum, ref count, ref maxDiff, threshold);
                    SumConstraints(c, item, str, item - Vector3I.UnitZ, c.TmpOffset, ref sum, ref absSum, ref count, ref maxDiff, threshold);
                }

                // Include myself, more cubes, harder to move
                sum += 0 * c.Cubes.Count;
                count += c.Cubes.Count;

                // Save new offset into current offset and add neighbour force
                float delta = count > 0 ? -sum / count * ratio : 0;

                float absMove = (c.TmpOffset + delta) - c.CurrentOffset;

                //c.Value.LastDelta = absMove > 0.04f ? c.Value.LastDelta * 1.01f : 0.05f;
                //c.Value.LastDelta = Math.Min(c.Value.LastDelta, 0.05f * 4);
                //c.Value.LastDelta = 0.05f + delta;
                //c.Value.LastDelta *= 0.2f;
                c.CurrentOffset = c.TmpOffset + delta;
                c.MaxDiff = maxDiff;
                c.Sum = sum;
                c.AbsSum = absSum;
                maxError = Math.Max(maxError, maxDiff);
            }

            Disconnect(str);

            //foreach (var c in cubes.ToArray())
            //{
            //    if (!c.Value.IsStatic)
            //    {
            //        MergeNeighbor(cubes, c.Value, c.Key, Vector3I.UnitX);
            //        MergeNeighbor(cubes, c.Value, c.Key, Vector3I.UnitY);
            //        MergeNeighbor(cubes, c.Value, c.Key, Vector3I.UnitZ);
            //        MergeNeighbor(cubes, c.Value, c.Key, -Vector3I.UnitX);
            //        MergeNeighbor(cubes, c.Value, c.Key, -Vector3I.UnitY);
            //        MergeNeighbor(cubes, c.Value, c.Key, -Vector3I.UnitZ);
            //    }
            //}
        }
コード例 #39
0
        private static void DrawCube(StructureData str, float size, KeyValuePair<Vector3I, Element> c, ref Color color, string text)
        {
            var local = Matrix.CreateScale(size * 1.02f) * Matrix.CreateTranslation(c.Key * size + new Vector3(0, -c.Value.CurrentOffset / 20.0f, 0));
            Matrix box = local * str.m_grid.WorldMatrix;
            //ten = c.Value.DistanceToStatic.ToString();

            MyRenderProxy.DebugDrawOBB(box, color.ToVector3(), 0.5f, true, true);
            MyRenderProxy.DebugDrawText3D(box.Translation, text, c.Value.Cubes.Count > 1 ? Color.Black : Color.White, 0.5f, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
        }
コード例 #40
0
        static void DrawMe(StructureData str)
        {
            var cubes = str.Lookup;

            float totalMax;

            Solve_Iterative(str, 0.9f, out totalMax);

            totalMax = Math.Max(totalMax, 0.2f);
            //totalMax = 1.0f;

            var size = str.m_grid.GridSize;

            float sum = 0;
            foreach (var c in cubes)
            {
                if (!c.Value.IsStatic)
                {
                    var color = GetTension(c.Value.MaxDiff, totalMax);
                    sum += c.Value.AbsSum;
                    string text = c.Value.AbsSum.ToString("0.00");

                    DrawCube(str, size, c, ref color, text);
                }
            }

            var stat = cubes.Where(s => s.Value.IsStatic);
            if (stat.Any())
            {
                Color color = Color.Black;
                //DrawCube(str, size, stat.First(), ref color, sum.ToString());
            }

        }
コード例 #41
0
 public StructureTag(Transform transform, StructureData data)
 {
     Internal = transform;
     InternalData = data;
 }