123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- /*
- * 2D Physic Engine
- * timeprobe.h: Simple time probe
- * Based on pikuma.com Learn Game Physics Engine Programming course.
- * Copyright (c) 2022 986-Studio. All rights reserved.
- *
- * Created by Manoël Trapier on 13/06/2022.
- */
- #ifndef PHYSICENGINE_TIMEPROBE_H
- #define PHYSICENGINE_TIMEPROBE_H
- #include <stdint.h>
- #include <sys/time.h>
- class timeProbe
- {
- private:
- double time;
- uint32_t tick;
- static uint32_t getMicroSecTime()
- {
- struct timeval curTime;
- gettimeofday(&curTime, nullptr);
- return ((curTime.tv_sec) * 1000 * 1000) + (curTime.tv_usec);
- }
- public:
- timeProbe() : time(0), tick(0) {};
- void start()
- {
- this->tick = this->getMicroSecTime();
- }
- void stop()
- {
- this->time = (this->time + (getMicroSecTime() - this->tick) / 1000.) / 2.0;
- }
- double get()
- {
- return this->time;
- }
- };
- #endif /* PHYSICENGINE_TIMEPROBE_H */
|