mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 01:52:24 -05:00
fix linux build again
This commit is contained in:
parent
53cfcd0b62
commit
0c2af35687
6 changed files with 138 additions and 112 deletions
|
@ -236,6 +236,9 @@ static void Huffman_Build(struct HuffmanTable* table, uint8_t* bitLens, int coun
|
|||
}
|
||||
|
||||
static int Huffman_Decode(struct InflateState* state, struct HuffmanTable* table) {
|
||||
uint32_t i, j, codeword;
|
||||
int packed, bits, offset;
|
||||
|
||||
/* Buffer as many bits as possible */
|
||||
while (state->NumBits <= INFLATE_MAX_BITS) {
|
||||
if (!state->AvailIn) break;
|
||||
|
@ -244,23 +247,22 @@ static int Huffman_Decode(struct InflateState* state, struct HuffmanTable* table
|
|||
|
||||
/* Try fast accelerated table lookup */
|
||||
if (state->NumBits >= INFLATE_FAST_BITS) {
|
||||
int packed = table->Fast[Inflate_PeekBits(state, INFLATE_FAST_BITS)];
|
||||
packed = table->Fast[Inflate_PeekBits(state, INFLATE_FAST_BITS)];
|
||||
if (packed >= 0) {
|
||||
int bits = packed >> INFLATE_FAST_BITS;
|
||||
bits = packed >> INFLATE_FAST_BITS;
|
||||
Inflate_ConsumeBits(state, bits);
|
||||
return packed & 0x1FF;
|
||||
}
|
||||
}
|
||||
|
||||
/* Slow, bit by bit lookup */
|
||||
uint32_t codeword = 0;
|
||||
uint32_t i, j;
|
||||
codeword = 0;
|
||||
for (i = 1, j = 0; i < INFLATE_MAX_BITS; i++, j++) {
|
||||
if (state->NumBits < i) return -1;
|
||||
codeword = (codeword << 1) | ((state->Bits >> j) & 1);
|
||||
|
||||
if (codeword < table->EndCodewords[i]) {
|
||||
int offset = table->FirstOffsets[i] + (codeword - table->FirstCodewords[i]);
|
||||
offset = table->FirstOffsets[i] + (codeword - table->FirstCodewords[i]);
|
||||
Inflate_ConsumeBits(state, i);
|
||||
return table->Values[offset];
|
||||
}
|
||||
|
@ -285,16 +287,18 @@ static int Huffman_Decode(struct InflateState* state, struct HuffmanTable* table
|
|||
}
|
||||
|
||||
static int Huffman_Unsafe_Decode_Slow(struct InflateState* state, struct HuffmanTable* table) {
|
||||
uint32_t codeword = Inflate_PeekBits(state, INFLATE_FAST_BITS);
|
||||
uint32_t i, j, codeword;
|
||||
int offset;
|
||||
|
||||
/* Slow, bit by bit lookup. Need to reverse order for huffman. */
|
||||
codeword = Inflate_PeekBits(state, INFLATE_FAST_BITS);
|
||||
codeword = Huffman_ReverseBits(codeword, INFLATE_FAST_BITS);
|
||||
|
||||
uint32_t i, j;
|
||||
for (i = INFLATE_FAST_BITS + 1, j = INFLATE_FAST_BITS; i < INFLATE_MAX_BITS; i++, j++) {
|
||||
codeword = (codeword << 1) | ((state->Bits >> j) & 1);
|
||||
|
||||
if (codeword < table->EndCodewords[i]) {
|
||||
int offset = table->FirstOffsets[i] + (codeword - table->FirstCodewords[i]);
|
||||
offset = table->FirstOffsets[i] + (codeword - table->FirstCodewords[i]);
|
||||
Inflate_ConsumeBits(state, i);
|
||||
return table->Values[offset];
|
||||
}
|
||||
|
@ -664,22 +668,28 @@ void Inflate_Process(struct InflateState* state) {
|
|||
}
|
||||
|
||||
static ReturnCode Inflate_StreamRead(struct Stream* stream, uint8_t* data, uint32_t count, uint32_t* modified) {
|
||||
struct InflateState* state = stream->Meta.Inflate;
|
||||
struct InflateState* state;
|
||||
uint8_t* inputEnd;
|
||||
uint32_t read, left;
|
||||
uint32_t startAvailOut;
|
||||
ReturnCode res;
|
||||
|
||||
*modified = 0;
|
||||
state->Output = data;
|
||||
state = stream->Meta.Inflate;
|
||||
state->Output = data;
|
||||
state->AvailOut = count;
|
||||
|
||||
bool hasInput = true;
|
||||
while (state->AvailOut > 0 && hasInput) {
|
||||
if (state->State == INFLATE_STATE_DONE) break;
|
||||
|
||||
if (!state->AvailIn) {
|
||||
/* Fully used up input buffer. Cycle back to start. */
|
||||
uint8_t* inputEnd = state->Input + INFLATE_MAX_INPUT;
|
||||
inputEnd = state->Input + INFLATE_MAX_INPUT;
|
||||
if (state->NextIn == inputEnd) state->NextIn = state->Input;
|
||||
|
||||
uint8_t* cur = state->NextIn;
|
||||
uint32_t read, remaining = (uint32_t)(inputEnd - state->NextIn);
|
||||
ReturnCode res = state->Source->Read(state->Source, cur, remaining, &read);
|
||||
left = (uint32_t)(inputEnd - state->NextIn);
|
||||
res = state->Source->Read(state->Source, state->NextIn, left, &read);
|
||||
if (res) return res;
|
||||
|
||||
/* Did we fail to read in more input data? Can't immediately return here, */
|
||||
|
@ -689,9 +699,9 @@ static ReturnCode Inflate_StreamRead(struct Stream* stream, uint8_t* data, uint3
|
|||
}
|
||||
|
||||
/* Reading data reduces available out */
|
||||
uint32_t preAvailOut = state->AvailOut;
|
||||
startAvailOut = state->AvailOut;
|
||||
Inflate_Process(state);
|
||||
*modified += (preAvailOut - state->AvailOut);
|
||||
*modified += (startAvailOut - state->AvailOut);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -757,6 +767,8 @@ static void Deflate_LenDist(struct DeflateState* state, int len, int dist) {
|
|||
}
|
||||
|
||||
static ReturnCode Deflate_FlushBlock(struct DeflateState* state, int len) {
|
||||
ReturnCode res;
|
||||
|
||||
if (!state->WroteHeader) {
|
||||
state->WroteHeader = true;
|
||||
Deflate_PushBits(state, 3, 3); /* final block TRUE, block type FIXED */
|
||||
|
@ -789,7 +801,7 @@ static ReturnCode Deflate_FlushBlock(struct DeflateState* state, int len) {
|
|||
pos = (int)(cur - src);
|
||||
uint16_t oldHead = state->Head[hash];
|
||||
state->Head[hash] = pos;
|
||||
state->Prev[pos] = oldHead;
|
||||
state->Prev[pos] = oldHead;
|
||||
|
||||
/* Lazy evaluation: Find longest match starting at next byte */
|
||||
/* If that's longer than the longest match at current byte, throwaway this match */
|
||||
|
@ -815,8 +827,8 @@ static ReturnCode Deflate_FlushBlock(struct DeflateState* state, int len) {
|
|||
|
||||
/* leave room for a few bytes and literals at end */
|
||||
if (state->AvailOut >= 20) continue;
|
||||
ReturnCode res = Stream_Write(state->Dest, state->Output, DEFLATE_OUT_SIZE - state->AvailOut);
|
||||
state->NextOut = state->Output;
|
||||
res = Stream_Write(state->Dest, state->Output, DEFLATE_OUT_SIZE - state->AvailOut);
|
||||
state->NextOut = state->Output;
|
||||
state->AvailOut = DEFLATE_OUT_SIZE;
|
||||
if (res) return res;
|
||||
}
|
||||
|
@ -826,12 +838,12 @@ static ReturnCode Deflate_FlushBlock(struct DeflateState* state, int len) {
|
|||
Deflate_Lit(state, *cur);
|
||||
len--; cur++;
|
||||
}
|
||||
|
||||
state->InputPosition = 0;
|
||||
ReturnCode resFinal = Stream_Write(state->Dest, state->Output, DEFLATE_OUT_SIZE - state->AvailOut);
|
||||
state->NextOut = state->Output;
|
||||
|
||||
res = Stream_Write(state->Dest, state->Output, DEFLATE_OUT_SIZE - state->AvailOut);
|
||||
state->NextOut = state->Output;
|
||||
state->AvailOut = DEFLATE_OUT_SIZE;
|
||||
return resFinal;
|
||||
return res;
|
||||
}
|
||||
|
||||
static ReturnCode Deflate_StreamWrite(struct Stream* stream, uint8_t* data, uint32_t count, uint32_t* modified) {
|
||||
|
|
|
@ -60,8 +60,8 @@ void AnimatedComp_Init(struct AnimatedComp* anim) {
|
|||
anim->BobStrength = 1.0f; anim->BobStrengthO = 1.0f; anim->BobStrengthN = 1.0f;
|
||||
}
|
||||
|
||||
void AnimatedComp_Update(struct Entity* entity, Vector3 oldPos, Vector3 newPos, double delta) {
|
||||
struct AnimatedComp* anim = &entity->Anim;
|
||||
void AnimatedComp_Update(struct Entity* e, Vector3 oldPos, Vector3 newPos, double delta) {
|
||||
struct AnimatedComp* anim = &e->Anim;
|
||||
float dx = newPos.X - oldPos.X;
|
||||
float dz = newPos.Z - oldPos.Z;
|
||||
float distance = Math_SqrtF(dx * dx + dz * dz);
|
||||
|
@ -83,12 +83,12 @@ void AnimatedComp_Update(struct Entity* entity, Vector3 oldPos, Vector3 newPos,
|
|||
/* TODO: the Tilt code was designed for 60 ticks/second, fix it up for 20 ticks/second */
|
||||
anim->BobStrengthO = anim->BobStrengthN;
|
||||
for (i = 0; i < 3; i++) {
|
||||
AnimatedComp_DoTilt(&anim->BobStrengthN, !Game_ViewBobbing || !entity->OnGround);
|
||||
AnimatedComp_DoTilt(&anim->BobStrengthN, !Game_ViewBobbing || !e->OnGround);
|
||||
}
|
||||
}
|
||||
|
||||
void AnimatedComp_GetCurrent(struct Entity* entity, float t) {
|
||||
struct AnimatedComp* anim = &entity->Anim;
|
||||
void AnimatedComp_GetCurrent(struct Entity* e, float t) {
|
||||
struct AnimatedComp* anim = &e->Anim;
|
||||
float idleTime = (float)Game_Accumulator;
|
||||
float idleXRot = Math_SinF(idleTime * ANIM_IDLE_XPERIOD) * ANIM_IDLE_MAX;
|
||||
float idleZRot = Math_CosF(idleTime * ANIM_IDLE_ZPERIOD) * ANIM_IDLE_MAX + ANIM_IDLE_MAX;
|
||||
|
@ -109,7 +109,7 @@ void AnimatedComp_GetCurrent(struct Entity* entity, float t) {
|
|||
anim->BobbingVer = Math_AbsF(Math_SinF(anim->WalkTime)) * anim->Swing * (2.5f/16.0f);
|
||||
anim->BobbingModel = Math_AbsF(Math_CosF(anim->WalkTime)) * anim->Swing * (4.0f/16.0f);
|
||||
|
||||
if (entity->Model->CalcHumanAnims && !Game_SimpleArmsAnim) {
|
||||
if (e->Model->CalcHumanAnims && !Game_SimpleArmsAnim) {
|
||||
AnimatedComp_CalcHumanAnim(anim, idleXRot, idleZRot);
|
||||
}
|
||||
}
|
||||
|
@ -323,15 +323,15 @@ static void InterpComp_AdvanceRotY(struct InterpComp* interp) {
|
|||
InterpComp_RemoveOldestRotY(interp);
|
||||
}
|
||||
|
||||
void InterpComp_LerpAngles(struct InterpComp* interp, struct Entity* entity, float t) {
|
||||
void InterpComp_LerpAngles(struct InterpComp* interp, struct Entity* e, float t) {
|
||||
struct InterpState* prev = &interp->Prev;
|
||||
struct InterpState* next = &interp->Next;
|
||||
|
||||
entity->HeadX = Math_LerpAngle(prev->HeadX, next->HeadX, t);
|
||||
entity->HeadY = Math_LerpAngle(prev->HeadY, next->HeadY, t);
|
||||
entity->RotX = Math_LerpAngle(prev->RotX, next->RotX, t);
|
||||
entity->RotY = Math_LerpAngle(interp->PrevRotY, interp->NextRotY, t);
|
||||
entity->RotZ = Math_LerpAngle(prev->RotZ, next->RotZ, t);
|
||||
e->HeadX = Math_LerpAngle(prev->HeadX, next->HeadX, t);
|
||||
e->HeadY = Math_LerpAngle(prev->HeadY, next->HeadY, t);
|
||||
e->RotX = Math_LerpAngle(prev->RotX, next->RotX, t);
|
||||
e->RotY = Math_LerpAngle(interp->PrevRotY, interp->NextRotY, t);
|
||||
e->RotZ = Math_LerpAngle(prev->RotZ, next->RotZ, t);
|
||||
}
|
||||
|
||||
static void InterpComp_SetPos(struct InterpState* state, struct LocationUpdate* update) {
|
||||
|
@ -417,12 +417,14 @@ void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdat
|
|||
struct InterpState* prev = &interp->Prev;
|
||||
struct InterpState* next = &interp->Next;
|
||||
uint8_t flags = update->Flags;
|
||||
float yOffset;
|
||||
|
||||
if (flags & LOCATIONUPDATE_FLAG_POS) {
|
||||
InterpComp_SetPos(next, update);
|
||||
/* If server sets Y position exactly on ground, push up a tiny bit */
|
||||
float yOffset = next->Pos.Y - Math_Floor(next->Pos.Y);
|
||||
if (yOffset < ENTITY_ADJUSTMENT) { next->Pos.Y += ENTITY_ADJUSTMENT; }
|
||||
yOffset = next->Pos.Y - Math_Floor(next->Pos.Y);
|
||||
|
||||
if (yOffset < ENTITY_ADJUSTMENT) next->Pos.Y += ENTITY_ADJUSTMENT;
|
||||
if (!interpolate) { prev->Pos = next->Pos; entity->Position = next->Pos; }
|
||||
}
|
||||
|
||||
|
@ -433,10 +435,10 @@ void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdat
|
|||
LocalInterpComp_Angle(&prev->HeadY, &next->HeadY, update->HeadY, interpolate);
|
||||
}
|
||||
if (flags & LOCATIONUPDATE_FLAG_ROTX) {
|
||||
LocalInterpComp_Angle(&prev->RotX, &next->RotX, update->RotX, interpolate);
|
||||
LocalInterpComp_Angle(&prev->RotX, &next->RotX, update->RotX, interpolate);
|
||||
}
|
||||
if (flags & LOCATIONUPDATE_FLAG_ROTZ) {
|
||||
LocalInterpComp_Angle(&prev->RotZ, &next->RotZ, update->RotZ, interpolate);
|
||||
LocalInterpComp_Angle(&prev->RotZ, &next->RotZ, update->RotZ, interpolate);
|
||||
}
|
||||
|
||||
if (flags & LOCATIONUPDATE_FLAG_HEADY) {
|
||||
|
@ -467,24 +469,27 @@ void LocalInterpComp_AdvanceState(struct InterpComp* interp) {
|
|||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------ShadowComponent-----------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static float ShadowComponent_radius, shadowComponent_uvScale;
|
||||
static float shadow_radius, shadow_uvScale;
|
||||
struct ShadowData { float Y; BlockID Block; uint8_t A; };
|
||||
|
||||
static bool lequal(float a, float b) { return a < b || Math_AbsF(a - b) < 0.001f; }
|
||||
static void ShadowComponent_DrawCoords(VertexP3fT2fC4b** vertices, struct Entity* entity, struct ShadowData* data, float x1, float z1, float x2, float z2) {
|
||||
Vector3 cen = entity->Position;
|
||||
if (lequal(x2, x1) || lequal(z2, z1)) return;
|
||||
static void ShadowComponent_DrawCoords(VertexP3fT2fC4b** vertices, struct Entity* e, struct ShadowData* data, float x1, float z1, float x2, float z2) {
|
||||
Vector3 cen;
|
||||
float u1, v1, u2, v2;
|
||||
|
||||
float u1 = (x1 - cen.X) * shadowComponent_uvScale + 0.5f;
|
||||
float v1 = (z1 - cen.Z) * shadowComponent_uvScale + 0.5f;
|
||||
float u2 = (x2 - cen.X) * shadowComponent_uvScale + 0.5f;
|
||||
float v2 = (z2 - cen.Z) * shadowComponent_uvScale + 0.5f;
|
||||
if (lequal(x2, x1) || lequal(z2, z1)) return;
|
||||
cen = e->Position;
|
||||
|
||||
u1 = (x1 - cen.X) * shadow_uvScale + 0.5f;
|
||||
v1 = (z1 - cen.Z) * shadow_uvScale + 0.5f;
|
||||
u2 = (x2 - cen.X) * shadow_uvScale + 0.5f;
|
||||
v2 = (z2 - cen.Z) * shadow_uvScale + 0.5f;
|
||||
if (u2 <= 0.0f || v2 <= 0.0f || u1 >= 1.0f || v1 >= 1.0f) return;
|
||||
|
||||
x1 = max(x1, cen.X - ShadowComponent_radius); u1 = u1 >= 0.0f ? u1 : 0.0f;
|
||||
z1 = max(z1, cen.Z - ShadowComponent_radius); v1 = v1 >= 0.0f ? v1 : 0.0f;
|
||||
x2 = min(x2, cen.X + ShadowComponent_radius); u2 = u2 <= 1.0f ? u2 : 1.0f;
|
||||
z2 = min(z2, cen.Z + ShadowComponent_radius); v2 = v2 <= 1.0f ? v2 : 1.0f;
|
||||
x1 = max(x1, cen.X - shadow_radius); u1 = u1 >= 0.0f ? u1 : 0.0f;
|
||||
z1 = max(z1, cen.Z - shadow_radius); v1 = v1 >= 0.0f ? v1 : 0.0f;
|
||||
x2 = min(x2, cen.X + shadow_radius); u2 = u2 <= 1.0f ? u2 : 1.0f;
|
||||
z2 = min(z2, cen.Z + shadow_radius); v2 = v2 <= 1.0f ? v2 : 1.0f;
|
||||
|
||||
PackedCol col = PACKEDCOL_CONST(255, 255, 255, data->A);
|
||||
VertexP3fT2fC4b* ptr = *vertices;
|
||||
|
@ -512,20 +517,20 @@ static void ShadowComponent_DrawSquareShadow(VertexP3fT2fC4b** vertices, float y
|
|||
*vertices = ptr;
|
||||
}
|
||||
|
||||
static void ShadowComponent_DrawCircle(VertexP3fT2fC4b** vertices, struct Entity* entity, struct ShadowData* data, float x, float z) {
|
||||
static void ShadowComponent_DrawCircle(VertexP3fT2fC4b** vertices, struct Entity* e, struct ShadowData* data, float x, float z) {
|
||||
x = (float)Math_Floor(x); z = (float)Math_Floor(z);
|
||||
Vector3 min = Block_MinBB[data[0].Block], max = Block_MaxBB[data[0].Block];
|
||||
|
||||
ShadowComponent_DrawCoords(vertices, entity, &data[0], x + min.X, z + min.Z, x + max.X, z + max.Z);
|
||||
ShadowComponent_DrawCoords(vertices, e, &data[0], x + min.X, z + min.Z, x + max.X, z + max.Z);
|
||||
int i;
|
||||
for (i = 1; i < 4; i++) {
|
||||
if (data[i].Block == BLOCK_AIR) return;
|
||||
Vector3 nMin = Block_MinBB[data[i].Block], nMax = Block_MaxBB[data[i].Block];
|
||||
ShadowComponent_DrawCoords(vertices, entity, &data[i], x + min.X, z + nMin.Z, x + max.X, z + min.Z);
|
||||
ShadowComponent_DrawCoords(vertices, entity, &data[i], x + min.X, z + max.Z, x + max.X, z + nMax.Z);
|
||||
ShadowComponent_DrawCoords(vertices, e, &data[i], x + min.X, z + nMin.Z, x + max.X, z + min.Z);
|
||||
ShadowComponent_DrawCoords(vertices, e, &data[i], x + min.X, z + max.Z, x + max.X, z + nMax.Z);
|
||||
|
||||
ShadowComponent_DrawCoords(vertices, entity, &data[i], x + nMin.X, z + nMin.Z, x + min.X, z + nMax.Z);
|
||||
ShadowComponent_DrawCoords(vertices, entity, &data[i], x + max.X, z + nMin.Z, x + nMax.X, z + nMax.Z);
|
||||
ShadowComponent_DrawCoords(vertices, e, &data[i], x + nMin.X, z + nMin.Z, x + min.X, z + nMax.Z);
|
||||
ShadowComponent_DrawCoords(vertices, e, &data[i], x + max.X, z + nMin.Z, x + nMax.X, z + nMax.Z);
|
||||
min = nMin; max = nMax;
|
||||
}
|
||||
}
|
||||
|
@ -544,13 +549,13 @@ static void ShadowComponent_CalcAlpha(float playerY, struct ShadowData* data) {
|
|||
else data->Y += 1.0f / 4.0f;
|
||||
}
|
||||
|
||||
static bool ShadowComponent_GetBlocks(struct Entity* entity, int x, int y, int z, struct ShadowData* data) {
|
||||
static bool ShadowComponent_GetBlocks(struct Entity* e, int x, int y, int z, struct ShadowData* data) {
|
||||
int i;
|
||||
struct ShadowData zeroData = { 0 };
|
||||
|
||||
for (i = 0; i < 4; i++) { data[i] = zeroData; }
|
||||
struct ShadowData* cur = data;
|
||||
float posY = entity->Position.Y;
|
||||
float posY = e->Position.Y;
|
||||
bool outside = x < 0 || z < 0 || x >= World_Width || z >= World_Length;
|
||||
|
||||
for (i = 0; y >= 0 && i < 4; y--) {
|
||||
|
@ -609,17 +614,19 @@ static void ShadowComponent_MakeTex(void) {
|
|||
ShadowComponent_ShadowTex = Gfx_CreateTexture(&bmp, false, false);
|
||||
}
|
||||
|
||||
void ShadowComponent_Draw(struct Entity* entity) {
|
||||
Vector3 Position = entity->Position;
|
||||
if (Position.Y < 0.0f) return;
|
||||
|
||||
float posX = Position.X, posZ = Position.Z;
|
||||
int posY = min((int)Position.Y, World_MaxY);
|
||||
void ShadowComponent_Draw(struct Entity* e) {
|
||||
GfxResourceID vb;
|
||||
Vector3 pos;
|
||||
int y, count;
|
||||
int x1, z1, x2, z2;
|
||||
|
||||
float radius = 7.0f * min(entity->ModelScale.Y, 1.0f) * entity->Model->ShadowScale;
|
||||
ShadowComponent_radius = radius / 16.0f;
|
||||
shadowComponent_uvScale = 16.0f / (radius * 2.0f);
|
||||
pos = e->Position;
|
||||
if (pos.Y < 0.0f) return;
|
||||
y = min((int)pos.Y, World_MaxY);
|
||||
|
||||
float radius = 7.0f * min(e->ModelScale.Y, 1.0f) * e->Model->ShadowScale;
|
||||
shadow_radius = radius / 16.0f;
|
||||
shadow_uvScale = 16.0f / (radius * 2.0f);
|
||||
|
||||
VertexP3fT2fC4b vertices[128];
|
||||
struct ShadowData data[4];
|
||||
|
@ -628,26 +635,26 @@ void ShadowComponent_Draw(struct Entity* entity) {
|
|||
VertexP3fT2fC4b* ptr = vertices;
|
||||
if (Entities_ShadowMode == SHADOW_MODE_SNAP_TO_BLOCK) {
|
||||
vb = GfxCommon_texVb;
|
||||
int x1 = Math_Floor(posX), z1 = Math_Floor(posZ);
|
||||
if (!ShadowComponent_GetBlocks(entity, x1, posY, z1, data)) return;
|
||||
x1 = Math_Floor(pos.X); z1 = Math_Floor(pos.Z);
|
||||
if (!ShadowComponent_GetBlocks(e, x1, y, z1, data)) return;
|
||||
|
||||
ShadowComponent_DrawSquareShadow(&ptr, data[0].Y, x1, z1);
|
||||
} else {
|
||||
vb = ModelCache_Vb;
|
||||
int x1 = Math_Floor(posX - ShadowComponent_radius), z1 = Math_Floor(posZ - ShadowComponent_radius);
|
||||
int x2 = Math_Floor(posX + ShadowComponent_radius), z2 = Math_Floor(posZ + ShadowComponent_radius);
|
||||
x1 = Math_Floor(pos.X - shadow_radius); z1 = Math_Floor(pos.Z - shadow_radius);
|
||||
x2 = Math_Floor(pos.X + shadow_radius); z2 = Math_Floor(pos.Z + shadow_radius);
|
||||
|
||||
if (ShadowComponent_GetBlocks(entity, x1, posY, z1, data) && data[0].A > 0) {
|
||||
ShadowComponent_DrawCircle(&ptr, entity, data, (float)x1, (float)z1);
|
||||
if (ShadowComponent_GetBlocks(e, x1, y, z1, data) && data[0].A > 0) {
|
||||
ShadowComponent_DrawCircle(&ptr, e, data, (float)x1, (float)z1);
|
||||
}
|
||||
if (x1 != x2 && ShadowComponent_GetBlocks(entity, x2, posY, z1, data) && data[0].A > 0) {
|
||||
ShadowComponent_DrawCircle(&ptr, entity, data, (float)x2, (float)z1);
|
||||
if (x1 != x2 && ShadowComponent_GetBlocks(e, x2, y, z1, data) && data[0].A > 0) {
|
||||
ShadowComponent_DrawCircle(&ptr, e, data, (float)x2, (float)z1);
|
||||
}
|
||||
if (z1 != z2 && ShadowComponent_GetBlocks(entity, x1, posY, z2, data) && data[0].A > 0) {
|
||||
ShadowComponent_DrawCircle(&ptr, entity, data, (float)x1, (float)z2);
|
||||
if (z1 != z2 && ShadowComponent_GetBlocks(e, x1, y, z2, data) && data[0].A > 0) {
|
||||
ShadowComponent_DrawCircle(&ptr, e, data, (float)x1, (float)z2);
|
||||
}
|
||||
if (x1 != x2 && z1 != z2 && ShadowComponent_GetBlocks(entity, x2, posY, z2, data) && data[0].A > 0) {
|
||||
ShadowComponent_DrawCircle(&ptr, entity, data, (float)x2, (float)z2);
|
||||
if (x1 != x2 && z1 != z2 && ShadowComponent_GetBlocks(e, x2, y, z2, data) && data[0].A > 0) {
|
||||
ShadowComponent_DrawCircle(&ptr, e, data, (float)x2, (float)z2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -659,8 +666,8 @@ void ShadowComponent_Draw(struct Entity* entity) {
|
|||
ShadowComponent_BoundShadowTex = true;
|
||||
}
|
||||
|
||||
int vCount = (int)(ptr - vertices);
|
||||
GfxCommon_UpdateDynamicVb_IndexedTris(vb, vertices, vCount);
|
||||
count = (int)(ptr - vertices);
|
||||
GfxCommon_UpdateDynamicVb_IndexedTris(vb, vertices, count);
|
||||
}
|
||||
|
||||
|
||||
|
@ -673,22 +680,22 @@ bool Collisions_HitHorizontal(struct CollisionsComp* comp) {
|
|||
}
|
||||
#define COLLISIONS_ADJ 0.001f
|
||||
|
||||
static void Collisions_ClipX(struct Entity* entity, Vector3* size, struct AABB* entityBB, struct AABB* extentBB) {
|
||||
entity->Velocity.X = 0.0f;
|
||||
entityBB->Min.X = entity->Position.X - size->X / 2; extentBB->Min.X = entityBB->Min.X;
|
||||
entityBB->Max.X = entity->Position.X + size->X / 2; extentBB->Max.X = entityBB->Max.X;
|
||||
static void Collisions_ClipX(struct Entity* e, Vector3* size, struct AABB* entityBB, struct AABB* extentBB) {
|
||||
e->Velocity.X = 0.0f;
|
||||
entityBB->Min.X = e->Position.X - size->X / 2; extentBB->Min.X = entityBB->Min.X;
|
||||
entityBB->Max.X = e->Position.X + size->X / 2; extentBB->Max.X = entityBB->Max.X;
|
||||
}
|
||||
|
||||
static void Collisions_ClipY(struct Entity* entity, Vector3* size, struct AABB* entityBB, struct AABB* extentBB) {
|
||||
entity->Velocity.Y = 0.0f;
|
||||
entityBB->Min.Y = entity->Position.Y; extentBB->Min.Y = entityBB->Min.Y;
|
||||
entityBB->Max.Y = entity->Position.Y + size->Y; extentBB->Max.Y = entityBB->Max.Y;
|
||||
static void Collisions_ClipY(struct Entity* e, Vector3* size, struct AABB* entityBB, struct AABB* extentBB) {
|
||||
e->Velocity.Y = 0.0f;
|
||||
entityBB->Min.Y = e->Position.Y; extentBB->Min.Y = entityBB->Min.Y;
|
||||
entityBB->Max.Y = e->Position.Y + size->Y; extentBB->Max.Y = entityBB->Max.Y;
|
||||
}
|
||||
|
||||
static void Collisions_ClipZ(struct Entity* entity, Vector3* size, struct AABB* entityBB, struct AABB* extentBB) {
|
||||
entity->Velocity.Z = 0.0f;
|
||||
entityBB->Min.Z = entity->Position.Z - size->Z / 2; extentBB->Min.Z = entityBB->Min.Z;
|
||||
entityBB->Max.Z = entity->Position.Z + size->Z / 2; extentBB->Max.Z = entityBB->Max.Z;
|
||||
static void Collisions_ClipZ(struct Entity* e, Vector3* size, struct AABB* entityBB, struct AABB* extentBB) {
|
||||
e->Velocity.Z = 0.0f;
|
||||
entityBB->Min.Z = e->Position.Z - size->Z / 2; extentBB->Min.Z = entityBB->Min.Z;
|
||||
entityBB->Max.Z = e->Position.Z + size->Z / 2; extentBB->Max.Z = entityBB->Max.Z;
|
||||
}
|
||||
|
||||
static bool Collisions_CanSlideThrough(struct AABB* adjFinalBB) {
|
||||
|
@ -720,13 +727,14 @@ static bool Collisions_CanSlideThrough(struct AABB* adjFinalBB) {
|
|||
static bool Collisions_DidSlide(struct CollisionsComp* comp, struct AABB* blockBB, Vector3* size,
|
||||
struct AABB* finalBB, struct AABB* entityBB, struct AABB* extentBB) {
|
||||
float yDist = blockBB->Max.Y - entityBB->Min.Y;
|
||||
struct AABB adjBB;
|
||||
|
||||
if (yDist > 0.0f && yDist <= comp->Entity->StepSize + 0.01f) {
|
||||
float blockBB_MinX = max(blockBB->Min.X, blockBB->Max.X - size->X / 2);
|
||||
float blockBB_MaxX = min(blockBB->Max.X, blockBB->Min.X + size->X / 2);
|
||||
float blockBB_MinZ = max(blockBB->Min.Z, blockBB->Max.Z - size->Z / 2);
|
||||
float blockBB_MaxZ = min(blockBB->Max.Z, blockBB->Min.Z + size->Z / 2);
|
||||
|
||||
struct AABB adjBB;
|
||||
|
||||
adjBB.Min.X = min(finalBB->Min.X, blockBB_MinX + COLLISIONS_ADJ);
|
||||
adjBB.Max.X = max(finalBB->Max.X, blockBB_MaxX - COLLISIONS_ADJ);
|
||||
adjBB.Min.Y = blockBB->Max.Y + COLLISIONS_ADJ;
|
||||
|
@ -867,11 +875,12 @@ static void Collisions_CollideWithReachableBlocks(struct CollisionsComp* comp, i
|
|||
|
||||
/* TODO: test for corner cases, and refactor this */
|
||||
void Collisions_MoveAndWallSlide(struct CollisionsComp* comp) {
|
||||
struct Entity* entity = comp->Entity;
|
||||
if (Vector3_Equals(&entity->Velocity, &Vector3_Zero)) return;
|
||||
|
||||
struct Entity* e = comp->Entity;
|
||||
struct AABB entityBB, entityExtentBB;
|
||||
int count = Searcher_FindReachableBlocks(entity, &entityBB, &entityExtentBB);
|
||||
int count;
|
||||
|
||||
if (Vector3_Equals(&e->Velocity, &Vector3_Zero)) return;
|
||||
count = Searcher_FindReachableBlocks(e, &entityBB, &entityExtentBB);
|
||||
Collisions_CollideWithReachableBlocks(comp, count, &entityBB, &entityExtentBB);
|
||||
}
|
||||
|
||||
|
@ -963,13 +972,13 @@ void PhysicsComp_DoNormalJump(struct PhysicsComp* comp) {
|
|||
}
|
||||
|
||||
static bool PhysicsComp_TouchesSlipperyIce(BlockID b) { return Block_ExtendedCollide[b] == COLLIDE_SLIPPERY_ICE; }
|
||||
static bool PhysicsComp_OnIce(struct Entity* entity) {
|
||||
Vector3 under = entity->Position; under.Y -= 0.01f;
|
||||
static bool PhysicsComp_OnIce(struct Entity* e) {
|
||||
Vector3 under = e->Position; under.Y -= 0.01f;
|
||||
Vector3I underCoords; Vector3I_Floor(&underCoords, &under);
|
||||
BlockID blockUnder = World_SafeGetBlock_3I(underCoords);
|
||||
if (Block_ExtendedCollide[blockUnder] == COLLIDE_ICE) return true;
|
||||
|
||||
struct AABB bounds; Entity_GetBounds(entity, &bounds);
|
||||
struct AABB bounds; Entity_GetBounds(e, &bounds);
|
||||
bounds.Min.Y -= 0.01f; bounds.Max.Y = bounds.Min.Y;
|
||||
return Entity_TouchesAny(&bounds, PhysicsComp_TouchesSlipperyIce);
|
||||
}
|
||||
|
@ -1062,11 +1071,15 @@ static float PhysicsComp_GetSpeed(struct HacksComp* hacks, float speedMul) {
|
|||
}
|
||||
|
||||
static float PhysicsComp_GetBaseSpeed(struct PhysicsComp* comp) {
|
||||
struct AABB bounds; Entity_GetBounds(comp->Entity, &bounds);
|
||||
struct AABB bounds;
|
||||
float baseModifier, solidModifier;
|
||||
|
||||
Entity_GetBounds(comp->Entity, &bounds);
|
||||
comp->UseLiquidGravity = false;
|
||||
float baseModifier = PhysicsComp_LowestModifier(comp, &bounds, false);
|
||||
bounds.Min.Y -= 0.5f / 16.0f; /* also check block standing on */
|
||||
float solidModifier = PhysicsComp_LowestModifier(comp, &bounds, true);
|
||||
|
||||
baseModifier = PhysicsComp_LowestModifier(comp, &bounds, false);
|
||||
bounds.Min.Y -= 0.5f/16.0f; /* also check block standing on */
|
||||
solidModifier = PhysicsComp_LowestModifier(comp, &bounds, true);
|
||||
|
||||
if (baseModifier == MATH_POS_INF && solidModifier == MATH_POS_INF) return 1.0f;
|
||||
return baseModifier == MATH_POS_INF ? solidModifier : baseModifier;
|
||||
|
|
|
@ -259,8 +259,8 @@ void Window_SetTitle(const String* title) {
|
|||
}
|
||||
|
||||
static char clipboard_copy_buffer[256];
|
||||
static String clipboard_copy_text = String_FromArray(clipboard_copy_buffer);
|
||||
static char clipboard_paste_buffer[256];
|
||||
static String clipboard_copy_text = String_FromArray(clipboard_copy_buffer);
|
||||
static String clipboard_paste_text = String_FromArray(clipboard_paste_buffer);
|
||||
|
||||
void Window_GetClipboardText(String* value) {
|
||||
|
|
|
@ -222,14 +222,14 @@ static bool TerrainParticle_Tick(struct TerrainParticle* p, double delta) {
|
|||
}
|
||||
|
||||
static void TerrainParticle_Render(struct TerrainParticle* p, float t, VertexP3fT2fC4b* vertices) {
|
||||
PackedCol col = PACKEDCOL_WHITE;
|
||||
Vector3 pos;
|
||||
Vector2 size;
|
||||
int x, y, z;
|
||||
|
||||
Vector3_Lerp(&pos, &p->Base.LastPos, &p->Base.NextPos, t);
|
||||
size.X = (float)p->Base.Size * 0.015625f; size.Y = size.X;
|
||||
|
||||
PackedCol col = PACKEDCOL_WHITE;
|
||||
|
||||
if (!Block_FullBright[p->Block]) {
|
||||
x = Math_Floor(pos.X); y = Math_Floor(pos.Y); z = Math_Floor(pos.Z);
|
||||
col = World_IsValidPos(x, y, z) ? Lighting_Col_XSide(x, y, z) : Env_SunXSide;
|
||||
|
|
|
@ -154,6 +154,7 @@ int Searcher_FindReachableBlocks(struct Entity* entity, struct AABB* entityBB, s
|
|||
Vector3I min, max;
|
||||
uint32_t elements;
|
||||
struct SearcherState* curState;
|
||||
int count;
|
||||
|
||||
BlockID block;
|
||||
struct AABB blockBB;
|
||||
|
@ -207,7 +208,7 @@ int Searcher_FindReachableBlocks(struct Entity* entity, struct AABB* entityBB, s
|
|||
}
|
||||
}
|
||||
|
||||
int count = (int)(curState - Searcher_States);
|
||||
count = (int)(curState - Searcher_States);
|
||||
if (count) Searcher_QuickSort(0, count - 1);
|
||||
return count;
|
||||
}
|
||||
|
|
|
@ -1372,7 +1372,7 @@ static size_t Http_GetHeaders(char *buffer, size_t size, size_t nitems, struct A
|
|||
|
||||
if (String_CaselessEqualsConst(&name, "ETag")) {
|
||||
tmp = String_ClearedArray(req->Etag);
|
||||
String_AppendString(&etag, &value);
|
||||
String_AppendString(&tmp, &value);
|
||||
} else if (String_CaselessEqualsConst(&name, "Content-Length")) {
|
||||
Convert_TryParseInt(&value, &req->ResultSize);
|
||||
} else if (String_CaselessEqualsConst(&name, "Last-Modified")) {
|
||||
|
|
Loading…
Add table
Reference in a new issue