Floating bodies: FloatingBodyId, KinematicBody.Step, Zone.NextBodyId and the three drift settings
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9116946874
commit
38c47d80ed
5 changed files with 205 additions and 0 deletions
42
Assets/Scripts/ServerShared/FloatingBodies.cs
Normal file
42
Assets/Scripts/ServerShared/FloatingBodies.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* 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;
|
||||
using CultMath;
|
||||
using static CultMath.math;
|
||||
using float2 = CultMath.float2;
|
||||
|
||||
// A free-floating body in a zone: a floating item or a mine. Zone-scoped and never reused within a zone;
|
||||
// runtime state only, never saved.
|
||||
public readonly struct FloatingBodyId : IEquatable<FloatingBodyId>
|
||||
{
|
||||
public readonly uint Value;
|
||||
public FloatingBodyId(uint value) => Value = value;
|
||||
public bool Equals(FloatingBodyId other) => Value == other.Value;
|
||||
public override bool Equals(object obj) => obj is FloatingBodyId other && Equals(other);
|
||||
public override int GetHashCode() => (int) Value;
|
||||
public override string ToString() => Value.ToString();
|
||||
}
|
||||
|
||||
// The one drift integrator of every free body in a zone. A launch velocity decays on its own drag; the zone's
|
||||
// force accumulates into a separate drift velocity that has its own drag, so a body settles to
|
||||
// force * gravity / drag. Engine-free: the caller supplies dt and the zone force at the body's position.
|
||||
public struct KinematicBody
|
||||
{
|
||||
public float2 Position;
|
||||
// The launch velocity, decaying.
|
||||
public float2 Velocity;
|
||||
public float2 Drift;
|
||||
|
||||
// What a presenter draws ahead with.
|
||||
public float2 TotalVelocity => Velocity + Drift;
|
||||
|
||||
public void Step(float dt, float2 force, GameplaySettings s)
|
||||
{
|
||||
Velocity *= exp(-s.FloatingBodyLaunchDrag * dt);
|
||||
Drift += force * s.FloatingBodyGravity * dt;
|
||||
Drift *= exp(-s.FloatingBodyDrag * dt);
|
||||
Position += (Velocity + Drift) * dt;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/FloatingBodies.cs.meta
Normal file
11
Assets/Scripts/ServerShared/FloatingBodies.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 274c5573e2634fb58c52dbbf0406ce79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -173,6 +173,11 @@ public class GameplaySettings
|
|||
public float ThermalQualityMin = 2;
|
||||
public float ThermalQualityMax = .25f;
|
||||
public float DefaultShutdownPerformance = .25f;
|
||||
// Free-floating bodies (floating items, mines): drag on a launch velocity, drag on the force-driven drift, and
|
||||
// how strongly the zone force accelerates it.
|
||||
public float FloatingBodyDrag = .05f;
|
||||
public float FloatingBodyLaunchDrag = .2f;
|
||||
public float FloatingBodyGravity = 1f;
|
||||
public float SevereHeatstrokeRiskThreshold = .25f;
|
||||
public float WormholeDepth = 1000;
|
||||
public float WormholeExitVelocity = 20;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@ public class Zone
|
|||
// of touching a shared stream.
|
||||
public uint CombatSeed { get; }
|
||||
|
||||
// The one source of floating item and mine ids: zone-scoped, from 1, never reused. Runtime state, not saved.
|
||||
private uint _lastBodyId;
|
||||
public FloatingBodyId NextBodyId() => new FloatingBodyId(++_lastBodyId);
|
||||
|
||||
public Zone(ItemManager itemManager, PlanetSettings settings, ZonePack pack, GalaxyZone galaxyZone, Galaxy galaxy)
|
||||
{
|
||||
_time = pack.Time;
|
||||
|
|
|
|||
Loading…
Reference in a new issue