Skip to content
Permalink
Browse files

Merge pull request #606 from UnknownShadow200/ColRewrite

Col rewrite
  • Loading branch information...
UnknownShadow200 committed Oct 5, 2019
2 parents 5675887 + 7d9a18a commit 97241ac63c243aa5320e84b621782bf76d868239
Showing with 267 additions and 266 deletions.
  1. +3 −3 src/AxisLinesRenderer.c
  2. +2 −0 src/Bitmap.h
  3. +5 −6 src/Block.c
  4. +1 −6 src/Block.h
  5. +20 −17 src/Builder.c
  6. +30 −13 src/Core.h
  7. +6 −16 src/Drawer.c
  8. +4 −4 src/EntityComponents.c
  9. +13 −13 src/EnvRenderer.c
  10. +13 −20 src/Formats.c
  11. +13 −12 src/Graphics.c
  12. +4 −5 src/Launcher.c
  13. +19 −15 src/Menus.c
  14. +24 −21 src/PackedCol.c
  15. +37 −18 src/PackedCol.h
  16. +1 −6 src/Particle.c
  17. +1 −1 src/PickedPosRenderer.c
  18. +18 −31 src/Protocol.c
  19. +6 −6 src/Screens.c
  20. +3 −2 src/SelectionBox.c
  21. +22 −24 src/Widgets.c
  22. +1 −1 src/Window.c
  23. +14 −24 src/World.c
  24. +7 −2 src/World.h
@@ -20,9 +20,9 @@ void AxisLinesRenderer_Render(double delta) {
1,2,3, 1,4,3, 3,4,1, 3,2,1, /* Y arrow */
};
static const PackedCol cols[3] = {
PACKEDCOL_CONST(255, 0, 0, 255), /* Red */
PACKEDCOL_CONST( 0, 0, 255, 255), /* Blue */
PACKEDCOL_CONST( 0, 255, 0, 255), /* Green */
PackedCol_Make(255, 0, 0, 255), /* Red */
PackedCol_Make( 0, 0, 255, 255), /* Blue */
PackedCol_Make( 0, 255, 0, 255), /* Green */
};

Vec3 coords[5], pos;
@@ -18,6 +18,8 @@ typedef union BitmapCol_ {

/* Whether components of two colours are all equal. */
#define BitmapCol_Equals(a,b) ((a)._raw == (b)._raw)
#define PackedCol_ARGB(r, g, b, a) (((cc_uint32)(r) << 16) | ((cc_uint32)(g) << 8) | ((cc_uint32)(b)) | ((cc_uint32)(a) << 24))


/* A 2D array of BitmapCol pixels */
typedef struct Bitmap_ { cc_uint8* Scan0; int Width, Height; } Bitmap;
@@ -38,13 +38,12 @@ static float DefaultSet_FogDensity(BlockID b) {
}

static PackedCol DefaultSet_FogColour(BlockID b) {
PackedCol colWater = PACKEDCOL_CONST( 5, 5, 51, 255);
PackedCol colLava = PACKEDCOL_CONST(153, 25, 0, 255);
PackedCol colZero = PACKEDCOL_CONST( 0, 0, 0, 0);
PackedCol colWater = PackedCol_Make( 5, 5, 51, 255);
PackedCol colLava = PackedCol_Make(153, 25, 0, 255);

if (b == BLOCK_WATER || b == BLOCK_STILL_WATER) return colWater;
if (b == BLOCK_LAVA || b == BLOCK_STILL_LAVA) return colLava;
return colZero;
return 0;
}

static cc_uint8 DefaultSet_Draw(BlockID b) {
@@ -156,9 +155,9 @@ void Block_SetCustomDefined(BlockID block, bool defined) {
}

void Block_DefineCustom(BlockID block) {
PackedCol black = PACKEDCOL_CONST(0, 0, 0, 255);
PackedCol black = PackedCol_Make(0, 0, 0, 255);
String name = Block_UNSAFE_GetName(block);
Blocks.Tinted[block] = !PackedCol_Equals(Blocks.FogCol[block], black) && String_IndexOf(&name, '#') >= 0;
Blocks.Tinted[block] = Blocks.FogCol[block] != black && String_IndexOf(&name, '#') >= 0;

Block_SetDrawType(block, Blocks.Draw[block]);
Block_CalcRenderBounds(block);
@@ -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);
@@ -533,7 +533,6 @@ static void Builder_DrawSprite(int count) {
*--------------------------------------------------Normal mesh builder----------------------------------------------------*
*#########################################################################################################################*/
static PackedCol Normal_LightCol(int x, int y, int z, Face face, BlockID block) {
PackedCol invalid = PACKEDCOL_CONST(0, 0, 0, 0);
int offset = (Blocks.LightOffset[block] >> face) & 1;

switch (face) {
@@ -550,7 +549,7 @@ static PackedCol Normal_LightCol(int x, int y, int z, Face face, BlockID block)
case FACE_YMAX:
return y >= World.MaxY ? Env.SunCol : Lighting_Col_YMax_Fast(x, (y + 1) - offset, z);
}
return invalid; /* should never happen */
return 0; /* should never happen */
}

static bool Normal_CanStretch(BlockID initial, int chunkIndex, int x, int y, int z, Face face) {
@@ -559,8 +558,7 @@ static bool Normal_CanStretch(BlockID initial, int chunkIndex, int x, int y, int
if (cur != initial || Block_IsFaceHidden(cur, Builder_Chunk[chunkIndex + Builder_Offsets[face]], face)) return false;
if (Builder_FullBright) return true;

return PackedCol_Equals(Normal_LightCol(Builder_X, Builder_Y, Builder_Z, face, initial),
Normal_LightCol(x, y, z, face, cur));
return Normal_LightCol(Builder_X, Builder_Y, Builder_Z, face, initial) == Normal_LightCol(x, y, z, face, cur);
}

static int NormalBuilder_StretchXLiquid(int countIndex, int x, int y, int z, int chunkIndex, BlockID block) {
@@ -920,7 +918,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 +940,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 +982,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 +1024,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 +1066,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 +1108,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 +1150,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];
@@ -26,7 +26,12 @@ typedef unsigned int cc_uintptr;
#define CC_API __declspec(dllexport, noinline)
#define CC_VAR __declspec(dllexport)
#endif

#define CC_HAS_TYPES
#define CC_HAS_MISC
#elif __GNUC__
/* really old GCC/clang might not have these */
#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ cc_int8;
typedef __INT16_TYPE__ cc_int16;
typedef __INT32_TYPE__ cc_int32;
@@ -46,6 +51,8 @@ typedef unsigned __INT32_TYPE__ cc_uint32;
typedef unsigned __INT64_TYPE__ cc_uint64;
typedef unsigned __INTPTR_TYPE__ cc_uintptr;
#endif
#define CC_HAS_TYPES
#endif

#define CC_INLINE inline
#define CC_NOINLINE __attribute__((noinline))
@@ -58,24 +65,34 @@ typedef unsigned __INTPTR_TYPE__ cc_uintptr;
#define CC_VAR __attribute__((visibility("default")))
#endif
#endif
#define CC_HAS_MISC
#ifdef __BIG_ENDIAN__
#define CC_BIG_ENDIAN
#endif
#elif __MWERKS__
typedef signed char cc_int8;
typedef signed short int cc_int16;
typedef signed long int cc_int32;
typedef signed long long cc_int64;

typedef unsigned char cc_uint8;
typedef unsigned short int cc_uint16;
typedef unsigned long int cc_uint32;
typedef unsigned long long cc_uint64;
typedef unsigned long int cc_uintptr;
/* TODO: Is there actual attribute support for these somewhere? */
/* TODO: Is there actual attribute support for CC_API etc somewhere? */
#define CC_BIG_ENDIAN
#endif

/* Unrecognised compiler, so just go with sensisble defaults */
#ifndef CC_HAS_TYPES
#include <stdint.h>
typedef int8_t cc_int8;
typedef int16_t cc_int16;
typedef int32_t cc_int32;
typedef int64_t cc_int64;

typedef uint8_t cc_uint8;
typedef uint16_t cc_uint16;
typedef uint32_t cc_uint32;
typedef uint64_t cc_uint64;
typedef uintptr_t cc_uintptr;
#endif
#ifndef CC_HAS_MISC
#define CC_INLINE inline
#define CC_NOINLINE
#define CC_API
#define CC_VAR
#else
#error "Unknown compiler. You'll need to add required definitions in Core.h!"
#endif

typedef cc_uint16 Codepoint;
@@ -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;
@@ -457,7 +457,7 @@ struct ShadowData { float Y; BlockID Block; cc_uint8 A; };

static bool lequal(float a, float b) { return a < b || Math_AbsF(a - b) < 0.001f; }
static void ShadowComponent_DrawCoords(VertexP3fT2fC4b** vertices, struct Entity* e, struct ShadowData* data, float x1, float z1, float x2, float z2) {
PackedCol col = PACKEDCOL_CONST(255, 255, 255, 0);
PackedCol col;
VertexP3fT2fC4b* v;
Vec3 cen;
float u1, v1, u2, v2;
@@ -476,8 +476,8 @@ static void ShadowComponent_DrawCoords(VertexP3fT2fC4b** vertices, struct Entity
x2 = min(x2, cen.X + shadow_radius); u2 = u2 <= 1.0f ? u2 : 1.0f;
z2 = min(z2, cen.Z + shadow_radius); v2 = v2 <= 1.0f ? v2 : 1.0f;

v = *vertices;
col.A = data->A;
v = *vertices;
col = PackedCol_Make(255, 255, 255, data->A);

v->X = x1; v->Y = data->Y; v->Z = z1; v->Col = col; v->U = u1; v->V = v1; v++;
v->X = x2; v->Y = data->Y; v->Z = z1; v->Col = col; v->U = u2; v->V = v1; v++;
@@ -488,7 +488,7 @@ static void ShadowComponent_DrawCoords(VertexP3fT2fC4b** vertices, struct Entity
}

static void ShadowComponent_DrawSquareShadow(VertexP3fT2fC4b** vertices, float y, float x, float z) {
PackedCol col = PACKEDCOL_CONST(255, 255, 255, 220);
PackedCol col = PackedCol_Make(255, 255, 255, 220);
float uv1 = 63/128.0f, uv2 = 64/128.0f;
VertexP3fT2fC4b* v = *vertices;

@@ -324,23 +324,23 @@ void EnvRenderer_RenderSkybox(double deltaTime) {
static void EnvRenderer_UpdateSkybox(void) {
static VertexP3fT2fC4b vertices[SKYBOX_COUNT] = {
/* Front quad */
{ -1, -1, -1, {0,0,0,0}, 0.25f, 1.00f }, { 1, -1, -1, {0,0,0,0}, 0.50f, 1.00f },
{ 1, 1, -1, {0,0,0,0}, 0.50f, 0.50f }, { -1, 1, -1, {0,0,0,0}, 0.25f, 0.50f },
{ -1, -1, -1, 0, 0.25f, 1.00f }, { 1, -1, -1, 0, 0.50f, 1.00f },
{ 1, 1, -1, 0, 0.50f, 0.50f }, { -1, 1, -1, 0, 0.25f, 0.50f },
/* Left quad */
{ -1, -1, 1, {0,0,0,0}, 0.00f, 1.00f }, { -1, -1, -1, {0,0,0,0}, 0.25f, 1.00f },
{ -1, 1, -1, {0,0,0,0}, 0.25f, 0.50f }, { -1, 1, 1, {0,0,0,0}, 0.00f, 0.50f },
{ -1, -1, 1, 0, 0.00f, 1.00f }, { -1, -1, -1, 0, 0.25f, 1.00f },
{ -1, 1, -1, 0, 0.25f, 0.50f }, { -1, 1, 1, 0, 0.00f, 0.50f },
/* Back quad */
{ 1, -1, 1, {0,0,0,0}, 0.75f, 1.00f }, { -1, -1, 1, {0,0,0,0}, 1.00f, 1.00f },
{ -1, 1, 1, {0,0,0,0}, 1.00f, 0.50f }, { 1, 1, 1, {0,0,0,0}, 0.75f, 0.50f },
{ 1, -1, 1, 0, 0.75f, 1.00f }, { -1, -1, 1, 0, 1.00f, 1.00f },
{ -1, 1, 1, 0, 1.00f, 0.50f }, { 1, 1, 1, 0, 0.75f, 0.50f },
/* Right quad */
{ 1, -1, -1, {0,0,0,0}, 0.50f, 1.00f }, { 1, -1, 1, {0,0,0,0}, 0.75f, 1.00f },
{ 1, 1, 1, {0,0,0,0}, 0.75f, 0.50f }, { 1, 1, -1, {0,0,0,0}, 0.50f, 0.50f },
{ 1, -1, -1, 0, 0.50f, 1.00f }, { 1, -1, 1, 0, 0.75f, 1.00f },
{ 1, 1, 1, 0, 0.75f, 0.50f }, { 1, 1, -1, 0, 0.50f, 0.50f },
/* Top quad */
{ 1, 1, -1, {0,0,0,0}, 0.50f, 0.50f }, { 1, 1, 1, {0,0,0,0}, 0.50f, 0.00f },
{ -1, 1, 1, {0,0,0,0}, 0.25f, 0.00f }, { -1, 1, -1, {0,0,0,0}, 0.25f, 0.50f },
{ 1, 1, -1, 0, 0.50f, 0.50f }, { 1, 1, 1, 0, 0.50f, 0.00f },
{ -1, 1, 1, 0, 0.25f, 0.00f }, { -1, 1, -1, 0, 0.25f, 0.50f },
/* Bottom quad */
{ 1, -1, -1, {0,0,0,0}, 0.75f, 0.50f }, { 1, -1, 1, {0,0,0,0}, 0.75f, 0.00f },
{ -1, -1, 1, {0,0,0,0}, 0.50f, 0.00f }, { -1, -1, -1, {0,0,0,0}, 0.50f, 0.50f },
{ 1, -1, -1, 0, 0.75f, 0.50f }, { 1, -1, 1, 0, 0.75f, 0.00f },
{ -1, -1, 1, 0, 0.50f, 0.00f }, { -1, -1, -1, 0, 0.50f, 0.50f },
};
int i;

@@ -494,7 +494,7 @@ void EnvRenderer_RenderWeather(double deltaTime) {
dist = dx * dx + dz * dz;
alpha = EnvRenderer_RainAlphaAt((float)dist);
Math_Clamp(alpha, 0.0f, 255.0f);
col.A = (cc_uint8)alpha;
col = (col & PACKEDCOL_RGB_MASK) | PackedCol_A_Bits(alpha);

worldV = vOffset + (z & 1) / 2.0f - (x & 0x0F) / 16.0f;
v1 = y / 6.0f + worldV;

0 comments on commit 97241ac

Please sign in to comment.
You can’t perform that action at this time.