1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
TerrainManager = {
sectors = {},
load_sector = function(self, x, y)
local sector_id = string.format("sector_%d_%d", x, y)
if not self.sectors[sector_id] then
local proxy = collectionproxy.create("#sector_template")
collectionproxy.load_async(proxy, function()
local root = collectionproxy.get_root(proxy)
terrain.apply_heightmap(root, x, y)
collectionproxy.init(proxy)
self.sectors[sector_id] = proxy
end)
end
end,
update = function(self, player_pos)
local sector_size = 2048
local current_x = math.floor(player_pos.x / sector_size)
local current_y = math.floor(player_pos.y / sector_size)
-- 加载周围3x3区域
for dx=-1,1 do
for dy=-1,1 do
self:load_sector(current_x + dx, current_y + dy)
end
end
end
}
|