@@ -230,9 +230,13 @@ void DoUnVision(Point position, uint8_t radius)
230230 }
231231}
232232
233- void DoVision (Point position, uint8_t radius, MapExplorationType doAutomap, bool visible)
233+ void DoVision (Point position, uint8_t radius,
234+ tl::function_ref<void (Point)> markVisibleFn,
235+ tl::function_ref<void(Point)> markTransparentFn,
236+ tl::function_ref<bool(Point)> passesLightFn,
237+ tl::function_ref<bool(Point)> inBoundsFn)
234238{
235- DoVisionFlags (position, doAutomap, visible );
239+ markVisibleFn (position);
236240
237241 // Adjustment to a ray length to ensure all rays lie on an
238242 // accurate circle
@@ -251,7 +255,7 @@ void DoVision(Point position, uint8_t radius, MapExplorationType doAutomap, bool
251255 const auto &relRayPoint = VisionRays[j][k];
252256 // Calculate the next point on a ray in the quadrant
253257 Point rayPoint = position + relRayPoint * quadrant;
254- if (!InDungeonBounds (rayPoint))
258+ if (!inBoundsFn (rayPoint))
255259 break ;
256260
257261 // We've cast an approximated ray on an integer 2D
@@ -280,28 +284,46 @@ void DoVision(Point position, uint8_t radius, MapExplorationType doAutomap, bool
280284 Displacement adjacent1 = { -quadrant.deltaX , 0 };
281285 Displacement adjacent2 = { 0 , -quadrant.deltaY };
282286
283- bool passesLight = (TileAllowsLight (rayPoint + adjacent1) || TileAllowsLight (rayPoint + adjacent2));
287+ bool passesLight = (passesLightFn (rayPoint + adjacent1) || passesLightFn (rayPoint + adjacent2));
284288 if (!passesLight)
285289 // Diagonally adjacent tiles do not pass the
286290 // light further, we are done with this ray
287291 break ;
288292 }
289- DoVisionFlags (rayPoint, doAutomap, visible );
293+ markVisibleFn (rayPoint);
290294
291- bool passesLight = TileAllowsLight (rayPoint);
295+ bool passesLight = passesLightFn (rayPoint);
292296 if (!passesLight)
293297 // Tile does not pass the light further, we are
294298 // done with this ray
295299 break ;
296300
297- int8_t trans = dTransVal[rayPoint.x ][rayPoint.y ];
298- if (trans != 0 )
299- TransList[trans] = true ;
301+ markTransparentFn (rayPoint);
300302 }
301303 }
302304 }
303305}
304306
307+ void DoVision (Point position, uint8_t radius, MapExplorationType doAutomap, bool visible)
308+ {
309+ auto markVisibleFn = [doAutomap, visible](Point rayPoint) {
310+ DoVisionFlags (rayPoint, doAutomap, visible);
311+ };
312+ auto markTransparentFn = [](Point rayPoint) {
313+ int8_t trans = dTransVal[rayPoint.x ][rayPoint.y ];
314+ if (trans != 0 )
315+ TransList[trans] = true ;
316+ };
317+ auto passesLightFn = [](Point rayPoint) {
318+ return TileAllowsLight (rayPoint);
319+ };
320+ auto inBoundsFn = [](Point rayPoint) {
321+ return InDungeonBounds (rayPoint);
322+ };
323+
324+ DoVision (position, radius, markVisibleFn, markTransparentFn, passesLightFn, inBoundsFn);
325+ }
326+
305327tl::expected<void , std::string> LoadTrns ()
306328{
307329 RETURN_IF_ERROR (LoadFileInMemWithStatus (" plrgfx\\ infra.trn" , InfravisionTable));
0 commit comments