public void Serialize(BinaryWriter writer) { writer.Write(Camera); writer.Write(CameraControls); // Planet info writer.Write(Planet.Seed); // Terrain writer.Write((Int16)Components.Count); Components.ForEach(c => DeserializationRegister.WriteObject(writer, c)); //TODO: weather // Entities writer.Write((Int16)(Entities.Count(e => e.ShouldSave) + EntityQueue.Count(e => e.ShouldSave))); Entities.ForEach(e => { if (e.ShouldSave) { e.Serialize(writer); } }); EntityQueue.ForEach(e => { if (e.ShouldSave) { e.Serialize(writer); } }); // Time writer.Write(TimeScale); }
public override void Deserialize(System.IO.BinaryReader reader) { Size = reader.ReadInt32(); int a = reader.ReadInt32(); for (int i = 0; i < a; ++i) { var item = DeserializationRegister.ReadObject <Item>(reader); Items.Add(item); } Equip = new Item[reader.ReadInt32()]; for (int i = 0; i < Equip.Length; ++i) { if (reader.ReadBoolean()) { var item = DeserializationRegister.ReadObject <Item>(reader); Equip[i] = item; } } UseItems = new Item[reader.ReadInt32()]; for (int i = 0; i < UseItems.Length; ++i) { if (reader.ReadBoolean()) { var item = DeserializationRegister.ReadObject <Item>(reader); UseItems[i] = item; } } }
public override void Serialize(System.IO.BinaryWriter writer) { writer.Write(Size); writer.Write(Items.Count); for (int i = 0; i < Items.Count; ++i) { DeserializationRegister.WriteObject(writer, Items[i]); } writer.Write(Equip.Length); for (int i = 0; i < Equip.Length; ++i) { writer.Write(Equip[i] != null); if (Equip[i] != null) { DeserializationRegister.WriteObject(writer, Equip[i]); } } writer.Write(UseItems.Length); for (int i = 0; i < UseItems.Length; ++i) { writer.Write(UseItems[i] != null); if (UseItems[i] != null) { DeserializationRegister.WriteObject(writer, UseItems[i]); } } }
public override void Serialize(BinaryWriter writer) { writer.Write(StopMovementOnDeath); writer.Write(Elements.Count); for (int i = 0; i < Elements.Count; ++i) { DeserializationRegister.WriteObject(writer, Elements[i]); } }
protected override void WriteToJson(JsonWriter writer) { writer.WritePropertyName("elements"); writer.WriteStartArray(); Elements.ForEach(el => DeserializationRegister.ObjectToJson(writer, el)); writer.WriteEndArray(); writer.WritePropertyName("stopMovementOnDeath"); writer.WriteValue(StopMovementOnDeath); }
public override void Deserialize(BinaryReader reader) { StopMovementOnDeath = reader.ReadBoolean(); int a = reader.ReadInt32(); for (int i = 0; i < a; ++i) { Elements.Add(DeserializationRegister.ReadObject <AiElement>(reader)); } }
/// <summary> /// Serialize this entity using a JsonWriter. /// </summary> /// <param name="writer">Writer.</param> public void ToJson(JsonWriter writer) { writer.WriteStartObject(); writer.WritePropertyName("tags"); writer.WriteStartArray(); // Array of components Tags.ForEach(t => writer.WriteValue(t)); writer.WriteEndArray(); writer.WritePropertyName("components"); writer.WriteStartArray(); // Array of components Components.ForEach(c => DeserializationRegister.ObjectToJson(writer, c)); writer.WriteEndArray(); writer.WriteEndObject(); }
public void Serialize(BinaryWriter writer) { writer.Write(UID); writer.Write(_active); // Tags writer.Write(Tags.Count); Tags.ForEach(t => writer.Write(t)); // Components writer.Write((byte)Components.Count); Components.ForEach(c => DeserializationRegister.WriteObject(writer, c)); }
protected override void ReadFromJson(JObject obj) { if (obj["elements"] != null) { var elemArray = (JArray)obj["elements"]; for (int i = 0; i < elemArray.Count; ++i) { Elements.Add(DeserializationRegister.ObjectFromJson <AiElement>((JObject)elemArray[i])); } } if (obj["stopMovementOnDeath"] != null) { StopMovementOnDeath = (bool)obj["stopMovementOnDeath"]; } }
public void Deserialize(BinaryReader reader) { Camera.Deserialize(reader); CameraControls = reader.ReadBoolean(); // Planet info var p = new PlanetInfo(); p.Randomize(reader.ReadInt32()); Planet = p; // Terrain { var count = reader.ReadInt16(); for (int i = 0; i < count; ++i) { AddComponent(DeserializationRegister.ReadObject <WorldComponent>(reader)); } } // Entities { var count = reader.ReadInt16(); for (int i = 0; i < count; ++i) { var ent = CreateEntity(); ent.Deserialize(reader); } } // Time TimeScale = reader.ReadSingle(); // Load camera region to prevent entities falling out of the world var terrain = GetComponent <TerrainComponent>(); if (terrain != null) { terrain.Multithreaded = false; } SetActiveArea(Camera.Position); if (terrain != null) { terrain.Multithreaded = true; } }
/// <summary> /// Deserialize this entity from a JSON object. /// </summary> /// <param name="obj">Object.</param> public void FromJson(JObject obj) { if (obj["tags"] != null) { var tags = (JArray)obj.GetValue("tags"); for (int i = 0; i < tags.Count; ++i) { Tags.Add((string)tags[i]); } } var components = (JArray)obj.GetValue("components"); for (int i = 0; i < components.Count; ++i) { AddComponent(DeserializationRegister.ObjectFromJson <EntityComponent>((JObject)components[i])); } }
public void Deserialize(BinaryReader reader) { UID = reader.ReadGuid(); _active = reader.ReadBoolean(); // Tags var tCount = reader.ReadInt32(); for (int i = 0; i < tCount; ++i) { Tags.Add(reader.ReadString()); } // Components var count = reader.ReadByte(); for (int i = 0; i < count; ++i) { var component = DeserializationRegister.ReadObject <EntityComponent>(reader); AddComponent(component); } }
static TotemGame() { DeserializationRegister.ScanAssembly(typeof(TotemGame).Assembly); Random = new Random(); }