public new void DisposeBillboardBuffers() { if (!MainThreadHelper.IsMainThread && ( (billboardVertices != null && !billboardVertices.IsDisposed) || (billboardIndices != null && !billboardIndices.IsDisposed) )) { // This is a disposal, there's no need to wait for this to be disposed, // let following reset calls realloc even before the olds get disposed. VertexBuffer billboardVerticesOld = billboardVertices; IndexBuffer billboardIndicesOld = billboardIndices; billboardVertices = null; billboardIndices = null; MainThreadHelper.Do(() => { if (billboardVerticesOld != null && !billboardVerticesOld.IsDisposed) { billboardVerticesOld.Dispose(); } if (billboardIndicesOld != null && !billboardIndicesOld.IsDisposed) { billboardIndicesOld.Dispose(); } }); return; } if (billboardVertices != null && !billboardVertices.IsDisposed) { billboardVertices.Dispose(); } if (billboardIndices != null && !billboardIndices.IsDisposed) { billboardIndices.Dispose(); } }
public void Exit() { task = null; Lines.Clear(); MainThreadHelper.Do(() => ((patch_OuiMainMenu)Overworld.GetUI <OuiMainMenu>())?.RebuildMainAndTitle()); Audio.Play(SFX.ui_main_button_back); Overworld.Goto <OuiModOptions>(); }
internal override void Unload() { Texture2D tex = Texture_Unsafe; // Handle already queued loads appropriately. object queuedLoadLock = _Texture_QueuedLoadLock; if (queuedLoadLock != null) { bool gotLock = false; try { Monitor.TryEnter(queuedLoadLock, ref gotLock); if (gotLock) { if (_Texture_QueuedLoadLock != null) { // If we still can, cancel the queued load. _Texture_QueuedLoadLock = null; } } else { // Welp. _Texture_UnloadAfterReload = true; Monitor.TryEnter(queuedLoadLock, ref gotLock); if (gotLock) { // It might be too late - let's unload ourselves. _Texture_UnloadAfterReload = false; } else { // The loader will still handle the request. return; } } } finally { if (gotLock) { Monitor.Exit(queuedLoadLock); } } if (!MainThreadHelper.IsMainThread) { // Otherwise wait for it to get loaded. (Don't wait locked!) while (!_Texture_QueuedLoad.IsValid) { Thread.Yield(); } tex = _Texture_QueuedLoad.GetResult(); } } Texture_Unsafe = null; if (tex == null || tex.IsDisposed) { return; } if (!(CoreModule.Settings.ThreadedGL ?? Everest.Flags.PreferThreadedGL) && !MainThreadHelper.IsMainThread) { MainThreadHelper.Do(() => tex.Dispose()); } else { tex.Dispose(); } }
protected override void addOptionsToMenu(TextMenu menu) { // for now, display a "loading" message. TextMenu.Button loading = new TextMenu.Button(Dialog.Clean("MODOPTIONS_MODTOGGLE_LOADING")) { Disabled = true }; menu.Add(loading); modLoadingTask = new Task(() => { // load all the mod yamls (that can take some time), update the progress every 500ms so that the text doesn't go crazy since it is centered. Stopwatch updateTimer = Stopwatch.StartNew(); modYamls = LoadAllModYamls(progress => { if (updateTimer.ElapsedMilliseconds > 500) { updateTimer.Restart(); loading.Label = $"{Dialog.Clean("MODOPTIONS_MODTOGGLE_LOADING")} ({(int) (progress * 100)}%)"; } }); updateTimer.Stop(); MainThreadHelper.Do(() => { modToggles = new Dictionary <string, TextMenu.OnOff>(); // remove the "loading..." message menu.Remove(loading); // if there is a whitelist, warn the user that it will break those settings. if (Everest.Loader.Whitelist != null) { menu.Add(restartMessage1 = new TextMenuExt.SubHeaderExt(Dialog.Clean("MODOPTIONS_MODTOGGLE_WHITELISTWARN")) { TextColor = Color.OrangeRed }); } // display the warning about blacklist.txt + restarting menu.Add(restartMessage1 = new TextMenuExt.SubHeaderExt(Dialog.Clean("MODOPTIONS_MODTOGGLE_MESSAGE_1"))); menu.Add(restartMessage2 = new TextMenuExt.SubHeaderExt(Dialog.Clean("MODOPTIONS_MODTOGGLE_MESSAGE_2")) { HeightExtra = 0f }); menu.Add(new TextMenuExt.SubHeaderExt(Dialog.Clean("MODOPTIONS_MODTOGGLE_MESSAGE_3")) { HeightExtra = 20f, TextColor = Color.Goldenrod }); // reduce spacing between the whitelist warning and the blacklist overwrite warning if (Everest.Loader.Whitelist != null) { restartMessage1.HeightExtra = 30f; } // "enable all" and "disable all" buttons menu.Add(new TextMenu.Button(Dialog.Clean("MODOPTIONS_MODTOGGLE_ENABLEALL")).Pressed(() => { foreach (TextMenu.OnOff toggle in modToggles.Values) { toggle.Index = 1; } blacklistedMods.Clear(); updateHighlightedMods(); })); menu.Add(new TextMenu.Button(Dialog.Clean("MODOPTIONS_MODTOGGLE_DISABLEALL")).Pressed(() => { blacklistedMods.Clear(); foreach (KeyValuePair <string, TextMenu.OnOff> toggle in modToggles) { toggle.Value.Index = 0; blacklistedMods.Add(toggle.Key); } updateHighlightedMods(); })); // "toggle dependencies automatically" button TextMenu.Item toggleDependenciesButton; menu.Add(toggleDependenciesButton = new TextMenu.OnOff(Dialog.Clean("MODOPTIONS_MODTOGGLE_TOGGLEDEPS"), true) .Change(value => toggleDependencies = value)); toggleDependenciesButton.AddDescription(menu, Dialog.Clean("MODOPTIONS_MODTOGGLE_TOGGLEDEPS_MESSAGE2")); toggleDependenciesButton.AddDescription(menu, Dialog.Clean("MODOPTIONS_MODTOGGLE_TOGGLEDEPS_MESSAGE1")); // "cancel" button to leave the screen without saving menu.Add(new TextMenu.Button(Dialog.Clean("MODOPTIONS_MODTOGGLE_CANCEL")).Pressed(() => { blacklistedMods = blacklistedModsOriginal; onBackPressed(Overworld); })); // reset the mods list allMods = new List <string>(); blacklistedMods = new HashSet <string>(); string[] files; bool headerInserted; // crawl directories files = Directory.GetDirectories(Everest.Loader.PathMods); Array.Sort(files, (a, b) => a.ToLowerInvariant().CompareTo(b.ToLowerInvariant())); headerInserted = false; for (int i = 0; i < files.Length; i++) { string file = Path.GetFileName(files[i]); if (file != "Cache") { if (!headerInserted) { menu.Add(new patch_TextMenu.patch_SubHeader(Dialog.Clean("MODOPTIONS_MODTOGGLE_DIRECTORIES"))); headerInserted = true; } addFileToMenu(menu, file); } } // crawl zips files = Directory.GetFiles(Everest.Loader.PathMods); Array.Sort(files, (a, b) => a.ToLowerInvariant().CompareTo(b.ToLowerInvariant())); headerInserted = false; for (int i = 0; i < files.Length; i++) { string file = Path.GetFileName(files[i]); if (file.EndsWith(".zip")) { if (!headerInserted) { menu.Add(new patch_TextMenu.patch_SubHeader(Dialog.Clean("MODOPTIONS_MODTOGGLE_ZIPS"))); headerInserted = true; } addFileToMenu(menu, file); } } // crawl map bins files = Directory.GetFiles(Everest.Loader.PathMods); Array.Sort(files, (a, b) => a.ToLowerInvariant().CompareTo(b.ToLowerInvariant())); headerInserted = false; for (int i = 0; i < files.Length; i++) { string file = Path.GetFileName(files[i]); if (file.EndsWith(".bin")) { if (!headerInserted) { menu.Add(new patch_TextMenu.patch_SubHeader(Dialog.Clean("MODOPTIONS_MODTOGGLE_BINS"))); headerInserted = true; } addFileToMenu(menu, file); } } // sort the mods list alphabetically, for output in the blacklist.txt file later. allMods.Sort((a, b) => a.ToLowerInvariant().CompareTo(b.ToLowerInvariant())); // adjust the mods' color if they are required dependencies for other mods foreach (KeyValuePair <string, TextMenu.OnOff> toggle in modToggles) { if (modHasDependencies(toggle.Key)) { ((patch_TextMenu.patch_Option <bool>)(object) toggle.Value).UnselectedColor = Color.Goldenrod; } } // snap the menu so that it doesn't show a scroll up. menu.Y = menu.ScrollTargetY; // clone the list to be able to check if the list changed when leaving the menu. blacklistedModsOriginal = new HashSet <string>(blacklistedMods); // loading is done! modLoadingTask = null; }); }); modLoadingTask.Start(); }
public void ctor(Session session, Vector2?startPosition = default(Vector2?)) { if (LastLoadingThread != null && LastLoadingThread.TryGetTarget(out Thread lastThread) && (lastThread?.IsAlive ?? false)) { lastThread?.Abort(); } if (CoreModule.Settings.LazyLoading) { MainThreadHelper.Do(() => VirtualContentExt.UnloadOverworld()); } // Vanilla TileToIndex mappings. SurfaceIndex.TileToIndex = new Dictionary <char, int> { { '1', 3 }, { '3', 4 }, { '4', 7 }, { '5', 8 }, { '6', 8 }, { '7', 8 }, { '8', 8 }, { '9', 13 }, { 'a', 8 }, { 'b', 23 }, { 'c', 8 }, { 'd', 8 }, { 'e', 8 }, { 'f', 8 }, { 'g', 8 }, { 'G', 8 }, // Reflection alt - unassigned in vanilla. { 'h', 33 }, { 'i', 4 }, { 'j', 8 }, { 'k', 3 }, { 'l', 25 }, { 'm', 44 }, { 'n', 40 }, { 'o', 43 } }; AreaData area = AreaData.Get(session); MapMeta meta = area.GetMeta(); string path; path = meta?.BackgroundTiles; if (string.IsNullOrEmpty(path)) { path = Path.Combine("Graphics", "BackgroundTiles.xml"); } GFX.BGAutotiler = new Autotiler(path); path = meta?.ForegroundTiles; if (string.IsNullOrEmpty(path)) { path = Path.Combine("Graphics", "ForegroundTiles.xml"); } GFX.FGAutotiler = new Autotiler(path); path = meta?.AnimatedTiles; if (string.IsNullOrEmpty(path)) { path = Path.Combine("Graphics", "AnimatedTiles.xml"); } GFX.AnimatedTilesBank = new AnimatedTilesBank(); XmlElement animatedData = Calc.LoadContentXML(path)["Data"]; foreach (XmlElement el in animatedData) { if (el != null) { GFX.AnimatedTilesBank.Add( el.Attr("name"), el.AttrFloat("delay", 0f), el.AttrVector2("posX", "posY", Vector2.Zero), el.AttrVector2("origX", "origY", Vector2.Zero), GFX.Game.GetAtlasSubtextures(el.Attr("path")) ); } } GFX.SpriteBank = new SpriteBank(GFX.Game, Path.Combine("Graphics", "Sprites.xml")); path = meta?.Sprites; if (!string.IsNullOrEmpty(path)) { SpriteBank bankOrig = GFX.SpriteBank; SpriteBank bankMod = new SpriteBank(GFX.Game, path); foreach (KeyValuePair <string, SpriteData> kvpBank in bankMod.SpriteData) { string key = kvpBank.Key; SpriteData valueMod = kvpBank.Value; if (bankOrig.SpriteData.TryGetValue(key, out SpriteData valueOrig)) { IDictionary animsOrig = valueOrig.Sprite.GetAnimations(); IDictionary animsMod = valueMod.Sprite.GetAnimations(); foreach (DictionaryEntry kvpAnim in animsMod) { animsOrig[kvpAnim.Key] = kvpAnim.Value; } valueOrig.Sources.AddRange(valueMod.Sources); // replay the starting animation to be sure it is referring to the new sprite. valueOrig.Sprite.Stop(); if (valueMod.Sprite.CurrentAnimationID != "") { valueOrig.Sprite.Play(valueMod.Sprite.CurrentAnimationID); } } else { bankOrig.SpriteData[key] = valueMod; } } } // This is done exactly once in the vanilla GFX.LoadData method. PlayerSprite.ClearFramesMetadata(); PlayerSprite.CreateFramesMetadata("player"); PlayerSprite.CreateFramesMetadata("player_no_backpack"); PlayerSprite.CreateFramesMetadata("badeline"); PlayerSprite.CreateFramesMetadata("player_badeline"); PlayerSprite.CreateFramesMetadata("player_playback"); path = meta?.Portraits; if (string.IsNullOrEmpty(path)) { path = Path.Combine("Graphics", "Portraits.xml"); } GFX.PortraitsSpriteBank = new SpriteBank(GFX.Portraits, path); orig_ctor(session, startPosition); LastLoadingThread = patch_RunThread.Current; }
public void ctor(Session session, Vector2?startPosition = default(Vector2?)) { if (CoreModule.Settings.LazyLoading) { MainThreadHelper.Do(() => VirtualContentExt.UnloadOverworld()); } // Vanilla TileToIndex mappings. SurfaceIndex.TileToIndex = new Dictionary <char, int> { { '1', 3 }, { '3', 4 }, { '4', 7 }, { '5', 8 }, { '6', 8 }, { '7', 8 }, { '8', 8 }, { '9', 13 }, { 'a', 8 }, { 'b', 23 }, { 'c', 8 }, { 'd', 8 }, { 'e', 8 }, { 'f', 8 }, { 'g', 8 }, { 'h', 33 }, { 'i', 4 }, { 'j', 8 }, { 'k', 3 }, { 'l', 25 }, { 'm', 44 }, { 'n', 40 }, { 'o', 43 } }; AreaData area = AreaData.Get(session); MapMeta meta = area.GetMeta(); string path; path = meta?.BackgroundTiles; if (string.IsNullOrEmpty(path)) { path = Path.Combine("Graphics", "BackgroundTiles.xml"); } GFX.BGAutotiler = new Autotiler(path); path = meta?.ForegroundTiles; if (string.IsNullOrEmpty(path)) { path = Path.Combine("Graphics", "ForegroundTiles.xml"); } GFX.FGAutotiler = new Autotiler(path); path = meta?.AnimatedTiles; if (string.IsNullOrEmpty(path)) { path = Path.Combine("Graphics", "AnimatedTiles.xml"); } GFX.AnimatedTilesBank = new AnimatedTilesBank(); XmlElement animatedData = Calc.LoadContentXML(path)["Data"]; foreach (XmlElement el in animatedData) { if (el != null) { GFX.AnimatedTilesBank.Add( el.Attr("name"), el.AttrFloat("delay", 0f), el.AttrVector2("posX", "posY", Vector2.Zero), el.AttrVector2("origX", "origY", Vector2.Zero), GFX.Game.GetAtlasSubtextures(el.Attr("path")) ); } } GFX.SpriteBank = new SpriteBank(GFX.Game, Path.Combine("Graphics", "Sprites.xml")); path = meta?.Sprites; if (!string.IsNullOrEmpty(path)) { SpriteBank bankOrig = GFX.SpriteBank; SpriteBank bankMod = new SpriteBank(GFX.Game, path); foreach (KeyValuePair <string, SpriteData> kvpBank in bankMod.SpriteData) { string key = kvpBank.Key; SpriteData valueMod = kvpBank.Value; if (bankOrig.SpriteData.TryGetValue(key, out SpriteData valueOrig)) { IDictionary animsOrig = valueOrig.Sprite.GetAnimations(); IDictionary animsMod = valueMod.Sprite.GetAnimations(); foreach (DictionaryEntry kvpAnim in animsMod) { animsOrig[kvpAnim.Key] = kvpAnim.Value; } } else { bankOrig.SpriteData[key] = valueMod; } } } path = meta?.Portraits; if (string.IsNullOrEmpty(path)) { path = Path.Combine("Graphics", "Portraits.xml"); } GFX.PortraitsSpriteBank = new SpriteBank(GFX.Portraits, path); orig_ctor(session, startPosition); }