Skip to content

Commit

Permalink
Merge pull request OpenSAGE#843 from charliefoxtwo/bugfix/bfme-npe-fixes
Browse files Browse the repository at this point in the history
Fix various BFME2 NPEs
  • Loading branch information
Tarcontar authored Feb 5, 2024
2 parents e41eb12 + 75f8b5b commit 0d374d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/OpenSage.Game/Logic/Object/Update/SlavedUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ internal override void Update(BehaviorUpdateContext context)
maxRange = _moduleData.AttackRange;
}

if (_gameObject.AIUpdate.TargetPoints.Count == 0 && distanceToMaster > maxRange)
if (_gameObject.AIUpdate?.TargetPoints.Count == 0 && distanceToMaster > maxRange)
{
_gameObject.AIUpdate.SetTargetPoint(Master.Translation);
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSage.Mods.Bfme/Gui/AptControlBarSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void ClearCommandbuttons()
for (var i = 1; i <= 6; i++)
{
// we do not know how bfme handles this yet
if (_game.SageGame == SageGame.Bfme) continue;
if (_game.SageGame is SageGame.Bfme or SageGame.Bfme2 or SageGame.Bfme2Rotwk) continue;

var commandButton = aptCommandButtons.GetMember((i - 1).ToString()).ToObject();
var placeHolder = commandButton.GetMember("placeholder").ToObject();
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSage.Rendering/MaterialPass.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace OpenSage.Rendering;

public sealed record MaterialPass(Material ForwardPass, Material ShadowPass);
public sealed record MaterialPass(Material? ForwardPass, Material? ShadowPass);
32 changes: 23 additions & 9 deletions src/OpenSage.Rendering/RenderScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ public void AddObject(RenderObject renderObject)
{
_renderObjects.Add(renderObject);

_forwardPassList.AddObject(renderObject, renderObject.MaterialPass.ForwardPass);

if (renderObject.MaterialPass?.ShadowPass != null)
if (renderObject.MaterialPass != null)
{
_shadowPassList.AddObject(renderObject, renderObject.MaterialPass.ShadowPass);
var (forwardPass, shadowPass) = renderObject.MaterialPass;
if (forwardPass != null)
{
_forwardPassList.AddObject(renderObject, forwardPass);
}

if (shadowPass != null)
{
_shadowPassList.AddObject(renderObject, shadowPass);
}
}

// TODO: Extract child objects and store in appropriate render buckets (opaque / transparent / etc.)
Expand All @@ -40,11 +47,18 @@ public void RemoveObject(RenderObject renderObject)
{
_renderObjects.Remove(renderObject);

_forwardPassList.RemoveObject(renderObject, renderObject.MaterialPass.ForwardPass);

if (renderObject.MaterialPass.ShadowPass != null)
if (renderObject.MaterialPass != null)
{
_shadowPassList.RemoveObject(renderObject, renderObject.MaterialPass.ShadowPass);
var (forwardPass, shadowPass) = renderObject.MaterialPass;
if (forwardPass != null)
{
_forwardPassList.RemoveObject(renderObject, forwardPass);
}

if (shadowPass != null)
{
_shadowPassList.RemoveObject(renderObject, shadowPass);
}
}
}

Expand Down Expand Up @@ -174,7 +188,7 @@ public abstract class RenderObject : DisposableBase
{
public abstract string DebugName { get; }

public abstract MaterialPass MaterialPass { get; }
public abstract MaterialPass? MaterialPass { get; }

//public readonly List<RenderableObject> ChildObjects = new();

Expand Down

0 comments on commit 0d374d6

Please sign in to comment.