|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics; |
| 4 | +using LudeonTK; |
4 | 5 | using Multiplayer.Client.Networking; |
5 | 6 | using Multiplayer.Client.Util; |
6 | 7 | using Multiplayer.Client.Windows; |
@@ -128,6 +129,14 @@ public static class SteamImages |
128 | 129 | { |
129 | 130 | private static readonly Dictionary<int, Texture2D> Cache = new(); |
130 | 131 |
|
| 132 | + [DebugAction(category = MpDebugActions.MultiplayerCategory, name = "Clear image cache", |
| 133 | + allowedGameStates = AllowedGameStates.Entry)] |
| 134 | + private static void ClearCache() |
| 135 | + { |
| 136 | + foreach (var tex in Cache.Values) UnityEngine.Object.Destroy(tex); |
| 137 | + Cache.Clear(); |
| 138 | + } |
| 139 | + |
131 | 140 | public static Texture2D GetTexture(int id, bool force = false) |
132 | 141 | { |
133 | 142 | if (Cache.TryGetValue(id, out Texture2D tex) && !force) |
@@ -162,16 +171,14 @@ public static Texture2D GetTexture(int id, bool force = false) |
162 | 171 | private static void FlipVertically(Texture2D tex) |
163 | 172 | { |
164 | 173 | var pixels = tex.GetPixels32(); |
| 174 | + var buf = new Color32[tex.width]; |
165 | 175 |
|
166 | 176 | for (int y = 0; y < tex.height / 2; y++) |
167 | 177 | { |
168 | | - for (int x = 0; x < tex.width; x++) |
169 | | - { |
170 | | - int top = y * tex.width + x; |
171 | | - int bottom = (tex.height - y - 1) * tex.width + x; |
172 | | - |
173 | | - (pixels[top], pixels[bottom]) = (pixels[bottom], pixels[top]); |
174 | | - } |
| 178 | + var reversedY = tex.height - y - 1; |
| 179 | + Array.Copy(pixels, y * tex.width, buf, 0, tex.width); |
| 180 | + Array.Copy(pixels, reversedY * tex.width, pixels, y * tex.width, tex.width); |
| 181 | + Array.Copy(buf, 0, pixels, reversedY * tex.width, tex.width); |
175 | 182 | } |
176 | 183 |
|
177 | 184 | tex.SetPixels32(pixels); |
|
0 commit comments