Further reduce size of IL code

This commit is contained in:
UnknownShadow200 2017-09-13 23:09:10 +10:00
parent a14492daa8
commit 3c6bf3624c
9 changed files with 150 additions and 120 deletions

View File

@ -81,7 +81,7 @@ namespace ClassicalSharp.Entities {
const byte c = 255; // avoids 'ambiguous match' compile errors. const byte c = 255; // avoids 'ambiguous match' compile errors.
static void DraqSquareShadow(VertexP3fT2fC4b[] verts, ref int index, static void DraqSquareShadow(VertexP3fT2fC4b[] verts, ref int index,
float y, byte alpha, float x, float z) { float y, byte alpha, float x, float z) {
int col = new FastColour(c, c, c, alpha).ToArgb(); int col = new FastColour(c, c, c, alpha).Pack();
TextureRec rec = new TextureRec(63/128f, 63/128f, 1/128f, 1/128f); TextureRec rec = new TextureRec(63/128f, 63/128f, 1/128f, 1/128f);
verts[index++] = new VertexP3fT2fC4b(x, y, z, rec.U1, rec.V1, col); verts[index++] = new VertexP3fT2fC4b(x, y, z, rec.U1, rec.V1, col);
verts[index++] = new VertexP3fT2fC4b(x + 1, y, z, rec.U2, rec.V1, col); verts[index++] = new VertexP3fT2fC4b(x + 1, y, z, rec.U2, rec.V1, col);
@ -122,7 +122,7 @@ namespace ClassicalSharp.Entities {
x2 = Math.Min(x2, cen.X + radius/16f); u2 = Math.Min(u2, 1); x2 = Math.Min(x2, cen.X + radius/16f); u2 = Math.Min(u2, 1);
z2 = Math.Min(z2, cen.Z + radius/16f); v2 = Math.Min(v2, 1); z2 = Math.Min(z2, cen.Z + radius/16f); v2 = Math.Min(v2, 1);
int col = new FastColour(c, c, c, data.A).ToArgb(); int col = new FastColour(c, c, c, data.A).Pack();
verts[index++] = new VertexP3fT2fC4b(x1, data.Y, z1, u1, v1, col); verts[index++] = new VertexP3fT2fC4b(x1, data.Y, z1, u1, v1, col);
verts[index++] = new VertexP3fT2fC4b(x2, data.Y, z1, u2, v1, col); verts[index++] = new VertexP3fT2fC4b(x2, data.Y, z1, u2, v1, col);
verts[index++] = new VertexP3fT2fC4b(x2, data.Y, z2, u2, v2, col); verts[index++] = new VertexP3fT2fC4b(x2, data.Y, z2, u2, v2, col);

View File

@ -120,7 +120,7 @@ namespace ClassicalSharp.GraphicsAPI {
int fogCol, lastFogCol = FastColour.BlackPacked; int fogCol, lastFogCol = FastColour.BlackPacked;
public override void SetFogColour(FastColour col) { public override void SetFogColour(FastColour col) {
fogCol = col.ToArgb(); fogCol = col.Pack();
if (fogCol == lastFogCol) return; if (fogCol == lastFogCol) return;
device.SetRenderState(RenderState.FogColor, fogCol); device.SetRenderState(RenderState.FogColor, fogCol);
@ -247,7 +247,7 @@ namespace ClassicalSharp.GraphicsAPI {
} }
public override void ClearColour(FastColour col) { public override void ClearColour(FastColour col) {
lastClearCol = col.ToArgb(); lastClearCol = col.Pack();
} }
public override bool ColourWrite { public override bool ColourWrite {

View File

@ -154,17 +154,19 @@ namespace ClassicalSharp {
col0_1 = Utils.Tint(col0_1, tint); col0_1 = Utils.Tint(col0_1, tint);
} }
int index = part.vIndex[Side.Left];
if (aY0_Z0 + aY1_Z1 > aY0_Z1 + aY1_Z0) { if (aY0_Z0 + aY1_Z1 > aY0_Z1 + aY1_Z0) {
part.vertices[part.vIndex[Side.Left]++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col1_0); part.vertices[index ] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col1_0);
part.vertices[part.vIndex[Side.Left]++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0);
part.vertices[part.vIndex[Side.Left]++] = new VertexP3fT2fC4b(x1, y1, z2 + (count - 1), u2, v2, col0_1); part.vertices[index + 2] = new VertexP3fT2fC4b(x1, y1, z2 + (count - 1), u2, v2, col0_1);
part.vertices[part.vIndex[Side.Left]++] = new VertexP3fT2fC4b(x1, y2, z2 + (count - 1), u2, v1, col1_1); part.vertices[index + 3] = new VertexP3fT2fC4b(x1, y2, z2 + (count - 1), u2, v1, col1_1);
} else { } else {
part.vertices[part.vIndex[Side.Left]++] = new VertexP3fT2fC4b(x1, y2, z2 + (count - 1), u2, v1, col1_1); part.vertices[index ] = new VertexP3fT2fC4b(x1, y2, z2 + (count - 1), u2, v1, col1_1);
part.vertices[part.vIndex[Side.Left]++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col1_0); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col1_0);
part.vertices[part.vIndex[Side.Left]++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0); part.vertices[index + 2] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0);
part.vertices[part.vIndex[Side.Left]++] = new VertexP3fT2fC4b(x1, y1, z2 + (count - 1), u2, v2, col0_1); part.vertices[index + 3] = new VertexP3fT2fC4b(x1, y1, z2 + (count - 1), u2, v2, col0_1);
} }
part.vIndex[Side.Left] += 4;
} }
void DrawRightFace(int count) { void DrawRightFace(int count) {
@ -194,17 +196,19 @@ namespace ClassicalSharp {
col0_1 = Utils.Tint(col0_1, tint); col0_1 = Utils.Tint(col0_1, tint);
} }
int index = part.vIndex[Side.Right];
if (aY0_Z0 + aY1_Z1 > aY0_Z1 + aY1_Z0) { if (aY0_Z0 + aY1_Z1 > aY0_Z1 + aY1_Z0) {
part.vertices[part.vIndex[Side.Right]++] = new VertexP3fT2fC4b(x2, y2, z1, u1, v1, col1_0); part.vertices[index ] = new VertexP3fT2fC4b(x2, y2, z1, u1, v1, col1_0);
part.vertices[part.vIndex[Side.Right]++] = new VertexP3fT2fC4b(x2, y2, z2 + (count - 1), u2, v1, col1_1); part.vertices[index + 1] = new VertexP3fT2fC4b(x2, y2, z2 + (count - 1), u2, v1, col1_1);
part.vertices[part.vIndex[Side.Right]++] = new VertexP3fT2fC4b(x2, y1, z2 + (count - 1), u2, v2, col0_1); part.vertices[index + 2] = new VertexP3fT2fC4b(x2, y1, z2 + (count - 1), u2, v2, col0_1);
part.vertices[part.vIndex[Side.Right]++] = new VertexP3fT2fC4b(x2, y1, z1, u1, v2, col0_0); part.vertices[index + 3] = new VertexP3fT2fC4b(x2, y1, z1, u1, v2, col0_0);
} else { } else {
part.vertices[part.vIndex[Side.Right]++] = new VertexP3fT2fC4b(x2, y2, z2 + (count - 1), u2, v1, col1_1); part.vertices[index ] = new VertexP3fT2fC4b(x2, y2, z2 + (count - 1), u2, v1, col1_1);
part.vertices[part.vIndex[Side.Right]++] = new VertexP3fT2fC4b(x2, y1, z2 + (count - 1), u2, v2, col0_1); part.vertices[index + 1] = new VertexP3fT2fC4b(x2, y1, z2 + (count - 1), u2, v2, col0_1);
part.vertices[part.vIndex[Side.Right]++] = new VertexP3fT2fC4b(x2, y1, z1, u1, v2, col0_0); part.vertices[index + 2] = new VertexP3fT2fC4b(x2, y1, z1, u1, v2, col0_0);
part.vertices[part.vIndex[Side.Right]++] = new VertexP3fT2fC4b(x2, y2, z1, u1, v1, col1_0); part.vertices[index + 3] = new VertexP3fT2fC4b(x2, y2, z1, u1, v1, col1_0);
} }
part.vIndex[Side.Right] += 4;
} }
void DrawFrontFace(int count) { void DrawFrontFace(int count) {
@ -234,17 +238,19 @@ namespace ClassicalSharp {
col0_1 = Utils.Tint(col0_1, tint); col0_1 = Utils.Tint(col0_1, tint);
} }
int index = part.vIndex[Side.Front];
if (aX1_Y1 + aX0_Y0 > aX0_Y1 + aX1_Y0) { if (aX1_Y1 + aX0_Y0 > aX0_Y1 + aX1_Y0) {
part.vertices[part.vIndex[Side.Front]++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v2, col1_0); part.vertices[index ] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v2, col1_0);
part.vertices[part.vIndex[Side.Front]++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0);
part.vertices[part.vIndex[Side.Front]++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_1); part.vertices[index + 2] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_1);
part.vertices[part.vIndex[Side.Front]++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_1); part.vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_1);
} else { } else {
part.vertices[part.vIndex[Side.Front]++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0); part.vertices[index ] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0);
part.vertices[part.vIndex[Side.Front]++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_1); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_1);
part.vertices[part.vIndex[Side.Front]++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_1); part.vertices[index + 2] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_1);
part.vertices[part.vIndex[Side.Front]++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v2, col1_0); part.vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v2, col1_0);
} }
part.vIndex[Side.Front] += 4;
} }
void DrawBackFace(int count) { void DrawBackFace(int count) {
@ -274,17 +280,19 @@ namespace ClassicalSharp {
col0_1 = Utils.Tint(col0_1, tint); col0_1 = Utils.Tint(col0_1, tint);
} }
int index = part.vIndex[Side.Back];
if (aX1_Y1 + aX0_Y0 > aX0_Y1 + aX1_Y0) { if (aX1_Y1 + aX0_Y0 > aX0_Y1 + aX1_Y0) {
part.vertices[part.vIndex[Side.Back]++] = new VertexP3fT2fC4b(x1, y2, z2, u1, v1, col0_1); part.vertices[index ] = new VertexP3fT2fC4b(x1, y2, z2, u1, v1, col0_1);
part.vertices[part.vIndex[Side.Back]++] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_0); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_0);
part.vertices[part.vIndex[Side.Back]++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_0); part.vertices[index + 2] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_0);
part.vertices[part.vIndex[Side.Back]++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v1, col1_1); part.vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v1, col1_1);
} else { } else {
part.vertices[part.vIndex[Side.Back]++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v1, col1_1); part.vertices[index ] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v1, col1_1);
part.vertices[part.vIndex[Side.Back]++] = new VertexP3fT2fC4b(x1, y2, z2, u1, v1, col0_1); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y2, z2, u1, v1, col0_1);
part.vertices[part.vIndex[Side.Back]++] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_0); part.vertices[index + 2] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_0);
part.vertices[part.vIndex[Side.Back]++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_0); part.vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_0);
} }
part.vIndex[Side.Back] += 4;
} }
void DrawBottomFace(int count) { void DrawBottomFace(int count) {
@ -314,17 +322,19 @@ namespace ClassicalSharp {
col0_1 = Utils.Tint(col0_1, tint); col0_1 = Utils.Tint(col0_1, tint);
} }
int index = part.vIndex[Side.Bottom];
if (aX0_Z1 + aX1_Z0 > aX0_Z0 + aX1_Z1) { if (aX0_Z1 + aX1_Z0 > aX0_Z0 + aX1_Z1) {
part.vertices[part.vIndex[Side.Bottom]++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_1); part.vertices[index ] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_1);
part.vertices[part.vIndex[Side.Bottom]++] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_1); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_1);
part.vertices[part.vIndex[Side.Bottom]++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v1, col0_0); part.vertices[index + 2] = new VertexP3fT2fC4b(x1, y1, z1, u1, v1, col0_0);
part.vertices[part.vIndex[Side.Bottom]++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v1, col1_0); part.vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v1, col1_0);
} else { } else {
part.vertices[part.vIndex[Side.Bottom]++] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_1); part.vertices[index ] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_1);
part.vertices[part.vIndex[Side.Bottom]++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v1, col0_0); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y1, z1, u1, v1, col0_0);
part.vertices[part.vIndex[Side.Bottom]++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v1, col1_0); part.vertices[index + 2] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v1, col1_0);
part.vertices[part.vIndex[Side.Bottom]++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_1); part.vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_1);
} }
part.vIndex[Side.Bottom] += 4;
} }
void DrawTopFace(int count) { void DrawTopFace(int count) {
@ -354,17 +364,19 @@ namespace ClassicalSharp {
col0_1 = Utils.Tint(col0_1, tint); col0_1 = Utils.Tint(col0_1, tint);
} }
int index = part.vIndex[Side.Top];
if (aX0_Z0 + aX1_Z1 > aX0_Z1 + aX1_Z0) { if (aX0_Z0 + aX1_Z1 > aX0_Z1 + aX1_Z0) {
part.vertices[part.vIndex[Side.Top]++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_0); part.vertices[index ] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_0);
part.vertices[part.vIndex[Side.Top]++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_0); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_0);
part.vertices[part.vIndex[Side.Top]++] = new VertexP3fT2fC4b(x1, y2, z2, u1, v2, col0_1); part.vertices[index + 2] = new VertexP3fT2fC4b(x1, y2, z2, u1, v2, col0_1);
part.vertices[part.vIndex[Side.Top]++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v2, col1_1); part.vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v2, col1_1);
} else { } else {
part.vertices[part.vIndex[Side.Top]++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_0); part.vertices[index ] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_0);
part.vertices[part.vIndex[Side.Top]++] = new VertexP3fT2fC4b(x1, y2, z2, u1, v2, col0_1); part.vertices[index + 1] = new VertexP3fT2fC4b(x1, y2, z2, u1, v2, col0_1);
part.vertices[part.vIndex[Side.Top]++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v2, col1_1); part.vertices[index + 2] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v2, col1_1);
part.vertices[part.vIndex[Side.Top]++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_0); part.vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_0);
} }
part.vIndex[Side.Top] += 4;
} }
int[] lerp = new int[5], lerpX = new int[5], lerpZ = new int[5], lerpY = new int[5]; int[] lerp = new int[5], lerpX = new int[5], lerpZ = new int[5], lerpY = new int[5];

View File

@ -239,8 +239,11 @@ namespace ClassicalSharp.Renderers {
} }
void DrawX(int x, int z1, int z2, int y1, int y2, int axisSize, void DrawX(int x, int z1, int z2, int y1, int y2, int axisSize,
int col, VertexP3fT2fC4b[] v, ref int i) { int col, VertexP3fT2fC4b[] vertices, ref int i) {
int endZ = z2, endY = y2, startY = y1; int endZ = z2, endY = y2, startY = y1;
VertexP3fT2fC4b v;
v.X = x; v.Colour = col;
for (; z1 < endZ; z1 += axisSize) { for (; z1 < endZ; z1 += axisSize) {
z2 = z1 + axisSize; z2 = z1 + axisSize;
if (z2 > endZ) z2 = endZ; if (z2 > endZ) z2 = endZ;
@ -249,18 +252,21 @@ namespace ClassicalSharp.Renderers {
y2 = y1 + axisSize; y2 = y1 + axisSize;
if (y2 > endY) y2 = endY; if (y2 > endY) y2 = endY;
TextureRec rec = new TextureRec(0, 0, z2 - z1, y2 - y1); float u2 = z2 - z1, v2 = y2 - y1;
v[i++] = new VertexP3fT2fC4b(x, y1, z1, rec.U1, rec.V2, col); v.Y = y1; v.Z = z1; v.U = 0f; v.V = v2; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x, y2, z1, rec.U1, rec.V1, col); v.Y = y2; v.V = 0f; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x, y2, z2, rec.U2, rec.V1, col); v.Z = z2; v.U = u2; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x, y1, z2, rec.U2, rec.V2, col); v.Y = y1; v.V = v2; vertices[i++] = v;
} }
} }
} }
void DrawZ(int z, int x1, int x2, int y1, int y2, int axisSize, void DrawZ(int z, int x1, int x2, int y1, int y2, int axisSize,
int col, VertexP3fT2fC4b[] v, ref int i) { int col, VertexP3fT2fC4b[] vertices, ref int i) {
int endX = x2, endY = y2, startY = y1; int endX = x2, endY = y2, startY = y1;
VertexP3fT2fC4b v;
v.Z = z; v.Colour = col;
for (; x1 < endX; x1 += axisSize) { for (; x1 < endX; x1 += axisSize) {
x2 = x1 + axisSize; x2 = x1 + axisSize;
if (x2 > endX) x2 = endX; if (x2 > endX) x2 = endX;
@ -269,18 +275,21 @@ namespace ClassicalSharp.Renderers {
y2 = y1 + axisSize; y2 = y1 + axisSize;
if (y2 > endY) y2 = endY; if (y2 > endY) y2 = endY;
TextureRec rec = new TextureRec(0, 0, x2 - x1, y2 - y1); float u2 = x2 - x1, v2 = y2 - y1;
v[i++] = new VertexP3fT2fC4b(x1, y1, z, rec.U1, rec.V2, col); v.X = x1; v.Y = y1; v.U = 0f; v.V = v2; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x1, y2, z, rec.U1, rec.V1, col); v.Y = y2; v.V = 0f; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x2, y2, z, rec.U2, rec.V1, col); v.X = x2; v.U = u2; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x2, y1, z, rec.U2, rec.V2, col); v.Y = y1; v.V = v2; vertices[i++] = v;
} }
} }
} }
void DrawY(int x1, int z1, int x2, int z2, float y, int axisSize, void DrawY(int x1, int z1, int x2, int z2, float y, int axisSize,
int col, float offset, float yOffset, VertexP3fT2fC4b[] v, ref int i) { int col, float offset, float yOffset, VertexP3fT2fC4b[] vertices, ref int i) {
int endX = x2, endZ = z2, startZ = z1; int endX = x2, endZ = z2, startZ = z1;
VertexP3fT2fC4b v;
v.Y = y + yOffset; v.Colour = col;
for (; x1 < endX; x1 += axisSize) { for (; x1 < endX; x1 += axisSize) {
x2 = x1 + axisSize; x2 = x1 + axisSize;
if (x2 > endX) x2 = endX; if (x2 > endX) x2 = endX;
@ -289,11 +298,11 @@ namespace ClassicalSharp.Renderers {
z2 = z1 + axisSize; z2 = z1 + axisSize;
if (z2 > endZ) z2 = endZ; if (z2 > endZ) z2 = endZ;
TextureRec rec = new TextureRec(0, 0, x2 - x1, z2 - z1); float u2 = x2 - x1, v2 = z2 - z1;
v[i++] = new VertexP3fT2fC4b(x1 + offset, y + yOffset, z1 + offset, rec.U1, rec.V1, col); v.X = x1 + offset; v.Z = z1 + offset; v.U = 0f; v.V = 0f; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x1 + offset, y + yOffset, z2 + offset, rec.U1, rec.V2, col); v.Z = z2 + offset; v.V = v2; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x2 + offset, y + yOffset, z2 + offset, rec.U2, rec.V2, col); v.X = x2 + offset; v.U = u2; vertices[i++] = v;
v[i++] = new VertexP3fT2fC4b(x2 + offset, y + yOffset, z1 + offset, rec.U2, rec.V1, col); v.Z = z1 + offset; v.V = 0f; vertices[i++] = v;
} }
} }
} }

View File

@ -233,6 +233,8 @@ namespace ClassicalSharp.Renderers {
void DrawSkyY(int x1, int z1, int x2, int z2, int y, int axisSize, int col, VertexP3fC4b[] vertices) { void DrawSkyY(int x1, int z1, int x2, int z2, int y, int axisSize, int col, VertexP3fC4b[] vertices) {
int endX = x2, endZ = z2, startZ = z1; int endX = x2, endZ = z2, startZ = z1;
int i = 0; int i = 0;
VertexP3fC4b v;
v.Y = y; v.Colour = col;
for (; x1 < endX; x1 += axisSize) { for (; x1 < endX; x1 += axisSize) {
x2 = x1 + axisSize; x2 = x1 + axisSize;
@ -242,10 +244,10 @@ namespace ClassicalSharp.Renderers {
z2 = z1 + axisSize; z2 = z1 + axisSize;
if (z2 > endZ) z2 = endZ; if (z2 > endZ) z2 = endZ;
vertices[i++] = new VertexP3fC4b(x1, y, z1, col); v.X = x1; v.Z = z1; vertices[i++] = v;
vertices[i++] = new VertexP3fC4b(x1, y, z2, col); v.Z = z2; vertices[i++] = v;
vertices[i++] = new VertexP3fC4b(x2, y, z2, col); v.X = x2; vertices[i++] = v;
vertices[i++] = new VertexP3fC4b(x2, y, z1, col); v.Z = z1; vertices[i++] = v;
} }
} }
} }
@ -255,6 +257,8 @@ namespace ClassicalSharp.Renderers {
// adjust range so that largest negative uv coordinate is shifted to 0 or above. // adjust range so that largest negative uv coordinate is shifted to 0 or above.
float offset = Utils.CeilDiv(-x1, 2048); float offset = Utils.CeilDiv(-x1, 2048);
int i = 0; int i = 0;
VertexP3fT2fC4b v;
v.Y = y + 0.1f; v.Colour = col;
for (; x1 < endX; x1 += axisSize) { for (; x1 < endX; x1 += axisSize) {
x2 = x1 + axisSize; x2 = x1 + axisSize;
@ -264,10 +268,12 @@ namespace ClassicalSharp.Renderers {
z2 = z1 + axisSize; z2 = z1 + axisSize;
if (z2 > endZ) z2 = endZ; if (z2 > endZ) z2 = endZ;
vertices[i++] = new VertexP3fT2fC4b(x1, y + 0.1f, z1, x1 / 2048f + offset, z1 / 2048f + offset, col); float u1 = x1 / 2048f + offset, u2 = x2 / 2048f + offset;
vertices[i++] = new VertexP3fT2fC4b(x1, y + 0.1f, z2, x1 / 2048f + offset, z2 / 2048f + offset, col); float v1 = z1 / 2048f + offset, v2 = z2 / 2048f + offset;
vertices[i++] = new VertexP3fT2fC4b(x2, y + 0.1f, z2, x2 / 2048f + offset, z2 / 2048f + offset, col); v.X = x1; v.Z = z1; v.U = u1; v.V = v1; vertices[i++] = v;
vertices[i++] = new VertexP3fT2fC4b(x2, y + 0.1f, z1, x2 / 2048f + offset, z1 / 2048f + offset, col); v.Z = z2; v.V = v2; vertices[i++] = v;
v.X = x2; v.U = u2; vertices[i++] = v;
v.Z = z1; v.V = v1; vertices[i++] = v;
} }
} }
} }

View File

@ -90,9 +90,11 @@ void BordersRenderer_ResetTextures(void) {
#define borders_HorOffset(block) (Block_RenderMinBB[block].X - Block_MinBB[block].X) #define borders_HorOffset(block) (Block_RenderMinBB[block].X - Block_MinBB[block].X)
#define borders_YOffset(block) (Block_RenderMinBB[block].Y - Block_MinBB[block].Y) #define borders_YOffset(block) (Block_RenderMinBB[block].Y - Block_MinBB[block].Y)
void BordersRenderer_DrawX(Int32 x, Int32 z1, Int32 z2, Int32 y1, Int32 y2, Int32 axisSize, PackedCol col, VertexP3fT2fC4b** v) { void BordersRenderer_DrawX(Int32 x, Int32 z1, Int32 z2, Int32 y1, Int32 y2, Int32 axisSize, PackedCol col, VertexP3fT2fC4b** vertices) {
Int32 endZ = z2, endY = y2, startY = y1; Int32 endZ = z2, endY = y2, startY = y1;
VertexP3fT2fC4b* ptr = *v; VertexP3fT2fC4b* ptr = *vertices;
VertexP3fT2fC4b v;
v.X = x; v.Colour = col;
for (; z1 < endZ; z1 += axisSize) { for (; z1 < endZ; z1 += axisSize) {
z2 = z1 + axisSize; z2 = z1 + axisSize;
@ -102,19 +104,21 @@ void BordersRenderer_DrawX(Int32 x, Int32 z1, Int32 z2, Int32 y1, Int32 y2, Int3
y2 = y1 + axisSize; y2 = y1 + axisSize;
if (y2 > endY) y2 = endY; if (y2 > endY) y2 = endY;
TextureRec rec = TextureRec_FromPoints(0, 0, (Real32)z2 - (Real32)z1, (Real32)y2 - (Real32)y1); Real32 u2 = (Real32)z2 - (Real32)z1, v2 = (Real32)y2 - (Real32)y1;
VertexP3fT2fC4b_Set(ptr, (Real32)x, (Real32)y1, (Real32)z1, rec.U1, rec.V2, col); ptr++; v.Y = (Real32)y1; v.Z = (Real32)z1; v.U = 0.0f; v.V = v2; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x, (Real32)y2, (Real32)z1, rec.U1, rec.V1, col); ptr++; v.Y = (Real32)y2; v.V = 0.0f; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x, (Real32)y2, (Real32)z2, rec.U2, rec.V1, col); ptr++; v.Z = (Real32)z2; v.U = u2; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x, (Real32)y1, (Real32)z2, rec.U2, rec.V2, col); ptr++; v.Y = (Real32)y1; v.V = v2; *ptr = v; ptr++;
} }
} }
*v = ptr; *vertices = ptr;
} }
void BordersRenderer_DrawZ(Int32 z, Int32 x1, Int32 x2, Int32 y1, Int32 y2, Int32 axisSize, PackedCol col, VertexP3fT2fC4b** v) { void BordersRenderer_DrawZ(Int32 z, Int32 x1, Int32 x2, Int32 y1, Int32 y2, Int32 axisSize, PackedCol col, VertexP3fT2fC4b** vertices) {
Int32 endX = x2, endY = y2, startY = y1; Int32 endX = x2, endY = y2, startY = y1;
VertexP3fT2fC4b* ptr = *v; VertexP3fT2fC4b* ptr = *vertices;
VertexP3fT2fC4b v;
v.Z = z; v.Colour = col;
for (; x1 < endX; x1 += axisSize) { for (; x1 < endX; x1 += axisSize) {
x2 = x1 + axisSize; x2 = x1 + axisSize;
@ -124,19 +128,21 @@ void BordersRenderer_DrawZ(Int32 z, Int32 x1, Int32 x2, Int32 y1, Int32 y2, Int3
y2 = y1 + axisSize; y2 = y1 + axisSize;
if (y2 > endY) y2 = endY; if (y2 > endY) y2 = endY;
TextureRec rec = TextureRec_FromPoints(0, 0, (Real32)x2 - (Real32)x1, (Real32)y2 - (Real32)y1); Real32 u2 = (Real32)x2 - (Real32)x1, v2 = (Real32)y2 - (Real32)y1;
VertexP3fT2fC4b_Set(ptr, (Real32)x1, (Real32)y1, (Real32)z, rec.U1, rec.V2, col); ptr++; v.X = (Real32)x1; v.Y = (Real32)y1; v.U = 0.0f; v.V = v2; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x1, (Real32)y2, (Real32)z, rec.U1, rec.V1, col); ptr++; v.Y = (Real32)y2; v.V = 0.0f; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x2, (Real32)y2, (Real32)z, rec.U2, rec.V1, col); ptr++; v.X = (Real32)x2; v.U = u2; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x2, (Real32)y1, (Real32)z, rec.U2, rec.V2, col); ptr++; v.Y = (Real32)y1; v.V = v2; *ptr = v; ptr++;
} }
} }
*v = ptr; *vertices = ptr;
} }
void BordersRenderer_DrawY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Real32 y, Int32 axisSize, PackedCol col, Real32 offset, Real32 yOffset, VertexP3fT2fC4b** v) { void BordersRenderer_DrawY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Real32 y, Int32 axisSize, PackedCol col, Real32 offset, Real32 yOffset, VertexP3fT2fC4b** vertices) {
Int32 endX = x2, endZ = z2, startZ = z1; Int32 endX = x2, endZ = z2, startZ = z1;
VertexP3fT2fC4b* ptr = *v; VertexP3fT2fC4b* ptr = *vertices;
VertexP3fT2fC4b v;
v.Y = y + yOffset; v.Colour = col;
for (; x1 < endX; x1 += axisSize) { for (; x1 < endX; x1 += axisSize) {
x2 = x1 + axisSize; x2 = x1 + axisSize;
@ -146,14 +152,14 @@ void BordersRenderer_DrawY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Real32 y, Int
z2 = z1 + axisSize; z2 = z1 + axisSize;
if (z2 > endZ) z2 = endZ; if (z2 > endZ) z2 = endZ;
TextureRec rec = TextureRec_FromPoints(0, 0, (Real32)x2 - (Real32)x1, (Real32)z2 - (Real32)z1); Real32 u2 = (Real32)x2 - (Real32)x1, v2 = (Real32)z2 - (Real32)z1;
VertexP3fT2fC4b_Set(ptr, (Real32)x1 + offset, y + yOffset, (Real32)z1 + offset, rec.U1, rec.V1, col); ptr++; v.X = (Real32)x1 + offset; v.Z = (Real32)z1 + offset; v.U = 0.0f; v.V = 0.0f; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x1 + offset, y + yOffset, (Real32)z2 + offset, rec.U1, rec.V2, col); ptr++; v.Z = (Real32)z2 + offset; v.V = v2; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x2 + offset, y + yOffset, (Real32)z2 + offset, rec.U2, rec.V2, col); ptr++; v.X = (Real32)x2 + offset; v.U = u2; *ptr = v; ptr++;
VertexP3fT2fC4b_Set(ptr, (Real32)x2 + offset, y + yOffset, (Real32)z1 + offset, rec.U2, rec.V1, col); ptr++; v.Z = (Real32)z1 + offset; v.V = 0.0f; *ptr = v; ptr++;
} }
} }
*v = ptr; *vertices = ptr;
} }
void BordersRenderer_RebuildSides(Int32 y, Int32 axisSize) { void BordersRenderer_RebuildSides(Int32 y, Int32 axisSize) {

View File

@ -151,6 +151,8 @@ void EnvRenderer_Render(Real64 deltaTime) {
void EnvRenderer_DrawSkyY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, Int32 axisSize, PackedCol col, VertexP3fC4b* vertices) { void EnvRenderer_DrawSkyY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, Int32 axisSize, PackedCol col, VertexP3fC4b* vertices) {
Int32 endX = x2, endZ = z2, startZ = z1; Int32 endX = x2, endZ = z2, startZ = z1;
VertexP3fC4b v;
v.Y = (Real32)y; v.Colour = col;
for (; x1 < endX; x1 += axisSize) { for (; x1 < endX; x1 += axisSize) {
x2 = x1 + axisSize; x2 = x1 + axisSize;
@ -160,10 +162,10 @@ void EnvRenderer_DrawSkyY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, Int32
z2 = z1 + axisSize; z2 = z1 + axisSize;
if (z2 > endZ) z2 = endZ; if (z2 > endZ) z2 = endZ;
VertexP3fC4b_Set(vertices, (Real32)x1, (Real32)y, (Real32)z1, col); vertices++; v.X = (Real32)x1; v.Z = (Real32)z1; *vertices = v; vertices++;
VertexP3fC4b_Set(vertices, (Real32)x1, (Real32)y, (Real32)z2, col); vertices++; v.Z = (Real32)z2; *vertices = v; vertices++;
VertexP3fC4b_Set(vertices, (Real32)x2, (Real32)y, (Real32)z2, col); vertices++; v.X = (Real32)x2; *vertices = v; vertices++;
VertexP3fC4b_Set(vertices, (Real32)x2, (Real32)y, (Real32)z1, col); vertices++; v.Z = (Real32)z1; *vertices = v; vertices++;
} }
} }
} }
@ -172,6 +174,8 @@ void EnvRenderer_DrawCloudsY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, In
Int32 endX = x2, endZ = z2, startZ = z1; Int32 endX = x2, endZ = z2, startZ = z1;
/* adjust range so that largest negative uv coordinate is shifted to 0 or above. */ /* adjust range so that largest negative uv coordinate is shifted to 0 or above. */
Real32 offset = (Real32)Math_CeilDiv(-x1, 2048); Real32 offset = (Real32)Math_CeilDiv(-x1, 2048);
VertexP3fT2fC4b v;
v.Y = (Real32)y + 0.1f; v.Colour = col;
for (; x1 < endX; x1 += axisSize) { for (; x1 < endX; x1 += axisSize) {
x2 = x1 + axisSize; x2 = x1 + axisSize;
@ -181,14 +185,12 @@ void EnvRenderer_DrawCloudsY(Int32 x1, Int32 z1, Int32 x2, Int32 z2, Int32 y, In
z2 = z1 + axisSize; z2 = z1 + axisSize;
if (z2 > endZ) z2 = endZ; if (z2 > endZ) z2 = endZ;
VertexP3fT2fC4b_Set(vertices, (Real32)x1, (Real32)y + 0.1f, (Real32)z1, Real32 u1 = (Real32)x1 / 2048.0f + offset, u2 = (Real32)x2 / 2048.0f + offset;
(Real32)x1 / 2048.0f + offset, (Real32)z1 / 2048.0f + offset, col); vertices++; Real32 v1 = (Real32)z1 / 2048.0f + offset, v2 = (Real32)z2 / 2048.0f + offset;
VertexP3fT2fC4b_Set(vertices, (Real32)x1, (Real32)y + 0.1f, (Real32)z2, v.X = (Real32)x1; v.Z = (Real32)z1; v.U = u1; v.V = v1; *vertices = v; vertices++;
(Real32)x1 / 2048.0f + offset, (Real32)z2 / 2048.0f + offset, col); vertices++; v.Z = (Real32)z2; v.V = v2; *vertices = v; vertices++;
VertexP3fT2fC4b_Set(vertices, (Real32)x2, (Real32)y + 0.1f, (Real32)z2, v.X = (Real32)x2; v.U = u2; *vertices = v; vertices++;
(Real32)x2 / 2048.0f + offset, (Real32)z2 / 2048.0f + offset, col); vertices++; v.Z = (Real32)z1; v.V = v1; *vertices = v; vertices++;
VertexP3fT2fC4b_Set(vertices, (Real32)x2, (Real32)y + 0.1f, (Real32)z1,
(Real32)x2 / 2048.0f + offset, (Real32)z1 / 2048.0f + offset, col); vertices++;
} }
} }
} }

View File

@ -32,6 +32,7 @@ void Physics_OnNewMapLoaded(void) {
Tree_Width = World_Width; Tree_Height = World_Height; Tree_Length = World_Length; Tree_Width = World_Width; Tree_Height = World_Height; Tree_Length = World_Length;
Tree_Blocks = World_Blocks; Tree_Blocks = World_Blocks;
Random_InitFromCurrentTime(&physics_rnd);
Tree_Rnd = &physics_rnd; Tree_Rnd = &physics_rnd;
} }

View File

@ -6,21 +6,15 @@
Copyright 2014 - 2017 ClassicalSharp | Licensed under BSD-3 Copyright 2014 - 2017 ClassicalSharp | Licensed under BSD-3
*/ */
typedef Int64 Random; typedef Int64 Random;
/* Initalises the random number generator with an initial given seed. */ /* Initalises the random number generator with an initial given seed. */
void Random_Init(Random* rnd, Int32 seed); void Random_Init(Random* rnd, Int32 seed);
/* Initalises the random number generator with an initial see based on current time. */ /* Initalises the random number generator with an initial see based on current time. */
void Random_InitFromCurrentTime(Random* rnd); void Random_InitFromCurrentTime(Random* rnd);
/* Returns a random number between min inclusive and max exclusive. */ /* Returns a random number between min inclusive and max exclusive. */
Int32 Random_Range(Random* rnd, Int32 min, Int32 max); Int32 Random_Range(Random* rnd, Int32 min, Int32 max);
/* Returns a random number from 0 inclusive to n exlucisve. */ /* Returns a random number from 0 inclusive to n exlucisve. */
Int32 Random_Next(Random* rnd, Int32 n); Int32 Random_Next(Random* rnd, Int32 n);
/* Returns a random number between 0 inclusive and 1 exlusive. */ /* Returns a random number between 0 inclusive and 1 exlusive. */
Real32 Random_Float(Random* rnd); Real32 Random_Float(Random* rnd);
#endif #endif