Skip to content

Commit b7e7d82

Browse files
committed
Filter animation shape loading only to building animations (other animations are currently never displayed)
Significantly reduces RAM consumption
1 parent c2df132 commit b7e7d82

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/TSMapEditor/Rendering/TheaterGraphics.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public TheaterGraphics(GraphicsDevice graphicsDevice, Theater theater, CCFileMan
402402
var task11 = Task.Factory.StartNew(() => ReadInfantryTextures(rules.InfantryTypes));
403403
var task12 = Task.Factory.StartNew(() => ReadOverlayTextures(rules.OverlayTypes));
404404
var task13 = Task.Factory.StartNew(() => ReadSmudgeTextures(rules.SmudgeTypes));
405-
var task14 = Task.Factory.StartNew(() => ReadAnimTextures(rules.AnimTypes));
405+
var task14 = Task.Factory.StartNew(() => ReadAnimTextures(rules.AnimTypes, rules.BuildingTypes));
406406
var task15 = Task.Factory.StartNew(() => ReadAlphaImages(rules));
407407
Task.WaitAll(task1, task2, task3, task4, task5, task6, task7, task8, task9, task10, task11, task12, task13, task14, task15);
408408
}
@@ -421,7 +421,7 @@ public TheaterGraphics(GraphicsDevice graphicsDevice, Theater theater, CCFileMan
421421
ReadInfantryTextures(rules.InfantryTypes);
422422
ReadOverlayTextures(rules.OverlayTypes);
423423
ReadSmudgeTextures(rules.SmudgeTypes);
424-
ReadAnimTextures(rules.AnimTypes);
424+
ReadAnimTextures(rules.AnimTypes, rules.BuildingTypes);
425425
ReadAlphaImages(rules);
426426
}
427427

@@ -443,21 +443,9 @@ private Texture2D TextureFromBuffer(int width, int height, byte[] buffer)
443443
// Create texture color buffer and copy the data from the working buffer to the color buffer.
444444
byte[] finalColorBuffer = new byte[width * height];
445445

446-
unsafe
446+
for (int ty = 0; ty < height; ty++)
447447
{
448-
fixed (byte* colorBufferPtr = finalColorBuffer)
449-
{
450-
fixed (byte* paramBufferPtr = buffer)
451-
{
452-
for (int ty = 0; ty < height; ty++)
453-
{
454-
for (int tx = 0; tx < width; tx++)
455-
{
456-
colorBufferPtr[ty * width + tx] = paramBufferPtr[ty * RenderingConstants.MaximumDX11TextureSize + tx];
457-
}
458-
}
459-
}
460-
}
448+
Buffer.BlockCopy(buffer, ty * RenderingConstants.MaximumDX11TextureSize, finalColorBuffer, ty * width, width);
461449
}
462450

463451
// Create Texture2D instance and write data from the color buffer to it.
@@ -1020,7 +1008,7 @@ public void ReadBuildingBarrelModels(List<BuildingType> buildingTypes)
10201008
Logger.Log("Finished loading building barrels' voxel models.");
10211009
}
10221010

1023-
public void ReadAnimTextures(List<AnimType> animTypes)
1011+
public void ReadAnimTextures(List<AnimType> animTypes, List<BuildingType> buildingTypes)
10241012
{
10251013
Logger.Log("Loading animation textures.");
10261014

@@ -1032,6 +1020,10 @@ public void ReadAnimTextures(List<AnimType> animTypes)
10321020
{
10331021
var animType = animTypes[i];
10341022

1023+
// Is this animation actually used as a building animation? If not, we can skip loading it.
1024+
if (!buildingTypes.Exists(btype => btype.ArtConfig.TurretAnim == animType || Array.Exists(btype.ArtConfig.Anims, atype => atype == animType) || Array.Exists(btype.ArtConfig.PowerUpAnims, atype => atype == animType)))
1025+
continue;
1026+
10351027
string shpFileName = string.IsNullOrWhiteSpace(animType.ArtConfig.Image) ? animType.ININame : animType.ArtConfig.Image;
10361028
string loadedShpName = "";
10371029

0 commit comments

Comments
 (0)