Skip to content

Commit 45385e0

Browse files
author
Jay
committed
Updates for 0.15.2
1 parent 0c87478 commit 45385e0

File tree

4 files changed

+82
-89
lines changed

4 files changed

+82
-89
lines changed

build.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn add_translatec_headers(
8282
switch (target.result.os.tag) {
8383
.macos => {
8484
//const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse
85-
const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse
85+
const sdk = std.zig.system.darwin.getSdk(b.allocator, &target.result) orelse
8686
@panic("macOS SDK is missing");
8787
std.log.info("engine using macos c headers: {s}", .{sdk});
8888
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{
@@ -96,7 +96,7 @@ pub fn add_translatec_headers(
9696
},
9797
.ios => {
9898
//const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse
99-
const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse
99+
const sdk = std.zig.system.darwin.getSdk(b.allocator, &target.result) orelse
100100
@panic("iOS SDK is missing");
101101
std.log.info("engine using iphoneos c headers: {s}", .{sdk});
102102
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{
@@ -146,7 +146,7 @@ pub fn add_libs(
146146
// For TranslateC to work, we need the system library headers
147147
switch (target.result.os.tag) {
148148
.macos => {
149-
const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse
149+
const sdk = std.zig.system.darwin.getSdk(b.allocator, &target.result) orelse
150150
@panic("macOS SDK is missing");
151151
std.log.info("engine using macos c headers: {s}", .{sdk});
152152
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{
@@ -159,7 +159,7 @@ pub fn add_libs(
159159
}) });
160160
},
161161
.ios => {
162-
const sdk = std.zig.system.darwin.getSdk(b.allocator, target.result) orelse
162+
const sdk = std.zig.system.darwin.getSdk(b.allocator, &target.result) orelse
163163
@panic("iOS SDK is missing");
164164
std.log.info("engine using iphoneos c headers: {s}", .{sdk});
165165
lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{

build.zig.zon

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
.{
22
.name = .engine,
3-
.version = "0.4.1",
3+
.version = "0.4.2",
44
.fingerprint = 0xe8a81a8d0aa558d5,
5-
.minimum_zig_version = "0.14.1",
5+
.minimum_zig_version = "0.15.2",
66
.dependencies = .{
77
.sdl = .{
8-
.url = "git+https://github.com/castholm/SDL.git#f6bbe8ac5e7b901db69ba62f017596090c362d84",
9-
.hash = "sdl-0.2.1+3.2.10-7uIn9PLkfQHKJO7TvSXbVa0VnySCHbLz28PDZIlKWF4Y",
8+
.url = "git+https://github.com/castholm/SDL.git#f103a1439670c35be756d4491b296a6e3ccffaed",
9+
.hash = "sdl-0.3.2+3.2.26-7uIn9BNgfwHaS0qXiSIBLkJf8Jfrh5P6gSWdQvtnvxEp",
1010
},
1111
.sdl_ttf = .{
12-
.url = "git+https://github.com/loftafi/SDL_ttf.git#85e45fbbbd9375d640628392fafab492600d1e32",
13-
.hash = "sdl_ttf-3.2.2-9xyaiOQVBwB315-061yAPXu0LcjjsUQJBxFyE3gmM-sY",
12+
.url = "git+https://github.com/loftafi/SDL_ttf.git#119d2eec127c4ca9de159939c95f5f3b55794155",
13+
.hash = "sdl_ttf-3.2.26-9xyaiOgVBwA6HIB5v3N8mf-hRpDwexBaJ2vFckQeqZNH",
1414
},
1515
.zigimg = .{
16-
.url = "git+https://github.com/loftafi/zigimg.git#aa93a624b7a67b20525198620403a6090e5f16ab",
17-
.hash = "zigimg-0.1.0-lly-O_qZEgAP5eJWUbcWtL9Jv4V_BGcK5p-570Hiaj7k",
16+
.url = "git+https://github.com/zigimg/zigimg.git#f5783e87627cbd9e0b45fad112e9f73503914f36",
17+
.hash = "zigimg-0.1.0-8_eo2vBrFQBhsrLpexdcDQY-zrlzkyFZfKuYX-Nry6KN",
1818
},
1919
.resources = .{
20-
.url = "git+https://github.com/loftafi/resources.git#58c9dc8d674ae49cee012e19d30804a9d4862b94",
21-
.hash = "resources-0.2.11-J0GwI4uHAQASzzVqZVvlM2gpnV6Y3QEF5ghs-gfw4U4J",
20+
.url = "git+https://github.com/loftafi/resources.git#09fe6e0dd0fec98096cd63fba15286e3441359d2",
21+
.hash = "resources-0.4.0-J0GwIySNAQBvdKL1b7tFxAq7qevZ0CCdIuRkjom8Qnsv",
2222
},
2323
},
2424
.paths = .{

src/engine.zig

Lines changed: 62 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,8 @@ pub const Element = struct {
15171517
dest.x += scroll_offset.x;
15181518
dest.y += scroll_offset.y;
15191519

1520+
if (dest.height <= 0 or dest.width <= 0) return;
1521+
15201522
// TODO: Sprites might have frames
15211523
const source: sdl.SDL_FRect = .{
15221524
.x = 0,
@@ -2456,10 +2458,10 @@ pub const Display = struct {
24562458
on_resized: ?*const fn (display: *Display, element: *Element) bool = null,
24572459
event_hook: ?*const fn (display: *Display, e: u32) error{OutOfMemory}!void = null,
24582460

2459-
pub fn create(allocator: Allocator, app_name: [:0]const u8, app_version: [:0]const u8, app_id: [:0]const u8, dev_resource_folder: []const u8, translation_filename: []const u8, gui_flags: usize) !*Display {
2460-
var display = try allocator.create(Display);
2461-
errdefer allocator.destroy(display);
2462-
display.allocator = allocator;
2461+
pub fn create(gpa: Allocator, app_name: [:0]const u8, app_version: [:0]const u8, app_id: [:0]const u8, dev_resource_folder: []const u8, translation_filename: []const u8, gui_flags: usize) !*Display {
2462+
var display = try gpa.create(Display);
2463+
errdefer gpa.destroy(display);
2464+
display.allocator = gpa;
24632465
display.hovered = null;
24642466
display.selected = null;
24652467
display.keyboard_selected = false;
@@ -2513,11 +2515,11 @@ pub const Display = struct {
25132515
}
25142516

25152517
debug("Initialising resource loader", .{});
2516-
display.resources = try init_resource_loader(allocator, engine.RESOURCE_BUNDLE_FILENAME, dev_resource_folder);
2517-
if (try display.resources.lookupOne(translation_filename, .csv)) |resource| {
2518-
const data = try sdl_load_resource(display.resources, resource, allocator);
2519-
defer allocator.free(data);
2520-
try display.translation.load_translation_data(allocator, data);
2518+
display.resources = try init_resource_loader(gpa, engine.RESOURCE_BUNDLE_FILENAME, dev_resource_folder);
2519+
if (try display.resources.lookupOne(translation_filename, .csv, gpa)) |resource| {
2520+
const data = try sdl_load_resource(display.resources, resource, gpa);
2521+
defer gpa.free(data);
2522+
try display.translation.load_translation_data(gpa, data);
25212523
debug("Translation file loaded", .{});
25222524
} else {
25232525
err("No translation file found.", .{});
@@ -2538,13 +2540,23 @@ pub const Display = struct {
25382540
return error.graphics_renderer_failed;
25392541
};
25402542

2541-
debug("Renderers: {}", .{driver_formatter(renderer)});
2543+
const current_driver = sdl.SDL_GetRendererName(renderer).?;
2544+
const count = sdl.SDL_GetNumRenderDrivers();
2545+
var i: c_int = 0;
2546+
while (i < count) : (i += 1) {
2547+
const driver = sdl.SDL_GetRenderDriver(i).?;
2548+
if (std.mem.orderZ(u8, current_driver, driver) == .eq) {
2549+
debug("Renderer: {s} (selected)", .{std.mem.span(driver)});
2550+
} else {
2551+
debug("Renderers: {s}", .{std.mem.span(driver)});
2552+
}
2553+
}
25422554

25432555
debug("Checking for desktop icon", .{});
2544-
if (try display.resources.lookupOne("desktop icon", .image)) |resource| {
2556+
if (try display.resources.lookupOne("desktop icon", .image, gpa)) |resource| {
25452557
var surface: SurfaceInfo = undefined;
2546-
try display.make_surface_from_resource(resource, allocator, &surface);
2547-
defer surface.deinit(allocator);
2558+
try display.make_surface_from_resource(resource, gpa, &surface);
2559+
defer surface.deinit(gpa);
25482560
if (!sdl.SDL_SetWindowIcon(window, surface.surface)) {
25492561
info("Did not set desktop icon", .{});
25502562
} else {
@@ -2580,21 +2592,21 @@ pub const Display = struct {
25802592
display.scale = display.pixel_scale / display.user_scale;
25812593

25822594
// App can accept these keybindings or replace them
2583-
try display.keybindings.put(allocator, sdl.SDLK_D, toggle_dev_mode);
2584-
try display.keybindings.put(allocator, sdl.SDLK_K, use_next_theme);
2585-
try display.keybindings.put(allocator, sdl.SDLK_X, increase_content_size);
2586-
try display.keybindings.put(allocator, sdl.SDLK_PLUS, increase_content_size);
2587-
try display.keybindings.put(allocator, sdl.SDLK_EQUALS, increase_content_size);
2588-
try display.keybindings.put(allocator, sdl.SDLK_MINUS, decrease_content_size);
2589-
try display.keybindings.put(allocator, sdl.SDLK_KP_PLUS, increase_content_size);
2590-
try display.keybindings.put(allocator, sdl.SDLK_KP_MINUS, decrease_content_size);
2595+
try display.keybindings.put(gpa, sdl.SDLK_D, toggle_dev_mode);
2596+
try display.keybindings.put(gpa, sdl.SDLK_K, use_next_theme);
2597+
try display.keybindings.put(gpa, sdl.SDLK_X, increase_content_size);
2598+
try display.keybindings.put(gpa, sdl.SDLK_PLUS, increase_content_size);
2599+
try display.keybindings.put(gpa, sdl.SDLK_EQUALS, increase_content_size);
2600+
try display.keybindings.put(gpa, sdl.SDLK_MINUS, decrease_content_size);
2601+
try display.keybindings.put(gpa, sdl.SDLK_KP_PLUS, increase_content_size);
2602+
try display.keybindings.put(gpa, sdl.SDLK_KP_MINUS, decrease_content_size);
25912603
if (engine.dev_build) {
2592-
try display.keybindings.put(allocator, sdl.SDLK_B, make_bundle);
2604+
try display.keybindings.put(gpa, sdl.SDLK_B, make_bundle);
25932605
}
25942606

25952607
display.themes = .empty;
25962608
for (&default_themes) |*theme| {
2597-
try display.themes.append(allocator, theme.*);
2609+
try display.themes.append(gpa, theme.*);
25982610
}
25992611
display.update_system_theme();
26002612

@@ -2629,16 +2641,16 @@ pub const Display = struct {
26292641
}
26302642

26312643
/// Cleanup memory assocaited with this display.
2632-
pub fn destroy(self: *Display, allocator: Allocator) void {
2644+
pub fn destroy(self: *Display, gpa: Allocator) void {
26332645
trace("Engine cleanup", .{});
26342646

2635-
self.root.deinit(self, allocator);
2636-
self.themes.deinit(allocator);
2647+
self.root.deinit(self, gpa);
2648+
self.themes.deinit(gpa);
26372649

26382650
for (self.fonts.items) |item| {
2639-
item.destroy(allocator);
2651+
item.destroy(gpa);
26402652
}
2641-
self.fonts.deinit(allocator);
2653+
self.fonts.deinit(gpa);
26422654

26432655
var i = self.textures.iterator();
26442656
while (i.next()) |x| {
@@ -2648,23 +2660,23 @@ pub const Display = struct {
26482660
x.value_ptr.*.references,
26492661
});
26502662
}
2651-
x.value_ptr.*.destroy(allocator);
2663+
x.value_ptr.*.destroy(gpa);
26522664
}
2653-
self.textures.deinit(allocator);
2665+
self.textures.deinit(gpa);
26542666
self.resources.destroy();
26552667
for (self.animators.items) |animator| {
2656-
allocator.destroy(animator);
2668+
gpa.destroy(animator);
26572669
}
2658-
self.animators.deinit(allocator);
2670+
self.animators.deinit(gpa);
26592671

26602672
sdl.SDL_DestroyRenderer(self.renderer);
26612673
sdl.SDL_DestroyWindow(self.window);
26622674
sdl.TTF_Quit();
26632675
sdl.SDL_Quit();
26642676

2665-
self.keybindings.deinit(allocator);
2666-
self.translation.deinit(allocator);
2667-
allocator.destroy(self);
2677+
self.keybindings.deinit(gpa);
2678+
self.translation.deinit(gpa);
2679+
gpa.destroy(self);
26682680
}
26692681

26702682
/// Check that a theme name is a valid theme name. Return a stack
@@ -2885,7 +2897,7 @@ pub const Display = struct {
28852897
std.debug.assert(parent.type == .panel);
28862898
//debug("relayout: {d}x{d}", .{ parent.width, parent.rect.height });
28872899

2888-
var expanders = std.BoundedArray(*Element, 10){};
2900+
var expanders = BoundedArray(*Element, 10){};
28892901
var expander_weights: f32 = 0;
28902902

28912903
// Make sure this element never exceeds its maximum.
@@ -3028,7 +3040,7 @@ pub const Display = struct {
30283040
inline fn relayout_top_to_bottom(
30293041
_: *Display,
30303042
parent: *Element,
3031-
expanders: *std.BoundedArray(*Element, 10),
3043+
expanders: *BoundedArray(*Element, 10),
30323044
expander_weights: f32,
30333045
) void {
30343046
// Layout each item from top to bottom, initially ignoring
@@ -3151,7 +3163,7 @@ pub const Display = struct {
31513163
inline fn relayout_left_to_right(
31523164
_: *Display,
31533165
parent: *Element,
3154-
_: *std.BoundedArray(*Element, 10),
3166+
_: *BoundedArray(*Element, 10),
31553167
_: f32,
31563168
) void {
31573169
// Draw panel children from top left corner of the panel
@@ -3318,7 +3330,7 @@ pub const Display = struct {
33183330
allocator: Allocator,
33193331
name: []const u8,
33203332
) (error{ OutOfMemory, UnknownImageFormat, ResourceNotFound, ResourceReadError } || ResourcesError)!*FontInfo {
3321-
const resource = try self.resources.lookupOne(name, .font);
3333+
const resource = try self.resources.lookupOne(name, .font, allocator);
33223334
if (resource == null) {
33233335
err("load_font({s}) Font not in resource folder", .{name});
33243336
return error.ResourceNotFound;
@@ -3451,7 +3463,7 @@ pub const Display = struct {
34513463
return texture;
34523464
}
34533465

3454-
const resource = try self.resources.lookupOne(name, .image);
3466+
const resource = try self.resources.lookupOne(name, .image, allocator);
34553467
if (resource == null) {
34563468
return null;
34573469
}
@@ -3473,7 +3485,7 @@ pub const Display = struct {
34733485

34743486
pub fn deinit(si: *@This(), gpa: Allocator) void {
34753487
gpa.free(si.buffer);
3476-
si.img.deinit();
3488+
si.img.deinit(gpa);
34773489
sdl.SDL_DestroySurface(si.surface);
34783490
}
34793491
};
@@ -3490,7 +3502,7 @@ pub const Display = struct {
34903502
if (e == error.OutOfMemory) return error.OutOfMemory;
34913503
return error.UnknownImageFormat;
34923504
};
3493-
errdefer si.img.deinit();
3505+
errdefer si.img.deinit(allocator);
34943506

34953507
var row_size: c_int = 0;
34963508
var sdl_format: sdl.SDL_PixelFormat = sdl.SDL_PIXELFORMAT_UNKNOWN;
@@ -4336,7 +4348,7 @@ pub const Display = struct {
43364348
//};
43374349

43384350
const base_folder = "/tmp/";
4339-
var buffer = std.BoundedArray(u8, 1000){};
4351+
var buffer = BoundedArray(u8, 1000){};
43404352
buffer.appendSlice(base_folder) catch {
43414353
return std.mem.Allocator.Error.OutOfMemory;
43424354
};
@@ -5100,31 +5112,6 @@ inline fn c_unicode_to_u21(text: [*c]const u8) u21 {
51005112
} catch text[0];
51015113
}
51025114

5103-
/// Return a formatter that outputs the list of available renderers, and
5104-
/// marking the current renderer that is in use.
5105-
fn driver_formatter(renderer: *sdl.SDL_Renderer) std.fmt.Formatter(list_drivers) {
5106-
return .{ .data = .{ .renderer = renderer } };
5107-
}
5108-
5109-
fn list_drivers(
5110-
context: struct { renderer: *sdl.SDL_Renderer },
5111-
comptime _: []const u8,
5112-
_: std.fmt.FormatOptions,
5113-
writer: anytype,
5114-
) !void {
5115-
const current_driver = sdl.SDL_GetRendererName(context.renderer).?;
5116-
const count = sdl.SDL_GetNumRenderDrivers();
5117-
var i: c_int = 0;
5118-
while (i < count) : (i += 1) {
5119-
const driver = sdl.SDL_GetRenderDriver(i).?;
5120-
if (i != 0) try writer.writeAll(", ");
5121-
try writer.writeAll(std.mem.span(driver));
5122-
if (std.mem.orderZ(u8, current_driver, driver) == .eq) {
5123-
try writer.writeAll(" (selected)");
5124-
}
5125-
}
5126-
}
5127-
51285115
/// SDL provides extra information that is sometimes helpful for debugging, lets print this
51295116
/// information when we are in debug mode.
51305117
///
@@ -5135,7 +5122,7 @@ fn sdl_log_callback(
51355122
category: c_int,
51365123
priority: sdl.SDL_LogPriority,
51375124
message: [*c]const u8,
5138-
) callconv(.C) void {
5125+
) callconv(.c) void {
51395126
std.log.scoped(.term_scope).debug("SDL ({s}, {s}) {s}", .{
51405127
@tagName(SdlLogCategory.fromInt(category)),
51415128
@tagName(SdlLogPriority.fromInt(priority)),
@@ -5215,18 +5202,20 @@ pub fn log_output(
52155202
comptime format: []const u8,
52165203
args: anytype,
52175204
) void {
5205+
var buffer: [1024 * 5]u8 = undefined;
52185206
const prefix = "[" ++ comptime level ++ "] ";
52195207
if (builtin.mode == .Debug) {
52205208
// Log to terminal in debug mode
52215209
std.debug.lockStdErr();
52225210
defer std.debug.unlockStdErr();
5223-
const stderr = std.io.getStdErr().writer();
5211+
var stderr_writer = std.fs.File.stderr().writer(&buffer);
5212+
const stderr = &stderr_writer.interface;
52245213
nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
5214+
stderr.flush() catch {};
52255215
} else {
52265216
// Log using SDL when in release mode
52275217
if (scope != .term_scope) {
5228-
var buf: [3000]u8 = undefined;
5229-
if (std.fmt.bufPrintZ(&buf, prefix ++ format, args)) |f| {
5218+
if (std.fmt.bufPrintZ(&buffer, prefix ++ format, args)) |f| {
52305219
sdl.SDL_LogInfo(@intFromEnum(SdlLogCategory.application), f.ptr);
52315220
} else |_| {
52325221
sdl.SDL_LogInfo(@intFromEnum(SdlLogCategory.application), prefix ++ format);
@@ -5521,6 +5510,7 @@ pub const Animator = @import("animator.zig");
55215510

55225511
const praxis = @import("praxis");
55235512
const Lang = @import("praxis").Lang;
5513+
const BoundedArray = praxis.BoundedArray;
55245514

55255515
pub const Chunker = @import("chunker.zig").Chunker;
55265516
pub const Translation = @import("translation.zig").Translation;

0 commit comments

Comments
 (0)