mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 20:15:35 -04:00
Rewrite DefaultSet in C
This commit is contained in:
parent
9eabf1b244
commit
3d8fc9eddb
@ -73,4 +73,25 @@
|
||||
#define Block_Pillar 63
|
||||
#define Block_Crate 64
|
||||
#define Block_StoneBrick 65
|
||||
|
||||
/* Max block ID used in original classic */
|
||||
#define Block_MaxOriginal Block_Obsidian
|
||||
|
||||
/* Number of blocks in original classic. */
|
||||
#define Block_OriginalCount (Block_MaxOriginal + 1)
|
||||
|
||||
/* Max block ID used in original classic plus CPE blocks. */
|
||||
#define Block_MaxCpe Block_StoneBrick
|
||||
|
||||
/* Number of blocks in original classic plus CPE blocks. */
|
||||
#define Block_CpeCount = (Block_MaxCpeBlock + 1)
|
||||
|
||||
#if USE16_BIT
|
||||
#define Block_MaxDefined 0xFFF
|
||||
#else
|
||||
#define Block_MaxDefined 0xFF
|
||||
#endif
|
||||
|
||||
#define Block_Count (MaxDefinedBlock + 1)
|
||||
#define Block_Invalid Block_MaxDefined
|
||||
#endif
|
@ -171,6 +171,8 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Block.h" />
|
||||
<ClInclude Include="Compiler.h" />
|
||||
<ClInclude Include="DefaultSet.h" />
|
||||
<ClInclude Include="FastColour.h" />
|
||||
<ClInclude Include="Funcs.h" />
|
||||
<ClInclude Include="Noise.h" />
|
||||
<ClInclude Include="Platform.h" />
|
||||
@ -181,6 +183,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Compiler.c" />
|
||||
<ClCompile Include="DefaultSet.c" />
|
||||
<ClCompile Include="Noise.c" />
|
||||
<ClCompile Include="NotchyGenerator.c" />
|
||||
<ClCompile Include="Random.c" />
|
||||
|
@ -34,6 +34,18 @@
|
||||
<Filter Include="Source Files\Utils">
|
||||
<UniqueIdentifier>{23df7aa9-c2fe-4dd9-ad2e-b07776510024}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Blocks">
|
||||
<UniqueIdentifier>{f693e3de-8aee-440f-9edc-61544d2f7f79}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Blocks">
|
||||
<UniqueIdentifier>{3ca12726-ff14-4e95-9f3b-4c4bab3d2122}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\2D">
|
||||
<UniqueIdentifier>{94eedec7-46cb-47cd-8729-fbf215de1cd6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\2D\Utils">
|
||||
<UniqueIdentifier>{7d28399b-8919-4015-b261-cfd8d18a7367}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="NotchyGenerator.h">
|
||||
@ -54,15 +66,21 @@
|
||||
<ClInclude Include="Funcs.h">
|
||||
<Filter>Header Files\Defines</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Block.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Platform.h">
|
||||
<Filter>Header Files\Platform</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="String.h">
|
||||
<Filter>Header Files\Utils</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Block.h">
|
||||
<Filter>Header Files\Blocks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DefaultSet.h">
|
||||
<Filter>Header Files\Blocks</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FastColour.h">
|
||||
<Filter>Header Files\2D\Utils</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="NotchyGenerator.c">
|
||||
@ -83,5 +101,8 @@
|
||||
<ClCompile Include="String.c">
|
||||
<Filter>Source Files\Utils</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DefaultSet.c">
|
||||
<Filter>Source Files\Blocks</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
113
src/Client/DefaultSet.c
Normal file
113
src/Client/DefaultSet.c
Normal file
@ -0,0 +1,113 @@
|
||||
#include "DefaultSet.h"
|
||||
#include "Block.h"
|
||||
|
||||
Real32 DefaultSet_Height(BlockID b) {
|
||||
if (b == Block_Slab) return 0.5f;
|
||||
if (b == Block_CobblestoneSlab) return 0.5f;
|
||||
if (b == Block_Snow) return 0.25f;
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
bool DefaultSet_FullBright(BlockID b) {
|
||||
return b == Block_Lava || b == Block_StillLava
|
||||
|| b == Block_Magma || b == Block_Fire;
|
||||
}
|
||||
|
||||
Real32 DefaultSet_FogDensity(BlockID b) {
|
||||
if (b == Block_Water || b == Block_StillWater)
|
||||
return 0.1f;
|
||||
if (b == Block_Lava || b == Block_StillLava)
|
||||
return 2.0f;
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
FastColour DefaultSet_FogColour(BlockID b) {
|
||||
if (b == Block_Water || b == Block_StillWater)
|
||||
return FastColour_Create3(5, 5, 51);
|
||||
if (b == Block_Lava || b == Block_StillLava)
|
||||
return FastColour_Create3(153, 25, 0);
|
||||
return FastColour_Create4(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
UInt8 DefaultSet_Collide(BlockID b) {
|
||||
if (b == Block_Ice) return CollideType_Ice;
|
||||
if (b == Block_Water || b == Block_StillWater)
|
||||
return CollideType_LiquidWater;
|
||||
if (b == Block_Lava || b == Block_StillLava)
|
||||
return CollideType_LiquidLava;
|
||||
|
||||
if (b == Block_Snow || b == Block_Air || DefaultSet_Draw(b) == DrawType_Sprite)
|
||||
return CollideType_Gas;
|
||||
return CollideType_Solid;
|
||||
}
|
||||
|
||||
UInt8 DefaultSet_MapOldCollide(BlockID b, UInt8 collide) {
|
||||
if (b == Block_Ice && collide == CollideType_Solid)
|
||||
return CollideType_Ice;
|
||||
if ((b == Block_Water || b == Block_StillWater) && collide == CollideType_Liquid)
|
||||
return CollideType_LiquidWater;
|
||||
if ((b == Block_Lava || b == Block_StillLava) && collide == CollideType_Liquid)
|
||||
return CollideType_LiquidLava;
|
||||
return collide;
|
||||
}
|
||||
|
||||
bool DefaultSet_BlocksLight(BlockID b) {
|
||||
return !(b == Block_Glass || b == Block_Leaves
|
||||
|| b == Block_Air || Draw(b) == DrawType_Sprite);
|
||||
}
|
||||
|
||||
UInt8 DefaultSet_StepSound(BlockID b) {
|
||||
if (b == Block_Glass) return SoundType_Stone;
|
||||
if (b == Block_Rope) return SoundType_Cloth;
|
||||
if (Draw(b) == DrawType_Sprite) return SoundType_None;
|
||||
return DigSound(b);
|
||||
}
|
||||
|
||||
|
||||
UInt8 DefaultSet_Draw(BlockID b) {
|
||||
if (b == Block_Air || b == Block_Invalid) return DrawType_Gas;
|
||||
if (b == Block_Leaves) return DrawType_TransparentThick;
|
||||
|
||||
if (b == Block_Ice || b == Block_Water || b == Block_StillWater)
|
||||
return DrawType_Translucent;
|
||||
if (b == Block_Glass || b == Block_Leaves)
|
||||
return DrawType_Transparent;
|
||||
|
||||
if (b >= Block_Dandelion && b <= Block_RedMushroom)
|
||||
return DrawType_Sprite;
|
||||
if (b == Block_Sapling || b == Block_Rope || b == Block_Fire)
|
||||
return DrawType_Sprite;
|
||||
return DrawType_Opaque;
|
||||
}
|
||||
|
||||
UInt8 DefaultSet_DigSound(BlockID b) {
|
||||
if (b >= Block_Red && b <= Block_White)
|
||||
return SoundType_Cloth;
|
||||
if (b >= Block_LightPink && b <= Block_Turquoise)
|
||||
return SoundType_Cloth;
|
||||
if (b == Block_Iron || b == Block_Gold)
|
||||
return SoundType_Metal;
|
||||
|
||||
if (b == Block_Bookshelf || b == Block_Wood
|
||||
|| b == Block_Log || b == Block_Crate || b == Block_Fire)
|
||||
return SoundType_Wood;
|
||||
|
||||
if (b == Block_Rope) return SoundType_Cloth;
|
||||
if (b == Block_Sand) return SoundType_Sand;
|
||||
if (b == Block_Snow) return SoundType_Snow;
|
||||
if (b == Block_Glass) return SoundType_Glass;
|
||||
if (b == Block_Dirt || b == Block_Gravel)
|
||||
return SoundType_Gravel;
|
||||
|
||||
if (b == Block_Grass || b == Block_Sapling || b == Block_TNT
|
||||
|| b == Block_Leaves || b == Block_Sponge)
|
||||
return SoundType_Grass;
|
||||
|
||||
if (b >= Block_Dandelion && b <= Block_RedMushroom)
|
||||
return SoundType_Grass;
|
||||
if (b >= Block_Water && b <= Block_StillLava)
|
||||
return SoundType_None;
|
||||
if (b >= Block_Stone && b <= Block_StoneBrick)
|
||||
return SoundType_Stone;
|
||||
return SoundType_None;
|
||||
}
|
38
src/Client/DefaultSet.h
Normal file
38
src/Client/DefaultSet.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef CS_DEFAULT_BLOCKS_H
|
||||
#define CS_DEFAULT_BLOCKS_H
|
||||
#include "Typedefs.h"
|
||||
#include "FastColour.h"
|
||||
/* List of properties for core blocks.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
/* 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. */
|
||||
FastColour DefaultSet_FogColour(BlockID b);
|
||||
|
||||
/* Gets the collide type of a block. */
|
||||
UInt8 DefaultSet_Collide(BlockID b);
|
||||
|
||||
/* Gets a backwards compatible collide type of a block. */
|
||||
UInt8 DefaultSet_MapOldCollide(BlockID b, UInt8 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);
|
||||
|
||||
/* Gets the type of method used to draw/render this block. */
|
||||
UInt8 DefaultSet_Draw(BlockID b);
|
||||
|
||||
/* Gets the ID of the sound played when deleting/placing this block. */
|
||||
UInt8 DefaultSet_DigSound(BlockID b);
|
||||
#endif
|
38
src/Client/FastColour.h
Normal file
38
src/Client/FastColour.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef FASTCOLOUR_H
|
||||
#define FASTCOLOUR_H
|
||||
#include "Typedefs.h"
|
||||
|
||||
/* Represents an ARGB colour, in a format suitable for the native graphics api. */
|
||||
typedef struct FastColour {
|
||||
union {
|
||||
#if USE_DX
|
||||
struct { UInt8 B; UInt8 G; UInt8 R; UInt8 A; };
|
||||
#else
|
||||
struct { UInt8 R; UInt8 G; UInt8 B; UInt8 A; };
|
||||
#endif
|
||||
UInt32 Packed;
|
||||
};
|
||||
} FastColour;
|
||||
|
||||
/* Constructs a new ARGB colour. */
|
||||
FastColour FastColour_Create4(UInt8 r, UInt8 g, UInt8 b, UInt8 a) {
|
||||
FastColour col;
|
||||
col.R = r; col.G = g; col.B = b; col.A = a;
|
||||
return col;
|
||||
}
|
||||
|
||||
/* Constructs a new ARGB colour. */
|
||||
FastColour FastColour_Create3(UInt8 r, UInt8 g, UInt8 b) {
|
||||
FastColour col;
|
||||
col.R = r; col.G = g; col.B = b; col.A = 255;
|
||||
return col;
|
||||
}
|
||||
|
||||
/* Multiplies the RGB components by t, where t is in [0, 1] */
|
||||
FastColour FastColour_Scale(FastColour value, Real32 t) {
|
||||
value.R = (UInt8)(value.R * t);
|
||||
value.G = (UInt8)(value.G * t);
|
||||
value.B = (UInt8)(value.B * t);
|
||||
return value;
|
||||
}
|
||||
#endif
|
@ -26,4 +26,6 @@ typedef UInt8 bool;
|
||||
typedef UInt8 BlockID;
|
||||
typedef UInt8 EntityID;
|
||||
|
||||
#define USE16_BIT FALSE
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user