{"id":48591817,"url":"https://github.com/nsmryan/zig_shadowcasting","last_synced_at":"2026-04-08T20:02:15.724Z","repository":{"id":56741574,"uuid":"522261351","full_name":"nsmryan/zig_shadowcasting","owner":"nsmryan","description":"A Zig translation of the algorithm found here: https://www.albertford.com/shadowcasting/","archived":false,"fork":false,"pushed_at":"2022-08-16T14:42:59.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-04-07T22:34:15.695Z","etag":null,"topics":["roguelike","shadowcasting","zig","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nsmryan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-07T16:13:06.000Z","updated_at":"2022-08-13T17:58:12.000Z","dependencies_parsed_at":"2022-08-16T01:10:23.358Z","dependency_job_id":null,"html_url":"https://github.com/nsmryan/zig_shadowcasting","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/nsmryan/zig_shadowcasting","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_shadowcasting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_shadowcasting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_shadowcasting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_shadowcasting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsmryan","download_url":"https://codeload.github.com/nsmryan/zig_shadowcasting/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_shadowcasting/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31571601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["roguelike","shadowcasting","zig","ziglang"],"created_at":"2026-04-08T20:02:15.020Z","updated_at":"2026-04-08T20:02:15.692Z","avatar_url":"https://github.com/nsmryan.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zig Symmetric Shadow Casting\n\nThis repository contains a Zig translation of the [Rust translation](https://github.com/nsmryan/shadowcasting) \nof this [Python algorithm](https://www.albertford.com/shadowcasting/).\nThe best source for information on this algorithm is the Python blog post\nby Albert Ford, which is a really beautiful post and worth reading.\n\n\nThe algorithm itself is a very nice field of view algorithm that can be used\nin a roguelike for determining visiblity, with the nice properties described\nin the original post. I have found this algorithm to give good results, and\nI use it with additional laying on top in my [own roguelike](https://github.com/nsmryan/RustRoguelike).\n\n\nThe Zig version is slightly different from the Rust and Python. I tried a series of\ndifferent designs before landing on a simplification of the other implementations which\nis less generic but easier to use in Zig.\n\n\n## Example Use\n\nThis repository defines a simple Pos (position) type which is just a pair of 'isize's. This can be \nconverted to an from user types if you already have a position type in use.\n\n\nTo use this field of view function, simply call 'compute_fov' with the starting location, the generic map structure,\nan ArrayList which will be used to mark visible locations, and a function pointer which takes a position and the map,\nand returns a boolean indicating whether the given position is blocked on the map.\n\nThis keeps the map type and the concept of 'blocking' tiles in the user's control. However, the return type (the visible tiles)\nis always an ArrayList(Pos), unlike the Rust and Python where these are generic.\n\n```zig\n    // The user must define a function which takes a Pos and the user's map type, and returns\n    // whether the given position is blocked in the map.\n    fn is_blocking_fn(pos: Pos, tiles: []const []const isize) bool {\n        return !inside_map(pos, tiles) or tiles[@intCast(usize, pos.y)][@intCast(usize, pos.x)] == 1;\n    }\n\n    // This 'use_fov' function is an example of using 'compute_fov'.\n    fn use_fov() void {\n        const origin = Pos.new(3, 0);\n\n        // The map, in this case an array of slices, each containing an isize. If the isize is 1, the tile\n        // is blocked. If the isize is 0 it is not blocked.\n        const tiles = [_][]const isize{ \u0026.{ 0, 0, 0, 0, 0, 0, 0 }, \u0026.{ 1, 1, 1, 1, 0, 0, 0 }, \u0026.{ 0, 0, 0, 1, 0, 0, 0 }, \u0026.{ 0, 0, 0, 1, 0, 0, 0 } };\n\n        // Create the arraylist to store visible tiles.\n        var allocator = std.heap.GeneralPurposeAllocator(.{}){};\n        var visible = ArrayList(Pos).init(allocator.allocator());\n        visible.deinit();\n\n        // Compute FoV using the symmetric shadow casting algorithm.\n        try compute_fov(origin, tiles[0..], \u0026visible, is_blocking_fn);\n        \n        // Now the 'visible' array list contains a series of Pos values indicating which positions were\n        // visible.\n    }\n```\n\nNote that the 'compute_fov' function takes a pointer to an ArrayList instead of creating the ArrayList\nitself in order to allow the user to re-use an existing ArrayList, avoiding additional allocations.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsmryan%2Fzig_shadowcasting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsmryan%2Fzig_shadowcasting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsmryan%2Fzig_shadowcasting/lists"}