- Scene Demo: cube + sphere + ground plane with proper lighting - Audio: XAudio2 dynamic loading + WAV playback - Physics: expanded collision system - Renderer: improved pipeline with materials - UI: extended widget system - VisualScript: enhanced serializer + block interactions - ASM: optimized math/memory/profiling routines - Window: mouse input + scroll support
146 lines
3.8 KiB
C
146 lines
3.8 KiB
C
#pragma once
|
|
|
|
// ============================================================================
|
|
// engine_api.h - C-ASM 接口头文件
|
|
// 暴露所有汇编函数给 C 代码使用
|
|
// ============================================================================
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// 当 MASM 不可用时,使用 C fallback
|
|
// math_c_fallback.h 已经定义了所有数学类型和函数
|
|
// 不需要重复声明
|
|
|
|
// ============================================================================
|
|
// memory.asm - 对齐内存分配
|
|
// ============================================================================
|
|
|
|
#if !defined(MATH_ASM_AVAILABLE) || MATH_ASM_AVAILABLE == 0
|
|
// 在 C fallback 模式下,这些函数已在 math_c_fallback.h 中定义
|
|
// 不需要重复声明
|
|
#else
|
|
void* mem_aligned_alloc(uint64_t size, uint64_t alignment);
|
|
void mem_aligned_free(void* ptr);
|
|
void* mem_aligned_realloc(void* ptr, uint64_t size, uint64_t alignment);
|
|
|
|
// ============================================================================
|
|
// string_ops.asm - 快速字符串操作
|
|
// ============================================================================
|
|
|
|
void fast_memcpy(void* dst, const void* src, uint64_t count);
|
|
void fast_memset(void* dst, int value, uint64_t count);
|
|
uint64_t fast_strlen(const char* str);
|
|
int fast_strcmp(const char* a, const char* b);
|
|
|
|
// ============================================================================
|
|
// profiling.asm - 性能分析
|
|
// ============================================================================
|
|
|
|
uint64_t prof_rdtsc(void);
|
|
double prof_cycles_to_ms(uint64_t cycles);
|
|
uint64_t prof_get_freq(void);
|
|
|
|
// 性能计时器结构
|
|
typedef struct {
|
|
uint64_t start;
|
|
uint64_t end;
|
|
double elapsed_ms;
|
|
} ProfTimer;
|
|
|
|
void prof_timer_start(ProfTimer* timer);
|
|
void prof_timer_stop(ProfTimer* timer);
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
// ============================================================================
|
|
// C++ 便利封装
|
|
// ============================================================================
|
|
|
|
#ifdef __cplusplus
|
|
|
|
// Vec3 运算符重载
|
|
inline Vec3 operator+(const Vec3& a, const Vec3& b) {
|
|
Vec3 result;
|
|
vec3_add(&a, &b, &result);
|
|
return result;
|
|
}
|
|
|
|
inline Vec3 operator-(const Vec3& a, const Vec3& b) {
|
|
Vec3 result;
|
|
vec3_sub(&a, &b, &result);
|
|
return result;
|
|
}
|
|
|
|
inline Vec3 operator*(const Vec3& a, float s) {
|
|
Vec3 result;
|
|
vec3_scale(&a, s, &result);
|
|
return result;
|
|
}
|
|
|
|
inline float dot(const Vec3& a, const Vec3& b) {
|
|
return vec3_dot(&a, &b);
|
|
}
|
|
|
|
inline Vec3 cross(const Vec3& a, const Vec3& b) {
|
|
Vec3 result;
|
|
vec3_cross(&a, &b, &result);
|
|
return result;
|
|
}
|
|
|
|
inline float length(const Vec3& a) {
|
|
return vec3_length(&a);
|
|
}
|
|
|
|
inline Vec3 normalize(const Vec3& a) {
|
|
Vec3 result;
|
|
vec3_normalize(&a, &result);
|
|
return result;
|
|
}
|
|
|
|
inline Vec3 lerp(const Vec3& a, const Vec3& b, float t) {
|
|
Vec3 result;
|
|
vec3_lerp(&a, &b, t, &result);
|
|
return result;
|
|
}
|
|
|
|
// Mat4 运算符重载
|
|
inline Mat4 operator*(const Mat4& a, const Mat4& b) {
|
|
Mat4 result;
|
|
mat4_multiply(&a, &b, &result);
|
|
return result;
|
|
}
|
|
|
|
inline Vec3 transformPoint(const Mat4& m, const Vec3& v) {
|
|
Vec3 result;
|
|
// 使用 vec4 乘法, w=1
|
|
Vec4 v4 = {v.x, v.y, v.z, 1.0f};
|
|
Vec4 r4;
|
|
// 简化: 逐行计算
|
|
result.x = m.m[0][0]*v.x + m.m[0][1]*v.y + m.m[0][2]*v.z + m.m[0][3];
|
|
result.y = m.m[1][0]*v.x + m.m[1][1]*v.y + m.m[1][2]*v.z + m.m[1][3];
|
|
result.z = m.m[2][0]*v.x + m.m[2][1]*v.y + m.m[2][2]*v.z + m.m[2][3];
|
|
return result;
|
|
}
|
|
|
|
// Quat 运算符重载
|
|
inline Quat operator*(const Quat& a, const Quat& b) {
|
|
Quat result;
|
|
quat_multiply(&a, &b, &result);
|
|
return result;
|
|
}
|
|
|
|
inline Vec3 rotate(const Quat& q, const Vec3& v) {
|
|
Vec3 result;
|
|
quat_rotate_vec3(&q, &v, &result);
|
|
return result;
|
|
}
|
|
|
|
#endif // __cplusplus
|