From 5cecadb81ccab1a2e6ff264349f5fa73a720db9f Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Fri, 22 Oct 2021 17:21:10 -0400 Subject: Specialise layers to be either lists of vertices or squares --- src/level.zig | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'src/level.zig') diff --git a/src/level.zig b/src/level.zig index f277b19..31d86df 100644 --- a/src/level.zig +++ b/src/level.zig @@ -17,35 +17,30 @@ const std = @import("std"); -pub const Layer = struct { +pub const Polygon = union(enum) { pub const MAX_VERTS = 16; - height : f32 = 0, - vertical_texture : u8 = 0, - vertical_texture_scale : f32 = 4, - horizontal_texture : u8 = 0, - // What happened to this error? Is it comptime? + square: void, vertices: std.BoundedArray([2]f32, MAX_VERTS), }; +pub const Layer = struct { + height: f32 = 0, + vertical_texture: u8 = 0, + vertical_texture_scale: f32 = 4, + horizontal_texture: u8 = 0, + + polygon: Polygon, +}; + pub const Cell = struct { pub const MAX_LAYERS = 16; - // floor_height: f32 = 0, - // ceiling_height: f32 = DEFAULT_HEIGHT, - // draw_down: bool = false, - // lower_texture: u8 = 0, - // upper_texture: u8 = 0, - // floor_texture: u8 = 0, - // ceiling_texture: u8 = 2, - - lower_layers : std.BoundedArray(Layer, MAX_LAYERS), - - // I'm not sure how i feel about reaching into the implementation of - // BoundedArray like this. Surely there should be an ``.empty'' or something - // default? + + lower_layers: std.BoundedArray(Layer, MAX_LAYERS), + fn empty() !Cell { const lower_layers = try std.BoundedArray(Layer, MAX_LAYERS).init(0); - return Cell{ . lower_layers = lower_layers }; + return Cell{ .lower_layers = lower_layers }; } pub const DEFAULT_HEIGHT: f32 = 4; -- cgit v1.3.1