返回提交历史
Modified
Common/DeathDomainTrailVisualSystem.cs
+204
-8
Modified
Projectiles/ReaperDeathDomainRiftProjectile.cs
+2
-1
XFEstudio/DeathMod
合并死神残留领域裂缝描边
50ada4d
代码差异
2 个文件
+206
-9
@@ -19,6 +19,10 @@ internal sealed class DeathDomainTrailVisualSystem : ModSystem
19
19
private static readonly Dictionary<long, TrailDrawState> drawStates = [];
20
20
private static readonly VertexPositionColorTexture[] vertices =
21
21
new VertexPositionColorTexture[MaximumPoints * 2];
22
private static readonly VertexPositionColorTexture[] outlineVertices =
23
new VertexPositionColorTexture[(MaximumPoints - 1) * 2 * 6];
24
private static readonly bool[] outlineVisible =
25
new bool[(MaximumPoints - 1) * 2];
22
26
private static readonly short[] indices = CreateIndices();
23
27
private static BasicEffect? effect;
24
28
@@ -26,10 +30,13 @@ internal sealed class DeathDomainTrailVisualSystem : ModSystem
26
30
IReadOnlyList<Vector2> Points,
27
31
float Width,
28
32
float Opacity,
33
bool MergeOverlappingRims,
34
Vector4 Bounds,
29
35
ulong UpdateTick);
30
36
31
37
internal static void Record(int owner, int identity,
32
IReadOnlyList<Vector2> points, float width, float opacity)
38
IReadOnlyList<Vector2> points, float width, float opacity,
39
bool mergeOverlappingRims = false)
33
40
{
34
41
if (Main.dedServ || points.Count < 2 || width <= 0.5f
35
42
|| opacity <= 0.001f)
@@ -38,6 +45,7 @@ internal sealed class DeathDomainTrailVisualSystem : ModSystem
38
45
}
39
46
long key = ((long)owner << 32) | (uint)identity;
40
47
drawStates[key] = new TrailDrawState(points, width, opacity,
48
mergeOverlappingRims, CalculateBounds(points, width),
41
49
Main.GameUpdateCount);
42
50
}
43
51
@@ -94,19 +102,37 @@ internal sealed class DeathDomainTrailVisualSystem : ModSystem
94
102
graphicsDevice.RasterizerState = RasterizerState.CullNone;
95
103
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
96
104
97
foreach (TrailDrawState state in drawStates.Values)
105
foreach ((long visualId, TrailDrawState state) in drawStates)
98
106
{
99
107
if (Main.GameUpdateCount > state.UpdateTick + 1)
100
108
continue;
101
109
int pointCount = Math.Min(MaximumPoints, state.Points.Count);
102
110
if (pointCount < 2)
103
111
continue;
104
DrawSolidRibbon(graphicsDevice, state, state.Width * 1.72f,
105
new Color(174, 0, 44, 0) * (state.Opacity * 0.24f));
106
DrawSolidRibbon(graphicsDevice, state, state.Width * 1.40f,
107
new Color(244, 12, 66, 235) * state.Opacity);
108
DrawSolidRibbon(graphicsDevice, state, state.Width * 1.17f,
109
new Color(255, 187, 178, 235) * (state.Opacity * 0.88f));
112
if (state.MergeOverlappingRims)
113
{
114
BuildMergedOutlineVisibility(visualId, state, pointCount);
115
DrawOutlineBand(graphicsDevice, state, pointCount,
116
state.Width * 0.70f, state.Width * 0.86f,
117
new Color(174, 0, 44, 0) * (state.Opacity * 0.24f));
118
DrawOutlineBand(graphicsDevice, state, pointCount,
119
state.Width * 0.585f, state.Width * 0.70f,
120
new Color(244, 12, 66, 235) * state.Opacity);
121
DrawOutlineBand(graphicsDevice, state, pointCount,
122
state.Width * 0.50f, state.Width * 0.585f,
123
new Color(255, 187, 178, 235)
124
* (state.Opacity * 0.88f));
125
}
126
else
127
{
128
DrawSolidRibbon(graphicsDevice, state, state.Width * 1.72f,
129
new Color(174, 0, 44, 0) * (state.Opacity * 0.24f));
130
DrawSolidRibbon(graphicsDevice, state, state.Width * 1.40f,
131
new Color(244, 12, 66, 235) * state.Opacity);
132
DrawSolidRibbon(graphicsDevice, state, state.Width * 1.17f,
133
new Color(255, 187, 178, 235)
134
* (state.Opacity * 0.88f));
135
}
110
136
BuildVertices(state, state.Width, Color.White * state.Opacity);
111
137
effect.TextureEnabled = true;
112
138
for (int layer = 0; layer < 3; layer++)
@@ -123,6 +149,176 @@ internal sealed class DeathDomainTrailVisualSystem : ModSystem
123
149
}
124
150
}
125
151
152
private static void BuildMergedOutlineVisibility(long visualId,
153
TrailDrawState state, int pointCount)
154
{
155
Array.Clear(outlineVisible, 0, outlineVisible.Length);
156
for (int segment = 0; segment < pointCount - 1; segment++)
157
{
158
Vector2 start = state.Points[segment];
159
Vector2 end = state.Points[segment + 1];
160
Vector2 tangent = (end - start).SafeNormalize(Vector2.UnitX);
161
Vector2 normal = tangent.RotatedBy(MathHelper.PiOver2);
162
Vector2 middle = (start + end) * 0.5f;
163
float middleProgress = (segment + 0.5f)
164
/ Math.Max(1f, pointCount - 1f);
165
float boundaryHalfWidth = state.Width
166
* GetTrailTaper(middleProgress) * 0.5f;
167
for (int sideIndex = 0; sideIndex < 2; sideIndex++)
168
{
169
float side = sideIndex == 0 ? -1f : 1f;
170
Vector2 boundaryProbe = middle
171
+ normal * side * boundaryHalfWidth;
172
outlineVisible[segment * 2 + sideIndex] =
173
!IsCoveredByAnotherMergedTrail(boundaryProbe, visualId);
174
}
175
}
176
}
177
178
private static void DrawOutlineBand(GraphicsDevice graphicsDevice,
179
TrailDrawState state, int pointCount, float innerHalfWidth,
180
float outerHalfWidth, Color color)
181
{
182
if (effect is null)
183
return;
184
185
int vertexIndex = 0;
186
for (int segment = 0; segment < pointCount - 1; segment++)
187
{
188
Vector2 start = state.Points[segment];
189
Vector2 end = state.Points[segment + 1];
190
Vector2 startNormal = GetTrailNormal(state.Points, segment,
191
pointCount);
192
Vector2 endNormal = GetTrailNormal(state.Points, segment + 1,
193
pointCount);
194
float startTaper = GetTrailTaper(segment
195
/ Math.Max(1f, pointCount - 1f));
196
float endTaper = GetTrailTaper((segment + 1f)
197
/ Math.Max(1f, pointCount - 1f));
198
for (int sideIndex = 0; sideIndex < 2; sideIndex++)
199
{
200
if (!outlineVisible[segment * 2 + sideIndex])
201
continue;
202
float side = sideIndex == 0 ? -1f : 1f;
203
Vector2 innerStart = start
204
+ startNormal * side * innerHalfWidth * startTaper;
205
Vector2 outerStart = start
206
+ startNormal * side * outerHalfWidth * startTaper;
207
Vector2 innerEnd = end
208
+ endNormal * side * innerHalfWidth * endTaper;
209
Vector2 outerEnd = end
210
+ endNormal * side * outerHalfWidth * endTaper;
211
WriteOutlineVertex(ref vertexIndex, outerStart, color);
212
WriteOutlineVertex(ref vertexIndex, innerStart, color);
213
WriteOutlineVertex(ref vertexIndex, outerEnd, color);
214
WriteOutlineVertex(ref vertexIndex, outerEnd, color);
215
WriteOutlineVertex(ref vertexIndex, innerStart, color);
216
WriteOutlineVertex(ref vertexIndex, innerEnd, color);
217
}
218
}
219
if (vertexIndex < 3)
220
return;
221
222
effect.TextureEnabled = false;
223
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
224
{
225
pass.Apply();
226
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList,
227
outlineVertices, 0, vertexIndex / 3);
228
}
229
}
230
231
private static Vector2 GetTrailNormal(IReadOnlyList<Vector2> points,
232
int index, int pointCount)
233
{
234
Vector2 previous = points[Math.Max(0, index - 1)];
235
Vector2 next = points[Math.Min(pointCount - 1, index + 1)];
236
return (next - previous).SafeNormalize(Vector2.UnitX)
237
.RotatedBy(MathHelper.PiOver2);
238
}
239
240
private static void WriteOutlineVertex(ref int vertexIndex,
241
Vector2 world, Color color)
242
{
243
outlineVertices[vertexIndex++] = new VertexPositionColorTexture(
244
new Vector3(world - Main.screenPosition, 0f), color, Vector2.Zero);
245
}
246
247
private static bool IsCoveredByAnotherMergedTrail(Vector2 world,
248
long currentVisualId)
249
{
250
const float sharedBoundaryTolerance = 1.5f;
251
foreach ((long otherVisualId, TrailDrawState other) in drawStates)
252
{
253
if (otherVisualId == currentVisualId
254
|| !other.MergeOverlappingRims
255
|| Main.GameUpdateCount > other.UpdateTick + 1
256
|| !Contains(other.Bounds, world))
257
{
258
continue;
259
}
260
261
float coverage = GetMaximumTrailCoverage(world, other);
262
if (coverage > sharedBoundaryTolerance)
263
return true;
264
if (coverage >= -sharedBoundaryTolerance
265
&& otherVisualId > currentVisualId)
266
{
267
return true;
268
}
269
}
270
return false;
271
}
272
273
private static float GetMaximumTrailCoverage(Vector2 point,
274
TrailDrawState state)
275
{
276
float bestCoverage = float.MinValue;
277
int count = Math.Min(MaximumPoints, state.Points.Count);
278
for (int index = 1; index < count; index++)
279
{
280
Vector2 start = state.Points[index - 1];
281
Vector2 delta = state.Points[index] - start;
282
float lengthSquared = delta.LengthSquared();
283
float progress = lengthSquared <= 0.001f ? 0f
284
: MathHelper.Clamp(Vector2.Dot(point - start, delta)
285
/ lengthSquared, 0f, 1f);
286
float trailProgress = (index - 1f + progress)
287
/ Math.Max(1f, count - 1f);
288
float localHalfWidth = state.Width
289
* GetTrailTaper(trailProgress) * 0.5f;
290
float distance = Vector2.Distance(point,
291
start + delta * progress);
292
bestCoverage = Math.Max(bestCoverage, localHalfWidth - distance);
293
}
294
return bestCoverage;
295
}
296
297
private static float GetTrailTaper(float progress)
298
=> (float)Math.Pow(Math.Max(0f,
299
Math.Sin(MathHelper.Clamp(progress, 0f, 1f) * MathHelper.Pi)),
300
0.34f);
301
302
private static Vector4 CalculateBounds(IReadOnlyList<Vector2> points,
303
float width)
304
{
305
Vector2 minimum = points[0];
306
Vector2 maximum = points[0];
307
int count = Math.Min(MaximumPoints, points.Count);
308
for (int index = 1; index < count; index++)
309
{
310
minimum = Vector2.Min(minimum, points[index]);
311
maximum = Vector2.Max(maximum, points[index]);
312
}
313
float padding = width * 0.5f + 2f;
314
return new Vector4(minimum.X - padding, minimum.Y - padding,
315
maximum.X + padding, maximum.Y + padding);
316
}
317
318
private static bool Contains(Vector4 bounds, Vector2 point)
319
=> point.X >= bounds.X && point.Y >= bounds.Y
320
&& point.X <= bounds.Z && point.Y <= bounds.W;
321
126
322
private static void DrawSolidRibbon(GraphicsDevice graphicsDevice,
127
323
TrailDrawState state, float width, Color color)
128
324
{
@@ -106,7 +106,8 @@ public sealed class ReaperDeathDomainRiftProjectile : ModProjectile
106
106
if (Main.netMode != NetmodeID.Server)
107
107
{
108
108
DeathDomainTrailVisualSystem.Record(Projectile.owner,
109
Projectile.identity, points, TrailWidth, opacity);
109
Projectile.identity, points, TrailWidth, opacity,
110
mergeOverlappingRims: true);
110
111
}
111
112
if (Main.netMode != NetmodeID.MultiplayerClient)
112
113
TryHarvestIntersectingEnemies();