Skip to content

Commit

Permalink
Changes for test 2
Browse files Browse the repository at this point in the history
- Adjusted the line of sight check
- Added an error fallback sprite for missing sprites from an IWAD
  • Loading branch information
adamd3v committed Oct 2, 2023
1 parent f8997a6 commit f809755
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 26 deletions.
Binary file modified Resources/doomlab_pcvr.pack
Binary file not shown.
Binary file modified Resources/doomlab_quest.pack
Binary file not shown.
4 changes: 2 additions & 2 deletions src/BuildInfo.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace NEP.DOOMLAB
{
static partial class BuildInfo
{
public const int Epoch = 1696211914;
public const string GitCommit = "227216e22af1157829a6af1c619a49298c935660";
public const int Epoch = 1696279013;
public const string GitCommit = "f8997a61d9a38dcf302ece79289f913ef5d65e30";
}
}
8 changes: 7 additions & 1 deletion src/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using BoneLib.BoneMenu.Elements;
using BoneLib.BoneMenu;
using SLZ.Marrow.Warehouse;
using UnityEngine.SearchService;

namespace NEP.DOOMLAB
{
Expand All @@ -39,14 +41,16 @@ public class Main : MelonMod
public static readonly string ModDirectory = Path.Combine(TeamDirectory, "DOOMLAB");
public static readonly string IWADDirectory = Path.Combine(ModDirectory, "IWADS");
public static readonly string PWADDirectory = Path.Combine(ModDirectory, "PWADS");

public static Texture2D MissingSprite;

private static AssetBundle GetEmbeddedBundle()
{
Assembly assembly = Assembly.GetExecutingAssembly();

string fileName = HelperMethods.IsAndroid() ? "doomlab_quest.pack" : "doomlab_pcvr.pack";

using (Stream resourceStream = assembly.GetManifestResourceStream("NEP.DOOMLAB." + fileName))
using (Stream resourceStream = assembly.GetManifestResourceStream("NEP.DOOMLAB.Resources." + fileName))
{
using (MemoryStream memoryStream = new MemoryStream())
{
Expand All @@ -65,6 +69,8 @@ public override void OnInitializeMelon()
bundle = GetEmbeddedBundle();
mobjTemplate = bundle.LoadAsset("[MOBJ] - Null").Cast<GameObject>();
mobjTemplate.hideFlags = HideFlags.DontUnloadUnusedAsset;
MissingSprite = bundle.LoadAsset("faila0").Cast<Texture2D>();
MissingSprite.hideFlags = HideFlags.DontUnloadUnusedAsset;

new WADManager();
WADManager.Instance.LoadWAD(WADManager.Instance.GetIWAD());
Expand Down
15 changes: 11 additions & 4 deletions src/Mobj/MobjBrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,23 @@ public bool CheckSight(Mobj other)
return false;
}

Vector3 direction = other.transform.position - mobj.transform.position;
// MobjInteraction.LineAttack(mobj, mobj.transform.position + Vector3.up, mobj.target.transform.position, damage / 10, 128);

if (Physics.Raycast(mobj.transform.position + Vector3.up, direction, out RaycastHit hit, float.PositiveInfinity, 0, QueryTriggerInteraction.Ignore))
Vector3 origin = mobj.transform.position + Vector3.up;
Vector3 direction = other.transform.position;
Ray ray = new Ray(origin, direction - origin);

if (Physics.Raycast(ray, out RaycastHit hit, 20))
{
if (hit.collider)
Mobj hitMobj = hit.collider.GetComponent<Mobj>();

if(hitMobj != null && hitMobj == other)
{
return false;
return true;
}
}

MelonLogger.Msg("Can see target");
return true;
}

Expand Down
36 changes: 34 additions & 2 deletions src/Rendering/MobjRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,38 @@ public MobjRenderer(System.IntPtr ptr) : base(ptr) { }

private Camera camera;

private static WAD.DataTypes.Patch missingPatch;
private static SpriteFrame missingFrame;

private void Awake()
{
meshRenderer = GetComponentInChildren<MeshRenderer>();
mobj = GetComponentInParent<Mobj>();
game = DoomGame.Instance;
camera = Camera.main;
drawQuad = transform.GetChild(0);

missingPatch = new WAD.DataTypes.Patch("FAILA0", 32, 32, 16, 38);
missingPatch.output = Main.MissingSprite;

missingFrame = new SpriteFrame()
{
canRotate = false,
flipBits = new bool[8],
mirrorSprite = new bool[8],
numRotations = 0,
patches = new WAD.DataTypes.Patch[8]
{
missingPatch,
missingPatch,
missingPatch,
missingPatch,
missingPatch,
missingPatch,
missingPatch,
missingPatch
}
};
}

private void Start()
Expand Down Expand Up @@ -74,7 +99,14 @@ public void UpdateSprite()
}

SpriteDef spriteDef = spriteDefs[(int)mobj.sprite];
SpriteFrame spriteFrame = spriteDef.GetFrame(stateFrame);

if(spriteDef.spriteFrames == null || stateFrame > spriteDef.spriteFrames.Length)
{
SetSprite(missingFrame, 0);
return;
}

SpriteFrame spriteFrame = spriteDef.spriteFrames[stateFrame];

// absolutely do NOT render anything if
// the patch array is null/empty
Expand Down Expand Up @@ -102,7 +134,7 @@ private void SetSprite(SpriteFrame spriteFrame, int rotation)

float leftOffset = patch.leftOffset / 32f;
float topOffset = patch.topOffset / 32f;

meshRenderer.material.mainTexture = patch.output;
transform.localScale = new Vector3(width * xScale, height, 1f);
drawQuad.localPosition = new Vector3(leftOffset / 100f, (topOffset / 100f) + 0.5f);
Expand Down
18 changes: 1 addition & 17 deletions src/Rendering/SpriteDef.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace NEP.DOOMLAB.Rendering
{
public struct SpriteDef
public class SpriteDef
{
public int numFrames;
public SpriteFrame[] spriteFrames;
Expand All @@ -9,21 +9,5 @@ public void ResetFrames()
{
numFrames = 0;
}

public SpriteFrame GetFrame(int frame)
{
if(spriteFrames == null)
{
// return an empty sprite frame
return new SpriteFrame();
}

if (frame > spriteFrames.Length - 1)
{
return spriteFrames[spriteFrames.Length - 1];
}

return spriteFrames[frame];
}
}
}

0 comments on commit f809755

Please sign in to comment.