• Stars
    star
    39
  • Rank 670,585 (Top 14 %)
  • Language
    C
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

timers and timeline

โฑ Timer and Timeline Utils for C

C/C++ CI MSBuild Codacy Badge

This library provides an easy way to set timers and timeouts. As initial version all timers run in single runloop at seperate thread. Currently only one thread is used for all timers, because there is only one runloop. In the future multiple runloop may be allowed.

Documentation

Currently all docs can be found in headers but in the future complete docs will be published.

Javascript and Swift/Objective-C like API

setTimeout in javascript is very useful and it is now in C:

tm_settimeout(callback, arg, delay);

TODOs:

  • Improve loopkup, make timers ordered. This may reduce some lookup operations runloop
  • Tests
  • More time and timeline utils
  • More platform support

Build

Unix (Autotools)

$ sh autogen.sh
$ ./configure
$ make
$ [sudo] make install

you can grap library in .libs folder after build finished

Windows (MSBuild)

Windows related build files, project files are located in win folder, make sure you are inside tm/win folder. Code Analysis are enabled, it may take awhile to build

$ cd win
$ .\build.bat

Example usage

#include <tm/tm.h>

/* callback */
void
mytimer(tm_timer *timer) {
  printf("my timer\n");
}

void
delayed_func(void *arg) {
  printf("settimeout: %s\n", (const char *)arg);
}

int 
main(int argc, const char * argv[]) {
  tm_timer   *timer1, *timer2, *timer3;
  tm_interval start, end, elapsed;
 
  /* option 1: alloc timer and start */
  timer1 = tm_alloc(mytimer, 1.5); /* 1.5 seconds */
  tm_start(timer1);
  
  /* option 2: alloc timer and start with delay */
  timer2 = tm_alloc(mytimer, 1.5); /* 1.5 seconds */
  tm_start_at(timer2, 0.05);       /* start after 0.05 secons */
  
  /* option 3: alloc timer and start with delay */
  timer3 = tm_schedule(mytimer, 1.5, 0.05); /* same as tm_alloc + tm_start_at */
  
  /* option 4: javascript-like setTimeout */
  tm_settimeout(delayed_func, "Hello World!", 0.00001);
  
  /*
  
  if we call free here timers will be stopped 
  
  tm_free(timer1);
  tm_free(timer2);
  tm_free(timer3);

  */
  
  /* measure elapsed time */
  start = tm_time();
  
  /* do stuff */
  
  end = tm_time();
  
  elapsed = end - start;
  
  /* wait timers to finish; otherwise main thread will cause timer thread to be exited */
  tm_wait();

  return 0;
}

License

MIT. check the LICENSE file

More Repositories

1

cglm

๐Ÿ“ฝ Highly Optimized 2D / 3D Graphics Math (glm) for C
C
2,039
star
2

AssetKit

๐ŸŽจ Modern 2D/3D - Importer โ€ข Exporter โ€ข Util - Library, also known as (AssetIO)
C
178
star
3

cmt

๐ŸŽฎ C Bindings/Wrappers for Apple's METAL framework
C
156
star
4

gkern

๐ŸŽฅ Graphics Kernel: flexible, highly configurable, extensible render engine (realtime + offline)
C
96
star
5

ds

๐Ÿ”— Common Data Structures and Algorithms
C
47
star
6

gpu

๐Ÿ”ญ cross platform general purpose GPU library - optimized for rendering
C
23
star
7

json

๐Ÿ”‹ In-place lightweight JSON parser
C
23
star
8

xml

๐Ÿ”‹ In-place lightweight XML parser
C
9
star
9

phy

physics engine written in C
C
9
star
10

im

๐Ÿ“ท image loader library for fast load images especially for rendering and image analysis (In Progress)
C
8
star
11

simple-collada-viewer

A simple viewer to show how to use AssetKit, libgk, assetkit-gl and cglm libraries (with screenshot)
C
6
star
12

mathkit

C vector, matrix library (including 3d, opengl math)
C
5
star
13

libsig

Signal/Event handling lib for C/C++
C++
4
star
14

rays

Physically-based path tracer for production rendering (may include fast ray tracer as altnative render path)
C
4
star
15

asset-xchange

new file format to store 2d/3d assets for game and films
3
star
16

assetkit-gl

Bridge library for loading AssetKit to libgk
C
3
star
17

filt

Image Filter
C
2
star
18

ui

๐Ÿ–ฑ user interface library top of GPU (OpenGL/Metal/Vulkan...)
Objective-C
2
star
19

libui

Cross platform user interface (including graphics) library for C++
C++
1
star
20

netutils

Network Utils for C/C++
C
1
star
21

http

http parser and utility
C
1
star
22

sample-models

3D sample models for loaders (AssetKit) for testing purpose
1
star
23

Qt-Dispatch

C++
1
star