Trying to improve threading, thread queue
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#define BASIC_IMPL
|
||||
#include "../basic/basic.h"
|
||||
#include "../basic/filesystem.h"
|
||||
#include "../basic/thread_queue.h"
|
||||
|
||||
#include <thread>
|
||||
#include <semaphore>
|
||||
@@ -11,9 +12,10 @@
|
||||
#include "imgui_impl_sdl2.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL_opengl.h>
|
||||
#include "glad.h"
|
||||
|
||||
Arena Perm;
|
||||
Arena Perm;
|
||||
WorkQueue MainWorkQueue;
|
||||
|
||||
#include "loading_thread.cpp"
|
||||
#include "searching_thread.cpp"
|
||||
@@ -35,13 +37,12 @@ int main(int, char **) {
|
||||
InitArena(&XArena);
|
||||
XArena.align = 0;
|
||||
|
||||
ThreadStartupInfo infos[16] = {};
|
||||
InitWorkQueue(&MainWorkQueue, 16, infos);
|
||||
|
||||
memcpy(Prompt, "read=D:/zizek", sizeof("read=D:/zizek"));
|
||||
|
||||
std::thread search_thread(SearchThreadEntry);
|
||||
int64_t chosen_text = 0;
|
||||
int64_t match_search_offset = 0;
|
||||
Array<String> filenames = {};
|
||||
Array<XToTimeString> x_to_time_string = {};
|
||||
Array<String> filenames = {};
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
|
||||
printf("Error: %s\n", SDL_GetError());
|
||||
@@ -67,6 +68,12 @@ int main(int, char **) {
|
||||
|
||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||
SDL_GL_MakeCurrent(window, gl_context);
|
||||
|
||||
if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress)) {
|
||||
Assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||
|
||||
// Setup Dear ImGui context
|
||||
@@ -138,13 +145,7 @@ int main(int, char **) {
|
||||
|
||||
{
|
||||
|
||||
ImGuiWindowFlags window_flags = 0;
|
||||
window_flags |= ImGuiWindowFlags_NoTitleBar;
|
||||
window_flags |= ImGuiWindowFlags_NoScrollbar;
|
||||
window_flags |= ImGuiWindowFlags_NoMove;
|
||||
window_flags |= ImGuiWindowFlags_NoResize;
|
||||
window_flags |= ImGuiWindowFlags_NoCollapse;
|
||||
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse;
|
||||
const ImGuiViewport *main_viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(main_viewport->Size.x, 20), ImGuiCond_Always);
|
||||
@@ -153,48 +154,42 @@ int main(int, char **) {
|
||||
if (set_focus_to_input) ImGui::SetKeyboardFocusHere(0);
|
||||
if (tab_press && ImGui::IsWindowFocused()) set_focus_to_list = true;
|
||||
if (ImGui::InputText("Input your query", Prompt, sizeof(Prompt))) {
|
||||
match_search_offset = 0;
|
||||
SearchThreadStopSearching = true;
|
||||
SearchThreadSemaphore.release();
|
||||
StartSearchingForMatches();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
if (enter_press) {
|
||||
String prompt = Prompt;
|
||||
if (StartsWith(prompt, "read=")) {
|
||||
AddFolder(prompt.skip(5), &filenames, &x_to_time_string);
|
||||
XAddFolder(prompt.skip(5), &filenames);
|
||||
memset(Prompt, 0, sizeof(Prompt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ImGuiWindowFlags window_flags = 0;
|
||||
window_flags |= ImGuiWindowFlags_NoTitleBar;
|
||||
window_flags |= ImGuiWindowFlags_NoMove;
|
||||
window_flags |= ImGuiWindowFlags_NoResize;
|
||||
window_flags |= ImGuiWindowFlags_NoCollapse;
|
||||
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse;
|
||||
const ImGuiViewport *main_viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 30), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(main_viewport->Size.x, main_viewport->Size.y - 30), ImGuiCond_Always);
|
||||
|
||||
ImGui::Begin("result", NULL, window_flags);
|
||||
if (!ImGui::IsWindowFocused() && set_focus_to_list) ImGui::SetKeyboardFocusHere(0);
|
||||
SearchThreadArrayMutex.lock();
|
||||
|
||||
Array<String> matches = LockSearchResults();
|
||||
defer { UnlockSearchResults(); };
|
||||
|
||||
float font_size = ImGui::GetFontSize();
|
||||
ImFont *font = ImGui::GetFont();
|
||||
int64_t chars_per_line = (int64_t)(main_viewport->WorkSize.x / 2) / (int64_t)font->GetCharAdvance('_') - strlen(Prompt) * 2;
|
||||
// int64_t chars_per_line = 200;
|
||||
|
||||
ImGuiListClipper clipper;
|
||||
clipper.Begin((int)Matches.len);
|
||||
clipper.Begin((int)matches.len);
|
||||
while (clipper.Step()) {
|
||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||
ImGui::PushID(i);
|
||||
defer { ImGui::PopID(); };
|
||||
auto &it = Matches[i];
|
||||
auto &it = matches[i];
|
||||
uintptr_t begin_region = (uintptr_t)XArena.data;
|
||||
uintptr_t end_region = (uintptr_t)XArena.data + XArena.len;
|
||||
|
||||
@@ -213,7 +208,7 @@ int main(int, char **) {
|
||||
String string = Format(frame_arena, "%.*s**%.*s**%.*s",
|
||||
FmtString(left), FmtString(middle), FmtString(right));
|
||||
|
||||
XToTimeString *item = FindItem(x_to_time_string, middle);
|
||||
XToTimeString *item = XFindItem(middle);
|
||||
if (ImGui::Button(string.data)) {
|
||||
String base = ChopLastPeriod(item->filepath); // .srt
|
||||
base = ChopLastPeriod(base); // .en
|
||||
@@ -235,8 +230,6 @@ int main(int, char **) {
|
||||
ImGui::Text(SkipToLastSlash(item->filepath).data);
|
||||
}
|
||||
}
|
||||
SearchThreadArrayMutex.unlock();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -250,8 +243,6 @@ int main(int, char **) {
|
||||
SDL_Delay(16);
|
||||
}
|
||||
|
||||
SearchThreadClose(search_thread);
|
||||
|
||||
// Cleanup
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
|
||||
Reference in New Issue
Block a user