mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
some micro optimisations
This commit is contained in:
parent
f96c93c932
commit
b45bb70785
@ -51,10 +51,7 @@ namespace ClassicalSharp.Audio {
|
||||
if (snd == null) return;
|
||||
|
||||
chunk.Channels = snd.Channels;
|
||||
if (board == digBoard)
|
||||
chunk.Frequency = (snd.SampleRate * 4) / 5;
|
||||
else
|
||||
chunk.Frequency = snd.SampleRate;
|
||||
chunk.Frequency = snd.SampleRate;
|
||||
chunk.BitsPerSample = snd.BitsPerSample;
|
||||
chunk.BytesOffset = 0;
|
||||
chunk.BytesUsed = snd.Data.Length;
|
||||
|
@ -116,10 +116,13 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
}
|
||||
}
|
||||
|
||||
int fogCol;
|
||||
int fogCol, lastFogCol = FastColour.BlackPacked;
|
||||
public override void SetFogColour(FastColour col) {
|
||||
fogCol = col.ToArgb();
|
||||
if (fogCol == lastFogCol) return;
|
||||
|
||||
device.SetRenderState(RenderState.FogColor, fogCol);
|
||||
lastFogCol = fogCol;
|
||||
}
|
||||
|
||||
float fogDensity = -1, fogStart = -1, fogEnd = -1;
|
||||
|
@ -74,11 +74,10 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
FastColour lastFogCol = FastColour.Black;
|
||||
public override void SetFogColour(FastColour col) {
|
||||
if (col != lastFogCol) {
|
||||
Vector4 colRGBA = new Vector4(col.R / 255f, col.G / 255f, col.B / 255f, col.A / 255f);
|
||||
GL.Fogfv(FogParameter.FogColor, &colRGBA.X);
|
||||
lastFogCol = col;
|
||||
}
|
||||
if (col == lastFogCol) return;
|
||||
Vector4 colRGBA = new Vector4(col.R / 255f, col.G / 255f, col.B / 255f, col.A / 255f);
|
||||
GL.Fogfv(FogParameter.FogColor, &colRGBA.X);
|
||||
lastFogCol = col;
|
||||
}
|
||||
|
||||
float lastFogEnd = -1, lastFogDensity = -1;
|
||||
@ -221,7 +220,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
int batchStride;
|
||||
public override void SetDynamicVbData<T>(int id, T[] vertices, int count) {
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, id);
|
||||
GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero,
|
||||
GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero,
|
||||
new IntPtr(count * batchStride), vertices);
|
||||
}
|
||||
|
||||
@ -268,7 +267,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
public override void DrawVb(DrawMode mode, int startVertex, int verticesCount) {
|
||||
setupBatchFunc();
|
||||
GL.DrawArrays(modeMappings[(int)mode], startVertex, verticesCount);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawIndexedVb(DrawMode mode, int indicesCount, int startIndex) {
|
||||
setupBatchFunc();
|
||||
|
@ -6,7 +6,7 @@ using OpenTK;
|
||||
namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Draws the vertices for a cuboid region. </summary>
|
||||
public unsafe sealed class CuboidDrawer {
|
||||
public sealed class CuboidDrawer {
|
||||
|
||||
public int elementsPerAtlas1D;
|
||||
public float invVerElementSize;
|
||||
|
@ -105,7 +105,7 @@ namespace ClassicalSharp {
|
||||
part.iCount += 6 * 4;
|
||||
}
|
||||
|
||||
unsafe void AddVertices(byte block, int count, int face) {
|
||||
void AddVertices(byte block, int count, int face) {
|
||||
int i = atlas.Get1DIndex(info.GetTextureLoc(block, face));
|
||||
DrawInfo part = info.Draw[block] == DrawType.Translucent ? translucentParts[i] : normalParts[i];
|
||||
part.iCount += 6;
|
||||
|
@ -55,7 +55,7 @@ namespace ClassicalSharp.Textures {
|
||||
}
|
||||
|
||||
/// <summary> Runs through all animations and if necessary updates the terrain atlas. </summary>
|
||||
public unsafe void Tick(ScheduledTask task) {
|
||||
public void Tick(ScheduledTask task) {
|
||||
if (useLavaAnim) {
|
||||
int size = Math.Min(game.TerrainAtlas.elementSize, 64);
|
||||
DrawAnimation(null, 30, size);
|
||||
|
@ -86,12 +86,11 @@ namespace ClassicalSharp {
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
// Calculate the colour at this coordinate in the heatmap
|
||||
float lSoupHeat = 0;
|
||||
for (int j = 0; j < 3; j++) {
|
||||
int xx = x + (j - 1);
|
||||
lSoupHeat += soupHeat[y << shift | (xx & mask)];
|
||||
}
|
||||
|
||||
float lSoupHeat =
|
||||
soupHeat[y << shift | ((x - 1) & mask)] +
|
||||
soupHeat[y << shift | x ] +
|
||||
soupHeat[y << shift | ((x + 1) & mask)];
|
||||
|
||||
soupHeat[i] = lSoupHeat / 3.3f + potHeat[i] * 0.8f;
|
||||
potHeat[i] += flameHeat[i] * 0.05f;
|
||||
if (potHeat[i] < 0) potHeat[i] = 0;
|
||||
|
@ -151,13 +151,19 @@ namespace ClassicalSharp {
|
||||
public static void CalcBillboardPoints(Vector2 size, Vector3 position, ref Matrix4 view, out Vector3 p111,
|
||||
out Vector3 p121, out Vector3 p212, out Vector3 p222) {
|
||||
Vector3 centre = position; centre.Y += size.Y / 2;
|
||||
Vector3 a = new Vector3(view.Row0.X * size.X, view.Row1.X * size.X, view.Row2.X * size.X); // right * size.X
|
||||
Vector3 a = new Vector3(view.Row0.X * size.X, view.Row1.X * size.X, view.Row2.X * size.X) * 0.5f; // right * size.X
|
||||
Vector3 b = new Vector3(view.Row0.Y * size.Y, view.Row1.Y * size.Y, view.Row2.Y * size.Y) * 0.5f; // up * size.Y
|
||||
|
||||
p111 = centre - a - b; p121 = centre - a + b;
|
||||
p212 = centre + a - b; p222 = centre + a + b;
|
||||
|
||||
/*Vector3 a = new Vector3(view.Row0.X * size.X, view.Row1.X * size.X, view.Row2.X * size.X); // right * size.X
|
||||
Vector3 b = new Vector3(view.Row0.Y * size.Y, view.Row1.Y * size.Y, view.Row2.Y * size.Y); // up * size.Y
|
||||
|
||||
p111 = centre + a * -0.5f + b * -0.5f;
|
||||
p121 = centre + a * -0.5f + b * 0.5f;
|
||||
p212 = centre + a * 0.5f + b * -0.5f;
|
||||
p222 = centre + a * 0.5f + b * 0.5f;
|
||||
p222 = centre + a * 0.5f + b * 0.5f;*/
|
||||
}
|
||||
|
||||
/// <summary> Linearly interpolates between a given angle range, adjusting if necessary. </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user