internal static void DisconnectPlayer(ClientObject client) { string playerName = client.playerName; if (warpList.ContainsKey(playerName)) { warpList.Remove(playerName); } if (voteList != null) { if (voteList.ContainsKey(playerName)) { voteList.Remove(playerName); } } if (ignoreList != null) { if (ignoreList.Contains(playerName)) { ignoreList.Remove(playerName); } } if (warpMaster == playerName || voteMaster == playerName) { SendSetController(null, long.MinValue); } if (!Settings.settingsStore.sendPlayerToLatestSubspace) { Subspace clientSubspace = subspaces[client.subspace]; double timeDelta = ((DateTime.UtcNow.Ticks - clientSubspace.serverClock) / 10000000d) * clientSubspace.subspaceSpeed; double playerOfflineTime = subspaces[client.subspace].planetTime + timeDelta; string storedTimeFile = Path.Combine(Server.universeDirectory, "OfflinePlayerTimes", playerName + ".txt"); File.WriteAllText(storedTimeFile, playerOfflineTime.ToString()); } }
public void Save() { if ((HighLogic.LoadedScene == GameScenes.FLIGHT) && (FlightGlobals.fetch.activeVessel != null)) { if (FlightGlobals.fetch.activeVessel.loaded && !FlightGlobals.fetch.activeVessel.packed) { if (FlightGlobals.fetch.activeVessel.situation != Vessel.Situations.FLYING) { savedVessel = new ConfigNode(); ProtoVessel tempVessel = new ProtoVessel(FlightGlobals.fetch.activeVessel); tempVessel.Save(savedVessel); savedSubspace = new Subspace(); savedSubspace.planetTime = Planetarium.GetUniversalTime(); savedSubspace.serverClock = TimeSyncer.fetch.GetServerClock(); savedSubspace.subspaceSpeed = 1f; ScreenMessages.PostScreenMessage("Quicksaved!", 3f, ScreenMessageStyle.UPPER_CENTER); } else { ScreenMessages.PostScreenMessage("Cannot quicksave - Active vessel is in flight!", 3f, ScreenMessageStyle.UPPER_CENTER); } } else { ScreenMessages.PostScreenMessage("Cannot quicksave - Active vessel is not loaded!", 3f, ScreenMessageStyle.UPPER_CENTER); } } else { ScreenMessages.PostScreenMessage("Cannot quicksave - Not in flight!", 3f, ScreenMessageStyle.UPPER_CENTER); } }
private void Clone(Subspace subspace) { GameObject clone = Instantiate(subspace.gameObject, subspacePivot.transform.position + new Vector3(0.2f, 0, 0), subspace.transform.rotation) as GameObject; clone.GetComponent <Subspace>().m_numControllersInner = 0; clone.GetComponent <Subspace>().m_modePrepareToDelete = false; clone.GetComponent <Subspace>().isOriginal = false; clone.GetComponent <Subspace>().m_letFilter = false; clone.GetComponent <Subspace>().m_letRotate = false; clone.GetComponent <Subspace>().subspacesChild = new List <string>(); clone.GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITHOUT_CONTROLLER; if (m_interaction) { if (m_interaction.versionSubspace.ContainsKey(subspace.name)) { m_interaction.versionSubspace[subspace.name]++; } else { m_interaction.versionSubspace.Add(subspace.name, 1); } clone.GetComponent <Subspace>().version = m_interaction.versionSubspace[subspace.name]; } }
private static void LoadSavedSubspace() { try { string subspaceFile = Path.Combine(Server.universeDirectory, "subspace.txt"); using (StreamReader sr = new StreamReader(subspaceFile)) { //Ignore the comment line. string firstLine = ""; while (firstLine.StartsWith("#") || String.IsNullOrEmpty(firstLine)) { firstLine = sr.ReadLine().Trim(); } Subspace savedSubspace = new Subspace(); int subspaceID = Int32.Parse(firstLine); savedSubspace.serverClock = Int64.Parse(sr.ReadLine().Trim()); savedSubspace.planetTime = Double.Parse(sr.ReadLine().Trim()); savedSubspace.subspaceSpeed = Single.Parse(sr.ReadLine().Trim()); subspaces.Add(subspaceID, savedSubspace); } } catch { DarkLog.Debug("Creating new subspace lock file"); Subspace newSubspace = new Subspace(); newSubspace.serverClock = DateTime.UtcNow.Ticks; newSubspace.planetTime = 100d; newSubspace.subspaceSpeed = 1f; subspaces.Add(0, newSubspace); SaveSubspace(0, newSubspace); } }
/** * Stop Scale mode and refactor type of Hands **/ private void StopScaleAndAutoDetectHand(Subspace subspace) { subspace.ResetDistanceInitialForScale(); // If the output MacroHand is the same that primaryHand if (this == subspace.m_PrimaryHand) { subspace.m_PrimaryHand = subspace.m_SecondaryHand; subspace.m_SecondaryHand = null; m_CurrentTakedSubspace = null; m_otherHand.m_isPressedPrimaryPickup = true; m_otherHand.m_isPressedSecundaryPickup = false; m_isPressedPrimaryPickup = false; m_isPressedSecundaryPickup = false; m_otherHand.DetectTypeHand(); m_otherHand.JoiningSubspace(); } else { subspace.m_SecondaryHand = null; m_CurrentTakedSubspace = null; m_isPressedPrimaryPickup = false; m_isPressedSecundaryPickup = false; DetectTypeHand(); m_otherHand.DetectTypeHand(); m_otherHand.JoiningSubspace(); } if (subspace.GetNumberUsedHandsInner() == 0) { subspace.m_PrimaryHand = null; } }
/** * Delete the subspace or no , depends the parameter answer **/ public void Delete(bool answer) { if (!answer && m_currentDialog) { DisableToDelete(); m_deletedCanceled++; return; } if (m_otherHand.m_ContactInteractables.Contains(dataToDelete)) { m_otherHand.OnTriggerExit(dataToDelete.GetComponent <Collider>()); } m_ContactInteractables.Remove(dataToDelete); m_CurrentTakedSubspace = null; Destroy(dataToDelete.gameObject); Destroy(m_currentDialog); if (m_currentIndexSelected > m_ContactInteractables.Count - 1) { m_currentIndexSelected = m_ContactInteractables.Count - 1; } DetectTypeHand(); m_myHand.ShowHand(); if (!m_custonStatusFingerOtherHand) { m_otherHand.GetComponent <Hand>().DesactivateFingerHand(); } m_otherHand.GetComponent <Hand>().modeAnswer = false; m_deletedAcepted++; }
public void Drop() { if (m_TypeHand == Constants.HAND_PRIMARY_USE) { m_isPressedPrimaryPickup = false; } if (m_TypeHand == Constants.HAND_SECONDARY_USE) { m_isPressedSecundaryPickup = false; } if (m_TypeHand == Constants.HAND_NONE_USE) { m_isPressedPrimaryPickup = false; m_isPressedSecundaryPickup = false; } if (m_currentIndexSelected < 0) { return; } if (!m_CurrentTakedSubspace) { return; } if (m_TypeHand == Constants.HAND_PRIMARY_USE) { if (m_CurrentTakedSubspace.m_PrimaryHand && !m_CurrentTakedSubspace.m_SecondaryHand) { Rigidbody targetBody = m_CurrentTakedSubspace.GetComponent <Rigidbody>(); targetBody.velocity = Vector3.zero; targetBody.angularVelocity = Vector3.zero; m_Joint.connectedBody = null; m_CurrentTakedSubspace.m_PrimaryHand = null; m_CurrentTakedSubspace = null; } else if (m_CurrentTakedSubspace.m_PrimaryHand && m_CurrentTakedSubspace.m_SecondaryHand) { m_CurrentTakedSubspace.ResetDistanceInitialForScale(); m_CurrentTakedSubspace.m_PrimaryHand = m_CurrentTakedSubspace.m_SecondaryHand; m_CurrentTakedSubspace.m_SecondaryHand = null; m_CurrentTakedSubspace = null; m_otherHand.m_isPressedPrimaryPickup = true; m_otherHand.m_isPressedSecundaryPickup = false; m_otherHand.DetectTypeHand(); m_otherHand.JoiningSubspace(); } } else if (m_TypeHand == Constants.HAND_SECONDARY_USE) { m_CurrentTakedSubspace.ResetDistanceInitialForScale(); m_CurrentTakedSubspace.m_SecondaryHand = null; m_CurrentTakedSubspace = null; JoiningSubspace(); } DetectTypeHand(); }
private Node CreateNode(GravisParser.Node_defContext context) { var node = new Node(); if (context.input_def() != null) { if (subspaceStack.Count != 0) { var subspace = subspaceStack.Peek(); subspace.input = node; } node.type = NodeType.Input; node.text = "I"; } else if (context.output_def() != null) { if (subspaceStack.Count != 0) { var subspace = subspaceStack.Peek(); subspace.output = node; } node.type = NodeType.Output; node.text = "O"; } else if (context.const_def() != null) { node.type = NodeType.Constant; node.text = context.const_def().NUMBER().GetText(); } else if (context.if_def() != null) { node.type = NodeType.If; node.text = context.if_def().comp_op().GetText(); } else if (context.opr_def() != null) { node.type = NodeType.Operator; node.text = context.opr_def().arith_op().GetText(); } else if (context.subspace_def() != null) { node.type = NodeType.Subspace; node.text = "S"; var subspace = new Subspace(node); subspaces.Add(subspace); subspaceStack.Push(subspace); } else if (context.self_subspace_def() != null) { node.type = NodeType.SelfSubspace; node.text = "S"; } else { node.text = "?"; } nodes.Add(node); return(node); }
public bool DetectSimimilarTransform(Subspace other) { if (Vector3.Distance(transform.position, other.gameObject.transform.position) <= m_minPositionDistance) // Vector3.Distance(transform.rotation.eulerAngles, other.gameObject.transform.rotation.eulerAngles) < m_minRotationDistance) { return(true); } return(false); }
public double GetUniverseTime(Subspace subspace) { long realTimeSinceLock = GetServerClock() - subspace.serverClock; double realTimeSinceLockSeconds = realTimeSinceLock / 10000000d; double adjustedTimeSinceLockSeconds = realTimeSinceLockSeconds * subspace.subspaceSpeed; return(subspace.planetTime + adjustedTimeSinceLockSeconds); }
public void LockTemporarySubspace(long serverClock, double planetTime, float subspaceSpeed) { Subspace tempSubspace = new Subspace(); tempSubspace.serverClock = serverClock; tempSubspace.planetTime = planetTime; tempSubspace.subspaceSpeed = subspaceSpeed; lockedSubspace = tempSubspace; }
private void SetTransformForSimilar() { Subspace target = m_currentIndexSelected + 1 == m_ContactInteractables.Count ? m_ContactInteractables[0] : m_ContactInteractables[m_currentIndexSelected + 1]; if (m_CurrentTakedSubspace.DetectSimimilarTransform(target)) { m_CurrentTakedSubspace.SetTransformToObject(target); Drop(); } }
public Subspace GetSubspace(int subspaceID) { Subspace ss = new Subspace(); if (subspaces.ContainsKey(subspaceID)) { ss.serverClock = subspaces[subspaceID].serverClock; ss.planetTime = subspaces[subspaceID].planetTime; ss.subspaceSpeed = subspaces[subspaceID].subspaceSpeed; } return(ss); }
public void LockNewSubspace(int subspaceID, long serverTime, double planetariumTime, float subspaceSpeed) { if (!subspaces.ContainsKey(subspaceID)) { Subspace newSubspace = new Subspace(); newSubspace.serverClock = serverTime; newSubspace.planetTime = planetariumTime; newSubspace.subspaceSpeed = subspaceSpeed; subspaces.Add(subspaceID, newSubspace); } DarkLog.Debug("Subspace " + subspaceID + " locked to server, time: " + planetariumTime); }
public static double GetTime() { int latestSubspaceInt = WarpControl.GetLatestSubspace(); if (subspaces.ContainsKey(latestSubspaceInt)) { Subspace latestSubspace = subspaces[latestSubspaceInt]; double clockDiff = (DateTime.UtcNow.Ticks - latestSubspace.serverClock) / (double)TimeSpan.TicksPerSecond; return(latestSubspace.planetTime + (clockDiff * latestSubspace.subspaceSpeed)); } return(0); }
public void AddNewSubspace(int subspaceID, long serverTime, double planetariumTime, float subspaceSpeed) { Subspace newSubspace = new Subspace(); newSubspace.serverClock = serverTime; newSubspace.planetTime = planetariumTime; newSubspace.subspaceSpeed = subspaceSpeed; subspaces[subspaceID] = newSubspace; if (currentSubspace == subspaceID) { LockSubspace(currentSubspace); } DarkLog.Debug("Subspace " + subspaceID + " locked to server, time: " + planetariumTime); }
private void CheckWarp() { bool resetWarp = true; if ((warpMode == WarpMode.MCW_FORCE) || (warpMode == WarpMode.MCW_VOTE)) { if (warpMaster != "") { //It could be us or another player. If it's another player it will be controlled from Update() instead. resetWarp = false; } } if (warpMode == WarpMode.SUBSPACE) { //Never reset warp in SUBSPACE mode. resetWarp = false; } if (warpMode == WarpMode.MCW_LOWEST) { //Controlled from above in Update() resetWarp = false; } if ((TimeWarp.CurrentRateIndex > 0) && resetWarp) { DarkLog.Debug("Resetting warp rate back to 0"); TimeWarp.SetRate(0, true); } if ((TimeWarp.CurrentRateIndex > 0) && (TimeWarp.CurrentRate > 1.1f) && !resetWarp && TimeSyncer.fetch.locked) { DarkLog.Debug("Unlocking from subspace"); TimeSyncer.fetch.UnlockSubspace(); } if ((TimeWarp.CurrentRateIndex == 0) && (TimeWarp.CurrentRate < 1.1f) && !TimeSyncer.fetch.locked && (warpMode == WarpMode.SUBSPACE) && (TimeSyncer.fetch.currentSubspace == -1)) { int newSubspaceID = TimeSyncer.fetch.LockNewSubspace(TimeSyncer.fetch.GetServerClock(), Planetarium.GetUniversalTime(), 1f); TimeSyncer.fetch.LockSubspace(newSubspaceID); Subspace newSubspace = TimeSyncer.fetch.GetSubspace(newSubspaceID); using (MessageWriter mw = new MessageWriter()) { mw.Write <int>((int)WarpMessageType.NEW_SUBSPACE); mw.Write <string>(Settings.fetch.playerName); mw.Write <int>(newSubspaceID); mw.Write <long>(newSubspace.serverClock); mw.Write <double>(newSubspace.planetTime); mw.Write <float>(newSubspace.subspaceSpeed); NetworkWorker.fetch.SendWarpMessage(mw.GetMessageBytes()); } } }
private void StopScaleBothHands(Subspace subspace) { subspace.ResetDistanceInitialForScale(); subspace.m_PrimaryHand = null; subspace.m_SecondaryHand = null; m_CurrentTakedSubspace = null; m_isPressedPrimaryPickup = false; m_isPressedSecundaryPickup = false; Rigidbody targetBody = subspace.GetComponent <Rigidbody>(); targetBody.velocity = Vector3.zero; targetBody.angularVelocity = Vector3.zero; m_Joint.connectedBody = null; m_otherHand.DetectTypeHand(); }
private static void SaveSubspace(int subspaceID, Subspace subspace) { string subspaceFile = Path.Combine(Server.universeDirectory, "subspace.txt"); using (StreamWriter sw = new StreamWriter(subspaceFile)) { sw.WriteLine("#Incorrectly editing this file will cause weirdness. If there is any errors, the universe time will be reset."); sw.WriteLine("#This file can only be edited if the server is stopped."); sw.WriteLine("#Each variable is on a new line. They are subspaceID, server clock (from DateTime.UtcNow.Ticks), universe time, and subspace speed."); sw.WriteLine(subspaceID); sw.WriteLine(subspace.serverClock); sw.WriteLine(subspace.planetTime); sw.WriteLine(subspace.subspaceSpeed); } }
private void OnTriggerEnter(Collider other) { if (!other.gameObject.CompareTag("Subspace")) { return; } if (printEvents) { print(Time.deltaTime + " " + "OnTriggerEnter : " + other.gameObject.name); } if (m_console) { m_console.AddText("ONTRIGGERENTERIN: " + other.gameObject.name); } Subspace subspace = other.gameObject.GetComponent <Subspace>(); m_ContactInteractables.Add(subspace); if (m_currentIndexSelected < 0) { m_currentIndexSelected = 0; subspace.m_HandsActivedInner.Add(this); } if (!m_CurrentTakedSubspace) { m_ContactInteractables[m_currentIndexSelected].m_HandsActivedInner.Remove(this); if (m_ContactInteractables[m_currentIndexSelected].m_HandsActivedInner.Count == 0) { m_ContactInteractables[m_currentIndexSelected].GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITHOUT_CONTROLLER; } m_currentIndexSelected = m_ContactInteractables.IndexOf(subspace); subspace.m_HandsActivedInner.Add(this); } subspace.m_numControllersInner++; if (enabled && !subspace.m_modePrepareToDelete) { m_ContactInteractables[m_currentIndexSelected].GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITH_CONTROLLER; } DetectTypeHand(); if (m_console) { m_console.AddText("ONTRIGGERENTEROUT: " + other.gameObject.name + " , m_ContactInteractables.Count: " + m_ContactInteractables.Count + " , m_currentIndexSelected: " + m_currentIndexSelected + " , subspace.m_numControllersInner: " + subspace.m_numControllersInner + " , typeHand: " + m_TypeHand); } }
private string GetDataSelected() { string dataSelected = ""; foreach (GameObject subspace in GameObject.FindGameObjectsWithTag("Subspace")) { Subspace sub = subspace.GetComponent <Subspace>(); dataSelected += "#" + sub.name + " " + sub.version + ": "; foreach (Data data in sub.selectedData) { dataSelected += data.Id + "-"; } } return(dataSelected); }
public void Pickup() { if (m_TypeHand == Constants.HAND_PRIMARY_USE) { m_isPressedPrimaryPickup = true; } if (m_TypeHand == Constants.HAND_SECONDARY_USE) { m_isPressedSecundaryPickup = true; } if (m_TypeHand == Constants.HAND_NONE_USE) { m_isPressedPrimaryPickup = false; m_isPressedSecundaryPickup = false; } if (m_CurrentTakedSubspace || m_currentIndexSelected < 0) { return; } m_CurrentTakedSubspace = m_ContactInteractables[m_currentIndexSelected]; if (!m_CurrentTakedSubspace) { return; } DetectTypeHand(); if (m_TypeHand == Constants.HAND_PRIMARY_USE) { Rigidbody targetBody = m_CurrentTakedSubspace.GetComponent <Rigidbody>(); m_Joint.connectedBody = targetBody; m_CurrentTakedSubspace.m_PrimaryHand = this; m_CurrentTakedSubspace.m_SecondaryHand = null; m_selectSubspaces++; if (m_consoleLeft) { m_consoleLeft.AddText("m_selectSubspaces: " + m_selectSubspaces); } } if (m_TypeHand == Constants.HAND_SECONDARY_USE) { m_CurrentTakedSubspace.m_SecondaryHand = this; StopJoiningSubspace(); m_CurrentTakedSubspace.m_distanceInitialForScale = Vector3.Distance(m_CurrentTakedSubspace.m_PrimaryHand.transform.position, transform.position); m_CurrentTakedSubspace.m_modeScale = true; } DetectTypeHand(); }
/** * Disable the Subspace to delete and close the confirmation dialog * **/ private void DisableToDelete() { Destroy(m_currentDialog); m_myHand.ShowHand(); dataToDelete.m_modePrepareToDelete = false; if (dataToDelete.GetNumberUsedHandsInner() == 0) { dataToDelete.GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITHOUT_CONTROLLER; } else { dataToDelete.GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITH_CONTROLLER; } dataToDelete = null; if (!m_custonStatusFingerOtherHand) { m_otherHand.GetComponent <Hand>().DesactivateFingerHand(); } m_otherHand.GetComponent <Hand>().modeAnswer = false; }
/** * Prepare to Subspace to Delete coloring and displying confirmation dialog **/ private void EnableToDelete() { if (m_currentIndexSelected < 0 && !m_ContactInteractables[m_currentIndexSelected]) { return; } if (m_ContactInteractables[m_currentIndexSelected].isOriginal) { return; } dataToDelete = m_ContactInteractables[m_currentIndexSelected]; dataToDelete.m_modePrepareToDelete = true; dataToDelete.GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_PREPARE_TO_DELETE; m_myHand.HideHand(); m_currentDialog = Instantiate(dialogCommon); m_currentDialog.transform.SetParent(transform); m_custonStatusFingerOtherHand = m_otherHand.GetComponent <Hand>().getStatusFingerHand(); m_otherHand.GetComponent <Hand>().ActivateFingerHand(); m_otherHand.GetComponent <Hand>().modeAnswer = true; }
private static void HandleNewSubspace(ClientObject client, long serverClock, double planetTime, float subspaceSpeed) { lock (createLock) { DarkLog.Debug("Create subspace"); //Create subspace Subspace newSubspace = new Subspace(); newSubspace.serverClock = serverClock; newSubspace.planetTime = planetTime; newSubspace.subspaceSpeed = subspaceSpeed; subspaces.Add(freeID, newSubspace); //Create message ServerMessage newMessage = new ServerMessage(); newMessage.type = ServerMessageType.WARP_CONTROL; using (MessageWriter mw = new MessageWriter()) { mw.Write <int>((int)WarpMessageType.NEW_SUBSPACE); mw.Write <int>(freeID); mw.Write <long>(serverClock); mw.Write <double>(planetTime); mw.Write <float>(subspaceSpeed); newMessage.data = mw.GetMessageBytes(); } //Tell all clients about the new subspace ClientHandler.SendToAll(null, newMessage, true); //Send the client to that subspace if (Settings.settingsStore.warpMode == WarpMode.MCW_FORCE || Settings.settingsStore.warpMode == WarpMode.MCW_VOTE || Settings.settingsStore.warpMode == WarpMode.MCW_LOWEST) { SendSetSubspaceToAll(freeID); } else { SendSetSubspace(client, freeID); } freeID++; //Save to disk SaveLatestSubspace(); } }
void Update() { if (m_myHand.modeAnswer) { return; } m_totalTime += Time.deltaTime; if (m_Joint.connectedBody) { m_pickupTime += Time.deltaTime; if (m_CurrentTakedSubspace && m_CurrentTakedSubspace.subspacesChild.Count > 0) { m_navSlaving += Time.deltaTime; } } if (m_CurrentTakedSubspace && m_CurrentTakedSubspace.m_modeScale) { m_scaleTime += Time.deltaTime; } /** FIX BUG**/ if (!m_isPressedPrimaryPickup && m_Joint.connectedBody) { m_CurrentTakedSubspace = null; Subspace joined = m_Joint.connectedBody.GetComponent <Subspace>(); joined.m_PrimaryHand = null; joined.m_SecondaryHand = null; m_Joint.connectedBody = null; if (m_console) { m_console.AddText("FIX BUG"); } return; } if (SteamVR_Actions._default.GrabGrip.GetStateDown(m_Pose.inputSource)) { if (printEvents) { print(Time.deltaTime + " " + m_Pose.inputSource + " Pickup"); } if (m_console) { m_console.AddText("PICKUP()"); } Pickup(); if (m_console) { m_console.AddText("m_currentIndexSelected: " + m_currentIndexSelected); } return; } if (SteamVR_Actions._default.TouchXbutton.GetStateDown(m_Pose.inputSource)) { if (printEvents) { print(Time.deltaTime + " " + m_Pose.inputSource + " Clone"); } if (m_console) { m_console.AddText("CLONE()"); } Clone(); return; } if (SteamVR_Actions._default.GrabGrip.GetStateUp(m_Pose.inputSource)) { if (printEvents) { print(Time.deltaTime + " " + m_Pose.inputSource + " Drop"); } if (m_console) { m_console.AddText("DROP()"); } Drop(); if (m_console) { m_console.AddText("m_currentIndexSelected: " + m_currentIndexSelected); } return; } /** * if (m_ContactInteractables.Count > 1 && SteamVR_Actions._default.GrabPinch.GetStateDown(m_Pose.inputSource) && * !m_isPressedPrimaryPickup && !m_isPressedSecundaryPickup) * { * if (printEvents) print(Time.deltaTime + " " + m_Pose.inputSource + " ChangeCurrentSelectionSpace"); * if (m_console) m_console.AddText("CHANGECURRENTSELECTIONSPACE()"); * ChangeCurrentSelectionSpace(); * return; * }**/ if (m_ContactInteractables.Count > 0 && !m_currentDialog && !m_myHand.m_FinishTaskDialog && SteamVR_Actions._default.TouchYbutton.GetStateDown(m_Pose.inputSource) && !m_isPressedPrimaryPickup) { if (printEvents) { print(Time.deltaTime + " " + m_Pose.inputSource + " EnableToDelete"); } if (m_console) { m_console.AddText("ENABLETODELETE()"); } EnableToDelete(); return; } /** * if (m_CurrentTakedSubspace && SteamVR_Actions._default.TouchXbutton.GetStateDown(m_Pose.inputSource) && m_ContactInteractables.Count > 1) * { * if (printEvents) print(Time.deltaTime + " " + m_Pose.inputSource + "SetTransformForSimilar"); * if (m_console) m_console.AddText("SETTRANSFORMFORSIMILAR()"); * SetTransformForSimilar(); * return; * }**/ }
public static void HandleWarpControl(ClientObject client, byte[] messageData) { ServerMessage newMessage = new ServerMessage(); newMessage.type = ServerMessageType.WARP_CONTROL; newMessage.data = messageData; using (MessageReader mr = new MessageReader(messageData)) { WarpMessageType warpType = (WarpMessageType)mr.Read <int>(); string fromPlayer = mr.Read <string>(); if (fromPlayer == client.playerName) { if (warpType == WarpMessageType.NEW_SUBSPACE) { int newSubspaceID = mr.Read <int>(); if (subspaces.ContainsKey(newSubspaceID)) { DarkLog.Debug("Kicked for trying to create an existing subspace"); Messages.ConnectionEnd.SendConnectionEnd(client, "Kicked for trying to create an existing subspace"); return; } else { Subspace newSubspace = new Subspace(); newSubspace.serverClock = mr.Read <long>(); newSubspace.planetTime = mr.Read <double>(); newSubspace.subspaceSpeed = mr.Read <float>(); subspaces.Add(newSubspaceID, newSubspace); client.subspace = newSubspaceID; SaveLatestSubspace(); } } if (warpType == WarpMessageType.CHANGE_SUBSPACE) { client.subspace = mr.Read <int>(); } if (warpType == WarpMessageType.REPORT_RATE) { int reportedSubspace = mr.Read <int>(); if (client.subspace != reportedSubspace) { DarkLog.Debug("Warning, setting client " + client.playerName + " to subspace " + client.subspace); client.subspace = reportedSubspace; } float newSubspaceRate = mr.Read <float>(); client.subspaceRate = newSubspaceRate; foreach (ClientObject otherClient in ClientHandler.GetClients()) { if (otherClient.authenticated && otherClient.subspace == reportedSubspace) { if (newSubspaceRate > otherClient.subspaceRate) { newSubspaceRate = otherClient.subspaceRate; } } } if (newSubspaceRate < 0.3f) { newSubspaceRate = 0.3f; } if (newSubspaceRate > 1f) { newSubspaceRate = 1f; } //Relock the subspace if the rate is more than 3% out of the average if (Math.Abs(subspaces[reportedSubspace].subspaceSpeed - newSubspaceRate) > 0.03f) { UpdateSubspace(reportedSubspace); subspaces[reportedSubspace].subspaceSpeed = newSubspaceRate; ServerMessage relockMessage = new ServerMessage(); relockMessage.type = ServerMessageType.WARP_CONTROL; using (MessageWriter mw = new MessageWriter()) { mw.Write <int>((int)WarpMessageType.RELOCK_SUBSPACE); mw.Write <string>(Settings.settingsStore.consoleIdentifier); mw.Write <int>(reportedSubspace); mw.Write <long>(subspaces[reportedSubspace].serverClock); mw.Write <double>(subspaces[reportedSubspace].planetTime); mw.Write <float>(subspaces[reportedSubspace].subspaceSpeed); relockMessage.data = mw.GetMessageBytes(); } SaveLatestSubspace(); //DarkLog.Debug("Subspace " + client.subspace + " locked to " + newSubspaceRate + "x speed."); ClientHandler.SendToClient(client, relockMessage, true); ClientHandler.SendToAll(client, relockMessage, true); } } } else { DarkLog.Debug(client.playerName + " tried to send an update for " + fromPlayer + ", kicking."); Messages.ConnectionEnd.SendConnectionEnd(client, "Kicked for sending an update for another player"); return; } } ClientHandler.SendToAll(client, newMessage, true); }
/** * void OnGUI() * { * //Press this button to lock the Cursor * if (GUI.Button(new Rect(0, 0, 100, 50), "Lock Cursor")) * { * Cursor.lockState = CursorLockMode.Locked; * } * * //Press this button to confine the Cursor within the screen * if (GUI.Button(new Rect(125, 0, 100, 50), "Confine Cursor")) * { * Cursor.lockState = CursorLockMode.Confined; * } * } **/ void Update() { if (!isReady && Input.GetMouseButtonUp(0)) { Cursor.lockState = CursorLockMode.Confined; Cursor.lockState = CursorLockMode.Locked; isReady = true; GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CamMouseLook>().mouselooked = false; } if (!isReady) { return; } m_totalTime += Time.deltaTime; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] f = Physics.RaycastAll(ray, Mathf.Infinity); if (Input.GetKeyDown(KeyCode.Return)) { GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CamMouseLook>().mouselooked = true; Cursor.lockState = CursorLockMode.None; dialogConfirmationF.SetActive(true); return; } if (Input.GetMouseButtonDown(1)) { Collider collision = GetNearestCollider(f, LayerMask.NameToLayer("Subspace")); if (collision) { subspaceNearest = collision.GetComponent <Subspace>(); GetComponent <MovementFPS>().stopMovement = true; CreatePivot(); subspaceNearest.GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITH_CONTROLLER; //subspaceNearest.GetComponent<Subspace>().m_letRotate = false; subspaceNearest.GetComponent <Subspace>().m_letRotate = true; cachedPosition = transform.position; m_dragging = true; GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CamMouseLook>().mouselooked = true; m_selectSubspaces++; Cursor.lockState = CursorLockMode.None; } return; } if (Input.GetMouseButtonUp(1) && !m_modeDelete) { GetComponent <MovementFPS>().stopMovement = false; if (subspaceNearest) { subspaceNearest.GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITHOUT_CONTROLLER; subspaceNearest.GetComponent <Subspace>().m_letRotate = false; } cachedPosition = Vector3.zero; m_dragging = false; DeletePivot(); GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CamMouseLook>().mouselooked = false; Cursor.lockState = CursorLockMode.Locked; return; } if (subspaceNearest && Input.GetMouseButton(1))//macro { m_pickupTime += Time.deltaTime; /**if (Input.GetMouseButtonDown(0)) * { * m_dragging = true; * DeletePivot(); * CreatePivot(); * subspaceNearest.GetComponent<Subspace>().m_letRotate = true; * return; * } * if (m_dragging && (Input.GetMouseButtonUp(1))) * { * GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CamMouseLook>().mouselooked = false; * m_dragging = false; * DeletePivot(); * subspaceNearest.GetComponent<Subspace>().m_letRotate = false; * return; * }**/ if (m_dragging) { float rotX = Input.GetAxis("Mouse X") * rotationSpeed; float rotY = Input.GetAxis("Mouse Y") * rotationSpeed; subspaceNearest.transform.parent.Rotate(Vector3.up, -rotX); subspaceNearest.transform.parent.Rotate(Vector3.right, rotY); m_rotationTime += Time.deltaTime; if (subspaceNearest.m_letRotate && subspaceNearest.subspacesChild.Count > 0) { m_navSlaving += Time.deltaTime; } //print("m_rotationTime " + m_rotationTime); //print("m_navSlaving " + m_navSlaving); } if (Input.GetAxisRaw("Vertical") != 0 || Input.GetAxisRaw("Horizontal") != 0 || Input.GetKey(KeyCode.E) || Input.GetKey(KeyCode.Q)) { if (m_isAxisInUse == false) { cachedPosition = transform.position; float translation = Input.GetAxis("Vertical") * 10f; float straffe = Input.GetAxis("Horizontal") * 10f; float high = 0f; if (Input.GetKey(KeyCode.E)) { high = 0.005f; } if (Input.GetKey(KeyCode.Q)) { high = -0.005f; } translation *= Time.deltaTime; straffe *= Time.deltaTime; DeletePivot(); CreatePivot(); Vector3 newPos = subspacePivot.transform.position + subspacePivot.transform.TransformDirection(straffe, high, translation); if (newPos.x < 2.7f && newPos.x > -1.7f && newPos.z < 1.9f && newPos.z > -1.74f && newPos.y < 4f && newPos.y > 1f) { subspacePivot.transform.Translate(straffe, high, translation); } m_traslationTime += Time.deltaTime; //print("m_traslationTime " + m_traslationTime); m_isAxisInUse = true; } if (Input.GetAxisRaw("Vertical") == 0 || Input.GetAxisRaw("Horizontal") == 0) { m_isAxisInUse = false; } } if (Input.GetAxis("Mouse ScrollWheel") != 0f) // forward { subspaceNearest.ChangeScaleScroll(Input.GetAxis("Mouse ScrollWheel")); m_scaleTime += Time.deltaTime; print("m_scaleTime " + m_scaleTime); } if (Input.GetKeyDown(KeyCode.Space)) { Clone(subspaceNearest); m_clones++; } if (Input.GetKeyDown(KeyCode.Delete) && !subspaceNearest.isOriginal) { GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CamMouseLook>().mouselooked = true; Cursor.lockState = CursorLockMode.None; m_modeDelete = true; subspaceNearest.GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_PREPARE_TO_DELETE; dialogConfirmation.SetActive(true); } } bool existData = false; Collider dataNearest = GetNearestCollider(f, LayerMask.NameToLayer("Data")); if (dataNearest) { existData = true; if (currentHit != dataNearest.gameObject.GetInstanceID()) { Destroy(highlightHolder); currentHit = dataNearest.gameObject.GetInstanceID(); Interactable interactable = dataNearest.gameObject.GetComponent <Interactable>(); CreateHighlightRenderers(interactable); if (text1) { text1.text = dataNearest.GetComponent <Data>().Name_1; } if (text2) { text2.text = dataNearest.GetComponent <Data>().Name_2; } if (text3) { text3.text = dataNearest.GetComponent <Data>().Name_3; } if (text4) { text4.text = dataNearest.GetComponent <Data>().Name_4; } } } if (!existData) { currentHit = 0; Destroy(highlightHolder); CleanTextCanvas(); } UpdateHighlightRenderers(false); if (m_modeDelete) { return; } if (!m_dragging && existData && Input.GetMouseButtonUp(0) && m_interaction)// micro { m_interaction.FilterData(dataNearest.GetComponent <Data>()); return; } }
public void SetTransformToObject(Subspace obj) { transform.position = obj.transform.position; transform.rotation *= GetShortestQuaternion(obj.transform); }
public void OnTriggerExit(Collider other) { if (!other.gameObject.CompareTag("Subspace")) { return; } if (printEvents) { print(Time.deltaTime + " " + "OnTriggerExit : " + other.gameObject.name); } if (m_console) { m_console.AddText("ONTRIGGEREXITIN: " + other.gameObject.name); } Subspace subspace = other.gameObject.GetComponent <Subspace>(); m_ContactInteractables.Remove(subspace); subspace.m_numControllersInner--; subspace.m_HandsActivedInner.Remove(this); if (enabled && !subspace.m_modePrepareToDelete && (subspace.GetNumberUsedHandsInner(true) == 0)) { other.GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITHOUT_CONTROLLER; } if (m_currentIndexSelected > m_ContactInteractables.Count - 1) { m_currentIndexSelected = m_ContactInteractables.Count - 1; } if (subspace.m_modeScale && subspace.m_PrimaryHand && subspace.m_SecondaryHand) { stoppingScaleOnTriggerExit = true; if (!m_otherHand.stoppingScaleOnTriggerExit) { StopScaleAndAutoDetectHand(subspace); } else { StopScaleBothHands(subspace); } } if (m_ContactInteractables.Count > 0 && !m_CurrentTakedSubspace) { m_ContactInteractables[m_currentIndexSelected].m_HandsActivedInner.Add(this); if (enabled) { m_ContactInteractables[m_currentIndexSelected].GetComponent <Renderer>().material.color = Constants.SPACE_COLOR_WITH_CONTROLLER; } } if (m_ContactInteractables.Count == 0) { m_CurrentTakedSubspace = null; } DetectTypeHand(); stoppingScaleOnTriggerExit = false; if (m_console) { m_console.AddText("ONTRIGGEREXITIUT: " + other.gameObject.name + " , m_ContactInteractables.Count: " + m_ContactInteractables.Count + " , m_currentIndexSelected: " + m_currentIndexSelected + " , subspace.m_numControllersInner: " + subspace.m_numControllersInner + " , typeHand: " + m_TypeHand); } }