feat: enhance entity packet parsing with additional packet types and improved logging

This commit is contained in:
MayaTheShy
2025-11-08 16:58:24 -05:00
parent 30a20c9b30
commit 04e3257e12

View File

@@ -211,17 +211,28 @@ void OverteClient::parseEntityPacket(const char* data, size_t len) {
unsigned char packetType = static_cast<unsigned char>(data[0]); unsigned char packetType = static_cast<unsigned char>(data[0]);
// Overte PacketType enum values (reference from protocol documentation) // Overte PacketType enum values (reference from protocol documentation)
// EntityAdd = 0x10, EntityEdit = 0x11, EntityErase = 0x12, etc. // Reference: https://github.com/overte-org/overte/blob/master/libraries/networking/src/udt/PacketHeaders.h
const unsigned char PACKET_TYPE_DOMAIN_LIST = 0x03;
const unsigned char PACKET_TYPE_DOMAIN_CONNECTION_DENIED = 0x06;
const unsigned char PACKET_TYPE_PING = 0x01;
const unsigned char PACKET_TYPE_PING_REPLY = 0x02;
// Entity packet types
const unsigned char PACKET_TYPE_ENTITY_ADD = 0x10; const unsigned char PACKET_TYPE_ENTITY_ADD = 0x10;
const unsigned char PACKET_TYPE_ENTITY_EDIT = 0x11; const unsigned char PACKET_TYPE_ENTITY_EDIT = 0x11;
const unsigned char PACKET_TYPE_ENTITY_ERASE = 0x12; const unsigned char PACKET_TYPE_ENTITY_ERASE = 0x12;
const unsigned char PACKET_TYPE_DOMAIN_LIST = 0x03; const unsigned char PACKET_TYPE_ENTITY_QUERY = 0x15;
const unsigned char PACKET_TYPE_OCTREE_STATS = 0x16;
switch (packetType) { switch (packetType) {
case PACKET_TYPE_DOMAIN_LIST: case PACKET_TYPE_DOMAIN_LIST:
handleDomainListReply(data + 1, len - 1); handleDomainListReply(data + 1, len - 1);
break; break;
case PACKET_TYPE_PING_REPLY:
std::cout << "[OverteClient] Ping reply received from domain" << std::endl;
break;
case PACKET_TYPE_ENTITY_ADD: { case PACKET_TYPE_ENTITY_ADD: {
// EntityAdd packet structure (simplified): // EntityAdd packet structure (simplified):
// u64 entityID, string name, vec3 position, quat rotation, vec3 dimensions, ... // u64 entityID, string name, vec3 position, quat rotation, vec3 dimensions, ...
@@ -238,12 +249,23 @@ void OverteClient::parseEntityPacket(const char* data, size_t len) {
} }
if (name.empty()) name = "Entity_" + std::to_string(entityId); if (name.empty()) name = "Entity_" + std::to_string(entityId);
// For now, default transform (will parse full properties later) // Create entity with a visible position spread out in front of user
OverteEntity entity{entityId, name, glm::mat4(1.0f)}; // Position entities in a grid pattern for visibility
float spacing = 0.5f;
int index = static_cast<int>(entityId % 10);
float x = (index % 3) * spacing - spacing; // -0.5, 0, 0.5
float y = 1.5f; // Eye level
float z = -2.0f - (index / 3) * spacing; // Start 2m in front, spread back
glm::vec3 position(x, y, z);
glm::mat4 transform = glm::translate(glm::mat4(1.0f), position);
OverteEntity entity{entityId, name, transform};
m_entities[entityId] = entity; m_entities[entityId] = entity;
m_updateQueue.push_back(entityId); m_updateQueue.push_back(entityId);
std::cout << "[OverteClient] Entity added: " << name << " (id=" << entityId << ")" << std::endl; std::cout << "[OverteClient] Entity added: " << name << " (id=" << entityId
<< ") at pos(" << x << ", " << y << ", " << z << ")" << std::endl;
break; break;
} }
@@ -280,7 +302,10 @@ void OverteClient::parseEntityPacket(const char* data, size_t len) {
} }
default: default:
// Unknown or unhandled packet type // Log unknown packet types for debugging
if (packetType != PACKET_TYPE_PING && packetType != PACKET_TYPE_PING_REPLY) {
std::cout << "[OverteClient] Unknown packet type: 0x" << std::hex << (int)packetType << std::dec << std::endl;
}
break; break;
} }
} }