private HeapFree ( int hHeap, int flags, void block ) : bool | ||
hHeap | int | |
flags | int | |
block | void | |
Résultat | bool |
private void ReinitializeTilesArray(ushort width, ushort height) { if (_tiles != null) { Memory.HeapFree(_tiles); } _tiles = (Tile *)Memory.HeapAlloc((_width = width) * (_height = height) * sizeof(Tile)); }
private void Dispose(bool disposing) { if (!disposing) { Memory.HeapFree(_tiles); _tiles = null; } }
private void RecreateMiniMap() { if (_miniMap != null) { Memory.HeapFree(_miniMap); } if (_width <= MINI_MAP_SIZE && _height <= MINI_MAP_SIZE) { MiniMapWidth = _width; MiniMapHeight = _height; } else if (_width > _height) { MiniMapWidth = MINI_MAP_SIZE; MiniMapHeight = (ushort)((float)_height / _width * MINI_MAP_SIZE); } else { MiniMapHeight = MINI_MAP_SIZE; MiniMapWidth = (ushort)((float)_width / _height * MINI_MAP_SIZE); } MiniMapSize = new ShortSize(MiniMapWidth, MiniMapHeight); int miniMapArea = MiniMapWidth * MiniMapHeight; _miniMap = (byte *)Memory.HeapAlloc(miniMapArea / 2); float xCoef = (float)_width / MiniMapWidth; float yCoef = (float)_height / MiniMapHeight; for (int i = 0; i < miniMapArea; i++) { ushort mapX = (ushort)(i * xCoef % _width); ushort mapY = (ushort)(i * xCoef * yCoef / _width); Tile *tile = &_tiles[mapY * _width + mapX]; byte pxl = (byte)((*tile).Type == TileType.Wall ? 1 : 0); if (i % 2 == 0) { _miniMap[i / 2] = (byte)(pxl << 4); } else { _miniMap[i / 2] = (byte)(_miniMap[i / 2] | pxl); } } }
internal void TestGameMapPerf() { const ushort mapWidth = 1000, mapHeight = 1000; int count = mapWidth * mapHeight; HRTimer timer = HRTimer.CreateAndStart(); #if UNSAFE_ARRAY int sizeOfTile = Marshal.SizeOf(typeof(Tile)); Tile *pTiles = (Tile *)Memory.HeapAlloc(count * sizeOfTile); #else Tile[,] aTiles = new Tile[MapWidth, MapHeight]; #endif System.Console.WriteLine(timer.StopWatch()); timer = HRTimer.CreateAndStart(); for (int i = 0; i < count; i++) { #if !UNSAFE_ARRAY fixed(Tile *pTiles = aTiles) #endif { pTiles[i].Type = TileType.Wall; pTiles[i].TypeIndex = 100; } } System.Console.WriteLine(timer.StopWatch()); #if UNSAFE_ARRAY Memory.HeapFree(pTiles); #endif using (ServerMap map = new ServerMap(mapWidth, mapHeight, 0)) { timer = HRTimer.CreateAndStart(); for (ushort y = 0; y < mapHeight; y++) { for (ushort x = 0; x < mapWidth; x++) { Tile *tile = map[x, y]; (*tile).Type = TileType.Nothing; (*tile).TypeIndex = 1; } } System.Console.WriteLine(timer.StopWatch()); } }
public void AppendMiniMapData(byte[] data, ShortSize size) { if (_miniMapData != null) { Memory.HeapFree(_miniMapData); } _miniMapSize = size; int miniMapArea = size.Width * size.Height; _miniMapData = (byte *)Memory.HeapAlloc(miniMapArea / 2); fixed(byte *bData = data) { int pos = 0, pxlCnt, curIdx = 0; Serializer.Read(bData, out pxlCnt, ref pos); for (int i = 0; i < pxlCnt; i++) { byte rleMark; ushort seriesLength; Serializer.Read(bData, out rleMark, ref pos); if ((rleMark | 0x80) == rleMark) { byte rleMark2; Serializer.Read(bData, out rleMark2, ref pos); seriesLength = (ushort)((rleMark & ~0x80) << 8 | rleMark2); } else { seriesLength = rleMark; } byte pxl; Serializer.Read(bData, out pxl, ref pos); int maxIdx = curIdx + seriesLength; for (; curIdx < maxIdx; curIdx++) { _miniMapData[curIdx] = pxl; } } } }
private unsafe void BtnGenerateLabyrinthClick(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; FractalType type = (FractalType)cbLabyrinthType.SelectedItem; BasisTypes basis = (BasisTypes)cbLabyrinthBasis.SelectedItem; InterpTypes interp = (InterpTypes)cbLabyrinthInterp.SelectedItem; int? octaves = !string.IsNullOrEmpty(tbLabyrinthOctaves.Text) ? int.Parse(tbLabyrinthOctaves.Text) : (int?)null; double?frequency = !string.IsNullOrEmpty(tbLabyrinthFrequency.Text) ? double.Parse(tbLabyrinthFrequency.Text) : (double?)null; double?angle = !string.IsNullOrEmpty(tbLabyrinthAngle.Text) ? double.Parse(tbLabyrinthAngle.Text) : (double?)null; double?lacunarity = !string.IsNullOrEmpty(tbLabyrinthLacunarity.Text) ? double.Parse(tbLabyrinthLacunarity.Text) : (double?)null; _labOldSeed = cbLabyrinthRnd.Checked ? (uint?)Environment.TickCount : _labOldSeed; ModuleBase moduleBase = new Fractal(type, basis, interp, octaves, frequency, _labOldSeed, angle, lacunarity); if (chkLabyrinthAC.Checked) { double acLow = double.Parse(tbLabyrinthACLow.Text); double acHigh = double.Parse(tbLabyrinthACHigh.Text); CombinerTypes combType = (CombinerTypes)cbLabyrinthACCombine.SelectedItem; AutoCorrect correct = new AutoCorrect(moduleBase, acLow, acHigh); moduleBase = new Combiner(combType, correct, moduleBase); } // Bias bias = new Bias(moduleBase, 0.01); // Gradient gradient = new Gradient(0, 0, 50, 100); // moduleBase = new TranslatedDomain(moduleBase, gradient, bias); if (chkLabyrinthSel.Checked) { double selLow = double.Parse(tbLabyrinthSelLow.Text); double selHigh = double.Parse(tbLabyrinthSelHigh.Text); double selThreshold = double.Parse(tbLabyrinthSelThreshold.Text); double?selFalloff = !string.IsNullOrEmpty(tbLabyrinthSelFalloff.Text) ? double.Parse(tbLabyrinthSelFalloff.Text) : (double?)null; moduleBase = new Select(moduleBase, selLow, selHigh, selThreshold, selFalloff); } if (pbLabyrinth.Image != null) { pbLabyrinth.Image.Dispose(); } ushort width = 500, height = 500; Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb); BitmapData data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat); byte *pRoughMap = (byte *)Memory.HeapAlloc(width * height); Parallel.For(0, height, y => { int *row = (int *)data.Scan0 + (y * data.Stride) / 4; Parallel.For(0, width, x => { double p = (double)x / width; double q = (double)y / height; double val = moduleBase.Get(p, q); pRoughMap[y * width + x] = (byte)Math.Abs(val - 1); Color color = Color.Black.Lerp(Color.White, val); row[x] = color.ToArgb(); }); }); using (ServerMap map = new ServerMap(width, height, 0, pRoughMap)) { map.SaveToFile("RK.save"); } Memory.HeapFree(pRoughMap); bitmap.UnlockBits(data); pbLabyrinth.Image = bitmap; Cursor = DefaultCursor; }