diff --git a/.github/workflows/nexjast-ci.yml b/.github/workflows/nexjast-ci.yml index 10a76730..46ff03a3 100644 --- a/.github/workflows/nexjast-ci.yml +++ b/.github/workflows/nexjast-ci.yml @@ -831,6 +831,14 @@ jobs: shell: bash run: python3 tools/ci/verify_gen1_hg_asset_egress_lockdown.py + - name: Regression-test dynamic texture retirement handoff + shell: bash + run: | + set -euo pipefail + python3 tools/ci/verify_gen1_dynamic_texture_refresh.py + dotnet run --project tools/ci/OglDynamicTextureRetentionRegression/OglDynamicTextureRetentionRegression.csproj --configuration Release + + - name: Verify Generation 1 approved-viewer admission policy shell: bash run: | diff --git a/OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj b/OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj index 5f436b02..85976371 100644 --- a/OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj +++ b/OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj @@ -476,6 +476,7 @@ Code + Code diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index b552186e..102c15a3 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs @@ -45,7 +45,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DynamicTextureModule")] public class DynamicTextureModule : ISharedRegionModule, IDynamicTextureManager { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(typeof(DynamicTextureModule)); private const int ALL_SIDES = -1; @@ -84,6 +84,20 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture /// private Cache m_reuseableDynamicTextures; + // Optional generation-1 handoff window: temporary superseded assets + // remain fetchable long enough for delayed viewer/cache requests. + private DynamicTextureRetirementQueue m_RetiredTextureQueue; + private System.Threading.Timer m_RetirementTimer; + + private void RetirePreviousTexture(IAssetCache cache, UUID oldId) + { + DynamicTextureRetirementQueue queue = m_RetiredTextureQueue; + if (queue == null) + cache.Expire(oldId.ToString()); + else + queue.Retire(() => cache.Expire(oldId.ToString())); + } + /// /// This constructor is only here because of the Unit Tests... /// Don't use it. @@ -188,6 +202,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture if (RenderPlugins.ContainsKey(contentType)) { DynamicTextureUpdater updater = new DynamicTextureUpdater(); + updater.RetirePreviousTexture = RetirePreviousTexture; updater.SimUUID = simID; updater.PrimID = primID; updater.ContentType = contentType; @@ -250,6 +265,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture disp = disp & ~DISP_EXPIRE; DynamicTextureUpdater updater = new DynamicTextureUpdater(); + updater.RetirePreviousTexture = RetirePreviousTexture; updater.SimUUID = simID; updater.PrimID = primID; updater.ContentType = contentType; @@ -337,6 +353,21 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture IConfig texturesConfig = config.Configs["Textures"]; if (texturesConfig != null) { + int retentionSeconds = Math.Clamp( + texturesConfig.GetInt("DynamicTexturePreviousRetentionSeconds", 0), 0, 120); + int retentionCapacity = Math.Clamp( + texturesConfig.GetInt("DynamicTexturePreviousRetentionLimit", 256), 1, 2048); + if (retentionSeconds > 0) + { + m_RetiredTextureQueue = new DynamicTextureRetirementQueue( + retentionSeconds, retentionCapacity, + onError: e => m_log.WarnFormat( + "[DYNAMIC TEXTURE MODULE]: Deferred expiration failed: {0}", e)); + m_RetirementTimer = new System.Threading.Timer( + _ => m_RetiredTextureQueue?.ExpireDue(), null, + TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5)); + } + ReuseTextures = texturesConfig.GetBoolean("ReuseDynamicTextures", false); ReuseLowDataTextures = texturesConfig.GetBoolean("ReuseDynamicLowDataTextures", false); @@ -373,6 +404,11 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture public void Close() { + m_RetirementTimer?.Dispose(); + m_RetirementTimer = null; + DynamicTextureRetirementQueue pending = m_RetiredTextureQueue; + m_RetiredTextureQueue = null; + pending?.Flush(); } public string Name @@ -405,6 +441,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture public int Disp; public string Url; public UUID newTextureID; + public Action RetirePreviousTexture; public DynamicTextureUpdater() { @@ -479,10 +516,16 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture if (part == null || data == null || data.Length <= 1) { - string msg = string.Format("DynamicTextureModule: Error preparing image using URL {0}", Url); - scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say, - 0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false); - + // A removed prim is a normal outcome of asynchronous URL rendering. + // Never dereference it while reporting a failed conversion. + if (part != null) + { + string msg = string.Format( + "DynamicTextureModule: Error preparing image using URL {0}", Url); + scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say, + 0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, + part.UUID, false); + } return UUID.Zero; } @@ -546,7 +589,12 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture if (oldAsset != null) { if (oldAsset.Temporary) - iac.Expire(oldID.ToString()); + { + if (RetirePreviousTexture != null) + RetirePreviousTexture(iac, oldID); + else + iac.Expire(oldID.ToString()); + } } } diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureRetirementQueue.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureRetirementQueue.cs new file mode 100644 index 00000000..d68d8245 --- /dev/null +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureRetirementQueue.cs @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: MPL-2.0 +using System; +using System.Collections.Generic; + +namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture +{ + /// + /// Keeps a limited number of superseded dynamic assets available briefly so + /// an in-flight viewer texture request cannot immediately lose its old UUID. + /// This does not guarantee that the viewer retains the old image on a new + /// texture UUID; it only protects the server cache handoff. + /// + internal sealed class DynamicTextureRetirementQueue + { + private readonly object m_Sync = new object(); + private readonly Queue m_Queue = new Queue(); + private readonly TimeSpan m_Retention; + private readonly int m_MaxPending; + private readonly Func m_UtcNow; + private readonly Action m_OnError; + + private sealed class RetiredAsset + { + public DateTime Expiry; + public Action Expire; + } + + public DynamicTextureRetirementQueue(int seconds, int maxPending, + Func utcNow = null, Action onError = null) + { + m_Retention = TimeSpan.FromSeconds(Math.Clamp(seconds, 0, 120)); + m_MaxPending = Math.Clamp(maxPending, 1, 2048); + m_UtcNow = utcNow ?? (() => DateTime.UtcNow); + m_OnError = onError; + } + + public int PendingCount + { + get { lock (m_Sync) return m_Queue.Count; } + } + + public void Retire(Action expire) + { + if (expire == null) + return; + + List due = new List(); + lock (m_Sync) + { + DateTime now = m_UtcNow(); + CollectDue(now, false, due); + if (m_Retention == TimeSpan.Zero) + due.Add(expire); + else + { + // The queue is bounded: when overloaded, age out the oldest + // superseded asset rather than retaining unlimited texture data. + if (m_Queue.Count >= m_MaxPending) + due.Add(m_Queue.Dequeue().Expire); + m_Queue.Enqueue(new RetiredAsset + { + Expiry = now + m_Retention, + Expire = expire + }); + } + } + Execute(due); + } + + public void ExpireDue() + { + List due = new List(); + lock (m_Sync) + CollectDue(m_UtcNow(), false, due); + Execute(due); + } + + public void Flush() + { + List due = new List(); + lock (m_Sync) + CollectDue(m_UtcNow(), true, due); + Execute(due); + } + + private void CollectDue(DateTime now, bool all, List due) + { + while (m_Queue.Count > 0 && + (all || m_Queue.Peek().Expiry <= now)) + due.Add(m_Queue.Dequeue().Expire); + } + + private void Execute(List callbacks) + { + // Never run potentially blocking cache expiration under m_Sync. + foreach (Action callback in callbacks) + { + try { callback(); } + catch (Exception error) { m_OnError?.Invoke(error); } + } + } + } +} diff --git a/bin/OpenSim.ini b/bin/OpenSim.ini index c035ac1a..c015301d 100644 --- a/bin/OpenSim.ini +++ b/bin/OpenSim.ini @@ -267,6 +267,13 @@ [FirestormBridge] Enabled = true +[Textures] + ; Generation 1: retain superseded dynamic textures briefly so viewer + ; requests for the previous image do not hit an immediately expired asset. + ; Bounds protect against a high number of minute-by-minute display updates. + DynamicTexturePreviousRetentionSeconds = 30 + DynamicTexturePreviousRetentionLimit = 256 + [Appearance] PersistBakedTextures = true ReuseTextures = true diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index c26ebd60..fbaa594b 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -265,6 +265,13 @@ [FirestormBridge] Enabled = true +[Textures] + ; Generation 1: retain superseded dynamic textures briefly so viewer + ; requests for the previous image do not hit an immediately expired asset. + ; Bounds protect against a high number of minute-by-minute display updates. + DynamicTexturePreviousRetentionSeconds = 30 + DynamicTexturePreviousRetentionLimit = 256 + [Appearance] PersistBakedTextures = true ReuseTextures = true diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index 555865d1..a1643587 100644 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini @@ -1117,6 +1117,13 @@ ; This setting only has an affect is ReuseDynamicTextures = true ; Default is false ReuseDynamicLowDataTextures = false + ; Generation 1 opt-in: keep superseded temporary dynamic textures in + ; cache briefly after a new texture ID is applied to a prim face. + ; This helps in-flight viewer requests, but cannot guarantee flash-free + ; transitions when a viewer must fetch an entirely new texture UUID. + ; 0 = legacy immediate expiry, max 120 seconds. Set a bounded limit. + DynamicTexturePreviousRetentionSeconds = 0 + DynamicTexturePreviousRetentionLimit = 256 [ODEPhysicsSettings] ; ## diff --git a/doc/NexVerse/GEN1_DYNAMIC_TEXTURE_SMOOTH_REFRESH.md b/doc/NexVerse/GEN1_DYNAMIC_TEXTURE_SMOOTH_REFRESH.md new file mode 100644 index 00000000..b6690046 --- /dev/null +++ b/doc/NexVerse/GEN1_DYNAMIC_TEXTURE_SMOOTH_REFRESH.md @@ -0,0 +1,48 @@ +# Generation 1 – Flüssigere Aktualisierung dynamischer Texturen + +## Problem + +`osSetDynamicTextureDataFace("", "vector", ...)` berechnet eine **neue Asset-UUID** bei jeder Minute der Stadt-NexVerse-Bus-Anzeigetafel. Die neue Grafik wird zuerst als lokales/temporäres Asset gecacht und anschließend der Textur-Slot des Prims aktualisiert. Der bisherige `DISP_EXPIRE`-Pfad löschte das vorherige temporäre Asset unmittelbar aus dem lokalen Asset-Cache. Das kann ausstehende Viewer-Requests auf die bisherige UUID ins Leere laufen lassen, während neue Daten noch übertragen werden. + +Die Generierung der neuen Grafik und das Prim-Update waren bereits in der richtigen Reihenfolge. Eine vom **Viewer sichtbare** vollständig atomare Übergabe zwischen zwei unterschiedlichen Texture-UUIDs ist über das bestehende LSL/OSSL-Protokoll hingegen nicht garantiert. + +## Implementierung + +Der DynamicTextureModule-Pfad behält die **vorherige temporäre Textur** bei aktiviertem `DISP_EXPIRE` optional für eine begrenzte Übergangszeit im Cache: + +```ini +[Textures] + DynamicTexturePreviousRetentionSeconds = 30 + DynamicTexturePreviousRetentionLimit = 256 +``` + +- Standardprofil `OpenSimDefaults.ini`: `RetentionSeconds = 0` (bisheriges Verhalten). +- Stadt-NexVerse-Aktivprofile und `OpenSim.ini.example`: 30 Sekunden, höchstens 256 noch nicht abgelaufene Asset-Referenzen pro Simulatorprozess. +- Wertebereiche: 0–120 Sekunden, 1–2048 zeitgleich anstehende alte Assets. +- Der neue `DynamicTextureRetirementQueue` erledigt die teure Cache-Expiration **außerhalb des Queue-Locks**. Ein Timer prüft alle fünf Sekunden. +- Wird die Anzahlgrenze erreicht, wird die älteste gespeicherte Textur vorzeitig freigegeben, damit Speicherverbrauch nicht grenzenlos wächst. +- Beim Schließen des Moduls wird die Queue geleert und der Timer gestoppt. +- Ist `ReuseDynamicTextures = true`, bleibt die bestehende eigene Reuse-Logik erhalten (sie deaktiviert bereits `DISP_EXPIRE`). Die neue Retention soll die normale, nicht wiederverwendbare Minutengrafik unterstützen. +- Das Löschen eines Prims während eines asynchronen URL-Renders erzeugt beim Fehlerbericht keine NullReferenceException mehr. + +Die neue Übergangsfrist gilt für Texturen, die tatsächlich per `DISP_EXPIRE` ersetzt werden und deren altes Asset als `Temporary` markiert ist. Andere Texturen, Berechtigungen, Viewer-CAPS und normale Asset-Routen werden nicht verändert. + +## Beispiel-Skript + +`tools/diagnostics/ogl_bus_departure_board_smooth.lsl` verwendet die vorhandene Stadt-NexVerse-Bustafel mit 1024×512-Vektorgrafik. Das Skript lässt die alte Face-Textur stehen und verhindert identische Neu-Renderings innerhalb derselben Minute und bei gleichem Vektor-Bildinhalt. `llMD5String` prüft, ob die Bildanweisungen tatsächlich geändert wurden. + +Der Timer prüft weiterhin alle 10 Sekunden und rechnet die nächsten Abfahrten jede volle Minute neu aus. Die deutsche Winter-/Sommerzeit muss in diesem Beispiel wie bisher über `UTC_OFFSET = 1/2` eingestellt werden. + +## Was diese Änderung **nicht** leistet + +**Keine 100-%-flackerfreie Umschaltung:** Der Firestorm-/OpenGenesisLINK-Viewer entscheidet selbst, wann er die **neue** Texture-UUID herunterlädt und auf die GPU bringt. Er kann bis dahin eine graue/weiße Platzhalterfläche zeigen, auch wenn die vorherige UUID serverseitig noch gültig ist. Die Serveränderung verhindert nur eine Ursache für verlorene alte Texture-Fetches. Für einen garantierten sichtbaren Bildwechsel benötigt man eine zusätzliche Viewer-Unterstützung (Swap nach bestätigtem Cache-Prefetch) oder einen geeigneten zweilagigen primseitigen Anzeigeaufbau mit vorgepufferter Textur. + +Die Retention vergrößert den temporären Asset-Cache und kann bei großer Last begrenzt werden. Deshalb ist die Funktion im generischen Default deaktiviert und im Stadt-NexVerse-Profil auf 30 Sekunden / 256 Referenzen begrenzt. + +## Tests + +- Deterministische Runtime-Regression der Queue: Grace-Period, Grenzfall, FIFO-Overflow, Immediate-Expire, Flush und Fehlerisolation. +- CI überprüft Parameter, Cache-vor-Prim-Reihenfolge, nur temporäre Expiration und bestehende OSSL-API. +- Auf echter Region prüfen: ein einzelner 1024×512-Anzeigetafel-Prim, anschließend viele parallel. Alle 60 Sekunden muss die Abfahrtstafel aktualisieren, ohne dass die vorige Textur sofort aus dem Cache verschwindet. +- Firestorm und OpenGenesisLINK Viewer separat beobachten: sichtbares Weiß-Flackern ist ein clientseitiger Abnahmetest und **nicht** durch die CI nachgewiesen. +- Nach Simulatorneustart dynamische Texte neu erzeugen; rein lokale Cache-Assets überleben den Neustart nicht dauerhaft. diff --git a/tools/ci/OglDynamicTextureRetentionRegression/OglDynamicTextureRetentionRegression.csproj b/tools/ci/OglDynamicTextureRetentionRegression/OglDynamicTextureRetentionRegression.csproj new file mode 100644 index 00000000..f02f365d --- /dev/null +++ b/tools/ci/OglDynamicTextureRetentionRegression/OglDynamicTextureRetentionRegression.csproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + disable + disable + + + + + diff --git a/tools/ci/OglDynamicTextureRetentionRegression/Program.cs b/tools/ci/OglDynamicTextureRetentionRegression/Program.cs new file mode 100644 index 00000000..5e9f5294 --- /dev/null +++ b/tools/ci/OglDynamicTextureRetentionRegression/Program.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using OpenSim.Region.CoreModules.Scripting.DynamicTexture; + +internal static class Program +{ + private static int checks; + + private static void Check(bool success, string reason) + { + checks++; + if (!success) + throw new InvalidOperationException("Dynamic texture retention: " + reason); + } + + private static void Main() + { + DateTime now = new DateTime(2026, 10, 28, 12, 0, 0, DateTimeKind.Utc); + List expired = new List(); + List errors = new List(); + + DynamicTextureRetirementQueue queue = new DynamicTextureRetirementQueue( + 30, 2, () => now, errors.Add); + + queue.Retire(() => expired.Add("A")); + Check(queue.PendingCount == 1 && expired.Count == 0, "first asset retained"); + now = now.AddSeconds(10); + queue.Retire(() => expired.Add("B")); + now = now.AddSeconds(10); + queue.Retire(() => expired.Add("C")); // bounded eviction of oldest A + Check(queue.PendingCount == 2, "queue capped at two"); + Check(expired.Count == 1 && expired[0] == "A", "oldest freed on overflow"); + now = now.AddSeconds(19); + queue.ExpireDue(); + Check(expired.Count == 1, "old B not expired before deadline"); + now = now.AddSeconds(1); + queue.ExpireDue(); + Check(expired.Count == 2 && expired[1] == "B", "B expired at deadline"); + now = now.AddSeconds(10); + queue.ExpireDue(); + Check(expired.Count == 3 && expired[2] == "C", "C expired at deadline"); + Check(queue.PendingCount == 0, "queue drained"); + + DynamicTextureRetirementQueue noGrace = + new DynamicTextureRetirementQueue(0, 2, () => now, errors.Add); + noGrace.Retire(() => expired.Add("D")); + Check(expired.Count == 4 && expired[3] == "D", "legacy immediate expiry"); + + DynamicTextureRetirementQueue draining = + new DynamicTextureRetirementQueue(120, 2, () => now, errors.Add); + draining.Retire(() => expired.Add("E")); + draining.Flush(); + Check(expired.Count == 5 && expired[4] == "E", "shutdown flushes pending assets"); + + DynamicTextureRetirementQueue resilient = + new DynamicTextureRetirementQueue(0, 1, () => now, errors.Add); + resilient.Retire(() => throw new InvalidOperationException("fake cache failure")); + resilient.Retire(() => expired.Add("F")); + Check(errors.Count == 1, "cache expiration exception reported"); + Check(expired.Count == 6 && expired[5] == "F", "subsequent callbacks remain usable"); + + Console.WriteLine("OGL dynamic texture retirement: PASS (" + checks + " checks)"); + } +} diff --git a/tools/ci/verify_gen1_dynamic_texture_refresh.py b/tools/ci/verify_gen1_dynamic_texture_refresh.py new file mode 100644 index 00000000..25fe012a --- /dev/null +++ b/tools/ci/verify_gen1_dynamic_texture_refresh.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +"""Guard smooth dynamic-texture refresh while preserving existing OSSL API and render path.""" +from pathlib import Path +root = Path(__file__).resolve().parents[2] +def read(p): + return (root / p).read_text(encoding="utf-8-sig") + +module = read("OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs") +retired = read("OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureRetirementQueue.cs") +proj = read("OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj") +defaults = read("bin/OpenSimDefaults.ini") +script_api = read("OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs") +ci = read(".github/workflows/nexjast-ci.yml") + +for marker in ( + '"DynamicTexturePreviousRetentionSeconds", 0', + '"DynamicTexturePreviousRetentionLimit", 256', + 'updater.RetirePreviousTexture = RetirePreviousTexture;', + 'RetirePreviousTexture(iac, oldID);', + 'm_RetirementTimer = new System.Threading.Timer(', + 'm_RetiredTextureQueue?.ExpireDue()', + 'pending?.Flush();', + 'iac.Cache(asset);', + 'UUID oldID = UpdatePart(part, asset.FullID);', + 'if (oldAsset.Temporary)', +): + assert marker in module, "missing handoff guard: " + marker +assert module.index('iac.Cache(asset);') < module.index('UUID oldID = UpdatePart(part, asset.FullID);') + +for marker in ( + 'Queue', + 'm_MaxPending', + 'DateTime.UtcNow', + 'CollectDue(now, false, due)', + 'm_Queue.Count >= m_MaxPending', + 'm_Queue.Dequeue()', + 'public void Flush()', +): + assert marker in retired, "missing bounded queue guard: " + marker + +assert 'Scripting\\DynamicTexture\\DynamicTextureRetirementQueue.cs' in proj +assert 'DynamicTexturePreviousRetentionSeconds = 0' in defaults +for config in ("bin/OpenSim.ini", "bin/OpenSim.ini.example"): + body = read(config) + assert 'DynamicTexturePreviousRetentionSeconds = 30' in body + assert 'DynamicTexturePreviousRetentionLimit = 256' in body + +assert 'public string osSetDynamicTextureDataFace(' in script_api +assert 'false, 3, 255, face' in script_api, "legacy OSSL API flags must remain unchanged" +assert "Regression-test dynamic texture retirement handoff" in ci +print("Generation 1 dynamic textures: bounded old-asset retention + legacy render path OK") diff --git a/tools/diagnostics/ogl_bus_departure_board_smooth.lsl b/tools/diagnostics/ogl_bus_departure_board_smooth.lsl new file mode 100644 index 00000000..b0a0f48e --- /dev/null +++ b/tools/diagnostics/ogl_bus_departure_board_smooth.lsl @@ -0,0 +1,203 @@ +// STADT NEXVERSE – BUS ABFAHRTSTAFEL (smooth-refresh edition) +// OpenGenesisLINK Generation 1, osSetDynamicTextureDataFace +// Installieren: [Textures] DynamicTexturePreviousRetentionSeconds = 30 +// Die alte Anzeige bleibt auf dem Prim, bis der Renderer die neue liefert. +// Der Viewer lädt neue UUIDs dennoch asynchron; 100 % flackerfrei ist +// ohne eine viewer-seitige Umschaltbestätigung nicht garantiert. + +integer DISPLAY_FACE = 3; +integer UTC_OFFSET = 1; // Im Sommer manuell auf 2 stellen. + +list ROUTEN = [ + "101", "Magdeburg", 10, 0, + "120", "Hamburg", 20, 5, + "130", "Freiburg Sued", 15, 10, + "140", "Gummybear Island",30, 12, + "150", "Jenseits", 20, 15 +]; + +integer lastMinute = -1; +string lastDrawHash = ""; + +string zwei(integer n) +{ + if (n < 10) return "0" + (string)n; + return (string)n; +} + +string formatTime(integer minutes) +{ + minutes = (minutes + 1440) % 1440; + return zwei(minutes / 60) + ":" + zwei(minutes % 60); +} + +list berechneAbfahrten() +{ + integer localMinute = ((llGetUnixTime() / 60) + UTC_OFFSET * 60) % 1440; + list abfahrten = []; + + integer i; + for (i = 0; i < llGetListLength(ROUTEN); i += 4) + { + string linie = llList2String(ROUTEN, i); + string ziel = llList2String(ROUTEN, i + 1); + integer takt = llList2Integer(ROUTEN, i + 2); + integer start = llList2Integer(ROUTEN, i + 3); + + if (takt > 0) + { + integer rest = (localMinute - start + 1440) % takt; + integer warten = (takt - rest) % takt; + integer abfahrt = (localMinute + warten) % 1440; + + abfahrten += [warten, linie, ziel, abfahrt]; + } + } + return llListSort(abfahrten, 4, TRUE); +} + +anzeigeAktualisieren() +{ + integer minute = llGetUnixTime() / 60; + + // Gleiche Minute? Dann keine neue UUID generieren – auch bei Touch. + if (minute == lastMinute) return; + + list daten = berechneAbfahrten(); + string d = ""; + + d = osSetPenColor(d, "black"); + d = osMovePen(d, 0, 0); + d = osDrawFilledRectangle(d, 1024, 512); + d = osSetFontName(d, "Arial"); + + d = osSetPenColor(d, "yellow"); + d = osSetFontSize(d, 39); + d = osMovePen(d, 35, 20); + d = osDrawText(d, "STADT NEXVERSE"); + + d = osSetPenColor(d, "white"); + d = osSetFontSize(d, 21); + d = osMovePen(d, 38, 76); + d = osDrawText(d, "BUS ABFAHRTEN | " + llGetRegionName()); + + d = osSetPenColor(d, "yellow"); + d = osSetFontSize(d, 23); + d = osMovePen(d, 42, 122); + d = osDrawText(d, "LINIE"); + d = osMovePen(d, 190, 122); + d = osDrawText(d, "ZIELREGION"); + d = osMovePen(d, 700, 122); + d = osDrawText(d, "ZEIT"); + d = osMovePen(d, 866, 122); + d = osDrawText(d, "IN"); + + d = osSetPenColor(d, "gray"); + d = osMovePen(d, 30, 155); + d = osDrawFilledRectangle(d, 964, 2); + + integer i; + integer zeilen = llGetListLength(daten) / 4; + if (zeilen > 5) zeilen = 5; + + for (i = 0; i < zeilen; ++i) + { + integer index = i * 4; + integer warten = llList2Integer(daten, index); + string linie = llList2String(daten, index + 1); + string ziel = llList2String(daten, index + 2); + integer abfahrt = llList2Integer(daten, index + 3); + integer y = 166 + i * 60; + + d = osSetPenColor(d, "yellow"); + d = osMovePen(d, 36, y); + d = osDrawFilledRectangle(d, 110, 45); + + d = osSetPenColor(d, "black"); + d = osSetFontSize(d, 28); + d = osMovePen(d, 49, y + 6); + d = osDrawText(d, linie); + + d = osSetPenColor(d, "white"); + d = osSetFontSize(d, 29); + d = osMovePen(d, 190, y + 7); + d = osDrawText(d, ziel); + + d = osSetPenColor(d, "white"); + d = osSetFontSize(d, 27); + d = osMovePen(d, 704, y + 9); + d = osDrawText(d, formatTime(abfahrt)); + + if (warten == 0) + { + d = osSetPenColor(d, "lime"); + d = osSetFontSize(d, 27); + d = osMovePen(d, 858, y + 9); + d = osDrawText(d, "JETZT"); + } + else + { + d = osSetPenColor(d, "yellow"); + d = osSetFontSize(d, 27); + d = osMovePen(d, 860, y + 9); + d = osDrawText(d, (string)warten + " Min"); + } + + if (i < zeilen - 1) + { + d = osSetPenColor(d, "gray"); + d = osMovePen(d, 36, y + 53); + d = osDrawFilledRectangle(d, 950, 1); + } + } + + d = osSetPenColor(d, "gray"); + d = osSetFontSize(d, 17); + d = osMovePen(d, 38, 481); + d = osDrawText(d, "STADT NEXVERSE VERKEHRSSYSTEM"); + + // Gleicher Bildinhalt? Keine neue Asset-ID und kein Viewer-Reload. + string nextHash = llMD5String(d, 0); + if (nextHash != lastDrawHash) + { + osSetDynamicTextureDataFace( + "", + "vector", + d, + "width:1024,height:512,alpha:255,bgcolour:black", + 0, + DISPLAY_FACE + ); + lastDrawHash = nextHash; + } + lastMinute = minute; +} + +default +{ + state_entry() + { + // Absichtlich kein llSetTexture/llSetColor: alte Anzeige nicht leeren. + llSetLinkPrimitiveParamsFast(LINK_THIS, + [PRIM_FULLBRIGHT, DISPLAY_FACE, TRUE]); + + anzeigeAktualisieren(); + llSetTimerEvent(10.0); + } + + timer() + { + anzeigeAktualisieren(); + } + + touch_start(integer total_number) + { + if (llDetectedKey(0) == llGetOwner()) + anzeigeAktualisieren(); + } + + on_rez(integer start_param) + { + llResetScript(); + } +}