Skip to content

Commit 051268a

Browse files
committed
Small corrections to the 3d View
1 parent 3789328 commit 051268a

File tree

10 files changed

+84
-21
lines changed

10 files changed

+84
-21
lines changed

Rendering/TheEngine/Interfaces/IRenderManager.cs

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public interface IRenderManager
1313
void Render(IMesh mesh, Material material, int submesh, Matrix localToWorld, Matrix? worldToLocal = null);
1414
void Render(IMesh mesh, Material material, int submesh, Vector3 position);
1515
void RenderInstancedIndirect(IMesh mesh, Material material, int submesh, int count);
16+
float ViewDistanceModifier { get; set; }
1617
}
1718
}

Rendering/TheEngine/Managers/RenderManager.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ internal static WorldMeshBounds LocalToWorld(in MeshBounds local, in LocalToWorl
366366
Stopwatch materialtimer = new Stopwatch();
367367
Stopwatch buffertimer = new Stopwatch();
368368
Stopwatch draw = new Stopwatch();
369+
private float viewDistanceModifier = 8;
370+
369371
private void RenderEntities()
370372
{
371373
var cameraPosition = cameraManager.MainCamera.Transform.Position;
@@ -387,6 +389,7 @@ private void RenderEntities()
387389
engine.statsManager.Counters.BoundsCalc.Add(boundsUpdate.Elapsed.TotalMilliseconds);
388390

389391
culler.Restart();
392+
float mod = viewDistanceModifier * viewDistanceModifier;
390393
toRenderArchetype.ParallelForEach<LocalToWorld, RenderEnabledBit, WorldMeshBounds>((itr, start, end, l2w, bits, worldMeshBounds) =>
391394
{
392395
for (int i = start; i < end; ++i)
@@ -395,8 +398,8 @@ private void RenderEntities()
395398
var pos = l2w[i].Position;
396399
var boundingBoxSize = boundingBox.Size;
397400
var size = boundingBoxSize.X + boundingBoxSize.Y + boundingBoxSize.Z;
398-
size = Math.Max(size, 40);
399-
bool doRender = (pos - cameraPosition).LengthSquared() < (size) * (size) * 4 * 4;
401+
size = Math.Max(size, 60);
402+
bool doRender = (pos - cameraPosition).LengthSquared() < (size) * (size) * mod;
400403
if (doRender)
401404
{
402405
bits[i] = (RenderEnabledBit)(frustum.Contains(ref boundingBox) != ContainmentType.Disjoint);
@@ -543,6 +546,16 @@ public void RenderInstancedIndirect(IMesh mesh, Material material, int submesh,
543546
engine.Device.DrawIndexedInstanced(count, instancesCount, start, 0, 0);
544547
}
545548

549+
public float ViewDistanceModifier
550+
{
551+
get => viewDistanceModifier;
552+
set
553+
{
554+
if (value > 0)
555+
viewDistanceModifier = value;
556+
}
557+
}
558+
546559
private void UpdateSceneBuffer()
547560
{
548561
var camera = cameraManager.MainCamera;

Rendering/TheEngine/TheEnginePanel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected override void OnOpenGlRender(GlInterface gl, int fb)
154154
Tick(delta);
155155
engine.statsManager.Counters.FrameTime.Add(delta);
156156
sw.Restart();
157-
RaisePropertyChanged(FrameRateProperty, Optional<float>.Empty, FrameRate);
157+
Dispatcher.UIThread.Post(() => RaisePropertyChanged(FrameRateProperty, Optional<float>.Empty, FrameRate), DispatcherPriority.Render);
158158

159159
Update(delta);
160160

WDE.MapRenderer/GameManager.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void Initialize(Engine engine)
3838
TimeManager = new TimeManager(this);
3939
ScreenSpaceSelector = new ScreenSpaceSelector(this);
4040
DbcManager = new DbcManager(this, databaseClientFileOpener);
41-
CurrentMap = DbcManager.MapStore.FirstOrDefault() ?? Map.Empty;
41+
CurrentMap = DbcManager.MapStore.FirstOrDefault(m => m.Id == 1) ?? Map.Empty;
4242
TextureManager = new WoWTextureManager(this);
4343
MeshManager = new WoWMeshManager(this);
4444
MdxManager = new MdxManager(this);
@@ -51,13 +51,17 @@ public void Initialize(Engine engine)
5151

5252
OnInitialized?.Invoke();
5353
IsInitialized = true;
54+
waitForInitialized.SetResult();
5455
}
5556

5657
public void StartCoroutine(IEnumerator coroutine)
5758
{
5859
coroutineManager.Start(coroutine);
5960
}
6061

62+
private TaskCompletionSource waitForInitialized = new();
63+
public Task WaitForInitialized => waitForInitialized.Task;
64+
6165
private Material? prevMaterial;
6266
public void Update(float delta)
6367
{
@@ -112,6 +116,7 @@ public void DisposeGame()
112116
{
113117
if (!IsInitialized)
114118
return;
119+
waitForInitialized = new();
115120
IsInitialized = false;
116121
ModuleManager.Dispose();
117122
LightingManager.Dispose();

WDE.MapRenderer/GameToolBar.axaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
<CheckBox Name="TimeFlow" IsChecked="{Binding DisableTimeFlow, Mode=TwoWay}">Disable time flow</CheckBox>
2222
<DockPanel LastChildFill="True" IsEnabled="{Binding #TimeFlow.IsChecked, Converter={x:Static InverseBoolConverter.Instance}}">
2323
<TextBlock VerticalAlignment="Center">Time speed: </TextBlock>
24-
<Slider Minimum="0" Maximum="6" SmallChange="1" LargeChange="1" Value="{Binding TimeSpeedMultiplier}" />
24+
<Slider Minimum="0" Maximum="6" IsSnapToTickEnabled="True" SmallChange="1" LargeChange="1" Value="{Binding TimeSpeedMultiplier}" />
2525
</DockPanel>
2626
<DockPanel LastChildFill="True">
2727
<TextBlock VerticalAlignment="Center">Time: </TextBlock>
2828
<Slider Minimum="0" Maximum="1439" Value="{Binding CurrentTime}" />
2929
</DockPanel>
3030
<CheckBox IsChecked="{Binding OverrideLighting, Mode=TwoWay}">Disable lightning</CheckBox>
31+
<DockPanel LastChildFill="True">
32+
<TextBlock VerticalAlignment="Center">View distance: </TextBlock>
33+
<Slider Minimum="1" Maximum="32" SmallChange="1" LargeChange="1" Value="{Binding ViewDistance}" />
34+
</DockPanel>
3135
</StackPanel>
3236
</DropDownButton>
3337
</ToolbarPanel>

WDE.MapRenderer/GameView.axaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</UserControl.Styles>
1313
<UserControl.KeyBindings>
1414
<KeyBinding Gesture="M" Command="{Binding ToggleMapVisibilityCommand}" />
15+
<KeyBinding Gesture="R" Command="{Binding ToggleStatsVisibilityCommand}" />
1516
</UserControl.KeyBindings>
1617
<DockPanel LastChildFill="True">
1718
<mapRenderer:GameToolBar DockPanel.Dock="Top" />
@@ -24,8 +25,8 @@
2425
<mapRenderer:MiniMapRenderer Context2="{Binding .}" PointerPressed="InputElement_OnPointerPressed"/>
2526
</worldMap:WoWMapViewer>
2627
</Border>
27-
<TextBlock Text="{Binding #TheEnginePanel.FrameRate, StringFormat={}{0:0.##}}" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="14" FontWeight="Bold" Background="Black" Foreground="White" FontFamily="Consolas,Menlo,Courier,Courier New" />
28-
<TextBlock Text="{Binding Stats}" Padding="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="13" FontWeight="Bold" Background="Black" Foreground="White" FontFamily="Consolas,Menlo,Courier,Courier New" />
28+
<TextBlock Text="{Binding #TheEnginePanel.FrameRate, StringFormat={}{0:0}}" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="14" FontWeight="Bold" Background="Black" Foreground="White" FontFamily="Consolas,Menlo,Courier,Courier New" />
29+
<TextBlock IsVisible="{Binding DisplayStats}" Text="{Binding Stats}" Padding="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="13" FontWeight="Bold" Background="Black" Foreground="White" FontFamily="Consolas,Menlo,Courier,Courier New" />
2930
</Panel>
3031
</DockPanel>
3132
</UserControl>

WDE.MapRenderer/GameViewModel.cs

+28-2
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ public GameViewModel(IMpqService mpqService,
104104
Game.TimeManager.SetTime(Time.FromMinutes(settings.CurrentTime));
105105
Game.TimeManager.TimeSpeedMultiplier = settings.TimeSpeedMultiplier;
106106
Game.ChunkManager.RenderGrid = settings.ShowGrid;
107+
Game.Engine.RenderManager.ViewDistanceModifier = settings.ViewDistanceModifier;
107108

108109
RaisePropertyChanged(nameof(OverrideLighting));
109110
RaisePropertyChanged(nameof(DisableTimeFlow));
110111
RaisePropertyChanged(nameof(TimeSpeedMultiplier));
111112
RaisePropertyChanged(nameof(ShowGrid));
112113
RaisePropertyChanged(nameof(CurrentTime));
114+
RaisePropertyChanged(nameof(ViewDistance));
113115
};
114116
AutoDispose(new ActionDisposable(() =>
115117
{
@@ -137,7 +139,8 @@ public GameViewModel(IMpqService mpqService,
137139
}));
138140

139141
ToggleMapVisibilityCommand = new DelegateCommand(() => IsMapVisible = !IsMapVisible);
140-
142+
ToggleStatsVisibilityCommand = new DelegateCommand(() => DisplayStats = !DisplayStats);
143+
141144
cameraViewModel = new GameCameraViewModel(this);
142145
Items.Add(cameraViewModel);
143146

@@ -149,6 +152,9 @@ public GameViewModel(IMpqService mpqService,
149152

150153
Game.UpdateLoop.Register(d =>
151154
{
155+
if (!DisplayStats)
156+
return;
157+
152158
ref var counters = ref Game.Engine.StatsManager.Counters;
153159
ref var stats = ref Game.Engine.StatsManager.RenderStats;
154160
float w = Game.Engine.StatsManager.PixelSize.X;
@@ -235,6 +241,16 @@ public bool ShowGrid
235241
}
236242
}
237243

244+
public float ViewDistance
245+
{
246+
get => Game.Engine.RenderManager.ViewDistanceModifier;
247+
set
248+
{
249+
Game.Engine.RenderManager.ViewDistanceModifier = value;
250+
RaisePropertyChanged(nameof(ViewDistance));
251+
}
252+
}
253+
238254
public int CurrentTime
239255
{
240256
get => Game.TimeManager?.Time.TotalMinutes ?? 0;
@@ -245,13 +261,22 @@ public int CurrentTime
245261
RaisePropertyChanged(nameof(CurrentTime));
246262
}
247263
}
248-
264+
265+
public bool DisplayStats
266+
{
267+
get => displayStats;
268+
set => SetProperty(ref displayStats, value);
269+
}
270+
249271
public bool IsMapVisible
250272
{
251273
get => isMapVisible;
252274
set => SetProperty(ref isMapVisible, value);
253275
}
276+
254277
public ICommand ToggleMapVisibilityCommand { get; }
278+
public ICommand ToggleStatsVisibilityCommand { get; }
279+
255280

256281
public string UniqueId => "game_view";
257282

@@ -282,6 +307,7 @@ public void Initialized()
282307

283308
private GameCameraViewModel cameraViewModel;
284309
private bool visibility;
310+
private bool displayStats;
285311
public ObservableCollection<GameCameraViewModel> Items { get; } = new();
286312
public IEnumerable<GameCameraViewModel> VisibleItems => Items;
287313
public GameCameraViewModel? SelectedItem { get; set; }

WDE.MapRenderer/GameViewSettings.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public GameViewSettings(IUserSettings settings)
1919
DisableTimeFlow = false,
2020
TimeSpeedMultiplier = 3,
2121
ShowGrid = true,
22-
CurrentTime = 360
22+
CurrentTime = 360,
23+
ViewDistanceModifier = 6
2324
});
2425
}
2526

@@ -73,13 +74,24 @@ public bool ShowGrid
7374
}
7475
}
7576

77+
public float ViewDistanceModifier
78+
{
79+
get => current.ViewDistanceModifier;
80+
set
81+
{
82+
current.ViewDistanceModifier = value;
83+
settings.Update(current);
84+
}
85+
}
86+
7687
public struct Data : ISettings
7788
{
7889
public bool OverrideLighting;
7990
public bool DisableTimeFlow;
8091
public int TimeSpeedMultiplier;
8192
public bool ShowGrid;
8293
public int CurrentTime;
94+
public float ViewDistanceModifier;
8395
}
8496
}
8597
}

WDE.MapRenderer/Managers/IGameContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ public interface IGameContext
2828
Map CurrentMap { get; }
2929
void SetMap(int id);
3030
void StartCoroutine(IEnumerator coroutine);
31+
Task WaitForInitialized { get; }
3132
}
3233
}

WoWDatabaseEditorCore.Avalonia/Docking/PersistentDockDataTemplate.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Reactive.Linq;
34
using Avalonia.Collections;
45
using Avalonia.Controls;
@@ -57,16 +58,6 @@ public IControl Build(object data, IControl? existing)
5758
return view;
5859
}
5960

60-
System.IDisposable? disposable = null;
61-
disposable = toolDockWrapper.ViewModel.ToObservable(i => i.Visibility)
62-
.SubscribeAction(toolVisibility =>
63-
{
64-
if (!toolVisibility)
65-
tools.Remove(toolDockWrapper.ViewModel);
66-
disposable?.Dispose();
67-
disposable = null;
68-
});
69-
7061
if (ViewBind.TryResolve(toolDockWrapper.ViewModel, out var documentView) && documentView is IControl control)
7162
{
7263
tools[toolDockWrapper.ViewModel] = control;
@@ -94,6 +85,15 @@ private void Bind()
9485
{
9586
documents.Remove(item.Item);
9687
});
88+
foreach (var tool in DocumentManager.AllTools)
89+
{
90+
tool.ToObservable(i => i.Visibility)
91+
.SubscribeAction(toolVisibility =>
92+
{
93+
if (!toolVisibility)
94+
tools.Remove(tool);
95+
});
96+
}
9797
}
9898
}
9999
}

0 commit comments

Comments
 (0)