summaryrefslogtreecommitdiff
path: root/src/common/timer.hpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2012-08-30 16:16:25 -0700
committerBen Longbons <b.r.longbons@gmail.com>2012-08-30 17:03:31 -0700
commit41974ae5265fbc23a06f276f9e008d5dad020e0b (patch)
tree9d595215172e87e2d83b74f7bf3430b3040e780e /src/common/timer.hpp
parent21742909143df9159b2401c3e2a39cc0b2bad620 (diff)
downloadtmwa-41974ae5265fbc23a06f276f9e008d5dad020e0b.tar.gz
tmwa-41974ae5265fbc23a06f276f9e008d5dad020e0b.tar.bz2
tmwa-41974ae5265fbc23a06f276f9e008d5dad020e0b.tar.xz
tmwa-41974ae5265fbc23a06f276f9e008d5dad020e0b.zip
Rename files for C++ conversion. Does not compile.
After updating, you can remove these files, as shown in 'git status': Untracked files: (use "git add <file>..." to include in what will be committed) src/map/magic-interpreter-lexer.c src/map/magic-interpreter-parser.c src/map/magic-interpreter-parser.h
Diffstat (limited to 'src/common/timer.hpp')
-rw-r--r--src/common/timer.hpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/common/timer.hpp b/src/common/timer.hpp
new file mode 100644
index 0000000..fdda344
--- /dev/null
+++ b/src/common/timer.hpp
@@ -0,0 +1,61 @@
+#ifndef TIMER_HPP
+#define TIMER_HPP
+
+# include "sanity.hpp"
+
+enum TIMER_TYPE
+{
+ TIMER_NONE,
+ TIMER_ONCE_AUTODEL,
+ TIMER_INTERVAL,
+};
+/// This is needed to produce a signed result when 2 ticks are subtracted
+# define DIFF_TICK(a,b) ((int32_t)((a)-(b)))
+
+// TODO replace with signed 64-bit to make code more clear and protect from the future
+typedef uint32_t tick_t;
+typedef uint32_t interval_t;
+typedef uint32_t timer_id;
+// BUG: pointers are stored in here
+typedef int32_t custom_id_t;
+typedef int32_t custom_data_t;
+typedef void (*timer_func) (timer_id, tick_t, custom_id_t, custom_data_t);
+
+struct TimerData
+{
+ /// When it will be triggered
+ tick_t tick;
+ /// What will be done
+ timer_func func;
+ /// Arbitrary data. WARNING, callers are stupid and put pointers in here
+ // Should we change to void* or intptr_t ?
+ custom_id_t id;
+ custom_data_t data;
+ /// Type of timer - 0 initially
+ enum TIMER_TYPE type;
+ /// Repeat rate
+ interval_t interval;
+};
+
+/// Server time, in milliseconds, since the epoch,
+/// but use of 32-bit integers means it wraps every 49 days.
+// The only external caller of this function is the core.c main loop, but that makes sense
+// in fact, it might make more sense if gettick() ALWAYS returned that cached value
+tick_t gettick_nocache (void);
+/// This function is called enough that it's worth caching the result for
+/// the next 255 times
+tick_t gettick (void);
+
+timer_id add_timer (tick_t, timer_func, custom_id_t, custom_data_t);
+timer_id add_timer_interval (tick_t, timer_func, custom_id_t, custom_data_t, interval_t);
+void delete_timer (timer_id, timer_func);
+
+tick_t addtick_timer (timer_id, interval_t);
+struct TimerData *get_timer (timer_id tid);
+
+/// Do all timers scheduled before tick, and return the number of milliseconds until the next timer happens
+interval_t do_timer (tick_t tick);
+
+
+
+#endif // TIMER_HPP