public void SetParent(WorldData World, SetParentDTO data) { if (World.Entities.ContainsKey(data.ID) && (data.parentID == 0 || World.Entities.ContainsKey(data.parentID))) { World.Entities[data.ID].parentID = data.parentID; World.Entities[data.ID].X = data.localPosition.x; World.Entities[data.ID].Y = data.localPosition.y; World.Entities[data.ID].Z = data.localPosition.z; World.Entities[data.ID].rotX = data.localRotation.x; World.Entities[data.ID].rotY = data.localRotation.y; World.Entities[data.ID].rotZ = data.localRotation.z; World.Entities[data.ID].scaleX = data.localScale.x; World.Entities[data.ID].scaleY = data.localScale.y; World.Entities[data.ID].scaleZ = data.localScale.z; using (DarkRiftWriter entityParentWriter = DarkRiftWriter.Create()) { entityParentWriter.Write(data); using (Message setParentMessage = Message.Create(Tags.SetEntityParentTag, entityParentWriter)) { foreach (IClient c in World.GetClients()) { c.SendMessage(setParentMessage, SendMode.Reliable); } } } } else { Console.WriteLine($"Setting parent failed, non exsistant child or parent. Child: {data.ID} Parent {data.parentID}"); } }
private void Client_MessageReceived(object sender, MessageReceivedEventArgs e) { using (Message message = e.GetMessage() as Message) { WorldData World = WorldManager.clients[e.Client].World; if (message.Tag == Tags.SpawnEntityTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { SpawnEntityClientDTO data = reader.ReadSerializable <SpawnEntityClientDTO>(); this.SpawnEntity(World, data); } } } else if (message.Tag == Tags.SpawnProceduralShapeEntityTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { SpawnProceduralShapeEntityClientDTO data = reader.ReadSerializable <SpawnProceduralShapeEntityClientDTO>(); Console.WriteLine("Got spawn procedural message"); this.SpawnProceduralShapeEntity(World, data); } } } else if (message.Tag == Tags.DespawnEntityTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { uint id = reader.ReadUInt32(); this.DespawnEntity(World, id); } } } else if (message.Tag == Tags.SetEntityParentTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { SetParentDTO data = reader.ReadSerializable <SetParentDTO>(); SetParent(World, data); } } } else if (message.Tag == Tags.SetStateEntityTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { uint id = reader.ReadUInt32(); ushort newState = reader.ReadUInt16(); SetState(World, id, newState); } } } else if (message.Tag == Tags.TransformEntityTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { uint id = reader.ReadUInt32(); float x = reader.ReadSingle(); float y = reader.ReadSingle(); float z = reader.ReadSingle(); float rx = reader.ReadSingle(); float ry = reader.ReadSingle(); float rz = reader.ReadSingle(); float sx = reader.ReadSingle(); float sy = reader.ReadSingle(); float sz = reader.ReadSingle(); SetTransform(World, id, x, y, z, rx, ry, rz, sx, sy, sz); } } } else if (message.Tag == Tags.PhysicsUpdateEntityTag) { if (e.Client == WorldManager.clients[e.Client].World.PhysicsHost) { PhysicsUpdate(sender, e, WorldManager.clients[e.Client].World); } } else if (message.Tag == Tags.SetPhysicsEntityTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { //Console.WriteLine("recieved physmessage"); SetPhysicsDTO data = reader.ReadSerializable <SetPhysicsDTO>(); setPhysics(World, data); } } } else if (message.Tag == Tags.AddComponentTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { //Console.WriteLine("recieved physmessage"); AddComponentClientDTO data = reader.ReadSerializable <AddComponentClientDTO>(); addComponent(World, data); } } } else if (message.Tag == Tags.RemoveComponentTag) { using (DarkRiftReader reader = message.GetReader()) { while (reader.Position < reader.Length) { //Console.WriteLine("recieved physmessage"); RemoveComponentDTO data = reader.ReadSerializable <RemoveComponentDTO>(); removeComponent(World, data); } } } else if (message.Tag == Tags.SetComponentPropertyTag) { using (DarkRiftReader reader = message.GetReader()) { //while (reader.Position < reader.Length) //{ ComponentPropertyDTO data = reader.ReadSerializable <ComponentPropertyDTO>(); setComponentProperty(World, data); //} } } } }