public static PastedEntity ConcurrentPasteBelt(int threadIndex, BeltCopy belt, Vector2 targetSpr, float yaw, int pasteIndex) { var actionBuild = _abs[threadIndex]; int pasteId = PASTE_INDEX_MULTIPLIER * pasteIndex + belt.originalId; if (!BlueprintManager.pastedEntities.TryGetValue(pasteId, out PastedEntity pastedEntity)) { BuildPreview bp = BuildPreview.CreateSingle(belt.itemProto, belt.itemProto.prefabDesc, false); pastedEntity = new PastedEntity() { pasteIndex = pasteIndex, pasteId = pasteId, status = EPastedStatus.NEW, type = EPastedType.BELT, sourceBelt = belt, buildPreview = bp, }; BlueprintManager.pastedEntities.TryAdd(pasteId, pastedEntity); lock (actionBuild.buildPreviews) { actionBuild.buildPreviews.Add(bp); } } else { pastedEntity.status = EPastedStatus.UPDATE; } Vector2 newRelative = belt.cursorRelativePos.Rotate(yaw * Mathf.Deg2Rad, belt.originalSegmentCount); Vector2 sprPos = newRelative + targetSpr; int newSegmentCount = Util.GetSegmentsCount(sprPos); float sizeDeviation = belt.originalSegmentCount / (float)newSegmentCount; sprPos = new Vector2(newRelative.x, newRelative.y * sizeDeviation) + targetSpr; Vector3 absoluteBeltPos = sprPos.SnapToGrid(belt.altitude * 1.3333333f / 2); // belts have always 0 yaw Quaternion absoluteBeltRot = Maths.SphericalRotation(absoluteBeltPos, 0f); Pose pose = new Pose(absoluteBeltPos, absoluteBeltRot); pastedEntity.objId = InserterPoses.AddOverride(pose, belt.itemProto); pastedEntity.pose = pose; pastedEntity.buildPreview.lpos = absoluteBeltPos; pastedEntity.buildPreview.lrot = absoluteBeltRot; pastedEntity.buildPreview.condition = EBuildCondition.Ok; return(pastedEntity); }
public static void PasteBelt(int index, BeltCopy belt, Vector2 targetSpr, float yaw) { Vector2 newRelative = belt.cursorRelativePos.Rotate(yaw * Mathf.Deg2Rad, belt.originalSegmentCount); Vector2 sprPos = newRelative + targetSpr; float rawLatitudeIndex = (sprPos.x - Mathf.PI / 2) / 6.2831855f * 200; int latitudeIndex = Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(rawLatitudeIndex) - 0.1f)); int newSegmentCount = PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, 200); float sizeDeviation = belt.originalSegmentCount / (float)newSegmentCount; sprPos = new Vector2(newRelative.x, newRelative.y * sizeDeviation) + targetSpr; Vector3 absoluteBeltPos = sprPos.SnapToGrid(belt.altitude * 1.3333333f / 2); // belts have always 0 yaw Quaternion absoluteBeltRot = Maths.SphericalRotation(absoluteBeltPos, 0f); BuildPreview bp = BuildPreview.CreateSingle(belt.itemProto, belt.itemProto.prefabDesc, false); bp.lpos = absoluteBeltPos; bp.lrot = absoluteBeltRot; bp.outputToSlot = -1; bp.outputFromSlot = 0; bp.inputFromSlot = -1; bp.inputToSlot = 1; bp.outputOffset = 0; bp.inputOffset = 0; Pose pose = new Pose(absoluteBeltPos, absoluteBeltRot); int objId = InserterPoses.AddOverride(pose, belt.itemProto); pastedEntities.Add(belt.originalId, new PastedEntity() { type = EPastedType.BELT, index = index, pose = pose, objId = objId, buildPreview = bp, }); previews.Add(bp); }
public static void PasteBuilding(int index, BuildingCopy building, Vector2 targetSpr, float yaw) { Vector2 newRelative = building.cursorRelativePos.Rotate(yaw * Mathf.Deg2Rad, building.originalSegmentCount); Vector2 sprPos = newRelative + targetSpr; float rawLatitudeIndex = (sprPos.x - Mathf.PI / 2) / 6.2831855f * 200; int latitudeIndex = Mathf.FloorToInt(Mathf.Max(0f, Mathf.Abs(rawLatitudeIndex) - 0.1f)); int newSegmentCount = PlanetGrid.DetermineLongitudeSegmentCount(latitudeIndex, 200); float sizeDeviation = building.originalSegmentCount / (float)newSegmentCount; sprPos = new Vector2(newRelative.x, newRelative.y * sizeDeviation) + targetSpr; Vector3 absoluteBuildingPos = sprPos.SnapToGrid(); Quaternion absoluteBuildingRot = Maths.SphericalRotation(absoluteBuildingPos, yaw + building.cursorRelativeYaw); PrefabDesc desc = GetPrefabDesc(building); BuildPreview bp = BuildPreview.CreateSingle(building.itemProto, desc, true); bp.ResetInfos(); bp.desc = desc; bp.item = building.itemProto; bp.recipeId = building.recipeId; bp.lpos = absoluteBuildingPos; bp.lrot = absoluteBuildingRot; Pose pose = new Pose(absoluteBuildingPos, absoluteBuildingRot); int objId = InserterPoses.AddOverride(pose, building.itemProto); pastedEntities.Add(building.originalId, new PastedEntity() { type = EPastedType.BUILDING, index = index, sourceBuilding = building, pose = pose, objId = objId, buildPreview = bp }); ActivateColliders(absoluteBuildingPos); previews.Add(bp); }
public static PastedEntity ConcurrentPasteBuilding(int threadIndex, BuildingCopy building, Vector2 targetSpr, float yaw, int pasteIndex) { var actionBuild = _abs[threadIndex]; int pasteId = PASTE_INDEX_MULTIPLIER * pasteIndex + building.originalId; if (!BlueprintManager.pastedEntities.TryGetValue(pasteId, out PastedEntity pastedEntity)) { PrefabDesc desc = BlueprintManager.GetPrefabDesc(building); BuildPreview bp = BuildPreview.CreateSingle(building.itemProto, desc, true); bp.ResetInfos(); bp.desc = desc; bp.item = building.itemProto; bp.recipeId = building.recipeId; pastedEntity = new PastedEntity() { pasteIndex = pasteIndex, pasteId = pasteId, status = EPastedStatus.NEW, type = EPastedType.BUILDING, sourceBuilding = building, buildPreview = bp, }; BlueprintManager.pastedEntities.TryAdd(pasteId, pastedEntity); lock (actionBuild.buildPreviews) { actionBuild.buildPreviews.Add(bp); } } else { pastedEntity.status = EPastedStatus.UPDATE; } Vector2 newRelative = building.cursorRelativePos.Rotate(yaw * Mathf.Deg2Rad, building.originalSegmentCount); Vector2 sprPos = newRelative + targetSpr; int newSegmentCount = Util.GetSegmentsCount(sprPos); float sizeDeviation = building.originalSegmentCount / (float)newSegmentCount; sprPos = new Vector2(newRelative.x, newRelative.y * sizeDeviation) + targetSpr; Vector3 absoluteBuildingPos = sprPos.SnapToGrid(); Quaternion absoluteBuildingRot = Maths.SphericalRotation(absoluteBuildingPos, yaw + building.cursorRelativeYaw); absoluteBuildingPos += absoluteBuildingRot * (building.altitude * pastedEntity.buildPreview.desc.lapJoint); Pose pose = new Pose(absoluteBuildingPos, absoluteBuildingRot); pastedEntity.objId = InserterPoses.AddOverride(pose, building.itemProto); pastedEntity.pose = pose; pastedEntity.buildPreview.lpos = absoluteBuildingPos; pastedEntity.buildPreview.lrot = absoluteBuildingRot; pastedEntity.buildPreview.condition = EBuildCondition.Ok; pastedEntity.connectedEntities.Clear(); return(pastedEntity); }