prog
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include "worldunit.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
void worldChunkPosAdd(worldchunkpos_t *pos, worldsubtile_t amt) {
|
||||
void worldChunkPosAdd(worldchunkpos_t *pos, const worldsubtile_t amt) {
|
||||
assertNotNull(pos, "Position pointer cannot be NULL");
|
||||
|
||||
/*
|
||||
@@ -29,12 +29,34 @@ void worldChunkPosAdd(worldchunkpos_t *pos, worldsubtile_t amt) {
|
||||
pos->tile = (uint8_t)(pos->tile + (uint8_t)tileCarry);
|
||||
}
|
||||
|
||||
void worldPosAddSubtile(worldpos_t *pos, const worldsubtile_t amt) {
|
||||
assertNotNull(pos, "Position pointer cannot be NULL");
|
||||
|
||||
// Same as worldChunkPosAdd but with chunk handling.
|
||||
int32_t shiftedTotal = (int32_t)pos->subtile + (int32_t)amt + 128;
|
||||
int32_t tileCarry = shiftedTotal >> 8; // divide by 256
|
||||
int32_t wrappedSubtile = shiftedTotal - (tileCarry << 8);
|
||||
pos->subtile = (int8_t)(wrappedSubtile - 128);
|
||||
int32_t newTile = (int32_t)pos->tile + (int32_t)tileCarry;
|
||||
int32_t chunkCarry = newTile / WORLD_CHUNK_SIZE;
|
||||
pos->tile = (uint8_t)(newTile % WORLD_CHUNK_SIZE);
|
||||
pos->chunk = (uint8_t)(pos->chunk + (uint8_t)chunkCarry);
|
||||
}
|
||||
|
||||
float_t worldChunkPosToF32(worldchunkpos_t pos, const uint8_t tileSize) {
|
||||
const float scaleFactor = (float)tileSize * (1.0f / 256.0f);
|
||||
float_t worldChunkPosToF32(const worldchunkpos_t pos, const uint8_t tileSize) {
|
||||
const float_t scaleFactor = (float_t)tileSize * (1.0f / 256.0f);
|
||||
return (
|
||||
(float)pos.tile * (float)tileSize + ((float)pos.subtile + 128.0f) *
|
||||
(float_t)pos.tile * (float_t)tileSize + ((float_t)pos.subtile + 128.0f) *
|
||||
scaleFactor
|
||||
);
|
||||
}
|
||||
|
||||
float_t worldPosToF32(const worldpos_t pos, const uint8_t tileSize) {
|
||||
const float_t scaleFactor = (float_t)tileSize * (1.0f / 256.0f);
|
||||
const float_t chunkFactor = WORLD_CHUNK_SIZE * (float_t)tileSize;
|
||||
return (
|
||||
(float_t)pos.chunk * chunkFactor +
|
||||
(float_t)pos.tile * (float_t)tileSize +
|
||||
((float_t)pos.subtile + 128.0f) * scaleFactor
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user