Browse Source

Cache brush surface texture numbers instead of re-marshaling them on each access. Fixes textures getting mixed up on brush model entities after map switch.

console
Nico de Poel 5 years ago
parent
commit
c9271a7772
  1. 2
      Assets/Scripts/Data/QTexture.cs
  2. 4
      Assets/Scripts/Game/GameState.cs
  3. 9
      Assets/Scripts/Support/BrushModel.cs

2
Assets/Scripts/Data/QTexture.cs

@ -45,7 +45,7 @@ public class QGLTexture
// Conveniently make use of the fact that texNum is the first field in QGLTexture,
// so we don't have to marshal the entire struct to get the texture number out of it.
public static uint TexNumFromPtr(IntPtr ptr) => ptr == IntPtr.Zero ? 0 : unchecked((uint)Marshal.ReadInt32(ptr));
public static uint TexNumFromPtr(IntPtr ptr) => ptr != IntPtr.Zero ? (uint)Marshal.ReadInt32(ptr) : 0;
}
/// <summary>

4
Assets/Scripts/Game/GameState.cs

@ -51,10 +51,10 @@ public class GameState
// TODO FIXME This is wrong for brush model entities
uq.CurrentStyle.SetupWorldModelRenderer(mr); // TODO FIXME this currently leaks Materials
uint texNum = surfaceMesh.Texture.TextureNum;
uint texNum = surfaceMesh.TextureNum;
if (uq.GameAssets.TryGetTexture(texNum, out var texture))
{
uint fbNum = surfaceMesh.Texture.FullBrightNum;
uint fbNum = surfaceMesh.FullBrightNum;
uq.GameAssets.TryGetTexture(fbNum, out var fullBright);
uq.CurrentStyle.SetWorldModelTextures(mr.material, texture, fullBright, null);

9
Assets/Scripts/Support/BrushModel.cs

@ -159,13 +159,18 @@ public class BrushModel
public class SurfaceMesh
{
public Mesh Mesh { get; }
public QTexture Texture { get; }
public uint TextureNum { get; }
public uint FullBrightNum { get; }
public uint WarpImageNum { get; }
public int Lightmap { get; }
public SurfaceMesh(Mesh mesh, IntPtr texturePtr, int lightmap)
{
Mesh = mesh;
Texture = Marshal.PtrToStructure<QTexture>(texturePtr);
var texture = Marshal.PtrToStructure<QTexture>(texturePtr);
TextureNum = texture.TextureNum;
FullBrightNum = texture.FullBrightNum;
WarpImageNum = texture.WarpImageNum;
Lightmap = lightmap;
}

Loading…
Cancel
Save