implemented poor timing
This commit is contained in:
parent
5e7ab246fe
commit
6244999b08
4
Makefile
4
Makefile
|
@ -8,14 +8,14 @@ OBJS := $(patsubst src/%.c, out/%.o, $(SRCS))
|
||||||
|
|
||||||
ALL: $(TARGET)
|
ALL: $(TARGET)
|
||||||
|
|
||||||
$(TARGET): mkdir $(OBJS)
|
$(TARGET): mkdir $(OBJS)
|
||||||
$(CC) -o out/$@ $(filter-out $<, $^) $(LIBRARIES)
|
$(CC) -o out/$@ $(filter-out $<, $^) $(LIBRARIES)
|
||||||
|
|
||||||
mkdir:
|
mkdir:
|
||||||
mkdir -p out
|
mkdir -p out
|
||||||
|
|
||||||
out/%.o: src/%.c
|
out/%.o: src/%.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(TARGET) out
|
rm -rf $(TARGET) out
|
||||||
|
|
|
@ -69,11 +69,18 @@ int main(int argc, char** argv)
|
||||||
void* advance_counter(void* data)
|
void* advance_counter(void* data)
|
||||||
{
|
{
|
||||||
uint16_t ticks_per_quarter = *((uint32_t*)data);
|
uint16_t ticks_per_quarter = *((uint32_t*)data);
|
||||||
|
struct timespec begin, end;
|
||||||
while(!playing);
|
while(!playing);
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_REALTIME, &begin);
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
usleep((uint64_t)time_per_quarter / ticks_per_quarter);
|
clock_gettime(CLOCK_REALTIME, &end);
|
||||||
|
uint64_t diff = 1000000 * (end.tv_sec - begin.tv_sec) + (end.tv_nsec - begin.tv_nsec) / 1000;
|
||||||
|
diff -= (uint64_t)time_per_quarter / ticks_per_quarter;
|
||||||
|
diff *= (diff < (uint64_t)time_per_quarter / ticks_per_quarter);
|
||||||
|
clock_gettime(CLOCK_REALTIME, &begin);
|
||||||
|
usleep((uint64_t)time_per_quarter / ticks_per_quarter - diff);
|
||||||
current_tick++;
|
current_tick++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue