mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 03:55:19 -04:00
minor code cleanup
This commit is contained in:
parent
29b172f2c6
commit
127df95b2c
@ -314,7 +314,7 @@ void Classic_SendChat(const String* text, cc_bool partial) {
|
|||||||
Server.SendData(data, 66);
|
Server.SendData(data, 66);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Classic_WritePosition(Vec3 pos, float rotY, float pitch) {
|
void Classic_WritePosition(Vec3 pos, float yaw, float pitch) {
|
||||||
BlockID payload;
|
BlockID payload;
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
|
||||||
@ -337,7 +337,7 @@ void Classic_WritePosition(Vec3 pos, float rotY, float pitch) {
|
|||||||
Stream_SetU16_BE(data, z); data += 2;
|
Stream_SetU16_BE(data, z); data += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
*data++ = Math_Deg2Packed(rotY);
|
*data++ = Math_Deg2Packed(yaw);
|
||||||
*data++ = Math_Deg2Packed(pitch);
|
*data++ = Math_Deg2Packed(pitch);
|
||||||
}
|
}
|
||||||
Server.WriteBuffer = data;
|
Server.WriteBuffer = data;
|
||||||
@ -573,15 +573,15 @@ static void Classic_RelPosAndOrientationUpdate(cc_uint8* data) {
|
|||||||
struct LocationUpdate update;
|
struct LocationUpdate update;
|
||||||
EntityID id = *data++;
|
EntityID id = *data++;
|
||||||
Vec3 pos;
|
Vec3 pos;
|
||||||
float rotY, pitch;
|
float yaw, pitch;
|
||||||
|
|
||||||
pos.X = (cc_int8)(*data++) / 32.0f;
|
pos.X = (cc_int8)(*data++) / 32.0f;
|
||||||
pos.Y = (cc_int8)(*data++) / 32.0f;
|
pos.Y = (cc_int8)(*data++) / 32.0f;
|
||||||
pos.Z = (cc_int8)(*data++) / 32.0f;
|
pos.Z = (cc_int8)(*data++) / 32.0f;
|
||||||
rotY = Math_Packed2Deg(*data++);
|
yaw = Math_Packed2Deg(*data++);
|
||||||
pitch = Math_Packed2Deg(*data++);
|
pitch = Math_Packed2Deg(*data++);
|
||||||
|
|
||||||
LocationUpdate_MakePosAndOri(&update, pos, rotY, pitch, true);
|
LocationUpdate_MakePosAndOri(&update, pos, yaw, pitch, true);
|
||||||
Protocol_UpdateLocation(id, &update, true);
|
Protocol_UpdateLocation(id, &update, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,12 +601,12 @@ static void Classic_RelPositionUpdate(cc_uint8* data) {
|
|||||||
static void Classic_OrientationUpdate(cc_uint8* data) {
|
static void Classic_OrientationUpdate(cc_uint8* data) {
|
||||||
struct LocationUpdate update;
|
struct LocationUpdate update;
|
||||||
EntityID id = *data++;
|
EntityID id = *data++;
|
||||||
float rotY, pitch;
|
float yaw, pitch;
|
||||||
|
|
||||||
rotY = Math_Packed2Deg(*data++);
|
yaw = Math_Packed2Deg(*data++);
|
||||||
pitch = Math_Packed2Deg(*data++);
|
pitch = Math_Packed2Deg(*data++);
|
||||||
|
|
||||||
LocationUpdate_MakeOri(&update, rotY, pitch);
|
LocationUpdate_MakeOri(&update, yaw, pitch);
|
||||||
Protocol_UpdateLocation(id, &update, true);
|
Protocol_UpdateLocation(id, &update, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,7 +655,7 @@ static void Classic_ReadAbsoluteLocation(cc_uint8* data, EntityID id, cc_bool in
|
|||||||
struct LocationUpdate update;
|
struct LocationUpdate update;
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
Vec3 pos;
|
Vec3 pos;
|
||||||
float rotY, pitch;
|
float yaw, pitch;
|
||||||
|
|
||||||
if (cpe_extEntityPos) {
|
if (cpe_extEntityPos) {
|
||||||
x = (int)Stream_GetU32_BE(&data[0]);
|
x = (int)Stream_GetU32_BE(&data[0]);
|
||||||
@ -673,11 +673,11 @@ static void Classic_ReadAbsoluteLocation(cc_uint8* data, EntityID id, cc_bool in
|
|||||||
if (id == ENTITIES_SELF_ID) y += 22;
|
if (id == ENTITIES_SELF_ID) y += 22;
|
||||||
|
|
||||||
pos.X = x/32.0f; pos.Y = y/32.0f; pos.Z = z/32.0f;
|
pos.X = x/32.0f; pos.Y = y/32.0f; pos.Z = z/32.0f;
|
||||||
rotY = Math_Packed2Deg(*data++);
|
yaw = Math_Packed2Deg(*data++);
|
||||||
pitch = Math_Packed2Deg(*data++);
|
pitch = Math_Packed2Deg(*data++);
|
||||||
|
|
||||||
if (id == ENTITIES_SELF_ID) classic_receivedFirstPos = true;
|
if (id == ENTITIES_SELF_ID) classic_receivedFirstPos = true;
|
||||||
LocationUpdate_MakePosAndOri(&update, pos, rotY, pitch, false);
|
LocationUpdate_MakePosAndOri(&update, pos, yaw, pitch, false);
|
||||||
Protocol_UpdateLocation(id, &update, interpolate);
|
Protocol_UpdateLocation(id, &update, interpolate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1318,31 +1318,20 @@ static void CPE_SetSpawnPoint(cc_uint8* data) {
|
|||||||
Vec3_Set(p->Spawn, (float)(x / 32.0f), (float)(y / 32.0f), (float)(z / 32.0f));
|
Vec3_Set(p->Spawn, (float)(x / 32.0f), (float)(y / 32.0f), (float)(z / 32.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
static float CalcVelocity(float cur, int raw, cc_uint8 mode) {
|
static void CalcVelocity(float* vel, cc_uint8* src, cc_uint8 mode) {
|
||||||
|
int raw = (int)Stream_GetU32_BE(src);
|
||||||
float value = Math_AbsF(raw / 10000.0f);
|
float value = Math_AbsF(raw / 10000.0f);
|
||||||
value = Math_Sign(raw) * PhysicsComp_CalcJumpVelocity(value);
|
value = Math_Sign(raw) * PhysicsComp_CalcJumpVelocity(value);
|
||||||
|
|
||||||
if (mode == 0) return cur + value;
|
if (mode == 0) *vel += value;
|
||||||
if (mode == 1) return value;
|
if (mode == 1) *vel = value;
|
||||||
return cur;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CPE_VelocityControl(cc_uint8* data) {
|
static void CPE_VelocityControl(cc_uint8* data) {
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
struct LocalPlayer* p = &LocalPlayer_Instance;
|
||||||
int x, y, z;
|
CalcVelocity(&p->Base.Velocity.X, data + 0, data[12]);
|
||||||
cc_uint8 xMode, yMode, zMode;
|
CalcVelocity(&p->Base.Velocity.Y, data + 4, data[13]);
|
||||||
|
CalcVelocity(&p->Base.Velocity.Z, data + 8, data[14]);
|
||||||
x = (int)Stream_GetU32_BE(&data[0]);
|
|
||||||
y = (int)Stream_GetU32_BE(&data[4]);
|
|
||||||
z = (int)Stream_GetU32_BE(&data[8]);
|
|
||||||
data += 12;
|
|
||||||
xMode = *data++;
|
|
||||||
yMode = *data++;
|
|
||||||
zMode = *data++;
|
|
||||||
|
|
||||||
p->Base.Velocity.X = CalcVelocity(p->Base.Velocity.X, x, xMode);
|
|
||||||
p->Base.Velocity.Y = CalcVelocity(p->Base.Velocity.Y, y, yMode);
|
|
||||||
p->Base.Velocity.Z = CalcVelocity(p->Base.Velocity.Z, z, zMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CPE_Reset(void) {
|
static void CPE_Reset(void) {
|
||||||
|
@ -54,7 +54,7 @@ void Protocol_Tick(void);
|
|||||||
|
|
||||||
extern cc_bool cpe_needD3Fix;
|
extern cc_bool cpe_needD3Fix;
|
||||||
void Classic_SendChat(const String* text, cc_bool partial);
|
void Classic_SendChat(const String* text, cc_bool partial);
|
||||||
void Classic_WritePosition(Vec3 pos, float rotY, float headX);
|
void Classic_WritePosition(Vec3 pos, float yaw, float pitch);
|
||||||
void Classic_WriteSetBlock(int x, int y, int z, cc_bool place, BlockID block);
|
void Classic_WriteSetBlock(int x, int y, int z, cc_bool place, BlockID block);
|
||||||
void Classic_SendLogin(const String* username, const String* verKey);
|
void Classic_SendLogin(const String* username, const String* verKey);
|
||||||
void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct PickedPos* pos);
|
void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct PickedPos* pos);
|
||||||
|
@ -196,7 +196,7 @@ static void SPConnection_SendChat(const String* text) {
|
|||||||
SPConnection_AddPart(&left);
|
SPConnection_AddPart(&left);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SPConnection_SendPosition(Vec3 pos, float rotY, float pitch) { }
|
static void SPConnection_SendPosition(Vec3 pos, float yaw, float pitch) { }
|
||||||
static void SPConnection_SendData(const cc_uint8* data, cc_uint32 len) { }
|
static void SPConnection_SendData(const cc_uint8* data, cc_uint32 len) { }
|
||||||
|
|
||||||
static void SPConnection_Tick(struct ScheduledTask* task) {
|
static void SPConnection_Tick(struct ScheduledTask* task) {
|
||||||
@ -339,8 +339,8 @@ static void MPConnection_SendChat(const String* text) {
|
|||||||
Classic_SendChat(&left, false);
|
Classic_SendChat(&left, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MPConnection_SendPosition(Vec3 pos, float rotY, float pitch) {
|
static void MPConnection_SendPosition(Vec3 pos, float yaw, float pitch) {
|
||||||
Classic_WritePosition(pos, rotY, pitch);
|
Classic_WritePosition(pos, yaw, pitch);
|
||||||
Net_SendPacket();
|
Net_SendPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ CC_VAR extern struct _ServerConnectionData {
|
|||||||
/* Sends a chat message to the server. */
|
/* Sends a chat message to the server. */
|
||||||
void (*SendChat)(const String* text);
|
void (*SendChat)(const String* text);
|
||||||
/* Sends a position update to the server. */
|
/* Sends a position update to the server. */
|
||||||
void (*SendPosition)(Vec3 pos, float rotY, float pitch);
|
void (*SendPosition)(Vec3 pos, float yaw, float pitch);
|
||||||
/* Sends raw data to the server. */
|
/* Sends raw data to the server. */
|
||||||
/* NOTE: Prefer SendBlock/Position/Chat instead, this does NOT work in singleplayer. */
|
/* NOTE: Prefer SendBlock/Position/Chat instead, this does NOT work in singleplayer. */
|
||||||
void (*SendData)(const cc_uint8* data, cc_uint32 len);
|
void (*SendData)(const cc_uint8* data, cc_uint32 len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user