forked from austinvaness/CameraLCD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraLCD.cs
More file actions
114 lines (97 loc) · 3.17 KB
/
CameraLCD.cs
File metadata and controls
114 lines (97 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using avaness.CameraLCD.Gui;
using avaness.CameraLCD.Patch;
using HarmonyLib;
using Sandbox.Graphics.GUI;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using VRage.Plugins;
namespace avaness.CameraLCD
{
public class CameraLCD : IPlugin
{
public static CameraLCDSettings Settings { get; private set; }
private static readonly ConcurrentDictionary<DisplayId, CameraTSS> displays = new ConcurrentDictionary<DisplayId, CameraTSS>();
private static int displayIndex = 0;
private static int renderCount = 0;
public CameraLCD()
{
Settings = CameraLCDSettings.Load();
}
public void Init(object gameInstance)
{
Harmony harmony = new Harmony("avaness.CameraLCDRevived");
harmony.PatchAll(Assembly.GetExecutingAssembly());
Patch_MyRender11.Patch(harmony);
}
/// <summary>
/// Returns true if a camera was drawn.
/// </summary>
public static bool OnDrawScene()
{
renderCount++;
if (IsRenderFrame() && HasNextDisplay())
{
// Try to draw displays at index -> end
int i = displayIndex;
if(i < displays.Count)
{
foreach (var display in displays.Values.Skip(displayIndex))
{
i++;
if (display != null && display.OnDrawScene())
{
displayIndex = i;
return true;
}
}
}
// Try to draw displays at start -> index
i = 0;
foreach(var display in displays.Values)
{
if (i == displayIndex)
{
displayIndex++;
return false;
}
i++;
if (display != null && display.OnDrawScene())
{
displayIndex = i;
return true;
}
}
// This point will only be reached if displayIndex is out of bounds and no displays could render
displayIndex = 0;
}
return false;
}
public void Update()
{ }
public void Dispose()
{ }
public void OpenConfigDialog()
{
MyGuiSandbox.AddScreen(new MyGuiScreenPluginConfig());
}
public static void AddDisplay(DisplayId id, CameraTSS browser)
{
if (id.EntityId != 0)
displays.TryAdd(id, browser);
}
public static void RemoveDisplay(DisplayId id)
{
if (id.EntityId != 0)
displays.TryRemove(id, out _);
}
public static bool HasNextDisplay()
{
return displays.Count > 0;
}
public static bool IsRenderFrame()
{
return Settings.Enabled && (renderCount % Settings.Ratio) == 0;
}
}
}