3D-Arena (Duell, Hub, Freiheit, Erstellung, Bestenliste), Retiarius beidhändig, Waffen je Klasse, Einführung, Willkommen, weniger Reiter, Wirtschaft ohne Taberna, Kantenglättung, Leuchten, weiche Schatten, Gamepad, Absturz-Protokoll

Stand von main 20cd8ba2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 13:24:20 +01:00
parent a08764c505
commit e29db47b20
44 changed files with 2089 additions and 991 deletions

View File

@@ -29,6 +29,7 @@ namespace GladiatorIdle
DuelScene? _scene;
ModelTestScene? _model; // --model3d: 3D-Test
FreedomScene? _freedom; // Freiheit: Clip, Bilanz, Götter
OfflineReport? _welcome; // was offline passiert ist (beim Weiterspielen gezeigt)
LeaderboardScene? _board; // Bestenliste (aus dem Menü)
bool _nextLife; // nächste Erstellung behält das Profil (Legenden, Götter)
Legend? _legend; // laufendes Duell gegen eine Legende
@@ -36,6 +37,7 @@ namespace GladiatorIdle
static readonly bool DevChampionRun = Array.IndexOf(Environment.GetCommandLineArgs(), "--champion") >= 0;
static readonly bool DevAdventureRun = Array.IndexOf(Environment.GetCommandLineArgs(), "--adventure") >= 0;
static readonly bool DevBoardRun = Array.IndexOf(Environment.GetCommandLineArgs(), "--leaderboard") >= 0;
static readonly bool DevTutorialRun = Array.IndexOf(Environment.GetCommandLineArgs(), "--tutorial") >= 0;
static readonly bool Model3DTest = Array.IndexOf(Environment.GetCommandLineArgs(), "--model3d") >= 0;
SettingsOverlay _settings = null!;
bool _paused;
@@ -59,9 +61,11 @@ namespace GladiatorIdle
public ArenaGame()
{
_gdm = new GraphicsDeviceManager(this) { SynchronizeWithVerticalRetrace = true, GraphicsProfile = GraphicsProfile.HiDef };
_gdm = new GraphicsDeviceManager(this) { SynchronizeWithVerticalRetrace = true, GraphicsProfile = GraphicsProfile.HiDef,
PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8 }; // Stencil: Schatten im Duell
SetMode(AppSettings.Fullscreen);
IsFixedTimeStep = false;
ApplyFrameLimit(apply: false);
IsMouseVisible = true;
Window.Title = L.t("app.title");
Window.AllowUserResizing = true;
@@ -86,6 +90,23 @@ namespace GladiatorIdle
}
}
/// Bildrate nach Einstellung: VSync, feste 120 Bilder/s oder unbegrenzt (Testläufe: immer VSync).
void ApplyFrameLimit(bool apply = true)
{
int mode = DevShot.Active ? 0 : AppSettings.FrameLimit;
_gdm.SynchronizeWithVerticalRetrace = mode == 0;
IsFixedTimeStep = mode == 1;
if (mode == 1) TargetElapsedTime = TimeSpan.FromSeconds(1 / 120.0);
if (apply) _gdm.ApplyChanges();
}
readonly Gfx.PostFx _post = new();
object? _shown; // zuletzt gezeigter Bildschirm (für das Überblenden)
double _fadeIn = 1; // 0 → 1 nach einem Wechsel
/// Spielstand sofort sichern (Absturz-Behandlung); Testläufe speichern ohnehin nie.
public void SaveNow() => _game?.Save();
void ToggleFullscreen()
{
AppSettings.Fullscreen = !AppSettings.Fullscreen;
@@ -111,7 +132,12 @@ namespace GladiatorIdle
_sb = new SpriteBatch(GraphicsDevice);
_fx = new BasicEffect(GraphicsDevice) { TextureEnabled = true, VertexColorEnabled = true, LightingEnabled = false, World = Matrix.Identity };
Assets.Init(GraphicsDevice);
_settings = new SettingsOverlay(ToggleFullscreen);
_settings = new SettingsOverlay(ToggleFullscreen)
{
ApplyGraphics = () => ApplyFrameLimit(),
Tutorial = () => _game == null ? null : _game.TutorialDone,
ReplayTutorial = () => { if (_game != null) { _game.TutorialDone = false; _game.Save(); } }
};
Window.TextInput += (_, e) => { if (!_settings.Open) _creator?.OnText(e.Character, e.Key); };
// eigener Spielstand fürs neue Spiel; vorhandenen laden und Abwesenheit nachrechnen
GameState.SaveFile = "arena.json";
@@ -119,8 +145,8 @@ namespace GladiatorIdle
if (!DevShot.Active && GameState.Load(out var savedUtc) is GameState loaded)
{
_game = loaded;
_game.ManualFights = true;
_game.ApplyOffline((DateTime.UtcNow - savedUtc).TotalSeconds);
var away = _game.ApplyOffline((DateTime.UtcNow - savedUtc).TotalSeconds);
if (away.Seconds >= 120) _welcome = away; // im Hub als erstes Fenster
ToMenu();
}
else if (!DevShot.Active) { _introThenCreate = true; _intro = new IntroScene(); } // erster Start: Intro
@@ -156,7 +182,10 @@ namespace GladiatorIdle
}
// --sim H: weiter vorn einsteigen (Testläufe, Ausprobieren späterer Arenen)
if (Array.IndexOf(Environment.GetCommandLineArgs(), "--sim") >= 0) Playtest.Advance(_game, DevShot.SimHours);
_game.ManualFights = true;
// --duelarena N: gleich in Arena N (Kulisse prüfen)
var cmd = Environment.GetCommandLineArgs();
int da = Array.IndexOf(cmd, "--duelarena");
if (da >= 0 && da + 1 < cmd.Length && int.TryParse(cmd[da + 1], out int arenaN)) _game.DevArena(arenaN);
_game.Save();
_creator = null;
var sw = Stopwatch.StartNew();
@@ -183,7 +212,6 @@ namespace GladiatorIdle
_offer = null;
_enemy = GameState.LegendEnemy(l);
_before = _hub!.Snapshot();
_game!.BeginDuel();
_scene = new DuelScene(_game, _enemy, _seed++);
if (DevShot.Active) _scene.Bot = new DuelBot(0.8, new Random(3));
DevShot.Log($"legend duel vs #{l.Number} {l.Name} ratio={_game.DuelRatio(_enemy):0.00}");
@@ -195,10 +223,11 @@ namespace GladiatorIdle
_offer = o;
_enemy = o.Enemy;
_before = _hub!.Snapshot();
_game!.BeginDuel();
var sw = Stopwatch.StartNew();
_scene = new DuelScene(_game, _enemy, _seed++);
DevShot.Log($"timing: duel created in {sw.ElapsedMilliseconds} ms");
// erster Kampf eines neuen Profils: Einführung (in Testläufen nur mit --tutorial)
if (!_game.TutorialDone && o.Kind != OfferKind.Champion && (!DevShot.Active || DevTutorialRun)) _scene.StartTutorial();
if (DevShot.Active) _scene.Bot = new DuelBot(0.8, new Random(3));
DevShot.Log($"duel vs {_enemy.NameKey} ({o.Kind}) arena={_game.Arena} rank={_game.Rank} ratio={_game.DuelRatio(_enemy):0.00}");
}
@@ -207,6 +236,7 @@ namespace GladiatorIdle
void EndDuel()
{
bool won = _scene!.Won;
if (_scene.TutorialRan) _game!.TutorialDone = true;
if (_legend is Legend l)
{
bool first = _game!.ResolveLegendDuel(l, won);
@@ -227,6 +257,26 @@ namespace GladiatorIdle
_game.Save();
}
// Speichern bald nach einem Klick außerhalb des Kampfs (Kauf, Anlegen, Lernen, Opfern, Expedition,
// Entscheidung …): gebündelt, höchstens alle 2 s. Testläufe speichern nie (GameState.Save).
double _saveSoon = -1, _clock, _lastSave = -9;
void SaveSoon(float dt)
{
_clock += dt;
if (_game == null || _creator != null) return;
if (_scene == null && _input.LeftClick) _saveSoon = 0.6;
if (_saveSoon < 0 || (_saveSoon -= dt) > 0) return;
if (_clock - _lastSave < 2) { _saveSoon = 0.3; return; }
_game.Save(); _lastSave = _clock; _saveSoon = -1;
}
/// Fenster verliert den Fokus (Alt+Tab, minimiert): sofort speichern.
protected override void OnDeactivated(object sender, EventArgs args)
{
if (_game != null && _creator == null) { _game.Save(); _lastSave = _clock; }
base.OnDeactivated(sender, args);
}
readonly Stopwatch _updWatch = new();
double _updMs;
@@ -245,12 +295,16 @@ namespace GladiatorIdle
_input.PrevKeys = _input.Keys; _input.PrevMouse = _input.Mouse;
_input.Keys = Keyboard.GetState();
_input.Mouse = IsActive ? Mouse.GetState() : default;
_input.PrevPad = _input.Pad;
_input.Pad = IsActive ? GamePad.GetState(PlayerIndex.One) : default;
_input.DetectDevice();
var ui = UiMatrix(out _, out _);
Window.Title = L.t("app.title");
// Einstellungen liegen über allem und nehmen die Eingaben
var input = _input;
if (_settings.Open) { _settings.Update(_input, ui); input = _noInput; }
SaveSoon(dt);
if (DevShot.Active) DevMenu(dt);
if (_model != null)
@@ -293,7 +347,7 @@ namespace GladiatorIdle
_menu.Update(dt, input, ui, _settings.Open);
switch (_menu.Picked)
{
case MenuScene.Choice.Continue when _game != null: _menu = null; _hub = new HubScene(_game); break;
case MenuScene.Choice.Continue when _game != null: _menu = null; _hub = new HubScene(_game) { Welcome = _welcome }; _welcome = null; break;
case MenuScene.Choice.New: _menu = null; _creator = new CreatorScene(DevShot.Active ? DevShot.Name : L.t("gladiator.defaultname")); break;
case MenuScene.Choice.Intro: _menu = null; _intro = new IntroScene(); break;
case MenuScene.Choice.Leaderboard:
@@ -329,7 +383,7 @@ namespace GladiatorIdle
{
if ((_saveIn -= dt) <= 0) { _saveIn = 30; _game!.Save(); }
if (!IsActive && !DevShot.Active && !_scene.Over) _scene.Paused = true; // Fenster verlassen: Pause
if (input.Pressed(Keys.Escape) && !_scene.Over) _scene.Paused = !_scene.Paused;
if ((input.Pressed(Keys.Escape) || input.PadPressed(Buttons.Start)) && !_scene.Over) _scene.Paused = !_scene.Paused;
if (_scene.Paused && input.Pressed(Keys.X)) _scene.GiveUp();
_game!.Tick(dt); // Training läuft auch im Kampf weiter
_scene.Update(dt, input);
@@ -388,6 +442,17 @@ namespace GladiatorIdle
if (m.Model == null) { DevShot.Log("model3d: no model"); Exit(); return; }
if (_capture != null) return;
var clips = m.Model.Clips;
// --clip=<name>: 8 Bilder über eine Bewegung verteilt (Seitenansicht), mit Treffermoment im Protokoll
var only = Array.Find(Environment.GetCommandLineArgs(), a => a.StartsWith("--clip="))?.Substring(7);
int ci = only == null ? -1 : clips.FindIndex(c => c.Name == only);
if (ci >= 0)
{
float impact = m.Model.ImpactTime(clips[ci]);
if (_mStep >= 9) { DevShot.Log($"model3d clip {only}: length {clips[ci].Length:0.00} impact {impact:0.00}"); Exit(); return; }
if (!_mArmed) { m.Paused = true; m.SetView(2); m.Color = -1; m.Play(ci); m.Time = _mStep == 8 ? impact : clips[ci].Length * _mStep / 7f; _mArmed = true; _mWait = 0.35; return; }
if ((_mWait -= dt) > 0) return;
_capture = $"clip_{_mStep}"; _mStep++; _mArmed = false; return;
}
if (_mStep >= 3 + clips.Count)
{
DevShot.Log($"model3d: {clips.Count} clips, {m.Model.BoneCount} bones, {m.Model.Vertices.Length} vertices, {m.Model.Indices.Length / 3} triangles, draw {_drawMs / Math.Max(1, _frames):0.00} ms/frame");
@@ -424,17 +489,24 @@ namespace GladiatorIdle
if (DevFreedomRun && _game!.Legends.Count == 0 && _devTime > 0.5) { _game.DevFreedom(); return; }
if (DevFreedomRun && _game!.Legends.Count > 0 && !_shots.Contains("m_end"))
{
if (_devTime > 0.8 && !_shots.Contains("h_hall_open")) { _shots.Add("h_hall_open"); _hub!.DevOpen(5); }
if (_devTime > 0.8 && !_shots.Contains("h_hall_open")) { _shots.Add("h_hall_open"); _hub!.DevOpen("hall"); }
if (_devTime > 1.5) Shot("h_hall");
if (_devTime > 1.8 && _capture == null && _shots.Contains("h_hall")) { _hub!.DevOpen(0); _hub.ChosenLegend = _game.Legends[0]; _devTime = 0; }
if (_devTime > 1.8 && _capture == null && _shots.Contains("h_hall")) { _hub!.DevOpen("none"); _hub.ChosenLegend = _game.Legends[0]; _devTime = 0; }
return;
}
if (Array.IndexOf(Environment.GetCommandLineArgs(), "--welcome") >= 0)
{
if (_devTime > 0.5 && !_shots.Contains("w_set")) { _shots.Add("w_set"); _hub!.Welcome = new OfflineReport(3 * 3600 + 1240, 1840, 96, 0, 0, 7); }
if (_devTime > 1.2) Shot("w_welcome");
if (_devTime > 1.6 && _capture == null && _shots.Contains("w_welcome")) Exit();
return;
}
if (DevAdventureRun)
{
// Expeditionen: Auswahl, unterwegs, Rückkehr-Bericht; dann ein Ereignis mit Entscheidung
if (_devTime > 0.8 && !_shots.Contains("x_open")) { _shots.Add("x_open"); _hub!.DevOpen(6); }
if (_devTime > 0.8 && !_shots.Contains("x_open")) { _shots.Add("x_open"); _hub!.DevOpen("expedition"); }
if (_devTime > 1.6) Shot("x_regions");
if (_devTime > 1.9 && !_shots.Contains("x_go")) { _shots.Add("x_go"); _hub!.DevOpen(0); _game!.StartExpedition("gallia", 1); }
if (_devTime > 1.9 && !_shots.Contains("x_go")) { _shots.Add("x_go"); _hub!.DevOpen("none"); _game!.StartExpedition("gallia", 1); }
if (_devTime > 2.6) Shot("x_away");
if (_devTime > 2.9 && !_shots.Contains("x_back")) { _shots.Add("x_back"); _game!.Tick(Adventures.Durations[1] + 1); }
if (_devTime > 3.6) Shot("x_report");
@@ -452,26 +524,26 @@ namespace GladiatorIdle
if (!_shots.Contains("m_end"))
{
if (_devTime > 1.0) Shot("h_hub");
if (_devTime > 1.5 && !_shots.Contains("h_pick")) { _shots.Add("h_pick"); _hub!.DevOpen(1); }
if (_devTime > 1.5 && !_shots.Contains("h_pick")) { _shots.Add("h_pick"); _hub!.DevOpen("gladiator"); }
if (_devTime > 2.2) Shot("h_gladiator");
if (_devTime > 2.6 && !_shots.Contains("h_ludus_open")) { _shots.Add("h_ludus_open"); _hub!.DevOpen(2); }
if (_devTime > 2.6 && !_shots.Contains("h_ludus_open")) { _shots.Add("h_ludus_open"); _hub!.DevOpen("ludus"); }
if (_devTime > 3.3) Shot("h_ludus");
if (_devTime > 3.5 && !_shots.Contains("h_forum_open")) { _shots.Add("h_forum_open"); _hub!.DevOpen(3); }
if (_devTime > 3.5 && !_shots.Contains("h_forum_open")) { _shots.Add("h_forum_open"); _hub!.DevOpen("gladiator"); }
if (_devTime > 4.2) Shot("h_forum");
if (_devTime > 4.4 && !_shots.Contains("h_skills_open")) { _shots.Add("h_skills_open"); _hub!.DevOpen(4); }
if (_devTime > 4.4 && !_shots.Contains("h_skills_open")) { _shots.Add("h_skills_open"); _hub!.DevOpen("skills"); }
if (_devTime > 5.1) Shot("h_skills");
if (_devTime > 5.3 && !_shots.Contains("h_hall_tab")) { _shots.Add("h_hall_tab"); _hub!.DevOpen(5); }
if (_devTime > 5.3 && !_shots.Contains("h_hall_tab")) { _shots.Add("h_hall_tab"); _hub!.DevOpen("hall"); }
if (_devTime > 6.0) Shot("h_hall2");
if (_devTime > 6.2 && !_shots.Contains("h_exp_tab")) { _shots.Add("h_exp_tab"); _hub!.DevOpen(6); }
if (_devTime > 6.2 && !_shots.Contains("h_exp_tab")) { _shots.Add("h_exp_tab"); _hub!.DevOpen("expedition"); }
if (_devTime > 6.9) Shot("h_exp");
if (_devTime > 7.3 && _capture == null) { _hub!.DevOpen(0); var offers = _game!.Offers(); _hub.Chosen = offers[Math.Min(1, offers.Count - 1)]; _devTime = 0; }
if (_devTime > 7.3 && _capture == null) { _hub!.DevOpen("none"); var offers = _game!.Offers(); _hub.Chosen = offers[Math.Min(1, offers.Count - 1)]; _devTime = 0; }
}
else
{
if (_devTime > 0.6) Shot("h_result");
if (_devTime > 0.8 && !_shots.Contains("h_inv_open")) { _shots.Add("h_inv_open"); _hub!.DevOpen(1); }
if (_devTime > 0.8 && !_shots.Contains("h_inv_open")) { _shots.Add("h_inv_open"); _hub!.DevOpen("gladiator"); }
if (_devTime > 1.4) Shot("h_inventory");
if (_devTime > 1.6 && !_shots.Contains("h_pause_open")) { _shots.Add("h_pause_open"); _hub!.DevOpen(0); _paused = true; }
if (_devTime > 1.6 && !_shots.Contains("h_pause_open")) { _shots.Add("h_pause_open"); _hub!.DevOpen("none"); _paused = true; }
if (_devTime > 2.0) Shot("h_pause");
if (_shots.Contains("h_pause") && _capture == null && _devTime > 2.2)
{
@@ -515,6 +587,7 @@ namespace GladiatorIdle
if (Perf) { PerfStep(); return; }
void Shot(string name) { if (_shots.Add(name)) _capture = name; }
if (_scene.InIntro) { if (_devTime > 2.5) Shot("m_champintro"); return; }
if (_scene.Tutorial != DuelScene.TutStep.Off) { Shot("t_" + _scene.Tutorial.ToString().ToLowerInvariant()); }
if (_devTime > 0.5) Shot("m_countdown");
if (d.Time > 0.6) Shot("m_fight");
if (d.Enemy.State == DuelState.Windup && d.Enemy.StateTime > d.Enemy.Windup * 0.6) Shot("m_telegraph");
@@ -545,15 +618,23 @@ namespace GladiatorIdle
static readonly bool Record = Array.IndexOf(Environment.GetCommandLineArgs(), "--record") >= 0;
readonly System.Collections.Generic.List<double> _times = new();
int _gcStart = -1, _duelsStarted;
void PerfStep()
{
if (_devTime > 3) _times.Add(_lastFrameMs);
if (_scene!.Over) { var o = _offer!; EndDuel(); StartDuel(o); }
if (_devTime > 3)
{
if (_gcStart < 0) { _gcStart = GC.CollectionCount(0); _duelDraw = 0; _duelFrames = 0; }
_times.Add(_lastFrameMs);
}
// nach jedem Kampf sofort ein neuer: misst auch den Ruckler beim Duellstart
if (_scene!.Over) { var o = _offer!; EndDuel(); StartDuel(o); _duelsStarted++; }
if (_devTime < 18) return;
_times.Sort();
double avg = 0; foreach (var t in _times) avg += t; avg /= Math.Max(1, _times.Count);
DevShot.Log($"perf {GraphicsDevice.PresentationParameters.BackBufferWidth}x{GraphicsDevice.PresentationParameters.BackBufferHeight}: " +
$"avg {avg:0.0} ms ({1000 / avg:0} fps), p95 {_times[(int)(_times.Count * 0.95)]:0.0} ms, frames {_times.Count}");
$"avg {avg:0.0} ms ({1000 / avg:0} fps), p95 {_times[(int)(_times.Count * 0.95)]:0.0} ms, p99 {_times[(int)(_times.Count * 0.99)]:0.0} ms, " +
$"max {_times[^1]:0.0} ms, draw {_duelDraw / Math.Max(1, _duelFrames):0.00} ms, gc0 {GC.CollectionCount(0) - _gcStart}, " +
$"duels restarted {_duelsStarted}, frames {_times.Count}");
Exit();
}
@@ -571,9 +652,10 @@ namespace GladiatorIdle
if (toTarget && (_rt == null || _rt.Width != w || _rt.Height != h))
{
_rt?.Dispose();
_rt = new RenderTarget2D(gd, w, h, false, SurfaceFormat.Color, DepthFormat.Depth24);
_rt = new RenderTarget2D(gd, w, h, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
}
if (toTarget) gd.SetRenderTarget(_rt);
// Bild entsteht in einer Zwischenfläche (Kantenglättung), danach Nachleuchten
_post.Begin(gd, w, h, AppSettings.AntiAlias);
gd.Clear(Color.Black);
float scale = Math.Min(w / Camera.W, h / Camera.H);
var offset = new Vector2((w - Camera.W * scale) / 2, (h - Camera.H * scale) / 2);
@@ -591,8 +673,21 @@ namespace GladiatorIdle
_hub.Draw(gd, _sb, _fx, scale, offset);
if (_paused && !_settings.Open) DrawPause(_sb, ui);
}
// weicher Wechsel zwischen Bildschirmen: neues Bild kommt kurz aus dem Schwarz
object? now = (object?)_model ?? _freedom ?? (object?)_board ?? _intro ?? (object?)_menu ?? _creator ?? (object?)_scene ?? _hub;
if (!ReferenceEquals(now, _shown)) { _shown = now; _fadeIn = 0; }
_fadeIn = Math.Min(1, _fadeIn + gameTime.ElapsedGameTime.TotalSeconds / 0.3);
if (_fadeIn < 1)
{
_sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, ui);
Gfx.Draw.Rect(_sb, new Gfx.RectangleF(0, 0, Camera.W, Camera.H), Color.Black * (float)(1 - _fadeIn * _fadeIn * (3 - 2 * _fadeIn)));
_sb.End();
}
if (_settings.Open) _settings.Draw(_sb, scale, offset);
bool bloomOn = AppSettings.Bloom && !AppSettings.ReduceMotion && _intro == null;
_post.End(gd, _sb, toTarget ? _rt : null, bloomOn ? 1f : 0f);
if (toTarget)
{
gd.SetRenderTarget(null);