mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
first cut at new version of ModelItem::appendModelData
This commit is contained in:
parent
f3dd34ae54
commit
12a563193f
2 changed files with 197 additions and 3 deletions
|
@ -135,8 +135,6 @@ bool ModelItem::appendModelData(OctreePacketData* packetData) const {
|
|||
|
||||
bool success = packetData->appendValue(getID());
|
||||
|
||||
//qDebug("ModelItem::appendModelData()... getID()=%d", getID());
|
||||
|
||||
if (success) {
|
||||
success = packetData->appendValue(getLastUpdated());
|
||||
}
|
||||
|
@ -197,6 +195,175 @@ bool ModelItem::appendModelData(OctreePacketData* packetData) const {
|
|||
return success;
|
||||
}
|
||||
|
||||
bool ModelItem::new___appendModelData(OctreePacketData* packetData, EncodeBitstreamParams& params) const {
|
||||
|
||||
// bool headerFits = ...
|
||||
|
||||
// ALL this fits...
|
||||
// object ID [16 bytes]
|
||||
// ByteCountCoded(type code) [~1 byte]
|
||||
// last edited [8 bytes]
|
||||
// ByteCountCoded(last_edited to last_updated delta) [~1-8 bytes]
|
||||
// PropertyFlags<>( everything ) [1-2 bytes]
|
||||
// ~27-35 bytes...
|
||||
|
||||
bool success = false;
|
||||
|
||||
quint16 updateDelta = getLastUpdated() <= getLastEdited() ? 0 : getLastUpdated() - getLastEdited();
|
||||
ModelPropertyFlags propertyFlags(PROP_LAST_ITEM);
|
||||
|
||||
LevelDetails modelLevel = packetData->startLevel();
|
||||
|
||||
bool successIDFits = packetData->appendValue(getID());
|
||||
bool successTypeFits = packetData->appendValue(getType());
|
||||
bool successLastEditedFits = packetData->appendValue(getLastEdited());
|
||||
bool successLastUpdatedFits = packetData->appendValue(updateDelta);
|
||||
|
||||
int propertyFlagsOffset = packetData->getUncompressedByteOffset();
|
||||
bool successPropertyFlagsFits = packetData->appendValue(propertyFlags);
|
||||
int propertyCount = 0;
|
||||
|
||||
bool headerFits = successIDFits && successTypeFits && successLastEditedFits
|
||||
&& successLastUpdatedFits && successPropertyFlagsFits;
|
||||
if (headerFits) {
|
||||
bool successPropertyFits;
|
||||
|
||||
propertyFlags -= PROP_LAST_ITEM; // clear the last item for now, we may or may not set it as the actual item
|
||||
|
||||
// These items would go here once supported....
|
||||
// PROP_PAGED_PROPERTY,
|
||||
// PROP_CUSTOM_PROPERTIES_INCLUDED,
|
||||
// PROP_VISIBLE,
|
||||
|
||||
// PROP_POSITION
|
||||
LevelDetails propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendPosition(getPosition());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_POSITION;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_RADIUS
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getRadius());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_RADIUS;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_MODEL_URL
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getModelURL());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_MODEL_URL;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_ROTATION
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getModelRotation());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_ROTATION;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_ROTATION
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendColor(getColor());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_COLOR;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_SCRIPT
|
||||
// script would go here...
|
||||
|
||||
// PROP_ANIMATION_URL
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getAnimationURL());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_ANIMATION_URL;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_ANIMATION_FPS
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getAnimationFPS());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_ANIMATION_FPS;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_ANIMATION_FRAME_INDEX
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getAnimationFrameIndex());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_ANIMATION_FRAME_INDEX;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_ANIMATION_PLAYING
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getAnimationIsPlaying());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_ANIMATION_PLAYING;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
|
||||
// PROP_SHOULD_BE_DELETED
|
||||
propertyLevel = packetData->startLevel();
|
||||
successPropertyFits = packetData->appendValue(getShouldDie());
|
||||
if (successPropertyFits) {
|
||||
propertyFlags |= PROP_SHOULD_BE_DELETED;
|
||||
propertyCount++;
|
||||
packetData->endLevel(propertyLevel);
|
||||
} else {
|
||||
packetData->discardLevel(propertyLevel);
|
||||
}
|
||||
}
|
||||
if (propertyCount > 0) {
|
||||
|
||||
// we need to...
|
||||
// * update the PropertyFlags data.
|
||||
// * shift the property stream "to left" if the property flags shrunk.
|
||||
|
||||
|
||||
packetData->endLevel(modelLevel);
|
||||
success = true;
|
||||
} else {
|
||||
packetData->discardLevel(modelLevel);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
int ModelItem::expectedBytes() {
|
||||
int expectedBytes = sizeof(uint32_t) // id
|
||||
+ sizeof(float) // age
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
|
||||
#include <AnimationCache.h>
|
||||
#include <CollisionInfo.h>
|
||||
#include <SharedUtil.h>
|
||||
#include <OctreePacketData.h>
|
||||
#include <PropertyFlags.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
class ModelItem;
|
||||
class ModelEditPacketSender;
|
||||
|
@ -58,6 +59,28 @@ const float MODEL_DEFAULT_ANIMATION_FPS = 30.0f;
|
|||
const PacketVersion VERSION_MODELS_HAVE_ANIMATION = 1;
|
||||
const PacketVersion VERSION_ROOT_ELEMENT_HAS_DATA = 2;
|
||||
|
||||
// PropertyFlags support
|
||||
enum ModelPropertyList {
|
||||
PROP_PAGED_PROPERTY,
|
||||
PROP_CUSTOM_PROPERTIES_INCLUDED,
|
||||
PROP_VISIBLE,
|
||||
PROP_POSITION,
|
||||
PROP_RADIUS,
|
||||
PROP_MODEL_URL,
|
||||
PROP_ROTATION,
|
||||
PROP_COLOR,
|
||||
PROP_SCRIPT,
|
||||
PROP_ANIMATION_URL,
|
||||
PROP_ANIMATION_FPS,
|
||||
PROP_ANIMATION_FRAME_INDEX,
|
||||
PROP_ANIMATION_PLAYING,
|
||||
PROP_SHOULD_BE_DELETED,
|
||||
PROP_LAST_ITEM = PROP_SHOULD_BE_DELETED
|
||||
};
|
||||
|
||||
typedef PropertyFlags<ModelPropertyList> ModelPropertyFlags;
|
||||
|
||||
|
||||
/// A collection of properties of a model item used in the scripting API. Translates between the actual properties of a model
|
||||
/// and a JavaScript style hash/QScriptValue storing a set of properties. Used in scripting to set/get the complete set of
|
||||
/// model item properties via JavaScript hashes/QScriptValues
|
||||
|
@ -186,6 +209,8 @@ public:
|
|||
virtual ~ModelItem();
|
||||
virtual void init(glm::vec3 position, float radius, rgbColor color, uint32_t id = NEW_MODEL);
|
||||
|
||||
quint8 getType() const { return 0; } /// place holder for now
|
||||
|
||||
/// get position in domain scale units (0.0 - 1.0)
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
|
||||
|
@ -257,6 +282,8 @@ public:
|
|||
|
||||
void setProperties(const ModelItemProperties& properties);
|
||||
|
||||
bool new___appendModelData(OctreePacketData* packetData, EncodeBitstreamParams& params) const;
|
||||
|
||||
bool appendModelData(OctreePacketData* packetData) const;
|
||||
int readModelDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args);
|
||||
static int expectedBytes();
|
||||
|
|
Loading…
Reference in a new issue