|
@@ -4,8 +4,9 @@ var Chunk = preload("res://chunk.tscn")
|
|
|
onready var Player = $"../Player"
|
|
|
|
|
|
var resolution = 512
|
|
|
-var radius = 1737.4
|
|
|
-var renderDistance = 1
|
|
|
+var scaleFact = 1000
|
|
|
+var radius = 1737.4*scaleFact
|
|
|
+var renderDistance = 0.2
|
|
|
|
|
|
var chunkIndex = {}
|
|
|
|
|
@@ -17,14 +18,29 @@ func _ready():
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
func _process(delta):
|
|
|
var playerSpos = Player.getSpos()
|
|
|
- var playerRoundSpos = playerSpos.round()
|
|
|
- var playerChunkPos = Vector2(int(playerRoundSpos.x), int(playerRoundSpos.y))
|
|
|
+ var playerChunkPos = Vector2(int(playerSpos.x), int(playerSpos.y))
|
|
|
var playerInterChunkPos = Vector2(playerSpos.x - playerChunkPos.x, playerSpos.y - playerChunkPos.y)
|
|
|
|
|
|
- for i in [Vector2(1,0),Vector2(1,1),Vector2(0,1),Vector2(-1,0),Vector2(0,-1),Vector2(-1,-1),Vector2(1,-1),Vector2(-1,1)]:
|
|
|
- var dist = Vector2(playerSpos.x, playerSpos.y).distance_to(playerChunkPos+i+Vector2(0.5,0.5))
|
|
|
- if dist < renderDistance:
|
|
|
- add_chunk(playerChunkPos+i)
|
|
|
+ var dir = Vector2()
|
|
|
+
|
|
|
+ if playerInterChunkPos.x < renderDistance:
|
|
|
+ dir = dir+Vector2(-1,0)
|
|
|
+ elif playerInterChunkPos.x > 1-renderDistance:
|
|
|
+ dir = dir+Vector2(1,0)
|
|
|
+
|
|
|
+ if playerInterChunkPos.y < renderDistance:
|
|
|
+ dir = dir+Vector2(0,-1)
|
|
|
+ elif playerInterChunkPos.y > 1-renderDistance:
|
|
|
+ dir = dir+Vector2(0,1)
|
|
|
+
|
|
|
+ add_chunk(playerChunkPos+dir)
|
|
|
+ add_chunk(playerChunkPos+Vector2(0,dir.y))
|
|
|
+ add_chunk(playerChunkPos+Vector2(dir.x,0))
|
|
|
+
|
|
|
+ #for i in [Vector2(1,0),Vector2(1,1),Vector2(0,1),Vector2(-1,0),Vector2(0,-1),Vector2(-1,-1),Vector2(1,-1),Vector2(-1,1)]:
|
|
|
+ # var dist = Vector2(playerSpos.x, playerSpos.y).distance_to(playerChunkPos+i)
|
|
|
+ # if dist < renderDistance:
|
|
|
+ # add_chunk(playerChunkPos+i)
|
|
|
|
|
|
|
|
|
func add_chunk(chunkPos = Vector2()):
|
|
@@ -33,7 +49,7 @@ func add_chunk(chunkPos = Vector2()):
|
|
|
if chunkIndex.has(lon) and chunkIndex[lon].has(lat):
|
|
|
return
|
|
|
var chunk = Chunk.instance()
|
|
|
- chunk.setParams(lat,lat+1,lon,lon+1,resolution,radius)
|
|
|
+ chunk.setParams(lat,lat+1,lon,lon+1,resolution,radius,scaleFact)
|
|
|
#moontile.scale=Vector3(1000,1000,1000)
|
|
|
.add_child(chunk)
|
|
|
if not chunkIndex.has(lon):
|