save bug fix

ascii 10 ist ein line feed. Einen line feed aus einer datei dann zurück umzuwandeln ist nicht möglich. Daher jeder ascii wert +32 am nur zeichen zu speichern.
This commit is contained in:
brausjonas
2022-05-17 16:51:35 +02:00
parent 45aae55fe2
commit f23fc16f0d
4 changed files with 21 additions and 7 deletions
@@ -101,7 +101,7 @@ public class Client
{ {
for (int z = 0; z < Data.chunkWidth; z++) for (int z = 0; z < Data.chunkWidth; z++)
{ {
blocks[x, y, z] = data[i]; blocks[x, y, z] = (byte)(data[i] - 32);
i++; i++;
} }
} }
+16 -2
View File
@@ -30,6 +30,7 @@ public class World : MonoBehaviour
//chunks //chunks
private Chunk[,] chunks; private Chunk[,] chunks;
private Queue<ChunkCoord> chunksToUpdate = new Queue<ChunkCoord>(); private Queue<ChunkCoord> chunksToUpdate = new Queue<ChunkCoord>();
private Queue<ChunkCoord> chunksToUpdate1 = new Queue<ChunkCoord>();
private List<Chunk> lastActiveChunks = new List<Chunk>(); private List<Chunk> lastActiveChunks = new List<Chunk>();
//blocks //blocks
@@ -43,6 +44,12 @@ public class World : MonoBehaviour
private void Start() private void Start()
{ {
//get default information //get default information
if (PlayerPrefs.HasKey("viewDistance"))
{
Data.viewDistance = PlayerPrefs.GetInt("viewDistance");
}
name = PlayerPrefs.GetString("userName"); name = PlayerPrefs.GetString("userName");
ip = PlayerPrefs.GetString("serverIP"); ip = PlayerPrefs.GetString("serverIP");
port = int.Parse(PlayerPrefs.GetString("port")); port = int.Parse(PlayerPrefs.GetString("port"));
@@ -74,6 +81,13 @@ public class World : MonoBehaviour
ChunkCoord chunk = chunksToUpdate.Dequeue(); ChunkCoord chunk = chunksToUpdate.Dequeue();
chunks[chunk.x, chunk.z].Update(); chunks[chunk.x, chunk.z].Update();
} }
//update 1 chunk in list
if (chunksToUpdate1.Count > 0)
{
ChunkCoord chunk = chunksToUpdate1.Dequeue();
chunks[chunk.x, chunk.z].Update();
}
//create 1 player in list //create 1 player in list
if (playersToCreate.Count > 0) if (playersToCreate.Count > 0)
@@ -125,7 +139,7 @@ public class World : MonoBehaviour
{ {
List<Chunk> checkList = new List<Chunk>(); List<Chunk> checkList = new List<Chunk>();
chunksToUpdate.Clear(); chunksToUpdate1.Clear();
for (int x = playerChunk.x - Data.viewDistance; x < playerChunk.x + Data.viewDistance; x++) for (int x = playerChunk.x - Data.viewDistance; x < playerChunk.x + Data.viewDistance; x++)
{ {
@@ -138,7 +152,7 @@ public class World : MonoBehaviour
} }
if(!chunks[x, z].active) if(!chunks[x, z].active)
{ {
chunksToUpdate.Enqueue(new ChunkCoord(x, z)); chunksToUpdate1.Enqueue(new ChunkCoord(x, z));
} }
checkList.Add(chunks[x, z]); checkList.Add(chunks[x, z]);
} }
+1 -1
View File
@@ -313,7 +313,7 @@ public class Server
{ {
for (int z = 0; z < Data.chunkWidth; z++) for (int z = 0; z < Data.chunkWidth; z++)
{ {
send[i] = world.chunks[xChunk, zChunk].blocks[x, y, z]; send[i] = (byte)(world.chunks[xChunk, zChunk].blocks[x, y, z] + 32);
i++; i++;
} }
} }
+3 -3
View File
@@ -57,7 +57,7 @@ public class World : MonoBehaviour
{ {
for (int z = 0; z < Data.chunkWidth; z++) for (int z = 0; z < Data.chunkWidth; z++)
{ {
chunks[xChunk, zChunk].blocks[x, y, z] = save[i]; chunks[xChunk, zChunk].blocks[x, y, z] = (byte)(save[i] - 32);
i++; i++;
} }
} }
@@ -289,7 +289,7 @@ public class World : MonoBehaviour
{ {
for (int z = 0; z < Data.chunkWidth; z++) for (int z = 0; z < Data.chunkWidth; z++)
{ {
save[i] = chunks[xChunk, zChunk].blocks[x, y, z]; save[i] = (byte)(chunks[xChunk, zChunk].blocks[x, y, z] + 32);
i++; i++;
} }
} }
@@ -300,6 +300,6 @@ public class World : MonoBehaviour
} }
} }
writer.Close(); writer.Close();
Console.WriteLine("world saved! (world.save) \n"); Console.WriteLine("world saved! (save.world) \n");
} }
} }