Handle stairs better

This commit is contained in:
2025-11-11 23:40:50 -06:00
parent 84593867dc
commit 542aeadf0f
4 changed files with 67 additions and 21 deletions

View File

@@ -22,7 +22,7 @@
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

37
assets/map/map/1_0_0.json Normal file
View File

@@ -0,0 +1,37 @@
{
"tiles": [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0
]
}

View File

@@ -51,12 +51,19 @@ void sceneMapGetWorldPosition(const worldpos_t pos, vec3 outPosition) {
outPosition[0] = pos.x * TILE_WIDTH;
outPosition[1] = pos.y * TILE_HEIGHT;
outPosition[2] = pos.z * TILE_DEPTH;
// Handle stair tiles.
tile_t tile = mapGetTile(pos);
if(tileIsStairs(tile)) {
outPosition[2] += TILE_DEPTH / 2.0f;
}
}
void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
assertNotNull(entity, "Entity cannot be NULL");
assertNotNull(outPosition, "Output position cannot be NULL");
// Get position
sceneMapGetWorldPosition(entity->position, outPosition);
// Add animation offset(s)
@@ -64,20 +71,12 @@ void sceneMapEntityGetPosition(const entity_t *entity, vec3 outPosition) {
case ENTITY_ANIM_WALK:
float_t animPercentage = entity->animTime / ENTITY_ANIM_WALK_DURATION;
// Get facing rel, we know we moved from the inverse direction.
vec3 lastPosition;
sceneMapGetWorldPosition(entity->lastPosition, lastPosition);
// Add tile size times percentage to posMin/max
vec3 offset = {
(
(float_t)entity->position.x - (float_t)entity->lastPosition.x
) * TILE_WIDTH * -animPercentage,
(
(float_t)entity->position.y - (float_t)entity->lastPosition.y
) * TILE_HEIGHT * -animPercentage,
(
(float_t)entity->position.z - (float_t)entity->lastPosition.z
) * TILE_DEPTH * -animPercentage
};
vec3 offset;
glm_vec3_sub(outPosition, lastPosition, offset);
glm_vec3_scale(offset, -animPercentage, offset);
glm_vec3_add(outPosition, offset, outPosition);
break;

View File

@@ -14,21 +14,21 @@ TILE_WIDTH = 16.0
TILE_HEIGHT = 16.0
TILE_DEPTH = 11.36
def processTile(tileIndex, x=0, y=0, z=0):
def processTile(tileIndex, x=0, y=0, z=0, chunkX=0, chunkY=0, chunkZ=0):
vertices = []
indices = []
tileType = tileIndex
# Placement X, Y, Z
px = x * TILE_WIDTH
py = y * TILE_HEIGHT
pz = z * TILE_DEPTH
px = (x * TILE_WIDTH) + (chunkX * CHUNK_WIDTH * TILE_WIDTH)
py = (y * TILE_HEIGHT) + (chunkY * CHUNK_HEIGHT * TILE_HEIGHT)
pz = (z * TILE_DEPTH) + (chunkZ * CHUNK_DEPTH * TILE_DEPTH)
if tileIndex == 0:
# Tile 0, nothing
return None
elif tileIndex == 2:
elif tileIndex == 5:
# Tile 2, ramp up
color = (255,0,0)
vertices = [
@@ -44,7 +44,7 @@ def processTile(tileIndex, x=0, y=0, z=0):
else:
# Determine color for checkerboard pattern
if tileIndex == 1:
color = (0, 255, 0)
color = (255, 255, 255)
else:
color = (0, 0, 255)
@@ -73,7 +73,17 @@ def processChunk(path):
with open(path, 'r') as f:
inData = json.load(f)
# Filename must contain chunk coordinates as X_Y_Z
fileName = os.path.basename(path)
nameParts = os.path.splitext(fileName)[0].split('_')
if len(nameParts) != 3:
print(f"Error: Chunk filename {fileName} does not contain valid chunk coordinates.")
sys.exit(1)
chunk = {
'chunkX': int(nameParts[0]),
'chunkY': int(nameParts[1]),
'chunkZ': int(nameParts[2]),
'tiles': [0] * CHUNK_TILE_COUNT,
'models': []
}
@@ -97,7 +107,7 @@ def processChunk(path):
z = i // (CHUNK_WIDTH * CHUNK_HEIGHT)
# Add tile 3D model
result = processTile(tile, x, y, z)
result = processTile(tile, x, y, z, chunk['chunkX'], chunk['chunkY'], chunk['chunkZ'])
if result is not None and len(result['vertices']) > 0:
base = len(baseModel['vertices'])
quad_indices = [base + idx for idx in result['indices']]