|
|
|
@ -49,6 +49,10 @@ pub fn World(comptime ctx: anytype) type { |
|
|
|
|
flecszigble.allocator.destroy(self); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn enableRest(self: *Self, options: struct { port: u16 = 0, addr: ?[:0]const u8 = null }) !void { |
|
|
|
|
try self.set(flecs.rest.Rest, .{ .port = options.port, .ipaddr = @constCast(options.addr) }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn progress(self: *Self, delta_time: f32) bool { |
|
|
|
|
return c.ecs_progress(self.raw, delta_time); |
|
|
|
|
} |
|
|
|
@ -285,3 +289,32 @@ pub fn World(comptime ctx: anytype) type { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
test "World REST API" { |
|
|
|
|
const expect = @import("./test/expect.zig"); |
|
|
|
|
const alloc = std.testing.allocator; |
|
|
|
|
|
|
|
|
|
flecszigble.init(alloc); |
|
|
|
|
var world = try World(void).init(); |
|
|
|
|
defer world.deinit(); |
|
|
|
|
try world.enableRest(.{ .port = 42666 }); |
|
|
|
|
|
|
|
|
|
const Runner = struct { |
|
|
|
|
pub fn run(w: *World(void)) void { |
|
|
|
|
while (w.progress(0.0)) {} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var thread = try std.Thread.spawn(.{ .allocator = alloc }, Runner.run, .{world}); |
|
|
|
|
defer thread.join(); |
|
|
|
|
|
|
|
|
|
const url = "http://localhost:42666/entity/flecs/core/World"; |
|
|
|
|
var client = std.http.Client{ .allocator = alloc }; |
|
|
|
|
defer client.deinit(); |
|
|
|
|
var result = try client.fetch(alloc, .{ .location = .{ .url = url } }); |
|
|
|
|
defer result.deinit(); |
|
|
|
|
|
|
|
|
|
try expect.equalStrings("{\"path\":\"flecs.core.World\", \"ids\":[]}", result.body); |
|
|
|
|
|
|
|
|
|
world.quit(); |
|
|
|
|
} |
|
|
|
|