Added game file structure, game loop handler, game tickrate helper.
This commit is contained in:
parent
5e0e47b249
commit
aacfe27f72
11 changed files with 129 additions and 1 deletions
24
src/helper/tickrateHelper.c
Normal file
24
src/helper/tickrateHelper.c
Normal 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(¤tTime, 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue