46#ifndef NILOREA_ISOMETRIC_ENGINE
47#define NILOREA_ISOMETRIC_ENGINE
77#define ISO_EDGE_W (1 << 0)
79#define ISO_EDGE_N (1 << 1)
81#define ISO_EDGE_E (1 << 2)
83#define ISO_EDGE_S (1 << 3)
85#define ISO_NUM_EDGE_MASKS 16
88#define ISO_CORNER_NW (1 << 0)
90#define ISO_CORNER_NE (1 << 1)
92#define ISO_CORNER_SE (1 << 2)
94#define ISO_CORNER_SW (1 << 3)
96#define ISO_NUM_CORNER_MASKS 16
98#define ISO_NUM_MASKS (ISO_NUM_EDGE_MASKS + ISO_NUM_CORNER_MASKS)
103#define ISO_PROJ_CLASSIC 0
105#define ISO_PROJ_ISOMETRIC 1
107#define ISO_PROJ_MILITARY 2
109#define ISO_PROJ_STAGGERED 3
111#define ISO_NUM_PROJECTIONS 4
115#define ISO_PROJ_STEEP ISO_PROJ_ISOMETRIC
117#define ISO_PROJ_WIDE ISO_PROJ_STAGGERED
122#define ISO_MAX_SEGMENTS_PER_TILE 2
301void iso_corner_to_screen(
const ISO_MAP* map,
int cx,
int cy,
float fh,
float cam_x,
float cam_y,
float zoom,
float* sx,
float* sy);
340ASTAR_GRID* iso_map_to_astar_grid(
const ISO_MAP* map,
int max_height_diff,
int start_x,
int start_y);
512#include <allegro5/allegro.h>
513#include <allegro5/allegro_primitives.h>
514#include <allegro5/allegro_font.h>
539 ALLEGRO_BITMAP** overlay_bitmaps,
540 int num_overlay_tiles,
577 ALLEGRO_BITMAP** masks,
static ALLEGRO_BITMAP * transition_tiles[8][(16+16)]
static ALLEGRO_BITMAP * tile_bitmaps[8]
Grid structure holding walkability, costs, and dimensions.
int bottom
segment bottom height (primary sort key)
float fz
height in map units (elevation)
int * neighbor_heights_west
Heights from west neighbor chunk's east edge [height], NULL = boundary.
float fy
fractional map Y position
int lower_tile
terrain index for wall/side faces (-1 = use tile's terrain layer)
int * ability
walkability per cell [height * width] (WALK/SWIM/BLCK)
int height
map height in tiles (Y axis)
float occluded_alpha
overlay alpha when behind tiles [0..1], 0=hidden, 0.35=ghost, 1=always visible
int upper_tile
terrain index for top face (-1 = use tile's terrain layer)
int neighbor_top_se
top height of SE neighbor (0 if absent/boundary)
float tile_lift
vertical pixel offset per height unit
float zoom_min
minimum allowed zoom
int * neighbor_heights_east
Heights from east neighbor chunk's west edge [height], NULL = boundary.
int draw_sw
1 if SW edge (S->W, bottom-left) should be drawn
int neighbor_top_sw
top height of SW neighbor (0 if absent/boundary)
float angle_deg
current projection angle in degrees
int smooth_height
0 = CUT mode (cliff walls), 1 = SMOOTH mode (per-corner slopes)
int * neighbor_terrains_north
[width], terrain of north neighbor's south edge
ISO_DRAW_ENTRY * cached_draw_order
Cached draw_order.
float half_w
half-width of a tile in pixels (horizontal extent)
int count
0..ISO_MAX_SEGMENTS_PER_TILE
int bottom
lower height bound (inclusive), must be < top
int hover_mx
hovered tile X (-1 = none)
int max_height
maximum allowed height value
int top
segment top height
float sprite_h
entity height in world units for occlusion (derived from sprite hot_y)
int seg_idx
segment index within tile (0..count-1)
int draw_nw
1 if NW edge (N->W, top-left) should be drawn
int underside
1 if underside face should be drawn
int neighbor_top_ne
top height of NE neighbor (0 if absent/boundary)
float occlude_clip_y
OUTPUT: screen Y of top occluder north vertex (for cross-chunk clip fallback)
int num_terrains
number of terrain types used
float * dynamic_light_map
Per-tile dynamic light accumulation buffer.
int top
upper height bound, must be > bottom
int * neighbor_terrains_east
[height], terrain of east neighbor's west edge
float half_h
half-height of a tile in pixels (vertical extent)
int * overlay
overlay tile index per cell [height * width], 0 = none.
float lerp_speed
interpolation speed factor (default 3.0)
int neighbor_top_nw
top height of NW neighbor (0 if absent/boundary)
float fx
fractional map X position
int * neighbor_terrains_west
[height], terrain of west neighbor's east edge
void * user_data
user data passed to draw callback
int * neighbor_terrains_south
[width], terrain of south neighbor's north edge
int * neighbor_heights_south
Heights from south neighbor chunk's north edge [width], NULL = boundary.
int * terrain
terrain type per cell [height * width], indices 0..num_terrains-1
N_ISO_OBJECT_DRAW_FN draw
draw callback
float zoom_max
maximum allowed zoom
int * neighbor_heights_north
Heights from north neighbor chunk's south edge [width], NULL = boundary.
float height_tint_intensity
0.0 = no tint, 0.3 = subtle, 1.0 = full range.
float zoom
zoom factor (1.0 = no zoom)
int is_occluded
OUTPUT: set to 1 if behind tiles during last iso_map_draw() call.
int draw_se
1 if SE edge (E->S, bottom-right) should be drawn
int cached_draw_order_count
int * heightmap
height value per cell [height * width], 0..max_height
float y
camera Y offset (world units, pre-zoom)
float ambient_r
Global ambient color (day/night + dark place tinting).
int width
map width in tiles (X axis)
int show_grid
1 = draw grid overlay
float target_angle
target angle for smooth interpolation (degrees)
int draw_ne
1 if NE edge (N->E, top-right) should be drawn
ISO_TILE_SEGMENTS * segments
Per-cell height segments.
float sprite_half_w
entity half-width in screen pixels for horizontal occlusion test
int draw_underside
1 if floating segment underside border should be drawn
int smooth_slope_max
max height diff rendered as slope (default 1)
int hover_my
hovered tile Y (-1 = none)
int cached_draw_order_cap
float x
camera X offset (world units, pre-zoom)
ISO_PROJECTION proj
current projection parameters
double n_iso_pass1_us
Per-pass timing accumulators populated by iso_map_draw.
void iso_map_set_height(ISO_MAP *map, int mx, int my, int h)
set height for a cell (bounds-checked, clamped)
void iso_map_set_projection_custom(ISO_MAP *map, float half_w, float half_h, float tile_lift)
set custom projection parameters directly
ALLEGRO_COLOR(* IsoPrimitiveColorFilter)(ALLEGRO_COLOR c)
Optional design-RGB to display-RGB filter applied to every primitive color (filled polygons,...
void iso_map_smooth_corner_heights(const ISO_MAP *map, int mx, int my, float *h_n, float *h_e, float *h_s, float *h_w)
compute smooth corner heights with slope clamping (for rendering)
ISO_MAP * iso_map_new(int width, int height, int num_terrains, int max_height)
create a new height-aware ISO_MAP with given dimensions
float iso_diamond_dist(int px, int py, int tile_w, int tile_h)
distance from pixel to diamond edge (0 at edge, 1 at center)
int iso_map_set_segments(ISO_MAP *map, int mx, int my, const ISO_TILE_SEGMENT *segs, int count)
set per-tile segments on an ISO_MAP.
void n_iso_camera_zoom(N_ISO_CAMERA *cam, float dz, float mouse_x, float mouse_y)
Zoom the camera toward a screen-space point (e.g.
void n_iso_camera_center_on(N_ISO_CAMERA *cam, float world_x, float world_y, int screen_w, int screen_h)
Center the camera so that a world point is at screen center.
int iso_map_save(const ISO_MAP *map, const char *filename)
save ISO_MAP to binary file (chunk-based format)
ALLEGRO_COLOR iso_apply_primitive_color_filter(ALLEGRO_COLOR c)
int iso_map_should_transition_smooth(const ISO_MAP *map, int mx1, int my1, int mx2, int my2)
check if terrain transition should render between two cells (height-aware)
void iso_corner_to_screen(const ISO_MAP *map, int cx, int cy, float fh, float cam_x, float cam_y, float zoom, float *sx, float *sy)
Project a tile corner to screen coordinates (canonical formula).
void iso_set_line_jitter_compensation(IsoLineJitterCompensationFn fn)
void iso_map_lerp_projection(ISO_MAP *map, float dt)
smoothly interpolate current projection angle toward target (call every frame)
#define ISO_MAX_SEGMENTS_PER_TILE
Max height segments per tile (ground + one elevated structure).
void iso_mask_tile_to_diamond(ALLEGRO_BITMAP *bmp, int tile_w, int tile_h)
Mask a tile bitmap to the isometric diamond shape.
ISO_VISIBLE_EDGES iso_map_get_visible_edges(const ISO_MAP *map, int mx, int my)
Compute which diamond edges of tile (mx, my) need a height border.
ISO_MAP * iso_map_load(const char *filename)
load ISO_MAP from binary file
void n_iso_camera_free(N_ISO_CAMERA **cam)
Free a camera and set the pointer to NULL.
int iso_map_build_draw_order(const ISO_MAP *map, ISO_DRAW_ENTRY *out, int max_entries)
Build the draw order for segment-sorted rendering.
int iso_map_should_transition(const ISO_MAP *map, int mx1, int my1, int mx2, int my2)
check if terrain blending should occur between two adjacent cells
const char * iso_projection_name(int preset)
get the display name for a projection preset
void n_iso_camera_follow(N_ISO_CAMERA *cam, float target_x, float target_y, int screen_w, int screen_h, float smoothing, float dt)
Smoothly follow a world-space target (camera lerp).
void iso_map_set_ability(ISO_MAP *map, int mx, int my, int ab)
set ability for a cell (bounds-checked)
ISO_VISIBLE_EDGES iso_map_get_visible_edges_segment(const ISO_MAP *map, int mx, int my, int seg_idx)
Compute per-segment edge visibility for height border rendering.
int iso_map_get_terrain(const ISO_MAP *map, int mx, int my)
get terrain type for a cell (bounds-checked)
void iso_map_calc_transitions_full(const ISO_MAP *map, int mx, int my, int *edge_bits, int *corner_bits)
compute per-terrain transition bitmasks with height filtering (Article 934).
int iso_map_get_ability(const ISO_MAP *map, int mx, int my)
get ability for a cell (bounds-checked)
void iso_map_draw(const ISO_MAP *map, ALLEGRO_BITMAP **tile_bitmaps, ALLEGRO_BITMAP ***transition_tiles, int num_masks, ALLEGRO_BITMAP **overlay_bitmaps, int num_overlay_tiles, float cam_px, float cam_py, float zoom, int screen_w, int screen_h, int player_mode, N_ISO_OBJECT *objects, int num_objects)
Draw the full ISO_MAP with height, transitions, overlays, cliff walls, hover, and grid.
void iso_map_to_screen(const ISO_MAP *map, int mx, int my, int h, float *screen_x, float *screen_y)
convert map tile coordinates to screen pixel coordinates
void iso_map_calc_transitions(const ISO_MAP *map, int mx, int my, int *edge_bits, int *corner_bits)
compute terrain transition bitmasks for a cell (Article 934)
void iso_map_set_projection(ISO_MAP *map, int preset, float tile_width)
set projection preset and snap to it immediately
void n_iso_camera_screen_to_world(const N_ISO_CAMERA *cam, float sx, float sy, float *wx, float *wy)
Convert screen pixel coordinates to world coordinates.
void iso_map_to_screen_f(const ISO_MAP *map, float fmx, float fmy, float h, float *screen_x, float *screen_y)
convert map tile coordinates to screen pixel coordinates (float version)
void iso_map_free(ISO_MAP **map)
free an ISO_MAP and set the pointer to NULL
int iso_is_in_diamond(int px, int py, int tile_w, int tile_h)
test if pixel (px,py) is inside the isometric diamond of size tile_w x tile_h
void iso_generate_transition_tiles(ALLEGRO_BITMAP ***tiles, ALLEGRO_BITMAP **masks, ALLEGRO_BITMAP **tile_bitmaps, int num_terrains, int tile_w, int tile_h)
Pre-composite transition tiles (terrain texture * alpha mask).
void iso_map_set_projection_target(ISO_MAP *map, int preset)
set target projection preset for smooth interpolation via iso_map_lerp_projection
void iso_set_primitive_color_filter(IsoPrimitiveColorFilter fn)
void iso_map_set_terrain(ISO_MAP *map, int mx, int my, int terrain)
set terrain type for a cell (bounds-checked)
void iso_screen_to_map(const ISO_MAP *map, float screen_x, float screen_y, int *mx, int *my)
convert screen pixel coordinates to map tile coordinates (flat, no height)
void iso_map_randomize(ISO_MAP *map)
randomize terrain and height for testing/demo purposes
void iso_generate_transition_masks(ALLEGRO_BITMAP **masks, int tile_w, int tile_h)
Generate the 32 procedural transition alpha masks (16 edge + 16 corner).
void(* IsoLineJitterCompensationFn)(float *out_dx, float *out_dy)
void(* N_ISO_OBJECT_DRAW_FN)(float screen_x, float screen_y, float zoom, float alpha, void *user_data)
Object draw callback.
const ISO_TILE_SEGMENTS * iso_map_get_segments(const ISO_MAP *map, int mx, int my)
get per-tile segments.
int iso_map_get_height(const ISO_MAP *map, int mx, int my)
get height for a cell (bounds-checked, clamped)
float iso_map_interpolate_height(const ISO_MAP *map, float fx, float fy)
bilinear height interpolation at fractional map coordinates
void n_iso_camera_world_to_screen(const N_ISO_CAMERA *cam, float wx, float wy, float *sx, float *sy)
Convert world coordinates to screen pixel coordinates.
void iso_screen_to_map_height_f(const ISO_MAP *map, float screen_x, float screen_y, int tile_w, int tile_h, int *mx, int *my, float *out_fx, float *out_fy)
height-aware screen-to-map conversion returning fractional tile coordinates.
void iso_screen_to_map_height(const ISO_MAP *map, float screen_x, float screen_y, int tile_w, int tile_h, int *mx, int *my)
height-aware screen-to-map conversion with diamond hit testing.
void iso_map_corner_heights(const ISO_MAP *map, int mx, int my, float *h_n, float *h_e, float *h_s, float *h_w)
compute average corner heights for smooth rendering (Article 2026)
void iso_apply_line_jitter_compensation(float *out_dx, float *out_dy)
void n_iso_camera_scroll(N_ISO_CAMERA *cam, float dx, float dy)
Scroll the camera by (dx, dy) world units.
N_ISO_CAMERA * n_iso_camera_new(float zoom_min, float zoom_max)
Create a new camera with the given zoom limits.
Draw order entry for segment-sorted rendering.
Height-aware isometric map with terrain and height layers, per-cell height values,...
Axonometric projection parameters.
Single vertical segment of a tile: solid matter from bottom to top.
Per-tile height segments.
Per-tile edge visibility flags for height border rendering.
2D isometric camera for viewport management.
Drawable object for depth-sorted isometric rendering.
Common headers and low-level functions & define.