mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
HacksComponent -> HacksComp in C.
This commit is contained in:
parent
be2f617d9d
commit
4274e04a87
@ -466,7 +466,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
int height = Math.Max(input.Height + input.YOffset, hud.BottomOffset);
|
||||
height += input.YOffset;
|
||||
altText.texture.Y1 = game.Height - (height + altText.texture.Height);
|
||||
altText.Y = altText.texture.Y1;
|
||||
altText.Y = altText.texture.Y;
|
||||
}
|
||||
|
||||
void SetHandlesAllInput(bool handles) {
|
||||
|
@ -26,7 +26,7 @@ void Block_Reset(void) {
|
||||
}
|
||||
|
||||
void Block_Init(void) {
|
||||
Int32 count = sizeof(DefinedCustomBlocks) / sizeof(DefinedCustomBlocks[0]);
|
||||
Int32 count = Array_NumElements(DefinedCustomBlocks);
|
||||
Int32 i;
|
||||
for (i = 0; i < count; i++) {
|
||||
DefinedCustomBlocks[i] = 0;
|
||||
@ -293,7 +293,7 @@ Real32 Block_GetSpriteBB_TopY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp)
|
||||
UInt32* row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size);
|
||||
for (x = 0; x < size; x++) {
|
||||
if ((UInt8)(row[x] >> 24) != 0) {
|
||||
return 1 - (float)y / size;
|
||||
return 1 - (Real32)y / size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -306,7 +306,7 @@ Real32 Block_GetSpriteBB_BottomY(Int32 size, Int32 tileX, Int32 tileY, Bitmap* b
|
||||
UInt32* row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size);
|
||||
for (x = 0; x < size; x++) {
|
||||
if ((UInt8)(row[x] >> 24) != 0) {
|
||||
return 1 - (float)(y + 1) / size;
|
||||
return 1 - (Real32)(y + 1) / size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -319,7 +319,7 @@ Real32 Block_GetSpriteBB_LeftX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bmp
|
||||
for (y = 0; y < size; y++) {
|
||||
UInt32* row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size);
|
||||
if ((UInt8)(row[x] >> 24) != 0) {
|
||||
return (float)x / size;
|
||||
return (Real32)x / size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -332,7 +332,7 @@ Real32 Block_GetSpriteBB_RightX(Int32 size, Int32 tileX, Int32 tileY, Bitmap* bm
|
||||
for (y = 0; y < size; y++) {
|
||||
UInt32* row = Bitmap_GetRow(bmp, tileY * size + y) + (tileX * size);
|
||||
if ((UInt8)(row[x] >> 24) != 0) {
|
||||
return (float)(x + 1) / size;
|
||||
return (Real32)(x + 1) / size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ void PerspectiveCamera_RegrabMouse(void) {
|
||||
#define adjust 0.025f
|
||||
|
||||
Real32 speedX = 0.0f, speedY = 0.0f;
|
||||
void PersepctiveCamera_UpdateMouseRotation(void) {
|
||||
void PerspectiveCamera_UpdateMouseRotation(void) {
|
||||
Real32 sensitivity = sensiFactor * Game_MouseSensitivity;
|
||||
|
||||
if (Game_SmoothCamera) {
|
||||
@ -98,8 +98,8 @@ void PersepctiveCamera_UpdateMouseRotation(void) {
|
||||
|
||||
void PerspectiveCamera_UpdateMouse(void) {
|
||||
if (game.Gui.ActiveScreen.HandlesAllInput) return;
|
||||
CentreMousePosition();
|
||||
UpdateMouseRotation();
|
||||
PerspectiveCamera_CentreMousePosition();
|
||||
PerspectiveCamera_UpdateMouseRotation();
|
||||
}
|
||||
|
||||
void PerspectiveCamera_CalcViewBobbing(Real32 t, Real32 velTiltScale) {
|
||||
@ -179,7 +179,7 @@ void ThirdPersonCamera_GetView(Matrix* mat) {
|
||||
}
|
||||
|
||||
Vector3 ThirdPersonCamera_GetCameraPosShared(Real32 t, Real32 dist, bool forward) {
|
||||
CalcViewBobbing(t, dist);
|
||||
PerspectiveCamera_CalcViewBobbing(t, dist);
|
||||
Entity* p = &LocalPlayer_Instance.Base.Base;
|
||||
Vector3 eyePos = Entity_GetEyePosition(p);
|
||||
eyePos.Y += Camera_BobbingVer;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "Platform.h"
|
||||
#include "Window.h"
|
||||
#include "GraphicsCommon.h"
|
||||
#include "Funcs.h"
|
||||
|
||||
#ifdef USE_DX
|
||||
//#define D3D_DISABLE_9EX causes compile errors
|
||||
@ -149,7 +150,7 @@ void D3D9_LoopUntilRetrieved(void) {
|
||||
}
|
||||
|
||||
void D3D9_FindCompatibleFormat(void) {
|
||||
Int32 count = sizeof(d3d9_viewFormats) / sizeof(d3d9_viewFormats[0]);
|
||||
Int32 count = Array_NumElements(d3d9_viewFormats);
|
||||
Int32 i;
|
||||
ReturnCode res;
|
||||
|
||||
@ -163,7 +164,7 @@ void D3D9_FindCompatibleFormat(void) {
|
||||
}
|
||||
}
|
||||
|
||||
count = sizeof(d3d9_depthFormats) / sizeof(d3d9_depthFormats[0]);
|
||||
count = Array_NumElements(d3d9_depthFormats);
|
||||
for (i = 0; i < count; i++) {
|
||||
d3d9_depthFormat = d3d9_depthFormats[i];
|
||||
res = IDirect3D9_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3d9_viewFormat, d3d9_viewFormat, d3d9_depthFormat);
|
||||
|
@ -49,15 +49,15 @@ void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale, Matrix* m)
|
||||
Matrix tmp;
|
||||
|
||||
Matrix_RotateZ(&tmp, -entity->RotZ * MATH_DEG2RAD);
|
||||
Matrix_Mult(m, m, &tmp);
|
||||
Matrix_MulBy(m, &tmp);
|
||||
Matrix_RotateX(&tmp, -entity->RotX * MATH_DEG2RAD);
|
||||
Matrix_Mult(m, m, &tmp);
|
||||
Matrix_MulBy(m, &tmp);
|
||||
Matrix_RotateY(&tmp, -entity->RotY * MATH_DEG2RAD);
|
||||
Matrix_Mult(m, m, &tmp);
|
||||
Matrix_MulBy(m, &tmp);
|
||||
Matrix_Scale(&tmp, scale.X, scale.Y, scale.Z);
|
||||
Matrix_Mult(m, m, &tmp);
|
||||
Matrix_MulBy(m, &tmp);
|
||||
Matrix_Translate(&tmp, pos.X, pos.Y, pos.Z);
|
||||
Matrix_Mult(m, m, &tmp);
|
||||
Matrix_MulBy(m, &tmp);
|
||||
/* return rotZ * rotX * rotY * scale * translate; */
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "AABB.h"
|
||||
#include "EntityComponents.h"
|
||||
#include "GraphicsEnums.h"
|
||||
#include "Matrix.h"
|
||||
/* Represents an in-game entity.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
@ -129,16 +129,17 @@ void TiltComp_GetCurrent(TiltComp* anim, Real32 t) {
|
||||
anim->TiltY = Math_Sin(pAnim->WalkTime) * pAnim->Swing * (0.15f * MATH_DEG2RAD);
|
||||
}
|
||||
|
||||
void HacksComponent_SetAll(HacksComp* hacks, bool allowed) {
|
||||
|
||||
void HacksComp_SetAll(HacksComp* hacks, bool allowed) {
|
||||
hacks->CanAnyHacks = allowed; hacks->CanFly = allowed;
|
||||
hacks->CanNoclip = allowed; hacks->CanRespawn = allowed;
|
||||
hacks->CanSpeed = allowed; hacks->CanPushbackBlocks = allowed;
|
||||
hacks->CanUseThirdPersonCamera = allowed;
|
||||
}
|
||||
|
||||
void HacksComponent_Init(HacksComp* hacks) {
|
||||
void HacksComp_Init(HacksComp* hacks) {
|
||||
Platform_MemSet(hacks, 0, sizeof(HacksComp));
|
||||
HacksComponent_SetAll(hacks, true);
|
||||
HacksComp_SetAll(hacks, true);
|
||||
hacks->SpeedMultiplier = 10.0f;
|
||||
hacks->Enabled = true;
|
||||
hacks->CanSeeAllNames = true;
|
||||
@ -149,15 +150,15 @@ void HacksComponent_Init(HacksComp* hacks) {
|
||||
hacks->HacksFlags = String_FromRawBuffer(&hacks->HacksFlagsBuffer[0], 128);
|
||||
}
|
||||
|
||||
bool HacksComponent_CanJumpHigher(HacksComp* hacks) {
|
||||
bool HacksComp_CanJumpHigher(HacksComp* hacks) {
|
||||
return hacks->Enabled && hacks->CanAnyHacks && hacks->CanSpeed;
|
||||
}
|
||||
|
||||
bool HacksComponent_Floating(HacksComp* hacks) {
|
||||
bool HacksComp_Floating(HacksComp* hacks) {
|
||||
return hacks->Noclip || hacks->Flying;
|
||||
}
|
||||
|
||||
String HacksComponent_GetFlagValue(String* flag, HacksComp* hacks) {
|
||||
String HacksComp_GetFlagValue(String* flag, HacksComp* hacks) {
|
||||
String* joined = &hacks->HacksFlags;
|
||||
Int32 start = String_IndexOfString(joined, flag);
|
||||
if (start < 0) return String_MakeNull();
|
||||
@ -169,9 +170,9 @@ String HacksComponent_GetFlagValue(String* flag, HacksComp* hacks) {
|
||||
return String_UNSAFE_Substring(joined, start, end - start);
|
||||
}
|
||||
|
||||
void HacksComponent_ParseHorizontalSpeed(HacksComp* hacks) {
|
||||
void HacksComp_ParseHorizontalSpeed(HacksComp* hacks) {
|
||||
String horSpeedFlag = String_FromConstant("horspeed=");
|
||||
String speedStr = HacksComponent_GetFlagValue(&horSpeedFlag, hacks);
|
||||
String speedStr = HacksComp_GetFlagValue(&horSpeedFlag, hacks);
|
||||
if (speedStr.length == 0) return;
|
||||
|
||||
Real32 speed = 0.0f;
|
||||
@ -179,9 +180,9 @@ void HacksComponent_ParseHorizontalSpeed(HacksComp* hacks) {
|
||||
hacks->MaxSpeedMultiplier = speed;
|
||||
}
|
||||
|
||||
void HacksComponent_ParseMultiSpeed(HacksComp* hacks) {
|
||||
void HacksComp_ParseMultiSpeed(HacksComp* hacks) {
|
||||
String jumpsFlag = String_FromConstant("jumps=");
|
||||
String jumpsStr = HacksComponent_GetFlagValue(&jumpsFlag, hacks);
|
||||
String jumpsStr = HacksComp_GetFlagValue(&jumpsFlag, hacks);
|
||||
if (jumpsStr.length == 0) return;
|
||||
|
||||
Int32 jumps = 0;
|
||||
@ -189,7 +190,7 @@ void HacksComponent_ParseMultiSpeed(HacksComp* hacks) {
|
||||
hacks->MaxJumps = jumps;
|
||||
}
|
||||
|
||||
void HacksComponent_ParseFlag(HacksComp* hacks, const UInt8* incFlag, const UInt8* excFlag, bool* target) {
|
||||
void HacksComp_ParseFlag(HacksComp* hacks, const UInt8* incFlag, const UInt8* excFlag, bool* target) {
|
||||
String include = String_FromReadonly(incFlag);
|
||||
String exclude = String_FromReadonly(excFlag);
|
||||
String* joined = &hacks->HacksFlags;
|
||||
@ -201,21 +202,21 @@ void HacksComponent_ParseFlag(HacksComp* hacks, const UInt8* incFlag, const UInt
|
||||
}
|
||||
}
|
||||
|
||||
void HacksComponent_ParseAllFlag(HacksComp* hacks, const UInt8* incFlag, const UInt8* excFlag) {
|
||||
void HacksComp_ParseAllFlag(HacksComp* hacks, const UInt8* incFlag, const UInt8* excFlag) {
|
||||
String include = String_FromReadonly(incFlag);
|
||||
String exclude = String_FromReadonly(excFlag);
|
||||
String* joined = &hacks->HacksFlags;
|
||||
|
||||
if (String_ContainsString(joined, &include)) {
|
||||
HacksComponent_SetAll(hacks, true);
|
||||
HacksComp_SetAll(hacks, true);
|
||||
} else if (String_ContainsString(joined, &exclude)) {
|
||||
HacksComponent_SetAll(hacks, false);
|
||||
HacksComp_SetAll(hacks, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* Sets the user type of this user. This is used to control permissions for grass,
|
||||
bedrock, water and lava blocks on servers that don't support CPE block permissions. */
|
||||
void HacksComponent_SetUserType(HacksComp* hacks, UInt8 value) {
|
||||
void HacksComp_SetUserType(HacksComp* hacks, UInt8 value) {
|
||||
bool isOp = value >= 100 && value <= 127;
|
||||
hacks->UserType = value;
|
||||
Block_CanPlace[BlockID_Bedrock] = isOp;
|
||||
@ -229,7 +230,7 @@ void HacksComponent_SetUserType(HacksComp* hacks, UInt8 value) {
|
||||
}
|
||||
|
||||
/* Disables any hacks if their respective CanHackX value is set to false. */
|
||||
void HacksComponent_CheckConsistency(HacksComp* hacks) {
|
||||
void HacksComp_CheckConsistency(HacksComp* hacks) {
|
||||
if (!hacks->CanFly || !hacks->Enabled) {
|
||||
hacks->Flying = false; hacks->FlyingDown = false; hacks->FlyingUp = false;
|
||||
}
|
||||
@ -252,8 +253,8 @@ void HacksComponent_CheckConsistency(HacksComp* hacks) {
|
||||
/* Updates ability to use hacks, and raises HackPermissionsChanged event.
|
||||
Parses hack flags specified in the motd and/or name of the server.
|
||||
Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax, and horspeed=xyz */
|
||||
void HacksComponent_UpdateState(HacksComp* hacks) {
|
||||
HacksComponent_SetAll(hacks, true);
|
||||
void HacksComp_UpdateState(HacksComp* hacks) {
|
||||
HacksComp_SetAll(hacks, true);
|
||||
if (hacks->HacksFlags.length == 0) return;
|
||||
|
||||
hacks->MaxSpeedMultiplier = 1;
|
||||
@ -261,20 +262,20 @@ void HacksComponent_UpdateState(HacksComp* hacks) {
|
||||
/* By default (this is also the case with WoM), we can use hacks. */
|
||||
String excHacks = String_FromConstant("-hax");
|
||||
if (String_ContainsString(&hacks->HacksFlags, &excHacks)) {
|
||||
HacksComponent_SetAll(hacks, false);
|
||||
HacksComp_SetAll(hacks, false);
|
||||
}
|
||||
|
||||
HacksComponent_ParseFlag(hacks, "+fly", "-fly", &hacks->CanFly);
|
||||
HacksComponent_ParseFlag(hacks, "+noclip", "-noclip", &hacks->CanNoclip);
|
||||
HacksComponent_ParseFlag(hacks, "+speed", "-speed", &hacks->CanSpeed);
|
||||
HacksComponent_ParseFlag(hacks, "+respawn", "-respawn", &hacks->CanRespawn);
|
||||
HacksComp_ParseFlag(hacks, "+fly", "-fly", &hacks->CanFly);
|
||||
HacksComp_ParseFlag(hacks, "+noclip", "-noclip", &hacks->CanNoclip);
|
||||
HacksComp_ParseFlag(hacks, "+speed", "-speed", &hacks->CanSpeed);
|
||||
HacksComp_ParseFlag(hacks, "+respawn", "-respawn", &hacks->CanRespawn);
|
||||
|
||||
if (hacks->UserType == 0x64) {
|
||||
HacksComponent_ParseAllFlag(hacks, "+ophax", "-ophax");
|
||||
HacksComp_ParseAllFlag(hacks, "+ophax", "-ophax");
|
||||
}
|
||||
HacksComponent_ParseHorizontalSpeed(hacks);
|
||||
HacksComponent_ParseMultiSpeed(hacks);
|
||||
HacksComp_ParseHorizontalSpeed(hacks);
|
||||
HacksComp_ParseMultiSpeed(hacks);
|
||||
|
||||
HacksComponent_CheckConsistency(hacks);
|
||||
HacksComp_CheckConsistency(hacks);
|
||||
Event_RaiseVoid(&UserEvents_HackPermissionsChanged);
|
||||
}
|
@ -31,7 +31,6 @@ typedef struct TiltComp_ {
|
||||
Real32 VelTiltStrengthO, VelTiltStrengthN;
|
||||
} TiltComp;
|
||||
|
||||
|
||||
/* Initalises default values for a tilt component. */
|
||||
void TiltComp_Init(TiltComp* anim);
|
||||
/* Calculates the next tilt animation state. */
|
||||
@ -40,7 +39,6 @@ void TiltComp_Update(TiltComp* anim, Real64 delta);
|
||||
void TiltComp_GetCurrent(TiltComp* anim, Real32 t);
|
||||
|
||||
|
||||
|
||||
/* Entity component that performs management of hack states. */
|
||||
typedef struct HacksComponent_ {
|
||||
UInt8 UserType;
|
||||
@ -101,23 +99,18 @@ typedef struct HacksComponent_ {
|
||||
} HacksComp;
|
||||
|
||||
/* Initalises the state of this HacksComponent. */
|
||||
void HacksComponent_Init(HacksComp* hacks);
|
||||
|
||||
void HacksComp_Init(HacksComp* hacks);
|
||||
/* Returns whether hacks flags allow for jumping higher usage. */
|
||||
bool HacksComponent_CanJumpHigher(HacksComp* hacks);
|
||||
|
||||
bool HacksComp_CanJumpHigher(HacksComp* hacks);
|
||||
/* Returns whether noclip or flying modes are on.*/
|
||||
bool HacksComponent_Floating(HacksComp* hacks);
|
||||
|
||||
bool HacksComp_Floating(HacksComp* hacks);
|
||||
/* Sets the user type of this user. This is used to control permissions for grass,
|
||||
bedrock, water and lava blocks on servers that don't support CPE block permissions. */
|
||||
void HacksComponent_SetUserType(HacksComp* hacks, UInt8 value);
|
||||
|
||||
void HacksComp_SetUserType(HacksComp* hacks, UInt8 value);
|
||||
/* Disables any hacks if their respective CanHackX value is set to false. */
|
||||
void HacksComponent_CheckConsistency(HacksComp* hacks);
|
||||
|
||||
void HacksComp_CheckConsistency(HacksComp* hacks);
|
||||
/* Updates ability to use hacks, and raises UserEvents_HackPermissionsChanged event.
|
||||
Parses hack flags specified in the motd and/or name of the server.
|
||||
Recognises +/-hax, +/-fly, +/-noclip, +/-speed, +/-respawn, +/-ophax, and horspeed=xyz */
|
||||
void HacksComponent_UpdateState(HacksComp* hacks);
|
||||
void HacksComp_UpdateState(HacksComp* hacks);
|
||||
#endif
|
@ -21,7 +21,7 @@ void FrustumCulling_Normalise(Real32* plane0, Real32* plane1, Real32* plane2, Re
|
||||
}
|
||||
|
||||
bool FrustumCulling_SphereInFrustum(Real32 x, Real32 y, Real32 z, Real32 radius) {
|
||||
float d = frustum00 * x + frustum01 * y + frustum02 * z + frustum03;
|
||||
Real32 d = frustum00 * x + frustum01 * y + frustum02 * z + frustum03;
|
||||
if (d <= -radius) return false;
|
||||
|
||||
d = frustum10 * x + frustum11 * y + frustum12 * z + frustum13;
|
||||
|
@ -8,16 +8,15 @@
|
||||
|
||||
/* returns a bit mask for the nth bit in an integer */
|
||||
#define bit(x) (1 << x)
|
||||
|
||||
/* returns smallest of two numbers */
|
||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
/* returns largest of two numbers */
|
||||
#define max(x, y) ((x) > (y) ? (x) : (y))
|
||||
/* returns number of elements in given array. */
|
||||
#define Array_NumElements(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
/* returns whether character is uppercase letter */
|
||||
bool Char_IsUpper(UInt8 c);
|
||||
|
||||
/* Converts uppercase letter to lowercase */
|
||||
UInt8 Char_ToLower(UInt8 c);
|
||||
#endif
|
@ -284,7 +284,7 @@ void NotchyGen_FloodFillLava(void) {
|
||||
|
||||
Int32 i;
|
||||
for (i = 0; i < numSources; i++) {
|
||||
Gen_CurrentProgress = (float)i / numSources;
|
||||
Gen_CurrentProgress = (Real32)i / numSources;
|
||||
Int32 x = Random_Next(&rnd, Gen_Width);
|
||||
Int32 z = Random_Next(&rnd, Gen_Length);
|
||||
Int32 y = (Int32)((waterLevel - 3) * Random_Float(&rnd) * Random_Float(&rnd));
|
||||
|
@ -122,7 +122,7 @@ void Matrix_PerspectiveOffCenter(Matrix* result, Real32 left, Real32 right, Real
|
||||
void Matrix_LookAt(Matrix* result, Vector3 eye, Vector3 target, Vector3 up) {
|
||||
/* Transposed, sourced from https://msdn.microsoft.com/en-us/library/windows/desktop/bb281711(v=vs.85).aspx */
|
||||
Vector3 x, y, z;
|
||||
Vector3_Sub(&z, &eye, &target); Vector3_Normalize(&z, &z);
|
||||
Vector3_Subtract(&z, &eye, &target); Vector3_Normalize(&z, &z);
|
||||
Vector3_Cross(&x, &up, &z); Vector3_Normalize(&x, &x);
|
||||
Vector3_Cross(&y, &z, &x); Vector3_Normalize(&y, &y);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user