Merge origin/master into asteroid-floater-layer
This commit is contained in:
commit
da2a7cc56a
17 changed files with 947 additions and 109 deletions
|
|
@ -132,8 +132,7 @@ public sealed class InspectableSchematicShapeDrawer : ICultInspectorDrawer
|
|||
using (new EditorGUILayout.HorizontalScope())
|
||||
for (var x = 0; x < shape.Width; x++)
|
||||
{
|
||||
var hardpoint = hull?.Hardpoints.FirstOrDefault(hp => hp.Shape.Coordinates
|
||||
.Any(v => v.x + hp.Position.x == x && v.y + hp.Position.y == y));
|
||||
var hardpoint = hull?.Hardpoints.FirstOrDefault(hp => HullFootprint.Cells(hp).Contains(int2(x, y)));
|
||||
var previous = GUI.backgroundColor;
|
||||
if (hardpoint != null) GUI.backgroundColor = hardpoint.TintColor.ToColor();
|
||||
shape[int2(x, y)] = GUILayout.Toggle(shape[int2(x, y)], GUIContent.none, GUILayout.Width(16));
|
||||
|
|
@ -145,3 +144,47 @@ public sealed class InspectableSchematicShapeDrawer : ICultInspectorDrawer
|
|||
return shape;
|
||||
}
|
||||
}
|
||||
|
||||
// A hardpoint's schematic footprint over its hull's cells: the hull's occupied cells shaded, this hardpoint's cells lit
|
||||
// in its tint, other hardpoints' cells tinted and disabled. A click edits Position and Shape together through
|
||||
// HullFootprint.Toggle, which owns the rule so a Thing host reads the same one. The footprint is authored for gameplay,
|
||||
// never derived from the model. Read-only on inspector.Record; only the HardpointData it is given changes.
|
||||
[CultInspectorDrawer(typeof(HardpointData))]
|
||||
public sealed class HardpointFootprintDrawer : ICultInspectorDrawer
|
||||
{
|
||||
public object Draw(CultInspector inspector, string label, Type type, object value, MemberInfo member)
|
||||
{
|
||||
var hardpoint = value as HardpointData;
|
||||
if (type != typeof(HardpointData) || hardpoint == null) return inspector.DrawDefault(label, type, value, member);
|
||||
var hull = inspector.Record as HullData;
|
||||
var own = hull?.Hardpoints.FirstOrDefault(hp => hp.Type == hardpoint.Type && hp.Position.Equals(hardpoint.Position)
|
||||
&& HullFootprint.Cells(hp).SequenceEqual(HullFootprint.Cells(hardpoint)));
|
||||
var drawn = (HardpointData) inspector.DrawDefault(label, type, value, member);
|
||||
if (hull?.Shape == null) return drawn;
|
||||
|
||||
var others = hull.Hardpoints.Where(hp => hp != own).ToArray();
|
||||
EditorGUILayout.LabelField("Footprint");
|
||||
for (var y = hull.Shape.Height - 1; y >= 0; y--)
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
for (var x = 0; x < hull.Shape.Width; x++)
|
||||
{
|
||||
var cell = int2(x, y);
|
||||
var other = others.FirstOrDefault(hp => HullFootprint.Cells(hp).Contains(cell));
|
||||
var on = HullFootprint.Cells(drawn).Contains(cell);
|
||||
var previous = GUI.backgroundColor;
|
||||
GUI.backgroundColor = on ? drawn.TintColor.ToColor() : other != null ? other.TintColor.ToColor()
|
||||
: hull.Shape[cell] ? Color.gray : previous;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
using (new EditorGUI.DisabledScope(other != null && !on))
|
||||
GUILayout.Toggle(on || other != null, GUIContent.none, GUILayout.Width(16));
|
||||
if (EditorGUI.EndChangeCheck() && HullFootprint.Toggle(drawn.Shape, drawn.Position, cell, out var shape, out var position))
|
||||
{
|
||||
drawn.Shape = shape;
|
||||
drawn.Position = position;
|
||||
GUI.changed = true;
|
||||
}
|
||||
GUI.backgroundColor = previous;
|
||||
}
|
||||
return drawn;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ using float2 = CultMath.float2;
|
|||
using float3 = CultMath.float3;
|
||||
|
||||
// Batch proof that the presenters read the drawn pose through the clock: DrawnPoseTests pins the pose maths headlessly,
|
||||
// and this is what pins that each presenter passes ActionGameManager.Clock.Lead into it. A zone is loaded into a fresh
|
||||
// ZoneRenderer with the pickup and mine prefabs ARPG.unity's ZoneRenderer names; a loose Projectile is launched on the
|
||||
// and this is what pins that each presenter passes ActionGameManager.Clock.Lead into it. A zone with a sun and a planet on a moving rail
|
||||
// is built and the pickup and mine prefabs ARPG.unity's ZoneRenderer names are bound to it as the renderer binds them; a loose Projectile is launched on the
|
||||
// zone. The zone is stepped once, then the clock is set to leads 0, 0.008 and 0.015 s with no step, and each presenter's
|
||||
// own Update places its transform. A body is drawn at its last step plus its step velocity times the lead, spelled here
|
||||
// from the body's fields, so a presenter that reads lead 0 (or half the lead) sits on the step and fails.
|
||||
|
|
@ -110,32 +110,34 @@ namespace Aetheria.EditorTools
|
|||
|
||||
var oneCell = new Shape(1, 1);
|
||||
oneCell[new CultMath.int2(0, 0)] = true;
|
||||
var cache = AetheriaStores.Open(Path.Combine(_work, "wiring.cc"), catalogWritable: true);
|
||||
var cache = AetheriaStores.Open(Path.Combine(_work, "wiring.cc"), Path.Combine(_work, "wiring-run.cc"), catalogWritable: true);
|
||||
cache.Upsert(new VerseGrammar { Revision = 1 });
|
||||
cache.Upsert(new SimpleCommodityData { Name = "Wiring Ore", Shape = oneCell, MaxStack = 100 });
|
||||
cache.FlushAsync().Wait();
|
||||
var ledger = new ProvenanceLedger();
|
||||
var items = new ItemManager(cache, ledger, settings, _ => { });
|
||||
var zone = new Zone(items, new PlanetSettings(), new ZonePack(), null, null);
|
||||
|
||||
// A sun and a planet on a moving rail round it, both near the bodies below: the field under a floater changes with the
|
||||
// drawn time, so a presenter that samples it at the step's time, drops it, or reads lead 0 for the height draws a different y.
|
||||
var sunOrbit = cache.Upsert(new OrbitData { FixedPosition = new float2(-55, -.5f) }).Key;
|
||||
var planetOrbit = cache.Upsert(new OrbitData { Parent = new CultRecordRef<OrbitData>(sunOrbit), Distance = 40f, Phase = 0f }).Key;
|
||||
var pack = new ZonePack { Radius = 5000f, Mass = 10000f };
|
||||
pack.Orbits.Add(new CultRecordRef<OrbitData>(sunOrbit));
|
||||
pack.Orbits.Add(new CultRecordRef<OrbitData>(planetOrbit));
|
||||
pack.Planets.Add(new CultRecordRef<BodyData>(cache.Upsert(new PlanetData { Name = "Wiring Sun", Orbit = new CultRecordRef<OrbitData>(sunOrbit), Mass = 400f }).Key));
|
||||
pack.Planets.Add(new CultRecordRef<BodyData>(cache.Upsert(new PlanetData { Name = "Wiring Planet", Orbit = new CultRecordRef<OrbitData>(planetOrbit), Mass = 400f }).Key));
|
||||
var curves = new PlanetSettings
|
||||
{
|
||||
BodyRadius = new ExponentialCurve(),
|
||||
WellStrength = new ExponentialCurve { Multiplier = 1f, Exponent = 1f },
|
||||
RocheLimit = new ExponentialCurve { Constant = 10f }
|
||||
};
|
||||
var zone = new Zone(items, curves, pack, null, null);
|
||||
|
||||
var rootObject = new GameObject("Wiring Zone Root");
|
||||
var rendererObject = new GameObject("Wiring Zone Renderer");
|
||||
rendererObject.SetActive(false); // inactive: ZoneRenderer.Update needs a GPU and is not part of this check
|
||||
var renderer = rendererObject.AddComponent<ZoneRenderer>();
|
||||
renderer.ZoneRoot = rootObject.transform;
|
||||
renderer.SimpleCommodityPickup = pickupPrefab;
|
||||
renderer.MinePrefab = minePrefab;
|
||||
renderer.ItemManager = items;
|
||||
renderer.SectorBrushes = new GameObject("Wiring Brushes").transform;
|
||||
renderer.AmbientLight = AmbientEdgeVerify.NewAmbientLight();
|
||||
renderer.SlimeGravityCamera = new GameObject("Wiring Gravity Camera").AddComponent<Camera>();
|
||||
var slimeObject = new GameObject("Wiring Slime");
|
||||
slimeObject.SetActive(false);
|
||||
renderer.SlimeRenderer = slimeObject.AddComponent<Slime>();
|
||||
renderer.LoadZone(zone);
|
||||
|
||||
var ore = new SimpleCommodity { Data = items.ItemData.RefOf<ItemData>(items.ItemData.GetByName<SimpleCommodityData>("Wiring Ore")), Quantity = 7 };
|
||||
var floating = zone.Release(ore, new float2(3, 4), new float2(10, 0));
|
||||
var floating = zone.Release(ore, new float2(-17, 4), new float2(10, 0));
|
||||
var mine = new Mine
|
||||
{
|
||||
Body = new KinematicBody { Position = new float2(-20, 8), Velocity = new float2(0, 14) },
|
||||
|
|
@ -143,6 +145,13 @@ namespace Aetheria.EditorTools
|
|||
};
|
||||
zone.Lay(mine);
|
||||
|
||||
// Bound the way ZoneRenderer.LoadFloatingItem and LoadMine bind them: the prefab ARPG.unity names, Bind(zone, body, settings).
|
||||
// (A ZoneRenderer would load this zone's sun and planet too, and that needs the planet prefab, the map and a GPU.)
|
||||
var pickup = UnityEngine.Object.Instantiate(pickupPrefab, rootObject.transform);
|
||||
pickup.Bind(zone, floating, settings);
|
||||
var mineInstance = UnityEngine.Object.Instantiate(minePrefab, rootObject.transform);
|
||||
mineInstance.Bind(zone, mine, settings);
|
||||
|
||||
// A round on its frozen line, no target and no outcome known: drawn at FireOrigin + direction * speed * (T - FireTime).
|
||||
var shot = new PendingShot
|
||||
{
|
||||
|
|
@ -155,13 +164,17 @@ namespace Aetheria.EditorTools
|
|||
|
||||
zone.Update(.5f);
|
||||
|
||||
var pickup = rootObject.GetComponentsInChildren<ItemPickup>(true).Single(p => p.Item == ore);
|
||||
var mineInstance = UnityEngine.Object.FindObjectsByType<MineInstance>(FindObjectsInactive.Include, FindObjectsSortMode.None).Single();
|
||||
|
||||
var pickupVelocity = floating.Body.TotalVelocity;
|
||||
var mineVelocity = mine.Body.TotalVelocity;
|
||||
Require(Mathf.Abs(pickupVelocity.x) > 1f && Mathf.Abs(mineVelocity.y) > 1f, "The fixture's bodies stopped: a lead would not move them.");
|
||||
|
||||
// The field under each floater really is a function of the drawn time here, by more than the tolerance at the largest lead.
|
||||
const float LargestLead = .015f;
|
||||
foreach (var at in new[] { floating.Body.Position + pickupVelocity * LargestLead, mine.Body.Position + mineVelocity * LargestLead })
|
||||
Require(Mathf.Abs(DrawAhead.Height(zone, at, LargestLead) - zone.GetHeight(at, zone.ExactTime)) > 5 * Tolerance,
|
||||
$"The fixture's field is flat under a floater: height {DrawAhead.Height(zone, at, LargestLead)} at the drawn time, {zone.GetHeight(at, zone.ExactTime)} at the step, planet at {zone.OrbitPositionAt(planetOrbit, zone.ExactTime)}, floater at {at}.");
|
||||
|
||||
Vector2 baseline = default;
|
||||
foreach (var leadSeconds in new[] { 0f, .008f, .015f })
|
||||
{
|
||||
|
|
@ -176,6 +189,9 @@ namespace Aetheria.EditorTools
|
|||
Require(Mathf.Abs(seen.x - want.x) < Tolerance && Mathf.Abs(seen.z - want.y) < Tolerance,
|
||||
$"ItemPickup at lead {lead}: drawn x/z {seen.x},{seen.z}, the step plus velocity times lead {want.x},{want.y}.");
|
||||
|
||||
Require(Mathf.Abs(seen.y - DrawAhead.FloaterHeight(zone, settings, new float2(want.x, want.y), lead)) < Tolerance,
|
||||
$"ItemPickup y {seen.y} is not on the floater layer.");
|
||||
|
||||
seen = mineInstance.transform.position;
|
||||
want = mine.Body.Position + mineVelocity * lead;
|
||||
Require(Mathf.Abs(seen.x - want.x) < Tolerance && Mathf.Abs(seen.z - want.y) < Tolerance,
|
||||
|
|
|
|||
43
Assets/Scripts/ServerShared/HullFootprint.cs
Normal file
43
Assets/Scripts/ServerShared/HullFootprint.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CultMath;
|
||||
|
||||
// A hardpoint's schematic footprint: its Shape laid over the hull's cells at its Position, in hull orientation.
|
||||
// The footprint is authored for gameplay and never derived from the model or the Blender add-on
|
||||
// (schematic-and-model-are-separate-spaces). This is the one reading of footprint cells in hull space and the one
|
||||
// edit rule, so any host (the Studio drawer now, a Thing host later) edits footprints the same way.
|
||||
public static class HullFootprint
|
||||
{
|
||||
public static IEnumerable<int2> Cells(HardpointData hardpoint) =>
|
||||
hardpoint.Shape.Coordinates.Select(c => c + hardpoint.Position);
|
||||
|
||||
// Toggles one hull cell of the footprint at `position`. A cell outside the footprint grows it toward any edge;
|
||||
// a cell inside is removed and empty border rows and columns are trimmed; every other cell keeps its hull
|
||||
// coordinate. Removing the last cell is refused (false, outputs are the inputs' values). Builds a new Shape and
|
||||
// never edits the one it is given.
|
||||
public static bool Toggle(Shape footprint, int2 position, int2 hullCell, out Shape shape, out int2 newPosition)
|
||||
{
|
||||
var cells = Cells(footprint, position);
|
||||
if (!cells.Remove(hullCell)) cells.Add(hullCell);
|
||||
else if (cells.Count == 0)
|
||||
{
|
||||
shape = footprint;
|
||||
newPosition = position;
|
||||
return false;
|
||||
}
|
||||
|
||||
var min = cells.Aggregate((a, b) => new int2(math.min(a.x, b.x), math.min(a.y, b.y)));
|
||||
var max = cells.Aggregate((a, b) => new int2(math.max(a.x, b.x), math.max(a.y, b.y)));
|
||||
shape = new Shape(max.x - min.x + 1, max.y - min.y + 1);
|
||||
foreach (var cell in cells) shape[cell - min] = true;
|
||||
newPosition = min;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static HashSet<int2> Cells(Shape footprint, int2 position) =>
|
||||
new HashSet<int2>(footprint.Coordinates.Select(c => c + position));
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/HullFootprint.cs.meta
Normal file
11
Assets/Scripts/ServerShared/HullFootprint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e2b8c4a7d1f4a39b6c0e83f91d7a254
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -60,6 +60,7 @@ public class Shape
|
|||
}
|
||||
|
||||
Cells = newCells;
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
private static int mod(int x, int m) {
|
||||
|
|
@ -85,11 +86,7 @@ public class Shape
|
|||
{
|
||||
get
|
||||
{
|
||||
if (_dirty)
|
||||
{
|
||||
_cachedShapeCoordinates = EnumerateShapeCoordinates().ToArray();
|
||||
_dirty = false;
|
||||
}
|
||||
Refresh();
|
||||
return _cachedShapeCoordinates;
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +105,14 @@ public class Shape
|
|||
private int2[] _cachedAllShapeCoordinates;
|
||||
|
||||
[IgnoreMember]
|
||||
public int2[] AllCoordinates => _cachedAllShapeCoordinates ?? (_cachedAllShapeCoordinates = EnumerateAllShapeCoordinates().ToArray());
|
||||
public int2[] AllCoordinates
|
||||
{
|
||||
get
|
||||
{
|
||||
Refresh();
|
||||
return _cachedAllShapeCoordinates;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<int2> EnumerateAllShapeCoordinates()
|
||||
{
|
||||
|
|
@ -121,11 +125,27 @@ public class Shape
|
|||
}
|
||||
}
|
||||
|
||||
private float2? _centerOfMass;
|
||||
private float2 _centerOfMass;
|
||||
|
||||
[IgnoreMember]
|
||||
public float2 CenterOfMass => _centerOfMass ?? (_centerOfMass = Coordinates
|
||||
.Aggregate(float2.zero, (total, coord) => total + coord) / Coordinates.Length).Value;
|
||||
public float2 CenterOfMass
|
||||
{
|
||||
get
|
||||
{
|
||||
Refresh();
|
||||
return _centerOfMass;
|
||||
}
|
||||
}
|
||||
|
||||
// One dirty flag: Coordinates, AllCoordinates and CenterOfMass are caches of Cells and recompute together.
|
||||
private void Refresh()
|
||||
{
|
||||
if (!_dirty) return;
|
||||
_cachedShapeCoordinates = EnumerateShapeCoordinates().ToArray();
|
||||
_cachedAllShapeCoordinates = EnumerateAllShapeCoordinates().ToArray();
|
||||
_centerOfMass = _cachedShapeCoordinates.Aggregate(float2.zero, (total, coord) => total + coord) / _cachedShapeCoordinates.Length;
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
public bool this[int2 pos] {
|
||||
get { return pos.x >= 0 && pos.y >= 0 && pos.x < Width && pos.y < Height && Cells[pos.x, pos.y]; }
|
||||
|
|
@ -256,7 +276,7 @@ public class Shape
|
|||
{
|
||||
if (x >= 0 && x < Width && y >= 0 && y < Height)
|
||||
{
|
||||
Cells[steep ? y : x, steep ? x : y] = true;
|
||||
this[int2(steep ? y : x, steep ? x : y)] = true;
|
||||
}
|
||||
error += derr;
|
||||
if (error >= 0.5f)
|
||||
|
|
@ -798,8 +818,8 @@ public static class StatValidation
|
|||
// ApplyModifier threw an unhelpful NullReferenceException at random equip time. Resolving it here, once,
|
||||
// memoized, and failing loudly at catalog load or Upsert (through ValidateStatModifiers below) names the
|
||||
// record instead of leaving the bug for whoever equips the item first.
|
||||
private static readonly Dictionary<(string Target, string Stat), (Type Type, FieldInfo Field)> _resolvedStatFields =
|
||||
new Dictionary<(string, string), (Type, FieldInfo)>();
|
||||
private static readonly System.Collections.Concurrent.ConcurrentDictionary<(string Target, string Stat), (Type Type, FieldInfo Field)> _resolvedStatFields =
|
||||
new System.Collections.Concurrent.ConcurrentDictionary<(string, string), (Type, FieldInfo)>();
|
||||
|
||||
private static Type[] _statReferenceTypes;
|
||||
private static Type[] StatReferenceTypes => _statReferenceTypes ??= typeof(BehaviorData).GetAllChildClasses()
|
||||
|
|
|
|||
Loading…
Reference in a new issue