From 2420efab8a4c92a52dad27b94da1d1a85d234fa0 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 22 Nov 2024 20:31:11 +0100 Subject: [PATCH] pulled audio in own thread, not working --- audio/Audio.cpp | 6 +++++- gpuapi/RenderUtils.h | 23 +++++++++++++---------- models/settings/setting_types.h | 3 ++- platform/win32/UtilsWin32.h | 22 ++++++++++++++++++++-- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/audio/Audio.cpp b/audio/Audio.cpp index c3407af..ca6dfe7 100644 --- a/audio/Audio.cpp +++ b/audio/Audio.cpp @@ -33,7 +33,11 @@ void audio_from_file(RingMemory* ring, const char* path, Audio* audio) } inline -void audio_fill_buffer(AudioSetting* setting, uint32 to_fill, Audio* sound, int16* buffer1, int32 buffer1_size, int16* buffer2 = NULL, int32 buffer2_size = 0) +void audio_fill_buffer( + AudioSetting* setting, uint32 to_fill, const Audio* sound, + int16* buffer1, int32 buffer1_size, + int16* buffer2 = NULL, int32 buffer2_size = 0 +) { uint32 limit = to_fill / setting->sample_size; buffer1_size /= setting->sample_size; diff --git a/gpuapi/RenderUtils.h b/gpuapi/RenderUtils.h index 8a643cf..c22d1bd 100644 --- a/gpuapi/RenderUtils.h +++ b/gpuapi/RenderUtils.h @@ -23,6 +23,9 @@ // @performance Create improved vertice generation for components (input + button, chat, ...) where we don't use as many // degenerate triangled +// @todo in many places we use ->value_int. We should load it as a value_float and also define it as float in the theme. +// This way we wouldn't have to convert the value + inline void vertex_degenerate_create( Vertex3DTextureColorIndex* __restrict vertices, uint32* __restrict index, f32 zindex, @@ -53,7 +56,7 @@ inline void vertex_line_create( Vertex3DTextureColorIndex* __restrict vertices, uint32* __restrict index, f32 zindex, f32 x1, f32 y1, f32 x2, f32 y2, f32 thickness, int32 align_h, int32 align_v, - uint32 color_index = 0, f32 tex_x1 = 0.0f, f32 tex_y1 = 0.0f, f32 tex_x2 = 0.0f, f32 tex_y2 = 0.0f + f32 color_index = 0, f32 tex_x1 = 0.0f, f32 tex_y1 = 0.0f, f32 tex_x2 = 0.0f, f32 tex_y2 = 0.0f ) { if (align_h == UI_ALIGN_H_RIGHT) { x1 -= thickness; @@ -132,7 +135,7 @@ inline void vertex_rect_create( Vertex3DTextureColorIndex* __restrict vertices, uint32* __restrict index, f32 zindex, f32 x, f32 y, f32 width, f32 height, int32 align_h, int32 align_v, - uint32 color_index = 0, f32 tex_x1 = 0.0f, f32 tex_y1 = 0.0f, f32 tex_x2 = 0.0f, f32 tex_y2 = 0.0f + f32 color_index = 0, f32 tex_x1 = 0.0f, f32 tex_y1 = 0.0f, f32 tex_x2 = 0.0f, f32 tex_y2 = 0.0f ) { if (align_h == UI_ALIGN_H_RIGHT) { x -= width; @@ -189,7 +192,7 @@ inline void vertex_rect_border_create( Vertex3DTextureColorIndex* __restrict vertices, uint32* __restrict index, f32 zindex, f32 x, f32 y, f32 width, f32 height, f32 thickness, int32 align_h, int32 align_v, - uint32 color_index = 0, f32 tex_x1 = 0.0f, f32 tex_y1 = 0.0f, f32 tex_x2 = 0.0f, f32 tex_y2 = 0.0f + f32 color_index = 0, f32 tex_x1 = 0.0f, f32 tex_y1 = 0.0f, f32 tex_x2 = 0.0f, f32 tex_y2 = 0.0f ) { if (align_h == UI_ALIGN_H_RIGHT) { x -= width; @@ -325,7 +328,7 @@ void vertex_rect_border_create( void vertex_input(Vertex3DTextureColorIndex* __restrict vertices, uint32* __restrict index, f32 zindex, f32 x, f32 y, f32 width, f32 height, int32 align_h, int32 align_v, - uint32 color_index = 0, f32 tex_x1 = 0.0f, f32 tex_y1 = 0.0f, f32 tex_x2 = 0.0f, f32 tex_y2 = 0.0f + f32 color_index = 0, f32 tex_x1 = 0.0f, f32 tex_y1 = 0.0f, f32 tex_x2 = 0.0f, f32 tex_y2 = 0.0f ) { vertex_rect_border_create( @@ -473,7 +476,7 @@ void text_calculate_dimensions( f32 vertex_text_create( Vertex3DTextureColorIndex* __restrict vertices, uint32* __restrict index, f32 zindex, f32 x, f32 y, f32 width, f32 height, int32 align_h, int32 align_v, - const Font* __restrict font, const char* __restrict text, f32 size, uint32 color_index = 0 + const Font* __restrict font, const char* __restrict text, f32 size, f32 color_index = 0 ) { int32 length = utf8_strlen(text); bool is_ascii = strlen(text) == length; @@ -619,8 +622,8 @@ f32 ui_text_create( // If we do a different alignment we need to pre-calculate the width and height if (align_h != NULL || align_v != NULL) { - f32 tmp_width = width->value_int; - f32 tmp_height = height->value_int; + f32 tmp_width = (f32) width->value_int; + f32 tmp_height = (f32) height->value_int; if (align_h != NULL && align_v != NULL) { text_calculate_dimensions(&tmp_width, &tmp_height, &theme->font, text->value_str, is_ascii, scale, length); @@ -646,14 +649,14 @@ f32 ui_text_create( uint32 first_glyph = theme->font.glyphs[0].codepoint; int32 start = *index; - f32 offset_x = x->value_int; - f32 offset_y = y->value_int; + f32 offset_x = (f32) x->value_int; + f32 offset_y = (f32) y->value_int; for (int32 i = 0; i < length; ++i) { int32 character = is_ascii ? text->value_str[i] : utf8_get_char_at(text->value_str, i); if (character == '\n') { offset_y += theme->font.line_height * scale; - offset_x = x->value_int; + offset_x = (f32) x->value_int; continue; } diff --git a/models/settings/setting_types.h b/models/settings/setting_types.h index 694dfe7..e0ef300 100644 --- a/models/settings/setting_types.h +++ b/models/settings/setting_types.h @@ -67,7 +67,8 @@ #define SETTING_DEBUG_VISIBILITY_WIREFRAME 1 #define SETTING_DEBUG_VISIBILITY_DEBUG 2 -#define SETTING_DEBUG_VISIBILITY_NORMALS 4 +#define SETTING_DEBUG_VISIBILITY_3D 2048 +#define SETTING_DEBUG_VISIBILITY_NORMALS 4096 #define SETTING_UI_VISIBILITY_FPS 1 #define SETTING_UI_VISIBILITY_APM 2 diff --git a/platform/win32/UtilsWin32.h b/platform/win32/UtilsWin32.h index 9879038..5ebf283 100644 --- a/platform/win32/UtilsWin32.h +++ b/platform/win32/UtilsWin32.h @@ -23,7 +23,25 @@ #include "../../memory/RingMemory.h" #define strtok_r strtok_s -#define usleep Sleep + +void usleep(uint64 microseconds) +{ + if ((microseconds % 1000) == 0) { + Sleep((DWORD) (microseconds / 1000)); + return; + } + + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + + LARGE_INTEGER start, end; + QueryPerformanceCounter(&start); + long long target = start.QuadPart + (microseconds * frequency.QuadPart) / 1000000; + + do { + QueryPerformanceCounter(&end); + } while (end.QuadPart < target); +} inline time_t system_time() @@ -113,7 +131,7 @@ file_size(const char* path) } inline -uint64 time_ms() +uint64 time_mu() { LARGE_INTEGER frequency; LARGE_INTEGER counter;