{"id":13663144,"url":"https://github.com/Vengarioth/ChunkTest","last_synced_at":"2025-04-25T13:31:50.867Z","repository":{"id":70271726,"uuid":"162576296","full_name":"Vengarioth/ChunkTest","owner":"Vengarioth","description":"Test/Example Chunked Tilemap for Unity ECS","archived":false,"fork":false,"pushed_at":"2018-12-20T12:24:47.000Z","size":31,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-10T15:45:18.639Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/Vengarioth.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-12-20T12:23:59.000Z","updated_at":"2024-01-19T14:24:58.000Z","dependencies_parsed_at":"2023-02-22T06:46:12.168Z","dependency_job_id":null,"html_url":"https://github.com/Vengarioth/ChunkTest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vengarioth%2FChunkTest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vengarioth%2FChunkTest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vengarioth%2FChunkTest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vengarioth%2FChunkTest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vengarioth","download_url":"https://codeload.github.com/Vengarioth/ChunkTest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250824984,"owners_count":21493374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-08-02T05:02:19.071Z","updated_at":"2025-04-25T13:31:45.850Z","avatar_url":"https://github.com/Vengarioth.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# ChunkTest\r\n\r\nThis repository contains an idea how to implement chunks using the Unity Job and ECS tech stack.\r\n\r\n## Idea\r\n\r\nThe system handles a fixed number of chunks in memory and loads/unloads before or after gameplay simulation as needed. Like with entities removing a chunk during simulation is not allowed. There is an example `LivenessManager` which performs those actions in the project.\r\n\r\nThe `Map` holds a primary `NativeArray\u003cChunkData\u003e` of chunk information and as many secondary `NativeArray\u003cT\u003e` as needed to store per-tile data. A Tile is very much like an Entity and per-tile data are very much like components.\r\n\r\nThe `ChunkData` contains an index into the per-tile arrays pointing to the first tile that belongs to the chunk, the following `CHUNK_WIDTH * CHUNK_HEIGHT` tiles also belong to that chunk. `ChunkData` also has an index to the chunks to the left, top, right and bottom of it in the `NativeArray\u003cChunkData\u003e` (or -1 if there is no chunk). This effectively forms a _2D linked list_ where a System can perform lookups into the 4 cardinal directions by chasing the indices in `ChunkData`. At worst a system should have to look into the data of 4 different chunks, if the entity is positioned near a corner.\r\n\r\nAn Entity should always have an updated index on which chunk it is before dispatching ECS systems, so that jobs can use that index as a starting point for queries into the tile data. If the entity chunk index is set as a `SharedComponentData`, the ECS should group entities with the same value next to each other, so that chunks remain hot in memory [source](https://forum.unity.com/threads/can-sharedcomponentdata-be-used-for-an-efficient-spacial-chunk-system.601183/#post-4019524).\r\n\r\n## Code Outline\r\n\r\n```csharp\r\npublic class Map\r\n{\r\n    // Chunk Information\r\n    public NativeArray\u003cChunkData\u003e Chunks;\r\n\r\n    // Per-tile collision data\r\n    public NativeArray\u003cCollisionData\u003e CollisionData;\r\n\r\n    // Per-tile custom data\r\n    public NativeArray\u003cMyOtherTileData\u003e OtherTileData;\r\n}\r\n\r\npublic struct ChunkData\r\n{\r\n    // Index into per-tile data arrays\r\n    public int TileIndex;\r\n\r\n    // Index into chunk to the left in ChunkData\r\n    public int Left;\r\n\r\n    // Index into chunk to the top in ChunkData\r\n    public int Top;\r\n\r\n    // Index into chunk to the right in ChunkData\r\n    public int Right;\r\n\r\n    // Index into chunk to the bottom in ChunkData\r\n    public int Bottom;\r\n}\r\n\r\npublic struct CollisionData\r\n{\r\n    /*\r\n     * Bits:\r\n     * 0 - Collides Left\r\n     * 1 - Collides Top\r\n     * 2 - Collides Right\r\n     * 3 - Collides Bottom\r\n     */\r\n    public byte CollisionMask;\r\n}\r\n\r\npublic struct MyOtherTileData\r\n{\r\n    public float MyOtherTileValue;\r\n}\r\n```\r\n\r\n## Resources\r\n\r\n* [RustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West](https://www.youtube.com/watch?v=aKLntZcp27M)\r\n\r\n## Licence\r\n\r\nMIT, except for some art assets by [kenney.nl](https://kenney.nl/)  (see licence in folders)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVengarioth%2FChunkTest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVengarioth%2FChunkTest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVengarioth%2FChunkTest/lists"}