Example rendering

This commit is contained in:
2025-10-08 22:34:27 -05:00
parent 20cf016b06
commit fef31b9102
9 changed files with 133 additions and 10 deletions

39
src/rpg/world/worldunit.c Normal file
View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "worldunit.h"
#include "assert/assert.h"
void worldChunkPosAdd(
worldchunkpos_t *pos,
const worldsubtile_t amt
) {
int8_t a = pos->subtile; // current signed subtile
int8_t b = amt; // signed delta
uint8_t unsignedAdded = (uint8_t)a + (uint8_t)b; // well-defined wrap add
int8_t r = (int8_t)unsignedAdded; // result in signed domain
pos->subtile = r;
// Signed-overflow detection for a + b -> r:
// overflow if sign(a) == sign(b) and sign(r) != sign(a)
uint8_t ov = (uint8_t)((a ^ r) & (b ^ r)) >> 7; // 1 if overflow, else 0
// Direction of carry: +1 for b >= 0, -1 for b < 0 (computed branchlessly)
uint8_t neg = ((uint8_t)b) >> 7; // 0 if b>=0, 1 if b<0
int8_t dir = (int8_t)(1 - (neg << 1)); // +1 or -1
// Apply tile adjustment (mod-256 via uint8_t arithmetic)
pos->tile = (uint8_t)(pos->tile + (uint8_t)(ov * (uint8_t)dir));
}
float_t worldChunkPosToF32(
const worldchunkpos_t pos,
const uint8_t tileSize
) {
return (float_t)(pos.tile * tileSize) + ((float_t)pos.subtile / 256.0f);
}