Port AABB to C.

This commit is contained in:
UnknownShadow200 2017-06-16 22:21:55 +10:00
parent 7740aeba1b
commit 9016dc1e33
10 changed files with 119 additions and 56 deletions

View File

@ -46,13 +46,6 @@ namespace ClassicalSharp.Physics {
return false;
}
/// <summary> Determines whether this bounding box entirely contains
/// the given bounding box on all axes. </summary>
public bool Contains(AABB other) {
return other.Min.X >= Min.X && other.Min.Y >= Min.Y && other.Min.Z >= Min.Z &&
other.Max.X <= Max.X && other.Max.Y <= Max.Y && other.Max.Z <= Max.Z;
}
/// <summary> Determines whether this bounding box entirely contains
/// the coordinates on all axes. </summary>
public bool Contains(Vector3 P) {

49
src/Client/AABB.c Normal file
View File

@ -0,0 +1,49 @@
#include "AABB.h"
void AABB_FromCoords6(AABB* result, Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2) {
result->Min = Vector3_Create3(x1, y1, z1);
result->Max = Vector3_Create3(x2, y2, z2);
}
void AABB_FromCoords(AABB* result, Vector3* min, Vector3* max) {
result->Min = *min;
result->Max = *max;
}
void AABB_Make(AABB* result, Vector3* pos, Vector3* size) {
result->Min.X = pos->X - size->X * 0.5f;
result->Min.Y = pos->Y;
result->Min.Z = pos->Z - size->Z * 0.5f;
result->Max.X = pos->X + size->X * 0.5f;
result->Min.Y = pos->Y + size->Y;
result->Max.Z = pos->Z + size->Z * 0.5f;
}
void AABB_Offset(AABB* result, AABB* bb, Vector3* amount) {
Vector3_Add(&result->Min, &bb->Min, amount);
Vector3_Add(&result->Max, &bb->Max, amount);
}
bool AABB_Intersects(AABB* bb, AABB* other) {
if (bb->Max.X >= other->Min.X && bb->Min.X <= other->Max.X) {
if (bb->Max.Y < other->Min.Y || bb->Min.Y > other->Max.Y) {
return false;
}
return bb->Max.Z >= other->Min.Z && bb->Min.Z <= other->Max.Z;
}
return false;
}
bool AABB_Contains(AABB* parent, AABB* child) {
return
child->Min.X >= parent->Min.X && child->Min.Y >= parent->Min.Y && child->Min.Z >= parent->Min.Z &&
child->Max.X <= parent->Max.X && child->Max.Y <= parent->Max.Y && child->Max.Z <= parent->Max.Z;
}
bool AABB_ContainsPoint(AABB* parent, Vector3* P) {
return
P->X >= parent->Min.X && P->Y >= parent->Min.Y && P->Z >= parent->Min.Z &&
P->X <= parent->Max.X && P->Y <= parent->Max.Y && P->Z <= parent->Max.Z;
}

View File

@ -23,9 +23,9 @@ typedef struct AABB {
#define AABB_Length(bb) (bb->Max.Z - bb.Min.Z)
void AABB_FromCoords6(Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2);
void AABB_FromCoords6(AABB* result, Real32 x1, Real32 y1, Real32 z1, Real32 x2, Real32 y2, Real32 z2);
void AABB_FromCoords(Vector3* min, Vector3* max, AABB* result);
void AABB_FromCoords(AABB* result, Vector3* min, Vector3* max);
void AABB_Make(AABB* result, Vector3* pos, Vector3* size);

View File

@ -156,11 +156,20 @@ void ChunkUpdater_FreeAllocations(void) {
void ChunkUpdater_PerformAllocations(void) {
MapRenderer_Chunks = Platform_MemAlloc(MapRenderer_ChunksCount * sizeof(ChunkInfo));
if (MapRenderer_Chunks == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk info");
MapRenderer_SortedChunks = Platform_MemAlloc(MapRenderer_ChunksCount * sizeof(ChunkInfo*));
if (MapRenderer_Chunks == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate sorted chunk info");
MapRenderer_RenderChunks = Platform_MemAlloc(MapRenderer_ChunksCount * sizeof(ChunkInfo*));
if (MapRenderer_RenderChunks == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate render chunk info");
ChunkUpdater_Distances = Platform_MemAlloc(MapRenderer_ChunksCount * sizeof(Int32));
if (ChunkUpdater_Distances == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk distances");
UInt32 partsSize = sizeof(ChunkPartInfo) * cu_atlas1DCount;
MapRenderer_PartsBuffer = Platform_MemAlloc(MapRenderer_ChunksCount * partsSize);
if (MapRenderer_PartsBuffer == NULL) ErrorHandler_Fail("ChunkUpdater - failed to allocate chunk parts buffer");
}

View File

@ -251,6 +251,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="2DStructs.c" />
<ClCompile Include="AABB.c" />
<ClCompile Include="AxisLinesRenderer.c" />
<ClCompile Include="Block.c" />
<ClCompile Include="BordersRenderer.c" />

View File

@ -554,5 +554,8 @@
<ClCompile Include="LocationUpdate.c">
<Filter>Source Files\Entities</Filter>
</ClCompile>
<ClCompile Include="AABB.c">
<Filter>Source Files\Math</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -14,6 +14,14 @@
GfxResourceID env_cloudsVb = -1, env_skyVb = -1, env_cloudsTex = -1;
GfxResourceID env_cloudVertices, env_skyVertices;
IGameComponent EnvRenderer_MakeGameComponent(void) {
IGameComponent comp = IGameComponent_MakeEmpty();
comp.Init = EnvRenderer_Init;
comp.Reset = EnvRenderer_Reset;
comp.OnNewMapLoaded = EnvRenderer_OnNewMapLoaded;
comp.Free = EnvRenderer_Free;
return comp;
}
void EnvRenderer_UseLegacyMode(bool legacy) {
EnvRenderer_Legacy = legacy;

View File

@ -36,7 +36,7 @@ static BlockID EnvRenderer_BlockOn(Real32* fogDensity, PackedCol* fogCol);
static Real32 EnvRenderer_BlendFactor(Real32 x);
static void EnvVariableChanged(EnvVar envVar);
static void EnvRenderer_EnvVariableChanged(EnvVar envVar);
static void EnvRenderer_ContextLost(void);
static void EnvRenderer_ContextRecreated(void);

View File

@ -13,52 +13,52 @@ typedef UInt8 FpsLimitMethod;
#define FpsLimitMethod_120FPS 3
#define FpsLimitMethod_None 4
const UInt8* OptionsKey_ViewDist = "viewdist";
const UInt8* OptionsKey_SingleplayerPhysics = "singleplayerphysics";
const UInt8* OptionsKey_UseMusic = "usemusic";
const UInt8* OptionsKey_UseSound = "usesound";
const UInt8* OptionsKey_ForceOpenAL = "forceopenal";
const UInt8* OptionsKey_NamesMode = "namesmode";
const UInt8* OptionsKey_InvertMouse = "invertmouse";
const UInt8* OptionsKey_Sensitivity = "mousesensitivity";
const UInt8* OptionsKey_FpsLimit = "fpslimit";
const UInt8* OptionsKey_DefaultTexturePack = "defaulttexpack";
const UInt8* OptionsKey_AutoCloseLauncher = "autocloselauncher";
const UInt8* OptionsKey_ViewBobbing = "viewbobbing";
const UInt8* OptionsKey_EntityShadow = "entityshadow";
const UInt8* OptionsKey_RenderType = "normal";
const UInt8* OptionsKey_SmoothLighting = "gfx-smoothlighting";
const UInt8* OptionsKey_SurvivalMode = "game-survivalmode";
const UInt8* OptionsKey_ChatLogging = "chat-logging";
#define OptionsKey_ViewDist "viewdist"
#define OptionsKey_SingleplayerPhysics "singleplayerphysics"
#define OptionsKey_UseMusic "usemusic"
#define OptionsKey_UseSound "usesound"
#define OptionsKey_ForceOpenAL "forceopenal"
#define OptionsKey_NamesMode "namesmode"
#define OptionsKey_InvertMouse "invertmouse"
#define OptionsKey_Sensitivity "mousesensitivity"
#define OptionsKey_FpsLimit "fpslimit"
#define OptionsKey_DefaultTexturePack "defaulttexpack"
#define OptionsKey_AutoCloseLauncher "autocloselauncher"
#define OptionsKey_ViewBobbing "viewbobbing"
#define OptionsKey_EntityShadow "entityshadow"
#define OptionsKey_RenderType "normal"
#define OptionsKey_SmoothLighting "gfx-smoothlighting"
#define OptionsKey_SurvivalMode "game-survivalmode"
#define OptionsKey_ChatLogging "chat-logging"
const UInt8* OptionsKey_HacksEnabled = "hacks-hacksenabled";
const UInt8* OptionsKey_FieldOfView = "hacks-fov";
const UInt8* OptionsKey_Speed = "hacks-speedmultiplier";
const UInt8* OptionsKey_ModifiableLiquids = "hacks-liquidsbreakable";
const UInt8* OptionsKey_PushbackPlacing = "hacks-pushbackplacing";
const UInt8* OptionsKey_NoclipSlide = "hacks-noclipslide";
const UInt8* OptionsKey_CameraClipping = "hacks-cameraclipping";
const UInt8* OptionsKey_WOMStyleHacks = "hacks-womstylehacks";
const UInt8* OptionsKey_FullBlockStep = "hacks-fullblockstep";
#define OptionsKey_HacksEnabled "hacks-hacksenabled"
#define OptionsKey_FieldOfView "hacks-fov"
#define OptionsKey_Speed "hacks-speedmultiplier"
#define OptionsKey_ModifiableLiquids "hacks-liquidsbreakable"
#define OptionsKey_PushbackPlacing "hacks-pushbackplacing"
#define OptionsKey_NoclipSlide "hacks-noclipslide"
#define OptionsKey_CameraClipping "hacks-cameraclipping"
#define OptionsKey_WOMStyleHacks "hacks-womstylehacks"
#define OptionsKey_FullBlockStep "hacks-fullblockstep"
const UInt8* OptionsKey_TabAutocomplete = "gui-tab-autocomplete";
const UInt8* OptionsKey_ShowBlockInHand = "gui-blockinhand";
const UInt8* OptionsKey_ChatLines = "gui-chatlines";
const UInt8* OptionsKey_ClickableChat = "gui-chatclickable";
const UInt8* OptionsKey_ArialChatFont = "gui-arialchatfont";
const UInt8* OptionsKey_HotbarScale = "gui-hotbarscale";
const UInt8* OptionsKey_InventoryScale = "gui-inventoryscale";
const UInt8* OptionsKey_ChatScale = "gui-chatscale";
const UInt8* OptionsKey_ShowFPS = "gui-showfps";
const UInt8* OptionsKey_FontName = "gui-fontname";
const UInt8* OptionsKey_BlackTextShadows = "gui-blacktextshadows";
#define OptionsKey_TabAutocomplete "gui-tab-autocomplete"
#define OptionsKey_ShowBlockInHand "gui-blockinhand"
#define OptionsKey_ChatLines "gui-chatlines"
#define OptionsKey_ClickableChat "gui-chatclickable"
#define OptionsKey_ArialChatFont "gui-arialchatfont"
#define OptionsKey_HotbarScale "gui-hotbarscale"
#define OptionsKey_InventoryScale "gui-inventoryscale"
#define OptionsKey_ChatScale "gui-chatscale"
#define OptionsKey_ShowFPS "gui-showfps"
#define OptionsKey_FontName "gui-fontname"
#define OptionsKey_BlackTextShadows "gui-blacktextshadows"
const UInt8* OptionsKey_AllowCustomBlocks = "nostalgia-customblocks";
const UInt8* OptionsKey_UseCPE = "nostalgia-usecpe";
const UInt8* OptionsKey_AllowServerTextures = "nostalgia-servertextures";
const UInt8* OptionsKey_UseClassicGui = "nostalgia-classicgui";
const UInt8* OptionsKey_SimpleArmsAnim = "nostalgia-simplearms";
const UInt8* OptionsKey_UseClassicTabList = "nostalgia-classictablist";
const UInt8* OptionsKey_UseClassicOptions = "nostalgia-classicoptions";
const UInt8* OptionsKey_AllowClassicHacks = "nostalgia-hacks";
#define OptionsKey_AllowCustomBlocks "nostalgia-customblocks"
#define OptionsKey_UseCPE "nostalgia-usecpe"
#define OptionsKey_AllowServerTextures "nostalgia-servertextures"
#define OptionsKey_UseClassicGui "nostalgia-classicgui"
#define OptionsKey_SimpleArmsAnim "nostalgia-simplearms"
#define OptionsKey_UseClassicTabList "nostalgia-classictablist"
#define OptionsKey_UseClassicOptions "nostalgia-classicoptions"
#define OptionsKey_AllowClassicHacks "nostalgia-hacks"
#endif

View File

@ -19,7 +19,7 @@ y = (index / World_Width) / World_Length;
/* Raw blocks of this world. */
BlockID* World_Blocks = NULL;
BlockID* World_Blocks;
/* Size of blocks array. */
Int32 World_BlocksSize;