diff --git a/gpuapi/RenderUtils.h b/gpuapi/RenderUtils.h index 0812f30..4d53526 100644 --- a/gpuapi/RenderUtils.h +++ b/gpuapi/RenderUtils.h @@ -276,7 +276,6 @@ void vertex_input(Vertex3DTextureColorIndex* __restrict vertices, uint32* __rest static inline f32 text_calculate_dimensions_height( - f32 height, const Font* __restrict font, const char* __restrict text, f32 scale, int32 length ) { f32 line_height = font->line_height * scale; @@ -295,7 +294,6 @@ f32 text_calculate_dimensions_height( static inline f32 text_calculate_dimensions_width( - f32 width, const Font* __restrict font, const char* __restrict text, bool is_ascii, f32 scale, int32 length ) { f32 x = 0; @@ -316,7 +314,7 @@ f32 text_calculate_dimensions_width( } Glyph* glyph = NULL; - // We try to jump t othe correct glyph based on the glyph codepoint + // We try to jump to the correct glyph based on the glyph codepoint // If that doesn't work we iterate the glyph list BUT only until the last possible match (glyphs must be sorted ascending) int32 perfect_glyph_pos = character - first_glyph; if (font->glyph_count > perfect_glyph_pos @@ -372,7 +370,7 @@ void text_calculate_dimensions( } Glyph* glyph = NULL; - // We try to jump t othe correct glyph based on the glyph codepoint + // We try to jump to the correct glyph based on the glyph codepoint // If that doesn't work we iterate the glyph list BUT only until the last possible match (glyphs must be sorted ascending) int32 perfect_glyph_pos = character - first_glyph; if (font->glyph_count > perfect_glyph_pos @@ -417,9 +415,9 @@ f32 vertex_text_create( if (align_h != 0 && align_v != 0) { text_calculate_dimensions(&width, &height, font, text, is_ascii, scale, length); } else if (align_h != 0) { - width = text_calculate_dimensions_width(width, font, text, is_ascii, scale, length); + width = text_calculate_dimensions_width(font, text, is_ascii, scale, length); } else { - height = text_calculate_dimensions_height(height, font, text, scale, length); + height = text_calculate_dimensions_height(font, text, scale, length); } if (align_h == UI_ALIGN_H_RIGHT) { @@ -450,7 +448,7 @@ f32 vertex_text_create( } Glyph* glyph = NULL; - // We try to jump t othe correct glyph based on the glyph codepoint + // We try to jump to the correct glyph based on the glyph codepoint // If that doesn't work we iterate the glyph list BUT only until the last possible match (glyphs must be sorted ascending) int32 perfect_glyph_pos = character - first_glyph; if (font->glyph_count > perfect_glyph_pos @@ -475,6 +473,7 @@ f32 vertex_text_create( f32 offset_y = y + glyph->metrics.offset_y * scale; offset_x += glyph->metrics.offset_x * scale; + // @performance Consider to handle whitespaces just by offsetting vertex_rect_create( vertices, index, zindex, offset_x, offset_y, glyph->metrics.width * scale, glyph->metrics.height * scale, UI_ALIGN_H_LEFT, UI_ALIGN_V_BOTTOM, @@ -560,9 +559,9 @@ f32 ui_text_create( if (align_h != NULL && align_v != NULL) { text_calculate_dimensions(&tmp_width, &tmp_height, &theme->font, text->value_str, is_ascii, scale, length); } else if (align_h != NULL) { - tmp_width = text_calculate_dimensions_width(tmp_width, &theme->font, text->value_str, is_ascii, scale, length); + tmp_width = text_calculate_dimensions_width(&theme->font, text->value_str, is_ascii, scale, length); } else { - tmp_height = text_calculate_dimensions_height(tmp_height, &theme->font, text->value_str, scale, length); + tmp_height = text_calculate_dimensions_height(&theme->font, text->value_str, scale, length); } if (align_h->value_int == UI_ALIGN_H_RIGHT) { @@ -596,7 +595,7 @@ f32 ui_text_create( } Glyph* glyph = NULL; - // We try to jump t othe correct glyph based on the glyph codepoint + // We try to jump to the correct glyph based on the glyph codepoint // If that doesn't work we iterate the glyph list BUT only until the last possible match (glyphs must be sorted ascending) int32 perfect_glyph_pos = character - first_glyph; if (theme->font.glyph_count > perfect_glyph_pos @@ -621,6 +620,7 @@ f32 ui_text_create( f32 offset_y2 = offset_y + glyph->metrics.offset_y * scale; offset_x += glyph->metrics.offset_x * scale; + // @performance Consider to handle whitespaces just by offsetting vertex_rect_create( vertices, index, zindex, offset_x, offset_y2, glyph->metrics.width * scale, glyph->metrics.height * scale, UI_ALIGN_H_LEFT, UI_ALIGN_V_BOTTOM, diff --git a/gpuapi/opengl/OpenglUtils.h b/gpuapi/opengl/OpenglUtils.h index 416e0e4..486491d 100644 --- a/gpuapi/opengl/OpenglUtils.h +++ b/gpuapi/opengl/OpenglUtils.h @@ -488,6 +488,15 @@ void gpuapi_buffer_update_dynamic(uint32 vbo, int32 size, const void* data) LOG_INCREMENT_BY(DEBUG_COUNTER_GPU_UPLOAD, size); } +inline +void gpuapi_buffer_update_sub(uint32 vbo, int32 offset, int32 size, const void* data) +{ + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferSubData(GL_ARRAY_BUFFER, offset, size, data); + + LOG_INCREMENT_BY(DEBUG_COUNTER_GPU_UPLOAD, size); +} + inline uint32 gpuapi_shaderbuffer_generate(int32 size, const void* data) { diff --git a/log/Debug.cpp b/log/Debug.cpp index 6ff93c8..d59bd93 100644 --- a/log/Debug.cpp +++ b/log/Debug.cpp @@ -62,8 +62,12 @@ void log_to_file() #if _WIN32 DWORD written; if (!WriteFile( - debug_container->log_fp, (char *) debug_container->log_memory.memory, (uint32) debug_container->log_memory.pos - 1, &written, NULL) - ) { + debug_container->log_fp, + (char *) debug_container->log_memory.memory, + (uint32) debug_container->log_memory.pos - 1, + &written, + NULL + )) { CloseHandle(debug_container->log_fp); } #else @@ -71,7 +75,11 @@ void log_to_file() return; } - if (!write(debug_container->log_fp, (char *) debug_container->log_memory.memory, (uint32) debug_container->log_memory.pos - 1)) { + if (!write( + debug_container->log_fp, + (char *) debug_container->log_memory.memory, + (uint32) debug_container->log_memory.pos - 1 + )) { close(debug_container->log_fp); } #endif @@ -90,8 +98,9 @@ void update_timing_stat(uint32 stat, const char* function) { uint64 new_tick_count = __rdtsc(); - spinlock_start(&debug_container->perf_stats_spinlock); TimingStat* timing_stat = &debug_container->perf_stats[stat]; + + spinlock_start(&debug_container->perf_stats_spinlock); timing_stat->function = function; timing_stat->delta_tick = new_tick_count - timing_stat->old_tick_count; timing_stat->delta_time = (double) timing_stat->delta_tick / (double) debug_container->performance_count_frequency; @@ -112,8 +121,9 @@ void update_timing_stat_end(uint32 stat, const char* function) { uint64 new_tick_count = __rdtsc(); - spinlock_start(&debug_container->perf_stats_spinlock); TimingStat* timing_stat = &debug_container->perf_stats[stat]; + + spinlock_start(&debug_container->perf_stats_spinlock); timing_stat->function = function; timing_stat->delta_tick = new_tick_count - timing_stat->old_tick_count; timing_stat->delta_time = (double) timing_stat->delta_tick / (double) debug_container->performance_count_frequency; @@ -126,8 +136,9 @@ void update_timing_stat_end_continued(uint32 stat, const char* function) { uint64 new_tick_count = __rdtsc(); - spinlock_start(&debug_container->perf_stats_spinlock); TimingStat* timing_stat = &debug_container->perf_stats[stat]; + + spinlock_start(&debug_container->perf_stats_spinlock); timing_stat->function = function; timing_stat->delta_tick = timing_stat->delta_tick + new_tick_count - timing_stat->old_tick_count; timing_stat->delta_time = timing_stat->delta_time + (double) timing_stat->delta_tick / (double) debug_container->performance_count_frequency; @@ -138,8 +149,9 @@ void update_timing_stat_end_continued(uint32 stat, const char* function) inline void update_timing_stat_reset(uint32 stat) { - spinlock_start(&debug_container->perf_stats_spinlock); TimingStat* timing_stat = &debug_container->perf_stats[stat]; + + spinlock_start(&debug_container->perf_stats_spinlock); timing_stat->function = NULL; timing_stat->delta_tick = 0; timing_stat->delta_time = 0; @@ -233,7 +245,6 @@ void debug_memory_log(uint64 start, uint64 size, int32 type, const char* functio dmr->start = start - mem->start; dmr->size = size; - // We are using rdtsc since it is faster -> less debugging overhead than using time() dmr->time = __rdtsc(); dmr->function_name = function; @@ -266,7 +277,6 @@ void debug_memory_reserve(uint64 start, uint64 size, int32 type, const char* fun dmr->start = start - mem->start; dmr->size = size; - // We are using rdtsc since it is faster -> less debugging overhead than using time() dmr->time = __rdtsc(); dmr->function_name = function; } diff --git a/platform/win32/Library.h b/platform/win32/Library.h index de5162e..d1ddc36 100644 --- a/platform/win32/Library.h +++ b/platform/win32/Library.h @@ -53,8 +53,7 @@ bool library_load(Library* lib) } int32 i = 0; - while (GetModuleHandleA((LPCSTR) dst) && i < 10) { - ++i; + while (GetModuleHandleA((LPCSTR) dst) && i++ < 10) { Sleep(100); } } diff --git a/scene/SceneState.h b/scene/SceneState.h index b048979..326ac65 100644 --- a/scene/SceneState.h +++ b/scene/SceneState.h @@ -18,6 +18,7 @@ enum SceneState : byte { SCENE_STATE_STARTED_SETUP = 4, SCENE_STATE_WAITING_SETUP = 8, SCENE_STATE_READY = 16, + SCENE_STATE_STATIC_CHANGES = 32, }; #endif \ No newline at end of file diff --git a/ui/UILayout.h b/ui/UILayout.h index 12807ef..b357300 100644 --- a/ui/UILayout.h +++ b/ui/UILayout.h @@ -27,6 +27,9 @@ struct UILayout { int32 vertex_size; Asset* ui_asset; + + // Defines the length of the static vertex array + int32 vertex_size_static; }; inline diff --git a/utils/StringUtils.h b/utils/StringUtils.h index 4a34892..293b5a0 100644 --- a/utils/StringUtils.h +++ b/utils/StringUtils.h @@ -846,6 +846,44 @@ void sprintf_fast(char *buffer, const char* format, ...) { va_end(args); } +inline +void format_time_hh_mm_ss(char* time_str, int32 hours, int32 minutes, int32 secs) { + time_str[0] = (char) ('0' + (hours / 10)); + time_str[1] = (char) ('0' + (hours % 10)); + time_str[2] = ':'; + time_str[3] = (char) ('0' + (minutes / 10)); + time_str[4] = (char) ('0' + (minutes % 10)); + time_str[5] = ':'; + time_str[6] = (char) ('0' + (secs / 10)); + time_str[7] = (char) ('0' + (secs % 10)); + time_str[8] = '\0'; +} +inline +void format_time_hh_mm_ss(char* time_str, int32 time) { + int32 hours = (time / 3600) % 24; + int32 minutes = (time / 60) % 60; + int32 secs = time % 60; + + format_time_hh_mm_ss(time_str, hours, minutes, secs); +} + +inline +void format_time_hh_mm(char* time_str, int32 hours, int32 minutes) { + time_str[0] = (char) ('0' + (hours / 10)); + time_str[1] = (char) ('0' + (hours % 10)); + time_str[2] = ':'; + time_str[3] = (char) ('0' + (minutes / 10)); + time_str[4] = (char) ('0' + (minutes % 10)); + time_str[5] = '\0'; +} + +inline +void format_time_hh_mm(char* time_str, int32 time) { + int32 hours = (time / 3600) % 24; + int32 minutes = (time / 60) % 60; + + format_time_hh_mm(time_str, hours, minutes); +} #endif \ No newline at end of file