Cornell Cocos
Cornell Extensions to Cocos2d
All Classes Functions Variables Enumerations Enumerator Friends
CUTimestamp.h
1 //
2 // CUTimestamp.h
3 // Cornell Extensions to Cocos2D
4 //
5 // This module simplifies timestamp support a bit. Accurate timestamp support
6 // is necessary for touch and mouse support, but timestamps requires some really
7 // arcane C++11.
8 //
9 // Author: Walker White
10 // Version: 12/5/15
11 //
12 #ifndef __CU_TIMESTAMP_H__
13 #define __CU_TIMESTAMP_H__
14 
15 NS_CC_BEGIN
16 
18 typedef std::chrono::high_resolution_clock::time_point timestamp_t;
19 
25 inline timestamp_t current_time() { return std::chrono::high_resolution_clock::now(); }
26 
35 inline long elapsed_millis(timestamp_t start, timestamp_t end) {
36  auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start);
37  return (long)elapsed.count();
38 }
39 
48 inline long elapsed_micros(timestamp_t start, timestamp_t end) {
49  auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end-start);
50  return (long)elapsed.count();
51 }
52 
61 inline long elapsed_nanos(timestamp_t start, timestamp_t end) {
62  auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end-start);
63  return (long)elapsed.count();
64 }
65 
66 NS_CC_END
67 #endif /* defined(__CU_TIMESTAMP_H__) */
68