Skip to content

Commit

Permalink
it worky :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Beyley committed Mar 7, 2024
1 parent 0c6388d commit 3ca2523
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 35 deletions.
37 changes: 23 additions & 14 deletions game/app.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const AudioTracker = @import("audio_tracker.zig");

pub const App = @This();

pub const mach_core_options = core.ComptimeOptions{
.use_wgpu = true,
.use_sysgpu = false,
};

is_running: bool,
///The tracker for our audio state
audio_tracker: AudioTracker,
Expand Down Expand Up @@ -44,16 +49,17 @@ fontstash: Fontstash,
screen_stack: ScreenStack,

pub fn init(app: *App) !void {
const config = try Config.readConfig();

const width: u32 = @intFromFloat(640 * config.window_scale);
const height: u32 = @intFromFloat(480 * config.window_scale);

try core.init(.{
.title = "ilo nanpa pi ilo nanpa",
.power_preference = .low_power,
.size = .{ .width = width, .height = height },
});

const config = try Config.readConfig();

//Initialize our graphics
var gfx: Gfx = try Gfx.init(app.config);

app.* = .{
.is_running = true,
.audio_tracker = .{
Expand All @@ -66,38 +72,40 @@ pub fn init(app: *App) !void {
.counter_curr = 0,
.config = config,
.name = undefined,
.gfx = try Gfx.init(config),
.gfx = try Gfx.init(app.config),
.texture = try Gfx.createTexture(core.allocator, @embedFile("content/atlas.qoi")),
.renderer = undefined,
.fontstash = undefined,
.screen_stack = ScreenStack.init(core.allocator),
};
std.debug.print("loaded {d} maps!\n", .{app.map_list.len});

const bass_window_ptr: usize = 0;
const bass_window_ptr: usize = if (builtin.os.tag == .windows)
core.nativeWindowWin32()
else
0;

try bass.init(.default, null, .{}, bass_window_ptr);
defer bass.deinit();

try bass.setConfig(.global_stream_volume, @intFromFloat(app.config.volume * 10000));

//Create the bind group for the texture
// try texture.createBindGroup(gfx.device, gfx.sampler, gfx.bind_group_layouts);
try app.texture.createBindGroup(app.gfx.sampler, app.gfx.bind_group_layouts);

gfx.updateProjectionMatrixBuffer();
app.gfx.updateProjectionMatrixBuffer();

//Init the renderer
app.renderer = try Renderer.init(core.allocator, &gfx, app.texture);
app.renderer = try Renderer.init(core.allocator, &app.gfx, app.texture);

//Init the font stash
try app.fontstash.init(&app.gfx, core.allocator);

//Load the main menu
try app.screen_stack.load(&Screen.MainMenu.MainMenu, gfx, app);
try app.screen_stack.load(&Screen.MainMenu.MainMenu, app.gfx, app);
}

pub fn deinit(app: *App) void {
defer core.deinit();
defer bass.deinit();
defer app.gfx.deinit();
defer app.texture.deinit();
defer app.fontstash.deinit();
Expand Down Expand Up @@ -125,8 +133,9 @@ pub fn deinit(app: *App) void {
app.convert.deinit();
}

app.gfx.deinit();
app.renderer.deinit();

core.deinit();
}

pub fn update(app: *App) !bool {
Expand Down
15 changes: 12 additions & 3 deletions game/gfx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn init(config: Config) !Self {
.min = .{ .width = width, .height = height },
.max = .{ .width = width, .height = height },
});
core.setSize(.{ .width = width, .height = height });
// core.setSize(.{ .width = width, .height = height });

//Update the viewport
self.viewport = RectU{ 0, 0, @intCast(width), @intCast(height) };
Expand All @@ -153,12 +153,22 @@ pub fn init(config: Config) !Self {

//Create the projection matrix buffer
self.projection_matrix_buffer = try createBuffer(math.Mat4x4, 1, .{ .uniform = true, .copy_dst = true });
std.debug.print("got proj matrix buffer {*}\n", .{self.projection_matrix_buffer});

//Create the projection matrix bind group
self.projection_matrix_bind_group = core.device.createBindGroup(&core.gpu.BindGroup.Descriptor.init(.{
.label = "Projection Matrix Bind Group",
.layout = self.bind_group_layouts.projection_matrix,
.entries = &.{core.gpu.BindGroup.Entry.buffer(0, self.projection_matrix_buffer, 0, @sizeOf(math.Mat4x4))},
.entries = &.{
core.gpu.BindGroup.Entry.buffer(
0,
self.projection_matrix_buffer,
0,
@sizeOf(math.Mat4x4),
// REENABLE THIS TO FIX SYSGPU
// @sizeOf(math.Mat4x4),
),
},
}));
std.debug.print("got projection matrix bind group {*}\n", .{self.projection_matrix_bind_group});

Expand Down Expand Up @@ -540,7 +550,6 @@ pub fn updateProjectionMatrixBuffer(self: *Self) void {
1,
);

std.debug.print("thsathss {}\n", .{mat});
core.queue.writeBuffer(self.projection_matrix_buffer, 0, &[_]math.Mat4x4{mat});
}

Expand Down
2 changes: 1 addition & 1 deletion game/screens/main_menu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn renderScreen(self: *Screen, render_state: RenderState) anyerror!void {

_ = try render_state.fontstash.drawText(
.{ Screen.display_width - 10, Screen.display_height - 10 },
"(c)2023 Beyley",
"(c)2024 Beyley",
.{
.font = Fontstash.Gothic,
.size = Fontstash.ptToPx(16),
Expand Down
35 changes: 18 additions & 17 deletions game/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn vs_main(
) -> VertexOutputs {
var output: VertexOutputs;

output.position = projection_matrix * vec4<f32>(pos, 0.0, 1.0);
output.position = vec4<f32>(pos, 0.0, 1.0) * projection_matrix;
output.tex_coord = tex_coord;
output.vertex_col = vertex_col;

Expand All @@ -44,23 +44,24 @@ fn fs_main(input: FragmentInputs) -> @location(0) vec4<f32> {

fn toLinear(sRGB: vec4<f32>) -> vec4<f32>
{
var cutoff: vec4<f32> = vec4<f32>(0.0);
return sRGB;
// var cutoff: vec4<f32> = vec4<f32>(0.0);

if(sRGB.r < 0.04045) {
cutoff.r = 1.0;
}
if(sRGB.g < 0.04045) {
cutoff.g = 1.0;
}
if(sRGB.b < 0.04045) {
cutoff.b = 1.0;
}
if(sRGB.a < 0.04045) {
cutoff.a = 1.0;
}
// if(sRGB.r < 0.04045) {
// cutoff.r = 1.0;
// }
// if(sRGB.g < 0.04045) {
// cutoff.g = 1.0;
// }
// if(sRGB.b < 0.04045) {
// cutoff.b = 1.0;
// }
// if(sRGB.a < 0.04045) {
// cutoff.a = 1.0;
// }

var higher: vec4<f32> = pow((sRGB + vec4<f32>(0.055))/vec4<f32>(1.055), vec4<f32>(2.4));
var lower: vec4<f32> = sRGB/vec4<f32>(12.92);
// var higher: vec4<f32> = pow((sRGB + vec4<f32>(0.055))/vec4<f32>(1.055), vec4<f32>(2.4));
// var lower: vec4<f32> = sRGB/vec4<f32>(12.92);

return mix(higher, lower, cutoff);
// return mix(higher, lower, cutoff);
}

0 comments on commit 3ca2523

Please sign in to comment.