@@ -1094,6 +1094,95 @@ const VoxelArea block_pad[] = {
1094
1094
VoxelArea (v3s16 (0 , 0 , 0 ), v3s16 (0 , 15 , 15 )) // X-
1095
1095
};
1096
1096
1097
+ /* !
1098
+ * The common part of bulk light updates - it is always executed.
1099
+ * The procedure takes the nodes that should be unlit, and the
1100
+ * full modified area.
1101
+ *
1102
+ * The procedure handles the correction of all lighting except
1103
+ * direct sunlight spreading.
1104
+ *
1105
+ * \param minblock least coordinates of the changed area in block
1106
+ * coordinates
1107
+ * \param maxblock greatest coordinates of the changed area in block
1108
+ * coordinates
1109
+ * \param unlight the first queue is for day light, the second is for
1110
+ * night light. Contains all nodes on the borders that need to be unlit.
1111
+ * \param relight the first queue is for day light, the second is for
1112
+ * night light. Contains nodes that were not modified, but got sunlight
1113
+ * because the changes.
1114
+ * \param modified_blocks the procedure adds all modified blocks to
1115
+ * this map
1116
+ */
1117
+ void finish_bulk_light_update (Map *map, mapblock_v3 minblock,
1118
+ mapblock_v3 maxblock, UnlightQueue unlight[2 ], ReLightQueue relight[2 ],
1119
+ std::map<v3s16, MapBlock*> *modified_blocks)
1120
+ {
1121
+ INodeDefManager *ndef = map->getNodeDefManager ();
1122
+ // dummy boolean
1123
+ bool is_valid;
1124
+
1125
+ // --- STEP 1: Do unlighting
1126
+
1127
+ for (size_t bank = 0 ; bank < 2 ; bank++) {
1128
+ LightBank b = banks[bank];
1129
+ unspread_light (map, ndef, b, unlight[bank], relight[bank],
1130
+ *modified_blocks);
1131
+ }
1132
+
1133
+ // --- STEP 2: Get all newly inserted light sources
1134
+
1135
+ // For each block:
1136
+ for (s16 b_x = minblock.X ; b_x <= maxblock.X ; b_x++)
1137
+ for (s16 b_y = minblock.Y ; b_y <= maxblock.Y ; b_y++)
1138
+ for (s16 b_z = minblock.Z ; b_z <= maxblock.Z ; b_z++) {
1139
+ v3s16 blockpos (b_x, b_y, b_z);
1140
+ MapBlock *block = map->getBlockNoCreateNoEx (blockpos);
1141
+ if (!block || block->isDummy ())
1142
+ // Skip not existing blocks
1143
+ continue ;
1144
+ // For each node in the block:
1145
+ for (s32 x = 0 ; x < MAP_BLOCKSIZE; x++)
1146
+ for (s32 z = 0 ; z < MAP_BLOCKSIZE; z++)
1147
+ for (s32 y = 0 ; y < MAP_BLOCKSIZE; y++) {
1148
+ v3s16 relpos (x, y, z);
1149
+ MapNode node = block->getNodeNoCheck (x, y, z, &is_valid);
1150
+ const ContentFeatures &f = ndef->get (node);
1151
+ // For each light bank
1152
+ for (size_t b = 0 ; b < 2 ; b++) {
1153
+ LightBank bank = banks[b];
1154
+ u8 light = f.param_type == CPT_LIGHT ?
1155
+ node.getLightNoChecks (bank, &f):
1156
+ f.light_source ;
1157
+ if (light > 1 )
1158
+ relight[b].push (light, relpos, blockpos, block, 6 );
1159
+ } // end of banks
1160
+ } // end of nodes
1161
+ } // end of blocks
1162
+
1163
+ // --- STEP 3: do light spreading
1164
+
1165
+ // For each light bank:
1166
+ for (size_t b = 0 ; b < 2 ; b++) {
1167
+ LightBank bank = banks[b];
1168
+ // Sunlight is already initialized.
1169
+ u8 maxlight = (b == 0 ) ? LIGHT_MAX : LIGHT_SUN;
1170
+ // Initialize light values for light spreading.
1171
+ for (u8 i = 0 ; i <= maxlight; i++) {
1172
+ const std::vector<ChangingLight> &lights = relight[b].lights [i];
1173
+ for (std::vector<ChangingLight>::const_iterator it = lights.begin ();
1174
+ it < lights.end (); ++it) {
1175
+ MapNode n = it->block ->getNodeNoCheck (it->rel_position ,
1176
+ &is_valid);
1177
+ n.setLight (bank, i, ndef);
1178
+ it->block ->setNodeNoCheck (it->rel_position , n);
1179
+ }
1180
+ }
1181
+ // Spread lights.
1182
+ spread_light (map, ndef, bank, relight[b], *modified_blocks);
1183
+ }
1184
+ }
1185
+
1097
1186
void blit_back_with_light (ServerMap *map, MMVManip *vm,
1098
1187
std::map<v3s16, MapBlock*> *modified_blocks)
1099
1188
{
@@ -1187,65 +1276,10 @@ void blit_back_with_light(ServerMap *map, MMVManip *vm,
1187
1276
1188
1277
vm->blitBackAll (modified_blocks, true );
1189
1278
1190
- // --- STEP 4: Do unlighting
1191
-
1192
- for (size_t bank = 0 ; bank < 2 ; bank++) {
1193
- LightBank b = banks[bank];
1194
- unspread_light (map, ndef, b, unlight[bank], relight[bank],
1195
- *modified_blocks);
1196
- }
1197
-
1198
- // --- STEP 5: Get all newly inserted light sources
1279
+ // --- STEP 4: Finish light update
1199
1280
1200
- // For each block:
1201
- for (s16 b_x = minblock.X ; b_x <= maxblock.X ; b_x++)
1202
- for (s16 b_y = minblock.Y ; b_y <= maxblock.Y ; b_y++)
1203
- for (s16 b_z = minblock.Z ; b_z <= maxblock.Z ; b_z++) {
1204
- v3s16 blockpos (b_x, b_y, b_z);
1205
- MapBlock *block = map->getBlockNoCreateNoEx (blockpos);
1206
- if (!block || block->isDummy ())
1207
- // Skip not existing blocks
1208
- continue ;
1209
- // For each node in the block:
1210
- for (s32 x = 0 ; x < MAP_BLOCKSIZE; x++)
1211
- for (s32 z = 0 ; z < MAP_BLOCKSIZE; z++)
1212
- for (s32 y = 0 ; y < MAP_BLOCKSIZE; y++) {
1213
- v3s16 relpos (x, y, z);
1214
- MapNode node = block->getNodeNoCheck (x, y, z, &is_valid);
1215
- const ContentFeatures &f = ndef->get (node);
1216
- // For each light bank
1217
- for (size_t b = 0 ; b < 2 ; b++) {
1218
- LightBank bank = banks[b];
1219
- u8 light = f.param_type == CPT_LIGHT ?
1220
- node.getLightNoChecks (bank, &f):
1221
- f.light_source ;
1222
- if (light > 1 )
1223
- relight[b].push (light, relpos, blockpos, block, 6 );
1224
- } // end of banks
1225
- } // end of nodes
1226
- } // end of blocks
1227
-
1228
- // --- STEP 6: do light spreading
1229
-
1230
- // For each light bank:
1231
- for (size_t b = 0 ; b < 2 ; b++) {
1232
- LightBank bank = banks[b];
1233
- // Sunlight is already initialized.
1234
- u8 maxlight = (b == 0 ) ? LIGHT_MAX : LIGHT_SUN;
1235
- // Initialize light values for light spreading.
1236
- for (u8 i = 0 ; i <= maxlight; i++) {
1237
- const std::vector<ChangingLight> &lights = relight[b].lights [i];
1238
- for (std::vector<ChangingLight>::const_iterator it = lights.begin ();
1239
- it < lights.end (); ++it) {
1240
- MapNode n = it->block ->getNodeNoCheck (it->rel_position ,
1241
- &is_valid);
1242
- n.setLight (bank, i, ndef);
1243
- it->block ->setNodeNoCheck (it->rel_position , n);
1244
- }
1245
- }
1246
- // Spread lights.
1247
- spread_light (map, ndef, bank, relight[b], *modified_blocks);
1248
- }
1281
+ finish_bulk_light_update (map, minblock, maxblock, unlight, relight,
1282
+ modified_blocks);
1249
1283
}
1250
1284
1251
1285
VoxelLineIterator::VoxelLineIterator (
0 commit comments