1.8 Changes - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Development (https://forum.cuberite.org/forum-13.html) +--- Thread: 1.8 Changes (/thread-1345.html) |
RE: 1.8 Changes - daniel0916 - 02-05-2014 When i decode x, y, z and then encode that. The x, y, z aren't the same. void WritePosition(int x, int y, int z) { long encoded_x = (x & 0x3FFFFFF) << 38; long encoded_y = (y & 0xFFF) << 26; long encoded_z = (z & 0x3FFFFFF); long value = encoded_x | encoded_y | encoded_z; LOGWARN(std::to_string(x).c_str()); LOGWARN(std::to_string(y).c_str()); LOGWARN(std::to_string(z).c_str()); LOGWARN(std::to_string(encoded_x).c_str()); LOGWARN(std::to_string(encoded_y).c_str()); LOGWARN(std::to_string(encoded_z).c_str()); LOGWARN(std::to_string(value).c_str()); long x2 = value >> 38; long y2 = value << 26 >> 52; long z2 = value << 38 >> 38; LOGWARN(std::to_string(x2).c_str()); LOGWARN(std::to_string(y2).c_str()); LOGWARN(std::to_string(z2).c_str()); m_Out.WriteBEInt64(value); } LOGWARN("Spawn Position"); cPacketizer Pkt(*this, 0x05); // Spawn Position packet Pkt.WritePosition(100, 100, 80); LOG: Code: [2a8c|18:01:09] Spawn Position Edit: Maybe the encode value from the client is not the same like my encode value. I will try it. RE: 1.8 Changes - FakeTruth - 02-05-2014 I think you're doing some very wrong things. First of all AFAIK a long is 4 bytes (=32 bits) and you're shifting it 38 bits. This will most definitely result in overflow of the value. Second -not really a problem- is the way you use LOGWARN. The log function takes a formatted string so you should write LOGWARN("%i", x); instead of the whole std::to_string() stuff. Last this totally blows my mind: Code: long z2 = value << 38 >> 38; Do you know what you're doing or are you just trying something? RE: 1.8 Changes - daniel0916 - 02-05-2014 (02-05-2014, 07:03 AM)FakeTruth Wrote: First of all AFAIK a long is 4 bytes (=32 bits) and you're shifting it 38 bits. This will most definitely result in overflow of the value.Which should i use then? (02-05-2014, 07:03 AM)FakeTruth Wrote: Second -not really a problem- is the way you use LOGWARN. The log function takes a formatted string so you should write LOGWARN("%i", x); instead of the whole std::to_string() stuff.Okay, thanks. (02-05-2014, 07:03 AM)FakeTruth Wrote: Last this totally blows my mind:This code is from the pre release protocol site (http://wiki.vg/Pre-release_protocol#Position) (02-05-2014, 07:03 AM)FakeTruth Wrote: Do you know what you're doing or are you just trying something?With Protocol yes. But with the new Position data currently no. RE: 1.8 Changes - FakeTruth - 02-05-2014 (02-05-2014, 04:05 PM)daniel0916 Wrote: Which should i use then?Try int64_t or uint64_t. You might need to do #include <inttypes.h> (02-05-2014, 04:05 PM)daniel0916 Wrote: This code is from the pre release protocol site (http://wiki.vg/Pre-release_protocol#Position)Yeah the decoding is a mystery to me but maybe it's using shifting and overflow in order to mask bits... I think in order to get z you simply do Code: z = val & 0x3FFFFFF; But who knows, maybe what you wrote works if you use int64_t RE: 1.8 Changes - xoft - 02-06-2014 (02-05-2014, 11:07 PM)FakeTruth Wrote: Try int64_t or uint64_t. You might need to do #include <inttypes.h>We have those as Int64 and UInt64, declared in Globals.h, so available anywhere. RE: 1.8 Changes - daniel0916 - 02-07-2014 Here the newest commit: https://github.com/daniel0916/MCServer/commit/87a3298e88268cca580318b60f0fe3121a05c3f8 Encoding isn't really working. Maybe i made something false? But i don't find the error. RE: 1.8 Changes - daniel0916 - 02-09-2014 The currently biggest problem is the encoding from x,y,z to Position. Current Code: void WritePosition(int x, int y, int z) { Int64 encoded_x = (x & 0x3FFFFFF) << 38; Int64 encoded_y = (y & 0xFFF) << 26; Int64 encoded_z = (z & 0x3FFFFFF); Int64 value = encoded_x | encoded_y | encoded_z; m_Out.WriteBEInt64(value); } RE: 1.8 Changes - xoft - 02-09-2014 Try this: void WritePosition(int x, int y, int z) { UInt64 encoded_x = x & 0x3FFFFFF; UInt64 encoded_y = y & 0xFFF; UInt64 encoded_z = z & 0x3FFFFFF; UInt64 value = (encoded_x << 38) | (encoded_y << 26) | encoded_z; m_Out.WriteBEInt64(value); } RE: 1.8 Changes - tigerw - 02-09-2014 Fancy RE: 1.8 Changes - xoft - 02-09-2014 The point is to do the bit shifts on the 64-bit number already, rather than on a 32-bit number which is then upgraded to 64-bits. |