Optimization and bug fixes.

This commit is contained in:
Droog71 2021-05-21 02:15:50 -04:00
parent 7f12057f62
commit 70211525a9
10 changed files with 102 additions and 16 deletions

View File

@ -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;
}
}
}

View File

@ -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<Vector3> 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<StateManager>().saving == false && GetComponent<StateManager>().AddressManagerBusy() == false)
{
Debug.Log("Saving world...");
UnityEngine.Debug.Log("Saving world...");
GetComponent<StateManager>().SaveData();
dataSaveRequested = false;
}
else if (GetComponent<StateManager>().AddressManagerBusy() == true)
{
if (GetComponent<GameManager>().simulationSpeed != 0.1f)
{
userSimSpeed = GetComponent<GameManager>().simulationSpeed;
}
GetComponent<GameManager>().simulationSpeed = 0.1f;
}
else
{
GetComponent<GameManager>().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<StateManager>().saving == false)
{
Debug.Log("Requesting save operation...");
UnityEngine.Debug.Log("Requesting save operation...");
dataSaveRequested = true;
blocksCombined = false;
}

View File

@ -7,7 +7,7 @@ public class Grass : MonoBehaviour
{
if (QualitySettings.GetQualityLevel() < 5)
{
gameObject.SetActive(false);
Destroy(gameObject);
}
}
}

View File

@ -14,7 +14,6 @@ public class MachineManager : MonoBehaviour
{
if (busy == false && GetComponent<StateManager>().initMachines == true)
{
Debug.Log("machine coroutine started");
machineUpdateCoroutine = StartCoroutine(MachineUpdateCoroutine());
}
}

View File

@ -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");
}

View File

@ -856,7 +856,7 @@ public class PlayerController : MonoBehaviour
string blockName = t.GetComponent<ModBlock>().blockName.ToUpper();
if (blockName.Contains("STAIR"))
{
GetComponent<Rigidbody>().AddForce(Vector3.up * 10000);
GetComponent<Rigidbody>().AddForce(Vector3.up * 1000);
}
}
}
@ -866,7 +866,7 @@ public class PlayerController : MonoBehaviour
string blockName = collision.gameObject.GetComponent<ModBlock>().blockName.ToUpper();
if (blockName.Contains("STAIR"))
{
GetComponent<Rigidbody>().AddForce(Vector3.up * 10000);
GetComponent<Rigidbody>().AddForce(Vector3.up * 1000);
}
}
}

View File

@ -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);

View File

@ -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<GameManager>().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());
}
}
}

View File

@ -5,6 +5,7 @@ public class StorageComputer : Machine
{
public InventoryManager[] computerContainers;
private List<InventoryManager> 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;
}
}

View File

@ -134,7 +134,7 @@ public class UniversalExtractor : Machine
else
{
connectionAttempts += 1;
if (connectionAttempts >= 120)
if (connectionAttempts >= 128)
{
connectionAttempts = 0;
connectionFailed = true;