Skip to content

Commit b95ef31

Browse files
authored
Merge pull request #4 from TorchAPI/staging
Prepare v1.3.0
2 parents 7ec1a49 + c0fb09a commit b95ef31

4 files changed

Lines changed: 157 additions & 46 deletions

File tree

‎Concealment/ConcealGroup.cs‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
using System.Linq;
44
using System.Reflection;
55
using NLog;
6+
using Sandbox.Engine.Physics;
67
using Sandbox.Game.Entities;
78
using Sandbox.Game.Entities.Blocks;
89
using Sandbox.Game.World;
910
using SpaceEngineers.Game.Entities.Blocks;
11+
using VRage.Game.Entity;
1012
using VRage.Groups;
13+
using VRage.ModAPI;
1114
using VRageMath;
1215

1316
namespace Concealment
@@ -120,6 +123,89 @@ public bool IsCryoOccupied(ulong steamId)
120123

121124
return false;
122125
}
126+
127+
/// <summary>
128+
/// Conceals this group from game and physics logic.
129+
/// </summary>
130+
public void Conceal()
131+
{
132+
foreach (var body in Grids)
133+
if (body.Parent == null)
134+
UnregisterRecursive(body);
135+
136+
foreach (var body in Grids)
137+
body.Physics?.UnweldAll(false);
138+
foreach (var body in Grids)
139+
body.Physics?.Deactivate();
140+
141+
foreach (var entity in Grids)
142+
if (entity.Parent == null)
143+
MyGamePruningStructure.Remove(entity);
144+
145+
void UnregisterRecursive(IMyEntity e)
146+
{
147+
MyEntities.UnregisterForUpdate((MyEntity)e);
148+
if (e.Hierarchy == null)
149+
return;
150+
151+
foreach (var child in e.Hierarchy.Children)
152+
UnregisterRecursive(child.Container.Entity);
153+
}
154+
}
155+
156+
/// <summary>
157+
/// Reveals this group to game and physics logic.
158+
/// </summary>
159+
public void Reveal()
160+
{
161+
foreach (var entity in Grids)
162+
if (entity.Parent == null)
163+
MyGamePruningStructure.Add(entity);
164+
165+
166+
var weldGroups = new HashSet<MyGroups<MyEntity, MyWeldGroupData>.Group>();
167+
foreach (var body in Grids)
168+
{
169+
if (body.Physics == null)
170+
continue;
171+
var group = MyWeldingGroups.Static.GetGroup(body);
172+
if (group == null)
173+
body.Physics.Activate();
174+
else
175+
weldGroups.Add(group);
176+
}
177+
foreach (var group in weldGroups)
178+
{
179+
var body = group.GroupData.Parent;
180+
if (!(body.Physics is MyPhysicsBody bodyPhysics))
181+
continue;
182+
bodyPhysics.Activate();
183+
184+
foreach (var child in group.Nodes)
185+
if (child.NodeData != body &&
186+
!child.NodeData.MarkedForClose &&
187+
child.NodeData.Physics is MyPhysicsBody physBody)
188+
bodyPhysics.Weld(physBody);
189+
190+
body.RaisePhysicsChanged();
191+
}
192+
193+
194+
foreach (var entity in Grids)
195+
if (entity.Parent == null)
196+
RegisterRecursive(entity);
197+
198+
void RegisterRecursive(IMyEntity e)
199+
{
200+
MyEntities.RegisterForUpdate((MyEntity)e);
201+
if (e.Hierarchy == null)
202+
return;
203+
204+
foreach (var child in e.Hierarchy.Children)
205+
RegisterRecursive(child.Container.Entity);
206+
}
207+
}
208+
123209
}
124210

125211
}

‎Concealment/ConcealmentPlugin.cs‎

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using System.Windows.Controls;
10-
using Havok;
1110
using NLog;
1211
using Sandbox.Definitions;
1312
using Sandbox.Engine.Multiplayer;
@@ -23,7 +22,6 @@
2322
using VRage.Game;
2423
using VRage.Game.Components;
2524
using VRage.Game.Definitions;
26-
using VRage.Game.Entity;
2725
using VRage.Game.ModAPI;
2826
using VRage.Game.ObjectBuilders.ComponentSystem;
2927
using VRage.ModAPI;
@@ -54,7 +52,7 @@ public ConcealmentPlugin()
5452

5553
UserControl IWpfPlugin.GetControl()
5654
{
57-
return _control ?? (_control = new ConcealmentControl {DataContext = this});
55+
return _control ?? (_control = new ConcealmentControl { DataContext = this });
5856
}
5957

6058
public override void Init(ITorchBase torch)
@@ -198,55 +196,17 @@ private void RevealSpawns(PlayerRequestArgs args)
198196
});
199197
}
200198

201-
private void ConcealEntity(IMyEntity entity)
202-
{
203-
if (entity != entity.GetTopMostParent())
204-
return;
205-
206-
entity.GetStorage().SetValue(Id, "True");
207-
MyGamePruningStructure.Remove((MyEntity)entity);
208-
entity.Physics?.Deactivate();
209-
UnregisterRecursive(entity);
210-
211-
void UnregisterRecursive(IMyEntity e)
212-
{
213-
MyEntities.UnregisterForUpdate((MyEntity)e);
214-
if (e.Hierarchy == null)
215-
return;
216-
217-
foreach (var child in e.Hierarchy.Children)
218-
UnregisterRecursive(child.Container.Entity);
219-
}
220-
}
221-
222-
private void RevealEntity(IMyEntity entity)
223-
{
224-
if (entity != entity.GetTopMostParent())
225-
return;
226-
227-
entity.GetStorage().SetValue(Id, "False");
228-
MyGamePruningStructure.Add((MyEntity)entity);
229-
entity.Physics?.Activate();
230-
RegisterRecursive(entity);
231-
232-
void RegisterRecursive(IMyEntity e)
233-
{
234-
MyEntities.RegisterForUpdate((MyEntity)e);
235-
if (e.Hierarchy == null)
236-
return;
237-
238-
foreach (var child in e.Hierarchy.Children)
239-
RegisterRecursive(child.Container.Entity);
240-
}
241-
}
242199

243200
private int ConcealGroup(ConcealGroup group)
244201
{
245202
if (ConcealedGroups.Any(g => g.Id == group.Id))
246203
return 0;
247204

248205
Log.Debug($"Concealing grids: {group.GridNames}");
249-
group.Grids.ForEach(ConcealEntity);
206+
group.Conceal();
207+
foreach (var entity in group.Grids)
208+
entity.GetStorage().SetValue(Id, "True");
209+
250210
group.UpdateAABB();
251211
var aabb = group.WorldAABB;
252212
group.ProxyId = _concealedAabbTree.AddProxy(ref aabb, group, 0);
@@ -277,7 +237,10 @@ public int RevealGroup(ConcealGroup group)
277237

278238
var count = group.Grids.Count;
279239
Log.Debug($"Revealing grids: {group.GridNames}");
280-
group.Grids.ForEach(RevealEntity);
240+
group.Reveal();
241+
foreach (var entity in group.Grids)
242+
entity.GetStorage().SetValue(Id, "False");
243+
281244
ConcealedGroups.Remove(group);
282245
_concealedAabbTree.RemoveProxy(group.ProxyId);
283246
group.UpdatePostReveal();

‎Jenkins/release.ps1‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
param([string] $ApiBase, [string]$tagName, [string]$authinfo, [string[]] $assetPaths)
2+
Add-Type -AssemblyName "System.Web"
3+
4+
$headers = @{
5+
Authorization = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($authinfo))
6+
Accept = "application/vnd.github.v3+json"
7+
}
8+
try
9+
{
10+
Write-Output("Checking if release with tag " + $tagName + " already exists...")
11+
$release = Invoke-RestMethod -Uri ($ApiBase+"releases/tags/$tagName") -Method "GET" -Headers $headers
12+
Write-Output(" Using existing release " + $release.id + " at " + $release.html_url)
13+
} catch {
14+
Write-Output(" Doesn't exist")
15+
$rel_arg = @{
16+
tag_name=$tagName
17+
name="Generated $tagName"
18+
body=""
19+
draft=$TRUE
20+
prerelease=$tagName.Contains("alpha") -or $tagName.Contains("beta")
21+
}
22+
Write-Output("Creating new release " + $tagName + "...")
23+
$release = Invoke-RestMethod -Uri ($ApiBase+"releases") -Method "POST" -Headers $headers -Body (ConvertTo-Json($rel_arg))
24+
Write-Output(" Created new release " + $tagName + " at " + $release.html_url)
25+
}
26+
27+
$assetsApiBase = $release.assets_url
28+
Write-Output("Checking for existing assets...")
29+
$existingAssets = Invoke-RestMethod -Uri ($assetsApiBase) -Method "GET" -Headers $headers
30+
$assetLabels = ($assetPaths | ForEach-Object {[System.IO.Path]::GetFileName($_)})
31+
foreach ($asset in $existingAssets) {
32+
if ($assetLabels -contains $asset.name) {
33+
$uri = $asset.url
34+
Write-Output(" Deleting old asset " + $asset.name + " (id " + $asset.id + "); URI=" + $uri)
35+
$result = Invoke-RestMethod -Uri $uri -Method "DELETE" -Headers $headers
36+
}
37+
}
38+
Write-Output("Uploading assets...")
39+
$uploadUrl = $release.upload_url.Substring(0, $release.upload_url.LastIndexOf('{'))
40+
foreach ($asset in $assetPaths) {
41+
$assetName = [System.IO.Path]::GetFileName($asset)
42+
$assetType = [System.Web.MimeMapping]::GetMimeMapping($asset)
43+
$assetData = [System.IO.File]::ReadAllBytes($asset)
44+
$headerExtra = $headers + @{
45+
"Content-Type" = $assetType
46+
Name = $assetName
47+
}
48+
$uri = $uploadUrl + "?name=" + $assetName
49+
Write-Output(" Uploading " + $asset + " as " + $assetType + "; URI=" + $uri)
50+
$result = Invoke-RestMethod -Uri $uri -Method "POST" -Headers $headerExtra -Body $assetData
51+
Write-Output(" ID=" + $result.id + ", found at=" + $result.browser_download_url)
52+
}

‎Jenkinsfile‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ node {
6565
stage('Archive') {
6666
archiveArtifacts artifacts: "bin/x64/Release/Concealment.dll", caseSensitive: false, fingerprint: true, onlyIfSuccessful: true
6767
}
68+
69+
gitVersion = bat(returnStdout: true, script: "@git describe --tags").trim()
70+
gitSimpleVersion = bat(returnStdout: true, script: "@git describe --tags --abbrev=0").trim()
71+
if (gitVersion == gitSimpleVersion) {
72+
stage('Release') {
73+
withCredentials([usernamePassword(credentialsId: 'torch-github', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
74+
powershell "& ./Jenkins/release.ps1 \"https://api.github.com/repos/TorchAPI/Concealment/\" \"$gitSimpleVersion\" \"$USERNAME:$PASSWORD\" @(\"bin/x64/Release/Concealment.dll\")"
75+
}
76+
}
77+
}
6878
}
6979
else
7080
currentBuild.result = "FAIL"

0 commit comments

Comments
 (0)