MiMoEngine ASM: x86-64 MASM汇编+C混合架构游戏引擎
核心热路径(数学/内存/字符串/性能分析)用MASM汇编(SSE/AVX2) 外围系统(窗口/渲染/ECS/音频/UI/脚本)用C语言 含自研编辑器、VisualScript积木编程、中文渲染(glyph_atlas)
This commit is contained in:
commit
2d56cb3bc9
91 files changed
+9988
No files matched your search
@@ -0,0 +1,78 @@
|
||||
// ============================================================================
|
||||
// timer.c - 高精度计时器实现 (使用 rdtsc.asm)
|
||||
// ============================================================================
|
||||
|
||||
#include "timer.h"
|
||||
#include "../include/engine_api.h"
|
||||
#include <Windows.h>
|
||||
|
||||
static double g_seconds_per_count = 0.0;
|
||||
static int64_t g_prev_time = 0;
|
||||
static int64_t g_curr_time = 0;
|
||||
static int64_t g_start_time = 0;
|
||||
static double g_delta_time = 0.0;
|
||||
static double g_total_time = 0.0;
|
||||
static double g_fps = 0.0;
|
||||
static uint64_t g_frame_count = 0;
|
||||
static double g_fps_accumulator = 0.0;
|
||||
static uint64_t g_fps_frame_count = 0;
|
||||
|
||||
void timer_init(void) {
|
||||
// 使用 QueryPerformanceCounter 获取高精度时间
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
g_seconds_per_count = 1.0 / (double)freq.QuadPart;
|
||||
|
||||
LARGE_INTEGER now;
|
||||
QueryPerformanceCounter(&now);
|
||||
g_start_time = now.QuadPart;
|
||||
g_prev_time = now.QuadPart;
|
||||
g_curr_time = now.QuadPart;
|
||||
|
||||
g_delta_time = 0.0;
|
||||
g_total_time = 0.0;
|
||||
g_fps = 0.0;
|
||||
g_frame_count = 0;
|
||||
g_fps_accumulator = 0.0;
|
||||
g_fps_frame_count = 0;
|
||||
}
|
||||
|
||||
void timer_reset(void) {
|
||||
timer_init();
|
||||
}
|
||||
|
||||
void timer_tick(void) {
|
||||
LARGE_INTEGER now;
|
||||
QueryPerformanceCounter(&now);
|
||||
g_curr_time = now.QuadPart;
|
||||
|
||||
g_delta_time = (g_curr_time - g_prev_time) * g_seconds_per_count;
|
||||
g_total_time = (g_curr_time - g_start_time) * g_seconds_per_count;
|
||||
g_prev_time = g_curr_time;
|
||||
|
||||
g_frame_count++;
|
||||
g_fps_frame_count++;
|
||||
g_fps_accumulator += g_delta_time;
|
||||
|
||||
if (g_fps_accumulator >= 1.0) {
|
||||
g_fps = (double)g_fps_frame_count / g_fps_accumulator;
|
||||
g_fps_frame_count = 0;
|
||||
g_fps_accumulator = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
double timer_get_delta(void) {
|
||||
return g_delta_time;
|
||||
}
|
||||
|
||||
double timer_get_total(void) {
|
||||
return g_total_time;
|
||||
}
|
||||
|
||||
double timer_get_fps(void) {
|
||||
return g_fps;
|
||||
}
|
||||
|
||||
uint64_t timer_get_frame_count(void) {
|
||||
return g_frame_count;
|
||||
}
|
||||
Reference in new issue
Block a user