mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
Nothing in the server writes or reads a packet by hand any more, so the helpers for doing so go: - CBITSTREAM, CMSGHEADER, CINSTREAM, CINSTREAM_SKIP_HEADER, SEND_PACKET, SEND_PACKET_BROADCAST and HEADER_SIZE leave dCommonVars.h; - the free BitStreamUtils::WriteHeader (LUBitStream::WriteHeader writes the same bytes) and the unused PacketUtils::SavePacket are deleted. The last raw reads are replaced: WorldServer builds its input stream directly, the master packet logs read the header with LUBitStream::ReadHeader instead of peeking at packet->data[1] and [3], and MessageInspector reads a sent game message's header with the new NetGameMsg::ReadPacketHeader (the counterpart of WritePacket) instead of memcmp/memcpy. packet->data[0] is still compared with RakNet's own connection IDs. The frozen oracles keep using the macros verbatim through the test-only tests/dGameTests/LegacyPacketMacros.h; the HeaderSkip tests, which only tested CINSTREAM_SKIP_HEADER, are removed. docs/PacketArchitecture.md: "where we are" now describes the final state and what still touches raw bytes (RakNet IDs, replica headers, behavior bit streams), and a new section collects the known wire discrepancies found during the conversion, with client addresses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
154 lines
5.6 KiB
C++
154 lines
5.6 KiB
C++
#include "GameDependencies.h"
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "BitStream.h"
|
|
#include "SimplePhysicsComponent.h"
|
|
#include "Entity.h"
|
|
#include "eReplicaComponentType.h"
|
|
#include "eStateChangeType.h"
|
|
|
|
class SimplePhysicsTest : public GameDependenciesTest {
|
|
protected:
|
|
std::unique_ptr<Entity> baseEntity;
|
|
SimplePhysicsComponent* simplePhysicsComponent;
|
|
RakNet::BitStream bitStream;
|
|
void SetUp() override {
|
|
SetUpDependencies();
|
|
baseEntity = std::make_unique<Entity>(15, GameDependenciesTest::info);
|
|
simplePhysicsComponent = baseEntity->AddComponent<SimplePhysicsComponent>(1);
|
|
simplePhysicsComponent->SetClimbableType(eClimbableType::CLIMBABLE_TYPE_WALL);
|
|
simplePhysicsComponent->SetPosition(NiPoint3(1.0f, 2.0f, 3.0f));
|
|
simplePhysicsComponent->SetRotation(NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
|
|
simplePhysicsComponent->SetVelocity(NiPoint3(5.0f, 6.0f, 7.0f));
|
|
simplePhysicsComponent->SetAngularVelocity(NiPoint3(5.0f, 6.0f, 7.0f));
|
|
simplePhysicsComponent->SetPhysicsMotionState(2);
|
|
}
|
|
|
|
void TearDown() override {
|
|
TearDownDependencies();
|
|
}
|
|
};
|
|
|
|
TEST_F(SimplePhysicsTest, SimplePhysicsSerializeTest) {
|
|
simplePhysicsComponent->Serialize(bitStream, false);
|
|
constexpr uint32_t sizeOfStream = 3 + BYTES_TO_BITS(3 * sizeof(NiPoint3)) + BYTES_TO_BITS(1 * sizeof(NiQuaternion)) + 1 * BYTES_TO_BITS(sizeof(uint32_t));
|
|
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), sizeOfStream);
|
|
|
|
bool dirtyVelocityFlag;
|
|
bitStream.Read(dirtyVelocityFlag);
|
|
ASSERT_EQ(dirtyVelocityFlag, true);
|
|
|
|
NiPoint3 velocity;
|
|
bitStream.Read(velocity.x);
|
|
bitStream.Read(velocity.y);
|
|
bitStream.Read(velocity.z);
|
|
ASSERT_EQ(velocity, NiPoint3(5.0f, 6.0f, 7.0f));
|
|
|
|
NiPoint3 angularVelocity;
|
|
bitStream.Read(angularVelocity.x);
|
|
bitStream.Read(angularVelocity.y);
|
|
bitStream.Read(angularVelocity.z);
|
|
ASSERT_EQ(angularVelocity, NiPoint3(5.0f, 6.0f, 7.0f));
|
|
|
|
bool dirtyPhysicsMotionStateFlag;
|
|
bitStream.Read(dirtyPhysicsMotionStateFlag);
|
|
ASSERT_EQ(dirtyPhysicsMotionStateFlag, true);
|
|
|
|
uint32_t physicsMotionState;
|
|
bitStream.Read(physicsMotionState);
|
|
ASSERT_EQ(physicsMotionState, 2.0f);
|
|
|
|
bool dirtyPositionFlag;
|
|
bitStream.Read(dirtyPositionFlag);
|
|
ASSERT_EQ(dirtyPositionFlag, true);
|
|
|
|
NiPoint3 position;
|
|
bitStream.Read(position.x);
|
|
bitStream.Read(position.y);
|
|
bitStream.Read(position.z);
|
|
ASSERT_EQ(position, NiPoint3(1.0f, 2.0f, 3.0f));
|
|
|
|
NiQuaternion rotation;
|
|
bitStream.Read(rotation.x);
|
|
bitStream.Read(rotation.y);
|
|
bitStream.Read(rotation.z);
|
|
bitStream.Read(rotation.w);
|
|
ASSERT_EQ(rotation, NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
|
|
}
|
|
|
|
TEST_F(SimplePhysicsTest, SimplePhysicsConstructionTest) {
|
|
simplePhysicsComponent->Serialize(bitStream, true);
|
|
constexpr uint32_t sizeOfStream = 4 + BYTES_TO_BITS(1 * sizeof(int32_t)) + BYTES_TO_BITS(3 * sizeof(NiPoint3)) + BYTES_TO_BITS(1 * sizeof(NiQuaternion)) + 1 * BYTES_TO_BITS(sizeof(uint32_t));
|
|
ASSERT_EQ(bitStream.GetNumberOfBitsUsed(), sizeOfStream);
|
|
|
|
bool dirtyClimbableTypeFlag;
|
|
bitStream.Read(dirtyClimbableTypeFlag);
|
|
ASSERT_EQ(dirtyClimbableTypeFlag, true);
|
|
|
|
int32_t climbableType;
|
|
bitStream.Read(climbableType);
|
|
ASSERT_EQ(climbableType, 2);
|
|
|
|
bool dirtyVelocityFlag;
|
|
bitStream.Read(dirtyVelocityFlag);
|
|
ASSERT_EQ(dirtyVelocityFlag, true);
|
|
|
|
NiPoint3 velocity;
|
|
bitStream.Read(velocity.x);
|
|
bitStream.Read(velocity.y);
|
|
bitStream.Read(velocity.z);
|
|
ASSERT_EQ(velocity, NiPoint3(5.0f, 6.0f, 7.0f));
|
|
|
|
NiPoint3 angularVelocity;
|
|
bitStream.Read(angularVelocity.x);
|
|
bitStream.Read(angularVelocity.y);
|
|
bitStream.Read(angularVelocity.z);
|
|
ASSERT_EQ(angularVelocity, NiPoint3(5.0f, 6.0f, 7.0f));
|
|
|
|
bool dirtyPhysicsMotionStateFlag;
|
|
bitStream.Read(dirtyPhysicsMotionStateFlag);
|
|
ASSERT_EQ(dirtyPhysicsMotionStateFlag, true);
|
|
|
|
uint32_t physicsMotionState;
|
|
bitStream.Read(physicsMotionState);
|
|
ASSERT_EQ(physicsMotionState, 2.0f);
|
|
|
|
bool dirtyPositionFlag;
|
|
bitStream.Read(dirtyPositionFlag);
|
|
ASSERT_EQ(dirtyPositionFlag, true);
|
|
|
|
NiPoint3 position;
|
|
bitStream.Read(position.x);
|
|
bitStream.Read(position.y);
|
|
bitStream.Read(position.z);
|
|
ASSERT_EQ(position, NiPoint3(1.0f, 2.0f, 3.0f));
|
|
|
|
NiQuaternion rotation;
|
|
bitStream.Read(rotation.x);
|
|
bitStream.Read(rotation.y);
|
|
bitStream.Read(rotation.z);
|
|
bitStream.Read(rotation.w);
|
|
ASSERT_EQ(rotation, NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
|
|
}
|
|
|
|
TEST_F(SimplePhysicsTest, SimplePhysicsGettersAndSettersTest) {
|
|
ASSERT_EQ(simplePhysicsComponent->GetClimabbleType(), eClimbableType::CLIMBABLE_TYPE_WALL);
|
|
ASSERT_EQ(simplePhysicsComponent->GetPosition(), NiPoint3(1.0f, 2.0f, 3.0f));
|
|
ASSERT_EQ(simplePhysicsComponent->GetRotation(), NiQuaternion(1.0f, 2.0f, 3.0f, 4.0f));
|
|
ASSERT_EQ(simplePhysicsComponent->GetVelocity(), NiPoint3(5.0f, 6.0f, 7.0f));
|
|
ASSERT_EQ(simplePhysicsComponent->GetAngularVelocity(), NiPoint3(5.0f, 6.0f, 7.0f));
|
|
ASSERT_EQ(simplePhysicsComponent->GetPhysicsMotionState(), 2);
|
|
simplePhysicsComponent->SetClimbableType(eClimbableType::CLIMBABLE_TYPE_LADDER);
|
|
simplePhysicsComponent->SetPosition(NiPoint3(4.0f, 5.0f, 6.0f));
|
|
simplePhysicsComponent->SetRotation(NiQuaternion(4.0f, 5.0f, 6.0f, 7.0f));
|
|
simplePhysicsComponent->SetVelocity(NiPoint3(6.0f, 7.0f, 8.0f));
|
|
simplePhysicsComponent->SetAngularVelocity(NiPoint3(6.0f, 7.0f, 8.0f));
|
|
simplePhysicsComponent->SetPhysicsMotionState(3);
|
|
ASSERT_EQ(simplePhysicsComponent->GetClimabbleType(), eClimbableType::CLIMBABLE_TYPE_LADDER);
|
|
ASSERT_EQ(simplePhysicsComponent->GetPosition(), NiPoint3(4.0f, 5.0f, 6.0f));
|
|
ASSERT_EQ(simplePhysicsComponent->GetRotation(), NiQuaternion(4.0f, 5.0f, 6.0f, 7.0f));
|
|
ASSERT_EQ(simplePhysicsComponent->GetVelocity(), NiPoint3(6.0f, 7.0f, 8.0f));
|
|
ASSERT_EQ(simplePhysicsComponent->GetAngularVelocity(), NiPoint3(6.0f, 7.0f, 8.0f));
|
|
ASSERT_EQ(simplePhysicsComponent->GetPhysicsMotionState(), 3);
|
|
}
|