Skip to content

Commit faec6a7

Browse files
committed
enhancement: texture preload on startup
massive enhancement on texture render, just load in all textures at startup and never dispose them, this way we don't need to reload them all at run time anymore.
1 parent e3d7d40 commit faec6a7

File tree

2 files changed

+2
-30
lines changed

2 files changed

+2
-30
lines changed

Intersect.Client.Core/MonoGame/Graphics/MonoRenderer.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,6 @@ public override void End()
712712
mFpsTimer = Timing.Global.MillisecondsUtc + 1000;
713713
mGameWindow.Title = Strings.Main.GameName;
714714
}
715-
716-
foreach (var texture in mAllTextures)
717-
{
718-
texture?.Update();
719-
}
720715
}
721716

722717
public override int GetFps()
@@ -913,12 +908,14 @@ public override GameTexture LoadTexture(string filename, string realFilename)
913908
if (packFrame != null)
914909
{
915910
var tx = new MonoTexture(mGraphicsDevice, filename, packFrame);
911+
tx.LoadTexture();
916912
mAllTextures.Add(tx);
917913

918914
return tx;
919915
}
920916

921917
var tex = new MonoTexture(mGraphicsDevice, filename, realFilename);
918+
tex.LoadTexture();
922919
mAllTextures.Add(tex);
923920

924921
return tex;

Intersect.Client.Core/MonoGame/Graphics/MonoTexture.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ public partial class MonoTexture : GameTexture
2626

2727
private readonly GameTexturePackFrame? _packFrame;
2828

29-
private readonly bool _doNotFree;
30-
3129
private int _width = -1;
3230

3331
private Texture2D? _texture;
3432

3533
private int _height = -1;
3634

37-
private long _lastAccessTime;
38-
3935
private bool _loadError;
4036

4137
private MonoTexture(Texture2D texture2D, string assetName) : base(assetName)
@@ -45,7 +41,6 @@ private MonoTexture(Texture2D texture2D, string assetName) : base(assetName)
4541
_realPath = string.Empty;
4642
_name = assetName;
4743
_texture = texture2D;
48-
_doNotFree = true;
4944
}
5045

5146
public MonoTexture(GraphicsDevice graphicsDevice, string filename, string realPath) : base(
@@ -160,17 +155,10 @@ public void LoadTexture()
160155
}
161156
}
162157

163-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
164-
public void ResetAccessTime()
165-
{
166-
_lastAccessTime = Timing.Global.MillisecondsUtc + 15000;
167-
}
168-
169158
public override int Width
170159
{
171160
get
172161
{
173-
ResetAccessTime();
174162
if (_width != -1)
175163
{
176164
return _width;
@@ -194,7 +182,6 @@ public override int Height
194182
{
195183
get
196184
{
197-
ResetAccessTime();
198185
if (_height != -1)
199186
{
200187
return _height;
@@ -222,8 +209,6 @@ public override int Height
222209
return _packFrame.PackTexture.GetTexture();
223210
}
224211

225-
ResetAccessTime();
226-
227212
if (_texture == null)
228213
{
229214
LoadTexture();
@@ -274,21 +259,11 @@ public override Color GetPixel(int x1, int y1)
274259

275260
public void Update()
276261
{
277-
if (_doNotFree)
278-
{
279-
return;
280-
}
281-
282262
if (_texture == null)
283263
{
284264
return;
285265
}
286266

287-
if (_lastAccessTime >= Timing.Global.MillisecondsUtc)
288-
{
289-
return;
290-
}
291-
292267
_texture.Dispose();
293268
_texture = null;
294269
}

0 commit comments

Comments
 (0)