Disable debugdraw in release

This commit is contained in:
Marco 2025-08-12 14:37:48 +02:00
commit 34a0e8e380
8 changed files with 70 additions and 68 deletions

View file

@ -5,14 +5,15 @@ namespace Cirno.Scripts.Actors._3D;
[Tool]
public partial class PlayerStartMarker3D : Marker3D
{
private readonly Vector3 _boxSize = new Vector3(0.5f, 0.8f, 0.5f);
public override void _Process(double delta)
{
if (!Engine.IsEditorHint()) return;
#if !DISABLE_DD3D
DebugDraw3D.DrawBox(this.GlobalPosition - _boxSize / 2, Quaternion.Identity, _boxSize, Colors.Green);
#endif
//DebugDraw3D.DrawSphere(this.GlobalPosition, 0.1f, Colors.Green);
}
}

View file

@ -9,7 +9,7 @@ namespace Cirno.Scripts.Actors;
public partial class EnemyMarker3D : PreviewMarker3D, IActivable
{
private readonly Vector3 _boxSize = new Vector3(0.5f, 0.8f, 0.5f);
private EnemyResource _enemy;
[Export]
@ -47,7 +47,6 @@ public partial class EnemyMarker3D : PreviewMarker3D, IActivable
SetSpriteAlpha(0.5f);
}
}
}
}
@ -102,13 +101,13 @@ public partial class EnemyMarker3D : PreviewMarker3D, IActivable
{
Activate();
}
public override void _Process(double delta)
{
if (!Engine.IsEditorHint()) return;
#if !DISABLE_DD3D
DebugDraw3D.DrawBox(this.GlobalPosition - _boxSize / 2, Quaternion.Identity, _boxSize, Colors.Red);
#endif
//DebugDraw3D.DrawSphere(this.GlobalPosition, 0.1f, Colors.Green);
}
}

View file

@ -124,8 +124,9 @@ public partial class ItemMarker3D : PreviewMarker3D
{
if (!Engine.IsEditorHint()) return;
#if !DISABLE_DD3D
DebugDraw3D.DrawBox(this.GlobalPosition - _boxSize / 2, Quaternion.Identity, _boxSize, Colors.Blue);
#endif
//DebugDraw3D.DrawSphere(this.GlobalPosition, 0.1f, Colors.Green);
}
}

View file

@ -6,52 +6,51 @@ namespace Cirno.Scripts.Components.FSM.Enemy._3D;
public partial class Idle : EnemyStateBase3D
{
public override EnemyState StateId => EnemyState.Idle;
[Export] public EnemyStorage3D Storage { get; private set; }
[Export] public EnemyStorage3D Storage { get; private set; }
[Export] public PlayerDetection3D PlayerDetection { get; private set; }
[Export] public GravityProvider GravityProvider { get; private set; }
[Export] public bool DebugEnabled { get; set; } = false;
private bool _isPlayerInRange = false;
public override void EnterState()
{
base.EnterState();
PlayerDetection.SetRange(Storage.Root.EnemyResource.PlayerDetectionRange);
_isPlayerInRange = PlayerDetection.IsPlayerInRange(Storage.Root.EnemyResource.ViewRange);
PlayerDetection.PlayerInRange += PlayerDetectionOnPlayerInRange;
PlayerDetection.PlayerOutOfRange += PlayerDetectionOnPlayerOutOfRange;
// player detection
// damage receiver will be a module
GD.Print("Entered Idle");
}
public override void ExitState()
{
base.ExitState();
PlayerDetection.PlayerInRange -= PlayerDetectionOnPlayerInRange;
PlayerDetection.PlayerOutOfRange -= PlayerDetectionOnPlayerOutOfRange;
// DamageReceiver.HealthProvider.ResourceDepleted -= HealthProviderOnResourceDepleted;
//
// DamageReceiver.HealthProvider.ResourceDecreased -= HealthProviderOnResourceDecreased;
// DamageReceiver.ChangeState(false);
}
private void HealthProviderOnResourceDepleted()
{
ChangeState(EnemyState.Dead);
}
private void HealthProviderOnResourceDecreased(float oldvalue, float newvalue, float maxvalue)
{
Storage.AiState = AiState.Enabled;
@ -63,12 +62,12 @@ public partial class Idle : EnemyStateBase3D
_isPlayerInRange = true;
GD.Print("Player In Range");
}
private void PlayerDetectionOnPlayerOutOfRange()
{
_isPlayerInRange = false;
}
public override void PhysicsProcessState(double delta)
{
base.PhysicsProcessState(delta);
@ -83,15 +82,17 @@ public partial class Idle : EnemyStateBase3D
if (DebugEnabled)
{
DebugDraw3D.DrawText(MainObject.GlobalPosition - new Vector3(0,16,0), "Idle");
#if !DISABLE_DD3D
DebugDraw3D.DrawText(MainObject.GlobalPosition - new Vector3(0, 16, 0), "Idle");
#endif
}
MainObject.Velocity = new Vector3(MainObject.Velocity.X, GravityProvider.CalculateGravityVelocity(MainObject.Velocity.Y, delta), MainObject.Velocity.Z);
MainObject.Velocity = new Vector3(MainObject.Velocity.X,
GravityProvider.CalculateGravityVelocity(MainObject.Velocity.Y, delta), MainObject.Velocity.Z);
MainObject.MoveAndSlide();
}
public override void ProcessState(double delta)
{
base.ProcessState(delta);

View file

@ -33,12 +33,12 @@ public partial class Bullet3D : Area3D, IBullet
public bool Enabled { get; private set; } = false;
//public float SpriteRotation { get; private set; } = 0f;
[Signal]
public delegate void OnDestroyEventHandler();
[Signal]
public delegate void InitializedEventHandler();
public delegate void InitializedEventHandler();
private AudioStreamPlayer3D _grazeSound;
private GpuParticles3D _grazeParticles;
@ -70,7 +70,7 @@ public partial class Bullet3D : Area3D, IBullet
rotation
);
}
public override void _Ready()
{
_grazeSound = GetNodeOrNull<AudioStreamPlayer3D>("GrazeSound");
@ -84,7 +84,7 @@ public partial class Bullet3D : Area3D, IBullet
public void Initialize(BulletInfo bulletInfo)
{
_bulletInfo = bulletInfo;
_elapsedTime = 0f;
this.Speed = bulletInfo.Speed;
@ -99,12 +99,12 @@ public partial class Bullet3D : Area3D, IBullet
if (_collisionShape.Shape is SphereShape3D sphere && bulletInfo.OriginalBulletResource.BulletSize > 0)
{
sphere.Radius = bulletInfo.OriginalBulletResource.BulletSize;
sphere.Radius = bulletInfo.OriginalBulletResource.BulletSize;
}
IsGrazed = false;
IsFrozen = false;
// Need to clone them here
// _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList();
@ -114,7 +114,7 @@ public partial class Bullet3D : Area3D, IBullet
// Ugly hack to make instances unique
_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
EmitSignalInitialized();
}
@ -134,11 +134,11 @@ public partial class Bullet3D : Area3D, IBullet
direction.X * cos - direction.Y * sin,
direction.X * sin + direction.Y * cos
);
//float zRotation = Mathf.Atan2(rotatedDir.Y, rotatedDir.X)/* - Mathf.Pi / 2f*/;
float zRotation = Mathf.Atan2(-rotatedDir.Y, rotatedDir.X) + Mathf.Pi;
return MakeRotationVectorRad(zRotation);
}
@ -190,7 +190,6 @@ public partial class Bullet3D : Area3D, IBullet
private void ApplyTimeModifiers(double delta)
{
foreach (var modifier in _modifiers)
{
if (_elapsedTime >= modifier.TimeModifier.TimeInSeconds)
@ -205,9 +204,8 @@ public partial class Bullet3D : Area3D, IBullet
{
modifier.Elapsed += delta;
}
modifier.TimeModifier.Update(this, delta, modifier.Elapsed);
}
}
}
@ -216,7 +214,7 @@ public partial class Bullet3D : Area3D, IBullet
{
float radians = Mathf.DegToRad(degrees);
_direction = _direction.Rotated(radians).Normalized(); // Rotate direction
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
SetSpriteRotationToDirection();
//SetRotation(Rotation + radians);
@ -227,9 +225,9 @@ public partial class Bullet3D : Area3D, IBullet
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
var currentRotation = _sprite.GetRotationDegrees().Z;
_sprite.RotateZ(Mathf.DegToRad(currentRotation + degrees));
// SpriteRotation = Mathf.DegToRad(Mathf.RadToDeg(SpriteRotation) + degrees);
//SetRotationDegrees(RotationDegrees + degrees);
@ -240,28 +238,28 @@ public partial class Bullet3D : Area3D, IBullet
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
var currentRotation = _sprite.GetRotation().Z;
var axis = Basis.FromEuler(_defaultRotation).Z;
_sprite?.Rotate(axis, currentRotation + radians);
//_sprite.SetRotation(new Vector3());
//Rotate(axis, radians);
//_sprite?.Rotate(Vector3.Forward, radians);
//_sprite?.RotateZ(radians);
//SetRotation(Rotation + radians);
}
public void FacePlayer()
{
if (GameController.Instance.PlayerPosition.HasValue)
{
_direction = (GameController.Instance.PlayerPosition.Value.ToVector2() - this.GlobalPosition.ToVector2()).Normalized();
_direction = (GameController.Instance.PlayerPosition.Value.ToVector2() - this.GlobalPosition.ToVector2())
.Normalized();
RotateBullet(0); // quick hack to rotate lasers
//LookAt(player.GlobalPosition);
}
}
public void SetDirection(Vector2 direction)
{
@ -270,11 +268,9 @@ public partial class Bullet3D : Area3D, IBullet
_direction = normalized;
if (!BulletInfo.Attributes.HasFlag(BulletFlags.Rotateable)) return;
SetSpriteRotationToDirection();
//SetRotation(Mathf.Atan2(normalized.Y, normalized.X) + Mathf.Pi / 2);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
@ -290,7 +286,10 @@ public partial class Bullet3D : Area3D, IBullet
if (GameController.Instance is not null && GameController.Instance.DebugDraw)
{
DebugDraw3D.DrawSphere(this.GlobalPosition, this._bulletInfo.OriginalBulletResource.BulletSize, Colors.DarkRed);
#if !DISABLE_DD3D
DebugDraw3D.DrawSphere(this.GlobalPosition, this._bulletInfo.OriginalBulletResource.BulletSize,
Colors.DarkRed);
#endif
}
}
@ -308,7 +307,7 @@ public partial class Bullet3D : Area3D, IBullet
}
var newPos2D = ((float)(Speed * delta) * _direction);
this.Position += new Vector3(newPos2D.X, 0, newPos2D.Y);
}
@ -335,7 +334,7 @@ public partial class Bullet3D : Area3D, IBullet
private readonly StringName SolidGroup = "Solid";
private readonly StringName PermeableGroup = "Permeable";
private readonly StringName DestroyableGroup = "Destroyable";
private void _on_body_entered(Node3D body)
{
if (body.IsInGroup(DestroyableGroup) && body is IDestructible destructible &&
@ -347,7 +346,7 @@ public partial class Bullet3D : Area3D, IBullet
RequestCollisionDestruction();
return;
}
if (body.IsInGroup(SolidGroup) && !body.IsInGroup(PermeableGroup))
{
//Debug.WriteLine("Collision");
@ -407,7 +406,7 @@ public partial class Bullet3D : Area3D, IBullet
var particleData =
_bulletInfo?.OriginalBulletResource.DestructionParticlesBullet.MakeBullet(
this.GlobalPosition.ToVector2());
var particle = PoolingManager.Instance.SpawnBullet<Bullet3D>(particleData.OriginalBulletResource);
particle.GlobalPosition = this.GlobalPosition;
particle.Initialize(particleData);