Fix framerate issue
This commit is contained in:
parent
e4f7fca02d
commit
acc3cd890d
|
@ -53,8 +53,8 @@ fn getTab(self: *Self) MenuTab {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tick(self: *Self) State {
|
pub fn tick(self: *Self) State {
|
||||||
const sel = self.getSel();
|
//const sel = self.getSel();
|
||||||
const tab = self.getTab();
|
//const tab = self.getTab();
|
||||||
var key_state = SDL.getKeyboardState();
|
var key_state = SDL.getKeyboardState();
|
||||||
|
|
||||||
for (self.action_list) |*action| {
|
for (self.action_list) |*action| {
|
||||||
|
@ -72,11 +72,11 @@ pub fn tick(self: *Self) State {
|
||||||
action.*.call(self);
|
action.*.call(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std.debug.print(
|
//std.debug.print(
|
||||||
\\Tab: {s}
|
//\\Tab: {s}
|
||||||
\\Selection: {s}
|
//\\Selection: {s}
|
||||||
\\
|
//\\
|
||||||
, .{ tab.name, sel.name });
|
//, .{ tab.name, sel.name });
|
||||||
return self.state;
|
return self.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,10 @@ pub fn init() !Self {
|
||||||
try sdl.gl.setAttribute(.{ .multisamplebuffers = true });
|
try sdl.gl.setAttribute(.{ .multisamplebuffers = true });
|
||||||
try sdl.gl.setAttribute(.{ .multisamplesamples = 4 });
|
try sdl.gl.setAttribute(.{ .multisamplesamples = 4 });
|
||||||
|
|
||||||
const window = try sdl.createWindow(
|
const window = try sdl.createWindow("USG", .{ .centered = {} }, .{ .centered = {} }, 1280, 720, .{ .context = .opengl, .vis = .shown });
|
||||||
"USG",
|
|
||||||
.{ .centered = {} },
|
|
||||||
.{ .centered = {} },
|
|
||||||
1280,
|
|
||||||
720,
|
|
||||||
.{ .context = .opengl, .vis = .shown }
|
|
||||||
);
|
|
||||||
|
|
||||||
const ctx = try sdl.gl.createContext(window);
|
const ctx = try sdl.gl.createContext(window);
|
||||||
|
_ = try sdl.gl.setSwapInterval(.immediate);
|
||||||
|
|
||||||
var mvp_loc: u32 = undefined;
|
var mvp_loc: u32 = undefined;
|
||||||
var color_loc: u32 = undefined;
|
var color_loc: u32 = undefined;
|
||||||
|
@ -73,13 +67,7 @@ pub fn init() !Self {
|
||||||
gl.enable(.blend);
|
gl.enable(.blend);
|
||||||
gl.blendFunc(.src_alpha, .one_minus_src_alpha);
|
gl.blendFunc(.src_alpha, .one_minus_src_alpha);
|
||||||
|
|
||||||
return Self{
|
return Self{ .window = window, .context = ctx, .color_loc = color_loc, .buffer = buf, .color = .{ 0, 0, 0, 0 } };
|
||||||
.window = window,
|
|
||||||
.context = ctx,
|
|
||||||
.color_loc = color_loc,
|
|
||||||
.buffer = buf,
|
|
||||||
.color = .{0,0,0,0}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(self: Self) void {
|
pub fn render(self: Self) void {
|
||||||
|
|
10
src/main.zig
10
src/main.zig
|
@ -19,6 +19,8 @@ pub fn main() !void {
|
||||||
try SDL.image.init(.{ .jpg = true });
|
try SDL.image.init(.{ .jpg = true });
|
||||||
|
|
||||||
mainLoop: while (true) {
|
mainLoop: while (true) {
|
||||||
|
const start = SDL.getTicks64();
|
||||||
|
|
||||||
while (SDL.pollEvent()) |ev| {
|
while (SDL.pollEvent()) |ev| {
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
.quit => break :mainLoop,
|
.quit => break :mainLoop,
|
||||||
|
@ -26,20 +28,18 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const start = SDL.getTicks64();
|
|
||||||
|
|
||||||
current_state = switch (current_state) {
|
current_state = switch (current_state) {
|
||||||
.main_menu => main_menu.tick(),
|
.main_menu => main_menu.tick(),
|
||||||
.game => game.tick(),
|
.game => game.tick(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
renderer.render();
|
renderer.render();
|
||||||
|
|
||||||
const delay = SDL.getTicks64() - start;
|
const delay = SDL.getTicks64() - start;
|
||||||
|
|
||||||
std.debug.print("{} ms\n", .{delay});
|
std.debug.print("{} ms\n", .{delay});
|
||||||
if (delay < 15) {
|
if (delay < 16) {
|
||||||
SDL.delay(15 - @intCast(u32, delay));
|
SDL.delay(16 - @intCast(u32, delay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue