void ReadCommands(ref RawInputStream input) { counters.commandsIn++; var schema = input.ReadRawBits(1) != 0; if (schema) { commandSchema = NetworkSchema.ReadSchema(ref input); // might be overridden } // NETTODO Reconstruct the wide sequence // NETTODO Rename to commandMessageSequence? var sequence = Sequence.FromUInt16((ushort)input.ReadRawBits(16), commandSequenceIn); if (sequence > commandSequenceIn) { commandSequenceIn = sequence; } CommandInfo previous = defaultCommandInfo; while (input.ReadRawBits(1) != 0) { var command = commandsIn.Acquire(sequence); command.time = (int)input.ReadPackedIntDelta(previous.time, NetworkConfig.commandTimeContext); uint hash = 0; DeltaReader.Read(ref input, commandSchema, command.data, previous.data, zeroFieldsChanged, 0, ref hash); previous = command; --sequence; } }
public void ReadPackage(byte[] packageData, INetworkCallbacks loop) { counters.bytesIn += packageData.Length; NetworkUtils.MemCopy(packageData, 0, packageBuffer, 0, packageData.Length); NetworkMessage content; int headerSize; var packageSequence = ProcessPackageHeader(packageBuffer, out content, out headerSize); var input = new RawInputStream(packageBuffer, headerSize); if ((content & NetworkMessage.ClientConfig) != 0) { ReadClientConfig(ref input); } if ((content & NetworkMessage.Commands) != 0) { ReadCommands(ref input); } if ((content & NetworkMessage.Events) != 0) { ReadEvents(ref input, loop); } }
void ReadClientConfig(ref RawInputStream input) { maxBPS = (int)input.ReadRawBits(32); var snapshotInterval = (int)input.ReadRawBits(16); SetSnapshotInterval(snapshotInterval); if (serverDebug.IntValue > 0) { GameDebug.Log(string.Format("ReadClientConfig: updateRate: {0} snapshotRate: {1}", maxBPS, snapshotInterval)); } }
public void ReadClientInfo(ref RawInputStream input) { var newClientId = (int)input.ReadRawBits(8); serverTickRate = (int)input.ReadRawBits(8); if (connectionState == ConnectionState.Connected) { return; } ConnectionId = newClientId; GameDebug.Log("Client received client info"); connectionState = ConnectionState.Connected; }
public void ReadPackage(byte[] packageData, ISnapshotConsumer snapshotConsumer, INetworkCallbacks networkClientConsumer) { counters.bytesIn += packageData.Length; NetworkUtils.MemCopy(packageData, 0, packageBuffer, 0, packageData.Length); NetworkMessage content; int headerSize; var packageSequence = ProcessPackageHeader(packageBuffer, out content, out headerSize); // The package was dropped (duplicate or too old) or if it was a fragment not yet assembled, bail out here if (packageSequence == 0) { return; } var input = new RawInputStream(); input.Initialize(packageBuffer, headerSize); if ((content & NetworkMessage.ClientInfo) != 0) { ReadClientInfo(ref input); } if ((content & NetworkMessage.MapInfo) != 0) { ReadMapInfo(ref input); } if ((content & NetworkMessage.Snapshot) != 0) { ReadSnapshot(packageSequence, ref input, snapshotConsumer); // Make sure the callback actually picked up the snapshot data. It is important that // every snapshot gets processed by the game so that the spawns, despawns and updates lists // does not end up containing stuff from different snapshots //GameDebug.Assert(spawns.Count == 0 && despawns.Count == 0 && updates.Count == 0, "Game did not consume snapshots"); } if ((content & NetworkMessage.Events) != 0) { ReadEvents(ref input, networkClientConsumer); } }
public static void SkipFields(NetworkSchema schema, ref RawInputStream input) { for (var fieldIndex = 0; fieldIndex < schema.fieldsInternal.Count; ++fieldIndex) { var field = schema.fieldsInternal[fieldIndex]; switch (field.fieldType) { case NetworkSchema.FieldType.Bool: case NetworkSchema.FieldType.UInt: case NetworkSchema.FieldType.Int: case NetworkSchema.FieldType.Float: input.ReadRawBits(field.bits); break; case NetworkSchema.FieldType.Vector2: input.ReadRawBits(field.bits); input.ReadRawBits(field.bits); break; case NetworkSchema.FieldType.Vector3: input.ReadRawBits(field.bits); input.ReadRawBits(field.bits); input.ReadRawBits(field.bits); break; case NetworkSchema.FieldType.Quaternion: input.ReadRawBits(field.bits); input.ReadRawBits(field.bits); input.ReadRawBits(field.bits); input.ReadRawBits(field.bits); break; case NetworkSchema.FieldType.String: case NetworkSchema.FieldType.ByteArray: input.SkipRawBytes((int)input.ReadPackedUInt(field.startContext)); break; default: GameDebug.Assert(false); break; } } }
public static NetworkSchema ReadSchema(ref RawInputStream input) { int count = (int)input.ReadPackedUInt(NetworkConfig.miscContext); int id = (int)input.ReadPackedUInt(NetworkConfig.miscContext); var schema = new NetworkSchema(id); for (int i = 0; i < count; ++i) { var field = new FieldInfo(); field.fieldType = (FieldType)input.ReadPackedNibble(NetworkConfig.miscContext); field.delta = input.ReadRawBits(1) != 0; field.bits = (int)input.ReadPackedUInt(NetworkConfig.miscContext); field.precision = (int)input.ReadPackedUInt(NetworkConfig.miscContext); field.arraySize = (int)input.ReadPackedUInt(NetworkConfig.miscContext); field.startContext = schema.fieldsInternal.Count * NetworkConfig.maxContextsPerField + schema.id * NetworkConfig.maxContextsPerSchema + NetworkConfig.firstSchemaContext; field.fieldMask = (byte)input.ReadPackedUInt(NetworkConfig.miscContext); schema.AddField(field); } schema.Finalize(); return(schema); }
void ReadMapInfo(ref RawInputStream input) { //input.SetStatsType(NetworkCompressionReader.Type.MapInfo); var mapSequence = (ushort)input.ReadRawBits(16); var schemaIncluded = input.ReadRawBits(1) != 0; if (schemaIncluded) { mapInfo.schema = NetworkSchema.ReadSchema(ref input); // might override previous definition } if (mapSequence > mapInfo.mapSequence) { mapInfo.mapSequence = mapSequence; mapInfo.ackSequence = inSequence; mapInfo.processed = false; NetworkSchema.CopyFieldsToBuffer(mapInfo.schema, ref input, mapInfo.data); } else { NetworkSchema.SkipFields(mapInfo.schema, ref input); } }
unsafe void ReadSnapshot(int sequence, ref RawInputStream input, ISnapshotConsumer consumer) { var haveBaseline = input.ReadRawBits(1) == 1; var baseSequence = (int)input.ReadPackedIntDelta(sequence - 1, NetworkConfig.baseSequenceContext); bool enableNetworkPrediction = input.ReadRawBits(1) != 0; int baseSequence1 = 0; int baseSequence2 = 0; if (enableNetworkPrediction) { baseSequence1 = (int)input.ReadPackedIntDelta(baseSequence - 1, NetworkConfig.baseSequence1Context); baseSequence2 = (int)input.ReadPackedIntDelta(baseSequence1 - 1, NetworkConfig.baseSequence2Context); } var snapshotInfo = snapshots.Acquire(sequence); snapshotInfo.serverTime = (int)input.ReadPackedIntDelta(haveBaseline ? snapshots[baseSequence].serverTime : 0, NetworkConfig.serverTimeContext); //GameDebug.Log("baseSequence : " + baseSequence + "server time:" + (haveBaseline ? snapshots[baseSequence].serverTime.ToString() : "")); var temp = (int)input.ReadRawBits(8); serverSimTime = temp * 0.1f; // Only update time if received in-order.. // TODO consider dropping out of order snapshots // TODO detecting out-of-order on pack sequences if (snapshotInfo.serverTime > serverTime) { serverTime = snapshotInfo.serverTime; snapshotReceivedTime = NetworkUtils.stopwatch.ElapsedMilliseconds; } else { GameDebug.Log(string.Format("NetworkClient. Dropping out of order snaphot. Server time:{0} snapshot time:{1}", serverTime, snapshotInfo.serverTime)); } // Read schemas var schemaCount = input.ReadPackedUInt(NetworkConfig.schemaCountContext); for (int schemaIndex = 0; schemaIndex < schemaCount; ++schemaIndex) { var typeId = (ushort)input.ReadPackedUInt(NetworkConfig.schemaTypeIdContext); var entityType = new EntityTypeInfo() { typeId = typeId }; entityType.schema = NetworkSchema.ReadSchema(ref input); //counters.AddSectionStats("snapShotSchemas", input.GetBitPosition2(), new Color(0.0f, (schemaIndex & 1) == 1 ? 0.5f : 1.0f, 1.0f)); entityType.baseline = new uint[NetworkConfig.maxEntitySnapshotDataSize]; NetworkSchema.CopyFieldsToBuffer(entityType.schema, ref input, entityType.baseline); if (!entityTypes.ContainsKey(typeId)) { entityTypes.Add(typeId, entityType); } //counters.AddSectionStats("snapShotSchemas", input.GetBitPosition2(), new Color(1.0f, (schemaIndex & 1) == 1 ? 0.5f : 1.0f, 1.0f)); } // Remove any despawning entities that belong to older base sequences for (int i = 0; i < entities.Count; i++) { var e = entities[i]; if (e.type == null) { continue; } if (e.despawnSequence > 0 && e.despawnSequence <= baseSequence) { e.Reset(); } } // Read new spawns m_TempSpawnList.Clear(); var previousId = 1; var spawnCount = input.ReadPackedUInt(NetworkConfig.spawnCountContext); for (var spawnIndex = 0; spawnIndex < spawnCount; ++spawnIndex) { var id = (int)input.ReadPackedIntDelta(previousId, NetworkConfig.idContext); previousId = id; // Register the entity var typeId = (ushort)input.ReadPackedUInt(NetworkConfig.spawnTypeIdContext); //TODO: use another encoding GameDebug.Assert(entityTypes.ContainsKey(typeId), "Spawn request with unknown type id {0}", typeId); byte fieldMask = (byte)input.ReadRawBits(8); // TODO need an max entity id for safety while (id >= entities.Count) { entities.Add(new EntityInfo()); } // Incoming spawn of different type than what we have for this id, so immediately nuke // the one we have to make room for the incoming if (entities[id].type != null && entities[id].type.typeId != typeId) { // This should only ever happen in case of no baseline as normally the server will // not reuse an id before all clients have acknowledged its despawn. GameDebug.Assert(haveBaseline == false, "Spawning entity but we already have with different type?"); GameDebug.Log("REPLACING old entity: " + id + " because snapshot gave us new type for this id"); despawns.Add(id); entities[id].Reset(); } // We can receive spawn information in several snapshots before our ack // has reached the server. Only pass on spawn to game layer once if (entities[id].type == null) { var e = entities[id]; e.type = entityTypes[typeId]; e.fieldMask = fieldMask; spawns.Add(id); } m_TempSpawnList.Add(id); } //counters.AddSectionStats("snapShotSpawns", input.GetBitPosition2(), new Color(0, 0.58f, 0)); // Read despawns var despawnCount = input.ReadPackedUInt(NetworkConfig.despawnCountContext); // If we have no baseline, we need to clear all entities that are not being spawned if (!haveBaseline) { GameDebug.Assert(despawnCount == 0, "There should not be any despawns in a non-baseline snapshot"); for (int i = 0, c = entities.Count; i < c; ++i) { var e = entities[i]; if (e.type == null) { continue; } if (m_TempSpawnList.Contains(i)) { continue; } GameDebug.Log("NO BL SO PRUNING Stale entity: " + i); despawns.Add(i); e.Reset(); } } for (var despawnIndex = 0; despawnIndex < despawnCount; ++despawnIndex) { var id = (int)input.ReadPackedIntDelta(previousId, NetworkConfig.idContext); previousId = id; // we may see despawns many times, only handle if we still have the entity GameDebug.Assert(id < entities.Count, "Getting despawn for id {0} but we only know about entities up to {1}", id, entities.Count); if (entities[id].type == null) { continue; } var entity = entities[id]; // Already in the process of being despawned. This happens with same-snapshot spawn/despawn cases if (entity.despawnSequence > 0) { continue; } // If we are spawning and despawning in same snapshot, delay actual deletion of // entity as we need it around to be able to read the update part of the snapshot if (m_TempSpawnList.Contains(id)) { entity.despawnSequence = sequence; // keep until baseSequence >= despawnSequence } else { entity.Reset(); // otherwise remove right away; no further updates coming, not even in this snap } // Add to despawns list so we can request despawn from game later GameDebug.Assert(!despawns.Contains(id), "Double despawn in same snaphot? {0}", id); despawns.Add(id); } // Predict all active entities for (var id = 0; id < entities.Count; id++) { var info = entities[id]; if (info.type == null) { continue; } // NOTE : As long as the server haven't gotten the spawn acked, it will keep sending // delta relative to 0, so we need to check if the entity was in the spawn list to determine // if the delta is relative to the last update or not int baseline0Time = 0; uint[] baseline0 = info.type.baseline; GameDebug.Assert(baseline0 != null, "Unable to find schema baseline for type {0}", info.type.typeId); if (haveBaseline && !m_TempSpawnList.Contains(id)) { baseline0 = info.baselines.FindMax(baseSequence); GameDebug.Assert(baseline0 != null, "Unable to find baseline for seq {0} for id {1}", baseSequence, id); baseline0Time = snapshots[baseSequence].serverTime; } if (enableNetworkPrediction) { uint num_baselines = 1; // 1 because either we have schema baseline or we have a real baseline int baseline1Time = 0; int baseline2Time = 0; uint[] baseline1 = null; uint[] baseline2 = null; if (baseSequence1 != baseSequence) { baseline1 = info.baselines.FindMax(baseSequence1); if (baseline1 != null) { num_baselines = 2; baseline1Time = snapshots[baseSequence1].serverTime; } if (baseSequence2 != baseSequence1) { baseline2 = info.baselines.FindMax(baseSequence2); if (baseline2 != null) { num_baselines = 3; baseline2Time = snapshots[baseSequence2].serverTime; } } } // TODO are these clears needed? for (int i = 0, c = info.fieldsChangedPrediction.Length; i < c; ++i) { info.fieldsChangedPrediction[i] = 0; } for (int i = 0; i < NetworkConfig.maxEntitySnapshotDataSize; i++) { info.prediction[i] = 0; fixed(uint *prediction = info.prediction, baseline0p = baseline0, baseline1p = baseline1, baseline2p = baseline2) { NetworkPrediction.PredictSnapshot(prediction, info.fieldsChangedPrediction, info.type.schema, num_baselines, (uint)baseline0Time, baseline0p, (uint)baseline1Time, baseline1p, (uint)baseline2Time, baseline2p, (uint)snapshotInfo.serverTime, info.fieldMask); } } else { var f = info.fieldsChangedPrediction; for (var i = 0; i < f.Length; ++i) { f[i] = 0; } for (int i = 0, c = info.type.schema.GetByteSize() / 4; i < c; ++i) { info.prediction[i] = baseline0[i]; } } } // Read updates var updateCount = input.ReadPackedUInt(NetworkConfig.updateCountContext); for (var updateIndex = 0; updateIndex < updateCount; ++updateIndex) { var id = (int)input.ReadPackedIntDelta(previousId, NetworkConfig.idContext); previousId = id; var info = entities[id]; uint hash = 0; // Copy prediction to temp buffer as we now overwrite info.prediction with fully unpacked // state by applying incoming delta to prediction. for (int i = 0, c = info.type.schema.GetByteSize() / 4; i < c; ++i) { tempSnapshotBuffer[i] = info.prediction[i]; } DeltaReader.Read(ref input, info.type.schema, info.prediction, tempSnapshotBuffer, info.fieldsChangedPrediction, info.fieldMask, ref hash); } //if (enableNetworkPrediction) // counters.AddSectionStats("snapShotUpdatesPredict", input.GetBitPosition2(), haveBaseline ? new Color(0.09f, 0.38f, 0.93f) : Color.cyan); //else // counters.AddSectionStats("snapShotUpdatesNoPredict", input.GetBitPosition2(), haveBaseline ? new Color(0.09f, 0.38f, 0.93f) : Color.cyan); uint snapshotHash = 0; // sum of hash for all (updated or not) entity snapshots uint numEnts = 0; for (int id = 0; id < entities.Count; id++) { var info = entities[id]; if (info.type == null) { continue; } // Skip despawned that have not also been spawned in this snapshot if (info.despawnSequence > 0 && !spawns.Contains(id)) { continue; } // If just spawned or if new snapshot is different from the last we deserialized, // we need to deserialize. Otherwise just ignore; no reason to deserialize the same // values again int schemaSize = info.type.schema.GetByteSize(); if (info.baselines.GetSize() == 0 || NetworkUtils.MemCmp(info.prediction, 0, info.lastUpdate, 0, schemaSize) != 0) { var data = info.baselines.Insert(sequence); for (int i = 0; i < schemaSize / 4; ++i) data[i] = info.prediction[i]; } if (sequence > info.lastUpdateSequence) { if (!updates.Contains(id)) { updates.Add(id); } for (int i = 0; i < schemaSize / 4; ++i) { info.lastUpdate[i] = info.prediction[i]; } info.lastUpdateSequence = sequence; } } //if (enableHashing && info.despawnSequence == 0) { // snapshotHash += NetworkUtils.SimpleHash(info.prediction, schemaSize); // numEnts++; //} }
unsafe public static void CopyFieldsToBuffer(NetworkSchema schema, ref RawInputStream input, uint[] outputBuffer) { var index = 0; for (var fieldIndex = 0; fieldIndex < schema.fieldsInternal.Count; ++fieldIndex) { var field = schema.fieldsInternal[fieldIndex]; switch (field.fieldType) { case NetworkSchema.FieldType.Bool: case NetworkSchema.FieldType.UInt: case NetworkSchema.FieldType.Int: case NetworkSchema.FieldType.Float: outputBuffer[index++] = input.ReadPackedUInt(NetworkConfig.miscContext); break; case NetworkSchema.FieldType.Vector2: outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); break; case NetworkSchema.FieldType.Vector3: outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); break; case NetworkSchema.FieldType.Quaternion: outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); outputBuffer[index++] = (input.ReadPackedUInt(NetworkConfig.miscContext)); break; case NetworkSchema.FieldType.String: case NetworkSchema.FieldType.ByteArray: var dataSize = input.ReadPackedUInt(NetworkConfig.miscContext); outputBuffer[index++] = dataSize; fixed(uint *buf = outputBuffer) { byte *dst = (byte *)(buf + index); int i = 0; for (; i < dataSize; i++) { *dst++ = (byte)input.ReadRawBits(8); } for (; i < field.arraySize; i++) { *dst++ = 0; } } index += field.arraySize / 4; break; default: GameDebug.Assert(false); break; } } }
public static int ReadEvents(Dictionary <ushort, NetworkEventType> eventTypesIn, int connectionId, ref RawInputStream input, INetworkCallbacks networkConsumer) { var eventCount = input.ReadPackedUInt(NetworkConfig.eventCountContext); for (var eventCounter = 0; eventCounter < eventCount; ++eventCounter) { var typeId = (ushort)input.ReadPackedUInt(NetworkConfig.eventTypeIdContext); var schemaIncluded = input.ReadRawBits(1) != 0; if (schemaIncluded) { var eventType = new NetworkEventType() { typeId = typeId }; eventType.schema = NetworkSchema.ReadSchema(ref input); if (!eventTypesIn.ContainsKey(typeId)) { eventTypesIn.Add(typeId, eventType); } } // TODO do we need to Create an info (as we are just releasing it right after?) var type = eventTypesIn[typeId]; var info = Create(type); NetworkSchema.CopyFieldsToBuffer(type.schema, ref input, info.data); if (NetworkConfig.netDebug.IntValue > 0) { GameDebug.Log("Received event " + ((GameNetworkEvents.EventType)info.type.typeId + ":" + info.sequence)); } networkConsumer.OnEvent(connectionId, info); info.Release(); } return((int)eventCount); }
public void ReadEvents(ref RawInputStream input, INetworkCallbacks networkConsumer) { var numEvents = NetworkEvent.ReadEvents(eventTypesIn, ConnectionId, ref input, networkConsumer); counters.eventsIn += numEvents; }
unsafe public static int Read(ref RawInputStream input, NetworkSchema schema, uint[] outputData, uint[] baselineData, byte[] fieldsChangedPrediction, byte fieldMask, ref uint hash) { GameDebug.Assert(baselineData != null); var index = 0; int numFields = schema.numFields; int skipContext = schema.id * NetworkConfig.maxContextsPerSchema + NetworkConfig.firstSchemaContext; for (int i = 0; i * 8 < numFields; i++) { uint value = input.ReadPackedNibble(skipContext + 2 * i + 0); value |= input.ReadPackedNibble(skipContext + 2 * i + 1) << 4; fieldsNotPredicted[i] = (byte)(value ^ fieldsChangedPrediction[i]); } for (int i = 0; i < numFields; ++i) { var field = schema.fields[i]; GameDebug.Assert(field.byteOffset == index * 4); int fieldStartContext = field.startContext; byte fieldByteOffset = (byte)((uint)i >> 3); byte fieldBitOffset = (byte)((uint)i & 0x7); bool skip = (fieldsNotPredicted[fieldByteOffset] & (1 << fieldBitOffset)) == 0; bool masked = ((field.fieldMask & fieldMask) != 0); skip = skip || masked; switch (field.fieldType) { case NetworkSchema.FieldType.Bool: { uint value = baselineData[index]; if (!skip) { value = input.ReadRawBits(1); } if (!masked) { hash = NetworkUtils.SimpleHashStreaming(hash, value); } outputData[index] = value; index++; break; } case NetworkSchema.FieldType.UInt: case NetworkSchema.FieldType.Int: case NetworkSchema.FieldType.Float: { uint baseline = (uint)baselineData[index]; uint value = baseline; if (!skip) { if (field.delta) { value = input.ReadPackedUIntDelta(baseline, fieldStartContext); } else { value = input.ReadRawBits(field.bits); } } if (!masked) { hash = NetworkUtils.SimpleHashStreaming(hash, value); } outputData[index] = value; index++; break; } case NetworkSchema.FieldType.Vector2: { uint bx = baselineData[index]; uint by = baselineData[index + 1]; uint vx = bx; uint vy = by; if (!skip) { if (field.delta) { vx = input.ReadPackedUIntDelta(bx, fieldStartContext + 0); vy = input.ReadPackedUIntDelta(by, fieldStartContext + 1); } else { vx = input.ReadRawBits(field.bits); vy = input.ReadRawBits(field.bits); } } if (!masked) { hash = NetworkUtils.SimpleHashStreaming(hash, vx); hash = NetworkUtils.SimpleHashStreaming(hash, vy); } outputData[index] = vx; outputData[index + 1] = vy; index += 2; break; } case NetworkSchema.FieldType.Vector3: { uint bx = baselineData[index]; uint by = baselineData[index + 1]; uint bz = baselineData[index + 2]; uint vx = bx; uint vy = by; uint vz = bz; if (!skip) { if (field.delta) { vx = input.ReadPackedUIntDelta(bx, fieldStartContext + 0); vy = input.ReadPackedUIntDelta(by, fieldStartContext + 1); vz = input.ReadPackedUIntDelta(bz, fieldStartContext + 2); } else { vx = input.ReadRawBits(field.bits); vy = input.ReadRawBits(field.bits); vz = input.ReadRawBits(field.bits); } } if (!masked) { hash = NetworkUtils.SimpleHashStreaming(hash, vx); hash = NetworkUtils.SimpleHashStreaming(hash, vy); hash = NetworkUtils.SimpleHashStreaming(hash, vz); } outputData[index] = vx; outputData[index + 1] = vy; outputData[index + 2] = vz; index += 3; break; } case NetworkSchema.FieldType.Quaternion: { uint bx = baselineData[index]; uint by = baselineData[index + 1]; uint bz = baselineData[index + 2]; uint bw = baselineData[index + 3]; uint vx = bx; uint vy = by; uint vz = bz; uint vw = bw; if (!skip) { if (field.delta) { vx = input.ReadPackedUIntDelta(bx, fieldStartContext + 0); vy = input.ReadPackedUIntDelta(by, fieldStartContext + 1); vz = input.ReadPackedUIntDelta(bz, fieldStartContext + 2); vw = input.ReadPackedUIntDelta(bw, fieldStartContext + 3); //RUTODO: normalize } else { vx = input.ReadRawBits(field.bits); vy = input.ReadRawBits(field.bits); vz = input.ReadRawBits(field.bits); vw = input.ReadRawBits(field.bits); } } if (!masked) { hash = NetworkUtils.SimpleHashStreaming(hash, vx); hash = NetworkUtils.SimpleHashStreaming(hash, vy); hash = NetworkUtils.SimpleHashStreaming(hash, vz); hash = NetworkUtils.SimpleHashStreaming(hash, vw); } outputData[index] = vx; outputData[index + 1] = vy; outputData[index + 2] = vz; outputData[index + 3] = vw; index += 4; break; } case NetworkSchema.FieldType.String: case NetworkSchema.FieldType.ByteArray: { // TODO : Do a better job with deltaing strings and buffers if (!skip) { uint count = input.ReadPackedUInt(fieldStartContext); outputData[index] = count; index++; fixed(uint *buf = outputData) { byte *dst = (byte *)(buf + index); int idx = 0; for (; idx < count; ++idx) { *dst++ = (byte)input.ReadRawBits(8); } for (; idx < field.arraySize / 4; ++idx) { *dst++ = 0; } } index += field.arraySize / 4; } else { for (int idx = 0, c = field.arraySize / 4; idx < c; ++idx) { outputData[index + idx] = baselineData[index + idx]; } index += field.arraySize / 4 + 1; } if (!masked) { hash += 0; // TODO (hash strings and bytearrays as well) } } break; } } return(index * 4); }