Skip to content

Commit 8d05d68

Browse files
committed
ImGui and Map Viewer
1 parent 3b76744 commit 8d05d68

File tree

101 files changed

+3654
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+3654
-166
lines changed

LoaderAvalonia/LoaderAvalonia.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<ItemGroup>
2121
<ProjectReference Include="..\AvaloniaStyles\AvaloniaStyles.csproj" />
2222
<ProjectReference Include="..\Modules\WDE.EventScriptsEditor\WDE.EventScriptsEditor.csproj" />
23+
<ProjectReference Include="..\Rendering\WDE.MapSpawns\WDE.MapSpawns.csproj" />
2324
<ProjectReference Include="..\WDE.AzerothCore\WDE.AzerothCore.csproj" />
2425
<ProjectReference Include="..\WDE.CMaNGOS\WDE.CMaNGOS.csproj" />
2526
<ProjectReference Include="..\WDE.Common.Avalonia\WDE.Common.Avalonia.csproj" />

LoaderAvalonia/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using WDE.WoWHeadConnector;
3131
using WDE.AnniversaryInfo;
3232
using WDE.EventScriptsEditor;
33+
using WDE.MapSpawns;
3334

3435
namespace LoaderAvalonia
3536
{
@@ -70,7 +71,8 @@ public static void Main(string[] args)
7071
typeof(CMaNGOSModule),
7172
typeof(CMMySqlDatabaseModule),
7273
typeof(AnniversaryModule),
73-
typeof(EventScriptsModule)
74+
typeof(EventScriptsModule),
75+
typeof(MapSpawnsModule)
7476
};
7577
WoWDatabaseEditorCore.Avalonia.Program.PreloadedModules = modules;
7678
WoWDatabaseEditorCore.Avalonia.Program.Main(args);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using ImGuiNET;
2+
using WDE.Common.Utils;
3+
using WDE.MapRenderer;
4+
using WDE.MapRenderer.Managers;
5+
using WDE.MpqReader.DBC;
6+
7+
namespace RenderingTester;
8+
9+
public class DebugWindow : IGameModule
10+
{
11+
private readonly MapStore maps;
12+
private readonly ChunkManager chunkManager;
13+
private readonly IGameContext gameContext;
14+
private readonly IGameProperties gameProperties;
15+
public object? ViewModel => null;
16+
private int selectedMap = 0;
17+
private string[] allMapNames;
18+
private int[] allMapIds;
19+
private bool renderTerrain = true;
20+
21+
public DebugWindow(MapStore maps,
22+
ChunkManager chunkManager,
23+
IGameContext gameContext,
24+
IGameProperties gameProperties)
25+
{
26+
this.maps = maps;
27+
this.chunkManager = chunkManager;
28+
this.gameContext = gameContext;
29+
this.gameProperties = gameProperties;
30+
allMapNames = maps.Select(x => x.Id + " - " + x.Name).ToArray();
31+
allMapIds = maps.Select(x => x.Id).ToArray();
32+
}
33+
34+
public void Dispose()
35+
{
36+
}
37+
38+
public void Initialize()
39+
{
40+
}
41+
42+
public void Update(float delta)
43+
{
44+
}
45+
46+
public void RenderGUI()
47+
{
48+
ImGui.Begin("Debug");
49+
50+
selectedMap = allMapIds.IndexOf(gameContext.CurrentMap.Id);
51+
52+
if (ImGui.Combo("Map", ref selectedMap, allMapNames, allMapNames.Length))
53+
gameContext.SetMap(allMapIds[selectedMap]);
54+
55+
if (ImGui.Checkbox("Render terrain", ref renderTerrain))
56+
chunkManager.RenderTerrain = renderTerrain;
57+
58+
bool pausedTime = gameProperties.DisableTimeFlow;
59+
if (ImGui.Checkbox("Pause time", ref pausedTime))
60+
gameProperties.DisableTimeFlow = pausedTime;
61+
62+
var minutes = gameProperties.CurrentTime.TotalMinutes;
63+
if (ImGui.SliderInt("Current time", ref minutes, 0, 1439))
64+
gameProperties.CurrentTime = Time.FromMinutes(minutes);
65+
66+
bool renderGui = gameProperties.RenderGui;
67+
if (ImGui.Checkbox("Render GUI", ref renderGui))
68+
gameProperties.RenderGui = renderGui;
69+
70+
float dynamicResolution = gameProperties.DynamicResolution;
71+
if (ImGui.SliderFloat("Dynamic scale", ref dynamicResolution, 0.1f, 1))
72+
gameProperties.DynamicResolution = dynamicResolution;
73+
74+
ImGui.End();
75+
}
76+
}

Rendering/RenderingTester/RenderingTester.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</Target>
1313

1414
<ItemGroup>
15+
<PackageReference Include="ImGui.NET" Version="1.87.3" />
1516
<PackageReference Include="JetBrains.Profiler.Api" Version="1.2.0-preview2" />
1617
<PackageReference Include="OpenTK" Version="4.6.4" />
1718
</ItemGroup>
@@ -26,6 +27,7 @@
2627
<ProjectReference Include="..\..\WoWDatabaseEditor.Common\WDE.DbcStore\WDE.DbcStore.csproj" />
2728
<ProjectReference Include="..\..\WoWDatabaseEditor.Common\WDE.TrinityMySqlDatabase\WDE.TrinityMySqlDatabase.csproj" />
2829
<ProjectReference Include="..\..\WoWDatabaseEditor\WoWDatabaseEditorCore.csproj" />
30+
<ProjectReference Include="..\WDE.MapSpawns\WDE.MapSpawns.csproj" />
2931
</ItemGroup>
3032

3133
<ItemGroup>

Rendering/RenderingTester/StandaloneCustomGameModule.cs

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace RenderingTester;
2020

21-
public class StandaloneCustomGameModule : IGameModule, IPostProcess
21+
public class StandaloneCustomGameModule : IGameModule
2222
{
2323
private readonly IUIManager uiManager;
2424
private readonly CoroutineManager coroutineManager;
@@ -64,39 +64,13 @@ public StandaloneCustomGameModule(IUIManager uiManager,
6464
this.mdxManager = mdxManager;
6565
}
6666

67-
private Material blurMaterial = null!;
68-
private Material replacementMaterial = null!;
69-
private Material outlineMaterial = null!;
70-
7167
public void Dispose()
7268
{
7369
}
7470

7571
public void Initialize()
7672
{
7773
//gameContext.SetMap(571);
78-
replacementMaterial = materialManager.CreateMaterial("data/unlit_flat_m2.json");
79-
replacementMaterial.SetUniform("mesh_color", new Vector4(1, 0, 0, 1));
80-
81-
outlineMaterial = materialManager.CreateMaterial("data/outline.json");
82-
outlineMaterial.BlendingEnabled = false;
83-
outlineMaterial.SourceBlending = Blending.One;
84-
outlineMaterial.DestinationBlending = Blending.Zero;
85-
outlineMaterial.DepthTesting = DepthCompare.Always;
86-
87-
blurMaterial = materialManager.CreateMaterial("data/blur.json");
88-
blurMaterial.BlendingEnabled = true;
89-
blurMaterial.SourceBlending = Blending.SrcAlpha;
90-
blurMaterial.DestinationBlending = Blending.OneMinusSrcAlpha;
91-
blurMaterial.DepthTesting = DepthCompare.Always;
92-
blurMaterial.SetUniform("blurSize", 0.125f/4);
93-
//blurMaterial.SetUniformInt("horizontalPass", 0);
94-
//blurMaterial.SetUniform("sigma", 4);
95-
96-
RT = new ScreenRenderTexture(engine);
97-
RT_downscaled = new ScreenRenderTexture(engine, 0.25f);
98-
99-
renderManager.AddPostprocess(this);
10074
}
10175

10276
private bool profiling = false;
@@ -116,15 +90,8 @@ public void Update(float delta)
11690
}
11791
}
11892

119-
private ScreenRenderTexture RT = null!;
120-
private ScreenRenderTexture RT_downscaled = null!;
121-
12293
public void Render()
12394
{
124-
RT.Update();
125-
RT_downscaled.Update();
126-
outlineMaterial.SetTexture("outlineTex", RT_downscaled);
127-
outlineMaterial.SetTexture("outlineTexUnBlurred", RT);
12895
}
12996

13097
public void RenderGUI()
@@ -157,10 +124,4 @@ public void RenderGUI()
157124
ui2.Text("calibri", $"Batches saved by instancing: " + stats.InstancedDrawSaved, 12, Vector4.One);
158125
ui2.Text("calibri", $"Tris: " + stats.TrianglesDrawn, 12, Vector4.One);
159126
}
160-
161-
public void RenderPostprocess(IRenderManager context, TextureHandle currentImage)
162-
{
163-
outlineMaterial.SetTexture("_MainTex", currentImage);
164-
context.RenderFullscreenPlane(outlineMaterial);
165-
}
166127
}

Rendering/RenderingTester/Window.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using WDE.Common.Tasks;
77
using WDE.MapRenderer;
88
using WDE.MapRenderer.Managers;
9+
using WDE.MapSpawns;
10+
using WDE.MapSpawns.Rendering;
911
using WDE.MpqReader.DBC;
1012
using WDE.MpqReader.Structures;
1113

@@ -23,7 +25,9 @@ public class DummyGameView : IGameView
2325
public IEnumerable<Func<IContainerProvider, IGameModule>> Modules { get; } =
2426
new List<Func<IContainerProvider, IGameModule>>()
2527
{
26-
provider => provider.Resolve<StandaloneCustomGameModule>()
28+
provider => provider.Resolve<StandaloneCustomGameModule>(),
29+
provider => provider.Resolve<DebugWindow>(),
30+
provider => provider.Resolve<SpawnViewer>()
2731
};
2832
public event Action<Func<IContainerProvider, IGameModule>>? ModuleRegistered;
2933
public event Action<Func<IContainerProvider, IGameModule>>? ModuleRemoved;
@@ -37,15 +41,16 @@ public Task<Game> Open()
3741

3842
public class DummyGameProperties : IGameProperties
3943
{
40-
public bool OverrideLighting => false;
41-
public bool DisableTimeFlow => false;
42-
public int TimeSpeedMultiplier => 2;
43-
public bool ShowGrid => false;
44+
public bool OverrideLighting { get; set; } = false;
45+
public bool DisableTimeFlow { get; set; } = false;
46+
public int TimeSpeedMultiplier { get; set; } = 2;
47+
public bool ShowGrid { get; set; } = false;
4448
public Time CurrentTime { get; set; } = Time.FromMinutes(720);
45-
public float ViewDistanceModifier => 16;
46-
public bool ShowAreaTriggers => false;
47-
public int TextureQuality => 0;
48-
public float DynamicResolution => 1;
49+
public float ViewDistanceModifier { get; set; } = 16;
50+
public bool ShowAreaTriggers { get; set; } = false;
51+
public int TextureQuality { get; set; } = 0;
52+
public float DynamicResolution { get; set; } = 1;
53+
public bool RenderGui { get; set; } = true;
4954
}
5055

5156
public class DummyMessageBox : IMessageBoxService

Rendering/TheAvaloniaOpenGL/DebugDevice.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ namespace TheAvaloniaOpenGL
77
{
88
public class DebugDevice : IDevice
99
{
10-
private RealDevice device;
10+
private IDevice device;
1111

1212
public List<string> commands = new();
1313

14-
public DebugDevice(RealDevice device)
14+
public DebugDevice(IDevice device)
1515
{
1616
this.device = device;
1717
}
@@ -491,13 +491,13 @@ public unsafe string GetActiveUniform(int unit, int index, int maxLength, out in
491491
public void DepthMask(bool @on)
492492
{
493493
Report($"DepthMask({@on})");
494-
device.DepthMask(@on ? 1 : 0);
494+
device.DepthMask(@on);
495495
}
496496

497497
public void DepthFunction(DepthFunction func)
498498
{
499499
Report($"DepthFunc({func})");
500-
device.DepthFunc(func);
500+
device.DepthFunction(func);
501501
}
502502

503503
public void Scissor(int x, int y, int width, int height)
@@ -509,7 +509,7 @@ public void Scissor(int x, int y, int width, int height)
509509
public unsafe void UniformMatrix4f(int location, ref Matrix4x4 m, bool transpose)
510510
{
511511
Report($"Matrix4f({location}, {transpose}, {m})");
512-
device.UniformMatrix4fv(location, 1, transpose, Unsafe.AsPointer(ref m));
512+
device.UniformMatrix4f(location, ref m, transpose);
513513
}
514514

515515
public void Flush()
@@ -521,5 +521,10 @@ public void Finish()
521521
{
522522
device.Finish();
523523
}
524+
525+
public void Debug(string msg)
526+
{
527+
commands.Add(msg);
528+
}
524529
}
525530
}

Rendering/TheAvaloniaOpenGL/IIDevice.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,6 @@ public interface IDevice
9797
void Scissor(int x, int y, int width, int height);
9898
void Flush();
9999
void Finish();
100+
void Debug(string msg);
100101
}
101102
}

Rendering/TheAvaloniaOpenGL/OpenTKDevice.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ public void Finish()
523523
GL.Finish();
524524
}
525525

526+
public void Debug(string msg)
527+
{
528+
529+
}
530+
526531
public void BlitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, ClearBufferMask mask, OpenGLBindings.BlitFramebufferFilter filter)
527532
{
528533
GL.BlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, (OpenTK.Graphics.OpenGL4.ClearBufferMask)mask, (BlitFramebufferFilter)filter);

Rendering/TheAvaloniaOpenGL/RealDeviceWrapper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,5 +426,10 @@ public void Finish()
426426
{
427427
device.Finish();
428428
}
429+
430+
public void Debug(string msg)
431+
{
432+
433+
}
429434
}
430435
}

Rendering/TheEngine/Components/LocalToWorld.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ public static void SetCopyParentTransform(this Entity entity, IEntityManager ent
1515
{
1616
entityManager.GetComponent<CopyParentTransform>(entity).Parent = parent;
1717
}
18+
19+
public static Entity GetRoot(this Entity entity, IEntityManager entityManager)
20+
{
21+
var copyTransformArchetype = entityManager.NewArchetype().WithComponentData<CopyParentTransform>();
22+
while (entityManager.Is(entity, copyTransformArchetype))
23+
{
24+
entity = entityManager.GetComponent<CopyParentTransform>(entity).Parent;
25+
}
26+
27+
return entity;
28+
}
1829
}
1930

2031
public struct LocalToWorld : IComponentData

Rendering/TheEngine/Components/RenderEnabledBit.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private RenderEnabledBit(bool b)
9494

9595
public void Enable()
9696
{
97-
enabled |= 1;
97+
enabled |= 0b01;
9898
}
9999

100100
public void Disable()
@@ -111,11 +111,11 @@ public void SetDisabled(bool disabled)
111111
{
112112
if (disabled)
113113
{
114-
enabled |= 10;
114+
enabled |= 0b10;
115115
}
116116
else
117117
{
118-
enabled &= 0b01;
118+
enabled &= 0b1;
119119
}
120120
}
121121

0 commit comments

Comments
 (0)