mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-12 19:59:28 +02:00
74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
//
|
|
// EntityEditPacketSender.cpp
|
|
// libraries/models/src
|
|
//
|
|
// Created by Brad Hefta-Gaub on 8/12/13.
|
|
// Copyright 2013 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
#include <assert.h>
|
|
#include <PerfStat.h>
|
|
#include <OctalCode.h>
|
|
#include <PacketHeaders.h>
|
|
#include "EntityEditPacketSender.h"
|
|
#include "EntityItem.h"
|
|
|
|
|
|
void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type,
|
|
unsigned char* editBuffer, size_t length, int clockSkew) {
|
|
|
|
if (type == PacketTypeEntityAddOrEdit) {
|
|
EntityItem::adjustEditPacketForClockSkew(editBuffer, length, clockSkew);
|
|
}
|
|
}
|
|
|
|
void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID,
|
|
const EntityItemProperties& properties) {
|
|
if (!_shouldSend) {
|
|
return; // bail early
|
|
}
|
|
|
|
// use MAX_PACKET_SIZE since it's static and guaranteed to be larger than _maxPacketSize
|
|
static unsigned char bufferOut[MAX_PACKET_SIZE];
|
|
int sizeOut = 0;
|
|
|
|
if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) {
|
|
queueOctreeEditMessage(type, bufferOut, sizeOut);
|
|
}
|
|
}
|
|
|
|
void EntityEditPacketSender::queueEraseEntityMessage(const EntityItemID& entityItemID) {
|
|
if (!_shouldSend) {
|
|
return; // bail early
|
|
}
|
|
|
|
bool wantDebug = false;
|
|
if (wantDebug) {
|
|
qDebug() << "EntityEditPacketSender::queueEraseEntityMessage() entityItemID=" << entityItemID;
|
|
}
|
|
|
|
// use MAX_PACKET_SIZE since it's static and guaranteed to be larger than _maxPacketSize
|
|
static unsigned char bufferOut[MAX_PACKET_SIZE];
|
|
size_t sizeOut = 0;
|
|
|
|
if (wantDebug) {
|
|
qDebug() << " _maxPacketSize=" << _maxPacketSize;
|
|
}
|
|
|
|
if (EntityItemProperties::encodeEraseEntityMessage(entityItemID, &bufferOut[0], _maxPacketSize, sizeOut)) {
|
|
|
|
if (wantDebug) {
|
|
qDebug() << " encodeEraseEntityMessage()... sizeOut=" << sizeOut;
|
|
{
|
|
QDebug debug = qDebug();
|
|
debug << " edit data contents:";
|
|
outputBufferBits(&bufferOut[0], sizeOut, &debug);
|
|
}
|
|
}
|
|
|
|
queueOctreeEditMessage(PacketTypeEntityErase, bufferOut, sizeOut);
|
|
}
|
|
}
|