const ext = @cImport({ @cInclude("SDL2/SDL.h"); }); const io = @import("./io.zig"); const stack = @import("./stack.zig"); const std = @import("std"); const sys = @import("./sys.zig"); /// /// Entry point. /// pub fn main() anyerror!void { if (ext.SDL_Init(ext.SDL_INIT_EVERYTHING) != 0) { ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize SDL2 runtime"); return error.InitFailure; } defer ext.SDL_Quit(); const pref_path = create_pref_path: { const path = ext.SDL_GetPrefPath("ona", "ona") orelse { ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to load user path"); return error.InitFailure; }; break: create_pref_path path[0 .. std.mem.len(path)]; }; defer ext.SDL_free(pref_path.ptr); const window = create_window: { const pos = ext.SDL_WINDOWPOS_UNDEFINED; var flags = @as(u32, 0); break: create_window ext.SDL_CreateWindow("Ona", pos, pos, 640, 480, flags) orelse { ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to load SDL2 window"); return error.InitFailure; }; }; defer ext.SDL_DestroyWindow(window); const renderer = create_renderer: { var flags = @as(u32, 0); break: create_renderer ext.SDL_CreateRenderer(window, -1, flags) orelse { ext.SDL_LogCritical(ext.SDL_LOG_CATEGORY_APPLICATION, "Failed to load SDL2 renderer"); return error.InitFailure; }; }; defer ext.SDL_DestroyRenderer(renderer); var event_loop = sys.EventLoop{}; var is_running = true; while (is_running) { var event = std.mem.zeroes(ext.SDL_Event); while (ext.SDL_PollEvent(&event) != 0) { switch (event.type) { ext.SDL_QUIT => is_running = false, else => {}, } } if (ext.SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255) != 0) { ext.SDL_LogError(ext.SDL_LOG_CATEGORY_VIDEO, ext.SDL_GetError()); ext.SDL_ClearError(); } if (ext.SDL_RenderClear(renderer) != 0) { ext.SDL_LogError(ext.SDL_LOG_CATEGORY_VIDEO, ext.SDL_GetError()); ext.SDL_ClearError(); } ext.SDL_RenderPresent(renderer); event_loop.tick(); ext.SDL_Delay(1); } }