Added game file structure, game loop handler, game tickrate helper.

This commit is contained in:
Hannah 2026-01-31 06:24:59 +01:00
commit aacfe27f72
11 changed files with 129 additions and 1 deletions

View file

@ -0,0 +1,24 @@
//
// Created by Hannah on 31/01/2026.
//
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int delayTickrate(int ticksPerSecond, long int period) {
int requiredNanoseconds = 10e9/ticksPerSecond;
struct timeval currentTime;
gettimeofday(&currentTime, NULL);
printf("Nanoseconds: %ld\nCurrent:%ld\n", requiredNanoseconds,currentTime.tv_usec*1000 - period*1000);
if (currentTime.tv_usec*1000 - period*1000 < requiredNanoseconds) {
struct timespec remainingTime;
remainingTime.tv_sec = 0;
remainingTime.tv_nsec = requiredNanoseconds - (currentTime.tv_usec*1000 - period*1000);
printf("Sleeping for %dnano and %dsec with %f effective sec\n", remainingTime.tv_nsec, remainingTime.tv_sec, remainingTime.tv_nsec/10e9);
clock_nanosleep(CLOCK_MONOTONIC, 0, &remainingTime, NULL);
return 0;
}
printf("Can't delay, %d larger than required %d", currentTime.tv_usec*1000 - period*1000, requiredNanoseconds);
return 1;
}