update to latest zig

This commit is contained in:
Andrew Kelley 2018-07-04 12:06:20 -04:00
parent a4c4a42e0a
commit ccb18ace37

View File

@ -3,7 +3,6 @@ const c = @cImport({
}); });
const assert = @import("std").debug.assert; const assert = @import("std").debug.assert;
// See https://github.com/zig-lang/zig/issues/565 // See https://github.com/zig-lang/zig/issues/565
// SDL_video.h:#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0) // SDL_video.h:#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0)
// SDL_video.h:#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X)) // SDL_video.h:#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X))
@ -31,37 +30,36 @@ pub fn main() !void {
} }
defer c.SDL_Quit(); defer c.SDL_Quit();
const screen = c.SDL_CreateWindow(c"My Game Window", const screen = c.SDL_CreateWindow(c"My Game Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 300, 73, c.SDL_WINDOW_OPENGL) orelse
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
300, 73,
c.SDL_WINDOW_OPENGL) ??
{ {
c.SDL_Log(c"Unable to create window: %s", c.SDL_GetError()); c.SDL_Log(c"Unable to create window: %s", c.SDL_GetError());
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
}; };
defer c.SDL_DestroyWindow(screen); defer c.SDL_DestroyWindow(screen);
const renderer = c.SDL_CreateRenderer(screen, -1, 0) ?? { const renderer = c.SDL_CreateRenderer(screen, -1, 0) orelse {
c.SDL_Log(c"Unable to create renderer: %s", c.SDL_GetError()); c.SDL_Log(c"Unable to create renderer: %s", c.SDL_GetError());
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
}; };
defer c.SDL_DestroyRenderer(renderer); defer c.SDL_DestroyRenderer(renderer);
const zig_bmp = @embedFile("zig.bmp"); const zig_bmp = @embedFile("zig.bmp");
const rw = c.SDL_RWFromConstMem(@ptrCast(*const c_void, &zig_bmp[0]), c_int(zig_bmp.len)) ?? { const rw = c.SDL_RWFromConstMem(
@ptrCast(*const c_void, &zig_bmp[0]),
@intCast(c_int, zig_bmp.len),
) orelse {
c.SDL_Log(c"Unable to get RWFromConstMem: %s", c.SDL_GetError()); c.SDL_Log(c"Unable to get RWFromConstMem: %s", c.SDL_GetError());
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
}; };
defer assert(SDL_RWclose(rw) == 0); defer assert(SDL_RWclose(rw) == 0);
const zig_surface = c.SDL_LoadBMP_RW(rw, 0) ?? { const zig_surface = c.SDL_LoadBMP_RW(rw, 0) orelse {
c.SDL_Log(c"Unable to load bmp: %s", c.SDL_GetError()); c.SDL_Log(c"Unable to load bmp: %s", c.SDL_GetError());
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
}; };
defer c.SDL_FreeSurface(zig_surface); defer c.SDL_FreeSurface(zig_surface);
const zig_texture = c.SDL_CreateTextureFromSurface(renderer, zig_surface) ?? { const zig_texture = c.SDL_CreateTextureFromSurface(renderer, zig_surface) orelse {
c.SDL_Log(c"Unable to create texture from surface: %s", c.SDL_GetError()); c.SDL_Log(c"Unable to create texture from surface: %s", c.SDL_GetError());
return error.SDLInitializationFailed; return error.SDLInitializationFailed;
}; };