79 lines
2.0 KiB
Zig
79 lines
2.0 KiB
Zig
const std = @import("std");
|
|
const core = @import("core");
|
|
const test_vert = @import("test.vert");
|
|
|
|
// controls glfw and general windowing
|
|
// graphics depends on this one
|
|
|
|
pub const windowing = @import("windowing.zig");
|
|
|
|
pub const Module: core.ModuleDescription = .{
|
|
.name = "platform",
|
|
.enabledByDefault = true,
|
|
};
|
|
|
|
var gPlatformInstance: *windowing.PlatformInstance = undefined;
|
|
|
|
pub fn context() *windowing.PlatformInstance {
|
|
return gPlatformInstance;
|
|
}
|
|
|
|
pub fn setupFromModule() void {
|
|
gPlatformInstance = core.getEngineObject(windowing.PlatformInstance).?;
|
|
}
|
|
|
|
pub fn getCursorPosition() core.Vector2f {
|
|
return gPlatformInstance.getCursorPosition();
|
|
}
|
|
|
|
pub fn setCursorVisible(visible: bool) void {
|
|
return gPlatformInstance.setCursorVisible(visible);
|
|
}
|
|
|
|
pub fn setMousePosition(pos: core.Vector2f) void {
|
|
gPlatformInstance.setMousePosition(pos);
|
|
}
|
|
|
|
pub fn setMouseRelativeMode(relativeMode: bool) void {
|
|
gPlatformInstance.setMouseRelativeMode(relativeMode);
|
|
}
|
|
|
|
pub fn setImguiVisible(visible: bool) void {
|
|
gPlatformInstance.imguiVisible = visible;
|
|
}
|
|
|
|
pub fn getMouseVisible() bool {
|
|
gPlatformInstance.isCursorEnabled();
|
|
}
|
|
|
|
pub fn start_module(spec: *core.SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void {
|
|
_ = args;
|
|
_ = spec;
|
|
_ = allocator;
|
|
if (core.isUtility()) {
|
|
return;
|
|
}
|
|
|
|
const parameters = windowing.PlatformParams.init();
|
|
|
|
gPlatformInstance = try core.createObject(windowing.PlatformInstance, .{}); //try allocator.create(windowing.PlatformInstance);
|
|
try gPlatformInstance.setParams(parameters);
|
|
|
|
// gPlatformInstance.* = try windowing.PlatformInstance.init(allocator, parameters);
|
|
|
|
try gPlatformInstance.setupWindow();
|
|
|
|
try gPlatformInstance.registerFuncs();
|
|
}
|
|
|
|
pub fn getInstance() *windowing.PlatformInstance {
|
|
return gPlatformInstance;
|
|
}
|
|
|
|
pub fn shutdown_module(allocator: std.mem.Allocator) void {
|
|
if (core.isUtility()) {
|
|
return;
|
|
}
|
|
_ = allocator;
|
|
}
|