Skip to content

Commit

Permalink
[3D] 3D rendering works again
Browse files Browse the repository at this point in the history
  • Loading branch information
BAndysc committed Sep 12, 2023
1 parent 074ff6b commit 442973c
Show file tree
Hide file tree
Showing 151 changed files with 5,928 additions and 946 deletions.
4 changes: 4 additions & 0 deletions LoaderAvalonia/LoaderAvalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<Copy SourceFiles="$(OutputPath)\runtimes\osx-universal\native\libcimgui.dylib" DestinationFolder="$(OutputPath)\runtimes\osx\native\" ContinueOnError="false" />
</Target>

<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AvaloniaStyles\AvaloniaStyles.csproj" />
<ProjectReference Include="..\Modules\WDE.DatabaseDefinitionEditor\WDE.DatabaseDefinitionEditor.csproj" />
Expand Down
28 changes: 28 additions & 0 deletions LoaderAvalonia/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="ControlCatalog.app"/>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->

<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

</application>
</compatibility>
</assembly>
154 changes: 110 additions & 44 deletions Modules/WDE.MapSpawnsEditor/Models/GamePhaseService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Prism.Events;
using WDE.Common.CoreVersion;
using WDE.Common.Database;
using WDE.Common.DBC;
using WDE.Common.Parameters;
using WDE.Common.Utils;
using WDE.MapSpawnsEditor.ViewModels;
using WDE.Module.Attributes;
using WDE.MVVM;
Expand All @@ -15,90 +18,153 @@ namespace WDE.MapSpawnsEditor.Models;
public interface IGamePhaseService
{
ObservableCollection<GamePhaseViewModel> Phases { get; }
ObservableCollection<GamePhaseViewModel> ActivePhases { get; }
IObservable<IReadOnlyList<GamePhaseViewModel>> ActivePhasesObservable { get; }
bool IsPhaseActive(int? phaseId, int? phaseGroup);
bool PhaseMaskOverlaps(uint phaseMask);
System.IObservable<Unit> ActivePhasesObservable { get; }
bool ShowAllPhases { get; set; }
bool IsVisible(uint? phaseMask, SmallReadOnlyList<int>? phaseId, int? phaseGroup);
}

[AutoRegister]
[SingleInstance]
public class GamePhaseService : IGamePhaseService
{
private readonly IParameterFactory parameterFactory;
private Subject<Unit> activePhasesObservable = new();
private HashSet<int> activePhases { get; } = new();
private uint activePhaseMask;
private bool showAllPhases;
public ObservableCollection<GamePhaseViewModel> Phases { get; } = new();
public ObservableCollection<GamePhaseViewModel> ActivePhases { get; } = new();
public IObservable<IReadOnlyList<GamePhaseViewModel>> ActivePhasesObservable { get; }
public System.IObservable<Unit> ActivePhasesObservable => activePhasesObservable;
public PhasingType PhasingType { get; }

public bool IsPhaseActive(int? phaseId, int? phaseGroup)
public bool ShowAllPhases
{
if (!phaseId.HasValue && !phaseGroup.HasValue)
return true;

if (phaseId.HasValue)
return ActivePhases.Any(x => x.Entry == phaseId.Value);

throw new Exception("Phase group not yet implemented (implement dbc loading first)");
}

public bool PhaseMaskOverlaps(uint phaseMask)
{
return (phaseMask & activePhaseMask) != 0;
get => showAllPhases;
set
{
showAllPhases = value;
activePhasesObservable.OnNext(default);
}
}

public GamePhaseService(IDbcStore dbcStore,
public GamePhaseService(IParameterFactory parameterFactory,
IEventAggregator eventAggregator,
ICurrentCoreVersion currentCoreVersion)
{
ActivePhasesObservable = FunctionalExtensions.Select(ActivePhases.ToCountChangedObservable(), _ => ActivePhases);
this.parameterFactory = parameterFactory;
PhasingType = currentCoreVersion.Current.PhasingType;

if (currentCoreVersion.Current.PhasingType == PhasingType.PhaseIds)
if (PhasingType is PhasingType.PhaseIds or PhasingType.Both)
{
DbcLoaded(dbcStore);
eventAggregator.GetEvent<DbcLoadedEvent>().Subscribe(DbcLoaded);
BindPhases();
this.parameterFactory.OnRegister("PhaseParameter").SubscribeAction(phases =>
{
if (phases is IDynamicParameter<long> dynP)
{
dynP.ItemsChanged += OnPhasesChanged;
OnPhasesChanged(dynP);
}
});
}
else

if (PhasingType is PhasingType.PhaseMasks or PhasingType.Both)
{
foreach (var phaseMask in Enum.GetValues<InGamePhase>())
Phases.Add(new GamePhaseViewModel((uint)phaseMask, ""));
BindPhases();
Phases[0].Active = true;
{
var vm = AddViewModel(GamePhaseViewModel.FromPhaseMask((uint)phaseMask));
if (phaseMask == InGamePhase.Phase1)
vm.Active = true;
}
}
}
private void DbcLoaded(IDbcStore dbcStore)

public bool IsVisible(uint? phaseMask, SmallReadOnlyList<int>? phaseIds, int? phaseGroup)
{
foreach (var phase in dbcStore.PhaseStore)
if (showAllPhases)
return true;

if (PhasingType is PhasingType.PhaseIds)
{
if (phaseIds == null || phaseIds.Value.Count == 0)
return true;

foreach (var phaseId in phaseIds)
if (!activePhases.Contains(phaseId))
return false;
return true;
}
else if (PhasingType is PhasingType.PhaseMasks)
{
Phases.Add(new GamePhaseViewModel((uint)phase.Key, phase.Value));
return (phaseMask & activePhaseMask) != 0;
}
else if (PhasingType is PhasingType.Both)
{
if (phaseIds != null && phaseIds.Value.Count > 0)
{
foreach (var phaseId in phaseIds)
if (!activePhases.Contains(phaseId))
return false;
return true;
}

return (phaseMask & activePhaseMask) != 0;
}
else if (PhasingType is PhasingType.NoPhasing)
return true;
else
throw new ArgumentOutOfRangeException(nameof(PhasingType), PhasingType, "Phasing type not implemented");
}

BindPhases();
var normalPhase = Phases.FirstOrDefault(x => x.Entry == 169);
if (normalPhase != null)
normalPhase.Active = true;
private void OnPhasesChanged(IParameter<long> phases)
{
if (phases.Items != null)
{
foreach (var phase in phases.Items)
{
if (Phases.FirstOrDefault(x => x.Entry == (uint)phase.Key && x.IsPhaseId) is { } existing)
existing.Name = phase.Value.Name;
else
AddViewModel(GamePhaseViewModel.FromPhaseId((uint)phase.Key, phase.Value.Name));
}
}
}

private void BindPhases()
private GamePhaseViewModel AddViewModel(GamePhaseViewModel vm)
{
foreach (var e in Phases)
if (vm.IsPhaseMask)
{
e.ToObservable(x => x.Active)
vm.ToObservable(x => x.Active)
.Skip(1)
.SubscribeAction(@is =>
{
if (@is)
{
activePhaseMask |= e.Entry;
ActivePhases.Add(e);
activePhaseMask |= vm.Entry;
}
else
{
activePhaseMask &= ~e.Entry;
ActivePhases.Remove(e);
activePhaseMask &= ~vm.Entry;
}
activePhasesObservable.OnNext(default);
});
}
else
{
vm.ToObservable(x => x.Active)
.Skip(1)
.SubscribeAction(@is =>
{
if (@is)
{
activePhases.Add((int)vm.Entry);
}
else
{
activePhases.Remove((int)vm.Entry);
}
activePhasesObservable.OnNext(default);
});
}

Phases.Add(vm);
return vm;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ModelPreviewRenderer(IRenderManager renderManager,
AmbientColor = Vector4.Zero
};

sceneData = new SceneData(previewCamera, mainLight, secondaryLight);
sceneData = new SceneData(previewCamera, new FogSettings(){Enabled = false}, mainLight, secondaryLight);
bonesMatrix = gameContext.Engine.CreateBuffer<Matrix>(BufferTypeEnum.StructuredBufferVertexOnly, 1, BufferInternalFormat.Float4);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private IEnumerator SpawnAndDragCoroutine(bool creature, uint entry)
Map = gameContext.CurrentMap.Id,
SpawnMask = 1,
PhaseMask = 1,
PhaseId = gamePhaseService.ActivePhases.FirstOrDefault(p => p.Active)?.Entry ?? 169,
PhaseId = new SmallReadOnlyList<uint>(gamePhaseService.Phases.Where(p => p.Active && p.IsPhaseId).Select(x => x.Entry)),
X = worldObjectInstance.Position.X,
Y = worldObjectInstance.Position.Y,
Z = worldObjectInstance.Position.Z,
Expand All @@ -225,7 +225,7 @@ private IEnumerator SpawnAndDragCoroutine(bool creature, uint entry)
Map = gameContext.CurrentMap.Id,
SpawnMask = 1,
PhaseMask = 1,
PhaseId = gamePhaseService.ActivePhases.FirstOrDefault(p => p.Active)?.Entry ?? 169,
PhaseId = new SmallReadOnlyList<uint>(gamePhaseService.Phases.Where(p => p.Active && p.IsPhaseId).Select(x => x.Entry)),
X = worldObjectInstance.Position.X,
Y = worldObjectInstance.Position.Y,
Z = worldObjectInstance.Position.Z,
Expand Down
4 changes: 2 additions & 2 deletions Modules/WDE.MapSpawnsEditor/Rendering/SpawnViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public class DummyCreature : ICreature
public uint Entry { get; set; }
public uint Map { get; set; }
public uint? PhaseMask { get; set; }
public int? PhaseId { get; set; }
public SmallReadOnlyList<int>? PhaseId { get; set; }
public int? PhaseGroup { get; set; }
public int EquipmentId { get; set; }
public uint Model { get; set; }
Expand All @@ -478,7 +478,7 @@ public class DummyGameObject : IGameObject
public uint Entry { get; set; }
public uint Map { get; set; }
public uint? PhaseMask { get; set; }
public int? PhaseId { get; set; }
public SmallReadOnlyList<int>? PhaseId { get; set; }
public int? PhaseGroup { get; set; }
public float X { get; set; }
public float Y { get; set; }
Expand Down
12 changes: 4 additions & 8 deletions Modules/WDE.MapSpawnsEditor/ViewModels/CreatureSpawnInstance.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using WDE.Common.Database;
using WDE.Common.Utils;
using WDE.MapRenderer.Managers.Entities;
using WDE.MapRenderer.StaticData;
using WDE.MapSpawnsEditor.Models;
Expand All @@ -12,6 +13,8 @@ public class CreatureSpawnInstance : SpawnInstance
public override uint Guid => data.Guid;
public override uint Entry => data.Entry;
public override Vector3 Position => new Vector3(data.X, data.Y, data.Z);
public override uint PhaseMask => data.PhaseMask ?? 0;
public override SmallReadOnlyList<int>? Phases => data.PhaseId;
public override uint Map => data.Map;
public MovementType MovementType => data.MovementType;
public float WanderDistance => data.WanderDistance;
Expand Down Expand Up @@ -44,14 +47,7 @@ public void UpdateData(ICreature creatureData, ISpawnGroupTemplate? spawnGroup)

public override bool IsVisibleInPhase(IGamePhaseService gamePhaseService)
{
if (data.PhaseMask.HasValue)
{
return gamePhaseService.PhaseMaskOverlaps(data.PhaseMask.Value);
}
else
{
return gamePhaseService.IsPhaseActive(data.PhaseId, data.PhaseGroup);
}
return gamePhaseService.IsVisible(data.PhaseMask, data.PhaseId, data.PhaseGroup);
}

public override void Dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using WDE.Common.Database;
using WDE.Common.Utils;
using WDE.MapRenderer.Managers.Entities;
using WDE.MapRenderer.StaticData;
using WDE.MapSpawnsEditor.Models;
Expand All @@ -13,6 +14,8 @@ public class GameObjectSpawnInstance : SpawnInstance
public override uint Entry => data.Entry;
public override Vector3 Position => new Vector3(data.X, data.Y, data.Z);
public override uint Map => data.Map;
public override uint PhaseMask => data.PhaseMask ?? 0;
public override SmallReadOnlyList<int>? Phases => data.PhaseId;
public Quaternion Rotation => new Quaternion(data.Rotation0, data.Rotation1, data.Rotation2, data.Rotation3);
public override (int, int) Chunk => new Vector3(data.X, data.Y, data.Z).WoWPositionToChunk();
public sealed override string Header { get; protected set; } = "";
Expand All @@ -39,14 +42,7 @@ public void UpdateData(IGameObject gameobjectData, ISpawnGroupTemplate? spawnGro

public override bool IsVisibleInPhase(IGamePhaseService gamePhaseService)
{
if (data.PhaseMask.HasValue)
{
return gamePhaseService.PhaseMaskOverlaps(data.PhaseMask.Value);
}
else
{
return gamePhaseService.IsPhaseActive(data.PhaseId, data.PhaseGroup);
}
return gamePhaseService.IsVisible(data.PhaseMask, data.PhaseId, data.PhaseGroup);
}

public override bool IsVisibleInEvents(IGameEventService eventService)
Expand Down
22 changes: 18 additions & 4 deletions Modules/WDE.MapSpawnsEditor/ViewModels/GamePhaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,32 @@ namespace WDE.MapSpawnsEditor.ViewModels;
public partial class GamePhaseViewModel : ObservableBase
{
[Notify] private bool active;
[Notify] private string name = "";
private bool isPhaseMask;

public GamePhaseViewModel(uint entry, string name)
private GamePhaseViewModel(uint entry, string name, bool isPhaseMask)
{
Entry = entry;
Name = name;
this.name = name;
this.isPhaseMask = isPhaseMask;
}

public static GamePhaseViewModel FromPhaseId(uint entry, string name)
{
return new GamePhaseViewModel(entry, name, false);
}

public static GamePhaseViewModel FromPhaseMask(uint mask)
{
return new GamePhaseViewModel(mask, "", true);
}

public uint Entry { get; }
public string Name { get; }
public bool IsPhaseMask => isPhaseMask;
public bool IsPhaseId => !isPhaseMask;

public override string ToString()
{
return Name;
return name;
}
}
Loading

0 comments on commit 442973c

Please sign in to comment.