Skip to content

Commit

Permalink
Merge pull request #56 from StarCoreSE/yard-logging
Browse files Browse the repository at this point in the history
Revert "disable shipyard scripts due to client lag"
  • Loading branch information
InvalidArgument3 authored Nov 17, 2024
2 parents 8e6f29f + c548c22 commit f935d70
Show file tree
Hide file tree
Showing 23 changed files with 6,589 additions and 0 deletions.
Binary file removed ShipyardsRevival/Data/Scripts/ShipyardMod.zip
Binary file not shown.
136 changes: 136 additions & 0 deletions ShipyardsRevival/Data/Scripts/ShipyardMod/BlockTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Sandbox.Definitions;
using Sandbox.Game.Entities;
using Sandbox.ModAPI;
using ShipyardMod.Utility;
using VRage.Game.ModAPI;
using VRageMath;

namespace ShipyardMod.ItemClasses
{
public class BlockTarget
{
public BlockTarget(IMySlimBlock block, ShipyardItem item)
{
Logging.Instance.WriteDebug($"[BlockTarget] Creating new target for block at position {block.Position}");

Block = block;

// Log physics and projector state
if (CubeGrid.Physics == null)
Logging.Instance.WriteDebug("[BlockTarget] Grid has no physics");
if (Projector != null)
Logging.Instance.WriteDebug("[BlockTarget] Block is from projector");

// Calculate and log distances
if (CubeGrid.Physics == null && Projector != null)
{
CenterDist = Vector3D.DistanceSquared(block.GetPosition(), Projector.GetPosition());
Logging.Instance.WriteDebug($"[BlockTarget] Distance to projector: {Math.Sqrt(CenterDist):F2}m");
}
else
{
CenterDist = Vector3D.DistanceSquared(block.GetPosition(), block.CubeGrid.Center());
Logging.Instance.WriteDebug($"[BlockTarget] Distance to grid center: {Math.Sqrt(CenterDist):F2}m");
}

// Calculate and log tool distances
ToolDist = new Dictionary<long, double>();
foreach (IMyCubeBlock tool in item.Tools)
{
double dist = Vector3D.DistanceSquared(block.GetPosition(), tool.GetPosition());
ToolDist.Add(tool.EntityId, dist);
Logging.Instance.WriteDebug($"[BlockTarget] Distance to tool {tool.EntityId}: {Math.Sqrt(dist):F2}m");
}

// Calculate build time
var blockDef = (MyCubeBlockDefinition)block.BlockDefinition;
BuildTime = blockDef.MaxIntegrity / blockDef.IntegrityPointsPerSec;
Logging.Instance.WriteDebug($"[BlockTarget] Estimated build time: {BuildTime:F2}s");

// Log initial block state
var missingComponents = new Dictionary<string, int>();
block.GetMissingComponents(missingComponents);
if (missingComponents.Any())
{
Logging.Instance.WriteDebug("[BlockTarget] Initial missing components:");
foreach (var component in missingComponents)
Logging.Instance.WriteDebug($" {component.Key}: {component.Value}");
}

Logging.Instance.WriteDebug($"[BlockTarget] Initial integrity: {block.BuildIntegrity:F2}/{block.MaxIntegrity:F2}");
}

public IMyCubeGrid CubeGrid
{
get { return Block.CubeGrid; }
}

public IMyProjector Projector
{
get { return ((MyCubeGrid)Block.CubeGrid).Projector; }
}

public Vector3I GridPosition
{
get { return Block.Position; }
}

public bool CanBuild
{
get
{
if (CubeGrid.Physics != null)
{
Logging.Instance.WriteDebug($"[BlockTarget] Block at {GridPosition} can build: has physics");
return true;
}

var result = Projector?.CanBuild(Block, false) == BuildCheckResult.OK;
if (!result)
{
var buildResult = Projector?.CanBuild(Block, false);
Logging.Instance.WriteDebug($"[BlockTarget] Block at {GridPosition} cannot build: {buildResult}");
}
return result;
}
}

public IMySlimBlock Block { get; private set; }
public float BuildTime { get; }
public double CenterDist { get; }
public Dictionary<long, double> ToolDist { get; }

public void UpdateAfterBuild()
{
Logging.Instance.WriteDebug($"[BlockTarget] Updating block at {GridPosition} after build");

Vector3D pos = Block.GetPosition();
IMyCubeGrid grid = Projector.CubeGrid;
Vector3I gridPos = grid.WorldToGridInteger(pos);
IMySlimBlock newBlock = grid.GetCubeBlock(gridPos);

if (newBlock != null)
{
Block = newBlock;
Logging.Instance.WriteDebug($"[BlockTarget] Updated to new block. Integrity: {Block.BuildIntegrity:F2}/{Block.MaxIntegrity:F2}");

// Log any remaining missing components
var missingComponents = new Dictionary<string, int>();
Block.GetMissingComponents(missingComponents);
if (missingComponents.Any())
{
Logging.Instance.WriteDebug("[BlockTarget] Post-build missing components:");
foreach (var component in missingComponents)
Logging.Instance.WriteDebug($" {component.Key}: {component.Value}");
}
}
else
{
Logging.Instance.WriteDebug("[BlockTarget] Failed to find new block after build");
}
}
}
}
12 changes: 12 additions & 0 deletions ShipyardsRevival/Data/Scripts/ShipyardMod/BoxItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using VRageMath;

namespace ShipyardMod.ItemClasses
{
public class BoxItem
{
public long GridId;
public Vector3D LastPos;
public LineItem[] Lines;
public uint PackedColor;
}
}
Loading

0 comments on commit f935d70

Please sign in to comment.