Files
Jiaqi Liu 5d0f564a00 Add a standalone battle editor and battle system for PAL3 and PAL3A (#99)
* build: migrate C# formatting and add offscreen editor test support

Host IMGUI tests on a detached panel without creating a native editor window.

* feat(core): decode native battle records, geometry and animation metadata

Read the two game variants’ battle tables and model data, with binary-reader and original-resource coverage.

* feat(battle): implement deterministic combat rules and action settlement

Implement actors, inventory, formation, action timing, status interruption, AI, stage ownership and deterministic replay. Keep the domain and its regression suite independent of Unity.

* feat(battle): project native HUD state and input commands

Add the presentation assembly and tests for command routing, lineup selection, floating numbers and stage messages.

* feat(rendering): add battle lighting, actor appearance and native shadows

Support baked and toon lighting, actor and weapon rendering, display refresh rate and resource ownership.

* feat(effects): drive battle effects through shared resource previews

Bind battle control nodes to action owners. Share preview lighting, geometry and effect resources with the existing Unity editors.

* refactor(game): isolate story battle targeting and actor lifetimes

Preserve scene ownership, bound story battle targeting and stop debug attacks when their actor leaves the scene.

* feat(editor): compile original game data into battle scenarios

Build per-variant animation and ability catalogs, encounter music, scene lighting profiles, random parties, equipment and test inventory from the original resources.

* feat(editor): play battle sessions with animated previews and synced media

Drive the preview scene, camera, effects, hit feedback, result choreography, music and movies from simulation snapshots and events.

* feat(editor): add the battle workbench, native HUD and input controls

Expose scenario authoring, replay, diagnostics, responsive command menus and mouse, touch and gamepad targeting. Include the editor workflow and HUD integration tests.
2026-11-21 22:28:47 +08:00

148 lines
5.4 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2021-2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Core.Primitives
{
using System;
using System.Runtime.CompilerServices;
[System.Serializable]
public struct GameBoxVector3 : IEquatable<GameBoxVector3>
{
public float X;
public float Y;
public float Z;
public static GameBoxVector3 Zero
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new ();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public GameBoxVector3(float x, float y, float z)
{
X = x;
Y = y;
Z = z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Magnitude(GameBoxVector3 vector) => (float) Math.Sqrt(
(double) vector.X * (double) vector.X +
(double) vector.Y * (double) vector.Y +
(double) vector.Z * (double) vector.Z);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float SqrtMagnitude(GameBoxVector3 vector) => (float) (
(double) vector.X * (double) vector.X +
(double) vector.Y * (double) vector.Y +
(double) vector.Z * (double) vector.Z);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GameBoxVector3 Cross(GameBoxVector3 a, GameBoxVector3 b) => new (
(float) ((double) a.Y * (double) b.Z - (double) a.X * (double) b.Y),
(float) ((double) a.Z * (double) b.X - (double) a.X * (double) b.Z),
(float) ((double) a.X * (double) b.Y - (double) a.Y * (double) b.X));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Distance(GameBoxVector3 a, GameBoxVector3 b)
{
float dx = a.X - b.X;
float dy = a.Y - b.Y;
float dz = a.Z - b.Z;
return (float) Math.Sqrt((double) dx * (double) dx +
(double) dy * (double) dy +
(double) dz * (double) dz);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GameBoxVector3 Normalize(GameBoxVector3 value)
{
float num = Magnitude(value);
return (double) num > 9.999999747378752E-06 ? value / num : Zero;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Normalize()
{
float num = Magnitude(this);
this = (double) num > 9.999999747378752E-06 ? this / num : Zero;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float SqrMagnitude()
{
return X * X + Y * Y + Z * Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GameBoxVector3 operator +(GameBoxVector3 a, GameBoxVector3 b) =>
new (a.X+ b.X, a.Y + b.Y, a.Z + b.Z);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GameBoxVector3 operator -(GameBoxVector3 a, GameBoxVector3 b) =>
new (a.X - b.X, a.Y - b.Y, a.Z - b.Z);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GameBoxVector3 operator -(GameBoxVector3 a) =>
new (-a.X, -a.Y, -a.Z);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GameBoxVector3 operator *(GameBoxVector3 a, float d) =>
new (a.X * d, a.Y * d, a.Z * d);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GameBoxVector3 operator *(float d, GameBoxVector3 a) =>
new (a.X * d, a.Y * d, a.Z * d);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static GameBoxVector3 operator /(GameBoxVector3 a, float d) =>
new GameBoxVector3(a.X / d, a.Y / d, a.Z / d);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(GameBoxVector3 a, GameBoxVector3 b)
{
float dx = a.X - b.X;
float dy = a.Y - b.Y;
float dz = a.Z - b.Z;
return
(double) dx * (double) dx +
(double) dy * (double) dy +
(double) dz * (double) dz < 9.999999439624929E-11;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(GameBoxVector3 a, GameBoxVector3 b) => !(a == b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object obj)
{
return obj is GameBoxVector3 gbVector3 && Equals(gbVector3);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(GameBoxVector3 other)
{
float dx = X - other.X;
float dy = Y - other.Y;
float dz = Z - other.Z;
return
(double) dx * (double) dx +
(double) dy * (double) dy +
(double) dz * (double) dz < 9.999999439624929E-11;
}
public override int GetHashCode()
{
int hash = this.X.GetHashCode();
hash = HashCode.Combine(hash, this.Y.GetHashCode());
hash = HashCode.Combine(hash, this.Z.GetHashCode());
return hash;
}
}
}