From 9016dc1e33be3fd754238cd16cb677e2b9e59906 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 16 Jun 2017 22:21:55 +1000 Subject: [PATCH] Port AABB to C. --- ClassicalSharp/Math/Physics/AABB.cs | 7 --- src/Client/AABB.c | 49 ++++++++++++++++ src/Client/AABB.h | 4 +- src/Client/ChunkUpdater.c | 9 +++ src/Client/Client.vcxproj | 1 + src/Client/Client.vcxproj.filters | 3 + src/Client/EnvRenderer.c | 8 +++ src/Client/EnvRenderer.h | 2 +- src/Client/Options.h | 90 ++++++++++++++--------------- src/Client/World.h | 2 +- 10 files changed, 119 insertions(+), 56 deletions(-) create mode 100644 src/Client/AABB.c diff --git a/ClassicalSharp/Math/Physics/AABB.cs b/ClassicalSharp/Math/Physics/AABB.cs index 4020ff7a1..7e0396cf3 100644 --- a/ClassicalSharp/Math/Physics/AABB.cs +++ b/ClassicalSharp/Math/Physics/AABB.cs @@ -46,13 +46,6 @@ namespace ClassicalSharp.Physics { return false; } - /// Determines whether this bounding box entirely contains - /// the given bounding box on all axes. - 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; - } - /// Determines whether this bounding box entirely contains /// the coordinates on all axes. public bool Contains(Vector3 P) { diff --git a/src/Client/AABB.c b/src/Client/AABB.c new file mode 100644 index 000000000..23166ab43 --- /dev/null +++ b/src/Client/AABB.c @@ -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; +} \ No newline at end of file diff --git a/src/Client/AABB.h b/src/Client/AABB.h index 449c08280..b7e9dc089 100644 --- a/src/Client/AABB.h +++ b/src/Client/AABB.h @@ -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); diff --git a/src/Client/ChunkUpdater.c b/src/Client/ChunkUpdater.c index 6ac634ca7..0d9dcaf66 100644 --- a/src/Client/ChunkUpdater.c +++ b/src/Client/ChunkUpdater.c @@ -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"); } diff --git a/src/Client/Client.vcxproj b/src/Client/Client.vcxproj index 5f08e2523..ca2d56162 100644 --- a/src/Client/Client.vcxproj +++ b/src/Client/Client.vcxproj @@ -251,6 +251,7 @@ + diff --git a/src/Client/Client.vcxproj.filters b/src/Client/Client.vcxproj.filters index e050d7651..49b93f3dc 100644 --- a/src/Client/Client.vcxproj.filters +++ b/src/Client/Client.vcxproj.filters @@ -554,5 +554,8 @@ Source Files\Entities + + Source Files\Math + \ No newline at end of file diff --git a/src/Client/EnvRenderer.c b/src/Client/EnvRenderer.c index a4f7ef934..25606d05b 100644 --- a/src/Client/EnvRenderer.c +++ b/src/Client/EnvRenderer.c @@ -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; diff --git a/src/Client/EnvRenderer.h b/src/Client/EnvRenderer.h index 70f694e5c..9e2e40a3f 100644 --- a/src/Client/EnvRenderer.h +++ b/src/Client/EnvRenderer.h @@ -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); diff --git a/src/Client/Options.h b/src/Client/Options.h index 0b74c5ef1..f5ff7450d 100644 --- a/src/Client/Options.h +++ b/src/Client/Options.h @@ -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 \ No newline at end of file diff --git a/src/Client/World.h b/src/Client/World.h index 6b91cacb7..657ff3f05 100644 --- a/src/Client/World.h +++ b/src/Client/World.h @@ -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;