private void handleVesselUpdate(KMPVesselUpdate vessel_update) { KMPClientMain.DebugLog("handleVesselUpdate"); String vessel_key = vessel_update.id.ToString(); KMPVessel vessel = null; //Try to find the key in the vessel dictionary VesselEntry entry; if (vessels.TryGetValue(vessel_key, out entry)) { vessel = entry.vessel; if (vessel == null || vessel.gameObj == null || (vessel.vesselRef != null && vessel.vesselRef.id != vessel_update.id)) { //Delete the vessel if it's null or needs to be renamed vessels.Remove(vessel_key); if (vessel != null && vessel.gameObj != null) GameObject.Destroy(vessel.gameObj); vessel = null; } else { //Update the entry's timestamp VesselEntry new_entry = new VesselEntry(); new_entry.vessel = entry.vessel; new_entry.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup; vessels[vessel_key] = new_entry; } } if (vessel == null) { //Add the vessel to the dictionary vessel = new KMPVessel(vessel_update.name, vessel_update.player, vessel_update.id); entry = new VesselEntry(); entry.vessel = vessel; entry.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup; if (vessels.ContainsKey(vessel_key)) vessels[vessel_key] = entry; else vessels.Add(vessel_key, entry); /*Queue this update for the next update call because updating a vessel on the same step as * creating it usually causes problems for some reason */ newVesselUpdateQueue.Enqueue(vessel_update); KMPClientMain.DebugLog("vessel update queued"); } else { applyVesselUpdate(vessel_update, vessel); //Apply the vessel update to the existing vessel KMPClientMain.DebugLog("vessel update applied"); } KMPClientMain.DebugLog("handleVesselUpdate done"); }
private void handleVesselUpdate(KLFVesselUpdate vessel_update) { //Debug.Log("*** Handling update!"); //Build the key for the vessel System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(vessel_update.ownerName); sb.Append(vessel_update.id.ToString()); String vessel_key = sb.ToString(); KLFVessel vessel = null; //Try to find the key in the vessel dictionary VesselEntry entry; if (vessels.TryGetValue(vessel_key, out entry)) { vessel = entry.vessel; if (vessel == null || vessel.gameObj == null || vessel.vesselName != vessel_update.vesselName) { //Delete the vessel if it's null or needs to be renamed vessels.Remove(vessel_key); if (vessel != null && vessel.gameObj != null) GameObject.Destroy(vessel.gameObj); vessel = null; } else { //Update the entry's timestamp VesselEntry new_entry = new VesselEntry(); new_entry.vessel = entry.vessel; new_entry.lastUpdateTime = UnityEngine.Time.fixedTime; vessels[vessel_key] = new_entry; } } if (vessel == null) { //Add the vessel to the dictionary vessel = new KLFVessel(vessel_update.vesselName, vessel_update.ownerName, vessel_update.id); entry = new VesselEntry(); entry.vessel = vessel; entry.lastUpdateTime = UnityEngine.Time.fixedTime; if (vessels.ContainsKey(vessel_key)) vessels[vessel_key] = entry; else vessels.Add(vessel_key, entry); /*Queue this update for the next update call because updating a vessel on the same step as * creating it usually causes problems for some reason */ vesselUpdateQueue.Enqueue(vessel_update); } else applyVesselUpdate(vessel_update, vessel); //Apply the vessel update to the existing vessel //Debug.Log("*** Updated handled"); }
private void handleVesselUpdate(KLFVesselUpdate vessel_update) { if (!isInFlight) { //While not in-flight don't create KLF vessel, just store the active vessel status info if (vessel_update.state == State.ACTIVE) { VesselStatusInfo status = new VesselStatusInfo(); status.info = vessel_update; status.ownerName = vessel_update.player; status.vesselName = vessel_update.name; status.orbit = null; status.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup; status.color = KLFVessel.generateActiveColor(status.ownerName); if (playerStatus.ContainsKey(status.ownerName)) playerStatus[status.ownerName] = status; else playerStatus.Add(status.ownerName, status); } return; //Don't handle updates while not flying a ship } //Build the key for the vessel System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(vessel_update.player); sb.Append(vessel_update.id.ToString()); String vessel_key = sb.ToString(); KLFVessel vessel = null; //Try to find the key in the vessel dictionary VesselEntry entry; if (vessels.TryGetValue(vessel_key, out entry)) { vessel = entry.vessel; if (vessel == null || vessel.gameObj == null || vessel.vesselName != vessel_update.name) { //Delete the vessel if it's null or needs to be renamed vessels.Remove(vessel_key); if (vessel != null && vessel.gameObj != null) GameObject.Destroy(vessel.gameObj); vessel = null; } else { //Update the entry's timestamp VesselEntry new_entry = new VesselEntry(); new_entry.vessel = entry.vessel; new_entry.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup; vessels[vessel_key] = new_entry; } } if (vessel == null) { //Add the vessel to the dictionary vessel = new KLFVessel(vessel_update.name, vessel_update.player, vessel_update.id); entry = new VesselEntry(); entry.vessel = vessel; entry.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup; if (vessels.ContainsKey(vessel_key)) vessels[vessel_key] = entry; else vessels.Add(vessel_key, entry); /*Queue this update for the next update call because updating a vessel on the same step as * creating it usually causes problems for some reason */ vesselUpdateQueue.Enqueue(vessel_update); } else applyVesselUpdate(vessel_update, vessel); //Apply the vessel update to the existing vessel }
private void HandleVesselUpdate(KLFVesselUpdate vesselUpdate) { if (!IsInFlight) { //While not in-flight don't create KLF vessel, just store the active vessel status info if (vesselUpdate.State == State.Active) { VesselStatusInfo status = new VesselStatusInfo(); status.Info = vesselUpdate; status.User = vesselUpdate.Player; status.VesselName = vesselUpdate.Name; status.Orbit = null; status.LastUpdateTime = UnityEngine.Time.realtimeSinceStartup; status.Color = KLFVessel.GenerateActiveColor(status.User); if (PlayerStatus.ContainsKey(status.User)) PlayerStatus[status.User] = status; else PlayerStatus.Add(status.User, status); } return; //Don't handle updates while not flying a ship } //Build the key for the vessel System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(vesselUpdate.Player); sb.Append(vesselUpdate.Id.ToString()); String vesselKey = sb.ToString(); KLFVessel kVes = null; //Try to find the key in the vessel dictionary VesselEntry entry; if (Vessels.TryGetValue(vesselKey, out entry)) { kVes = entry.Vessel; if(kVes == null || kVes.GameObj == null || kVes.VesselName != vesselUpdate.Name) {//Delete the vessel if it's null or needs to be renamed Vessels.Remove(vesselKey); if (kVes != null && kVes.GameObj != null) GameObject.Destroy(kVes.GameObj); kVes = null; } else { //Update the entry's timestamp VesselEntry newEntry = new VesselEntry(); newEntry.Vessel = entry.Vessel; newEntry.LastUpdateTime = UnityEngine.Time.realtimeSinceStartup; Vessels[vesselKey] = newEntry; } } if (kVes == null) {//Add the vessel to the dictionary kVes = new KLFVessel(vesselUpdate.Name, vesselUpdate.Player, vesselUpdate.Id); entry = new VesselEntry(); entry.Vessel = kVes; entry.LastUpdateTime = UnityEngine.Time.realtimeSinceStartup; if (Vessels.ContainsKey(vesselKey)) Vessels[vesselKey] = entry; else Vessels.Add(vesselKey, entry); /*Queue this update for the next update call because updating a vessel on the same step as * creating it usually causes problems for some reason */ VesselUpdateQueue.Enqueue(vesselUpdate); } else ApplyVesselUpdate(vesselUpdate, kVes); //Apply the vessel update to the existing vessel }