Skip to content

Commit c78961a

Browse files
Initial commit
0 parents  commit c78961a

36 files changed

Lines changed: 1134 additions & 0 deletions

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 HardCodeDev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Native/ultratimerwindows.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#pragma warning(disable: 6011)
2+
#include "ultratimerwindows.h"
3+
4+
#pragma region timer methods
5+
EXPORT ULTRA_TIMER_WINDOWS* create_ultra_timer_windows() {
6+
LARGE_INTEGER freq;
7+
QueryPerformanceFrequency(&freq);
8+
9+
ULTRA_TIMER_WINDOWS* timer = malloc(sizeof(ULTRA_TIMER_WINDOWS));
10+
timer->frequency = freq.QuadPart;
11+
timer->count_of_calling = 0;
12+
timer->is_running = false;
13+
timer->last_elapsed_ticks = 0;
14+
timer->total_elapsed_ticks = 0;
15+
timer->start_ticks = 0;
16+
17+
return timer;
18+
}
19+
20+
EXPORT void start_ultra_timer_windows(ULTRA_TIMER_WINDOWS* timer) {
21+
if (timer->is_running == false) {
22+
LARGE_INTEGER now;
23+
QueryPerformanceCounter(&now);
24+
25+
timer->start_ticks = now.QuadPart;
26+
timer->is_running = true;
27+
}
28+
}
29+
30+
EXPORT void stop_ultra_timer_windows(ULTRA_TIMER_WINDOWS* timer) {
31+
if (timer->is_running == true && timer != NULL) {
32+
LARGE_INTEGER now;
33+
QueryPerformanceCounter(&now);
34+
35+
int64_t elapsed_ticks = now.QuadPart - timer->start_ticks;;
36+
timer->last_elapsed_ticks = elapsed_ticks;
37+
timer->total_elapsed_ticks += elapsed_ticks;
38+
timer->count_of_calling += 1;
39+
timer->is_running = false;
40+
}
41+
}
42+
43+
EXPORT void reset_ultra_timer_windows(ULTRA_TIMER_WINDOWS* timer) {
44+
timer->count_of_calling = 0;
45+
timer->is_running = false;
46+
timer->last_elapsed_ticks = 0;
47+
timer->total_elapsed_ticks = 0;
48+
timer->start_ticks = 0;
49+
}
50+
51+
EXPORT void free_ultra_timer_windows(ULTRA_TIMER_WINDOWS* timer) {
52+
free(timer);
53+
}
54+
#pragma endregion
55+
56+
#pragma region getters
57+
EXPORT int64_t get_ultra_timer_windows_last_elapsed_ticks(ULTRA_TIMER_WINDOWS* timer) {
58+
return timer->last_elapsed_ticks;
59+
}
60+
61+
EXPORT int64_t get_ultra_timer_windows_total_elapsed_ticks(ULTRA_TIMER_WINDOWS* timer) {
62+
return timer->total_elapsed_ticks;
63+
}
64+
65+
EXPORT int64_t get_ultra_timer_windows_count_of_calling(ULTRA_TIMER_WINDOWS* timer) {
66+
return timer->count_of_calling;
67+
}
68+
69+
EXPORT int64_t get_ultra_timer_windows_frequency(ULTRA_TIMER_WINDOWS* timer) {
70+
return timer->frequency;
71+
}
72+
#pragma endregion

Native/ultratimerwindows.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include <stdint.h>
3+
#include <stdbool.h>
4+
#include <windows.h>
5+
#define EXPORT __declspec(dllexport)
6+
7+
typedef struct {
8+
int64_t start_ticks, last_elapsed_ticks, total_elapsed_ticks, count_of_calling, frequency;
9+
bool is_running;
10+
11+
} ULTRA_TIMER_WINDOWS;
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
EXPORT ULTRA_TIMER_WINDOWS* create_ultra_timer_windows();
17+
EXPORT void free_ultra_timer_windows(ULTRA_TIMER_WINDOWS* timer);
18+
EXPORT void start_ultra_timer_windows(ULTRA_TIMER_WINDOWS* timer);
19+
EXPORT void stop_ultra_timer_windows(ULTRA_TIMER_WINDOWS* timer);
20+
EXPORT void reset_ultra_timer_windows(ULTRA_TIMER_WINDOWS* timer);
21+
EXPORT int64_t get_ultra_timer_windows_last_elapsed_ticks(ULTRA_TIMER_WINDOWS* timer);
22+
EXPORT int64_t get_ultra_timer_windows_total_elapsed_ticks(ULTRA_TIMER_WINDOWS* timer);
23+
EXPORT int64_t get_ultra_timer_windows_count_of_calling(ULTRA_TIMER_WINDOWS* timer);
24+
EXPORT int64_t get_ultra_timer_windows_frequency(ULTRA_TIMER_WINDOWS* timer);
25+
#ifdef __cplusplus
26+
}
27+
#endif

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# UltraTimerWindows
2+

Unity/Plugins.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
10.5 KB
Binary file not shown.

Unity/Plugins/UltraTimerWindows.dll.meta

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Unity/Samples.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Unity/Samples~/Scenes.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)