minor code cleanup

This commit is contained in:
UnknownShadow200 2019-11-27 22:50:27 +11:00
parent 29b172f2c6
commit 127df95b2c
4 changed files with 24 additions and 35 deletions

View File

@ -314,7 +314,7 @@ void Classic_SendChat(const String* text, cc_bool partial) {
Server.SendData(data, 66);
}
void Classic_WritePosition(Vec3 pos, float rotY, float pitch) {
void Classic_WritePosition(Vec3 pos, float yaw, float pitch) {
BlockID payload;
int x, y, z;
@ -337,7 +337,7 @@ void Classic_WritePosition(Vec3 pos, float rotY, float pitch) {
Stream_SetU16_BE(data, z); data += 2;
}
*data++ = Math_Deg2Packed(rotY);
*data++ = Math_Deg2Packed(yaw);
*data++ = Math_Deg2Packed(pitch);
}
Server.WriteBuffer = data;
@ -573,15 +573,15 @@ static void Classic_RelPosAndOrientationUpdate(cc_uint8* data) {
struct LocationUpdate update;
EntityID id = *data++;
Vec3 pos;
float rotY, pitch;
float yaw, pitch;
pos.X = (cc_int8)(*data++) / 32.0f;
pos.Y = (cc_int8)(*data++) / 32.0f;
pos.Z = (cc_int8)(*data++) / 32.0f;
rotY = Math_Packed2Deg(*data++);
yaw = 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);
}
@ -601,12 +601,12 @@ static void Classic_RelPositionUpdate(cc_uint8* data) {
static void Classic_OrientationUpdate(cc_uint8* data) {
struct LocationUpdate update;
EntityID id = *data++;
float rotY, pitch;
float yaw, pitch;
rotY = Math_Packed2Deg(*data++);
yaw = Math_Packed2Deg(*data++);
pitch = Math_Packed2Deg(*data++);
LocationUpdate_MakeOri(&update, rotY, pitch);
LocationUpdate_MakeOri(&update, yaw, pitch);
Protocol_UpdateLocation(id, &update, true);
}
@ -655,7 +655,7 @@ static void Classic_ReadAbsoluteLocation(cc_uint8* data, EntityID id, cc_bool in
struct LocationUpdate update;
int x, y, z;
Vec3 pos;
float rotY, pitch;
float yaw, pitch;
if (cpe_extEntityPos) {
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;
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++);
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);
}
@ -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));
}
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);
value = Math_Sign(raw) * PhysicsComp_CalcJumpVelocity(value);
value = Math_Sign(raw) * PhysicsComp_CalcJumpVelocity(value);
if (mode == 0) return cur + value;
if (mode == 1) return value;
return cur;
if (mode == 0) *vel += value;
if (mode == 1) *vel = value;
}
static void CPE_VelocityControl(cc_uint8* data) {
struct LocalPlayer* p = &LocalPlayer_Instance;
int x, y, z;
cc_uint8 xMode, yMode, zMode;
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);
CalcVelocity(&p->Base.Velocity.X, data + 0, data[12]);
CalcVelocity(&p->Base.Velocity.Y, data + 4, data[13]);
CalcVelocity(&p->Base.Velocity.Z, data + 8, data[14]);
}
static void CPE_Reset(void) {

View File

@ -54,7 +54,7 @@ void Protocol_Tick(void);
extern cc_bool cpe_needD3Fix;
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_SendLogin(const String* username, const String* verKey);
void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct PickedPos* pos);

View File

@ -196,7 +196,7 @@ static void SPConnection_SendChat(const String* text) {
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_Tick(struct ScheduledTask* task) {
@ -339,8 +339,8 @@ static void MPConnection_SendChat(const String* text) {
Classic_SendChat(&left, false);
}
static void MPConnection_SendPosition(Vec3 pos, float rotY, float pitch) {
Classic_WritePosition(pos, rotY, pitch);
static void MPConnection_SendPosition(Vec3 pos, float yaw, float pitch) {
Classic_WritePosition(pos, yaw, pitch);
Net_SendPacket();
}

View File

@ -31,7 +31,7 @@ CC_VAR extern struct _ServerConnectionData {
/* Sends a chat message to the server. */
void (*SendChat)(const String* text);
/* 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. */
/* NOTE: Prefer SendBlock/Position/Chat instead, this does NOT work in singleplayer. */
void (*SendData)(const cc_uint8* data, cc_uint32 len);