public void DeserializePart(Vector3I minBone, Vector3I maxBone, float boneRange, List <byte> data)
        {
            var size = maxBone - minBone;

            size += Vector3I.One; // bounds inclusive

            if (size.Size * 3 < data.Count)
            {
                Debug.Fail("Data has wrong length");
                return;
            }

            int index = 0;

            Vector3I pos;

            for (pos.X = minBone.X; pos.X <= maxBone.X; pos.X++)
            {
                for (pos.Y = minBone.Y; pos.Y <= maxBone.Y; pos.Y++)
                {
                    for (pos.Z = minBone.Z; pos.Z <= maxBone.Z; pos.Z++)
                    {
                        this[pos] = Vector3UByte.Denormalize(new Vector3UByte(data[index], data[index + 1], data[index + 2]), boneRange);
                        index    += 3;
                    }
                }
            }
        }
Exemple #2
0
        public void handle_60Hz()
        {
            check_disposed();
            if (!_grid.IsStatic && _ECU != null && _num_thrusters > 0)
            {
                IMyPlayer controlling_player = get_controlling_player();
                if (controlling_player == null)
                {
                    _ECU.reset_user_input(reset_gyros_only: false);
                    _prev_manual_rotation = Vector3UByte.Zero;
                }
                else //if (!sync_helper.network_handlers_registered || MyAPIGateway.Multiplayer == null || !MyAPIGateway.Multiplayer.IsServer || MyAPIGateway.Multiplayer.IsServerPlayer(controlling_player.Client))
                {
                    handle_user_input(controlling_player.Controller.ControlledEntity);
                }

                _ID_on = false;
                foreach (var cur_controller in _ship_controllers)
                {
                    _ID_on |= cur_controller.EnabledDamping;
                    //break;
                }
                _ECU.linear_dampers_on = _ID_on;

                _ECU.handle_60Hz();
            }
        }
        public void Serialize(List <BoneInfo> result, float boneRange, MyCubeGrid grid)
        {
            var info = new BoneInfo();

            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("Serialize");

            float boneErrorSquared = GetMaxBoneError(grid.GridSize);

            boneErrorSquared *= boneErrorSquared;

            foreach (var bone in Bones)
            {
                Vector3I?cube = GetCubeFromBone(bone.Key, grid);
                if (cube != null)
                {
                    var   boneOffset = GetDefinitionOffsetWithNeighbours(cube.Value, bone.Key, grid);
                    float distance   = Math.Abs(boneOffset.LengthSquared() - bone.Value.LengthSquared());
                    if (distance > boneErrorSquared)
                    {
                        info.BonePosition = bone.Key;
                        info.BoneOffset   = Vector3UByte.Normalize(bone.Value, boneRange);
                        if (!Vector3UByte.IsMiddle(info.BoneOffset)) // Middle number means zero in floats
                        {
                            result.Add(info);
                        }
                    }
                }
            }
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
        public void Deserialize(List <BoneInfo> data, float boneRange, float gridSize, bool clear = false)
        {
            ProfilerShort.Begin("MyGridSkeleton.Deserialize(...)");
            if (clear)
            {
                Bones.Clear();
            }

            foreach (var bone in data)
            {
                Bones[bone.BonePosition] = Vector3UByte.Denormalize(bone.BoneOffset, boneRange);
                //FixBone(bone.BonePosition, gridSize);
            }
            ProfilerShort.End();
        }
 public void AddBlock(Vector3UByte offset)
 {
     Vector3I pos = m_posInGrid + offset * m_stepDelta;
     Vector3I cube;
     for (cube.X = m_blockMin.X; cube.X <= m_blockMax.X; cube.X++)
     {
         for (cube.Y = m_blockMin.Y; cube.Y <= m_blockMax.Y; cube.Y++)
         {
             for (cube.Z = m_blockMin.Z; cube.Z <= m_blockMax.Z; cube.Z++)
             {
                 m_lookup.Add(pos + cube, pos);
             }
         }
     }
 }
        // TODO: this parameter won't be optional
        public void AddInstance(ModelId model, MatrixD matrix, ref MatrixD invGridWorldMatrix, Vector4 colorMaskHsv = default(Vector4), Vector3UByte[] bones = null, float gridSize = 1f)
        {
            Matrix localMatrix = (Matrix)(matrix * invGridWorldMatrix);

            MyBuilderInstanceData builderInstanceData;
            if (!m_instanceParts.TryGetValue(model, out builderInstanceData))
            {
                builderInstanceData = new MyBuilderInstanceData();
                builderInstanceData.Model = model;
                m_instanceParts.Add(model, builderInstanceData);
            }

            //if (bones == null)
            //{
            //    builderInstanceData.InstanceData.Add(new MyCubeInstanceData()
            //    {
            //        ColorMaskHSV = new Vector4(MyPlayer.SelectedColor, 0),
            //        EnableSkinning = false,
            //        LocalMatrix = localMatrix
            //    });
            //}
            //else
            //{
            //    var cubeInstance = new MyCubeInstanceData()
            //    {
            //        ColorMaskHSV = new Vector4(MyPlayer.SelectedColor, 0),
            //        EnableSkinning = true,
            //        LocalMatrix = localMatrix,
            //    };

            //    cubeInstance.BoneRange = gridSize;

            //    for (int i = 0; i < 9; i++)
            //    {
            //        cubeInstance[i] = bones[i];
            //    }

            //    builderInstanceData.InstanceData.Add(cubeInstance);
            //}

            builderInstanceData.InstanceData.Add(new MyInstanceData()
            {
                ColorMaskHSV = new VRageMath.PackedVector.HalfVector4(new Vector4(MyPlayer.SelectedColor, 0)),
                LocalMatrix = localMatrix
            });
        }
        public void SerializePart(Vector3I minBone, Vector3I maxBone, float boneRange, List <byte> result)
        {
            Vector3I pos;

            for (pos.X = minBone.X; pos.X <= maxBone.X; pos.X++)
            {
                for (pos.Y = minBone.Y; pos.Y <= maxBone.Y; pos.Y++)
                {
                    for (pos.Z = minBone.Z; pos.Z <= maxBone.Z; pos.Z++)
                    {
                        var boneValue = Vector3UByte.Normalize(this[pos], boneRange);
                        result.Add(boneValue.X);
                        result.Add(boneValue.Y);
                        result.Add(boneValue.Z);
                    }
                }
            }
        }
        // TODO: this parameter won't be optional
        public void AddInstance(ModelId model, MatrixD matrix, ref MatrixD invGridWorldMatrix, Vector4 colorMaskHsv = default(Vector4), Vector3UByte[] bones = null, float gridSize = 1f)
        {
            Matrix localMatrix = (Matrix)(matrix * invGridWorldMatrix);

            MyBuilderInstanceData builderInstanceData;
            if (!m_instanceParts.TryGetValue(model, out builderInstanceData))
            {
                builderInstanceData = new MyBuilderInstanceData();
                builderInstanceData.Model = model;
                m_instanceParts.Add(model, builderInstanceData);
            }

            if (bones == null)
            {
                builderInstanceData.InstanceData.Add(new MyCubeInstanceData()
                {
                    ColorMaskHSV = new Vector4(MyPlayer.SelectedColor, 0),
                    EnableSkinning = false,
                    LocalMatrix = localMatrix
                });
            }
            else
            {
                var cubeInstance = new MyCubeInstanceData()
                {
					ColorMaskHSV = new Vector4(MyPlayer.SelectedColor, 0),
                    EnableSkinning = true,
                    LocalMatrix = localMatrix,
                };

                cubeInstance.BoneRange = gridSize;

                for (int i = 0; i < 9; i++)
                {
                    cubeInstance[i] = bones[i];
                }

                builderInstanceData.InstanceData.Add(cubeInstance);
            }

            m_cubeBuilderAABB = m_cubeBuilderAABB.Include(
                new BoundingBox(new Vector3(-MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large)),
                                new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large))).Transform(localMatrix));
        }
Exemple #9
0
        public void handle_2s_period()
        {
            check_disposed();
            if (!_grid.IsStatic && _ECU != null && _num_thrusters > 0)
            {
                _ECU.handle_2s_period();

                if (MyAPIGateway.Multiplayer != null && !MyAPIGateway.Multiplayer.IsServer)
                {
                    _prev_manual_rotation = new Vector3UByte(128, 128, 128);
                }
                else if (_zero_controls_counter++ >= CONTROLS_TIMEOUT)
                {
                    _ECU.reset_user_input(reset_gyros_only: false);
                    _prev_manual_rotation  = new Vector3UByte(128, 128, 128);
                    _zero_controls_counter = 0;
                }
            }
        }
        public bool AddGrid(MyCubeGrid grid)
        {
            HashSet <Sandbox.Game.Entities.Cube.MySlimBlock> lst = new HashSet <Sandbox.Game.Entities.Cube.MySlimBlock>();

            foreach (var block in grid.GetBlocks())
            {
                if (block.FatBlock is MyCompoundCubeBlock)
                {
                    bool added = false;
                    foreach (var subb in (block.FatBlock as MyCompoundCubeBlock).GetBlocks())
                    {
                        if (AddBlock(subb))
                        {
                            added = true;
                        }
                    }
                    if (added)
                    {
                        lst.Add(block);
                    }
                }
                else
                {
                    if (AddBlock(block))
                    {
                        lst.Add(block);
                    }
                }
            }


            foreach (var b in lst)
            {
                Vector3I     pos  = b.Position;
                Vector3UByte size = new Vector3UByte(1, 1, 1);
                grid.RazeBlocks(ref pos, ref size);
                //   grid.RemoveBlock(b, true); not synced
            }

            return(lst.Count > 0);
        }
 void IMyCubeGrid.RazeBlocks(ref Vector3I pos, ref Vector3UByte size)
 {
     RazeBlocks(ref pos, ref size);
 }
Exemple #12
0
        /// <summary>
        /// Stops continuous building/removing. Do not put any gizmo related stuff here.
        /// </summary>
        protected void StopBuilding(bool smallViewChange, ref Vector3I? startBuild, ref Vector3I? startRemove, ref Vector3I? continueBuild, Vector3I blockMinPosition, Vector3I blockMaxPosition, 
            Vector3I blockCenterPosition, ref Matrix localMatrixAdd, MyCubeBlockDefinition blockDefinition)
        {
            if (startBuild != null && (continueBuild != null || smallViewChange))
            {
                Vector3I min = blockMinPosition - blockCenterPosition;
                Vector3I max = blockMaxPosition - blockCenterPosition;

                Vector3I rotatedSize;
                Vector3I.TransformNormal(ref CurrentBlockDefinition.Size, ref localMatrixAdd, out rotatedSize);
                rotatedSize = Vector3I.Abs(rotatedSize);

                Vector3I stepDelta;
                Vector3I counter;
                int stepCount;

                if (smallViewChange)
                    continueBuild = startBuild;

                ComputeSteps(startBuild.Value, continueBuild.Value, rotatedSize, out stepDelta, out counter, out stepCount);

                Vector3I centerPos = blockCenterPosition;
                Quaternion orientation = Quaternion.CreateFromRotationMatrix(localMatrixAdd);
                MyDefinitionId definitionId = blockDefinition.Id;

                // Blocks can be randomly rotated if line/plane building is used.
                bool allowRandomRotation = blockDefinition.RandomRotation
                    && blockDefinition.Size.X == blockDefinition.Size.Y && blockDefinition.Size.X == blockDefinition.Size.Z
                    && (blockDefinition.Rotation == MyBlockRotation.Both || blockDefinition.Rotation == MyBlockRotation.Vertical);

                if (allowRandomRotation)
                {
                    m_blocksBuildQueue.Clear();

                    Vector3I temp;
                    for (temp.X = 0; temp.X < counter.X; ++temp.X)
                    {
                        for (temp.Y = 0; temp.Y < counter.Y; ++temp.Y)
                        {
                            for (temp.Z = 0; temp.Z < counter.Z; ++temp.Z)
                            {
                                Vector3I tempCenter = blockCenterPosition + temp * stepDelta;
                                Vector3I tempMin = blockMinPosition + temp * stepDelta;
                                Vector3I tempMax = blockMaxPosition + temp * stepDelta;

                                Quaternion tempOrientation;

                                if (blockDefinition.Rotation == MyBlockRotation.Both)
                                {
                                    Base6Directions.Direction forward = (Base6Directions.Direction)(Math.Abs(MyRandom.Instance.Next()) % 6);
                                    Base6Directions.Direction up = forward;

                                    while (Vector3I.Dot(Base6Directions.GetIntVector(forward), Base6Directions.GetIntVector(up)) != 0)
                                        up = (Base6Directions.Direction)(Math.Abs(MyRandom.Instance.Next()) % 6);

                                    tempOrientation = Quaternion.CreateFromForwardUp(Base6Directions.GetIntVector(forward), Base6Directions.GetIntVector(up));
                                }
                                else
                                {
                                    Base6Directions.Direction up = Base6Directions.Direction.Up;
                                    Base6Directions.Direction forward = up;

                                    while (Vector3I.Dot(Base6Directions.GetIntVector(forward), Base6Directions.GetIntVector(up)) != 0)
                                        forward = (Base6Directions.Direction)(Math.Abs(MyRandom.Instance.Next()) % 6);

                                    tempOrientation = Quaternion.CreateFromForwardUp(Base6Directions.GetIntVector(forward), Base6Directions.GetIntVector(up));
                                }

                                m_blocksBuildQueue.Add(new MyCubeGrid.MyBlockLocation(blockDefinition.Id, tempMin, tempMax, tempCenter, tempOrientation,
                                    MyEntityIdentifier.AllocateId(), MySession.Static.LocalPlayerId));
                            }
                        }
                    }
                    if (m_blocksBuildQueue.Count > 0)
                    {
                        MyGuiAudio.PlaySound(MyGuiSounds.HudPlaceBlock);
                    }
                }
                else
                {
                    // New version of build code
                    MyCubeGrid.MyBlockBuildArea area = new MyCubeGrid.MyBlockBuildArea();
                    area.PosInGrid = centerPos;
                    area.BlockMin = new Vector3B(min);
                    area.BlockMax = new Vector3B(max);
                    area.BuildAreaSize = new Vector3UByte(counter);
                    area.StepDelta = new Vector3B(stepDelta);
                    area.OrientationForward = Base6Directions.GetForward(ref orientation);
                    area.OrientationUp = Base6Directions.GetUp(ref orientation);
                    area.DefinitionId = definitionId;
                    area.ColorMaskHSV = MyPlayer.SelectedColor.PackHSVToUint();

                    CurrentGrid.BuildBlocks(ref area, MySession.Static.LocalCharacterEntityId, MySession.Static.LocalPlayerId);
                }
            }
            else if (startRemove != null && (continueBuild != null || smallViewChange))
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudDeleteBlock);

                Vector3I min = startRemove.Value;
                Vector3I max = startRemove.Value;

                Vector3I stepDelta;
                Vector3I counter;
                int stepCount;
                if (smallViewChange)
                    continueBuild = startRemove;

                ComputeSteps(startRemove.Value, continueBuild.Value, Vector3I.One, out stepDelta, out counter, out stepCount);

                min = Vector3I.Min(startRemove.Value, continueBuild.Value);
                max = Vector3I.Max(startRemove.Value, continueBuild.Value);
                var size = new Vector3UByte(max - min);
                CurrentGrid.RazeBlocks(ref min, ref size);
            }

            startBuild = null;
            continueBuild = null;
            startRemove = null;
        }
        private void AddGizmoCubeParts(MyGizmoSpaceProperties gizmoSpace, MyBlockBuilderRenderData renderData, ref MatrixD invGridWorldMatrix, MyCubeBlockDefinition definition)
        {
            Vector3UByte[] bones = null;
            MyTileDefinition[] tiles = null;
            MatrixD invGridWorldMatrixOrientation = invGridWorldMatrix.GetOrientation();
            float gridSize = 1f;
            if (definition != null && definition.Skeleton != null)
            {
                tiles = MyCubeGridDefinitions.GetCubeTiles(definition);
                gridSize = MyDefinitionManager.Static.GetCubeSize(definition.CubeSize);
            }

            for (int faceIndex = 0; faceIndex < gizmoSpace.m_cubeModelsTemp.Count; faceIndex++)
            {
                string cubePartModel = gizmoSpace.m_cubeModelsTemp[faceIndex];

                gizmoSpace.m_cubeModels.Add(cubePartModel);
                gizmoSpace.m_cubeMatrices.Add(gizmoSpace.m_cubeMatricesTemp[faceIndex]);

                int tileIndex = faceIndex % tiles.Count();

                var invertedTile = Matrix.Transpose(tiles[tileIndex].LocalMatrix);
                var onlyOrientation = invertedTile * gizmoSpace.m_cubeMatricesTemp[faceIndex].GetOrientation();
                var boneMatrix = onlyOrientation * invGridWorldMatrixOrientation;

                if (tiles != null)
                {
                    bones = new Vector3UByte[9];
                    for (int i = 0; i < 9; i++)
                    {
                        bones[i] = new Vector3UByte(128, 128, 128);
                    }

                    var model = MyModels.GetModel(cubePartModel);

                    for (int index = 0; index < Math.Min(model.BoneMapping.Length, 9); index++)
                    {
                        var boneOffset = model.BoneMapping[index];
                        Vector3 centered = boneOffset - Vector3.One;

                        Vector3I transformedOffset = Vector3I.Round(Vector3.Transform(centered, tiles[tileIndex].LocalMatrix) + Vector3.One);

                        for (int skeletonIndex = 0; skeletonIndex < definition.Skeleton.Count; skeletonIndex++)
                        {
                            BoneInfo skeletonBone = definition.Skeleton[skeletonIndex];
                            if (skeletonBone.BonePosition == (SerializableVector3I)transformedOffset)
                            {
                                Vector3 bone = Vector3UByte.Denormalize(skeletonBone.BoneOffset, gridSize);
                                Vector3 transformedBone = Vector3.Transform(bone, boneMatrix);
                                bones[index] = Vector3UByte.Normalize(transformedBone, gridSize);
                                break;
                            }
                        }
                    }
                }

                renderData.AddInstance(MyModel.GetId(cubePartModel), gizmoSpace.m_cubeMatricesTemp[faceIndex], ref invGridWorldMatrix, bones: bones, gridSize: gridSize);
            }
        }
Exemple #14
0
        void StopBuilding()
        {
            if ((!GridAndBlockValid && !VoxelMapAndBlockValid && !MultiBlockCreationIsActivated) || MyEntities.MemoryLimitReachedReport)
            {
                foreach (var gizmoSpace in m_gizmo.Spaces)
                {
                    gizmoSpace.m_startBuild = null;
                    gizmoSpace.m_continueBuild = null;
                    gizmoSpace.m_startRemove = null;
                }
                return;
            }

            bool smallViewChange = CheckSmallViewChange();

            m_blocksBuildQueue.Clear();
            m_tmpBlockPositionList.Clear();

            UpdateGizmos(true, true, false);

            int enabledCount = 0;
            foreach (var gizmoSpace in m_gizmo.Spaces)
            {
                if (gizmoSpace.Enabled)
                    ++enabledCount;
            }

            foreach (var gizmoSpace in m_gizmo.Spaces)
            {
                if (!gizmoSpace.Enabled)
                    continue;

                if (gizmoSpace.m_startBuild != null && (gizmoSpace.m_continueBuild != null || smallViewChange))
                {
                    Vector3I gridPos = gizmoSpace.m_startBuild.Value;
                    Vector3I min = gizmoSpace.m_min - gizmoSpace.m_centerPos;
                    Vector3I max = gizmoSpace.m_max - gizmoSpace.m_centerPos;

                    Vector3I rotatedSize;
                    Vector3I.TransformNormal(ref CurrentBlockDefinition.Size, ref gizmoSpace.m_localMatrixAdd, out rotatedSize);
                    rotatedSize = Vector3I.Abs(rotatedSize);

                    Vector3I stepDelta;
                    Vector3I counter;
                    int stepCount;

                    if (smallViewChange)
                        gizmoSpace.m_continueBuild = gizmoSpace.m_startBuild;

                    ComputeSteps(gizmoSpace.m_startBuild.Value, gizmoSpace.m_continueBuild.Value, rotatedSize, out stepDelta, out counter, out stepCount);

                    Vector3I centerPos = gizmoSpace.m_centerPos;
                    Quaternion orientation = gizmoSpace.LocalOrientation;
                    MyDefinitionId definitionId = gizmoSpace.m_blockDefinition.Id;

                    // Blocks can be randomly rotated if line/plane building is used.
                    bool allowRandomRotation = gizmoSpace.m_blockDefinition.RandomRotation 
                        && gizmoSpace.m_blockDefinition.Size.X == gizmoSpace.m_blockDefinition.Size.Y && gizmoSpace.m_blockDefinition.Size.X == gizmoSpace.m_blockDefinition.Size.Z
                        && (gizmoSpace.m_blockDefinition.Rotation == MyBlockRotation.Both || gizmoSpace.m_blockDefinition.Rotation == MyBlockRotation.Vertical);

                    if (allowRandomRotation)
                    {
                        m_blocksBuildQueue.Clear();

                        Vector3I temp;
                        for (temp.X = 0; temp.X < counter.X; ++temp.X)
                        {
                            for (temp.Y = 0; temp.Y < counter.Y; ++temp.Y)
                            {
                                for (temp.Z = 0; temp.Z < counter.Z; ++temp.Z)
                                {
                                    Vector3I tempCenter = gizmoSpace.m_centerPos + temp * stepDelta;
                                    Vector3I tempMin = gizmoSpace.m_min + temp * stepDelta;
                                    Vector3I tempMax = gizmoSpace.m_max + temp * stepDelta;

                                    Quaternion tempOrientation;

                                    if (gizmoSpace.m_blockDefinition.Rotation == MyBlockRotation.Both)
                                    {
                                        Base6Directions.Direction forward = (Base6Directions.Direction)(Math.Abs(MyRandom.Instance.Next()) % 6);
                                        Base6Directions.Direction up = forward;
                                        
                                        while (Vector3I.Dot(Base6Directions.GetIntVector(forward), Base6Directions.GetIntVector(up)) != 0) 
                                            up = (Base6Directions.Direction)(Math.Abs(MyRandom.Instance.Next()) % 6);
                                        
                                        tempOrientation = Quaternion.CreateFromForwardUp(Base6Directions.GetIntVector(forward), Base6Directions.GetIntVector(up));
                                    }
                                    else
                                    {
                                        Base6Directions.Direction up = Base6Directions.Direction.Up;
                                        Base6Directions.Direction forward = up;

                                        while (Vector3I.Dot(Base6Directions.GetIntVector(forward), Base6Directions.GetIntVector(up)) != 0)
                                            forward = (Base6Directions.Direction)(Math.Abs(MyRandom.Instance.Next()) % 6);

                                        tempOrientation = Quaternion.CreateFromForwardUp(Base6Directions.GetIntVector(forward), Base6Directions.GetIntVector(up));
                                    }

                                    m_blocksBuildQueue.Add(new MyCubeGrid.MyBlockLocation(gizmoSpace.m_blockDefinition.Id, tempMin, tempMax, tempCenter, tempOrientation,
                                        MyEntityIdentifier.AllocateId(), MySession.LocalPlayerId, MySession.LocalCharacter.EntityId));
                                }
                            }
                        }

                        CurrentGrid.BuildBlocks(MyToolbar.ColorMaskHSV, m_blocksBuildQueue);
                    }
                    else
                    {
                        // New version of build code
                        MyCubeGrid.MyBlockBuildArea area = new MyCubeGrid.MyBlockBuildArea();
                        area.PosInGrid = centerPos;
                        area.BlockMin = new Vector3B(min);
                        area.BlockMax = new Vector3B(max);
                        area.BuildAreaSize = new Vector3UByte(counter);
                        area.StepDelta = new Vector3B(stepDelta);
                        area.OrientationForward = Base6Directions.GetForward(ref orientation);
                        area.OrientationUp = Base6Directions.GetUp(ref orientation);
                        area.DefinitionId = definitionId;
                        area.ColorMaskHSV = MyToolbar.ColorMaskHSV.PackHSVToUint();

                        CurrentGrid.BuildBlocks(MySession.LocalPlayerId, ref area);

                        // TODO: There will be message send instead of this, this will called and iterated after message success
                        //BuildByGizmo(ref min, ref max, ref stepDelta, ref counter, ref centerPos, ref orientation, ref definitionId);
                    }
                }
                else if (gizmoSpace.m_startRemove != null && (gizmoSpace.m_continueBuild != null || smallViewChange))
                {
                    MyGuiAudio.PlaySound(MyGuiSounds.HudDeleteBlock);

                    Vector3I min = gizmoSpace.m_startRemove.Value;
                    Vector3I max = gizmoSpace.m_startRemove.Value;

                    Vector3I stepDelta;
                    Vector3I counter;
                    int stepCount;
                    if (smallViewChange)
                        gizmoSpace.m_continueBuild = gizmoSpace.m_startRemove;

                    ComputeSteps(gizmoSpace.m_startRemove.Value, gizmoSpace.m_continueBuild.Value, Vector3I.One, out stepDelta, out counter, out stepCount);

                    min = Vector3I.Min(gizmoSpace.m_startRemove.Value, gizmoSpace.m_continueBuild.Value);
                    max = Vector3I.Max(gizmoSpace.m_startRemove.Value, gizmoSpace.m_continueBuild.Value);
                    var size = new Vector3UByte(max - min);
                    CurrentGrid.RazeBlocks(ref min, ref size);

                    //Vector3I offset = Vector3I.Zero;
                    //for (int i = 0; i < counter.X; i += 1, offset.X += stepDelta.X)
                    //{
                    //    offset.Y = 0;
                    //    for (int j = 0; j < counter.Y; j += 1, offset.Y += stepDelta.Y)
                    //    {
                    //        offset.Z = 0;
                    //        for (int k = 0; k < counter.Z; k += 1, offset.Z += stepDelta.Z)
                    //        {
                    //            Vector3I pos = gizmoSpace.m_startRemove.Value + offset;
                    //            if (CurrentGrid.CubeExists(pos))
                    //            {
                    //                m_tmpBlockPositionList.Add(pos);
                    //            }
                    //        }
                    //    }
                    //}
                }

                gizmoSpace.m_startBuild = null;
                gizmoSpace.m_continueBuild = null;
                gizmoSpace.m_startRemove = null;
            }

            if (m_blocksBuildQueue.Count > 0)
            {
                CurrentGrid.BuildBlocks(MyToolbar.ColorMaskHSV, m_blocksBuildQueue);
            }

            if (m_tmpBlockPositionList.Count > 0)
            {
                CurrentGrid.RazeBlocks(m_tmpBlockPositionList);
            }
        }
Exemple #15
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_CubeBlockDefinition;

            MyDebug.AssertDebug(ob != null);

            this.Size  = ob.Size;
            this.Model = ob.Model;
            this.UseModelIntersection = ob.UseModelIntersection;
            this.CubeSize             = ob.CubeSize;
            this.ModelOffset          = ob.ModelOffset;
            this.BlockTopology        = ob.BlockTopology;
            this.PhysicsOption        = ob.PhysicsOption;
            this.BlockPairName        = ob.BlockPairName;
            this.m_center             = ob.Center ?? ((Size - 1) / 2);
            this.m_symmetryX          = ob.MirroringX;
            this.m_symmetryY          = ob.MirroringY;
            this.m_symmetryZ          = ob.MirroringZ;
            this.DeformationRatio     = ob.DeformationRatio;
            this.EdgeType             = ob.EdgeType;
            this.AutorotateMode       = ob.AutorotateMode;
            this.m_mirroringBlock     = ob.MirroringBlock;
            this.MultiBlock           = ob.MultiBlock;
            this.GuiVisible           = ob.GuiVisible;
            this.Rotation             = ob.Rotation;
            this.Direction            = ob.Direction;
            this.Mirrored             = ob.Mirrored;
            this.RandomRotation       = ob.RandomRotation;
            this.BuildType            = ob.BuildType != null?ob.BuildType.ToLower() : null;

            this.GeneratedBlockType = MyStringId.GetOrCompute(ob.GeneratedBlockType != null ? ob.GeneratedBlockType.ToLower() : null);
            if (ob.DamageEffectId != 0)
            {
                this.DamageEffectID = ob.DamageEffectId;
            }

            this.CompoundTemplates = ob.CompoundTemplates;
            Debug.Assert(this.CompoundTemplates == null || this.CompoundTemplates.Length > 0, "Wrong compound templates, array is empty");

            if (ob.SubBlockDefinitions != null)
            {
                SubBlockDefinitions = new Dictionary <string, MyDefinitionId>();

                foreach (var definition in ob.SubBlockDefinitions)
                {
                    MyDefinitionId defId;
                    if (SubBlockDefinitions.TryGetValue(definition.SubBlock, out defId))
                    {
                        MyDebug.AssertDebug(false, "Subblock definition already defined!");
                        continue;
                    }

                    defId = definition.Id;
                    SubBlockDefinitions.Add(definition.SubBlock, defId);
                }
            }

            if (ob.BlockVariants != null)
            {
                BlockStages = new MyDefinitionId[ob.BlockVariants.Length];

                for (int i = 0; i < ob.BlockVariants.Length; ++i)
                {
                    BlockStages[i] = ob.BlockVariants[i];
                }
            }

            var cubeDef = ob.CubeDefinition;

            if (cubeDef != null)
            {
                MyCubeDefinition tmp = new MyCubeDefinition();
                tmp.CubeTopology = cubeDef.CubeTopology;
                tmp.ShowEdges    = cubeDef.ShowEdges;

                var sides = cubeDef.Sides;
                tmp.Model       = new string[sides.Length];
                tmp.PatternSize = new Vector2I[sides.Length];
                for (int j = 0; j < sides.Length; ++j)
                {
                    var side = sides[j];
                    tmp.Model[j]       = side.Model;
                    tmp.PatternSize[j] = side.PatternSize;
                }
                this.CubeDefinition = tmp;
            }

            var components = ob.Components;

            MyDebug.AssertDebug(components != null);
            MyDebug.AssertDebug(components.Length != 0);
            float mass = 0.0f;
            float criticalIntegrity  = 0f;
            float ownershipIntegrity = 0f;

            if (components != null && components.Length != 0)
            {
                Components = new MyCubeBlockDefinition.Component[components.Length];

                float integrity           = 0.0f;
                int   criticalTypeCounter = 0;
                for (int j = 0; j < components.Length; ++j)
                {
                    var component = components[j];

                    MyCubeBlockDefinition.Component tmp = new MyCubeBlockDefinition.Component()
                    {
                        Count      = component.Count,
                        Definition = MyDefinitionManager.Static.GetComponentDefinition(new MyDefinitionId(component.Type, component.Subtype))
                    };

                    if (component.Type == typeof(MyObjectBuilder_Component) && component.Subtype == "Computer")
                    {
                        if (ownershipIntegrity == 0)
                        {
                            ownershipIntegrity = integrity + tmp.Definition.MaxIntegrity;
                        }
                    }

                    integrity += tmp.Count * tmp.Definition.MaxIntegrity;
                    if (component.Type == ob.CriticalComponent.Type &&
                        component.Subtype == ob.CriticalComponent.Subtype)
                    {
                        if (criticalTypeCounter == ob.CriticalComponent.Index)
                        {
                            CriticalGroup     = (UInt16)j;
                            criticalIntegrity = integrity - 1;
                        }
                        ++criticalTypeCounter;
                    }

                    mass += tmp.Count * tmp.Definition.Mass;

                    Components[j] = tmp;
                }
                MaxIntegrity          = integrity;
                IntegrityPointsPerSec = integrity / ob.BuildTimeSeconds;
                DisassembleRatio      = ob.DisassembleRatio;
                Mass = mass;
            }

            CriticalIntegrityRatio  = criticalIntegrity / MaxIntegrity;
            OwnershipIntegrityRatio = ownershipIntegrity / MaxIntegrity;

            if (ob.BuildProgressModels != null)
            {
                ob.BuildProgressModels.Sort((a, b) => a.BuildPercentUpperBound.CompareTo(b.BuildPercentUpperBound));
                this.BuildProgressModels = new BuildProgressModel[ob.BuildProgressModels.Count];
                for (int i = 0; i < BuildProgressModels.Length; ++i)
                {
                    var builderModel = ob.BuildProgressModels[i];
                    if (!string.IsNullOrEmpty(builderModel.File))
                    {
                        this.BuildProgressModels[i] = new BuildProgressModel()
                        {
                            BuildRatioUpperBound = builderModel.BuildPercentUpperBound * CriticalIntegrityRatio,
                            File = builderModel.File,
                            RandomOrientation = builderModel.RandomOrientation
                        };
                    }
                }
            }

            if (ob.GeneratedBlocks != null)
            {
                this.GeneratedBlockDefinitions = new MyDefinitionId[ob.GeneratedBlocks.Length];

                for (int i = 0; i < ob.GeneratedBlocks.Length; ++i)
                {
                    var genBlockId = ob.GeneratedBlocks[i];
                    Debug.Assert(!string.IsNullOrEmpty(genBlockId.SubtypeName));
                    Debug.Assert(!string.IsNullOrEmpty(genBlockId.TypeIdString));

                    this.GeneratedBlockDefinitions[i] = genBlockId;
                }
            }

            Skeleton = ob.Skeleton;
            if (Skeleton != null)
            {
                Bones = new Dictionary <Vector3I, Vector3>(ob.Skeleton.Count);
                foreach (var bone in Skeleton)
                {
                    Bones[bone.BonePosition] = Vector3UByte.Denormalize(bone.BoneOffset, MyDefinitionManager.Static.GetCubeSize(ob.CubeSize));
                }
            }

            IsAirTight = ob.IsAirTight;

            InitMountPoints(ob);
            InitPressurization();

            InitNavigationInfo(ob, ob.NavigationDefinition);

            CheckBuildProgressModels();
            // Components and CriticalComponent will be initialized elsewhere

            this.PrimarySound = new MySoundPair(ob.PrimarySound);
        }
Exemple #16
0
        public void RazeBlocksAreaSuccess(ref Vector3I pos, ref Vector3UByte size, HashSet<Vector3UByte> failList)
        {
            if (Sync.IsServer)
            {
                var successMsg = new RazeBlocksAreaSuccessMsg();
                successMsg.GridEntityId = Entity.EntityId;
                successMsg.Pos = pos;
                successMsg.Size = size;
                successMsg.FailList = failList;

                Sync.Layer.SendMessageToAll(ref successMsg);
            }
        }
Exemple #17
0
 public void RazeBlocksArea(ref Vector3I pos, ref Vector3UByte size)
 {
     var msg = new RazeBlocksAreaRequestMsg();
     msg.GridEntityId = Entity.EntityId;
     msg.Pos = pos;
     msg.Size = size;
     Sync.Layer.SendMessageToServer(ref msg);
 }
 static MyGridSkeleton()
 {
     MAX_BONE_ERROR = Vector3UByte.Denormalize(new Vector3UByte(128, 128, 128), 1f).X * 0.75f;
 }
Exemple #19
0
 public MyDelayedRazeBatch(Vector3I pos, Vector3UByte size)
 {
     this.Pos  = pos;
     this.Size = size;
 }
Exemple #20
0
        public bool AddGrid(MyCubeGrid grid)
        {
            HashSet<Sandbox.Game.Entities.Cube.MySlimBlock> lst = new HashSet<Sandbox.Game.Entities.Cube.MySlimBlock>();

            foreach (var block in grid.GetBlocks())
            {
                if (block.FatBlock is MyCompoundCubeBlock)
                {
                    bool added = false;
                    foreach (var subb in (block.FatBlock as MyCompoundCubeBlock).GetBlocks())
                    {
                        if (AddBlock(subb))
                        {
                            added = true;
                        }
                    }
                    if (added)
                    {
                        lst.Add(block);
                    }
                }
                else
                {
                    if (AddBlock(block))
                    {
                        lst.Add(block);
                    }
                }
            }


            foreach (var b in lst)
            {
                Vector3I pos = b.Position;
                Vector3UByte size = new Vector3UByte(1, 1, 1);
                grid.RazeBlocks(ref pos, ref size);
                //   grid.RemoveBlock(b, true); not synced
            }

            return lst.Count > 0;
        }
 void IMyCubeGrid.RazeBlocks(ref Vector3I pos, ref Vector3UByte size)
 {
     RazeBlocks(ref pos, ref size);
 }