Skip to content

Commit 041b190

Browse files
committed
Update for new torch version
1 parent 0ce5aba commit 041b190

6 files changed

Lines changed: 64 additions & 11 deletions

File tree

Concealment/Commands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public void Conceal(double distance = 0)
2323
[Command("reveal", "Reveal all grids within the given distance"), Permission(MyPromoteLevel.SpaceMaster)]
2424
public void Reveal(double distance = 1000)
2525
{
26-
var pos = Context.Player.Controller.ControlledEntity?.Entity.GetPosition();
26+
var pos = Context.Player?.Controller.ControlledEntity?.Entity.GetPosition();
2727
if (!pos.HasValue)
2828
{
29-
Context.Respond("You must be controlling an entity");
29+
Context.Respond("You must be controlling an entity.");
3030
return;
3131
}
3232

Concealment/Concealment.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,19 @@
169169
<Generator>MSBuild:Compile</Generator>
170170
</Page>
171171
</ItemGroup>
172+
<ItemGroup>
173+
<Content Include="manifest.tt">
174+
<Generator>TextTemplatingFileGenerator</Generator>
175+
<LastGenOutput>manifest.xml</LastGenOutput>
176+
</Content>
177+
<Content Include="manifest.xml">
178+
<AutoGen>True</AutoGen>
179+
<DesignTime>True</DesignTime>
180+
<DependentUpon>manifest.tt</DependentUpon>
181+
</Content>
182+
</ItemGroup>
183+
<ItemGroup>
184+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
185+
</ItemGroup>
172186
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
173187
</Project>

Concealment/ConcealmentControl.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
<StackPanel DockPanel.Dock="Top">
1111
<StackPanel DataContext="{Binding Settings.Data}">
1212
<CheckBox Content="Enable Concealment" Margin="3" IsChecked="{Binding Enabled}" />
13-
<CheckBox Content="Manage Physics" Margin="3" IsChecked="{Binding ManagePhysics}" />
14-
<CheckBox Content="Manage Gamelogic" Margin="3" IsChecked="{Binding ManageGamelogic}" />
1513
<StackPanel Orientation="Horizontal">
1614
<TextBox Margin="3" Width="150" Text="{Binding ConcealDistance}" />
1715
<Label Content="Conceal Distance (meters)" Margin="3" />

Concealment/ConcealmentPlugin.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5+
using System.IO;
56
using System.Linq;
67
using System.Threading;
78
using System.Threading.Tasks;
89
using System.Windows.Controls;
910
using Havok;
1011
using NLog;
12+
using Sandbox.Definitions;
1113
using Sandbox.Engine.Multiplayer;
1214
using Sandbox.Game.Entities;
1315
using Sandbox.Game.EntityComponents;
@@ -20,17 +22,21 @@
2022
using Torch.Managers;
2123
using VRage.Game;
2224
using VRage.Game.Components;
25+
using VRage.Game.Definitions;
2326
using VRage.Game.Entity;
2427
using VRage.Game.ModAPI;
28+
using VRage.Game.ObjectBuilders.ComponentSystem;
2529
using VRage.ModAPI;
30+
using VRage.ObjectBuilders;
31+
using VRage.Utils;
2632
using VRageMath;
2733

2834
namespace Concealment
2935
{
3036
[Plugin("Concealment", "1.1", "17f44521-b77a-4e85-810f-ee73311cf75d")]
3137
public class ConcealmentPlugin : TorchPluginBase, IWpfPlugin
3238
{
33-
public Persistent<Settings> Settings { get; }
39+
public Persistent<Settings> Settings { get; private set; }
3440
public MTObservableCollection<ConcealGroup> ConcealGroups { get; } = new MTObservableCollection<ConcealGroup>();
3541

3642
private static readonly Logger Log = LogManager.GetLogger("Concealment");
@@ -44,7 +50,6 @@ public class ConcealmentPlugin : TorchPluginBase, IWpfPlugin
4450
public ConcealmentPlugin()
4551
{
4652
_intersectGroups = new List<ConcealGroup>();
47-
Settings = Persistent<Settings>.Load("Concealment.cfg");
4853
}
4954

5055
public UserControl GetControl()
@@ -55,8 +60,18 @@ public UserControl GetControl()
5560
public override void Init(ITorchBase torch)
5661
{
5762
base.Init(torch);
63+
Settings = Persistent<Settings>.Load(Path.Combine(StoragePath, "Concealment.cfg"));
5864
_concealedAabbTree = new MyDynamicAABBTreeD(MyConstants.GAME_PRUNING_STRUCTURE_AABB_EXTENSION);
5965
torch.SessionUnloading += Torch_SessionUnloading;
66+
67+
//Init storage component.
68+
var comp = new MyModStorageComponentDefinition
69+
{
70+
Id = new MyDefinitionId(typeof(MyObjectBuilder_ModStorageComponent), "Concealment"),
71+
RegisteredStorageGuids = new[] {Id}
72+
};
73+
MyDefinitionManager.Static.Definitions.AddDefinition(comp);
74+
6075
}
6176

6277
private void Torch_SessionUnloading()
@@ -224,6 +239,7 @@ public int RevealGroup(ConcealGroup group)
224239

225240
public int RevealGridsInSphere(BoundingSphereD sphere)
226241
{
242+
Log.Debug($"reveal in sphere {sphere.Center} | {sphere.Radius}");
227243
var revealed = 0;
228244
#if !NOPHYS
229245
_concealedAabbTree.OverlapAllBoundingSphere(ref sphere, _intersectGroups);
@@ -244,10 +260,10 @@ public int RevealGridsInSphere(BoundingSphereD sphere)
244260

245261
public int RevealNearbyGrids(double distanceFromPlayers)
246262
{
247-
//annoying log spam
248-
//Log.Debug("Revealing nearby grids");
263+
Log.Debug("Revealing nearby grids");
249264
var revealed = 0;
250265
var playerSpheres = GetPlayerBoundingSpheres(distanceFromPlayers);
266+
Log.Debug(playerSpheres.Count);
251267
foreach (var sphere in playerSpheres)
252268
revealed += RevealGridsInSphere(sphere);
253269

@@ -263,19 +279,20 @@ public int ConcealDistantGrids(double distanceFromPlayers)
263279
var playerSpheres = GetPlayerBoundingSpheres(distanceFromPlayers);
264280

265281
ConcurrentBag<ConcealGroup> groups = new ConcurrentBag<ConcealGroup>();
266-
Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group =>
282+
//Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group =>
283+
foreach (var group in MyCubeGridGroups.Static.Physical.Groups)
267284
{
268285
var concealGroup = new ConcealGroup(group);
269286

270287
var volume = group.GetWorldAABB();
271288
if (playerSpheres.Any(s => s.Contains(volume) != ContainmentType.Disjoint))
272-
return;
289+
continue;
273290

274291
//if (IsExcluded(concealGroup))
275292
// return;
276293

277294
groups.Add(concealGroup);
278-
});
295+
}
279296
foreach (var group in groups)
280297
{
281298
concealed += ConcealGroup(group);

Concealment/manifest.tt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<#@ template debug="false" hostspecific="false" language="C#" #>
2+
<#@ assembly name="System.Core" #>
3+
<#@ import namespace="System.Linq" #>
4+
<#@ import namespace="System.Text" #>
5+
<#@ import namespace="System.Collections.Generic" #>
6+
<#@ output extension=".xml" #>
7+
8+
<# var dt = DateTime.Now;
9+
int major = 1;
10+
int minor = 0;
11+
int build = dt.DayOfYear;
12+
int rev = (int)dt.TimeOfDay.TotalMinutes / 2;
13+
#>
14+
<?xml version="1.0"?>
15+
<PluginManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
16+
<Repository>TorchAPI/Concealment</Repository>
17+
<Version><#= major #>.<#= minor #>.<#= build #>.<#= rev #></Version>
18+
</PluginManifest>

Concealment/manifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
<?xml version="1.0"?>
3+
<PluginManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<Repository>TorchAPI/Concealment</Repository>
5+
<Version>1.0.162.241</Version>
6+
</PluginManifest>

0 commit comments

Comments
 (0)