@@ -340,8 +340,8 @@ static void gen_chunk_blocks(chunk_t* chunk)
340340 map_clear (& chunk -> lights );
341341 rand_get_blocks (chunk , chunk -> x , chunk -> z , set_chunk_block_function );
342342 save_get_blocks (chunk , chunk -> x , chunk -> z , set_chunk_block_function );
343+ CHECK (SDL_GetAtomicInt (& chunk -> block_state ) == JOB_STATE_RUNNING );
343344 SDL_SetAtomicInt (& chunk -> block_state , JOB_STATE_COMPLETED );
344- // Schedule because neighbors might have lights
345345 if (SDL_GetAtomicInt (& chunk -> voxel_state ) == JOB_STATE_REQUESTED )
346346 {
347347 SDL_SetAtomicInt (& chunk -> light_state , JOB_STATE_REQUESTED );
@@ -393,6 +393,15 @@ static void gen_chunk_voxels(chunk_t* chunks[3][3], cpu_buffer_t voxels[MESH_TYP
393393 SDL_SetAtomicInt (& chunk -> voxel_state , JOB_STATE_COMPLETED );
394394}
395395
396+ static void regen_chunk_voxels (int x , int z )
397+ {
398+ CHECK (!is_chunk_on_border (x , z ));
399+ chunk_t * chunks [3 ][3 ] = {0 };
400+ get_neighborhood (x , z , chunks );
401+ SDL_SetAtomicInt (& chunks [1 ][1 ]-> voxel_state , JOB_STATE_RUNNING );
402+ gen_chunk_voxels (chunks , cpu_voxels );
403+ }
404+
396405static void gen_chunk_lights (chunk_t * chunks [3 ][3 ], cpu_buffer_t * lights )
397406{
398407 chunk_t * chunk = chunks [1 ][1 ];
@@ -962,15 +971,6 @@ block_t world_get_block(const int position[3])
962971 }
963972}
964973
965- static void gen_voxels_sync (int x , int z )
966- {
967- CHECK (!is_chunk_on_border (x , z ));
968- chunk_t * chunks [3 ][3 ] = {0 };
969- get_neighborhood (x , z , chunks );
970- SDL_SetAtomicInt (& chunks [1 ][1 ]-> voxel_state , JOB_STATE_RUNNING );
971- gen_chunk_voxels (chunks , cpu_voxels );
972- }
973-
974974void world_set_block (const int position [3 ], block_t block )
975975{
976976 if (position [1 ] < 0 || position [1 ] >= CHUNK_HEIGHT )
@@ -1002,22 +1002,22 @@ void world_set_block(const int position[3], block_t block)
10021002 int local_z = position [2 ];
10031003 world_to_chunk (chunk , & local_x , & local_y , & local_z );
10041004 block_t old_block = set_chunk_block (chunk , position [0 ], position [1 ], position [2 ], block );
1005- gen_voxels_sync (chunk_x , chunk_z );
1005+ regen_chunk_voxels (chunk_x , chunk_z );
10061006 if (local_x == 0 )
10071007 {
1008- gen_voxels_sync (chunk_x - 1 , chunk_z );
1008+ regen_chunk_voxels (chunk_x - 1 , chunk_z );
10091009 }
10101010 else if (local_x == CHUNK_WIDTH - 1 )
10111011 {
1012- gen_voxels_sync (chunk_x + 1 , chunk_z );
1012+ regen_chunk_voxels (chunk_x + 1 , chunk_z );
10131013 }
10141014 if (local_z == 0 )
10151015 {
1016- gen_voxels_sync (chunk_x , chunk_z - 1 );
1016+ regen_chunk_voxels (chunk_x , chunk_z - 1 );
10171017 }
10181018 else if (local_z == CHUNK_WIDTH - 1 )
10191019 {
1020- gen_voxels_sync (chunk_x , chunk_z + 1 );
1020+ regen_chunk_voxels (chunk_x , chunk_z + 1 );
10211021 }
10221022 chunk_t * neighborhood [3 ][3 ] = {0 };
10231023 get_neighborhood (chunk_x , chunk_z , neighborhood );
0 commit comments