public void SaveChunkBlocks(TerrainChunk chunk) { _ = Time.RealTime; Terrain terrain = m_subsystemTerrain.Terrain; int num = chunk.Origin.X >> 4; int num2 = chunk.Origin.Y >> 4; try { bool flag = false; if (m_chunkOffsets.TryGetValue(new Point2(num, num2), out int value)) { m_stream.Seek(value, SeekOrigin.Begin); } else { flag = true; value = (int)m_stream.Length; m_stream.Seek(value, SeekOrigin.Begin); } WriteChunkHeader(m_stream, num, num2); int num3 = 0; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { int num4 = TerrainChunk.CalculateCellIndex(i, 0, j); for (int k = 0; k < 256; k++) { int cellValueFast = chunk.GetCellValueFast(num4++); m_buffer[num3++] = (byte)cellValueFast; m_buffer[num3++] = (byte)(cellValueFast >> 8); } } } m_stream.Write(m_buffer, 0, 131072); num3 = 0; for (int l = 0; l < 16; l++) { for (int m = 0; m < 16; m++) { int shaftValue = terrain.GetShaftValue(l + chunk.Origin.X, m + chunk.Origin.Y); m_buffer[num3++] = (byte)shaftValue; m_buffer[num3++] = (byte)(shaftValue >> 8); m_buffer[num3++] = (byte)(shaftValue >> 16); m_buffer[num3++] = (byte)(shaftValue >> 24); } } m_stream.Write(m_buffer, 0, 1024); if (flag) { m_stream.Flush(); int num5 = m_chunkOffsets.Count % 65536 * 3 * 4; m_stream.Seek(num5, SeekOrigin.Begin); WriteInt(m_stream, num); WriteInt(m_stream, num2); WriteInt(m_stream, value); m_chunkOffsets[new Point2(num, num2)] = value; } } catch (Exception e) { Log.Error(ExceptionManager.MakeFullErrorMessage($"Error writing data for chunk ({num},{num2}).", e)); } _ = Time.RealTime; }
public override void Update() { if (!m_loadingStarted) { m_loadingStarted = true; } else { if (m_loadingFinished) { return; } double realTime = Time.RealTime; while (!m_pauseLoading && m_index < m_loadActions.Count) { try { m_loadActions[m_index++](); } catch (Exception ex) { Log.Error("Loading error. Reason: " + ex.Message); if (!m_loadingErrorsSuppressed) { m_pauseLoading = true; DialogsManager.ShowDialog(ScreensManager.RootWidget, new MessageDialog("Loading Error", ExceptionManager.MakeFullErrorMessage(ex), LanguageControl.Get("Usual", "ok"), "Suppress", delegate(MessageDialogButton b) { switch (b) { case MessageDialogButton.Button1: m_pauseLoading = false; break; case MessageDialogButton.Button2: m_loadingErrorsSuppressed = true; break; } })); } } if (Time.RealTime - realTime > 0.1) { break; } } if (m_index >= m_loadActions.Count) { m_loadingFinished = true; AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f); ScreensManager.SwitchScreen("MainMenu"); } } }
public unsafe void SaveChunkBlocks(TerrainChunk chunk) { _ = Time.RealTime; int num = chunk.Origin.X >> 4; int num2 = chunk.Origin.Y >> 4; try { bool flag = false; if (m_chunkOffsets.TryGetValue(new Point2(num, num2), out long value)) { m_stream.Seek(value, SeekOrigin.Begin); } else { flag = true; value = m_stream.Length; m_stream.Seek(value, SeekOrigin.Begin); } WriteChunkHeader(m_stream, num, num2); try { fixed(byte *ptr = &m_buffer[0]) { int *ptr2 = (int *)ptr; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { int num3 = TerrainChunk.CalculateCellIndex(i, 0, j); int num4 = 0; while (num4 < 256) { *ptr2 = chunk.GetCellValueFast(num3); num4++; num3++; ptr2++; } } } } } finally { } m_stream.Write(m_buffer, 0, 262144); try { fixed(byte *ptr = &m_buffer[0]) { int *ptr3 = (int *)ptr; for (int k = 0; k < 16; k++) { for (int l = 0; l < 16; l++) { *ptr3 = m_terrain.GetShaftValue(k + chunk.Origin.X, l + chunk.Origin.Y); ptr3++; } } } } finally { } m_stream.Write(m_buffer, 0, 1024); if (flag) { m_stream.Flush(); int num5 = m_chunkOffsets.Count % 65536 * 3 * 4; m_stream.Seek(num5, SeekOrigin.Begin); WriteInt(m_stream, num); WriteInt(m_stream, num2); WriteInt(m_stream, m_chunkOffsets.Count); m_chunkOffsets[new Point2(num, num2)] = value; } m_stream.Flush(); } catch (Exception e) { Log.Error(ExceptionManager.MakeFullErrorMessage($"Error writing data for chunk ({num},{num2}).", e)); } _ = Time.RealTime; }
public unsafe bool LoadChunkBlocks(TerrainChunk chunk) { bool result = false; int num = chunk.Origin.X >> 4; int num2 = chunk.Origin.Y >> 4; try { if (!m_chunkOffsets.TryGetValue(new Point2(num, num2), out long value)) { return(result); } _ = Time.RealTime; m_stream.Seek(value, SeekOrigin.Begin); ReadChunkHeader(m_stream); m_stream.Read(m_buffer, 0, 262144); try { fixed(byte *ptr = &m_buffer[0]) { int *ptr2 = (int *)ptr; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { int num3 = TerrainChunk.CalculateCellIndex(i, 0, j); int num4 = 0; while (num4 < 256) { chunk.SetCellValueFast(num3, *ptr2); num4++; num3++; ptr2++; } } } } } finally { } m_stream.Read(m_buffer, 0, 1024); try { fixed(byte *ptr = &m_buffer[0]) { int *ptr3 = (int *)ptr; for (int k = 0; k < 16; k++) { for (int l = 0; l < 16; l++) { m_terrain.SetShaftValue(k + chunk.Origin.X, l + chunk.Origin.Y, *ptr3); ptr3++; } } } } finally { } result = true; _ = Time.RealTime; return(result); } catch (Exception e) { Log.Error(ExceptionManager.MakeFullErrorMessage($"Error loading data for chunk ({num},{num2}).", e)); return(result); } }
public static void Get(string address, Dictionary <string, string> parameters, Dictionary <string, string> headers, CancellableProgress progress, Action <byte[]> success, Action <Exception> failure) { MemoryStream targetStream = default(MemoryStream); Exception e = default(Exception); Task.Run(async delegate { _ = 3; try { progress = (progress ?? new CancellableProgress()); if (!IsInternetConnectionAvailable()) { throw new InvalidOperationException("Internet connection is unavailable."); } using (HttpClient client = new HttpClient()) { System.Uri requestUri = (parameters != null && parameters.Count > 0) ? new System.Uri($"{address}?{UrlParametersToString(parameters)}") : new System.Uri(address); client.DefaultRequestHeaders.Referrer = new System.Uri(address); if (headers != null) { foreach (KeyValuePair <string, string> header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } } HttpResponseMessage responseMessage = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, progress.CancellationToken); await VerifyResponse(responseMessage); long?contentLength = responseMessage.Content.Headers.ContentLength; progress.Total = contentLength.GetValueOrDefault(); using (Stream responseStream = await responseMessage.Content.ReadAsStreamAsync()) { targetStream = new MemoryStream(); try { long written = 0L; byte[] buffer = new byte[1024]; int num; do { num = await responseStream.ReadAsync(buffer, 0, buffer.Length, progress.CancellationToken); if (num > 0) { targetStream.Write(buffer, 0, num); written += num; progress.Completed = written; } }while (num > 0); if (success != null) { Dispatcher.Dispatch(delegate { success(targetStream.ToArray()); }); } } finally { if (targetStream != null) { ((IDisposable)targetStream).Dispose(); } } } } } catch (Exception ex) { e = ex; Log.Error(ExceptionManager.MakeFullErrorMessage(e)); if (failure != null) { Dispatcher.Dispatch(delegate { failure(e); }); } } }); }
public override void Update() { try { m_stateMachine.Update(); } catch (Exception e) { ScreensManager.SwitchScreen(ScreensManager.PreviousScreen); DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get(fName, 1), ExceptionManager.MakeFullErrorMessage(e), LanguageControl.Get("Usual", "ok"), null, null)); } }