Skip to content

Commit d56512d

Browse files
committed
Revert concealment update because bugs
1 parent ee94a04 commit d56512d

10 files changed

Lines changed: 125 additions & 111 deletions

‎Concealment/Commands.cs‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,32 @@ public class Commands : CommandModule
99
{
1010
public ConcealmentPlugin Plugin => (ConcealmentPlugin)Context.Plugin;
1111

12-
[Command("update", "Forces a concealment update immediately."), Permission(MyPromoteLevel.SpaceMaster)]
13-
public void Conceal()
12+
[Command("conceal", "Conceal grids x distance from players."), Permission(MyPromoteLevel.SpaceMaster)]
13+
public void Conceal(double distance = 0)
1414
{
15-
var num = Plugin.ConcealGrids();
16-
Context.Respond($"{num.Item1} grids concealed, {num.Item2} grids revealed");
15+
if (distance == 0)
16+
{
17+
distance = Plugin.Settings.Data.ConcealDistance;
18+
}
19+
var num = Plugin.ConcealGrids(distance);
20+
Context.Respond($"{num} grids concealed.");
1721
}
18-
22+
23+
[Command("reveal", "Reveal all grids within the given distance"), Permission(MyPromoteLevel.SpaceMaster)]
24+
public void Reveal(double distance = 1000)
25+
{
26+
var pos = Context.Player?.Controller.ControlledEntity?.Entity.GetPosition();
27+
if (!pos.HasValue)
28+
{
29+
Context.Respond("You must be controlling an entity.");
30+
return;
31+
}
32+
33+
var sphere = new BoundingSphereD(pos.Value, distance);
34+
var num = Plugin.RevealGridsInSphere(sphere);
35+
Context.Respond($"{num} grids revealed.");
36+
}
37+
1938
[Command("reveal all", "Reveal all grids"), Permission(MyPromoteLevel.SpaceMaster)]
2039
public void RevealAll()
2140
{
@@ -27,7 +46,7 @@ public void RevealAll()
2746
public void Enable()
2847
{
2948
Plugin.Settings.Data.Enabled = true;
30-
Plugin.ConcealGrids();
49+
Plugin.ConcealGrids(Plugin.Settings.Data.ConcealDistance);
3150
}
3251

3352
[Command("conceal off", "Disable concealment.")]

‎Concealment/ConcealGroup.cs‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;
5-
using System.Windows.Media.Animation;
65
using Havok;
76
using NLog;
87
using Sandbox.Engine.Physics;
@@ -35,25 +34,6 @@ public class ConcealGroup
3534
public event Action<ConcealGroup> Closing;
3635
internal volatile int ProxyId = -1;
3736

38-
public override int GetHashCode()
39-
{
40-
int hash = 17;
41-
foreach (var grid in Grids)
42-
hash = hash * 23 + grid.EntityId.GetHashCode();
43-
return hash;
44-
}
45-
46-
public override bool Equals(object obj)
47-
{
48-
var a = this;
49-
var b = obj as ConcealGroup;
50-
51-
if (b == null)
52-
return false;
53-
54-
return a.GridNames.Equals(b.GridNames);
55-
}
56-
5737
public ConcealGroup(MyGroups<MyCubeGrid, MyGridPhysicalGroupData>.Group group)
5838
{
5939
Grids = group.Nodes.Select(n => n.NodeData).ToList();

‎Concealment/Concealment.csproj‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
<Private>False</Private>
3535
</Reference>
3636
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
37-
<HintPath>..\packages\NLog.4.4.2\lib\net45\NLog.dll</HintPath>
37+
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
38+
<Private>False</Private>
3839
</Reference>
3940
<Reference Include="PresentationCore" />
4041
<Reference Include="PresentationFramework" />
@@ -153,10 +154,8 @@
153154
<DependentUpon>DynamicConcealmentEditor.xaml</DependentUpon>
154155
</Compile>
155156
<Compile Include="DynamicConcealmentManager.cs" />
156-
<Compile Include="Patches\PatchReplicableRequest.cs" />
157157
<Compile Include="Properties\AssemblyInfo.cs" />
158158
<Compile Include="Settings.cs" />
159-
<Compile Include="Utilities.cs" />
160159
</ItemGroup>
161160
<ItemGroup>
162161
<Page Include="ConcealmentControl.xaml">

‎Concealment/ConcealmentControl.xaml‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,26 @@
1919
<CheckBox Content="Enable Concealment" Margin="3" IsChecked="{Binding Enabled}" />
2020
<CheckBox Content="Conceal Production" ToolTip="Conceal grids with active production blocks." Margin="3" IsChecked="{Binding ConcealProduction}" />
2121
<CheckBox Content="Conceal Pirates" ToolTip="Conceal grids owned by Space Pirates." Margin="3" IsChecked="{Binding ConcealPirates}" />
22-
22+
<StackPanel Orientation="Horizontal">
23+
<TextBox Margin="3" Width="150" Text="{Binding ConcealDistance}" />
24+
<Label Content="Conceal Distance (meters)" Margin="3" />
25+
</StackPanel>
26+
<StackPanel Orientation="Horizontal">
27+
<TextBox Margin="3" Width="150" Text="{Binding RevealDistance}" />
28+
<Label Content="Reveal Distance (meters)" Margin="3" />
29+
</StackPanel>
2330
<StackPanel Orientation="Horizontal">
2431
<TextBox Margin="3" Width="150" Text="{Binding ConcealInterval}" />
2532
<Label Content="Conceal Interval (ticks, 1/60 s)" Margin="3" />
2633
</StackPanel>
34+
<StackPanel Orientation="Horizontal">
35+
<TextBox Margin="3" Width="150" Text="{Binding RevealInterval}" />
36+
<Label Content="Reveal Interval (ticks, 1/60 s)" Margin="3" />
37+
</StackPanel>
2738
</StackPanel>
2839
<StackPanel Orientation="Horizontal">
29-
<Button Content="Force Update" Margin="3" Click="Conceal_OnClick" />
40+
<Button Content="Manual Conceal" Margin="3" Click="Conceal_OnClick" />
41+
<Button Content="Manual Reveal" Margin="3" Click="Reveal_OnClick" />
3042
</StackPanel>
3143
<Button Content="Edit Excluded Subtypes" Margin="3" Click="EditExclusion_OnClick"/>
3244
<Button Content="Edit Dynamic Concealment" Margin="3" Click="EditDynamicConcealment_OnClick"/>

‎Concealment/ConcealmentControl.xaml.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ private void RevealSelected_OnClick(object sender, RoutedEventArgs e)
3636
});
3737
}
3838

39+
private void Reveal_OnClick(object sender, RoutedEventArgs e)
40+
{
41+
var p = Plugin;
42+
Plugin.Torch.Invoke(delegate { p.RevealGrids(p.Settings.Data.RevealDistance); });
43+
}
44+
3945
private void Conceal_OnClick(object sender, RoutedEventArgs e)
4046
{
4147
var p = Plugin;
42-
Plugin.Torch.Invoke(delegate { p.ConcealGrids(); });
48+
Plugin.Torch.Invoke(delegate { p.ConcealGrids(p.Settings.Data.ConcealDistance); });
4349
}
4450

4551
private void EditExclusion_OnClick(object sender, RoutedEventArgs e)

‎Concealment/ConcealmentPlugin.cs‎

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
using VRage.Game.ModAPI;
3030
using VRage.Game.ObjectBuilders.ComponentSystem;
3131
using VRage.ModAPI;
32-
using VRage.Network;
3332
using VRageMath;
3433

3534
namespace Concealment
@@ -51,10 +50,6 @@ public sealed class ConcealmentPlugin : TorchPluginBase, IWpfPlugin
5150
private bool _settingsChanged;
5251
private bool _ready;
5352

54-
private MyReplicationServer Replication => (MyReplicationServer)MyMultiplayer.Static.ReplicationLayer;
55-
56-
public static ConcealmentPlugin Instance { get; private set; }
57-
5853
public ConcealmentPlugin()
5954
{
6055
_intersectGroups = new List<ConcealGroup>();
@@ -81,8 +76,6 @@ public override void Init(ITorchBase torch)
8176
Settings.Data.PropertyChanged += Data_PropertyChanged;
8277
_concealedAabbTree = new MyDynamicAABBTreeD(MyConstants.GAME_PRUNING_STRUCTURE_AABB_EXTENSION);
8378
torch.Managers.GetManager<ITorchSessionManager>()?.AddFactory(CreateManager);
84-
85-
Instance = this;
8679
}
8780

8881
private IManager CreateManager(ITorchSession session)
@@ -104,7 +97,9 @@ public override void Update()
10497
if (_ready)
10598
{
10699
if (_counter % (ulong)Settings.Data.ConcealInterval == 0)
107-
ConcealGrids();
100+
ConcealGrids(Settings.Data.ConcealDistance);
101+
if (_counter % (ulong)Settings.Data.RevealInterval == 0)
102+
RevealGrids(Settings.Data.RevealDistance);
108103
_counter += 1;
109104
}
110105

@@ -244,9 +239,8 @@ public int RevealGroup(ConcealGroup group)
244239
{
245240
if (!group.IsConcealed)
246241
{
247-
Log.Trace($"Group for reveal is not concealed: {group.GridNames}");
248-
//Log.Warn($"Attempted to reveal a group that wasn't concealed: {group.GridNames}");
249-
//Log.Warn(new StackTrace());
242+
Log.Warn($"Attempted to reveal a group that wasn't concealed: {group.GridNames}");
243+
Log.Warn(new StackTrace());
250244
return 0;
251245
}
252246

@@ -274,93 +268,70 @@ public int RevealGridsInSphere(BoundingSphereD sphere)
274268
return revealed;
275269
}
276270

277-
//public int RevealGrids()
278-
//{
279-
// var revealed = 0;
280-
281-
// foreach (var sphere in playerSpheres)
282-
// {
283-
// Log.Trace($"{sphere.Center}: {sphere.Radius}");
284-
// revealed += RevealGridsInSphere(sphere);
285-
// }
286-
287-
// if (_settingsChanged)
288-
// {
289-
// for (var i = ConcealedGroups.Count - 1; i >= 0; i--)
290-
// {
291-
// if (IsExcluded(ConcealedGroups[i]))
292-
// revealed += RevealGroup(ConcealedGroups[i]);
293-
// }
294-
295-
// _settingsChanged = false;
296-
// }
297-
298-
// if (revealed != 0)
299-
// Log.Info($"Revealed {revealed} grids near players.");
300-
// return revealed;
301-
//}
302-
303-
public (int ,int) ConcealGrids()
271+
public int RevealGrids(double distanceFromPlayers)
272+
{
273+
var revealed = 0;
274+
var playerSpheres = GetPlayerViewSpheres(distanceFromPlayers);
275+
foreach (var sphere in playerSpheres)
276+
{
277+
Log.Trace($"{sphere.Center}: {sphere.Radius}");
278+
revealed += RevealGridsInSphere(sphere);
279+
}
280+
281+
if (_settingsChanged)
282+
{
283+
for (var i = ConcealedGroups.Count - 1; i >= 0; i--)
284+
{
285+
if (IsExcluded(ConcealedGroups[i]))
286+
revealed += RevealGroup(ConcealedGroups[i]);
287+
}
288+
289+
_settingsChanged = false;
290+
}
291+
292+
if (revealed != 0)
293+
Log.Info($"Revealed {revealed} grids near players.");
294+
return revealed;
295+
}
296+
297+
public int ConcealGrids(double distanceFromPlayers = 0)
304298
{
305299
Log.Debug("Concealing grids");
306300
int concealed = 0;
307-
int revealed = 0;
301+
var playerSpheres = GetPlayerViewSpheres(distanceFromPlayers);
308302

309303
ConcurrentBag<ConcealGroup> groups = new ConcurrentBag<ConcealGroup>();
310-
ConcurrentBag<ConcealGroup> reveal = new ConcurrentBag<ConcealGroup>();
311304
var sw = Stopwatch.StartNew();
312305
Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group =>
313306
{
314307
var concealGroup = new ConcealGroup(group);
315308

316-
if (IsExcluded(concealGroup))
309+
if (distanceFromPlayers != 0)
317310
{
318-
Log.Trace("group excluded");
319-
return;
311+
var volume = group.GetWorldAABB();
312+
if (playerSpheres.Any(s => s.Contains(volume) != ContainmentType.Disjoint))
313+
{
314+
Log.Trace("group near player");
315+
return;
316+
}
320317
}
321318

322-
//Checks if any connected clients have requested any grid in this group for replication
323-
if (concealGroup.Grids.Any(g => Replication.IsReplicated(Utilities.GetReplicable(g))))
319+
if (IsExcluded(concealGroup))
324320
{
325-
Log.Trace("group in replication");
321+
Log.Trace("group excluded");
326322
return;
327323
}
328324

329325
groups.Add(concealGroup);
330326
});
331-
Log.Debug($"Scanned conceal grids in {sw.ElapsedMilliseconds}ms.");
332-
sw.Restart();
333-
334-
Parallel.ForEach(ConcealedGroups, group =>
335-
{
336-
if (IsExcluded(group))
337-
{
338-
reveal.Add(group);
339-
return;
340-
}
341-
342-
if (group.Grids.Any(grid => Replication.IsReplicated(Utilities.GetReplicable(grid))))
343-
{
344-
reveal.Add(group);
345-
return;
346-
}
347-
});
348-
Log.Debug($"Scanned reveal grids in {sw.ElapsedMilliseconds}ms");
327+
Log.Debug($"Scanned grids in {sw.ElapsedMilliseconds}ms.");
349328
sw.Restart();
350329

351330
foreach (var group in groups)
352331
{
353332
concealed += ConcealGroup(group);
354333
}
355334
Log.Debug($"Concealed grids in {sw.ElapsedMilliseconds}ms.");
356-
sw.Restart();
357-
358-
foreach (var group in reveal)
359-
{
360-
revealed += RevealGroup(group);
361-
}
362-
363-
Log.Debug($"Revealed grids in {sw.ElapsedMilliseconds}ms");
364335
sw.Stop();
365336

366337
var concealedCount = ConcealedGroups.SelectMany(x => x.Grids).Count();
@@ -369,10 +340,7 @@ public int RevealGridsInSphere(BoundingSphereD sphere)
369340
if (concealed > 0)
370341
Log.Info($"{concealedCount+concealed}/{totalCount} grids are concealed ({concealedCount+concealed/(float)totalCount:P}), {concealed} new.");
371342

372-
if(revealed > 0)
373-
Log.Info($"Revealed {revealed} grids replicated to players.");
374-
375-
return (concealed, revealed);
343+
return concealed;
376344
}
377345

378346
public bool IsExcluded(ConcealGroup group)

‎Concealment/DynamicConcealmentManager.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ private static MyRelationsBetweenPlayerAndBlock GetRelationTolerant(long id1, lo
613613
if (playerFaction1 == playerFaction2)
614614
return MyRelationsBetweenPlayerAndBlock.FactionShare;
615615
return MySession.Static.Factions.GetRelationBetweenFactions(playerFaction1.FactionId,
616-
playerFaction2.FactionId).Item1 == MyRelationsBetweenFactions.Neutral
616+
playerFaction2.FactionId) == MyRelationsBetweenFactions.Neutral
617617
? MyRelationsBetweenPlayerAndBlock.Neutral
618618
: MyRelationsBetweenPlayerAndBlock.Enemies;
619619
}

‎Concealment/Settings.cs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,36 @@ public int ConcealInterval
203203
}
204204
}
205205

206+
public int RevealInterval
207+
{
208+
get => _revealInterval;
209+
set
210+
{
211+
_revealInterval = value;
212+
OnPropertyChanged();
213+
}
214+
}
215+
216+
public double ConcealDistance
217+
{
218+
get => _concealDistance;
219+
set
220+
{
221+
_concealDistance = value;
222+
OnPropertyChanged();
223+
}
224+
}
225+
226+
public double RevealDistance
227+
{
228+
get => _revealDistance;
229+
set
230+
{
231+
_revealDistance = value;
232+
OnPropertyChanged();
233+
}
234+
}
235+
206236
public bool ConcealProduction
207237
{
208238
get => _concealProduction;

‎Concealment/packages.config‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="NLog" version="4.4.2" targetFramework="net461" />
3+
<package id="NLog" version="4.4.12" targetFramework="net461" />
44
</packages>

0 commit comments

Comments
 (0)