mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-12 17:42:39 +02:00
try to get rid of qobject vecs
This commit is contained in:
parent
7c8d080050
commit
3c805df3cc
3 changed files with 21 additions and 68 deletions
|
@ -25,23 +25,6 @@ AtomicUIntStat OctreePacketData::_totalBytesOfValues { 0 };
|
|||
AtomicUIntStat OctreePacketData::_totalBytesOfPositions { 0 };
|
||||
AtomicUIntStat OctreePacketData::_totalBytesOfRawData { 0 };
|
||||
|
||||
struct vec2FloatData {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
struct vec3FloatData {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
|
||||
struct vec3UCharData {
|
||||
unsigned char x;
|
||||
unsigned char y;
|
||||
unsigned char z;
|
||||
};
|
||||
|
||||
struct aaCubeData {
|
||||
glm::vec3 corner;
|
||||
float scale;
|
||||
|
@ -380,7 +363,6 @@ bool OctreePacketData::appendValue(quint64 value) {
|
|||
}
|
||||
|
||||
bool OctreePacketData::appendValue(float value) {
|
||||
|
||||
const unsigned char* data = (const unsigned char*)&value;
|
||||
int length = sizeof(value);
|
||||
bool success = append(data, length);
|
||||
|
@ -392,9 +374,8 @@ bool OctreePacketData::appendValue(float value) {
|
|||
}
|
||||
|
||||
bool OctreePacketData::appendValue(const ScriptVec2Float& value) {
|
||||
vec2FloatData vec { value.x, value.y };
|
||||
const unsigned char* data = (const unsigned char*)&vec;
|
||||
int length = sizeof(vec2FloatData);
|
||||
const unsigned char* data = (const unsigned char*)&value;
|
||||
int length = sizeof(ScriptVec2Float);
|
||||
bool success = append(data, length);
|
||||
if (success) {
|
||||
_bytesOfValues += length;
|
||||
|
@ -404,9 +385,8 @@ bool OctreePacketData::appendValue(const ScriptVec2Float& value) {
|
|||
}
|
||||
|
||||
bool OctreePacketData::appendValue(const ScriptVec3Float& value) {
|
||||
vec3FloatData vec { value.x, value.y, value.z };
|
||||
const unsigned char* data = (const unsigned char*)&vec;
|
||||
int length = sizeof(vec3FloatData);
|
||||
const unsigned char* data = (const unsigned char*)&value;
|
||||
int length = sizeof(ScriptVec3Float);
|
||||
bool success = append(data, length);
|
||||
if (success) {
|
||||
_bytesOfValues += length;
|
||||
|
@ -423,14 +403,10 @@ bool OctreePacketData::appendValue(const QVector<ScriptVec3Float>& value) {
|
|||
uint16_t qVecSize = value.size();
|
||||
bool success = appendValue(qVecSize);
|
||||
if (success) {
|
||||
QVector<vec3FloatData> rawVector(qVecSize);
|
||||
for (int i = 0; i < qVecSize; i++) {
|
||||
rawVector[i] = { value[i].x, value[i].y, value[i].z };
|
||||
}
|
||||
success = append((const unsigned char*)rawVector.constData(), qVecSize * sizeof(vec3FloatData));
|
||||
success = append((const unsigned char*)value.constData(), qVecSize * sizeof(ScriptVec3Float));
|
||||
if (success) {
|
||||
_bytesOfValues += qVecSize * sizeof(vec3FloatData);
|
||||
_totalBytesOfValues += qVecSize * sizeof(vec3FloatData);
|
||||
_bytesOfValues += qVecSize * sizeof(ScriptVec3Float);
|
||||
_totalBytesOfValues += qVecSize * sizeof(ScriptVec3Float);
|
||||
}
|
||||
}
|
||||
return success;
|
||||
|
@ -693,24 +669,18 @@ void OctreePacketData::debugBytes() {
|
|||
}
|
||||
|
||||
int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, ScriptVec2Float& result) {
|
||||
vec2FloatData vec;
|
||||
memcpy(&vec, dataBytes, sizeof(vec2FloatData));
|
||||
result = ScriptVec2Float(vec.x, vec.y);
|
||||
return sizeof(vec2FloatData);
|
||||
memcpy(&result, dataBytes, sizeof(result));
|
||||
return sizeof(result);
|
||||
}
|
||||
|
||||
int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, ScriptVec3Float& result) {
|
||||
vec3FloatData vec;
|
||||
memcpy(&vec, dataBytes, sizeof(vec3FloatData));
|
||||
result = ScriptVec3Float(vec.x, vec.y, vec.z);
|
||||
return sizeof(vec3FloatData);
|
||||
memcpy(&result, dataBytes, sizeof(result));
|
||||
return sizeof(result);
|
||||
}
|
||||
|
||||
int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, ScriptVec3UChar& result) {
|
||||
vec3UCharData vec;
|
||||
memcpy(&vec, dataBytes, sizeof(vec3UCharData));
|
||||
result = ScriptVec3UChar(vec.x, vec.y, vec.z);
|
||||
return sizeof(vec3UCharData);
|
||||
memcpy(&result, dataBytes, sizeof(result));
|
||||
return sizeof(result);
|
||||
}
|
||||
|
||||
int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QString& result) {
|
||||
|
@ -741,17 +711,12 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVecto
|
|||
dataBytes += sizeof(length);
|
||||
|
||||
// FIXME - this size check is wrong if we allow larger packets
|
||||
if (length * sizeof(vec3FloatData) > MAX_OCTREE_UNCOMRESSED_PACKET_SIZE) {
|
||||
if (length * sizeof(ScriptVec3Float) > MAX_OCTREE_UNCOMRESSED_PACKET_SIZE) {
|
||||
result.resize(0);
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
result.resize(length);
|
||||
QVector<vec3FloatData> rawVector(length);
|
||||
memcpy(rawVector.data(), dataBytes, length * sizeof(vec3FloatData));
|
||||
for (int i = 0; i < length; i++) {
|
||||
auto v = rawVector[i];
|
||||
result[i] = ScriptVec3Float(v.x, v.y, v.z);
|
||||
}
|
||||
memcpy(result.data(), dataBytes, length * sizeof(ScriptVec3Float));
|
||||
return sizeof(uint16_t) + length * sizeof(ScriptVec3Float);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,13 +51,12 @@ void mat4FromScriptValue(const QScriptValue& object, glm::mat4& mat4);
|
|||
* @property {number} x - X-coordinate of the vector. Synonyms: <code>u</code> and <code>width</code>.
|
||||
* @property {number} y - Y-coordinate of the vector. Synonyms: <code>v</code> and <code>height</code>.
|
||||
*/
|
||||
class ScriptVec2Float : public QObject {
|
||||
Q_OBJECT
|
||||
class ScriptVec2Float {
|
||||
public:
|
||||
ScriptVec2Float() {}
|
||||
ScriptVec2Float(float xy) : x(xy), y(xy) {}
|
||||
ScriptVec2Float(float x, float y) : x(x), y(y) {}
|
||||
ScriptVec2Float(const ScriptVec2Float& other) : QObject(), x(other.x), y(other.y) {}
|
||||
ScriptVec2Float(const ScriptVec2Float& other) : x(other.x), y(other.y) {}
|
||||
ScriptVec2Float(const glm::vec2& other) : x(other.x), y(other.y) {}
|
||||
void operator=(const ScriptVec2Float& other) { x = other.x; y = other.y; }
|
||||
inline bool operator==(const ScriptVec2Float& other) const { return (x == other.x && y == other.y); }
|
||||
|
@ -66,7 +65,6 @@ public:
|
|||
inline bool operator!=(const glm::vec2& other) const { return !(*this == other); }
|
||||
|
||||
glm::vec2 toGlm() const { return glm::vec2(x, y); }
|
||||
Q_INVOKABLE QVariant toJSON() const { return toJsonValue(*this, { "x", "y" }).toVariant(); }
|
||||
|
||||
float x { 0.0f };
|
||||
float y { 0.0f };
|
||||
|
@ -101,13 +99,12 @@ glm::vec2 vec2FromVariant(const QVariant& object);
|
|||
* @property {number} y - Y-coordinate of the vector. Synonyms: <code>g</code>, <code>green</code>, and <code>height</code>.
|
||||
* @property {number} z - Z-coordinate of the vector. Synonyms: <code>b</code>, <code>blue</code>, and <code>depth</code>.
|
||||
*/
|
||||
class ScriptVec3Float : public QObject {
|
||||
Q_OBJECT
|
||||
class ScriptVec3Float {
|
||||
public:
|
||||
ScriptVec3Float() {}
|
||||
ScriptVec3Float(float xyz) : x(xyz), y(xyz), z(xyz) {}
|
||||
ScriptVec3Float(float x, float y, float z) : x(x), y(y), z(z) {}
|
||||
ScriptVec3Float(const ScriptVec3Float& other) : QObject(), x(other.x), y(other.y), z(other.z) {}
|
||||
ScriptVec3Float(const ScriptVec3Float& other) : x(other.x), y(other.y), z(other.z) {}
|
||||
ScriptVec3Float(const glm::vec3& other) : x(other.x), y(other.y), z(other.z) {}
|
||||
void operator=(const ScriptVec3Float& other) { x = other.x; y = other.y; z = other.z; }
|
||||
inline bool operator==(const ScriptVec3Float& other) const { return (x == other.x && y == other.y && z == other.z); }
|
||||
|
@ -116,7 +113,6 @@ public:
|
|||
inline bool operator!=(const glm::vec3& other) const { return !(*this == other); }
|
||||
|
||||
glm::vec3 toGlm() const { return glm::vec3(x, y, z); }
|
||||
Q_INVOKABLE QVariant toJSON() const { return toJsonValue(*this, { "x", "y", "z" }).toVariant(); }
|
||||
|
||||
float x { 0.0f };
|
||||
float y { 0.0f };
|
||||
|
@ -144,20 +140,18 @@ void vec3FloatFromScriptValue(const QScriptValue& object, ScriptVec3Float& vec3)
|
|||
* @property {number} y - Green component value. Integer in the range <code>0</code> - <code>255</code>. Synonyms: <code>g</code>, <code>green</code>, and <code>height</code>.
|
||||
* @property {number} z - Blue component value. Integer in the range <code>0</code> - <code>255</code>. Synonyms: <code>b</code>, <code>blue</code>, and <code>depth</code>.
|
||||
*/
|
||||
class ScriptVec3UChar : public QObject {
|
||||
Q_OBJECT
|
||||
class ScriptVec3UChar {
|
||||
public:
|
||||
ScriptVec3UChar() {}
|
||||
ScriptVec3UChar(unsigned int xyz) : x(xyz), y(xyz), z(xyz) {}
|
||||
ScriptVec3UChar(unsigned int x, unsigned int y, unsigned int z) : x(x), y(y), z(z) {}
|
||||
ScriptVec3UChar(const ScriptVec3UChar& other) : QObject(), x(other.x), y(other.y), z(other.z) {}
|
||||
ScriptVec3UChar(const ScriptVec3UChar& other) : x(other.x), y(other.y), z(other.z) {}
|
||||
ScriptVec3UChar(const glm::vec3& other) : x(other.x), y(other.y), z(other.z) {}
|
||||
void operator=(const ScriptVec3UChar& other) { x = other.x; y = other.y; z = other.z; }
|
||||
inline bool operator==(const ScriptVec3UChar& other) const { return (x == other.x && y == other.y && z == other.z); }
|
||||
inline bool operator!=(const ScriptVec3UChar& other) const { return !(*this == other); }
|
||||
|
||||
glm::vec3 toGlm() const { return glm::vec3(x, y, z); }
|
||||
Q_INVOKABLE QVariant toJSON() const { return toJsonValue(*this, { "x", "y", "z" }).toVariant(); }
|
||||
|
||||
unsigned char x { 0 };
|
||||
unsigned char y { 0 };
|
||||
|
|
|
@ -76,12 +76,6 @@ QJsonValue toJsonValueHelper(const QVariant& variant, int type) {
|
|||
return toJsonValue(variant.value<vec3>());
|
||||
} else if (type == qMetaTypeId<vec4>()) {
|
||||
return toJsonValue(variant.value<vec4>());
|
||||
} else if (type == qMetaTypeId<ScriptVec2Float>()) {
|
||||
return toJsonValue(variant.value<ScriptVec2Float>(), {"x", "y"});
|
||||
} else if (type == qMetaTypeId<ScriptVec3Float>()) {
|
||||
return toJsonValue(variant.value<ScriptVec2Float>(), { "x", "y", "z" });
|
||||
} else if (type == qMetaTypeId<ScriptVec3UChar>()) {
|
||||
return toJsonValue(variant.value<ScriptVec3UChar>(), { "x", "y", "z" });
|
||||
} else {
|
||||
// Qt types are converted automatically
|
||||
return QJsonValue::fromVariant(variant);
|
||||
|
|
Loading…
Reference in a new issue