public static void WriteDoubleNullable(this NetworkWriter writer, double?value) { writer.WriteBool(value.HasValue); if (value.HasValue) { writer.WriteDouble(value.Value); } }
public static void WriteCharacter(this NetworkWriter writer, Character character) { writer.WriteVector2(character.grid_Position); writer.WriteVector2(character.future_Position); writer.WriteInt16(character.gold_Cost); writer.WriteInt16(character.level); writer.WriteInt16(character.mana); writer.WriteInt16(character.max_Mana); writer.WriteInt16(character.base_Mana); writer.WriteInt16(character.attack_Damage); writer.WriteInt16(character.spell_Power); writer.WriteDouble(character.attack_Speed); writer.WriteInt16(character.maxHealth); writer.WriteInt16(character.armor); writer.WriteInt16(character.magic_Resistance); writer.WriteInt16(character.range); writer.WriteInt16(character.ID); writer.WriteDouble(character.attack_Timer); }
// batch as many messages as possible into writer // returns true if any batch was made. public bool MakeNextBatch(NetworkWriter writer, double timeStamp) { // if we have no messages then there's nothing to do if (messages.Count == 0) { return(false); } // make sure the writer is fresh to avoid uncertain situations if (writer.Position != 0) { throw new ArgumentException($"MakeNextBatch needs a fresh writer!"); } // write timestamp first // -> double precision for accuracy over long periods of time writer.WriteDouble(timeStamp); // do start no matter what do { // add next message no matter what. even if > threshold. // (we do allow > threshold sized messages as single batch) NetworkWriterPooled message = messages.Dequeue(); ArraySegment <byte> segment = message.ToArraySegment(); writer.WriteBytes(segment.Array, segment.Offset, segment.Count); // return the writer to pool NetworkWriterPool.Return(message); } // keep going as long as we have more messages, // AND the next one would fit into threshold. while (messages.Count > 0 && writer.Position + messages.Peek().Position <= threshold); // we had messages, so a batch was made return(true); }
public void Serialize(NetworkWriter writer) { writer.WriteDouble(clientTime); writer.WriteDouble(serverTime); }
public override void Serialize(NetworkWriter writer) { writer.WriteDouble(value); }