X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=tst%2Fnet%2FPacketTest.cpp;h=86517ca32b7c4d3abf3543e4b74c289bb0fa418a;hb=4727825186798902f68df5b99a6a32f0ef618454;hp=d616fd32101cecca72d2a9588c7c7a86aad351ab;hpb=808d9dbd3ab101c0ff10697e36ef2c45a23b6ef5;p=blank.git diff --git a/tst/net/PacketTest.cpp b/tst/net/PacketTest.cpp index d616fd3..86517ca 100644 --- a/tst/net/PacketTest.cpp +++ b/tst/net/PacketTest.cpp @@ -1,5 +1,6 @@ #include "PacketTest.hpp" +#include "geometry/const.hpp" #include "model/Model.hpp" #include "world/Entity.hpp" @@ -108,14 +109,17 @@ void PacketTest::testLogin() { void PacketTest::testJoin() { auto pack = Packet::Make(udp_pack); - AssertPacket("Join", 2, 54, 86, pack); + AssertPacket("Join", 2, 47, 78, pack); Entity write_entity; write_entity.ID(534574); - write_entity.GetState().chunk_pos = { 7, 2, -3 }; - write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; - write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; - write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + EntityState write_state; + write_state.pos = { { 7, 2, -3 }, { 1.5f, 0.9f, 12.0f } }; + write_state.velocity = { 0.025f, 0.001f, 0.0f }; + write_state.orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + write_state.pitch = 0.3f; + write_state.yaw = -2.3f; + write_entity.SetState(write_state); uint32_t read_id = 0; EntityState read_state; pack.WritePlayer(write_entity); @@ -156,35 +160,26 @@ void PacketTest::testPart() { void PacketTest::testPlayerUpdate() { auto pack = Packet::Make(udp_pack); - AssertPacket("PlayerUpdate", 4, 62, pack); + AssertPacket("PlayerUpdate", 4, 50, pack); EntityState write_state; - write_state.chunk_pos = { 7, 2, -3 }; - write_state.block_pos = { 1.5f, 0.9f, 12.0f }; + write_state.pos = { { 7, 2, -3 }, { 1.5f, 0.9f, 12.0f } }; write_state.velocity = { 0.025f, 0.001f, 0.0f }; write_state.orient = { 1.0f, 0.0f, 0.0f, 0.0f }; glm::vec3 write_movement(0.5f, -1.0f, 1.0f); - float write_pitch = 1.25f; - float write_yaw = -2.5f; uint8_t write_actions = 0x05; uint8_t write_slot = 3; pack.WritePredictedState(write_state); pack.WriteMovement(write_movement); - pack.WritePitch(write_pitch); - pack.WriteYaw(write_yaw); pack.WriteActions(write_actions); pack.WriteSlot(write_slot); EntityState read_state; glm::vec3 read_movement; - float read_pitch; - float read_yaw; uint8_t read_actions; uint8_t read_slot; pack.ReadPredictedState(read_state); pack.ReadMovement(read_movement); - pack.ReadPitch(read_pitch); - pack.ReadYaw(read_yaw); pack.ReadActions(read_actions); pack.ReadSlot(read_slot); AssertEqual( @@ -195,14 +190,6 @@ void PacketTest::testPlayerUpdate() { "player movement input not correctly transported in PlayerUpdate packet", write_movement, read_movement, 0.0001f ); - CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( - "player pitch input not correctly transported in PlayerUpdate packet", - write_pitch, read_pitch, 0.0001f - ); - CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( - "player yaw input not correctly transported in PlayerUpdate packet", - write_yaw, read_yaw, 0.0001f - ); CPPUNIT_ASSERT_EQUAL_MESSAGE( "player actions not correctly transported in PlayerUpdate packet", int(write_actions), int(read_actions) @@ -215,17 +202,20 @@ void PacketTest::testPlayerUpdate() { void PacketTest::testSpawnEntity() { auto pack = Packet::Make(udp_pack); - AssertPacket("SpawnEntity", 5, 87, 118, pack); + AssertPacket("SpawnEntity", 5, 79, 110, pack); Entity write_entity; write_entity.ID(534574); Model model; model.ID(23); + model.Enumerate(); model.Instantiate(write_entity.GetModel()); - write_entity.GetState().chunk_pos = { 7, 2, -3 }; - write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; - write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; - write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + EntityState write_state; + write_state.pos = { { 7, 2, -3 }, { 1.5f, 0.9f, 12.0f } }; + write_state.velocity = { 0.025f, 0.001f, 0.0f }; + write_state.pitch = 0.3f; + write_state.yaw = -2.3f; + write_entity.SetState(write_state); write_entity.Bounds({{ -1, -1, -1 }, { 1, 1, 1 }}); write_entity.WorldCollidable(true); write_entity.Name("blah"); @@ -281,12 +271,12 @@ void PacketTest::testDespawnEntity() { void PacketTest::testEntityUpdate() { auto pack = Packet::Make(udp_pack); - AssertPacket("EntityUpdate", 7, 16, 466, pack); + AssertPacket("EntityUpdate", 7, 16, 460, pack); pack.length = Packet::EntityUpdate::GetSize(3); CPPUNIT_ASSERT_EQUAL_MESSAGE( "length not correctly set in EntityUpdate packet", - size_t(16 + 3 * 45), pack.length + size_t(16 + 3 * 37), pack.length ); uint32_t write_count = 3; @@ -310,10 +300,12 @@ void PacketTest::testEntityUpdate() { Entity write_entity; write_entity.ID(8567234); - write_entity.GetState().chunk_pos = { 7, 2, -3 }; - write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; - write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; - write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + EntityState write_state; + write_state.pos = { { 7, 2, -3 }, { 1.5f, 0.9f, 12.0f } }; + write_state.velocity = { 0.025f, 0.001f, 0.0f }; + write_state.pitch = 0.3f; + write_state.yaw = -2.3f; + write_entity.SetState(write_state); pack.WriteEntity(write_entity, write_base, 1); pack.WriteEntity(write_entity, write_base, 0); pack.WriteEntity(write_entity, write_base, 2); @@ -334,7 +326,7 @@ void PacketTest::testEntityUpdate() { void PacketTest::testPlayerCorrection() { auto pack = Packet::Make(udp_pack); - AssertPacket("PlayerCorrection", 8, 52, pack); + AssertPacket("PlayerCorrection", 8, 44, pack); uint16_t write_seq = 50050; uint16_t read_seq; @@ -346,10 +338,12 @@ void PacketTest::testPlayerCorrection() { ); Entity write_entity; - write_entity.GetState().chunk_pos = { 7, 2, -3 }; - write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; - write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; - write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + EntityState write_state; + write_state.pos = { { 7, 2, -3 }, { 1.5f, 0.9f, 12.0f } }; + write_state.velocity = { 0.025f, 0.001f, 0.0f }; + write_state.pitch = 0.3f; + write_state.yaw = -2.3f; + write_entity.SetState(write_state); pack.WritePlayer(write_entity); EntityState read_state; @@ -596,11 +590,11 @@ void PacketTest::AssertEqual( ) { AssertEqual( message + ": bad chunk position", - expected.chunk_pos, actual.chunk_pos + expected.pos.chunk, actual.pos.chunk ); AssertEqual( message + ": bad block position", - expected.block_pos, actual.block_pos, 16.0f/65535.0f // that's about the max accuracy that packing's going to give us + expected.pos.block, actual.pos.block, 16.0f/65535.0f // that's about the max accuracy that packing's going to give us ); AssertEqual( message + ": bad velocity", @@ -610,6 +604,14 @@ void PacketTest::AssertEqual( message + ": bad orientation", expected.orient, actual.orient ); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + message + ": bad pitch", + expected.pitch, actual.pitch, PI/65534.0f + ); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( + message + ": bad yaw", + expected.yaw, actual.yaw, PI/32767.0f + ); } void PacketTest::AssertEqual( @@ -673,19 +675,19 @@ void PacketTest::AssertEqual( ) { CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( message + " (W component)", - expected.w, actual.w, numeric_limits::epsilon() + expected.w, actual.w, (1.0f / 32767.0f) ); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( message + " (X component)", - expected.x, actual.x, numeric_limits::epsilon() + expected.x, actual.x, (1.0f / 32767.0f) ); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( message + " (Y component)", - expected.y, actual.y, numeric_limits::epsilon() + expected.y, actual.y, (1.0f / 32767.0f) ); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( message + " (Z component)", - expected.z, actual.z, numeric_limits::epsilon() + expected.z, actual.z, (1.0f / 32767.0f) ); }