Skip to content

Commit

Permalink
Create a main function for the ThreadManager.
Browse files Browse the repository at this point in the history
  • Loading branch information
Makosai committed Aug 22, 2024
1 parent 066f14e commit f657eec
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ArrayList = std.ArrayList;
const transport = sustenet.transport;
const clients = sustenet.clients;

const ThreadManager = transport.ThreadManager;
const Constants = sustenet.utils.Constants;
const BaseServer = transport.BaseServer;

Expand Down Expand Up @@ -97,6 +98,22 @@ pub fn main() !void {
}
}

fn updateMain() void {
var next = std.time.milliTimestamp();

while (is_running) {
const now = std.time.milliTimestamp();
while (next < now) {
ThreadManager.updateMain();
next += Constants.MS_PER_TICK;

if (next > std.time.milliTimestamp()) {
std.time.sleep(next - std.time.milliTimestamp());
}
}
}
}

//#region Tests
test {
std.testing.refAllDecls(@This());
Expand Down

0 comments on commit f657eec

Please sign in to comment.