Chunking system, save/load chunks #1

Merged
chrisbell merged 8 commits from chunking into master 2025-02-28 14:40:37 +00:00
4 changed files with 9 additions and 22 deletions
Showing only changes of commit f9ea78d62e - Show all commits

File diff suppressed because one or more lines are too long

BIN
game/game

Binary file not shown.

View File

@ -20,8 +20,9 @@ main :: proc() {
rl.SetTargetFPS(60) rl.SetTargetFPS(60)
player = { player = {
position = {CELL_SIZE * 5, CELL_SIZE * 5}, position = {CELL_SIZE * 500, CELL_SIZE * 500},
camera = { camera = {
zoom = 2, zoom = 2,
target = {player.position.x + (CELL_SIZE / 2), player.position.y + (CELL_SIZE / 2)}, target = {player.position.x + (CELL_SIZE / 2), player.position.y + (CELL_SIZE / 2)},
@ -35,6 +36,9 @@ main :: proc() {
world = create_world("test_world") world = create_world("test_world")
load_nearby_chunks(&world, player.position) load_nearby_chunks(&world, player.position)
set_tile(&world, tree_tile, {400,400})
save_world(&world) save_world(&world)

View File

@ -7,7 +7,7 @@ import "core:path/filepath"
import "core:mem" import "core:mem"
CELL_SIZE :: 16 CELL_SIZE :: 16
CHUNK_SIZE :: 5 CHUNK_SIZE :: 32
WORLD_DATA_PATH :: "data/worlds" WORLD_DATA_PATH :: "data/worlds"
World :: struct { World :: struct {
@ -111,22 +111,6 @@ load_chunk :: proc(pos:Vec2i, w:^World) -> Chunk {
mem.copy(transmute([^]u8)&chunk.position.y, &data[offset], size_of(int)) mem.copy(transmute([^]u8)&chunk.position.y, &data[offset], size_of(int))
offset += size_of(int) offset += size_of(int)
// // Load Tiles
// for row in &chunk.tiles {
// for &tile in row {
// mem.copy(transmute([^]u8)tile.tilemap_pos.x, &data[offset], size_of(int))
// offset += size_of(int)
// mem.copy(transmute([^]u8)tile.tilemap_pos.y, &data[offset], size_of(int))
// offset += size_of(int)
// //Color
// tile.color = {}
//
// }
// }
// Load tiles // Load tiles
for row_index := 0; row_index < len(chunk.tiles); row_index += 1 { for row_index := 0; row_index < len(chunk.tiles); row_index += 1 {
for tile_index := 0; tile_index < len(chunk.tiles[row_index]); tile_index += 1 { for tile_index := 0; tile_index < len(chunk.tiles[row_index]); tile_index += 1 {
@ -169,11 +153,11 @@ generate_chunk :: proc(pos:Vec2i) -> Chunk {
for x in 0..<CHUNK_SIZE { for x in 0..<CHUNK_SIZE {
for y in 0..<CHUNK_SIZE { for y in 0..<CHUNK_SIZE {
chunk.tiles[x][y] = Tile { chunk.tiles[x][y] = Tile {
type = .FOLIAGE, type = .NOTHING,
tilemap_pos = {0,2}, tilemap_pos = {0,0},
interaction = .NOTHING, interaction = .NOTHING,
resource = .NOTHING, resource = .NOTHING,
color = {0,255,0,255} color = {0,0,0,255}
} }
} }
} }