Compare commits

..

No commits in common. "9320b46f68e57489efa3e760c626b6d203b11f21" and "ca2940191113df13a2214aef056fe4bcc1002229" have entirely different histories.

11 changed files with 281 additions and 1190 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -11,11 +11,11 @@ pub fn build(b: *std.Build) !void {
"Prototype_Character/Default/idle.png", "Prototype_Character/Default/idle.png",
"Prototype_Character/Default/walk.png", "Prototype_Character/Default/walk.png",
"Prototype_Character/Default/death.png", "Prototype_Character/Default/death.png",
"font/pixeloid/PixeloidSans.ttf", "font/pixeloid/PixeloidSans.ttf"
"tranquil_tunnels_transparent.png", // "sokoban/sokoban_tilesheet.png",
"fire/1.png", // "roboto-font/Roboto-Regular.ttf",
"fire/2.png", // "tiled/map.tmx",
"fire/5.png", // "tiled/tileset.tsx"
}; };
const asset_dir_realpath = try b.build_root.join(b.graph.arena, &.{ assets_dir }); const asset_dir_realpath = try b.build_root.join(b.graph.arena, &.{ assets_dir });

File diff suppressed because it is too large Load Diff

View File

@ -41,12 +41,3 @@ pub fn rgb_hex(text: []const u8) ?Color {
const b = std.fmt.parseInt(u8, text[5..7], 16) catch return null; const b = std.fmt.parseInt(u8, text[5..7], 16) catch return null;
return rgb(r, g, b); return rgb(r, g, b);
} }
pub fn lerp(self: Color, other: Color, t: f32) Color {
return Color{
.r = std.math.lerp(self.r, other.r, t),
.g = std.math.lerp(self.g, other.g, t),
.b = std.math.lerp(self.b, other.b, t),
.a = std.math.lerp(self.a, other.a, t),
};
}

View File

@ -39,8 +39,8 @@ const State = struct {
nearest_sampler: sg.Sampler, nearest_sampler: sg.Sampler,
default_sampler: Sampler, default_sampler: Sampler,
quads_buffer: [8192]VertexQuad, quads_buffer: [2048]Quad,
quads: std.ArrayList(VertexQuad), quads: std.ArrayList(Quad),
clear_color: Color, clear_color: Color,
@ -126,7 +126,7 @@ pub fn init(gpa: std.mem.Allocator, logger: sg.Logger) !void {
const max_quads = self.quads_buffer.len; const max_quads = self.quads_buffer.len;
bindings.vertex_buffers[0] = sg.makeBuffer(.{ bindings.vertex_buffers[0] = sg.makeBuffer(.{
.size = @sizeOf(VertexQuad) * max_quads, .size = @sizeOf(Quad) * max_quads,
.usage = .{ .vertex_buffer = true, .stream_update = true }, .usage = .{ .vertex_buffer = true, .stream_update = true },
.label = "quad-vertices" .label = "quad-vertices"
}); });
@ -530,13 +530,9 @@ pub fn endFrame() void {
} }
pub fn drawRectangle(pos: Vec2, size: Vec2, color: Color) void { pub fn drawRectangle(pos: Vec2, size: Vec2, color: Color) void {
drawQuad(Quad.initRect(pos, size), color);
}
pub fn drawQuad(quad: Quad, color: Color) void {
const self = &g_state; const self = &g_state;
drawSpriteQuad(self.default_sprite, quad, color); drawSprite(self.default_sprite, pos, size, color);
} }
pub fn drawRectangleOutline(pos: Vec2, size: Vec2, color: Color, width: f32, alignment: f32) void { pub fn drawRectangleOutline(pos: Vec2, size: Vec2, color: Color, width: f32, alignment: f32) void {
@ -547,42 +543,42 @@ pub fn drawRectangleOutline(pos: Vec2, size: Vec2, color: Color, width: f32, ali
drawSpriteQuad( drawSpriteQuad(
self.default_sprite, self.default_sprite,
.init(.{ .{
.init(outer_rect.right(), outer_rect.top()), .init(outer_rect.right(), outer_rect.top()),
.init(outer_rect.left(), outer_rect.top()), .init(outer_rect.left(), outer_rect.top()),
.init(inner_rect.right(), inner_rect.top()), .init(inner_rect.right(), inner_rect.top()),
.init(inner_rect.left(), inner_rect.top()), .init(inner_rect.left(), inner_rect.top()),
}), },
color color
); );
drawSpriteQuad( drawSpriteQuad(
self.default_sprite, self.default_sprite,
.init(.{ .{
.init(outer_rect.right(), outer_rect.top()), .init(outer_rect.right(), outer_rect.top()),
.init(inner_rect.right(), inner_rect.top()), .init(inner_rect.right(), inner_rect.top()),
.init(outer_rect.right(), outer_rect.bottom()), .init(outer_rect.right(), outer_rect.bottom()),
.init(inner_rect.right(), inner_rect.bottom()), .init(inner_rect.right(), inner_rect.bottom()),
}), },
color color
); );
drawSpriteQuad( drawSpriteQuad(
self.default_sprite, self.default_sprite,
.init(.{ .{
.init(outer_rect.left(), outer_rect.top()), .init(outer_rect.left(), outer_rect.top()),
.init(inner_rect.left(), inner_rect.top()), .init(inner_rect.left(), inner_rect.top()),
.init(outer_rect.left(), outer_rect.bottom()), .init(outer_rect.left(), outer_rect.bottom()),
.init(inner_rect.left(), inner_rect.bottom()), .init(inner_rect.left(), inner_rect.bottom()),
}), },
color color
); );
drawSpriteQuad( drawSpriteQuad(
self.default_sprite, self.default_sprite,
.init(.{ .{
.init(outer_rect.right(), outer_rect.bottom()), .init(outer_rect.right(), outer_rect.bottom()),
.init(outer_rect.left(), outer_rect.bottom()), .init(outer_rect.left(), outer_rect.bottom()),
.init(inner_rect.right(), inner_rect.bottom()), .init(inner_rect.right(), inner_rect.bottom()),
.init(inner_rect.left(), inner_rect.bottom()), .init(inner_rect.left(), inner_rect.bottom()),
}), },
color color
); );
} }
@ -599,7 +595,7 @@ pub fn drawLine(from: Vec2, to: Vec2, color: Color, width: f32) void {
drawSpriteQuad( drawSpriteQuad(
self.default_sprite, self.default_sprite,
.init(.{ top_right, top_left, bottom_right, bottom_left }), .{ top_right, top_left, bottom_right, bottom_left },
color color
); );
} }
@ -759,7 +755,7 @@ pub fn setTexture(id: Texture.Id, texture_data: ImageData) void {
} }
pub fn drawTexture(id: Texture.Id, pos: Vec2, size: Vec2, color: Color) void { pub fn drawTexture(id: Texture.Id, pos: Vec2, size: Vec2, color: Color) void {
var quad: VertexQuad = undefined; var quad: Quad = undefined;
quad.setColor(color); quad.setColor(color);
quad.setRect(.{ .pos = pos, .size = size }); quad.setRect(.{ .pos = pos, .size = size });
quad.setUVRect(.init(0, 0, 1, 1)); quad.setUVRect(.init(0, 0, 1, 1));
@ -799,7 +795,7 @@ pub const Sampler = enum {
const DrawOptions = struct { const DrawOptions = struct {
sampler: ?Sampler = null, sampler: ?Sampler = null,
texture: Texture.Id, texture: Texture.Id,
quad: VertexQuad quad: Quad
}; };
pub fn draw(opts: DrawOptions) void { pub fn draw(opts: DrawOptions) void {
@ -1184,15 +1180,15 @@ pub fn getSpriteUVRect(id: Sprite.Id) ?Rect {
return uv_rect; return uv_rect;
} }
pub fn drawSpriteQuad(id: Sprite.Id, points: Quad, color: Color) void { fn drawSpriteQuad(id: Sprite.Id, points: [4]Vec2, color: Color) void {
const self = &g_state; const self = &g_state;
var quad: VertexQuad = undefined; var quad: Quad = undefined;
quad.setColor(color); quad.setColor(color);
quad.vertices[0].position = points.positions[0]; quad.vertices[0].position = points[0];
quad.vertices[1].position = points.positions[1]; quad.vertices[1].position = points[1];
quad.vertices[2].position = points.positions[2]; quad.vertices[2].position = points[2];
quad.vertices[3].position = points.positions[3]; quad.vertices[3].position = points[3];
var texture: ?Texture.Id = null; var texture: ?Texture.Id = null;
if (id != self.nil_sprite) { if (id != self.nil_sprite) {
@ -1212,7 +1208,12 @@ pub fn drawSpriteQuad(id: Sprite.Id, points: Quad, color: Color) void {
} }
pub fn drawSprite(id: Sprite.Id, pos: Vec2, size: Vec2, color: Color) void { pub fn drawSprite(id: Sprite.Id, pos: Vec2, size: Vec2, color: Color) void {
const rect = Quad.initRect(pos, size); const rect = .{
pos,
pos.add(.init(size.x, 0)),
pos.add(.init(0, size.y)),
pos.add(size),
};
drawSpriteQuad(id, rect, color); drawSpriteQuad(id, rect, color);
} }
@ -1715,7 +1716,7 @@ pub const ImageData = struct {
} }
} }
pub fn getPixel(self: ImageData, x: u32, y: u32) []u8 { fn getPixel(self: ImageData, x: u32, y: u32) []u8 {
const pixel_index = y * self.width + x; const pixel_index = y * self.width + x;
if (self.pixels) |pixels| { if (self.pixels) |pixels| {
return switch (pixels) { return switch (pixels) {
@ -1822,7 +1823,7 @@ pub const Sprite = struct {
position: ?Vec2, position: ?Vec2,
padding: u32, padding: u32,
const max_sprites = 256; const max_sprites = 128;
const SlotMap = SlotMapType(std.math.IntFittingRange(0, max_sprites-1), u8, Sprite); const SlotMap = SlotMapType(std.math.IntFittingRange(0, max_sprites-1), u8, Sprite);
pub const Id = SlotMap.Id; pub const Id = SlotMap.Id;
}; };
@ -2295,16 +2296,16 @@ pub const Vertex = extern struct {
color: Vec4, color: Vec4,
}; };
pub const VertexQuad = extern struct { pub const Quad = extern struct {
vertices: [4]Vertex, vertices: [4]Vertex,
pub fn init(vertices: [4]Vertex) VertexQuad { pub fn init(vertices: [4]Vertex) Quad {
return VertexQuad{ return Quad{
.vertices = vertices .vertices = vertices
}; };
} }
pub fn setColor(self: *VertexQuad, color: Color) void { pub fn setColor(self: *Quad, color: Color) void {
for (&self.vertices) |*vertex| { for (&self.vertices) |*vertex| {
vertex.color = Vec4{ vertex.color = Vec4{
.x = color.r, .x = color.r,
@ -2315,7 +2316,7 @@ pub const VertexQuad = extern struct {
} }
} }
pub fn setUVRect(self: *VertexQuad, rect: Rect) void { pub fn setUVRect(self: *Quad, rect: Rect) void {
const pos = rect.pos; const pos = rect.pos;
const size = rect.size; const size = rect.size;
self.vertices[0].texcoord = pos; self.vertices[0].texcoord = pos;
@ -2324,7 +2325,7 @@ pub const VertexQuad = extern struct {
self.vertices[3].texcoord = pos.add(size); self.vertices[3].texcoord = pos.add(size);
} }
pub fn setRect(self: *VertexQuad, rect: Rect) void { pub fn setRect(self: *Quad, rect: Rect) void {
const pos = rect.pos; const pos = rect.pos;
const size = rect.size; const size = rect.size;
self.vertices[0].position = pos; self.vertices[0].position = pos;
@ -2334,39 +2335,6 @@ pub const VertexQuad = extern struct {
} }
}; };
pub const Quad = struct {
positions: [4]Vec2,
pub fn init(positions: [4]Vec2) Quad {
return Quad{
.positions = positions
};
}
pub fn initRect(pos: Vec2, size: Vec2) Quad {
return Quad{
.positions = .{
pos,
pos.add(.init(size.x, 0)),
pos.add(.init(0, size.y)),
pos.add(size),
}
};
}
pub fn applyRotate(self: *Quad, rad: f32, origin: Vec2) void {
for (&self.positions) |*pos| {
pos.* = pos.sub(origin).rotate(rad).add(origin);
}
}
pub fn applyOffset(self: *Quad, vec2: Vec2) void {
for (&self.positions) |*pos| {
pos.* = pos.add(vec2);
}
}
};
pub const TransformFrame = struct { pub const TransformFrame = struct {
offset: Vec2, offset: Vec2,
scale: Vec2, scale: Vec2,

View File

@ -47,7 +47,7 @@ pub fn isMousePressed(self: Input, button: MouseButton) bool {
return self.mouse_buttons.pressed.contains(button); return self.mouse_buttons.pressed.contains(button);
} }
pub fn isMouseReleased(self: Input, button: MouseButton) bool { pub fn iMouseReleased(self: Input, button: MouseButton) bool {
return self.mouse_buttons.released.contains(button); return self.mouse_buttons.released.contains(button);
} }

View File

@ -403,11 +403,6 @@ fn PlatformType(App: type) type {
.unfocused = {} .unfocused = {}
}); });
}, },
.RESIZED => {
self.pushEvent(.{
.window_resize = .initFromInt(i32, e.window_width, e.window_height)
});
},
else => {} else => {}
} }