mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-12 22:09:18 -04:00
Revive windows support.
It had been broken for a while due to a (now fixed) bug in zig and a couple other problems.
This commit is contained in:
parent
b0a358f63c
commit
bf3a01ad95
11
build.zig
11
build.zig
@ -59,14 +59,21 @@ pub fn build(b: *std.build.Builder) !void {
|
|||||||
"portaudio/src/common/pa_trace.c",
|
"portaudio/src/common/pa_trace.c",
|
||||||
}, &[_][]const u8{"-g", "-O3"});
|
}, &[_][]const u8{"-g", "-O3"});
|
||||||
if(target.getOsTag() == .windows) {
|
if(target.getOsTag() == .windows) {
|
||||||
// TODO: Choose a host API
|
// windows:
|
||||||
|
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/os/win/pa_win_coinitialize.c", "portaudio/src/os/win/pa_win_hostapis.c", "portaudio/src/os/win/pa_win_util.c", "portaudio/src/os/win/pa_win_waveformat.c", "portaudio/src/os/win/pa_win_wdmks_utils.c", "portaudio/src/os/win/pa_x86_plain_converters.c", }, &[_][]const u8{"-g", "-O3", "-DPA_USE_WASAPI"});
|
||||||
|
exe.addIncludePath("portaudio/src/os/win");
|
||||||
|
exe.linkSystemLibrary("ole32");
|
||||||
|
exe.linkSystemLibrary("winmm");
|
||||||
|
exe.linkSystemLibrary("uuid");
|
||||||
|
// WASAPI:
|
||||||
|
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/hostapi/wasapi/pa_win_wasapi.c"}, &[_][]const u8{"-g", "-O3"});
|
||||||
} else if(target.getOsTag() == .linux) {
|
} else if(target.getOsTag() == .linux) {
|
||||||
// unix:
|
// unix:
|
||||||
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/os/unix/pa_unix_hostapis.c", "portaudio/src/os/unix/pa_unix_util.c"}, &[_][]const u8{"-g", "-O3", "-DPA_USE_ALSA"});
|
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/os/unix/pa_unix_hostapis.c", "portaudio/src/os/unix/pa_unix_util.c"}, &[_][]const u8{"-g", "-O3", "-DPA_USE_ALSA"});
|
||||||
exe.addIncludePath("portaudio/src/os/unix");
|
exe.addIncludePath("portaudio/src/os/unix");
|
||||||
// ALSA:
|
// ALSA:
|
||||||
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/hostapi/alsa/pa_linux_alsa.c"}, &[_][]const u8{"-g", "-O3"});
|
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/hostapi/alsa/pa_linux_alsa.c"}, &[_][]const u8{"-g", "-O3"});
|
||||||
exe.linkSystemLibrary("alsa");
|
exe.linkSystemLibrary("asound");
|
||||||
} else {
|
} else {
|
||||||
std.log.err("Unsupported target: {}\n", .{ target.getOsTag() });
|
std.log.err("Unsupported target: {}\n", .{ target.getOsTag() });
|
||||||
}
|
}
|
||||||
|
@ -60,14 +60,32 @@ const Socket = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn receive(self: Socket, buffer: []u8, timeout: i32, resultAddress: *Address) ![]u8 {
|
fn receive(self: Socket, buffer: []u8, timeout: i32, resultAddress: *Address) ![]u8 {
|
||||||
|
if(builtin.os.tag == .windows) { // Of course Windows always has it's own special thing.
|
||||||
|
var pfd = [1]os.pollfd {
|
||||||
|
.{.fd = self.socketID, .events = std.c.POLL.RDNORM | std.c.POLL.RDBAND, .revents = undefined},
|
||||||
|
};
|
||||||
|
const length = os.windows.ws2_32.WSAPoll(&pfd, pfd.len, timeout); // TODO: #16122
|
||||||
|
if (length == os.windows.ws2_32.SOCKET_ERROR) {
|
||||||
|
switch (os.windows.ws2_32.WSAGetLastError()) {
|
||||||
|
.WSANOTINITIALISED => unreachable,
|
||||||
|
.WSAENETDOWN => return error.NetworkSubsystemFailed,
|
||||||
|
.WSAENOBUFS => return error.SystemResources,
|
||||||
|
// TODO: handle more errors
|
||||||
|
else => |err| return os.windows.unexpectedWSAError(err),
|
||||||
|
}
|
||||||
|
} else if(length == 0) {
|
||||||
|
return error.Timeout;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
var pfd = [1]os.pollfd {
|
var pfd = [1]os.pollfd {
|
||||||
.{.fd = self.socketID, .events = os.POLL.IN, .revents = undefined},
|
.{.fd = self.socketID, .events = os.POLL.IN, .revents = undefined},
|
||||||
};
|
};
|
||||||
var length = try os.poll(&pfd, timeout);
|
const length = try os.poll(&pfd, timeout);
|
||||||
if(length == 0) return error.Timeout;
|
if(length == 0) return error.Timeout; return error.Timeout;
|
||||||
|
}
|
||||||
var addr: os.sockaddr.in = undefined;
|
var addr: os.sockaddr.in = undefined;
|
||||||
var addrLen: os.socklen_t = @sizeOf(os.sockaddr.in);
|
var addrLen: os.socklen_t = @sizeOf(os.sockaddr.in);
|
||||||
length = try os.recvfrom(self.socketID, buffer, 0, @ptrCast(*os.sockaddr, &addr), &addrLen);
|
const length = try os.recvfrom(self.socketID, buffer, 0, @ptrCast(*os.sockaddr, &addr), &addrLen);
|
||||||
resultAddress.ip = addr.addr;
|
resultAddress.ip = addr.addr;
|
||||||
resultAddress.port = @byteSwap(addr.port);
|
resultAddress.port = @byteSwap(addr.port);
|
||||||
return buffer[0..length];
|
return buffer[0..length];
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
const main = @import("main.zig");
|
const main = @import("main.zig");
|
||||||
|
|
||||||
@ -29,6 +30,14 @@ pub const Compression = struct {
|
|||||||
while(try walker.next()) |entry| {
|
while(try walker.next()) |entry| {
|
||||||
if(entry.kind == .file) {
|
if(entry.kind == .file) {
|
||||||
var relPath = entry.path;
|
var relPath = entry.path;
|
||||||
|
if(builtin.os.tag == .windows) { // I hate you
|
||||||
|
const copy = try main.threadAllocator.dupe(u8, relPath);
|
||||||
|
std.mem.replaceScalar(u8, copy, '\\', '/');
|
||||||
|
relPath = copy;
|
||||||
|
}
|
||||||
|
defer if(builtin.os.tag == .windows) {
|
||||||
|
main.threadAllocator.free(relPath);
|
||||||
|
};
|
||||||
var len: [4]u8 = undefined;
|
var len: [4]u8 = undefined;
|
||||||
std.mem.writeIntBig(u32, &len, @intCast(u32, relPath.len));
|
std.mem.writeIntBig(u32, &len, @intCast(u32, relPath.len));
|
||||||
_ = try comp.write(&len);
|
_ = try comp.write(&len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user