Cleanup enumerations

This commit is contained in:
UnknownShadow200 2017-05-20 15:33:07 +10:00
parent 9e9cfae15f
commit 7842ee5675
8 changed files with 106 additions and 95 deletions

View file

@ -93,17 +93,17 @@ void Block_ResetProps(BlockID block) {
if (block >= Block_CpeCount) {
#if USE16_BIT
/* give some random texture ids */
Block_SetTex((block * 10 + (block % 7) + 20) % 80, Side_Top, block);
Block_SetTex((block * 8 + (block & 5) + 5) % 80, Side_Bottom, block);
Block_SetTex((block * 10 + (block % 7) + 20) % 80, Face_YTop, block);
Block_SetTex((block * 8 + (block & 5) + 5) % 80, Face_YMin, block);
Block_SetSide((block * 4 + (block / 4) + 4) % 80, block);
#else
Block_SetTex(0, Side_Top, block);
Block_SetTex(0, Side_Bottom, block);
Block_SetTex(0, Face_YTop, block);
Block_SetTex(0, Face_YMin, block);
Block_SetSide(0, block);
#endif
} else {
Block_SetTex(topTex[block], Side_Top, block);
Block_SetTex(bottomTex[block], Side_Bottom, block);
Block_SetTex(topTex[block], Face_YTop, block);
Block_SetTex(bottomTex[block], Face_YMin, block);
Block_SetSide(sideTex[block], block);
}
}
@ -163,52 +163,52 @@ static void Block_SplitUppercase(String* buffer, String* blockNames, Int32 start
void Block_SetSide(TextureID textureId, BlockID blockId) {
Int32 index = blockId * Side_Sides;
Block_Textures[index + Side_Left] = textureId;
Block_Textures[index + Side_Right] = textureId;
Block_Textures[index + Side_Front] = textureId;
Block_Textures[index + Side_Back] = textureId;
Int32 index = blockId * Face_Count;
Block_Textures[index + Face_XMin] = textureId;
Block_Textures[index + Face_XMax] = textureId;
Block_Textures[index + Face_ZMin] = textureId;
Block_Textures[index + Face_ZMax] = textureId;
}
void Block_SetTex(TextureID textureId, Int32 face, BlockID blockId) {
Block_Textures[blockId * Side_Sides + face] = textureId;
void Block_SetTex(TextureID textureId, Face face, BlockID blockId) {
Block_Textures[blockId * Face_Count + face] = textureId;
}
TextureID Block_GetTextureLoc(BlockID block, Int32 face) {
return Block_Textures[block * Side_Sides + face];
TextureID Block_GetTex(BlockID block, Face face) {
return Block_Textures[block * Face_Count + face];
}
void Block_GetTextureRegion(BlockID block, Int32 side, Vector2* min, Vector2* max) {
void Block_GetTextureRegion(BlockID block, Face face, Vector2* min, Vector2* max) {
*min = Vector2_Zero; *max = Vector2_One;
Vector3 bbMin = Block_MinBB[block], bbMax = Block_MaxBB[block];
switch (side) {
case Side_Left:
case Side_Right:
switch (face) {
case Face_XMin:
case Face_XMax:
*min = Vector2_Create2(bbMin.Z, bbMin.Y);
*max = Vector2_Create2(bbMax.Z, bbMax.Y);
if (Block_IsLiquid(block)) max->Y -= 1.5f / 16.0f;
break;
case Side_Front:
case Side_Back:
case Face_ZMin:
case Face_ZMax:
*min = Vector2_Create2(bbMin.X, bbMin.Y);
*max = Vector2_Create2(bbMax.X, bbMax.Y);
if (Block_IsLiquid(block)) max->Y -= 1.5f / 16.0f;
break;
case Side_Top:
case Side_Bottom:
case Face_YTop:
case Face_YMin:
*min = Vector2_Create2(bbMin.X, bbMin.Z);
*max = Vector2_Create2(bbMax.X, bbMax.Z);
break;
}
}
bool Block_FaceOccluded(BlockID block, BlockID other, Int32 side) {
bool Block_FaceOccluded(BlockID block, BlockID other, Face face) {
Vector2 bMin, bMax, oMin, oMax;
Block_GetTextureRegion(block, side, &bMin, &bMax);
Block_GetTextureRegion(other, side, &oMin, &oMax);
Block_GetTextureRegion(block, face, &bMin, &bMax);
Block_GetTextureRegion(other, face, &oMin, &oMax);
return bMin.X >= oMin.X && bMin.Y >= oMin.Y
&& bMax.X <= oMax.X && bMax.Y <= oMax.Y;
@ -236,14 +236,14 @@ UInt8 Block_CalcLightOffset(BlockID block) {
Int32 flags = 0xFF;
Vector3 min = Block_MinBB[block], max = Block_MaxBB[block];
if (min.X != 0) flags &= ~(1 << Side_Left);
if (max.X != 1) flags &= ~(1 << Side_Right);
if (min.Z != 0) flags &= ~(1 << Side_Front);
if (max.Z != 1) flags &= ~(1 << Side_Back);
if (min.X != 0) flags &= ~(1 << Face_XMin);
if (max.X != 1) flags &= ~(1 << Face_XMax);
if (min.Z != 0) flags &= ~(1 << Face_ZMin);
if (max.Z != 1) flags &= ~(1 << Face_ZMax);
if ((min.Y != 0 && max.Y == 1) && Block_Draw[block] != DrawType_Gas) {
flags &= ~(1 << Side_Top);
flags &= ~(1 << Side_Bottom);
flags &= ~(1 << Face_YTop);
flags &= ~(1 << Face_YMin);
}
return (UInt8)flags;
}
@ -260,7 +260,7 @@ void Block_RecalculateSpriteBB() {
void Block_RecalculateBB(BlockID block) {
Bitmap* bmp = &Atlas2D_Bitmap;
Int32 elemSize = Atlas2D_ElementSize;
TextureID texId = Block_GetTextureLoc(block, Side_Right);
TextureID texId = Block_GetTex(block, Face_XMax);
Int32 texX = texId & 0x0F, texY = texId >> 4;
Real32 topY = Block_GetSpriteBB_TopY(elemSize, texX, texY, bmp);
@ -360,30 +360,30 @@ void Block_CalcCulling(BlockID block, BlockID other) {
if (Block_IsLiquid(other)) oMax.Y -= 1.5f / 16;
if (Block_Draw[block] == DrawType_Sprite) {
Block_SetHidden(block, other, Side_Left, true);
Block_SetHidden(block, other, Side_Right, true);
Block_SetHidden(block, other, Side_Front, true);
Block_SetHidden(block, other, Side_Back, true);
Block_SetHidden(block, other, Side_Bottom, oMax.Y == 1);
Block_SetHidden(block, other, Side_Top, bMax.Y == 1);
Block_SetHidden(block, other, Face_XMin, true);
Block_SetHidden(block, other, Face_XMax, true);
Block_SetHidden(block, other, Face_ZMin, true);
Block_SetHidden(block, other, Face_ZMax, true);
Block_SetHidden(block, other, Face_YMin, oMax.Y == 1);
Block_SetHidden(block, other, Face_YTop, bMax.Y == 1);
} else {
Block_SetXStretch(block, bMin.X == 0 && bMax.X == 1);
Block_SetZStretch(block, bMin.Z == 0 && bMax.Z == 1);
bool bothLiquid = Block_IsLiquid(block) && Block_IsLiquid(other);
Block_SetHidden(block, other, Side_Left, oMax.X == 1 && bMin.X == 0);
Block_SetHidden(block, other, Side_Right, oMin.X == 0 && bMax.X == 1);
Block_SetHidden(block, other, Side_Front, oMax.Z == 1 && bMin.Z == 0);
Block_SetHidden(block, other, Side_Back, oMin.Z == 0 && bMax.Z == 1);
Block_SetHidden(block, other, Face_XMin, oMax.X == 1 && bMin.X == 0);
Block_SetHidden(block, other, Face_XMax, oMin.X == 0 && bMax.X == 1);
Block_SetHidden(block, other, Face_ZMin, oMax.Z == 1 && bMin.Z == 0);
Block_SetHidden(block, other, Face_ZMax, oMin.Z == 0 && bMax.Z == 1);
Block_SetHidden(block, other, Side_Bottom,
Block_SetHidden(block, other, Face_YMin,
bothLiquid || (oMax.Y == 1 && bMin.Y == 0));
Block_SetHidden(block, other, Side_Top,
Block_SetHidden(block, other, Face_YTop,
bothLiquid || (oMin.Y == 0 && bMax.Y == 1));
}
}
bool Block_IsHidden(BlockID block, BlockID other, Int32 side) {
bool Block_IsHidden(BlockID block, BlockID other, Face face) {
/* Sprite blocks can never hide faces. */
if (Block_Draw[block] == DrawType_Sprite) return false;
@ -406,18 +406,18 @@ bool Block_IsHidden(BlockID block, BlockID other, Int32 side) {
return canSkip;
}
void Block_SetHidden(BlockID block, BlockID other, Int32 side, bool value) {
value = Block_IsHidden(block, other, side) && Block_FaceOccluded(block, other, side) && value;
void Block_SetHidden(BlockID block, BlockID other, Face face, bool value) {
value = Block_IsHidden(block, other, face) && Block_FaceOccluded(block, other, face) && value;
int bit = value ? 1 : 0;
Block_Hidden[block * Block_Count + other] &= (UInt8)~(1 << side);
Block_Hidden[block * Block_Count + other] |= (UInt8)(bit << side);
Block_Hidden[block * Block_Count + other] &= (UInt8)~(1 << face);
Block_Hidden[block * Block_Count + other] |= (UInt8)(bit << face);
}
bool Block_IsFaceHidden(BlockID block, BlockID other, Int32 side) {
bool Block_IsFaceHidden(BlockID block, BlockID other, Face face) {
#if USE16_BIT
return (hidden[(block << 12) | other] & (1 << side)) != 0;
return (hidden[(block << 12) | other] & (1 << face)) != 0;
#else
return (Block_Hidden[(block << 8) | other] & (1 << side)) != 0;
return (Block_Hidden[(block << 8) | other] & (1 << face)) != 0;
#endif
}

View file

@ -38,10 +38,10 @@ PackedCol Block_FogColour[Block_Count];
Real32 Block_FogDensity[Block_Count];
/* Gets the basic collision type for the given block. */
UInt8 Block_Collide[Block_Count];
CollideType Block_Collide[Block_Count];
/* Gets the action performed when colliding with the given block. */
UInt8 Block_ExtendedCollide[Block_Count];
CollideType Block_ExtendedCollide[Block_Count];
/* Speed modifier when colliding (or standing on for solid collide type) with the given block. */
Real32 Block_SpeedMultiplier[Block_Count];
@ -50,7 +50,7 @@ Real32 Block_SpeedMultiplier[Block_Count];
UInt8 Block_LightOffset[Block_Count];
/* Gets the DrawType for the given block. */
UInt8 Block_Draw[Block_Count];
DrawType Block_Draw[Block_Count];
/* Gets whether the given block has an opaque draw type and is also a full tile block.
Full tile block means Min of (0, 0, 0) and max of (1, 1, 1).*/
@ -59,10 +59,10 @@ bool Block_FullOpaque[Block_Count];
UInt32 DefinedCustomBlocks[Block_Count >> 5];
/* Gets the dig sound ID for the given block. */
UInt8 Block_DigSounds[Block_Count];
SoundType Block_DigSounds[Block_Count];
/* Gets the step sound ID for the given block. */
UInt8 Block_StepSounds[Block_Count];
SoundType Block_StepSounds[Block_Count];
/* Gets whether the given block has a tinting colour applied to it when rendered.
The tinting colour used is the block's fog colour. */
@ -83,7 +83,7 @@ Vector3 Block_RenderMinBB[Block_Count];
Vector3 Block_RenderMaxBB[Block_Count];
#define Block_TexturesCount Block_Count * Side_Sides
#define Block_TexturesCount Block_Count * Face_Count
/* Raw texture ids of each face of each block. */
TextureID Block_Textures[Block_TexturesCount];
@ -141,10 +141,10 @@ void Block_RecalculateBB(BlockID block);
void Block_SetSide(TextureID textureId, BlockID blockId);
/* Sets the texture for the given face of the given block. */
void Block_SetTex(TextureID textureId, Int32 face, BlockID blockId);
void Block_SetTex(TextureID textureId, Face face, BlockID blockId);
/* Gets the texture ID of the given face of the given block. */
TextureID Block_GetTextureLoc(BlockID block, Int32 face);
TextureID Block_GetTex(BlockID block, Face face);
/* Recalculates culling state for all blocks. */
@ -155,7 +155,7 @@ void Block_UpdateCulling(BlockID block);
/* Returns whether the face at the given face of the block
should be drawn with the neighbour 'other' present on the other side of the face. */
bool Block_IsFaceHidden(BlockID block, BlockID other, Int32 side);
bool Block_IsFaceHidden(BlockID block, BlockID other, Face face);
static String Block_DefaultName(BlockID block);
@ -172,33 +172,33 @@ static Real32 Block_GetSpriteBB_LeftX(Int32 size, Int32 tileX, Int32 tileY, Bitm
static Real32 Block_GetSpriteBB_RightX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp);
static void Block_GetTextureRegion(BlockID block, Int32 side, Vector2* min, Vector2* max);
static void Block_GetTextureRegion(BlockID block, Face face, Vector2* min, Vector2* max);
static bool Block_FaceOccluded(BlockID block, BlockID other, Int32 side);
static bool Block_FaceOccluded(BlockID block, BlockID other, Face face);
static void Block_CalcCulling(BlockID block, BlockID other);
void Block_SetHidden(BlockID block, BlockID other, Int32 side, bool value);
void Block_SetHidden(BlockID block, BlockID other, Face face, bool value);
static bool Block_IsHidden(BlockID block, BlockID other, Int32 side);
static bool Block_IsHidden(BlockID block, BlockID other, Face face);
static void Block_SetXStretch(BlockID block, bool stretch);
static void Block_SetZStretch(BlockID block, bool stretch);
static UInt8 topTex[Block_CpeCount] = { 0, 1, 0, 2, 16, 4, 15, 17, 14, 14,
static TextureID topTex[Block_CpeCount] = { 0, 1, 0, 2, 16, 4, 15, 17, 14, 14,
30, 30, 18, 19, 32, 33, 34, 21, 22, 48, 49, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 13, 12, 29, 28, 24, 23, 6, 6, 7, 9, 4,
36, 37, 16, 11, 25, 50, 38, 80, 81, 82, 83, 84, 51, 54, 86, 26, 53, 52, };
static UInt8 sideTex[Block_CpeCount] = { 0, 1, 3, 2, 16, 4, 15, 17, 14, 14,
static TextureID sideTex[Block_CpeCount] = { 0, 1, 3, 2, 16, 4, 15, 17, 14, 14,
30, 30, 18, 19, 32, 33, 34, 20, 22, 48, 49, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 13, 12, 29, 28, 40, 39, 5, 5, 7, 8, 35,
36, 37, 16, 11, 41, 50, 38, 80, 81, 82, 83, 84, 51, 54, 86, 42, 53, 52, };
static UInt8 bottomTex[Block_CpeCount] = { 0, 1, 2, 2, 16, 4, 15, 17, 14, 14,
static TextureID bottomTex[Block_CpeCount] = { 0, 1, 2, 2, 16, 4, 15, 17, 14, 14,
30, 30, 18, 19, 32, 33, 34, 21, 22, 48, 49, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 13, 12, 29, 28, 56, 55, 6, 6, 7, 10, 4,
36, 37, 16, 11, 57, 50, 38, 80, 81, 82, 83, 84, 51, 54, 86, 58, 53, 52 };

View file

@ -1,29 +1,31 @@
#ifndef CS_BLOCKENUMS_H
#define CS_BLOCKENUMS_H
#include "Typedefs.h"
/* Block related enumerations.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
/* Sides of a block. */
typedef UInt8 Face;
/* Face X = 0. */
#define Side_Left 0
#define Face_XMin 0
/* Face X = 1. */
#define Side_Right 1
/* Face Z = 0. */
#define Side_Front 2
/* Face Z = 1. */
#define Side_Back 3
#define Face_XMax 1
/* Face Y = 0. */
#define Side_Bottom 4
#define Face_YMin 2
/* Face Y = 1. */
#define Side_Top 5
/* Number of sides on a cube. */
#define Side_Sides 6
#define Face_YTop 3
/* Face Z = 0. */
#define Face_ZMin 4
/* Face Z = 1. */
#define Face_ZMax 5
/* Number of faces on a cube. */
#define Face_Count 6
/* Sound types for blocks. */
typedef UInt8 SoundType;
#define SoundType_None 0
#define SoundType_Wood 1
#define SoundType_Gravel 2
@ -37,6 +39,7 @@
/* Describes how a block is rendered in the world. */
typedef UInt8 DrawType;
/* Completely covers blocks behind (e.g. dirt). */
#define DrawType_Opaque 0
/* Blocks behind show (e.g. glass). Pixels are either fully visible or invisible. */
@ -52,6 +55,7 @@
/* Describes the interaction a block has with a player when they collide with it. */
typedef UInt8 CollideType;
/* No interaction when player collides. */
#define CollideType_Gas 0
/* 'swimming'/'bobbing' interaction when player collides. */

View file

@ -30,7 +30,7 @@ PackedCol DefaultSet_FogColour(BlockID b) {
return PackedCol_Create4(0, 0, 0, 0);
}
UInt8 DefaultSet_Collide(BlockID b) {
CollideType DefaultSet_Collide(BlockID b) {
if (b == BlockID_Ice) return CollideType_Ice;
if (b == BlockID_Water || b == BlockID_StillWater)
return CollideType_LiquidWater;
@ -42,7 +42,7 @@ UInt8 DefaultSet_Collide(BlockID b) {
return CollideType_Solid;
}
UInt8 DefaultSet_MapOldCollide(BlockID b, UInt8 collide) {
CollideType DefaultSet_MapOldCollide(BlockID b, CollideType collide) {
if (b == BlockID_Ice && collide == CollideType_Solid)
return CollideType_Ice;
if ((b == BlockID_Water || b == BlockID_StillWater) && collide == CollideType_Liquid)
@ -57,15 +57,14 @@ bool DefaultSet_BlocksLight(BlockID b) {
|| b == BlockID_Air || DefaultSet_Draw(b) == DrawType_Sprite);
}
UInt8 DefaultSet_StepSound(BlockID b) {
SoundType DefaultSet_StepSound(BlockID b) {
if (b == BlockID_Glass) return SoundType_Stone;
if (b == BlockID_Rope) return SoundType_Cloth;
if (DefaultSet_Draw(b) == DrawType_Sprite) return SoundType_None;
return DefaultSet_DigSound(b);
}
UInt8 DefaultSet_Draw(BlockID b) {
DrawType DefaultSet_Draw(BlockID b) {
if (b == BlockID_Air || b == BlockID_Invalid) return DrawType_Gas;
if (b == BlockID_Leaves) return DrawType_TransparentThick;
@ -81,7 +80,7 @@ UInt8 DefaultSet_Draw(BlockID b) {
return DrawType_Opaque;
}
UInt8 DefaultSet_DigSound(BlockID b) {
SoundType DefaultSet_DigSound(BlockID b) {
if (b >= BlockID_Red && b <= BlockID_White)
return SoundType_Cloth;
if (b >= BlockID_LightPink && b <= BlockID_Turquoise)

View file

@ -1,6 +1,7 @@
#ifndef CS_DEFAULT_BLOCKS_H
#define CS_DEFAULT_BLOCKS_H
#include "Typedefs.h"
#include "BlockEnums.h"
#include "PackedCol.h"
/* List of properties for core blocks.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
@ -19,20 +20,20 @@ Real32 DefaultSet_FogDensity(BlockID b);
PackedCol DefaultSet_FogColour(BlockID b);
/* Gets the collide type of a block. */
UInt8 DefaultSet_Collide(BlockID b);
CollideType DefaultSet_Collide(BlockID b);
/* Gets a backwards compatible collide type of a block. */
UInt8 DefaultSet_MapOldCollide(BlockID b, UInt8 collide);
CollideType DefaultSet_MapOldCollide(BlockID b, CollideType collide);
/* Gets whether the given block prevents light passing through it. */
bool DefaultSet_BlocksLight(BlockID b);
/* Gets the ID of the sound played when stepping on this block. */
UInt8 DefaultSet_StepSound(BlockID b);
SoundType DefaultSet_StepSound(BlockID b);
/* Gets the type of method used to draw/render this block. */
UInt8 DefaultSet_Draw(BlockID b);
DrawType DefaultSet_Draw(BlockID b);
/* Gets the ID of the sound played when deleting/placing this block. */
UInt8 DefaultSet_DigSound(BlockID b);
SoundType DefaultSet_DigSound(BlockID b);
#endif

View file

@ -1,6 +1,9 @@
#ifndef CS_NETWORKENUMS_H
#define CS_NETWORKSENUM_H
#include "Typedefs.h"
/* Network packet opcodes. */
typedef UInt8 Opcode;
#define Opcode_Handshake 0
#define Opcode_Ping 1
#define Opcode_LevelInit 2
@ -46,6 +49,9 @@
#define Opcode_CpeSetMapEnvProperty 41
#define Opcode_CpeSetEntityProperty 42
/* Chat message types.*/
typedef UInt8 MessageType;
/* CPE message types */
#define MessageType_Normal 0

View file

@ -1,6 +1,7 @@
#include "Typedefs.h"
#include "Vector3I.h"
#include "Vectors.h"
#include "BlockEnums.h"
/* Describes the picked/selected block by the user and its position. */
typedef struct PickedPos {
@ -24,16 +25,16 @@ typedef struct PickedPos {
bool Valid;
/* Face of the picked block that is closet to the player. */
BlockFace Face;
Face ClosestFace;
/* Block ID of the picked block. */
BlockID Block;
} PickedPos;
/* Mark as having a selected block, and calculates the closest face of the selected block's position. */
void PickedPos_SetAsValid(PickedPos* pos, int x, int y, int z, Vector3 min, Vector3 max);
void PickedPos_SetAsValid(PickedPos* pos, Int32 x, Int32 y, Int32 z, Vector3 min, Vector3 max);
/* Marks as not having a selected block. */
void PickedPos_SetAsInvalid(PickedPos* pos);
static void PickedPos_TestAxis(float dAxis, float* dist, BlockFace fAxis);
static void PickedPos_TestAxis(Real32 dAxis, Real32* dist, Face face);

View file

@ -41,7 +41,7 @@ void WeatherRenderer_Init() {
void WeatherRenderer_Render(Real64 deltaTime) {
Int32 weather = WorldEnv_Weather;
if (weather == Weather_Sunny) return;
if (weather_heightmap == NULL) InitHeightmap();
if (weather_heightmap == NULL) WeatherRenderer_InitHeightmap();
Gfx_BindTexture(weather == Weather_Rainy ? weather_rainTex : weather_snowTex);
Vector3 camPos = Game_CurrentCameraPos;