2011年2月4日 星期五

Time in C++ class

Source: [chrome] / trunk / src / base / time.h.

Requirement: get the current time, perform simple arithmetic.

To achieve this goal, we do the following steps:

1. In TimeDelta class, keep the following important methods: converts units of time to TimeDeltas, ToInternalValue(), returns the time delta in some unit, computations with other deltas, comparison operators.

2. In Time class, keep the following important methods: Now(), compute the difference between two times, return a new time modified by some delta, comparison operators.

3. In TimeTicks class, keep the following important methods: Now(), compute the difference between two times, modify by some time delta, return a new TimeTicks modified by some delta, comparison operators.

4. Add base/basictypes.h, base/port.h, and build/build_config.h first.

5. Add base/time.cc and platform-specified implementation (For example, we need base/time_win.cc under the Windows platform). Remove unnecessary included header files and implementations. Remove all debugging and logging codes.

Done! Time class is very important because many games need the concept of time. Keep stealing!

沒有留言:

張貼留言