private unsafe void ParseExistsTable(byte* mh2oChunk, SMLiquidInstance* instance) { if (instance->existsTable != 0 && UseExistsTable(instance->liquidObjectId, instance->liquidType)) { var table = mh2oChunk + instance->existsTable; ExistsTable = new bool[TilesPerRow, TilesPerRow]; for (int x = MinX; x < MaxX; x++) { for (int y = MinY; y < MaxY; y++) { int index = y*(MaxX - MinX) + x; ExistsTable[y, x] = (table[index/8] & (1 << (index & 7))) != 0; } } } else { ExistsTable = FullExistsTable; } }
private unsafe void ParseHeightMap(byte* mh2oChunk, SMLiquidInstance* instance) { if (HasHeightMapData(instance) && UseExistsTable(instance->liquidObjectId, instance->liquidType)) { var data = (float*)(mh2oChunk + instance->data); HeightMap = new float[VerticesPerRow, VerticesPerRow]; for (int y = MinY; y <= MaxY; y++) { for (int x = MinX; x <= MaxX; x++) { int index = y*(MaxX - MinX + 1) + x; HeightMap[y, x] = data[index]; } } } else { HeightMap = ArrayUtil.MakeTwoDimensionalArray(instance->maxWaterHeight, VerticesPerRow, VerticesPerRow); } }
private static unsafe bool HasHeightMapData(SMLiquidInstance* instance) { return instance->data != 0; }