remove static methods from Block C header

This commit is contained in:
UnknownShadow200 2017-09-11 22:12:03 +10:00
parent f5bd452765
commit 926b07b5c4
4 changed files with 47 additions and 117 deletions

View File

@ -70,7 +70,7 @@ namespace ClassicalSharp.Blocks {
public static SoundType StepSound(BlockID b) {
if (b == Block.Glass) return SoundType.Stone;
if (b == Block.Rope) return SoundType.Cloth;
if (b == Block.Rope) return SoundType.Cloth;
if (Draw(b) == DrawType.Sprite) return SoundType.None;
return DigSound(b);
}

View File

@ -267,26 +267,6 @@ void Block_RecalculateSpriteBB(void) {
}
}
void Block_RecalculateBB(BlockID block) {
Bitmap* bmp = &Atlas2D_Bitmap;
Int32 elemSize = Atlas2D_ElementSize;
TextureLoc texLoc = Block_GetTexLoc(block, Face_XMax);
Int32 texX = texLoc & 0x0F, texY = texLoc >> 4;
Real32 topY = Block_GetSpriteBB_TopY(elemSize, texX, texY, bmp);
Real32 bottomY = Block_GetSpriteBB_BottomY(elemSize, texX, texY, bmp);
Real32 leftX = Block_GetSpriteBB_LeftX(elemSize, texX, texY, bmp);
Real32 rightX = Block_GetSpriteBB_RightX(elemSize, texX, texY, bmp);
Vector3 centre = Vector3_Create3(0.5f, 0, 0.5f);
Vector3 minRaw = Vector3_RotateY3(leftX - 0.5f, bottomY, 0, 45.0f * MATH_DEG2RAD);
Vector3 maxRaw = Vector3_RotateY3(rightX - 0.5f, topY, 0, 45.0f * MATH_DEG2RAD);
Vector3_Add(&minRaw, &centre, &Block_MinBB[block]);
Vector3_Add(&maxRaw, &centre, &Block_MaxBB[block]);
Block_CalcRenderBounds(block);
}
Real32 Block_GetSpriteBB_TopY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp) {
Int32 x, y;
for (y = 0; y < size; y++) {
@ -339,28 +319,36 @@ Real32 Block_GetSpriteBB_RightX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bm
return 0;
}
void Block_RecalculateBB(BlockID block) {
Bitmap* bmp = &Atlas2D_Bitmap;
Int32 elemSize = Atlas2D_ElementSize;
TextureLoc texLoc = Block_GetTexLoc(block, Face_XMax);
Int32 texX = texLoc & 0x0F, texY = texLoc >> 4;
Real32 topY = Block_GetSpriteBB_TopY(elemSize, texX, texY, bmp);
Real32 bottomY = Block_GetSpriteBB_BottomY(elemSize, texX, texY, bmp);
Real32 leftX = Block_GetSpriteBB_LeftX(elemSize, texX, texY, bmp);
Real32 rightX = Block_GetSpriteBB_RightX(elemSize, texX, texY, bmp);
void Block_UpdateCullingAll(void) {
Int32 block, neighbour;
for (block = BlockID_Air; block < Block_Count; block++)
Block_CanStretch[block] = 0x3F;
Vector3 centre = Vector3_Create3(0.5f, 0, 0.5f);
Vector3 minRaw = Vector3_RotateY3(leftX - 0.5f, bottomY, 0, 45.0f * MATH_DEG2RAD);
Vector3 maxRaw = Vector3_RotateY3(rightX - 0.5f, topY, 0, 45.0f * MATH_DEG2RAD);
for (block = BlockID_Air; block < Block_Count; block++) {
for (neighbour = BlockID_Air; neighbour < Block_Count; neighbour++) {
Block_CalcCulling((BlockID)block, (BlockID)neighbour);
}
}
Vector3_Add(&minRaw, &centre, &Block_MinBB[block]);
Vector3_Add(&maxRaw, &centre, &Block_MaxBB[block]);
Block_CalcRenderBounds(block);
}
void Block_UpdateCulling(BlockID block) {
Block_CanStretch[block] = 0x3F;
Int32 other;
for (other = BlockID_Air; other < Block_Count; other++) {
Block_CalcCulling(block, (BlockID)other);
Block_CalcCulling((BlockID)other, block);
}
void Block_SetXStretch(BlockID block, bool stretch) {
Block_CanStretch[block] &= 0xC3; /* ~0x3C */
Block_CanStretch[block] |= (stretch ? 0x3C : (UInt8)0);
}
void Block_SetZStretch(BlockID block, bool stretch) {
Block_CanStretch[block] &= 0xFC; /* ~0x03 */
Block_CanStretch[block] |= (stretch ? 0x03 : (UInt8)0);
}
void Block_CalcCulling(BlockID block, BlockID other) {
@ -393,6 +381,28 @@ void Block_CalcCulling(BlockID block, BlockID other) {
}
}
void Block_UpdateCullingAll(void) {
Int32 block, neighbour;
for (block = BlockID_Air; block < Block_Count; block++)
Block_CanStretch[block] = 0x3F;
for (block = BlockID_Air; block < Block_Count; block++) {
for (neighbour = BlockID_Air; neighbour < Block_Count; neighbour++) {
Block_CalcCulling((BlockID)block, (BlockID)neighbour);
}
}
}
void Block_UpdateCulling(BlockID block) {
Block_CanStretch[block] = 0x3F;
Int32 other;
for (other = BlockID_Air; other < Block_Count; other++) {
Block_CalcCulling(block, (BlockID)other);
Block_CalcCulling((BlockID)other, block);
}
}
bool Block_IsHidden(BlockID block, BlockID other) {
/* Sprite blocks can never hide faces. */
if (Block_Draw[block] == DrawType_Sprite) return false;
@ -431,15 +441,6 @@ bool Block_IsFaceHidden(BlockID block, BlockID other, Face face) {
#endif
}
void Block_SetXStretch(BlockID block, bool stretch) {
Block_CanStretch[block] &= 0xC3; /* ~0x3C */
Block_CanStretch[block] |= (stretch ? 0x3C : (UInt8)0);
}
void Block_SetZStretch(BlockID block, bool stretch) {
Block_CanStretch[block] &= 0xFC; /* ~0x03 */
Block_CanStretch[block] |= (stretch ? 0x03 : (UInt8)0);
}
#define AR_EQ1(s, x) (s.length >= 1 && Char_ToLower(s.buffer[0]) == x)

View File

@ -59,58 +59,41 @@ typedef UInt8 CollideType;
/* Lava style 'swimming'/'bobbing' interaction when player collides. */
#define CollideType_LiquidLava 6
/* Array of block names. */
UInt8 Block_NamesBuffer[String_BufferSize(STRING_SIZE) * Block_Count];
/* Index of given block name. */
#define Block_NamePtr(i) &Block_NamesBuffer[String_BufferSize(STRING_SIZE) * i]
/* Gets whether the given block stops sunlight. */
bool Block_BlocksLight[Block_Count];
/* Gets whether the given block should draw all its faces in a full white colour. */
bool Block_FullBright[Block_Count];
/* Gets the name of the given block, or 'Invalid' if the block is not defined. */
String Block_Name[Block_Count];
/* Gets the custom fog colour that should be used when the player is standing within this block.
Note that this is only used for exponential fog mode. */
PackedCol Block_FogColour[Block_Count];
/* Gets the fog density for the given block.
A value of 0 means this block does not apply fog.*/
Real32 Block_FogDensity[Block_Count];
/* Gets the basic collision type for the given block. */
CollideType Block_Collide[Block_Count];
/* Gets the action performed when colliding with the given block. */
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];
/* Light offset of each block, as bitflags of 1 per face. */
UInt8 Block_LightOffset[Block_Count];
/* Gets the DrawType for the given block. */
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).*/
bool Block_FullOpaque[Block_Count];
UInt32 DefinedCustomBlocks[Block_Count >> 5];
/* Gets the dig sound ID for the given block. */
SoundType Block_DigSounds[Block_Count];
/* Gets the step sound ID for the given block. */
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. */
bool Block_Tinted[Block_Count];
@ -124,125 +107,80 @@ if (Block_Tinted[block]) {\
}
/* Min corner of a block. */
Vector3 Block_MinBB[Block_Count];
/* Max corner of a block. */
Vector3 Block_MaxBB[Block_Count];
/* Rendered min corner of a block. */
Vector3 Block_RenderMinBB[Block_Count];
/* Rendered max corner of a block. */
Vector3 Block_RenderMaxBB[Block_Count];
#define Block_TexturesCount Block_Count * Face_Count
/* Raw texture ids of each face of each block. */
TextureLoc Block_Textures[Block_TexturesCount];
/* Returns whether player is allowed to place the given block. */
bool Block_CanPlace[Block_Count];
/* Returns whether player is allowed to delete the given block. */
bool Block_CanDelete[Block_Count];
/* Gets a bit flags of faces hidden of two neighbouring blocks. */
UInt8 Block_Hidden[Block_Count * Block_Count];
/* Gets a bit flags of which faces of a block can stretch with greedy meshing. */
UInt8 Block_CanStretch[Block_Count];
/* Recalculates the initial properties and culling states for all blocks. */
void Block_Reset(void);
/* Calculates the initial properties and culling states for all blocks. */
void Block_Init(void);
/* Initialises the default blocks the player is allowed to place and delete. */
void Block_SetDefaultPerms(void);
/* Sets collision type of a block. */
void Block_SetCollide(BlockID block, UInt8 collide);
/* Sets draw method of a block. */
void Block_SetDrawType(BlockID block, UInt8 draw);
/* Resets the properties for the given block to their defaults. */
void Block_ResetProps(BlockID block);
/* Finds the ID of the block whose name caselessly matches the input, -1 otherwise. */
Int32 Block_FindID(STRING_TRANSIENT String* name);
/* Gets whether the given block is a liquid. (water and lava) */
bool Block_IsLiquid(BlockID b);
/* Calculates rendered corners of a block. */
void Block_CalcRenderBounds(BlockID block);
/* Calculates the light offset of all six faces of a block. */
UInt8 Block_CalcLightOffset(BlockID block);
/* Recalculates bounding boxes of all blocks that are sprites. */
void Block_RecalculateSpriteBB(void);
/* Recalculates bounding box of a sprite. */
void Block_RecalculateBB(BlockID block);
/* Sets the texture for the four side faces of the given block. */
void Block_SetSide(TextureLoc texLoc, BlockID blockId);
/* Sets the texture for the given face of the given block. */
void Block_SetTex(TextureLoc texLoc, Face face, BlockID blockId);
/* Gets the texture ID of the given face of the given block. */
#define Block_GetTexLoc(block, face) Block_Textures[(block) * Face_Count + face]
/* Recalculates culling state for all blocks. */
void Block_UpdateCullingAll(void);
/* Recalculates culling state for the given blocks. */
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, Face face);
static String Block_DefaultName(BlockID block);
static void Block_SplitUppercase(STRING_TRANSIENT String* buffer, STRING_TRANSIENT String* blockNames,
Int32 start, Int32 end);
static Real32 Block_GetSpriteBB_TopY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp);
static Real32 Block_GetSpriteBB_BottomY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp);
static Real32 Block_GetSpriteBB_LeftX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp);
static Real32 Block_GetSpriteBB_RightX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp);
static void Block_GetTextureRegion(BlockID block, Face face, Vector2* min, Vector2* max);
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, Face face, bool value);
static bool Block_IsHidden(BlockID block, BlockID other);
static void Block_SetXStretch(BlockID block, bool stretch);
static void Block_SetZStretch(BlockID block, bool stretch);
/* Attempts to find the rotated block based on the user's orientation and offset on selected block. */
BlockID AutoRotate_RotateBlock(BlockID block);
#endif

View File

@ -9,31 +9,22 @@
/* Default height of a block. */
Real32 DefaultSet_Height(BlockID b);
/* Gets whether the given block is fully bright. */
bool DefaultSet_FullBright(BlockID b);
/* Gets default fog density of a block. 0 means no fog density. */
Real32 DefaultSet_FogDensity(BlockID b);
/* Gets the fog colour of this block. */
PackedCol DefaultSet_FogColour(BlockID b);
/* Gets the collide type of a block. */
CollideType DefaultSet_Collide(BlockID b);
/* Gets a backwards compatible collide type of a block. */
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. */
SoundType DefaultSet_StepSound(BlockID b);
/* Gets the type of method used to draw/render this block. */
DrawType DefaultSet_Draw(BlockID b);
/* Gets the ID of the sound played when deleting/placing this block. */
SoundType DefaultSet_DigSound(BlockID b);
#endif