From 2bd198a1837e53cfb48c1e8315545ac5b6b21f55 Mon Sep 17 00:00:00 2001 From: Westin Miller Date: Wed, 30 Aug 2017 17:57:46 -0700 Subject: [PATCH 1/2] Reveal and conceal while respecting weld groups. Related to TorchAPI/Torch#50 --- Concealment.sln | 2 +- Concealment/ConcealGroup.cs | 86 ++++++++++++++++++++++++++++++++ Concealment/ConcealmentPlugin.cs | 55 ++++---------------- 3 files changed, 96 insertions(+), 47 deletions(-) diff --git a/Concealment.sln b/Concealment.sln index 1cf89d7..953c4ac 100644 --- a/Concealment.sln +++ b/Concealment.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.26730.8 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment", "Concealment/Concealment.csproj", "{E5C0184B-7DC4-43D8-872E-2F71162748AA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concealment", "Concealment\Concealment.csproj", "{E5C0184B-7DC4-43D8-872E-2F71162748AA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Concealment/ConcealGroup.cs b/Concealment/ConcealGroup.cs index 5eb7b09..05a36cd 100644 --- a/Concealment/ConcealGroup.cs +++ b/Concealment/ConcealGroup.cs @@ -3,11 +3,14 @@ using System.Linq; using System.Reflection; using NLog; +using Sandbox.Engine.Physics; using Sandbox.Game.Entities; using Sandbox.Game.Entities.Blocks; using Sandbox.Game.World; using SpaceEngineers.Game.Entities.Blocks; +using VRage.Game.Entity; using VRage.Groups; +using VRage.ModAPI; using VRageMath; namespace Concealment @@ -120,6 +123,89 @@ public bool IsCryoOccupied(ulong steamId) return false; } + + /// + /// Conceals this group from game and physics logic. + /// + public void Conceal() + { + foreach (var body in Grids) + if (body.Parent == null) + UnregisterRecursive(body); + + foreach (var body in Grids) + body.Physics?.UnweldAll(false); + foreach (var body in Grids) + body.Physics?.Deactivate(); + + foreach (var entity in Grids) + if (entity.Parent == null) + MyGamePruningStructure.Remove(entity); + + void UnregisterRecursive(IMyEntity e) + { + MyEntities.UnregisterForUpdate((MyEntity)e); + if (e.Hierarchy == null) + return; + + foreach (var child in e.Hierarchy.Children) + UnregisterRecursive(child.Container.Entity); + } + } + + /// + /// Reveals this group to game and physics logic. + /// + public void Reveal() + { + foreach (var entity in Grids) + if (entity.Parent == null) + MyGamePruningStructure.Add(entity); + + + var weldGroups = new HashSet.Group>(); + foreach (var body in Grids) + { + if (body.Physics == null) + continue; + var group = MyWeldingGroups.Static.GetGroup(body); + if (group == null) + body.Physics.Activate(); + else + weldGroups.Add(group); + } + foreach (var group in weldGroups) + { + var body = group.GroupData.Parent; + if (!(body.Physics is MyPhysicsBody bodyPhysics)) + continue; + bodyPhysics.Activate(); + + foreach (var child in group.Nodes) + if (child.NodeData != body && + !child.NodeData.MarkedForClose && + child.NodeData.Physics is MyPhysicsBody physBody) + bodyPhysics.Weld(physBody); + + body.RaisePhysicsChanged(); + } + + + foreach (var entity in Grids) + if (entity.Parent == null) + RegisterRecursive(entity); + + void RegisterRecursive(IMyEntity e) + { + MyEntities.RegisterForUpdate((MyEntity)e); + if (e.Hierarchy == null) + return; + + foreach (var child in e.Hierarchy.Children) + RegisterRecursive(child.Container.Entity); + } + } + } } diff --git a/Concealment/ConcealmentPlugin.cs b/Concealment/ConcealmentPlugin.cs index a420794..59b64bd 100644 --- a/Concealment/ConcealmentPlugin.cs +++ b/Concealment/ConcealmentPlugin.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Controls; -using Havok; using NLog; using Sandbox.Definitions; using Sandbox.Engine.Multiplayer; @@ -23,7 +22,6 @@ using VRage.Game; using VRage.Game.Components; using VRage.Game.Definitions; -using VRage.Game.Entity; using VRage.Game.ModAPI; using VRage.Game.ObjectBuilders.ComponentSystem; using VRage.ModAPI; @@ -54,7 +52,7 @@ public ConcealmentPlugin() UserControl IWpfPlugin.GetControl() { - return _control ?? (_control = new ConcealmentControl {DataContext = this}); + return _control ?? (_control = new ConcealmentControl { DataContext = this }); } public override void Init(ITorchBase torch) @@ -198,47 +196,6 @@ private void RevealSpawns(PlayerRequestArgs args) }); } - private void ConcealEntity(IMyEntity entity) - { - if (entity != entity.GetTopMostParent()) - return; - - entity.GetStorage().SetValue(Id, "True"); - MyGamePruningStructure.Remove((MyEntity)entity); - entity.Physics?.Deactivate(); - UnregisterRecursive(entity); - - void UnregisterRecursive(IMyEntity e) - { - MyEntities.UnregisterForUpdate((MyEntity)e); - if (e.Hierarchy == null) - return; - - foreach (var child in e.Hierarchy.Children) - UnregisterRecursive(child.Container.Entity); - } - } - - private void RevealEntity(IMyEntity entity) - { - if (entity != entity.GetTopMostParent()) - return; - - entity.GetStorage().SetValue(Id, "False"); - MyGamePruningStructure.Add((MyEntity)entity); - entity.Physics?.Activate(); - RegisterRecursive(entity); - - void RegisterRecursive(IMyEntity e) - { - MyEntities.RegisterForUpdate((MyEntity)e); - if (e.Hierarchy == null) - return; - - foreach (var child in e.Hierarchy.Children) - RegisterRecursive(child.Container.Entity); - } - } private int ConcealGroup(ConcealGroup group) { @@ -246,7 +203,10 @@ private int ConcealGroup(ConcealGroup group) return 0; Log.Debug($"Concealing grids: {group.GridNames}"); - group.Grids.ForEach(ConcealEntity); + group.Conceal(); + foreach (var entity in group.Grids) + entity.GetStorage().SetValue(Id, "True"); + group.UpdateAABB(); var aabb = group.WorldAABB; group.ProxyId = _concealedAabbTree.AddProxy(ref aabb, group, 0); @@ -277,7 +237,10 @@ public int RevealGroup(ConcealGroup group) var count = group.Grids.Count; Log.Debug($"Revealing grids: {group.GridNames}"); - group.Grids.ForEach(RevealEntity); + group.Reveal(); + foreach (var entity in group.Grids) + entity.GetStorage().SetValue(Id, "False"); + ConcealedGroups.Remove(group); _concealedAabbTree.RemoveProxy(group.ProxyId); group.UpdatePostReveal(); From 475381bfb7ce07d577d79cdb096cbb8e9c4b1f6d Mon Sep 17 00:00:00 2001 From: Westin Miller Date: Wed, 6 Sep 2017 20:13:24 -0700 Subject: [PATCH 2/2] Auto-release setup --- Jenkins/release.ps1 | 52 +++++++++++++++++++++++++++++++++++++++++++++ Jenkinsfile | 10 +++++++++ 2 files changed, 62 insertions(+) create mode 100644 Jenkins/release.ps1 diff --git a/Jenkins/release.ps1 b/Jenkins/release.ps1 new file mode 100644 index 0000000..81e5e63 --- /dev/null +++ b/Jenkins/release.ps1 @@ -0,0 +1,52 @@ +param([string] $ApiBase, [string]$tagName, [string]$authinfo, [string[]] $assetPaths) +Add-Type -AssemblyName "System.Web" + +$headers = @{ + Authorization = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($authinfo)) + Accept = "application/vnd.github.v3+json" +} +try +{ + Write-Output("Checking if release with tag " + $tagName + " already exists...") + $release = Invoke-RestMethod -Uri ($ApiBase+"releases/tags/$tagName") -Method "GET" -Headers $headers + Write-Output(" Using existing release " + $release.id + " at " + $release.html_url) +} catch { + Write-Output(" Doesn't exist") + $rel_arg = @{ + tag_name=$tagName + name="Generated $tagName" + body="" + draft=$TRUE + prerelease=$tagName.Contains("alpha") -or $tagName.Contains("beta") + } + Write-Output("Creating new release " + $tagName + "...") + $release = Invoke-RestMethod -Uri ($ApiBase+"releases") -Method "POST" -Headers $headers -Body (ConvertTo-Json($rel_arg)) + Write-Output(" Created new release " + $tagName + " at " + $release.html_url) +} + +$assetsApiBase = $release.assets_url +Write-Output("Checking for existing assets...") +$existingAssets = Invoke-RestMethod -Uri ($assetsApiBase) -Method "GET" -Headers $headers +$assetLabels = ($assetPaths | ForEach-Object {[System.IO.Path]::GetFileName($_)}) +foreach ($asset in $existingAssets) { + if ($assetLabels -contains $asset.name) { + $uri = $asset.url + Write-Output(" Deleting old asset " + $asset.name + " (id " + $asset.id + "); URI=" + $uri) + $result = Invoke-RestMethod -Uri $uri -Method "DELETE" -Headers $headers + } +} +Write-Output("Uploading assets...") +$uploadUrl = $release.upload_url.Substring(0, $release.upload_url.LastIndexOf('{')) +foreach ($asset in $assetPaths) { + $assetName = [System.IO.Path]::GetFileName($asset) + $assetType = [System.Web.MimeMapping]::GetMimeMapping($asset) + $assetData = [System.IO.File]::ReadAllBytes($asset) + $headerExtra = $headers + @{ + "Content-Type" = $assetType + Name = $assetName + } + $uri = $uploadUrl + "?name=" + $assetName + Write-Output(" Uploading " + $asset + " as " + $assetType + "; URI=" + $uri) + $result = Invoke-RestMethod -Uri $uri -Method "POST" -Headers $headerExtra -Body $assetData + Write-Output(" ID=" + $result.id + ", found at=" + $result.browser_download_url) +} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 952f992..55c9c41 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -65,6 +65,16 @@ node { stage('Archive') { archiveArtifacts artifacts: "bin/x64/Release/Concealment.dll", caseSensitive: false, fingerprint: true, onlyIfSuccessful: true } + + gitVersion = bat(returnStdout: true, script: "@git describe --tags").trim() + gitSimpleVersion = bat(returnStdout: true, script: "@git describe --tags --abbrev=0").trim() + if (gitVersion == gitSimpleVersion) { + stage('Release') { + withCredentials([usernamePassword(credentialsId: 'torch-github', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { + powershell "& ./Jenkins/release.ps1 \"https://api.github.com/repos/TorchAPI/Concealment/\" \"$gitSimpleVersion\" \"$USERNAME:$PASSWORD\" @(\"bin/x64/Release/Concealment.dll\")" + } + } + } } else currentBuild.result = "FAIL"