Merge pull request #29 from birarda/entity-script-server

some fixes from code review
This commit is contained in:
Clément Brisset 2017-01-20 14:15:11 -08:00 committed by GitHub
commit b60ba0ff5c
4 changed files with 35 additions and 30 deletions

View file

@ -1021,7 +1021,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue
ADD_PROPERTY_TO_MAP(PROP_X_P_NEIGHBOR_ID, XPNeighborID, xPNeighborID, EntityItemID);
ADD_PROPERTY_TO_MAP(PROP_Y_P_NEIGHBOR_ID, YPNeighborID, yPNeighborID, EntityItemID);
ADD_PROPERTY_TO_MAP(PROP_Z_P_NEIGHBOR_ID, ZPNeighborID, zPNeighborID, EntityItemID);
ADD_PROPERTY_TO_MAP(PROP_PARENT_ID, ParentID, parentID, QUuid);
ADD_PROPERTY_TO_MAP(PROP_PARENT_JOINT_INDEX, ParentJointIndex, parentJointIndex, uint16_t);

View file

@ -284,6 +284,16 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
// entities for encoding. This is needed because we encode the element data at the "parent" level, and so we
// need to handle the case where our sibling elements need encoding but we don't.
if (!entityTreeElementExtraEncodeData->elementCompleted) {
QJsonObject jsonFilters;
auto entityNodeData = static_cast<EntityNodeData*>(params.nodeData);
if (entityNodeData) {
// we have an EntityNodeData instance
// so we should assume that means we might have JSON filters to check
jsonFilters = entityNodeData->getJSONParameters();
}
for (uint16_t i = 0; i < _entityItems.size(); i++) {
EntityItemPointer entity = _entityItems[i];
bool includeThisEntity = true;
@ -291,35 +301,27 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
if (!params.forceSendScene && entity->getLastChangedOnServer() < params.lastQuerySent) {
includeThisEntity = false;
}
auto entityNodeData = dynamic_cast<EntityNodeData*>(params.nodeData);
if (entityNodeData) {
// we have an EntityNodeData instance
// so we should assume that means we might have JSON filters to check
auto jsonFilters = entityNodeData->getJSONParameters();
if (!jsonFilters.isEmpty()) {
// if params include JSON filters, check if this entity matches
bool entityMatchesFilters = entity->matchesJSONFilters(jsonFilters);
if (entityMatchesFilters) {
// we should include this entity unless it has already been excluded
if (!jsonFilters.isEmpty()) {
// if params include JSON filters, check if this entity matches
bool entityMatchesFilters = entity->matchesJSONFilters(jsonFilters);
if (entityMatchesFilters) {
// we should include this entity unless it has already been excluded
includeThisEntity = includeThisEntity && true;
// make sure this entity is in the set of entities sent last frame
entityNodeData->insertEntitySentLastFrame(entity->getID());
} else {
// we might include this entity if it matched in the previous frame
if (entityNodeData->sentEntityLastFrame(entity->getID())) {
includeThisEntity = includeThisEntity && true;
// make sure this entity is in the set of entities sent last frame
entityNodeData->insertEntitySentLastFrame(entity->getID());
entityNodeData->removeEntitySentLastFrame(entity->getID());
} else {
// we might include this entity if it matched in the previous frame
if (entityNodeData->sentEntityLastFrame(entity->getID())) {
includeThisEntity = includeThisEntity && true;
entityNodeData->removeEntitySentLastFrame(entity->getID());
} else {
includeThisEntity = false;
}
includeThisEntity = false;
}
}
}

View file

@ -50,7 +50,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
case PacketType::EntityData:
return VERSION_ENTITIES_SERVER_SCRIPTS;
case PacketType::EntityQuery:
return VERSION_ENTITIES_JSON_FILTER;
return static_cast<PacketVersion>(EntityQueryPacketVersion::JsonFilter);
case PacketType::AvatarIdentity:
case PacketType::AvatarData:
case PacketType::BulkAvatarData:

View file

@ -201,7 +201,10 @@ const PacketVersion VERSION_WEB_ENTITIES_SUPPORT_DPI = 63;
const PacketVersion VERSION_ENTITIES_ARROW_ACTION = 64;
const PacketVersion VERSION_ENTITIES_LAST_EDITED_BY = 65;
const PacketVersion VERSION_ENTITIES_SERVER_SCRIPTS = 66;
const PacketVersion VERSION_ENTITIES_JSON_FILTER = 67;
enum class EntityQueryPacketVersion: PacketVersion {
JsonFilter = 18
};
enum class AssetServerPacketVersion: PacketVersion {
VegasCongestionControl = 19