XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

DeathMod

【Terraria】DeathMod (now aka Soul Harvest)

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/DeathMod

修复领域纹理的主线程加载

b593882
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

1 个文件 +13 -6
Modified Common/DeathDomainPrimitiveTextureSystem.cs +13 -6
@@ -16,11 +16,8 @@ internal sealed class DeathDomainPrimitiveTextureSystem : ModSystem
16 16 {
17 17 internal static Texture2D? BladeMask { get; private set; }
18 18
19 public override void PostSetupContent()
19 private static Texture2D CreateBladeMask()
20 20 {
21 if (Main.dedServ)
22 return;
23
24 21 const int width = 1024;
25 22 const int height = 256;
26 23 Texture2D texture = new(Main.instance.GraphicsDevice, width, height, false, SurfaceFormat.Color);
@@ -44,13 +41,15 @@ internal sealed class DeathDomainPrimitiveTextureSystem : ModSystem
44 41 }
45 42
46 43 texture.SetData(pixels);
47 BladeMask = texture;
44 return texture;
48 45 }
49 46
50 47 public override void Unload()
51 48 {
52 BladeMask?.Dispose();
49 Texture2D? texture = BladeMask;
53 50 BladeMask = null;
51 if (texture is not null && !Main.dedServ)
52 Main.QueueMainThreadAction(texture.Dispose);
54 53 }
55 54
56 55 internal static void DrawBlade(
@@ -61,7 +60,15 @@ internal sealed class DeathDomainPrimitiveTextureSystem : ModSystem
61 60 Color color,
62 61 float completion = 1f)
63 62 {
63 // Mod content hooks may run on a loader worker thread. PreDraw always runs
64 // on the main thread, so lazy creation here satisfies FNA's graphics-thread
65 // requirement and keeps dedicated servers entirely texture-free.
64 66 Texture2D? texture = BladeMask;
67 if (texture is null && !Main.dedServ)
68 {
69 texture = CreateBladeMask();
70 BladeMask = texture;
71 }
65 72 completion = MathHelper.Clamp(completion, 0f, 1f);
66 73 if (texture is null || length <= 0.05f || width <= 0.05f || completion <= 0.001f)
67 74 return;