diff --git a/AddressManager.cs b/AddressManager.cs index 27771a1..aa40170 100644 --- a/AddressManager.cs +++ b/AddressManager.cs @@ -212,6 +212,10 @@ public class AddressManager } } machineIdCoroutineActive = false; + if (gameManager.dataSaveRequested == true) + { + stateManager.finalMachineAddress = true; + } } public IEnumerator BlockIdCoroutine() @@ -284,5 +288,9 @@ public class AddressManager } } blockIdCoroutineActive = false; + if (gameManager.dataSaveRequested == true) + { + stateManager.finalBlockAddress = true; + } } } \ No newline at end of file diff --git a/GameManager.cs b/GameManager.cs index 9e29f45..d1df5a8 100644 --- a/GameManager.cs +++ b/GameManager.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Collections; using UnityEngine; +using System.Diagnostics; +using System; public class GameManager : MonoBehaviour { @@ -36,6 +38,7 @@ public class GameManager : MonoBehaviour public bool replacingMeshFilters; public bool runningUndo; private float mfDelay; + private float userSimSpeed; public bool clearBrickDummies; public bool clearGlassDummies; public bool clearIronDummies; @@ -49,11 +52,13 @@ public class GameManager : MonoBehaviour public bool loadedPirateTimer; private bool loadedBlockPhysics; private bool loadedHazardsEnabled; + private bool memoryCoroutineBusy; public Rocket rocketScript; public Coroutine separateCoroutine; public Coroutine meshCombineCoroutine; public Coroutine blockCombineCoroutine; public Coroutine hazardRemovalCoroutine; + private Coroutine memoryCoroutine; private Coroutine undoCoroutine; public List meteorShowerLocationList; @@ -102,7 +107,7 @@ public class GameManager : MonoBehaviour // Load chunk size setting. float simSpeed = PlayerPrefs.GetFloat("simulationSpeed"); - simulationSpeed = simSpeed > 0 ? simSpeed : 0.04f; + simulationSpeed = simSpeed > 0 ? simSpeed : 0.02f; simulationSpeed = PlayerPrefs.GetFloat("simulationSpeed"); // Create initial iron block holder for mesh manager. @@ -134,9 +139,9 @@ public class GameManager : MonoBehaviour brickHolders = new GameObject[] { brickInit }; } + //! Creates initial block holders for mod blocks. public void InitModBlocks() { - // Create initial block holders for mod blocks. int index = 0; int count = modBlockNames.Count; foreach (string blockName in modBlockNames) @@ -205,10 +210,22 @@ public class GameManager : MonoBehaviour { if (GetComponent().saving == false && GetComponent().AddressManagerBusy() == false) { - Debug.Log("Saving world..."); + UnityEngine.Debug.Log("Saving world..."); GetComponent().SaveData(); dataSaveRequested = false; } + else if (GetComponent().AddressManagerBusy() == true) + { + if (GetComponent().simulationSpeed != 0.1f) + { + userSimSpeed = GetComponent().simulationSpeed; + } + GetComponent().simulationSpeed = 0.1f; + } + else + { + GetComponent().simulationSpeed = userSimSpeed; + } } // Used to ensure components are removed before combining meshes. @@ -227,9 +244,33 @@ public class GameManager : MonoBehaviour { hazardManager.UpdateHazards(); } + + if (memoryCoroutineBusy == false) + { + memoryCoroutine = StartCoroutine(ManageMemory()); + } } } + //! Unloads unused assets when the game is using too much memory. + public IEnumerator ManageMemory() + { + memoryCoroutineBusy = true; + float availableMemory = SystemInfo.systemMemorySize; + Process proc = Process.GetCurrentProcess(); + proc.Refresh(); + float usedMemory = Math.Abs((int)(proc.WorkingSet64 / (1024*1024))); + proc.Dispose(); + float percentUsedMemory = usedMemory / availableMemory; + if (percentUsedMemory >= 0.5f) + { + Resources.UnloadUnusedAssets(); + } + yield return new WaitForSeconds(60); + memoryCoroutineBusy = false; + } + + //! Starts the undo coroutine. public void UndoBuiltObjects() { if (runningUndo == false) @@ -264,7 +305,7 @@ public class GameManager : MonoBehaviour { if (working == false && GetComponent().saving == false) { - Debug.Log("Requesting save operation..."); + UnityEngine.Debug.Log("Requesting save operation..."); dataSaveRequested = true; blocksCombined = false; } diff --git a/Grass.cs b/Grass.cs index 8331131..243b3ef 100644 --- a/Grass.cs +++ b/Grass.cs @@ -7,7 +7,7 @@ public class Grass : MonoBehaviour { if (QualitySettings.GetQualityLevel() < 5) { - gameObject.SetActive(false); + Destroy(gameObject); } } } \ No newline at end of file diff --git a/MachineManager.cs b/MachineManager.cs index 6a2c310..e86d02c 100644 --- a/MachineManager.cs +++ b/MachineManager.cs @@ -14,7 +14,6 @@ public class MachineManager : MonoBehaviour { if (busy == false && GetComponent().initMachines == true) { - Debug.Log("machine coroutine started"); machineUpdateCoroutine = StartCoroutine(MachineUpdateCoroutine()); } } diff --git a/MainMenu.cs b/MainMenu.cs index 19035a7..fcd2bc6 100644 --- a/MainMenu.cs +++ b/MainMenu.cs @@ -167,7 +167,7 @@ public class MainMenu : MonoBehaviour private void DownloadWorld() { string savePath = Path.Combine(Application.persistentDataPath, "SaveData"); - if (Application.isEditor) + if (Application.isEditor || UnityEngine.Debug.isDebugBuild) { savePath = Path.Combine(Application.persistentDataPath, "Downloads"); } diff --git a/PlayerController.cs b/PlayerController.cs index aea086c..4e04e46 100644 --- a/PlayerController.cs +++ b/PlayerController.cs @@ -856,7 +856,7 @@ public class PlayerController : MonoBehaviour string blockName = t.GetComponent().blockName.ToUpper(); if (blockName.Contains("STAIR")) { - GetComponent().AddForce(Vector3.up * 10000); + GetComponent().AddForce(Vector3.up * 1000); } } } @@ -866,7 +866,7 @@ public class PlayerController : MonoBehaviour string blockName = collision.gameObject.GetComponent().blockName.ToUpper(); if (blockName.Contains("STAIR")) { - GetComponent().AddForce(Vector3.up * 10000); + GetComponent().AddForce(Vector3.up * 1000); } } } diff --git a/PlayerGUI.cs b/PlayerGUI.cs index 4b79208..0f1a372 100644 --- a/PlayerGUI.cs +++ b/PlayerGUI.cs @@ -535,7 +535,7 @@ public class PlayerGUI : MonoBehaviour GUI.Label(guiCoordinates.sliderLabel2Rect, "Chunk Size " + "(" + gameManager.chunkSize + ")"); - int simSpeed = (int)(gameManager.simulationSpeed * 2500); + int simSpeed = (int)(gameManager.simulationSpeed * 5000); GUI.Label(guiCoordinates.sliderLabel3Rect, "Simulation Speed " + "(" + simSpeed + "%)"); AudioListener.volume = GUI.HorizontalSlider(guiCoordinates.optionsButton4Rect, AudioListener.volume, 0, 5); diff --git a/StateManager.cs b/StateManager.cs index 070f8bc..89ad441 100644 --- a/StateManager.cs +++ b/StateManager.cs @@ -9,6 +9,8 @@ public class StateManager : MonoBehaviour public bool dataSaved; public bool worldLoaded; public bool initMachines; + public bool finalMachineAddress; + public bool finalBlockAddress; public int progress; public int totalMachines; public int currentMachine; @@ -551,13 +553,32 @@ public class StateManager : MonoBehaviour //! Assigns ID to objects in the world. private void AssignIDs() { - if (initMachines == true && addressManager.machineIdCoroutineActive == false) + if (GetComponent().dataSaveRequested == true) { - machineIdCoroutine = StartCoroutine(addressManager.MachineIdCoroutine()); + if (finalMachineAddress == false || finalBlockAddress == false) + { + if (initMachines == true && addressManager.machineIdCoroutineActive == false) + { + machineIdCoroutine = StartCoroutine(addressManager.MachineIdCoroutine()); + } + if (worldLoaded == true && addressManager.blockIdCoroutineActive == false) + { + blockIdCoroutine = StartCoroutine(addressManager.BlockIdCoroutine()); + } + } } - if (worldLoaded == true && addressManager.blockIdCoroutineActive == false) + else { - blockIdCoroutine = StartCoroutine(addressManager.BlockIdCoroutine()); + finalMachineAddress = false; + finalBlockAddress = false; + if (initMachines == true && addressManager.machineIdCoroutineActive == false) + { + machineIdCoroutine = StartCoroutine(addressManager.MachineIdCoroutine()); + } + if (worldLoaded == true && addressManager.blockIdCoroutineActive == false) + { + blockIdCoroutine = StartCoroutine(addressManager.BlockIdCoroutine()); + } } } diff --git a/StorageComputer.cs b/StorageComputer.cs index 5d08acb..e8ea489 100644 --- a/StorageComputer.cs +++ b/StorageComputer.cs @@ -5,6 +5,7 @@ public class StorageComputer : Machine { public InventoryManager[] computerContainers; private List computerContainerList; + private int connectionAttempts; public string ID = "unassigned"; public bool powerON; public int bootTimer; @@ -45,7 +46,23 @@ public class StorageComputer : Machine if (bootTimer >= 5) { GetContainers(); - initialized = true; + bool foundContainer = false; + int containerCount = 0; + foreach (InventoryManager manager in computerContainers) + { + foundContainer |= computerContainers[containerCount] != null; + containerCount++; + } + if (foundContainer == false) + { + Reboot(); + connectionAttempts++; + initialized |= connectionAttempts >= 128; + } + else + { + initialized = true; + } bootTimer = 0; } } diff --git a/UniversalExtractor.cs b/UniversalExtractor.cs index 5af4281..6205f4f 100644 --- a/UniversalExtractor.cs +++ b/UniversalExtractor.cs @@ -134,7 +134,7 @@ public class UniversalExtractor : Machine else { connectionAttempts += 1; - if (connectionAttempts >= 120) + if (connectionAttempts >= 128) { connectionAttempts = 0; connectionFailed = true;