Initial commit

This commit is contained in:
kayomn 2022-08-10 14:52:16 +01:00
commit c2cf7c965a
5 changed files with 108 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
**/zig-out/
**/zig-cache/

14
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"editor.rulers": [100],
"files.exclude":{
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/zig-cache": true,
"**/zig-out": true,
},
}

15
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Ona",
"type": "shell",
"command": "zig build",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

33
build.zig Normal file
View File

@ -0,0 +1,33 @@
const std = @import("std");
pub fn build(builder: *std.build.Builder) void {
const target = builder.standardTargetOptions(.{});
const mode = builder.standardReleaseOptions();
// Ona executable.
{
const ona_exe = builder.addExecutable("ona", "src/main.zig");
ona_exe.setTarget(target);
ona_exe.setBuildMode(mode);
ona_exe.install();
ona_exe.linkSystemLibrary("sdl2");
const run_cmd = ona_exe.run();
run_cmd.step.dependOn(builder.getInstallStep());
if (builder.args) |args| run_cmd.addArgs(args);
builder.step("run", "Run Ona application").dependOn(&run_cmd.step);
}
// Ona tests.
{
const ona_tests = builder.addTest("src/main.zig");
ona_tests.setTarget(target);
ona_tests.setBuildMode(mode);
builder.step("test", "Run Ona unit tests").dependOn(&ona_tests.step);
}
}

44
src/main.zig Normal file
View File

@ -0,0 +1,44 @@
const c = @cImport({
@cInclude("SDL2/SDL.h");
});
const std = @import("std");
pub fn main() anyerror!void {
if (c.SDL_Init(c.SDL_INIT_EVERYTHING) != 0) {
c.SDL_LogCritical(c.SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize SDL2");
return error.SystemFailure;
}
defer c.SDL_Quit();
const sdl_window = create_sdl_window: {
const pos = c.SDL_WINDOWPOS_UNDEFINED;
var flags = @as(u32, 0);
break: create_sdl_window c.SDL_CreateWindow("Ona", pos, pos, 640, 480, flags);
};
if (sdl_window == null) {
c.SDL_LogCritical(c.SDL_LOG_CATEGORY_APPLICATION, "Failed to create window");
return error.SystemFailure;
}
defer c.SDL_DestroyWindow(sdl_window);
var is_running = true;
while (is_running) {
var sdl_event = std.mem.zeroes(c.SDL_Event);
while (c.SDL_PollEvent(&sdl_event) != 0) {
switch (sdl_event.type) {
c.SDL_QUIT => is_running = false,
else => {},
}
}
}
}