@@ -3,7 +3,7 @@ pragma solidity >=0.8.24;
3
3
4
4
import { BiomesTest } from "./BiomesTest.sol " ;
5
5
6
- import { TerrainLib, VERSION_PADDING, BIOME_PADDING } from "../src/systems/libraries/TerrainLib.sol " ;
6
+ import { TerrainLib, VERSION_PADDING, BIOME_PADDING, SURFACE_PADDING } from "../src/systems/libraries/TerrainLib.sol " ;
7
7
import { ObjectTypeId } from "../src/ObjectTypeId.sol " ;
8
8
import { ObjectTypes } from "../src/ObjectTypes.sol " ;
9
9
import { Vec3, vec3 } from "../src/Vec3.sol " ;
@@ -51,19 +51,19 @@ contract TerrainTest is BiomesTest {
51
51
function testGetBlockIndex () public {
52
52
Vec3 coord = vec3 (1 , 2 , 2 );
53
53
uint256 index = TerrainLib._getBlockIndex (coord);
54
- assertEq (index, 1 * 256 + 2 * 16 + 2 + VERSION_PADDING + BIOME_PADDING);
54
+ assertEq (index, 1 * 256 + 2 * 16 + 2 + VERSION_PADDING + BIOME_PADDING + SURFACE_PADDING );
55
55
56
56
coord = vec3 (16 , 17 , 18 );
57
57
index = TerrainLib._getBlockIndex (coord);
58
- assertEq (index, 0 * 256 + 1 * 16 + 2 + VERSION_PADDING + BIOME_PADDING);
58
+ assertEq (index, 0 * 256 + 1 * 16 + 2 + VERSION_PADDING + BIOME_PADDING + SURFACE_PADDING );
59
59
60
60
coord = vec3 (- 1 , - 2 , - 3 );
61
61
index = TerrainLib._getBlockIndex (coord);
62
- assertEq (index, 15 * 256 + 14 * 16 + 13 + VERSION_PADDING + BIOME_PADDING);
62
+ assertEq (index, 15 * 256 + 14 * 16 + 13 + VERSION_PADDING + BIOME_PADDING + SURFACE_PADDING );
63
63
64
64
coord = vec3 (16 , - 17 , - 18 );
65
65
index = TerrainLib._getBlockIndex (coord);
66
- assertEq (index, 0 * 256 + 15 * 16 + 14 + VERSION_PADDING + BIOME_PADDING);
66
+ assertEq (index, 0 * 256 + 15 * 16 + 14 + VERSION_PADDING + BIOME_PADDING + SURFACE_PADDING );
67
67
}
68
68
69
69
function testGetChunkSalt () public {
@@ -78,7 +78,7 @@ contract TerrainTest is BiomesTest {
78
78
assertEq (salt, bytes32 (uint256 (uint96 (bytes12 (abi.encodePacked (chunkCoord))))));
79
79
}
80
80
81
- function _getTestChunk () internal pure returns (uint8 [][][] memory chunk ) {
81
+ function _getTestChunk () internal pure returns (uint8 [][][] memory chunk , uint8 biome , bool isSurface ) {
82
82
chunk = new uint8 [][][](uint256 (int256 (CHUNK_SIZE)));
83
83
for (uint256 x = 0 ; x < uint256 (int256 (CHUNK_SIZE)); x++ ) {
84
84
chunk[x] = new uint8 [][](uint256 (int256 (CHUNK_SIZE)));
@@ -89,12 +89,13 @@ contract TerrainTest is BiomesTest {
89
89
}
90
90
}
91
91
}
92
+ biome = 1 ;
93
+ isSurface = true ;
92
94
}
93
95
94
96
function testExploreChunk () public {
95
- uint8 [][][] memory chunk = _getTestChunk ();
96
- uint8 inputBiome = 1 ;
97
- bytes memory encodedChunk = encodeChunk (inputBiome, chunk);
97
+ (uint8 [][][] memory chunk , uint8 inputBiome , bool inputIsSurface ) = _getTestChunk ();
98
+ bytes memory encodedChunk = encodeChunk (inputBiome, inputIsSurface, chunk);
98
99
Vec3 chunkCoord = vec3 (0 , 0 , 0 );
99
100
bytes32 [] memory merkleProof = new bytes32 [](0 );
100
101
@@ -123,6 +124,16 @@ contract TerrainTest is BiomesTest {
123
124
124
125
assertEq (biome, inputBiome);
125
126
127
+ startGasReport ("TerrainLib.isSurfaceChunk (non-root) " );
128
+ bool isSurface = TerrainLib.isSurfaceChunk (coord.toChunkCoord ());
129
+ endGasReport ();
130
+
131
+ startGasReport ("TerrainLib.isSurfaceChunk (root) " );
132
+ isSurface = TerrainLib.isSurfaceChunk (coord.toChunkCoord (), worldAddress);
133
+ endGasReport ();
134
+
135
+ assertEq (isSurface, inputIsSurface);
136
+
126
137
for (int32 x = 0 ; x < CHUNK_SIZE; x++ ) {
127
138
for (int32 y = 0 ; y < CHUNK_SIZE; y++ ) {
128
139
for (int32 z = 0 ; z < CHUNK_SIZE; z++ ) {
@@ -138,9 +149,8 @@ contract TerrainTest is BiomesTest {
138
149
}
139
150
140
151
function testExploreChunk_Fail_ChunkAlreadyExplored () public {
141
- uint8 [][][] memory chunk = _getTestChunk ();
142
- uint8 biome = 1 ;
143
- bytes memory encodedChunk = encodeChunk (biome, chunk);
152
+ (uint8 [][][] memory chunk , uint8 biome , bool isSurface ) = _getTestChunk ();
153
+ bytes memory encodedChunk = encodeChunk (biome, isSurface, chunk);
144
154
Vec3 chunkCoord = vec3 (0 , 0 , 0 );
145
155
IWorld (worldAddress).exploreChunk (chunkCoord, encodedChunk, new bytes32 [](0 ));
146
156
@@ -149,9 +159,8 @@ contract TerrainTest is BiomesTest {
149
159
}
150
160
151
161
function testGetBlockType () public {
152
- uint8 [][][] memory chunk = _getTestChunk ();
153
- uint8 biome = 1 ;
154
- bytes memory encodedChunk = encodeChunk (biome, chunk);
162
+ (uint8 [][][] memory chunk , uint8 biome , bool isSurface ) = _getTestChunk ();
163
+ bytes memory encodedChunk = encodeChunk (biome, isSurface, chunk);
155
164
156
165
// Test we can get the block type for a voxel in the chunk
157
166
Vec3 chunkCoord = vec3 (0 , 0 , 0 );
0 commit comments