Skip to content

Commit

Permalink
Major changes for debugging and more
Browse files Browse the repository at this point in the history
- Added visual debugging! (Mobj colliders, states, sight view and more)
- Made both the sound manager and the MOBJ manager not a MonoBehaviour
- Moved the CheckSight method into the MobjInteractions class
- Tried to do some optimizations with the state switching
- Added an unlit material when the sprites need to be rendered in fullbright
  • Loading branch information
adamd3v committed Oct 7, 2023
1 parent 09403db commit 6ff97f1
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 117 deletions.
7 changes: 7 additions & 0 deletions DOOMLAB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="src\Info\State.cs" />
<Compile Include="src\Info\StateNum.cs" />
<Compile Include="src\Main.cs" />
<Compile Include="src\Debug\DebugMobjStats.cs" />
<Compile Include="src\Entities\Mobj.cs" />
<Compile Include="src\Entities\MobjBrain.cs" />
<Compile Include="src\Entities\MobjCollisionEvents.cs" />
Expand Down Expand Up @@ -146,6 +147,12 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\BONELAB\MelonLoader\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Users\adamdev.NOTENOUGHPHOTON\Documents\DOOMLAB\bin\Release\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="System.Runtime" />
<Reference Include="System" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
3 changes: 1 addition & 2 deletions ISSUES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DOOMLAB ISSUE LIST
----------------------------
> Player isn't affected by projectile damage (sometimes)
> Mancubus attacks don't spawn two fireballs at the right locations
> Player isn't affected by projectile damage (sometimes)
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 = 1696594765;
public const string GitCommit = "482f4ae47d30bbedcd322a4200a3becff752b007";
public const int Epoch = 1696713866;
public const string GitCommit = "09403dbeaee688ca3a8dd907205ce16978c64a56";
}
}
34 changes: 21 additions & 13 deletions src/Entities/Mobj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using SLZ.Marrow.Warehouse;

using System;

using System.Diagnostics;
using UnityEngine;

namespace NEP.DOOMLAB.Entities
Expand Down Expand Up @@ -76,6 +76,9 @@ public enum MoveDirection

public AudioSource audioSource;

public Action<Mobj> CurrentAction { get; private set; }
public Stopwatch ActionStopwatch { get; private set; } = new Stopwatch();

private void Awake()
{
info = Info.MobjInfos[(int)type];
Expand All @@ -84,6 +87,7 @@ private void Awake()

private void Start()
{
player.health = player.playerHealth.curr_Health;
DoomGame.Instance.OnTick += WorldTick;
}

Expand All @@ -95,7 +99,6 @@ private void OnDestroy()
private void WorldTick()
{
position = transform.position;
Mobj.player.health = Mobj.player.playerHealth.curr_Health;
UpdateThinker();
}

Expand All @@ -111,10 +114,13 @@ public void UpdateThinker()
target = null;
}

// Too far away, stop updating
if(Vector3.Distance(transform.position, BoneLib.Player.playerHead.position) > 2048)
if(Vector3.Distance(transform.position, player.transform.position) > Settings.ProjectilePruneDistance)
{
return;
if(flags.HasFlag(MobjFlags.MF_MISSILE))
{
MobjManager.Instance.RemoveMobj(this);
return;
}
}

if (tics != -1)
Expand Down Expand Up @@ -159,26 +165,28 @@ public void UpdateThinker()

public bool SetState(StateNum state)
{
State st;

currentState = state;

State st;

if (state == StateNum.S_NULL)
{
this.state = Info.GetState(StateNum.S_NULL);
this.state = Info.states[(int)StateNum.S_NULL];
MobjManager.Instance.RemoveMobj(this);
return false;
}

st = Info.GetState(state);
st = Info.states[(int)state];
this.state = st;
this.tics = st.tics;
this.sprite = st.sprite;
this.frame = st.frame;

System.Action<Mobj> action = st.action;

BoneLib.SafeActions.InvokeActionSafe(action, this);
ActionStopwatch = new Stopwatch();
ActionStopwatch.Start();
st.action?.Invoke(this);
CurrentAction = st.action;
ActionStopwatch.Stop();

return true;
}
Expand All @@ -194,7 +202,7 @@ public void OnSpawn(Vector3 position, MobjType type)
this.health = info.spawnHealth;
this.reactionTime = info.reactionTime;

State st = Info.GetState(info.spawnState);
State st = Info.states[(int)info.spawnState];

this.state = st;
this.tics = st.tics;
Expand Down
91 changes: 33 additions & 58 deletions src/Entities/MobjBrain.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using Il2CppSystem.Numerics;
using MelonLoader;
using NEP.DOOMLAB.Data;
using NEP.DOOMLAB.Game;
using NEP.DOOMLAB.Sound;
using SLZ.Marrow.Forklift;
using SLZ.Props;
using UnhollowerBaseLib;
using UnityEngine;

namespace NEP.DOOMLAB.Entities
Expand All @@ -17,6 +13,8 @@ public class MobjBrain : MonoBehaviour
{
public MobjBrain(System.IntPtr ptr) : base(ptr) { }

public bool SeesTarget;

public Mobj mobj;

private List<Mobj> listBrainTargets;
Expand Down Expand Up @@ -366,7 +364,7 @@ public bool CheckMeleeRange()
return false;
}

if(!CheckSight(mobj.target))
if(!MobjInteraction.CheckSight(mobj, mobj.target))
{
return false;
}
Expand All @@ -376,7 +374,7 @@ public bool CheckMeleeRange()

public bool CheckMissileRange()
{
if (!CheckSight(mobj.target))
if (!MobjInteraction.CheckSight(mobj, mobj.target))
{
return false;
}
Expand Down Expand Up @@ -444,42 +442,12 @@ public bool CheckMissileRange()
return true;
}

// Checks if a raycast line is unobstructed.
public bool CheckSight(Mobj other)
{
if (other == null)
{
return false;
}

Vector3 origin = mobj.transform.position + Vector3.up;
Vector3 direction = other.transform.position + Vector3.up;
Ray ray = new Ray(origin, direction - origin);

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

if(hitMobj == other)
{
return true;
}

if(hit.collider)
{
return false;
}
}

return true;
}

public bool FindPlayer()
{
Vector3 direction = Mobj.player.transform.position - mobj.transform.position;
float angle = Vector3.Angle(direction, mobj.transform.forward);

if (!CheckSight(Mobj.player))
if (!MobjInteraction.CheckSight(mobj, Mobj.player))
{
// Out of sight
return false;
Expand Down Expand Up @@ -548,6 +516,7 @@ public void A_SeeYou()
mobj.SetState(mobj.info.seeState);
}


public void A_Chase()
{
if (mobj.reactionTime != 0)
Expand Down Expand Up @@ -592,7 +561,6 @@ public void A_Chase()

if (mobj.info.meleeState != StateNum.S_NULL && CheckMeleeRange() || CheckObstructedByBreakable())
{
MelonLogger.Msg("Melee state");
if (mobj.info.attackSound != SoundType.sfx_None)
{
SoundManager.Instance.PlaySound(mobj.info.attackSound, mobj.transform.position, false);
Expand Down Expand Up @@ -626,7 +594,7 @@ public void A_Chase()

public void A_NoMissile()
{
if (mobj.threshold == 0 && !CheckSight(mobj.target))
if (mobj.threshold == 0 && !MobjInteraction.CheckSight(mobj, mobj.target))
{
if (FindPlayer())
{
Expand Down Expand Up @@ -678,16 +646,20 @@ public void A_TroopAttack()
MobjInteraction.DamageMobj(mobj.target, mobj, mobj, damage);
return;
}
else if(CheckObstructedByBreakable(out Prop_Health destructibleProp))
{
destructibleProp?.TAKEDAMAGE(damage, false, SLZ.Marrow.Data.AttackType.Stabbing);
return;
}
else if(CheckObstructedByBreakable(out ObjectDestructable objectDestructable))
if(CheckObstructedByBreakable())
{
objectDestructable?.TakeDamage(mobj.transform.forward, damage, false, SLZ.Marrow.Data.AttackType.Stabbing);
return;
}
if (CheckObstructedByBreakable(out Prop_Health destructibleProp))
{
destructibleProp?.TAKEDAMAGE(damage, false, SLZ.Marrow.Data.AttackType.Stabbing);
return;
}

if (CheckObstructedByBreakable(out ObjectDestructable objectDestructable))
{
objectDestructable?.TakeDamage(mobj.transform.forward, damage, false, SLZ.Marrow.Data.AttackType.Stabbing);
return;
}
}

MobjManager.Instance.SpawnMissile(mobj, mobj.target, Data.MobjType.MT_TROOPSHOT);
}
Expand Down Expand Up @@ -756,7 +728,7 @@ public void A_CPosRefire()
return;
}

if (mobj.target == null || mobj.target.health <= 0 || !CheckSight(mobj.target))
if (mobj.target == null || mobj.target.health <= 0 || !MobjInteraction.CheckSight(mobj, mobj.target))
{
mobj.SetState(mobj.info.seeState);
}
Expand All @@ -771,7 +743,7 @@ public void A_SpidRefire()
return;
}

if (mobj.target == null || mobj.target.health == 0 || !CheckSight(mobj.target))
if (mobj.target == null || mobj.target.health == 0 || !MobjInteraction.CheckSight(mobj, mobj.target))
{
mobj.SetState(mobj.info.seeState);
}
Expand Down Expand Up @@ -1011,38 +983,41 @@ public void A_FatRaise()

public void A_FatAttack1()
{
float fatSpread = (90 / 8);
float fatSpread = (90 / 8) / 32f;
A_FaceTarget();
mobj.transform.rotation *= Quaternion.AngleAxis(fatSpread, Vector3.up);
var firstBall = MobjManager.Instance.SpawnMissile(mobj, mobj.target, MobjType.MT_FATSHOT);

var secondBall = MobjManager.Instance.SpawnMissile(mobj, mobj.target, MobjType.MT_FATSHOT);
Physics.IgnoreCollision(firstBall.collider, secondBall.collider);
secondBall.transform.rotation *= Quaternion.AngleAxis(fatSpread, Vector3.up);
secondBall.transform.rotation = mobj.transform.rotation;
secondBall.rigidbody.velocity = secondBall.transform.forward * secondBall.info.speed;
}

public void A_FatAttack2()
{
float fatSpread = (90 / 8);
float fatSpread = (90 / 8) / 32f;
A_FaceTarget();
mobj.transform.rotation *= Quaternion.AngleAxis(-fatSpread, Vector3.up);
var firstBall = MobjManager.Instance.SpawnMissile(mobj, mobj.target, MobjType.MT_FATSHOT);

var secondBall = MobjManager.Instance.SpawnMissile(mobj, mobj.target, MobjType.MT_FATSHOT);
Physics.IgnoreCollision(firstBall.collider, secondBall.collider);
secondBall.transform.rotation *= Quaternion.AngleAxis(-fatSpread * 2, Vector3.up);
secondBall.transform.rotation = mobj.transform.rotation;
secondBall.rigidbody.velocity = secondBall.transform.forward * secondBall.info.speed;
}

public void A_FatAttack3()
{
float fatSpread = (90 / 8);
float fatSpread = (90 / 8) / 32f;
A_FaceTarget();
mobj.transform.rotation *= Quaternion.AngleAxis(-fatSpread / 2, Vector3.up);
var firstBall = MobjManager.Instance.SpawnMissile(mobj, mobj.target, MobjType.MT_FATSHOT);

var secondBall = MobjManager.Instance.SpawnMissile(mobj, mobj.target, MobjType.MT_FATSHOT);
Physics.IgnoreCollision(firstBall.collider, secondBall.collider);
secondBall.transform.rotation *= Quaternion.AngleAxis(-fatSpread / 2, Vector3.up);
secondBall.transform.rotation = mobj.transform.rotation;
secondBall.rigidbody.velocity = secondBall.transform.forward * secondBall.info.speed;
}

public void A_Hoof()
Expand Down Expand Up @@ -1184,7 +1159,7 @@ public void A_Fire()
return;
}

if(!mobj.brain.CheckSight(dest))
if(!MobjInteraction.CheckSight(mobj, dest))
{
return;
}
Expand Down Expand Up @@ -1216,7 +1191,7 @@ public void A_VileAttack()

A_FaceTarget();

if(!CheckSight(mobj.target))
if(!MobjInteraction.CheckSight(mobj, mobj.target))
{
return;
}
Expand Down
Loading

0 comments on commit 6ff97f1

Please sign in to comment.