public static Snapshot createInterpolationSnapshot(Snapshot previous, Snapshot next, float time, int id, ClientMessenger cm) { List <CubeEntity> cubeEntities = new List <CubeEntity>(); for (int i = 0; i < previous.entities.Count; i++) { int nextId = previous.entities[i].Id; if (!nextId.Equals(id)) { if (cm.isIdRegistered(nextId)) { var cubeEntity = next.getEntityById(nextId); if (cubeEntity != null) { cubeEntities.Add(CubeEntity.createInterpolationEntity(previous.entities[i], cubeEntity, time)); } else { cm.deletePlayer(nextId); } } } } return(new Snapshot(-1, cubeEntities)); }
public void DeserializeSpecific(BitBuffer buffer, List <CubeEntity> entities, ClientMessenger cm) { Deserialize(buffer); CubeEntity founded = null; foreach (var c in entities) { if (c.id.Equals(aux_id)) { founded = c; break; } } if (founded == null) { this.gameObject = cm.createClient(aux_id, false); this.id = aux_id; this.health = aux_health; this.kills = aux_kills; } else { this.gameObject = founded.gameObject; this.id = founded.id; this.health = founded.health; } }
public static Snapshot setUniqueSnapshot(Snapshot unique) { List <CubeEntity> cubeEntities = new List <CubeEntity>(); for (int i = 0; i < unique.entities.Count; i++) { cubeEntities.Add(CubeEntity.createFromUnique(unique.entities[i])); } return(new Snapshot(-1, cubeEntities)); }
public void Deserialize(BitBuffer buffer, ClientMessenger cm) { packetNumber = buffer.GetInt(); List <CubeEntity> news = new List <CubeEntity>(); while (buffer.HasRemaining()) { CubeEntity aux = new CubeEntity(null, -1); aux.DeserializeSpecific(buffer, entities, cm); news.Add(aux); } entities = news; }
public static CubeEntity createFromUnique(CubeEntity ce) { var entity = new CubeEntity(ce.gameObject, ce.id, ce.Health, ce.kills); entity.aux_position = entity.aux_position + ce.aux_position; var rotation = ce.aux_rotation; entity.aux_rotation = rotation; entity.aux_lastCommandProcessed = ce.aux_lastCommandProcessed; entity.aux_health = ce.aux_health; entity.Health = ce.Health; entity.kills = ce.kills; entity.aux_kills = ce.aux_kills; return(entity); }
public static CubeEntity createInterpolationEntity(CubeEntity previousEntity, CubeEntity nextEntity, float time) { var entity = new CubeEntity(previousEntity.gameObject, previousEntity.id, nextEntity.Health, nextEntity.kills); entity.aux_position = entity.aux_position + Vector3.Lerp( previousEntity.aux_position, nextEntity.aux_position, time); var rotation1 = previousEntity.aux_rotation; var deltaRotation = Quaternion.Lerp(rotation1, nextEntity.aux_rotation, time); var rotation = new Quaternion(); rotation.x = rotation1.x + deltaRotation.x; rotation.w = rotation1.w + deltaRotation.w; rotation.y = rotation1.y + deltaRotation.y; rotation.z = rotation1.z + deltaRotation.z; entity.aux_rotation = rotation; entity.aux_lastCommandProcessed = nextEntity.aux_lastCommandProcessed; entity.aux_health = nextEntity.aux_health; entity.aux_kills = nextEntity.aux_kills; return(entity); }