10 years ago by fourstar07
I'm currently working on a topdown, stealth style game that involves field of vision cones for my enemy entities. The field of vision is working perfectly thanks to the wonderful write up at redblobgames on visibility.
Currently, I'm converting each solid tile in the collision map into a polygon which is then broken into individual line segments that I can use as wall endpoints to cast rays at when performing my visibility cone updates. This works perfectly fine, but is not very efficient. For example, a horizontal wall going from tile (0,0) on the collision map to tile (19,0) will create 20 separate polygons totaling 80 endpoints that will be checked during a visibility cycle. The exact same results could be achieved by checking against a single polygon spanning the entire horizontal width. I'm not encountering any performance issues at the moment, but that's a significant amount of improvement that I'd like to address sooner than later.
My question is whether anyone has tackled converting and merging collision maps to polygons or even continuous line segments from the in game collision map array. I could take what I currently have (which produces a few thousand line segments for all the collision map tiles) and compare line segment endpoints and slopes and combine them as necessary. This would work and I'm not incredibly hard pressed for the efficiency of line segment generation since it's only calculated once on game load, but I feel there must be a better way.
Any thoughts?
Currently, I'm converting each solid tile in the collision map into a polygon which is then broken into individual line segments that I can use as wall endpoints to cast rays at when performing my visibility cone updates. This works perfectly fine, but is not very efficient. For example, a horizontal wall going from tile (0,0) on the collision map to tile (19,0) will create 20 separate polygons totaling 80 endpoints that will be checked during a visibility cycle. The exact same results could be achieved by checking against a single polygon spanning the entire horizontal width. I'm not encountering any performance issues at the moment, but that's a significant amount of improvement that I'd like to address sooner than later.
My question is whether anyone has tackled converting and merging collision maps to polygons or even continuous line segments from the in game collision map array. I could take what I currently have (which produces a few thousand line segments for all the collision map tiles) and compare line segment endpoints and slopes and combine them as necessary. This would work and I'm not incredibly hard pressed for the efficiency of line segment generation since it's only calculated once on game load, but I feel there must be a better way.
Any thoughts?