Make multiplying two colours a function instead of inline

Despite its appearance, it balloons to 30-40 instructions
This commit is contained in:
UnknownShadow200 2019-10-03 13:47:32 +10:00
parent 5675887e0e
commit ab1dc2418c
5 changed files with 34 additions and 35 deletions

View file

@ -103,12 +103,7 @@ CC_VAR extern struct _BlockLists {
} Blocks;
#define Block_Tint(col, block)\
if (Blocks.Tinted[block]) {\
PackedCol tintCol = Blocks.FogCol[block];\
col.R = (cc_uint8)(col.R * tintCol.R / 255);\
col.G = (cc_uint8)(col.G * tintCol.G / 255);\
col.B = (cc_uint8)(col.B * tintCol.B / 255);\
}
if (Blocks.Tinted[block]) col = PackedCol_Tint(col, Blocks.FogCol[block]);
/* Returns whether the given block has been changed from default. */
bool Block_IsCustomDefined(BlockID block);

View file

@ -920,7 +920,6 @@ static int Adv_StretchZ(int countIndex, int x, int y, int z, int chunkIndex, Blo
#define Adv_CountBits(F, a, b, c, d) (((F >> a) & 1) + ((F >> b) & 1) + ((F >> c) & 1) + ((F >> d) & 1))
#define Adv_Tint(c) c.R = (cc_uint8)(c.R * tint.R / 255); c.G = (cc_uint8)(c.G * tint.G / 255); c.B = (cc_uint8)(c.B * tint.B / 255);
static void Adv_DrawXMin(int count) {
TextureLoc texLoc = Block_Tex(Builder_Block, FACE_XMIN);
@ -943,8 +942,9 @@ static void Adv_DrawXMin(int count) {
VertexP3fT2fC4b* vertices, v;
if (Builder_Tinted) {
tint = Blocks.FogCol[Builder_Block];
Adv_Tint(col0_0); Adv_Tint(col1_0); Adv_Tint(col1_1); Adv_Tint(col0_1);
tint = Blocks.FogCol[Builder_Block];
col0_0 = PackedCol_Tint(col0_0, tint); col1_0 = PackedCol_Tint(col1_0, tint);
col1_1 = PackedCol_Tint(col1_1, tint); col0_1 = PackedCol_Tint(col0_1, tint);
}
vertices = part->fVertices[FACE_XMIN];
@ -984,8 +984,9 @@ static void Adv_DrawXMax(int count) {
VertexP3fT2fC4b* vertices, v;
if (Builder_Tinted) {
tint = Blocks.FogCol[Builder_Block];
Adv_Tint(col0_0); Adv_Tint(col1_0); Adv_Tint(col1_1); Adv_Tint(col0_1);
tint = Blocks.FogCol[Builder_Block];
col0_0 = PackedCol_Tint(col0_0, tint); col1_0 = PackedCol_Tint(col1_0, tint);
col1_1 = PackedCol_Tint(col1_1, tint); col0_1 = PackedCol_Tint(col0_1, tint);
}
vertices = part->fVertices[FACE_XMAX];
@ -1025,8 +1026,9 @@ static void Adv_DrawZMin(int count) {
VertexP3fT2fC4b* vertices, v;
if (Builder_Tinted) {
tint = Blocks.FogCol[Builder_Block];
Adv_Tint(col0_0); Adv_Tint(col1_0); Adv_Tint(col1_1); Adv_Tint(col0_1);
tint = Blocks.FogCol[Builder_Block];
col0_0 = PackedCol_Tint(col0_0, tint); col1_0 = PackedCol_Tint(col1_0, tint);
col1_1 = PackedCol_Tint(col1_1, tint); col0_1 = PackedCol_Tint(col0_1, tint);
}
vertices = part->fVertices[FACE_ZMIN];
@ -1066,8 +1068,9 @@ static void Adv_DrawZMax(int count) {
VertexP3fT2fC4b* vertices, v;
if (Builder_Tinted) {
tint = Blocks.FogCol[Builder_Block];
Adv_Tint(col0_0); Adv_Tint(col1_0); Adv_Tint(col1_1); Adv_Tint(col0_1);
tint = Blocks.FogCol[Builder_Block];
col0_0 = PackedCol_Tint(col0_0, tint); col1_0 = PackedCol_Tint(col1_0, tint);
col1_1 = PackedCol_Tint(col1_1, tint); col0_1 = PackedCol_Tint(col0_1, tint);
}
vertices = part->fVertices[FACE_ZMAX];
@ -1107,8 +1110,9 @@ static void Adv_DrawYMin(int count) {
VertexP3fT2fC4b* vertices, v;
if (Builder_Tinted) {
tint = Blocks.FogCol[Builder_Block];
Adv_Tint(col0_0); Adv_Tint(col1_0); Adv_Tint(col1_1); Adv_Tint(col0_1);
tint = Blocks.FogCol[Builder_Block];
col0_0 = PackedCol_Tint(col0_0, tint); col1_0 = PackedCol_Tint(col1_0, tint);
col1_1 = PackedCol_Tint(col1_1, tint); col0_1 = PackedCol_Tint(col0_1, tint);
}
vertices = part->fVertices[FACE_YMIN];
@ -1148,8 +1152,9 @@ static void Adv_DrawYMax(int count) {
VertexP3fT2fC4b* vertices, v;
if (Builder_Tinted) {
tint = Blocks.FogCol[Builder_Block];
Adv_Tint(col0_0); Adv_Tint(col1_0); Adv_Tint(col1_1); Adv_Tint(col0_1);
tint = Blocks.FogCol[Builder_Block];
col0_0 = PackedCol_Tint(col0_0, tint); col1_0 = PackedCol_Tint(col1_0, tint);
col1_1 = PackedCol_Tint(col1_1, tint); col0_1 = PackedCol_Tint(col0_1, tint);
}
vertices = part->fVertices[FACE_YMAX];

View file

@ -1,18 +1,8 @@
#include "Drawer.h"
#include "TexturePack.h"
#include "Constants.h"
struct _DrawerData Drawer;
/* Performance critical, use macro to ensure always inlined. */
#define ApplyTint \
if (Drawer.Tinted) {\
col.R = (cc_uint8)(col.R * Drawer.TintCol.R / 255);\
col.G = (cc_uint8)(col.G * Drawer.TintCol.G / 255);\
col.B = (cc_uint8)(col.B * Drawer.TintCol.B / 255);\
}
void Drawer_XMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b** vertices) {
VertexP3fT2fC4b* ptr = *vertices; VertexP3fT2fC4b v;
float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
@ -22,7 +12,7 @@ void Drawer_XMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);
v.X = Drawer.X1; v.Col = col;
v.Y = Drawer.Y2; v.Z = Drawer.Z2 + (count - 1); v.U = u2; v.V = v1; *ptr++ = v;
@ -41,7 +31,7 @@ void Drawer_XMax(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);
v.X = Drawer.X2; v.Col = col;
v.Y = Drawer.Y2; v.Z = Drawer.Z1; v.U = u1; v.V = v1; *ptr++ = v;
@ -60,7 +50,7 @@ void Drawer_ZMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);
v.Z = Drawer.Z1; v.Col = col;
v.X = Drawer.X2 + (count - 1); v.Y = Drawer.Y1; v.U = u2; v.V = v2; *ptr++ = v;
@ -79,7 +69,7 @@ void Drawer_ZMax(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
float v1 = vOrigin + Drawer.MaxBB.Y * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MinBB.Y * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);
v.Z = Drawer.Z2; v.Col = col;
v.X = Drawer.X2 + (count - 1); v.Y = Drawer.Y2; v.U = u2; v.V = v1; *ptr++ = v;
@ -98,7 +88,7 @@ void Drawer_YMin(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
float v1 = vOrigin + Drawer.MinBB.Z * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MaxBB.Z * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);
v.Y = Drawer.Y1; v.Col = col;
v.X = Drawer.X2 + (count - 1); v.Z = Drawer.Z2; v.U = u2; v.V = v2; *ptr++ = v;
@ -117,7 +107,7 @@ void Drawer_YMax(int count, PackedCol col, TextureLoc texLoc, VertexP3fT2fC4b**
float v1 = vOrigin + Drawer.MinBB.Z * Atlas1D.InvTileSize;
float v2 = vOrigin + Drawer.MaxBB.Z * Atlas1D.InvTileSize * UV2_Scale;
ApplyTint;
if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);
v.Y = Drawer.Y2; v.Col = col;
v.X = Drawer.X2 + (count - 1); v.Z = Drawer.Z1; v.U = u2; v.V = v1; *ptr++ = v;

View file

@ -15,6 +15,13 @@ PackedCol PackedCol_Lerp(PackedCol a, PackedCol b, float t) {
return a;
}
PackedCol PackedCol_Tint(PackedCol a, PackedCol b) {
a.R = (cc_uint8)(a.R * b.R / 255);
a.G = (cc_uint8)(a.G * b.G / 255);
a.B = (cc_uint8)(a.B * b.B / 255);
return a;
}
void PackedCol_GetShaded(PackedCol normal, PackedCol* xSide, PackedCol* zSide, PackedCol* yMin) {
*xSide = PackedCol_Scale(normal, PACKEDCOL_SHADE_X);
*zSide = PackedCol_Scale(normal, PACKEDCOL_SHADE_Z);

View file

@ -29,6 +29,8 @@ typedef union PackedCol_ {
CC_API PackedCol PackedCol_Scale(PackedCol value, float t);
/* Linearly interpolates RGB components of the two given colours. */
CC_API PackedCol PackedCol_Lerp(PackedCol a, PackedCol b, float t);
/* Multiplies RGB components of the two given colours. */
CC_API PackedCol PackedCol_Tint(PackedCol a, PackedCol b);
CC_NOINLINE bool PackedCol_Unhex(const char* src, int* dst, int count);
CC_NOINLINE void PackedCol_ToHex(String* str, PackedCol value);