Skip to content

Commit c0d369c

Browse files
authored
Cleaned up mod communications, and added new message type (#526)
* Cleaned up mod communications, and added new message type * Removed debug logs
1 parent 976d0a6 commit c0d369c

7 files changed

Lines changed: 322 additions & 52 deletions

File tree

‎Torch.Mod/Messages/IncomingMessage.cs‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎Torch.Mod/Messages/MessageBase.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Torch.Mod.Messages
1212
[ProtoInclude(2, typeof(NotificationMessage))]
1313
[ProtoInclude(3, typeof(VoxelResetMessage))]
1414
[ProtoInclude(4, typeof(JoinServerMessage))]
15+
[ProtoInclude(5, typeof(DrawDebug))]
1516
#endregion
1617

1718
[ProtoContract]
@@ -28,6 +29,8 @@ public abstract class MessageBase
2829
internal ulong Target;
2930
internal ulong[] Ignore;
3031
internal byte[] CompressedData;
32+
33+
3134
}
3235

3336
public enum MessageTarget
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+

2+
using ProtoBuf;
3+
using Sandbox.ModAPI;
4+
using System.Collections.Generic;
5+
using VRage.Game;
6+
using VRageMath;
7+
using Color = VRageMath.Color;
8+
9+
namespace Torch.Mod.Messages
10+
{
11+
[ProtoContract]
12+
public class DrawDebug : MessageBase
13+
{
14+
//Since we can only clear all renders, we can keep track of each one sent such that we can remove one but keep the rest
15+
public static Dictionary<string, DrawDebug> AllDraws = new Dictionary<string, DrawDebug>();
16+
17+
18+
//Used as an identifier if you only want to remove one draw group
19+
[ProtoMember(301)]
20+
public string uniqueName;
21+
22+
[ProtoMember(302)]
23+
public List<drawObject> drawObjects = new List<drawObject>();
24+
25+
26+
[ProtoMember(303)]
27+
public bool remove = false;
28+
29+
[ProtoMember(304)]
30+
public bool removeAll = false;
31+
32+
33+
34+
public DrawDebug() { }
35+
36+
37+
public DrawDebug(string uniqueName)
38+
{
39+
this.uniqueName = uniqueName;
40+
}
41+
42+
public override void ProcessClient()
43+
{
44+
//must have a unique name
45+
if(string.IsNullOrEmpty(uniqueName))
46+
return;
47+
48+
if(remove)
49+
{
50+
clear(uniqueName);
51+
return;
52+
}
53+
else if(removeAll)
54+
{
55+
clearAll();
56+
return;
57+
}
58+
59+
//MyAPIGateway.Utilities.ShowMessage("Torch", $"Hit process client on debug draw!");
60+
61+
if(!AllDraws.ContainsKey(uniqueName))
62+
AllDraws.Add(uniqueName, this);
63+
64+
//If both are not false, then we have new items to draw
65+
}
66+
67+
public override void ProcessServer()
68+
{
69+
//Nothing to do server side
70+
}
71+
72+
73+
74+
public void addOBB(BoundingBoxD box, Quaternion orientation, Color color, MySimpleObjectRasterizer raster, float intensity, float linethickness)
75+
{
76+
drawObject obj = new drawObject(drawObject.drawtype.OBB);
77+
78+
obj.box = box;
79+
obj.orientation = orientation;
80+
obj.color= color;
81+
obj.intensity = intensity;
82+
obj.linethickness = linethickness;
83+
obj.raster= raster;
84+
85+
drawObjects.Add(obj);
86+
}
87+
88+
public void addSphere(Vector3D position, float radius, Color color, MySimpleObjectRasterizer raster, float intensity, float linethickness)
89+
{
90+
drawObject obj = new drawObject(drawObject.drawtype.Sphere);
91+
92+
obj.position = position;
93+
obj.radius = radius;
94+
obj.color= color;
95+
obj.intensity = intensity;
96+
obj.linethickness = linethickness;
97+
obj.raster= raster;
98+
99+
drawObjects.Add(obj);
100+
}
101+
102+
103+
public static void clear(string uniquename)
104+
{
105+
if(AllDraws.ContainsKey(uniquename))
106+
AllDraws.Remove(uniquename);
107+
}
108+
109+
public static void clearAll()
110+
{
111+
AllDraws.Clear();
112+
}
113+
114+
//Updates individual method
115+
public void refreshDraw()
116+
{
117+
foreach(var draw in drawObjects)
118+
{
119+
draw.update();
120+
}
121+
}
122+
123+
124+
//static update to update all draws
125+
public static void refreshAllDraws()
126+
{
127+
//MyRenderProxy.DebugClearPersistentMessages();
128+
129+
foreach (var draw in AllDraws)
130+
{
131+
draw.Value.refreshDraw();
132+
}
133+
}
134+
135+
}
136+
137+
138+
[ProtoContract]
139+
public class drawObject
140+
{
141+
142+
public drawObject() { }
143+
144+
public drawObject(drawtype type) { this.type= type; }
145+
146+
147+
148+
[ProtoMember(100)]
149+
public drawtype type;
150+
151+
[ProtoMember(101)]
152+
public Vector3D position;
153+
154+
[ProtoMember(102)]
155+
public VRageMath.Color color;
156+
157+
[ProtoMember(103)]
158+
public MySimpleObjectRasterizer raster;
159+
160+
[ProtoMember(104)]
161+
public BoundingBoxD box;
162+
163+
[ProtoMember(105)]
164+
public Quaternion orientation;
165+
166+
167+
[ProtoMember(120)]
168+
public float radius;
169+
170+
[ProtoMember(121)]
171+
public float intensity;
172+
173+
[ProtoMember(122)]
174+
public float linethickness = -1;
175+
176+
//[ProtoMember(100)]
177+
//public MyOrientedBoundingBoxD obb;
178+
179+
180+
public enum drawtype
181+
{
182+
OBB,
183+
Sphere
184+
}
185+
186+
public void update()
187+
{
188+
189+
switch (type)
190+
{
191+
case drawtype.OBB:
192+
drawOBB();
193+
break;
194+
case drawtype.Sphere:
195+
drawSphere();
196+
break;
197+
}
198+
}
199+
200+
201+
public void drawOBB()
202+
{
203+
var transform = MatrixD.CreateFromQuaternion(orientation);
204+
var material = TorchModCore.id;
205+
MySimpleObjectDraw.DrawTransparentBox(ref transform, ref box, ref color, raster, 1, linethickness, material, material);
206+
207+
}
208+
209+
public void drawSphere()
210+
{
211+
var material = TorchModCore.id;
212+
var transform = MatrixD.CreateTranslation(position);
213+
MySimpleObjectDraw.DrawTransparentSphere(ref transform, 10, ref color, raster, 25, material, material, -1);
214+
}
215+
216+
217+
218+
219+
}
220+
221+
}

0 commit comments

Comments
 (0)