Rename a couple of Atlas variables

Sometimes names can be too long
This commit is contained in:
Marc Di Luzio 2020-06-28 11:01:01 +01:00
parent 9bb91920c9
commit e5ee0eaece

View file

@ -38,11 +38,11 @@ type Atlas struct {
// This is intentionally not a 2D array so it can be expanded in all directions // This is intentionally not a 2D array so it can be expanded in all directions
Chunks []Chunk `json:"chunks"` Chunks []Chunk `json:"chunks"`
// CurrentSizeInChunks is the current width/height of the atlas in chunks // CurrentSize is the current width/height of the atlas in chunks
CurrentSizeInChunks vector.Vector `json:"currentSizeInChunks"` CurrentSize vector.Vector `json:"currentSize"`
// WorldOriginInChunkSpace represents the location of [0,0] in chunk space // WorldOrigin represents the location of the [0,0] world space point in terms of the allotted current chunks
WorldOriginInChunkSpace vector.Vector `json:"worldOriginInChunkSpace"` WorldOrigin vector.Vector `json:"worldOrigin"`
// ChunkSize is the x/y dimensions of each square chunk // ChunkSize is the x/y dimensions of each square chunk
ChunkSize int `json:"chunksize"` ChunkSize int `json:"chunksize"`
@ -52,10 +52,10 @@ type Atlas struct {
func NewAtlas(chunkSize int) Atlas { func NewAtlas(chunkSize int) Atlas {
// Start up with one chunk // Start up with one chunk
a := Atlas{ a := Atlas{
ChunkSize: chunkSize, ChunkSize: chunkSize,
Chunks: make([]Chunk, 1), Chunks: make([]Chunk, 1),
CurrentSizeInChunks: vector.Vector{X: 1, Y: 1}, CurrentSize: vector.Vector{X: 1, Y: 1},
WorldOriginInChunkSpace: vector.Vector{X: 0, Y: 0}, WorldOrigin: vector.Vector{X: 0, Y: 0},
} }
// Initialise the first chunk // Initialise the first chunk
a.Chunks[0].SpawnContent(chunkSize) a.Chunks[0].SpawnContent(chunkSize)
@ -125,7 +125,7 @@ func (a *Atlas) worldSpaceToChunkSpace(v vector.Vector) vector.Vector {
// Convert to chunk space coordinate // Convert to chunk space coordinate
chunkSpaceOrigin := chunkOrigin.Divided(a.ChunkSize) chunkSpaceOrigin := chunkOrigin.Divided(a.ChunkSize)
// Shift it by our current chunk origin // Shift it by our current chunk origin
chunkIndexOrigin := chunkSpaceOrigin.Added(a.WorldOriginInChunkSpace) chunkIndexOrigin := chunkSpaceOrigin.Added(a.WorldOrigin)
return chunkIndexOrigin return chunkIndexOrigin
} }
@ -134,7 +134,7 @@ func (a *Atlas) worldSpaceToChunkSpace(v vector.Vector) vector.Vector {
func (a *Atlas) chunkSpaceToWorldSpace(v vector.Vector) vector.Vector { func (a *Atlas) chunkSpaceToWorldSpace(v vector.Vector) vector.Vector {
// Shift it by the current chunk origin // Shift it by the current chunk origin
shifted := v.Added(a.WorldOriginInChunkSpace.Negated()) shifted := v.Added(a.WorldOrigin.Negated())
// Multiply out by chunk size // Multiply out by chunk size
return shifted.Multiplied(a.ChunkSize) return shifted.Multiplied(a.ChunkSize)
@ -146,7 +146,7 @@ func (a *Atlas) chunkOriginInChunkSpace(chunk int) vector.Vector {
chunkOrigin := a.chunkToChunkSpace(chunk) chunkOrigin := a.chunkToChunkSpace(chunk)
// Shift it by the current chunk origin // Shift it by the current chunk origin
return chunkOrigin.Added(a.WorldOriginInChunkSpace.Negated()) return chunkOrigin.Added(a.WorldOrigin.Negated())
} }
// chunkOriginInWorldSpace gets the chunk origin for a given chunk index // chunkOriginInWorldSpace gets the chunk origin for a given chunk index
@ -161,20 +161,20 @@ func (a *Atlas) chunkOriginInWorldSpace(chunk int) vector.Vector {
// chunkSpaceToChunk converts from chunk space to the chunk // chunkSpaceToChunk converts from chunk space to the chunk
func (a *Atlas) chunkSpaceToChunk(v vector.Vector) int { func (a *Atlas) chunkSpaceToChunk(v vector.Vector) int {
// Along the coridor and up the stair // Along the coridor and up the stair
return (v.Y * a.CurrentSizeInChunks.X) + v.X return (v.Y * a.CurrentSize.X) + v.X
} }
// chunkToChunkSpace returns the chunk space coord for the chunk // chunkToChunkSpace returns the chunk space coord for the chunk
func (a *Atlas) chunkToChunkSpace(chunk int) vector.Vector { func (a *Atlas) chunkToChunkSpace(chunk int) vector.Vector {
return vector.Vector{ return vector.Vector{
X: maths.Pmod(chunk, a.CurrentSizeInChunks.Y), X: maths.Pmod(chunk, a.CurrentSize.Y),
Y: (chunk / a.CurrentSizeInChunks.X), Y: (chunk / a.CurrentSize.X),
} }
} }
func (a *Atlas) getExtents() (min vector.Vector, max vector.Vector) { func (a *Atlas) getExtents() (min vector.Vector, max vector.Vector) {
min = a.WorldOriginInChunkSpace.Negated() min = a.WorldOrigin.Negated()
max = min.Added(a.CurrentSizeInChunks) max = min.Added(a.CurrentSize)
return return
} }
@ -192,7 +192,7 @@ func (a *Atlas) worldSpaceToChunkWithGrow(v vector.Vector) int {
// Calculate the new origin and the new size // Calculate the new origin and the new size
origin := min origin := min
size := a.CurrentSizeInChunks size := a.CurrentSize
// If we need to shift the origin back // If we need to shift the origin back
originDiff := origin.Added(v.Negated()) originDiff := origin.Added(v.Negated())
@ -216,10 +216,10 @@ func (a *Atlas) worldSpaceToChunkWithGrow(v vector.Vector) int {
// Set up the new size and origin // Set up the new size and origin
newAtlas := Atlas{ newAtlas := Atlas{
ChunkSize: a.ChunkSize, ChunkSize: a.ChunkSize,
WorldOriginInChunkSpace: origin.Negated(), WorldOrigin: origin.Negated(),
CurrentSizeInChunks: size, CurrentSize: size,
Chunks: make([]Chunk, size.X*size.Y), Chunks: make([]Chunk, size.X*size.Y),
} }
// Copy all old chunks into the new atlas // Copy all old chunks into the new atlas