diff --git a/.idea/.name b/.idea/.name index a342109..37aca99 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -fluid_sim \ No newline at end of file +FLUID_SIM \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 34647b2..7d135a2 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -10,5 +10,7 @@ + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7574ca2..b03d30d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.11) -set(PROJECT_NAME fluid_sim) -project(${PROJECT_NAME}) +project(FLUID_SIM) find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) @@ -10,80 +9,22 @@ endif(CCACHE_FOUND) set(CMAKE_CXX_STANDARD 17) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type -march=native") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") -file(GLOB_RECURSE PROJECT_SOURCES src/*.cpp) -file(GLOB_RECURSE PROJECT_HEADERS src/*.h) -file(GLOB_RECURSE PROJECT_SHADERS src/shaders/*.vert src/shaders/*.frag src/shaders/*.geom) +set(ALTLIB_DIR ${PROJECT_SOURCE_DIR}/deps/altlib) +add_subdirectory(${ALTLIB_DIR}) -add_executable(${PROJECT_NAME} ${PROJECT_HEADERS} ${PROJECT_SOURCES} ${PROJECT_SHADERS}) +set(ALTMATH_DIR ${PROJECT_SOURCE_DIR}/deps/altmath) +set(altmath_build_tests OFF) +add_subdirectory(${ALTMATH_DIR}) option(USE_AVX "Use AVX SIMD Instructions." ON) if (USE_AVX) add_compile_definitions(USE_AVX_SIMD) endif() -# PThreads -set(THREADS_PREFER_PTHREAD_FLAG ON) -find_package(Threads REQUIRED) -target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads) - -# OpenMP -find_package(OpenMP) -if (OpenMP_FOUND) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_SHARED_LINKER_FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") -endif() - -# SDL2 -if (MINGW) - set(SDL2_PATH "C:\\Libraries\\SDL2-2.0.8-MinGW\\x86_64-w64-mingw32") -endif(MINGW) -find_package(SDL2 REQUIRED) -target_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_INCLUDE_DIR}) - -# MKL -if (MINGW) - include_directories("C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/mkl/include") - link_directories("C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2019/windows/mkl/lib/intel64") -endif(MINGW) +set(LIBRARY_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) +file(GLOB_RECURSE LIBRARY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) -# GLAD -set(GLAD_DIR deps/glad) -add_library(glad ${GLAD_DIR}/src/glad.c) -target_include_directories(glad PUBLIC ${GLAD_DIR}/include) -target_link_libraries(${PROJECT_NAME} PRIVATE glad ${CMAKE_DL_LIBS}) - -# altlib -set(ALTLIB_DIR deps/altlib) -add_subdirectory(${ALTLIB_DIR}) -target_link_libraries(${PROJECT_NAME} PRIVATE altlib) - -# IMGUI -set(IMGUI_DIR deps/imgui-1.65) -add_library(imgui - ${IMGUI_DIR}/imgui.cpp - ${IMGUI_DIR}/imgui_draw.cpp - ${IMGUI_DIR}/imgui_widgets.cpp - ${IMGUI_DIR}/examples/imgui_impl_sdl.cpp - ${IMGUI_DIR}/examples/imgui_impl_opengl3.cpp) -target_include_directories(imgui PUBLIC ${SDL2_INCLUDE_DIR}) -target_include_directories(imgui PUBLIC ${IMGUI_DIR}) -target_include_directories(imgui PUBLIC ${IMGUI_DIR}/examples) -target_link_libraries(imgui PRIVATE glad) -target_link_libraries(imgui PRIVATE SDL2) -target_link_libraries(${PROJECT_NAME} PRIVATE imgui) - -# STB -set(STB_DIR deps/stb) -target_include_directories(${PROJECT_NAME} PRIVATE ${STB_DIR}) - -# altmath -set(ALTMATH_DIR deps/altmath) -set(altmath_build_tests OFF) -add_subdirectory(${ALTMATH_DIR}) -target_include_directories(${PROJECT_NAME} PUBLIC altmath) -target_link_libraries(${PROJECT_NAME} PUBLIC altmath) \ No newline at end of file +add_subdirectory(src) +add_subdirectory(demo) diff --git a/src/App.cpp b/demo/App.cpp similarity index 99% rename from src/App.cpp rename to demo/App.cpp index 3f9222c..60d5bd1 100644 --- a/src/App.cpp +++ b/demo/App.cpp @@ -14,10 +14,8 @@ #include "InputManager.h" -#include "FluidSim3D.h" #include "FluidSim2D.h" #include "FluidRenderer2D.h" -#include "WaterRenderer3D.h" static void sdl_die(const char* message) { log_error("%s: %s\n", message, SDL_GetError()); diff --git a/src/App.h b/demo/App.h similarity index 100% rename from src/App.h rename to demo/App.h diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt new file mode 100644 index 0000000..4414b2a --- /dev/null +++ b/demo/CMakeLists.txt @@ -0,0 +1,41 @@ +file(GLOB DEMO_SOURCES *.cpp) +file(GLOB DEMO_HEADERS *.h) + +add_executable(fluid_sim_demo ${DEMO_SOURCES} ${DEMO_HEADERS}) + +target_link_libraries(fluid_sim_demo LINK_PUBLIC fluid_sim) +target_link_libraries(fluid_sim_demo PUBLIC altlib) +target_link_libraries(fluid_sim_demo PUBLIC altmath) + +# SDL2 +if (MINGW) + set(SDL2_PATH "C:\\Libraries\\SDL2-2.0.8-MinGW\\x86_64-w64-mingw32") +endif(MINGW) +find_package(SDL2 REQUIRED) +target_include_directories(fluid_sim_demo PRIVATE ${SDL2_INCLUDE_DIR}) + +# GLAD +set(GLAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/glad) +add_library(glad ${GLAD_DIR}/src/glad.c) +target_include_directories(glad PUBLIC ${GLAD_DIR}/include) +target_link_libraries(fluid_sim_demo PRIVATE glad ${CMAKE_DL_LIBS}) + +# IMGUI +set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/imgui-1.65) +add_library(imgui + ${IMGUI_DIR}/imgui.cpp + ${IMGUI_DIR}/imgui_draw.cpp + ${IMGUI_DIR}/imgui_widgets.cpp + ${IMGUI_DIR}/examples/imgui_impl_sdl.cpp + ${IMGUI_DIR}/examples/imgui_impl_opengl3.cpp) +target_include_directories(imgui PUBLIC ${SDL2_INCLUDE_DIR}) +target_include_directories(imgui PUBLIC ${IMGUI_DIR}) +target_include_directories(imgui PUBLIC ${IMGUI_DIR}/examples) +target_link_libraries(imgui PRIVATE glad) +target_link_libraries(imgui PRIVATE SDL2) +target_link_libraries(fluid_sim_demo PRIVATE imgui) + +# STB +set(STB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/stb) +target_include_directories(fluid_sim_demo PRIVATE ${STB_DIR}) + diff --git a/src/Camera2D.cpp b/demo/Camera2D.cpp similarity index 100% rename from src/Camera2D.cpp rename to demo/Camera2D.cpp diff --git a/src/Camera2D.h b/demo/Camera2D.h similarity index 100% rename from src/Camera2D.h rename to demo/Camera2D.h diff --git a/src/FirstPersonCamera.cpp b/demo/FirstPersonCamera.cpp similarity index 100% rename from src/FirstPersonCamera.cpp rename to demo/FirstPersonCamera.cpp diff --git a/src/FirstPersonCamera.h b/demo/FirstPersonCamera.h similarity index 100% rename from src/FirstPersonCamera.h rename to demo/FirstPersonCamera.h diff --git a/src/FluidRenderer2D.cpp b/demo/FluidRenderer2D.cpp similarity index 97% rename from src/FluidRenderer2D.cpp rename to demo/FluidRenderer2D.cpp index 65b6a6d..05ccc3b 100644 --- a/src/FluidRenderer2D.cpp +++ b/demo/FluidRenderer2D.cpp @@ -6,6 +6,7 @@ #include #include "App.h" +#include "FluidSim2D.h" const char* FluidRenderer2D::particleVS = R"SHADER( #version 330 core @@ -418,7 +419,14 @@ void FluidRenderer2D::drawUI() { ImGui::Checkbox("Render level set", &renderLevelSet); } if (ImGui::CollapsingHeader("Performance")) { - sim->perfCounter.renderUI(); + if (sim->perfCounter.sampleFinished) { + for (int i = 0; i < sim->perfCounter.average.size; i++) { + ImGui::Text("Stage %d: %f ms", i, sim->perfCounter.average[i]); + } + ImGui::Text("Avg time per frame: %f ms", sim->perfCounter.avgTimePerFrame); + } else { + ImGui::Text("Sampling frames..."); + } } ImGui::End(); diff --git a/src/FluidRenderer2D.h b/demo/FluidRenderer2D.h similarity index 98% rename from src/FluidRenderer2D.h rename to demo/FluidRenderer2D.h index 6656549..1adf656 100644 --- a/src/FluidRenderer2D.h +++ b/demo/FluidRenderer2D.h @@ -8,7 +8,6 @@ #include #include -#include "FluidSimSettings.h" #include "Shader.h" #include "FluidSim2D.h" #include "FirstPersonCamera.h" diff --git a/src/Image.cpp b/demo/Image.cpp similarity index 100% rename from src/Image.cpp rename to demo/Image.cpp diff --git a/src/Image.h b/demo/Image.h similarity index 100% rename from src/Image.h rename to demo/Image.h diff --git a/src/InputManager.cpp b/demo/InputManager.cpp similarity index 100% rename from src/InputManager.cpp rename to demo/InputManager.cpp diff --git a/src/InputManager.h b/demo/InputManager.h similarity index 100% rename from src/InputManager.h rename to demo/InputManager.h diff --git a/src/Shader.cpp b/demo/Shader.cpp similarity index 100% rename from src/Shader.cpp rename to demo/Shader.cpp diff --git a/src/Shader.h b/demo/Shader.h similarity index 100% rename from src/Shader.h rename to demo/Shader.h diff --git a/src/Transform.h b/demo/Transform.h similarity index 100% rename from src/Transform.h rename to demo/Transform.h diff --git a/src/WaterRenderer3D.cpp b/demo/WaterRenderer3D.cpp similarity index 97% rename from src/WaterRenderer3D.cpp rename to demo/WaterRenderer3D.cpp index b3e0fb9..16c3080 100644 --- a/src/WaterRenderer3D.cpp +++ b/demo/WaterRenderer3D.cpp @@ -1,264 +1,264 @@ -// -// Created by lasagnaphil on 2018-09-17. -// - -#include "FluidSim3D.h" -#include "WaterRenderer3D.h" - -#include -#include "FirstPersonCamera.h" -#include "InputManager.h" - -static float origCubeVertices[3*36] = { - -0.5f, -0.5f, -0.5f, - 0.5f, -0.5f, -0.5f, - 0.5f, 0.5f, -0.5f, - 0.5f, 0.5f, -0.5f, - -0.5f, 0.5f, -0.5f, - -0.5f, -0.5f, -0.5f, - - -0.5f, -0.5f, 0.5f, - 0.5f, -0.5f, 0.5f, - 0.5f, 0.5f, 0.5f, - 0.5f, 0.5f, 0.5f, - -0.5f, 0.5f, 0.5f, - -0.5f, -0.5f, 0.5f, - - -0.5f, 0.5f, 0.5f, - -0.5f, 0.5f, -0.5f, - -0.5f, -0.5f, -0.5f, - -0.5f, -0.5f, -0.5f, - -0.5f, -0.5f, 0.5f, - -0.5f, 0.5f, 0.5f, - - 0.5f, 0.5f, 0.5f, - 0.5f, 0.5f, -0.5f, - 0.5f, -0.5f, -0.5f, - 0.5f, -0.5f, -0.5f, - 0.5f, -0.5f, 0.5f, - 0.5f, 0.5f, 0.5f, - - -0.5f, -0.5f, -0.5f, - 0.5f, -0.5f, -0.5f, - 0.5f, -0.5f, 0.5f, - 0.5f, -0.5f, 0.5f, - -0.5f, -0.5f, 0.5f, - -0.5f, -0.5f, -0.5f, - - -0.5f, 0.5f, -0.5f, - 0.5f, 0.5f, -0.5f, - 0.5f, 0.5f, 0.5f, - 0.5f, 0.5f, 0.5f, - -0.5f, 0.5f, 0.5f, - -0.5f, 0.5f, -0.5f, -}; - -constexpr float WaterRenderer3D::CELL_SIZE; -constexpr float WaterRenderer3D::VEL_LINE_SCALE; -constexpr size_t WaterRenderer3D::POINT_VERTEX_COUNT; -constexpr size_t WaterRenderer3D::LINE_VERTEX_COUNT; - -void WaterRenderer3D::setup(FluidSim3D* sim, FirstPersonCamera* camera) { - this->sim = sim; - - const auto EMPTY_COLOR = vec4f {0.0f, 0.0f, 0.0f, 1.0f}; - const auto FLUID_COLOR = vec4f {0.0f, 0.0f, 1.0f, 1.0f}; - const auto SOLID_COLOR = vec4f {0.1f, 0.1f, 0.1f, 1.0f}; - - lineShader = Shader::create("assets/shaders/lines.vert", "assets/shaders/lines.frag"); - voxelShader = Shader::create("assets/shaders/voxels.vert", "assets/shaders/lines.frag"); - - memcpy(cubeVertices, origCubeVertices, sizeof(origCubeVertices)); - for (int i = 0; i < 3*36; i++) { - cubeVertices[i] *= 0.8f * CELL_SIZE; - } - - sim->mac.iterate([&](size_t i, size_t j, size_t k) { - FluidSim3D::CellType cellType = sim->cell(i, j, k); - if (cellType == FluidSim3D::CellType::EMPTY) { - vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i)] = EMPTY_COLOR; - vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i) + 1] = EMPTY_COLOR; - } - else if (cellType == FluidSim3D::CellType::FLUID) { - vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i)] = FLUID_COLOR; - vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i) + 1] = FLUID_COLOR; - } - else if (cellType == FluidSim3D::CellType::SOLID) { - vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i)] = SOLID_COLOR; - vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i) + 1] = SOLID_COLOR; - } - }); - - updateWaterVoxelLocations(); - - glGenVertexArrays(1, &lineVAO); - glGenVertexArrays(1, &pointVAO); - glGenVertexArrays(1, &voxelVAO); - glGenBuffers(1, &lineVBO); - glGenBuffers(1, &lineTypeVBO); - glGenBuffers(1, &voxelVertexVBO); - glGenBuffers(1, &cellOffsetVBO); - - glBindVertexArray(lineVAO); - - glBindBuffer(GL_ARRAY_BUFFER, lineVBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vec3f) * LINE_VERTEX_COUNT, vertices, GL_DYNAMIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vec3f), 0); - - glBindBuffer(GL_ARRAY_BUFFER, lineTypeVBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vec4f) * LINE_VERTEX_COUNT, vertexColors, GL_STATIC_DRAW); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(vec4f), 0); - - glBindVertexArray(pointVAO); - - glBindBuffer(GL_ARRAY_BUFFER, lineVBO); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 2*sizeof(vec3f), 0); - - glBindBuffer(GL_ARRAY_BUFFER, lineTypeVBO); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 2*sizeof(vec4f), 0); - - glBindVertexArray(voxelVAO); - - glBindBuffer(GL_ARRAY_BUFFER, voxelVertexVBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 36, cubeVertices, GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, 0); - - glBindBuffer(GL_ARRAY_BUFFER, cellOffsetVBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vec3f) * SIZEX*SIZEY*SIZEZ, waterVoxelLocations.data, GL_DYNAMIC_DRAW); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vec3d), 0); - glVertexAttribDivisor(1, 1); - - glBindVertexArray(0); - - lineShader.use(); - lineShader.setMatrix4("model", aml::matIdentity()); - camera->addShader(&lineShader); - camera->addShader(&voxelShader); -} - -void WaterRenderer3D::update() { - auto inputMgr = InputManager::get(); - if (inputMgr->isKeyEntered(SDL_SCANCODE_1)) { - drawMode = DrawMode::POINT; - sim->rendered = false; - } - else if (inputMgr->isKeyEntered(SDL_SCANCODE_2)) { - drawMode = DrawMode::LINE; - sim->rendered = false; - } - else if (inputMgr->isKeyEntered(SDL_SCANCODE_3)) { - drawMode = DrawMode::VOXEL; - sim->rendered = false; - } - - if (!sim->rendered) { - if (drawMode == DrawMode::POINT || drawMode == DrawMode::LINE) { - sim->mac.iterate([&](size_t i, size_t j, size_t k) { - vec3d dir_d = sim->mac.vel(i, j, k); - vec3f dir = vec3f{(float)dir_d.x, (float)dir_d.y, (float)dir_d.z}; - vertices[2 * (k * SIZEY * SIZEX + j * SIZEX + i)] - = CELL_SIZE * vec3f{(float)i, (float)j, (float)k}; - vertices[2 * (k * SIZEY * SIZEX + j * SIZEX + i) + 1] - = CELL_SIZE * vec3f{(float)i, (float)j, (float)k} + VEL_LINE_SCALE * dir; - }); - glBindVertexArray(lineVAO); - glBindBuffer(GL_ARRAY_BUFFER, lineVBO); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec3d) * LINE_VERTEX_COUNT, vertices); - glBindVertexArray(0); - } - else if (drawMode == DrawMode::VOXEL) { - updateWaterVoxelLocations(); - glBindVertexArray(voxelVAO); - glBindBuffer(GL_ARRAY_BUFFER, cellOffsetVBO); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec3d) * waterVoxelLocations.size, waterVoxelLocations.data); - glBindVertexArray(0); - } - sim->rendered = true; - } -} - -void WaterRenderer3D::draw() { - if (drawMode == DrawMode::POINT) { - glBindVertexArray(pointVAO); - lineShader.use(); - glDrawArrays(GL_POINTS, 0, POINT_VERTEX_COUNT); - } - else if (drawMode == DrawMode::LINE) { - glBindVertexArray(lineVAO); - lineShader.use(); - glDrawArrays(GL_LINES, 0, LINE_VERTEX_COUNT); - } - else if (drawMode == DrawMode::VOXEL) { - glBindVertexArray(voxelVAO); - voxelShader.use(); - glDrawArraysInstanced(GL_TRIANGLES, 0, 6*36, waterVoxelLocations.size); - } - glBindVertexArray(0); -} - -void WaterRenderer3D::drawUI() { - static size_t curr_k = 0; - - ImGui::Begin("Simulation Data"); - if (sim->stage == FluidSim3D::Stage::ADVECTION) { - ImGui::Text("Advection done."); - } - else if (sim->stage == FluidSim3D::Stage::GRAVITY) { - ImGui::Text("Gravity done."); - } - else if (sim->stage == FluidSim3D::Stage::PROJECTION) { - ImGui::Text("Projection done."); - } - - ImGui::SliderInt("layer(z)", (int *) &curr_k, 0, SIZEZ - 1); - - if (ImGui::CollapsingHeader("Pressure")) { - ImGui::Columns(SIZEZ, "table_p"); - ImGui::Separator(); - for (size_t j = 0; j < SIZEY; j++) { - for (size_t i = 0; i < SIZEX; i++) { - char fstr[32]; - sprintf(fstr, "%6f", sim->p(i, SIZEY - 1 - j, curr_k)); - ImGui::Text("%s", fstr); - ImGui::NextColumn(); - } - ImGui::Separator(); - } - ImGui::Columns(1); - ImGui::Separator(); - } - if (ImGui::CollapsingHeader("Velocity")) { - ImGui::Columns(SIZEZ, "table_vel"); - ImGui::Separator(); - for (size_t j = 0; j < SIZEY; j++) { - for (size_t i = 0; i < SIZEX; i++) { - char fstr[32]; - vec3d v = sim->mac.vel(i, SIZEY - 1 - j, curr_k); - sprintf(fstr, "%2.2f %2.2f %2.2f", v.x, v.y, v.z); - ImGui::Text("%s", fstr); - ImGui::NextColumn(); - } - ImGui::Separator(); - } - ImGui::Columns(1); - ImGui::Separator(); - } - ImGui::End(); -} - -void WaterRenderer3D::updateWaterVoxelLocations() { - waterVoxelLocations.size = 0; - sim->mac.iterate([&](size_t i, size_t j, size_t k) { - FluidSim3D::CellType cellType = sim->cell(i, j, k); - if (cellType == FluidSim3D::CellType::FLUID) { - waterVoxelLocations.push(vec3f {i*CELL_SIZE, j*CELL_SIZE, k*CELL_SIZE}); - } - }); -} - +// +// Created by lasagnaphil on 2018-09-17. +// + +#include "FluidSim3D.h" +#include "WaterRenderer3D.h" + +#include +#include "FirstPersonCamera.h" +#include "InputManager.h" + +static float origCubeVertices[3*36] = { + -0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, + -0.5f, 0.5f, -0.5f, + -0.5f, -0.5f, -0.5f, + + -0.5f, -0.5f, 0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, 0.5f, + -0.5f, -0.5f, 0.5f, + + -0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, -0.5f, + -0.5f, -0.5f, -0.5f, + -0.5f, -0.5f, -0.5f, + -0.5f, -0.5f, 0.5f, + -0.5f, 0.5f, 0.5f, + + 0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + + -0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, -0.5f, + 0.5f, -0.5f, 0.5f, + 0.5f, -0.5f, 0.5f, + -0.5f, -0.5f, 0.5f, + -0.5f, -0.5f, -0.5f, + + -0.5f, 0.5f, -0.5f, + 0.5f, 0.5f, -0.5f, + 0.5f, 0.5f, 0.5f, + 0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, 0.5f, + -0.5f, 0.5f, -0.5f, +}; + +constexpr float WaterRenderer3D::CELL_SIZE; +constexpr float WaterRenderer3D::VEL_LINE_SCALE; +constexpr size_t WaterRenderer3D::POINT_VERTEX_COUNT; +constexpr size_t WaterRenderer3D::LINE_VERTEX_COUNT; + +void WaterRenderer3D::setup(FluidSim3D* sim, FirstPersonCamera* camera) { + this->sim = sim; + + const auto EMPTY_COLOR = vec4f {0.0f, 0.0f, 0.0f, 1.0f}; + const auto FLUID_COLOR = vec4f {0.0f, 0.0f, 1.0f, 1.0f}; + const auto SOLID_COLOR = vec4f {0.1f, 0.1f, 0.1f, 1.0f}; + + lineShader = Shader::create("assets/shaders/lines.vert", "assets/shaders/lines.frag"); + voxelShader = Shader::create("assets/shaders/voxels.vert", "assets/shaders/lines.frag"); + + memcpy(cubeVertices, origCubeVertices, sizeof(origCubeVertices)); + for (int i = 0; i < 3*36; i++) { + cubeVertices[i] *= 0.8f * CELL_SIZE; + } + + sim->mac.iterate([&](size_t i, size_t j, size_t k) { + FluidSim3D::CellType cellType = sim->cell(i, j, k); + if (cellType == FluidSim3D::CellType::EMPTY) { + vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i)] = EMPTY_COLOR; + vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i) + 1] = EMPTY_COLOR; + } + else if (cellType == FluidSim3D::CellType::FLUID) { + vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i)] = FLUID_COLOR; + vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i) + 1] = FLUID_COLOR; + } + else if (cellType == FluidSim3D::CellType::SOLID) { + vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i)] = SOLID_COLOR; + vertexColors[2 * (k * SIZEY * SIZEX + j * SIZEX + i) + 1] = SOLID_COLOR; + } + }); + + updateWaterVoxelLocations(); + + glGenVertexArrays(1, &lineVAO); + glGenVertexArrays(1, &pointVAO); + glGenVertexArrays(1, &voxelVAO); + glGenBuffers(1, &lineVBO); + glGenBuffers(1, &lineTypeVBO); + glGenBuffers(1, &voxelVertexVBO); + glGenBuffers(1, &cellOffsetVBO); + + glBindVertexArray(lineVAO); + + glBindBuffer(GL_ARRAY_BUFFER, lineVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(vec3f) * LINE_VERTEX_COUNT, vertices, GL_DYNAMIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vec3f), 0); + + glBindBuffer(GL_ARRAY_BUFFER, lineTypeVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(vec4f) * LINE_VERTEX_COUNT, vertexColors, GL_STATIC_DRAW); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(vec4f), 0); + + glBindVertexArray(pointVAO); + + glBindBuffer(GL_ARRAY_BUFFER, lineVBO); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 2*sizeof(vec3f), 0); + + glBindBuffer(GL_ARRAY_BUFFER, lineTypeVBO); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 2*sizeof(vec4f), 0); + + glBindVertexArray(voxelVAO); + + glBindBuffer(GL_ARRAY_BUFFER, voxelVertexVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 36, cubeVertices, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, 0); + + glBindBuffer(GL_ARRAY_BUFFER, cellOffsetVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(vec3f) * SIZEX*SIZEY*SIZEZ, waterVoxelLocations.data, GL_DYNAMIC_DRAW); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vec3d), 0); + glVertexAttribDivisor(1, 1); + + glBindVertexArray(0); + + lineShader.use(); + lineShader.setMatrix4("model", aml::matIdentity()); + camera->addShader(&lineShader); + camera->addShader(&voxelShader); +} + +void WaterRenderer3D::update() { + auto inputMgr = InputManager::get(); + if (inputMgr->isKeyEntered(SDL_SCANCODE_1)) { + drawMode = DrawMode::POINT; + sim->rendered = false; + } + else if (inputMgr->isKeyEntered(SDL_SCANCODE_2)) { + drawMode = DrawMode::LINE; + sim->rendered = false; + } + else if (inputMgr->isKeyEntered(SDL_SCANCODE_3)) { + drawMode = DrawMode::VOXEL; + sim->rendered = false; + } + + if (!sim->rendered) { + if (drawMode == DrawMode::POINT || drawMode == DrawMode::LINE) { + sim->mac.iterate([&](size_t i, size_t j, size_t k) { + vec3d dir_d = sim->mac.vel(i, j, k); + vec3f dir = vec3f{(float)dir_d.x, (float)dir_d.y, (float)dir_d.z}; + vertices[2 * (k * SIZEY * SIZEX + j * SIZEX + i)] + = CELL_SIZE * vec3f{(float)i, (float)j, (float)k}; + vertices[2 * (k * SIZEY * SIZEX + j * SIZEX + i) + 1] + = CELL_SIZE * vec3f{(float)i, (float)j, (float)k} + VEL_LINE_SCALE * dir; + }); + glBindVertexArray(lineVAO); + glBindBuffer(GL_ARRAY_BUFFER, lineVBO); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec3d) * LINE_VERTEX_COUNT, vertices); + glBindVertexArray(0); + } + else if (drawMode == DrawMode::VOXEL) { + updateWaterVoxelLocations(); + glBindVertexArray(voxelVAO); + glBindBuffer(GL_ARRAY_BUFFER, cellOffsetVBO); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vec3d) * waterVoxelLocations.size, waterVoxelLocations.data); + glBindVertexArray(0); + } + sim->rendered = true; + } +} + +void WaterRenderer3D::draw() { + if (drawMode == DrawMode::POINT) { + glBindVertexArray(pointVAO); + lineShader.use(); + glDrawArrays(GL_POINTS, 0, POINT_VERTEX_COUNT); + } + else if (drawMode == DrawMode::LINE) { + glBindVertexArray(lineVAO); + lineShader.use(); + glDrawArrays(GL_LINES, 0, LINE_VERTEX_COUNT); + } + else if (drawMode == DrawMode::VOXEL) { + glBindVertexArray(voxelVAO); + voxelShader.use(); + glDrawArraysInstanced(GL_TRIANGLES, 0, 6*36, waterVoxelLocations.size); + } + glBindVertexArray(0); +} + +void WaterRenderer3D::drawUI() { + static size_t curr_k = 0; + + ImGui::Begin("Simulation Data"); + if (sim->stage == FluidSim3D::Stage::ADVECTION) { + ImGui::Text("Advection done."); + } + else if (sim->stage == FluidSim3D::Stage::GRAVITY) { + ImGui::Text("Gravity done."); + } + else if (sim->stage == FluidSim3D::Stage::PROJECTION) { + ImGui::Text("Projection done."); + } + + ImGui::SliderInt("layer(z)", (int *) &curr_k, 0, SIZEZ - 1); + + if (ImGui::CollapsingHeader("Pressure")) { + ImGui::Columns(SIZEZ, "table_p"); + ImGui::Separator(); + for (size_t j = 0; j < SIZEY; j++) { + for (size_t i = 0; i < SIZEX; i++) { + char fstr[32]; + sprintf(fstr, "%6f", sim->p(i, SIZEY - 1 - j, curr_k)); + ImGui::Text("%s", fstr); + ImGui::NextColumn(); + } + ImGui::Separator(); + } + ImGui::Columns(1); + ImGui::Separator(); + } + if (ImGui::CollapsingHeader("Velocity")) { + ImGui::Columns(SIZEZ, "table_vel"); + ImGui::Separator(); + for (size_t j = 0; j < SIZEY; j++) { + for (size_t i = 0; i < SIZEX; i++) { + char fstr[32]; + vec3d v = sim->mac.vel(i, SIZEY - 1 - j, curr_k); + sprintf(fstr, "%2.2f %2.2f %2.2f", v.x, v.y, v.z); + ImGui::Text("%s", fstr); + ImGui::NextColumn(); + } + ImGui::Separator(); + } + ImGui::Columns(1); + ImGui::Separator(); + } + ImGui::End(); +} + +void WaterRenderer3D::updateWaterVoxelLocations() { + waterVoxelLocations.size = 0; + sim->mac.iterate([&](size_t i, size_t j, size_t k) { + FluidSim3D::CellType cellType = sim->cell(i, j, k); + if (cellType == FluidSim3D::CellType::FLUID) { + waterVoxelLocations.push(vec3f {i*CELL_SIZE, j*CELL_SIZE, k*CELL_SIZE}); + } + }); +} + diff --git a/src/WaterRenderer3D.h b/demo/WaterRenderer3D.h similarity index 96% rename from src/WaterRenderer3D.h rename to demo/WaterRenderer3D.h index 7655a5e..2d80288 100644 --- a/src/WaterRenderer3D.h +++ b/demo/WaterRenderer3D.h @@ -1,62 +1,62 @@ -// -// Created by lasagnaphil on 2018-09-17. -// - -#ifndef FLUID_SIM_FLUIDRENDERER3D_H -#define FLUID_SIM_FLUIDRENDERER3D_H - -#include -#include -#include - -#include "Shader.h" -#include "FluidSimSettings.h" - -struct FirstPersonCamera; -struct FluidSim3D; - -class WaterRenderer3D { - static constexpr int SIZEX = FluidSimSettings::Dim3D::SIZEX; - static constexpr int SIZEY = FluidSimSettings::Dim3D::SIZEY; - static constexpr int SIZEZ = FluidSimSettings::Dim3D::SIZEZ; - static constexpr int ENABLE_DEBUG_UI = FluidSimSettings::Dim3D::ENABLE_DEBUG_UI; - - enum class DrawMode { - POINT, LINE, VOXEL - }; - DrawMode drawMode = DrawMode::POINT; - static constexpr float CELL_SIZE = 1.0f / SIZEY; - static constexpr float VEL_LINE_SCALE = 0.001f / SIZEY; - static constexpr size_t POINT_VERTEX_COUNT = SIZEX * SIZEY * SIZEZ; - static constexpr size_t LINE_VERTEX_COUNT = SIZEX * SIZEY * SIZEZ * 2; - - GLuint lineVAO; - GLuint pointVAO; - GLuint lineVBO; - GLuint lineTypeVBO; - GLuint voxelVAO; - GLuint voxelVertexVBO; - GLuint cellOffsetVBO; - - vec3f vertices[LINE_VERTEX_COUNT]; - vec4f vertexColors[LINE_VERTEX_COUNT]; - float cubeVertices[3*36]; - StackVec waterVoxelLocations = {}; - - Shader lineShader; - Shader voxelShader; - - FluidSim3D* sim; - -public: - void setup(FluidSim3D* sim, FirstPersonCamera* camera); - void update(); - void draw(); - void drawUI(); - -private: - void updateWaterVoxelLocations(); -}; - - -#endif //FLUID_SIM_FLUIDRENDERER3D_H +// +// Created by lasagnaphil on 2018-09-17. +// + +#ifndef FLUID_SIM_FLUIDRENDERER3D_H +#define FLUID_SIM_FLUIDRENDERER3D_H + +#include +#include +#include + +#include "Shader.h" +#include "FluidSimSettings.h" + +struct FirstPersonCamera; +struct FluidSim3D; + +class WaterRenderer3D { + static constexpr int SIZEX = FluidSimSettings::Dim3D::SIZEX; + static constexpr int SIZEY = FluidSimSettings::Dim3D::SIZEY; + static constexpr int SIZEZ = FluidSimSettings::Dim3D::SIZEZ; + static constexpr int ENABLE_DEBUG_UI = FluidSimSettings::Dim3D::ENABLE_DEBUG_UI; + + enum class DrawMode { + POINT, LINE, VOXEL + }; + DrawMode drawMode = DrawMode::POINT; + static constexpr float CELL_SIZE = 1.0f / SIZEY; + static constexpr float VEL_LINE_SCALE = 0.001f / SIZEY; + static constexpr size_t POINT_VERTEX_COUNT = SIZEX * SIZEY * SIZEZ; + static constexpr size_t LINE_VERTEX_COUNT = SIZEX * SIZEY * SIZEZ * 2; + + GLuint lineVAO; + GLuint pointVAO; + GLuint lineVBO; + GLuint lineTypeVBO; + GLuint voxelVAO; + GLuint voxelVertexVBO; + GLuint cellOffsetVBO; + + vec3f vertices[LINE_VERTEX_COUNT]; + vec4f vertexColors[LINE_VERTEX_COUNT]; + float cubeVertices[3*36]; + StackVec waterVoxelLocations = {}; + + Shader lineShader; + Shader voxelShader; + + FluidSim3D* sim; + +public: + void setup(FluidSim3D* sim, FirstPersonCamera* camera); + void update(); + void draw(); + void drawUI(); + +private: + void updateWaterVoxelLocations(); +}; + + +#endif //FLUID_SIM_FLUIDRENDERER3D_H diff --git a/deps/glad/include/glad/glad.h b/demo/deps/glad/include/glad/glad.h similarity index 100% rename from deps/glad/include/glad/glad.h rename to demo/deps/glad/include/glad/glad.h diff --git a/deps/glad/src/glad.c b/demo/deps/glad/src/glad.c similarity index 100% rename from deps/glad/src/glad.c rename to demo/deps/glad/src/glad.c diff --git a/deps/glad_gen.sh b/demo/deps/glad_gen.sh old mode 100755 new mode 100644 similarity index 100% rename from deps/glad_gen.sh rename to demo/deps/glad_gen.sh diff --git a/deps/imgui-1.65/.github/CONTRIBUTING.md b/demo/deps/imgui-1.65/.github/CONTRIBUTING.md similarity index 100% rename from deps/imgui-1.65/.github/CONTRIBUTING.md rename to demo/deps/imgui-1.65/.github/CONTRIBUTING.md diff --git a/deps/imgui-1.65/.github/issue_template.md b/demo/deps/imgui-1.65/.github/issue_template.md similarity index 100% rename from deps/imgui-1.65/.github/issue_template.md rename to demo/deps/imgui-1.65/.github/issue_template.md diff --git a/deps/imgui-1.65/.github/pull_request_template.md b/demo/deps/imgui-1.65/.github/pull_request_template.md similarity index 100% rename from deps/imgui-1.65/.github/pull_request_template.md rename to demo/deps/imgui-1.65/.github/pull_request_template.md diff --git a/deps/imgui-1.65/.travis.yml b/demo/deps/imgui-1.65/.travis.yml similarity index 100% rename from deps/imgui-1.65/.travis.yml rename to demo/deps/imgui-1.65/.travis.yml diff --git a/deps/imgui-1.65/LICENSE.txt b/demo/deps/imgui-1.65/LICENSE.txt similarity index 100% rename from deps/imgui-1.65/LICENSE.txt rename to demo/deps/imgui-1.65/LICENSE.txt diff --git a/deps/imgui-1.65/docs/CHANGELOG.txt b/demo/deps/imgui-1.65/docs/CHANGELOG.txt similarity index 100% rename from deps/imgui-1.65/docs/CHANGELOG.txt rename to demo/deps/imgui-1.65/docs/CHANGELOG.txt diff --git a/deps/imgui-1.65/docs/README.md b/demo/deps/imgui-1.65/docs/README.md similarity index 100% rename from deps/imgui-1.65/docs/README.md rename to demo/deps/imgui-1.65/docs/README.md diff --git a/deps/imgui-1.65/docs/TODO.txt b/demo/deps/imgui-1.65/docs/TODO.txt similarity index 100% rename from deps/imgui-1.65/docs/TODO.txt rename to demo/deps/imgui-1.65/docs/TODO.txt diff --git a/deps/imgui-1.65/examples/.gitignore b/demo/deps/imgui-1.65/examples/.gitignore similarity index 100% rename from deps/imgui-1.65/examples/.gitignore rename to demo/deps/imgui-1.65/examples/.gitignore diff --git a/deps/imgui-1.65/examples/README.txt b/demo/deps/imgui-1.65/examples/README.txt similarity index 100% rename from deps/imgui-1.65/examples/README.txt rename to demo/deps/imgui-1.65/examples/README.txt diff --git a/deps/imgui-1.65/examples/example_allegro5/README.md b/demo/deps/imgui-1.65/examples/example_allegro5/README.md similarity index 100% rename from deps/imgui-1.65/examples/example_allegro5/README.md rename to demo/deps/imgui-1.65/examples/example_allegro5/README.md diff --git a/deps/imgui-1.65/examples/example_allegro5/example_allegro5.vcxproj b/demo/deps/imgui-1.65/examples/example_allegro5/example_allegro5.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_allegro5/example_allegro5.vcxproj rename to demo/deps/imgui-1.65/examples/example_allegro5/example_allegro5.vcxproj diff --git a/deps/imgui-1.65/examples/example_allegro5/example_allegro5.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_allegro5/example_allegro5.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_allegro5/example_allegro5.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_allegro5/example_allegro5.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_allegro5/imconfig_allegro5.h b/demo/deps/imgui-1.65/examples/example_allegro5/imconfig_allegro5.h similarity index 100% rename from deps/imgui-1.65/examples/example_allegro5/imconfig_allegro5.h rename to demo/deps/imgui-1.65/examples/example_allegro5/imconfig_allegro5.h diff --git a/deps/imgui-1.65/examples/example_allegro5/main.cpp b/demo/deps/imgui-1.65/examples/example_allegro5/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_allegro5/main.cpp rename to demo/deps/imgui-1.65/examples/example_allegro5/main.cpp diff --git a/deps/imgui-1.65/examples/example_apple_metal/README.md b/demo/deps/imgui-1.65/examples/example_apple_metal/README.md similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/README.md rename to demo/deps/imgui-1.65/examples/example_apple_metal/README.md diff --git a/deps/imgui-1.65/examples/example_apple_metal/Shared/AppDelegate.h b/demo/deps/imgui-1.65/examples/example_apple_metal/Shared/AppDelegate.h similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/Shared/AppDelegate.h rename to demo/deps/imgui-1.65/examples/example_apple_metal/Shared/AppDelegate.h diff --git a/deps/imgui-1.65/examples/example_apple_metal/Shared/AppDelegate.m b/demo/deps/imgui-1.65/examples/example_apple_metal/Shared/AppDelegate.m similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/Shared/AppDelegate.m rename to demo/deps/imgui-1.65/examples/example_apple_metal/Shared/AppDelegate.m diff --git a/deps/imgui-1.65/examples/example_apple_metal/Shared/Renderer.h b/demo/deps/imgui-1.65/examples/example_apple_metal/Shared/Renderer.h similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/Shared/Renderer.h rename to demo/deps/imgui-1.65/examples/example_apple_metal/Shared/Renderer.h diff --git a/deps/imgui-1.65/examples/example_apple_metal/Shared/Renderer.mm b/demo/deps/imgui-1.65/examples/example_apple_metal/Shared/Renderer.mm similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/Shared/Renderer.mm rename to demo/deps/imgui-1.65/examples/example_apple_metal/Shared/Renderer.mm diff --git a/deps/imgui-1.65/examples/example_apple_metal/Shared/ViewController.h b/demo/deps/imgui-1.65/examples/example_apple_metal/Shared/ViewController.h similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/Shared/ViewController.h rename to demo/deps/imgui-1.65/examples/example_apple_metal/Shared/ViewController.h diff --git a/deps/imgui-1.65/examples/example_apple_metal/Shared/ViewController.mm b/demo/deps/imgui-1.65/examples/example_apple_metal/Shared/ViewController.mm similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/Shared/ViewController.mm rename to demo/deps/imgui-1.65/examples/example_apple_metal/Shared/ViewController.mm diff --git a/deps/imgui-1.65/examples/example_apple_metal/Shared/main.m b/demo/deps/imgui-1.65/examples/example_apple_metal/Shared/main.m similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/Shared/main.m rename to demo/deps/imgui-1.65/examples/example_apple_metal/Shared/main.m diff --git a/deps/imgui-1.65/examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj b/demo/deps/imgui-1.65/examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj rename to demo/deps/imgui-1.65/examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj diff --git a/deps/imgui-1.65/examples/example_apple_metal/iOS/Base.lproj/Main.storyboard b/demo/deps/imgui-1.65/examples/example_apple_metal/iOS/Base.lproj/Main.storyboard similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/iOS/Base.lproj/Main.storyboard rename to demo/deps/imgui-1.65/examples/example_apple_metal/iOS/Base.lproj/Main.storyboard diff --git a/deps/imgui-1.65/examples/example_apple_metal/iOS/Default-568h@2x.png b/demo/deps/imgui-1.65/examples/example_apple_metal/iOS/Default-568h@2x.png similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/iOS/Default-568h@2x.png rename to demo/deps/imgui-1.65/examples/example_apple_metal/iOS/Default-568h@2x.png diff --git a/deps/imgui-1.65/examples/example_apple_metal/iOS/Info-iOS.plist b/demo/deps/imgui-1.65/examples/example_apple_metal/iOS/Info-iOS.plist similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/iOS/Info-iOS.plist rename to demo/deps/imgui-1.65/examples/example_apple_metal/iOS/Info-iOS.plist diff --git a/deps/imgui-1.65/examples/example_apple_metal/iOS/Launch Screen.storyboard b/demo/deps/imgui-1.65/examples/example_apple_metal/iOS/Launch Screen.storyboard similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/iOS/Launch Screen.storyboard rename to demo/deps/imgui-1.65/examples/example_apple_metal/iOS/Launch Screen.storyboard diff --git a/deps/imgui-1.65/examples/example_apple_metal/macOS/Base.lproj/Main.storyboard b/demo/deps/imgui-1.65/examples/example_apple_metal/macOS/Base.lproj/Main.storyboard similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/macOS/Base.lproj/Main.storyboard rename to demo/deps/imgui-1.65/examples/example_apple_metal/macOS/Base.lproj/Main.storyboard diff --git a/deps/imgui-1.65/examples/example_apple_metal/macOS/Info-macOS.plist b/demo/deps/imgui-1.65/examples/example_apple_metal/macOS/Info-macOS.plist similarity index 100% rename from deps/imgui-1.65/examples/example_apple_metal/macOS/Info-macOS.plist rename to demo/deps/imgui-1.65/examples/example_apple_metal/macOS/Info-macOS.plist diff --git a/deps/imgui-1.65/examples/example_apple_opengl2/example_apple_opengl2.xcodeproj/project.pbxproj b/demo/deps/imgui-1.65/examples/example_apple_opengl2/example_apple_opengl2.xcodeproj/project.pbxproj similarity index 100% rename from deps/imgui-1.65/examples/example_apple_opengl2/example_apple_opengl2.xcodeproj/project.pbxproj rename to demo/deps/imgui-1.65/examples/example_apple_opengl2/example_apple_opengl2.xcodeproj/project.pbxproj diff --git a/deps/imgui-1.65/examples/example_apple_opengl2/main.mm b/demo/deps/imgui-1.65/examples/example_apple_opengl2/main.mm similarity index 100% rename from deps/imgui-1.65/examples/example_apple_opengl2/main.mm rename to demo/deps/imgui-1.65/examples/example_apple_opengl2/main.mm diff --git a/deps/imgui-1.65/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj b/demo/deps/imgui-1.65/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj rename to demo/deps/imgui-1.65/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj diff --git a/deps/imgui-1.65/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_freeglut_opengl2/main.cpp b/demo/deps/imgui-1.65/examples/example_freeglut_opengl2/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_freeglut_opengl2/main.cpp rename to demo/deps/imgui-1.65/examples/example_freeglut_opengl2/main.cpp diff --git a/deps/imgui-1.65/examples/example_glfw_opengl2/Makefile b/demo/deps/imgui-1.65/examples/example_glfw_opengl2/Makefile similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl2/Makefile rename to demo/deps/imgui-1.65/examples/example_glfw_opengl2/Makefile diff --git a/deps/imgui-1.65/examples/example_glfw_opengl2/build_win32.bat b/demo/deps/imgui-1.65/examples/example_glfw_opengl2/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl2/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_glfw_opengl2/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj b/demo/deps/imgui-1.65/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj rename to demo/deps/imgui-1.65/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj diff --git a/deps/imgui-1.65/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_glfw_opengl2/main.cpp b/demo/deps/imgui-1.65/examples/example_glfw_opengl2/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl2/main.cpp rename to demo/deps/imgui-1.65/examples/example_glfw_opengl2/main.cpp diff --git a/deps/imgui-1.65/examples/example_glfw_opengl3/Makefile b/demo/deps/imgui-1.65/examples/example_glfw_opengl3/Makefile similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl3/Makefile rename to demo/deps/imgui-1.65/examples/example_glfw_opengl3/Makefile diff --git a/deps/imgui-1.65/examples/example_glfw_opengl3/build_win32.bat b/demo/deps/imgui-1.65/examples/example_glfw_opengl3/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl3/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_glfw_opengl3/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj b/demo/deps/imgui-1.65/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj rename to demo/deps/imgui-1.65/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj diff --git a/deps/imgui-1.65/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_glfw_opengl3/main.cpp b/demo/deps/imgui-1.65/examples/example_glfw_opengl3/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_opengl3/main.cpp rename to demo/deps/imgui-1.65/examples/example_glfw_opengl3/main.cpp diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/CMakeLists.txt b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/CMakeLists.txt similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/CMakeLists.txt rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/CMakeLists.txt diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/build_win32.bat b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/build_win64.bat b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/build_win64.bat similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/build_win64.bat rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/build_win64.bat diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/gen_spv.sh b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/gen_spv.sh old mode 100755 new mode 100644 similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/gen_spv.sh rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/gen_spv.sh diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/glsl_shader.frag b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/glsl_shader.frag similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/glsl_shader.frag rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/glsl_shader.frag diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/glsl_shader.vert b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/glsl_shader.vert similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/glsl_shader.vert rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/glsl_shader.vert diff --git a/deps/imgui-1.65/examples/example_glfw_vulkan/main.cpp b/demo/deps/imgui-1.65/examples/example_glfw_vulkan/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_glfw_vulkan/main.cpp rename to demo/deps/imgui-1.65/examples/example_glfw_vulkan/main.cpp diff --git a/deps/imgui-1.65/examples/example_marmalade/data/app.icf b/demo/deps/imgui-1.65/examples/example_marmalade/data/app.icf similarity index 100% rename from deps/imgui-1.65/examples/example_marmalade/data/app.icf rename to demo/deps/imgui-1.65/examples/example_marmalade/data/app.icf diff --git a/deps/imgui-1.65/examples/example_marmalade/main.cpp b/demo/deps/imgui-1.65/examples/example_marmalade/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_marmalade/main.cpp rename to demo/deps/imgui-1.65/examples/example_marmalade/main.cpp diff --git a/deps/imgui-1.65/examples/example_marmalade/marmalade_example.mkb b/demo/deps/imgui-1.65/examples/example_marmalade/marmalade_example.mkb similarity index 100% rename from deps/imgui-1.65/examples/example_marmalade/marmalade_example.mkb rename to demo/deps/imgui-1.65/examples/example_marmalade/marmalade_example.mkb diff --git a/deps/imgui-1.65/examples/example_null/build_win32.bat b/demo/deps/imgui-1.65/examples/example_null/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_null/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_null/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_null/main.cpp b/demo/deps/imgui-1.65/examples/example_null/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_null/main.cpp rename to demo/deps/imgui-1.65/examples/example_null/main.cpp diff --git a/deps/imgui-1.65/examples/example_sdl_opengl2/Makefile b/demo/deps/imgui-1.65/examples/example_sdl_opengl2/Makefile similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl2/Makefile rename to demo/deps/imgui-1.65/examples/example_sdl_opengl2/Makefile diff --git a/deps/imgui-1.65/examples/example_sdl_opengl2/README.md b/demo/deps/imgui-1.65/examples/example_sdl_opengl2/README.md similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl2/README.md rename to demo/deps/imgui-1.65/examples/example_sdl_opengl2/README.md diff --git a/deps/imgui-1.65/examples/example_sdl_opengl2/build_win32.bat b/demo/deps/imgui-1.65/examples/example_sdl_opengl2/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl2/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_sdl_opengl2/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj b/demo/deps/imgui-1.65/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj rename to demo/deps/imgui-1.65/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj diff --git a/deps/imgui-1.65/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_sdl_opengl2/main.cpp b/demo/deps/imgui-1.65/examples/example_sdl_opengl2/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl2/main.cpp rename to demo/deps/imgui-1.65/examples/example_sdl_opengl2/main.cpp diff --git a/deps/imgui-1.65/examples/example_sdl_opengl3/Makefile b/demo/deps/imgui-1.65/examples/example_sdl_opengl3/Makefile similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl3/Makefile rename to demo/deps/imgui-1.65/examples/example_sdl_opengl3/Makefile diff --git a/deps/imgui-1.65/examples/example_sdl_opengl3/README.md b/demo/deps/imgui-1.65/examples/example_sdl_opengl3/README.md similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl3/README.md rename to demo/deps/imgui-1.65/examples/example_sdl_opengl3/README.md diff --git a/deps/imgui-1.65/examples/example_sdl_opengl3/build_win32.bat b/demo/deps/imgui-1.65/examples/example_sdl_opengl3/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl3/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_sdl_opengl3/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj b/demo/deps/imgui-1.65/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj rename to demo/deps/imgui-1.65/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj diff --git a/deps/imgui-1.65/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_sdl_opengl3/main.cpp b/demo/deps/imgui-1.65/examples/example_sdl_opengl3/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_opengl3/main.cpp rename to demo/deps/imgui-1.65/examples/example_sdl_opengl3/main.cpp diff --git a/deps/imgui-1.65/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj b/demo/deps/imgui-1.65/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj rename to demo/deps/imgui-1.65/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj diff --git a/deps/imgui-1.65/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_sdl_vulkan/main.cpp b/demo/deps/imgui-1.65/examples/example_sdl_vulkan/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_sdl_vulkan/main.cpp rename to demo/deps/imgui-1.65/examples/example_sdl_vulkan/main.cpp diff --git a/deps/imgui-1.65/examples/example_win32_directx10/build_win32.bat b/demo/deps/imgui-1.65/examples/example_win32_directx10/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx10/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_win32_directx10/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_win32_directx10/example_win32_directx10.vcxproj b/demo/deps/imgui-1.65/examples/example_win32_directx10/example_win32_directx10.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx10/example_win32_directx10.vcxproj rename to demo/deps/imgui-1.65/examples/example_win32_directx10/example_win32_directx10.vcxproj diff --git a/deps/imgui-1.65/examples/example_win32_directx10/example_win32_directx10.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_win32_directx10/example_win32_directx10.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx10/example_win32_directx10.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_win32_directx10/example_win32_directx10.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_win32_directx10/main.cpp b/demo/deps/imgui-1.65/examples/example_win32_directx10/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx10/main.cpp rename to demo/deps/imgui-1.65/examples/example_win32_directx10/main.cpp diff --git a/deps/imgui-1.65/examples/example_win32_directx11/build_win32.bat b/demo/deps/imgui-1.65/examples/example_win32_directx11/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx11/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_win32_directx11/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_win32_directx11/example_win32_directx11.vcxproj b/demo/deps/imgui-1.65/examples/example_win32_directx11/example_win32_directx11.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx11/example_win32_directx11.vcxproj rename to demo/deps/imgui-1.65/examples/example_win32_directx11/example_win32_directx11.vcxproj diff --git a/deps/imgui-1.65/examples/example_win32_directx11/example_win32_directx11.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_win32_directx11/example_win32_directx11.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx11/example_win32_directx11.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_win32_directx11/example_win32_directx11.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_win32_directx11/main.cpp b/demo/deps/imgui-1.65/examples/example_win32_directx11/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx11/main.cpp rename to demo/deps/imgui-1.65/examples/example_win32_directx11/main.cpp diff --git a/deps/imgui-1.65/examples/example_win32_directx12/build_win32.bat b/demo/deps/imgui-1.65/examples/example_win32_directx12/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx12/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_win32_directx12/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_win32_directx12/example_win32_directx12.vcxproj b/demo/deps/imgui-1.65/examples/example_win32_directx12/example_win32_directx12.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx12/example_win32_directx12.vcxproj rename to demo/deps/imgui-1.65/examples/example_win32_directx12/example_win32_directx12.vcxproj diff --git a/deps/imgui-1.65/examples/example_win32_directx12/example_win32_directx12.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_win32_directx12/example_win32_directx12.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx12/example_win32_directx12.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_win32_directx12/example_win32_directx12.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_win32_directx12/main.cpp b/demo/deps/imgui-1.65/examples/example_win32_directx12/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx12/main.cpp rename to demo/deps/imgui-1.65/examples/example_win32_directx12/main.cpp diff --git a/deps/imgui-1.65/examples/example_win32_directx9/build_win32.bat b/demo/deps/imgui-1.65/examples/example_win32_directx9/build_win32.bat similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx9/build_win32.bat rename to demo/deps/imgui-1.65/examples/example_win32_directx9/build_win32.bat diff --git a/deps/imgui-1.65/examples/example_win32_directx9/example_win32_directx9.vcxproj b/demo/deps/imgui-1.65/examples/example_win32_directx9/example_win32_directx9.vcxproj similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx9/example_win32_directx9.vcxproj rename to demo/deps/imgui-1.65/examples/example_win32_directx9/example_win32_directx9.vcxproj diff --git a/deps/imgui-1.65/examples/example_win32_directx9/example_win32_directx9.vcxproj.filters b/demo/deps/imgui-1.65/examples/example_win32_directx9/example_win32_directx9.vcxproj.filters similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx9/example_win32_directx9.vcxproj.filters rename to demo/deps/imgui-1.65/examples/example_win32_directx9/example_win32_directx9.vcxproj.filters diff --git a/deps/imgui-1.65/examples/example_win32_directx9/main.cpp b/demo/deps/imgui-1.65/examples/example_win32_directx9/main.cpp similarity index 100% rename from deps/imgui-1.65/examples/example_win32_directx9/main.cpp rename to demo/deps/imgui-1.65/examples/example_win32_directx9/main.cpp diff --git a/deps/imgui-1.65/examples/imgui_examples.sln b/demo/deps/imgui-1.65/examples/imgui_examples.sln similarity index 100% rename from deps/imgui-1.65/examples/imgui_examples.sln rename to demo/deps/imgui-1.65/examples/imgui_examples.sln diff --git a/deps/imgui-1.65/examples/imgui_impl_allegro5.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_allegro5.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_allegro5.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_allegro5.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_allegro5.h b/demo/deps/imgui-1.65/examples/imgui_impl_allegro5.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_allegro5.h rename to demo/deps/imgui-1.65/examples/imgui_impl_allegro5.h diff --git a/deps/imgui-1.65/examples/imgui_impl_dx10.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_dx10.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_dx10.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_dx10.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_dx10.h b/demo/deps/imgui-1.65/examples/imgui_impl_dx10.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_dx10.h rename to demo/deps/imgui-1.65/examples/imgui_impl_dx10.h diff --git a/deps/imgui-1.65/examples/imgui_impl_dx11.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_dx11.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_dx11.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_dx11.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_dx11.h b/demo/deps/imgui-1.65/examples/imgui_impl_dx11.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_dx11.h rename to demo/deps/imgui-1.65/examples/imgui_impl_dx11.h diff --git a/deps/imgui-1.65/examples/imgui_impl_dx12.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_dx12.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_dx12.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_dx12.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_dx12.h b/demo/deps/imgui-1.65/examples/imgui_impl_dx12.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_dx12.h rename to demo/deps/imgui-1.65/examples/imgui_impl_dx12.h diff --git a/deps/imgui-1.65/examples/imgui_impl_dx9.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_dx9.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_dx9.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_dx9.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_dx9.h b/demo/deps/imgui-1.65/examples/imgui_impl_dx9.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_dx9.h rename to demo/deps/imgui-1.65/examples/imgui_impl_dx9.h diff --git a/deps/imgui-1.65/examples/imgui_impl_freeglut.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_freeglut.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_freeglut.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_freeglut.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_freeglut.h b/demo/deps/imgui-1.65/examples/imgui_impl_freeglut.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_freeglut.h rename to demo/deps/imgui-1.65/examples/imgui_impl_freeglut.h diff --git a/deps/imgui-1.65/examples/imgui_impl_glfw.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_glfw.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_glfw.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_glfw.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_glfw.h b/demo/deps/imgui-1.65/examples/imgui_impl_glfw.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_glfw.h rename to demo/deps/imgui-1.65/examples/imgui_impl_glfw.h diff --git a/deps/imgui-1.65/examples/imgui_impl_marmalade.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_marmalade.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_marmalade.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_marmalade.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_marmalade.h b/demo/deps/imgui-1.65/examples/imgui_impl_marmalade.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_marmalade.h rename to demo/deps/imgui-1.65/examples/imgui_impl_marmalade.h diff --git a/deps/imgui-1.65/examples/imgui_impl_metal.h b/demo/deps/imgui-1.65/examples/imgui_impl_metal.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_metal.h rename to demo/deps/imgui-1.65/examples/imgui_impl_metal.h diff --git a/deps/imgui-1.65/examples/imgui_impl_metal.mm b/demo/deps/imgui-1.65/examples/imgui_impl_metal.mm similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_metal.mm rename to demo/deps/imgui-1.65/examples/imgui_impl_metal.mm diff --git a/deps/imgui-1.65/examples/imgui_impl_opengl2.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_opengl2.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_opengl2.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_opengl2.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_opengl2.h b/demo/deps/imgui-1.65/examples/imgui_impl_opengl2.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_opengl2.h rename to demo/deps/imgui-1.65/examples/imgui_impl_opengl2.h diff --git a/deps/imgui-1.65/examples/imgui_impl_opengl3.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_opengl3.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_opengl3.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_opengl3.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_opengl3.h b/demo/deps/imgui-1.65/examples/imgui_impl_opengl3.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_opengl3.h rename to demo/deps/imgui-1.65/examples/imgui_impl_opengl3.h diff --git a/deps/imgui-1.65/examples/imgui_impl_osx.h b/demo/deps/imgui-1.65/examples/imgui_impl_osx.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_osx.h rename to demo/deps/imgui-1.65/examples/imgui_impl_osx.h diff --git a/deps/imgui-1.65/examples/imgui_impl_osx.mm b/demo/deps/imgui-1.65/examples/imgui_impl_osx.mm similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_osx.mm rename to demo/deps/imgui-1.65/examples/imgui_impl_osx.mm diff --git a/deps/imgui-1.65/examples/imgui_impl_sdl.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_sdl.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_sdl.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_sdl.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_sdl.h b/demo/deps/imgui-1.65/examples/imgui_impl_sdl.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_sdl.h rename to demo/deps/imgui-1.65/examples/imgui_impl_sdl.h diff --git a/deps/imgui-1.65/examples/imgui_impl_vulkan.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_vulkan.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_vulkan.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_vulkan.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_vulkan.h b/demo/deps/imgui-1.65/examples/imgui_impl_vulkan.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_vulkan.h rename to demo/deps/imgui-1.65/examples/imgui_impl_vulkan.h diff --git a/deps/imgui-1.65/examples/imgui_impl_win32.cpp b/demo/deps/imgui-1.65/examples/imgui_impl_win32.cpp similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_win32.cpp rename to demo/deps/imgui-1.65/examples/imgui_impl_win32.cpp diff --git a/deps/imgui-1.65/examples/imgui_impl_win32.h b/demo/deps/imgui-1.65/examples/imgui_impl_win32.h similarity index 100% rename from deps/imgui-1.65/examples/imgui_impl_win32.h rename to demo/deps/imgui-1.65/examples/imgui_impl_win32.h diff --git a/deps/imgui-1.65/examples/libs/gl3w/GL/gl3w.c b/demo/deps/imgui-1.65/examples/libs/gl3w/GL/gl3w.c similarity index 100% rename from deps/imgui-1.65/examples/libs/gl3w/GL/gl3w.c rename to demo/deps/imgui-1.65/examples/libs/gl3w/GL/gl3w.c diff --git a/deps/imgui-1.65/examples/libs/gl3w/GL/gl3w.h b/demo/deps/imgui-1.65/examples/libs/gl3w/GL/gl3w.h similarity index 100% rename from deps/imgui-1.65/examples/libs/gl3w/GL/gl3w.h rename to demo/deps/imgui-1.65/examples/libs/gl3w/GL/gl3w.h diff --git a/deps/imgui-1.65/examples/libs/gl3w/GL/glcorearb.h b/demo/deps/imgui-1.65/examples/libs/gl3w/GL/glcorearb.h similarity index 100% rename from deps/imgui-1.65/examples/libs/gl3w/GL/glcorearb.h rename to demo/deps/imgui-1.65/examples/libs/gl3w/GL/glcorearb.h diff --git a/deps/imgui-1.65/examples/libs/glfw/COPYING.txt b/demo/deps/imgui-1.65/examples/libs/glfw/COPYING.txt similarity index 100% rename from deps/imgui-1.65/examples/libs/glfw/COPYING.txt rename to demo/deps/imgui-1.65/examples/libs/glfw/COPYING.txt diff --git a/deps/imgui-1.65/examples/libs/glfw/include/GLFW/glfw3.h b/demo/deps/imgui-1.65/examples/libs/glfw/include/GLFW/glfw3.h similarity index 100% rename from deps/imgui-1.65/examples/libs/glfw/include/GLFW/glfw3.h rename to demo/deps/imgui-1.65/examples/libs/glfw/include/GLFW/glfw3.h diff --git a/deps/imgui-1.65/examples/libs/glfw/include/GLFW/glfw3native.h b/demo/deps/imgui-1.65/examples/libs/glfw/include/GLFW/glfw3native.h similarity index 100% rename from deps/imgui-1.65/examples/libs/glfw/include/GLFW/glfw3native.h rename to demo/deps/imgui-1.65/examples/libs/glfw/include/GLFW/glfw3native.h diff --git a/deps/imgui-1.65/examples/libs/glfw/lib-vc2010-32/glfw3.lib b/demo/deps/imgui-1.65/examples/libs/glfw/lib-vc2010-32/glfw3.lib similarity index 100% rename from deps/imgui-1.65/examples/libs/glfw/lib-vc2010-32/glfw3.lib rename to demo/deps/imgui-1.65/examples/libs/glfw/lib-vc2010-32/glfw3.lib diff --git a/deps/imgui-1.65/examples/libs/glfw/lib-vc2010-64/glfw3.lib b/demo/deps/imgui-1.65/examples/libs/glfw/lib-vc2010-64/glfw3.lib similarity index 100% rename from deps/imgui-1.65/examples/libs/glfw/lib-vc2010-64/glfw3.lib rename to demo/deps/imgui-1.65/examples/libs/glfw/lib-vc2010-64/glfw3.lib diff --git a/deps/imgui-1.65/examples/libs/usynergy/README.txt b/demo/deps/imgui-1.65/examples/libs/usynergy/README.txt similarity index 100% rename from deps/imgui-1.65/examples/libs/usynergy/README.txt rename to demo/deps/imgui-1.65/examples/libs/usynergy/README.txt diff --git a/deps/imgui-1.65/examples/libs/usynergy/uSynergy.c b/demo/deps/imgui-1.65/examples/libs/usynergy/uSynergy.c similarity index 96% rename from deps/imgui-1.65/examples/libs/usynergy/uSynergy.c rename to demo/deps/imgui-1.65/examples/libs/usynergy/uSynergy.c index a8d01da..8dce47b 100644 --- a/deps/imgui-1.65/examples/libs/usynergy/uSynergy.c +++ b/demo/deps/imgui-1.65/examples/libs/usynergy/uSynergy.c @@ -1,636 +1,636 @@ -/* -uSynergy client -- Implementation for the embedded Synergy client library - version 1.0.0, July 7th, 2012 - -Copyright (c) 2012 Alex Evans - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*/ -#include "uSynergy.h" -#include -#include - - - -//--------------------------------------------------------------------------------------------------------------------- -// Internal helpers -//--------------------------------------------------------------------------------------------------------------------- - - - -/** -@brief Read 16 bit integer in network byte order and convert to native byte order -**/ -static int16_t sNetToNative16(const unsigned char *value) -{ -#ifdef USYNERGY_LITTLE_ENDIAN - return value[1] | (value[0] << 8); -#else - return value[0] | (value[1] << 8); -#endif -} - - - -/** -@brief Read 32 bit integer in network byte order and convert to native byte order -**/ -static int32_t sNetToNative32(const unsigned char *value) -{ -#ifdef USYNERGY_LITTLE_ENDIAN - return value[3] | (value[2] << 8) | (value[1] << 16) | (value[0] << 24); -#else - return value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); -#endif -} - - - -/** -@brief Trace text to client -**/ -static void sTrace(uSynergyContext *context, const char* text) -{ - // Don't trace if we don't have a trace function - if (context->m_traceFunc != 0L) - context->m_traceFunc(context->m_cookie, text); -} - - - -/** -@brief Add string to reply packet -**/ -static void sAddString(uSynergyContext *context, const char *string) -{ - size_t len = strlen(string); - memcpy(context->m_replyCur, string, len); - context->m_replyCur += len; -} - - - -/** -@brief Add uint8 to reply packet -**/ -static void sAddUInt8(uSynergyContext *context, uint8_t value) -{ - *context->m_replyCur++ = value; -} - - - -/** -@brief Add uint16 to reply packet -**/ -static void sAddUInt16(uSynergyContext *context, uint16_t value) -{ - uint8_t *reply = context->m_replyCur; - *reply++ = (uint8_t)(value >> 8); - *reply++ = (uint8_t)value; - context->m_replyCur = reply; -} - - - -/** -@brief Add uint32 to reply packet -**/ -static void sAddUInt32(uSynergyContext *context, uint32_t value) -{ - uint8_t *reply = context->m_replyCur; - *reply++ = (uint8_t)(value >> 24); - *reply++ = (uint8_t)(value >> 16); - *reply++ = (uint8_t)(value >> 8); - *reply++ = (uint8_t)value; - context->m_replyCur = reply; -} - - - -/** -@brief Send reply packet -**/ -static uSynergyBool sSendReply(uSynergyContext *context) -{ - // Set header size - uint8_t *reply_buf = context->m_replyBuffer; - uint32_t reply_len = (uint32_t)(context->m_replyCur - reply_buf); /* Total size of reply */ - uint32_t body_len = reply_len - 4; /* Size of body */ - uSynergyBool ret; - reply_buf[0] = (uint8_t)(body_len >> 24); - reply_buf[1] = (uint8_t)(body_len >> 16); - reply_buf[2] = (uint8_t)(body_len >> 8); - reply_buf[3] = (uint8_t)body_len; - - // Send reply - ret = context->m_sendFunc(context->m_cookie, context->m_replyBuffer, reply_len); - - // Reset reply buffer write pointer - context->m_replyCur = context->m_replyBuffer+4; - return ret; -} - - - -/** -@brief Call mouse callback after a mouse event -**/ -static void sSendMouseCallback(uSynergyContext *context) -{ - // Skip if no callback is installed - if (context->m_mouseCallback == 0L) - return; - - // Send callback - context->m_mouseCallback(context->m_cookie, context->m_mouseX, context->m_mouseY, context->m_mouseWheelX, - context->m_mouseWheelY, context->m_mouseButtonLeft, context->m_mouseButtonRight, context->m_mouseButtonMiddle); -} - - - -/** -@brief Send keyboard callback when a key has been pressed or released -**/ -static void sSendKeyboardCallback(uSynergyContext *context, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) -{ - // Skip if no callback is installed - if (context->m_keyboardCallback == 0L) - return; - - // Send callback - context->m_keyboardCallback(context->m_cookie, key, modifiers, down, repeat); -} - - - -/** -@brief Send joystick callback -**/ -static void sSendJoystickCallback(uSynergyContext *context, uint8_t joyNum) -{ - int8_t *sticks; - - // Skip if no callback is installed - if (context->m_joystickCallback == 0L) - return; - - // Send callback - sticks = context->m_joystickSticks[joyNum]; - context->m_joystickCallback(context->m_cookie, joyNum, context->m_joystickButtons[joyNum], sticks[0], sticks[1], sticks[2], sticks[3]); -} - - - -/** -@brief Parse a single client message, update state, send callbacks and send replies -**/ -#define USYNERGY_IS_PACKET(pkt_id) memcmp(message+4, pkt_id, 4)==0 -static void sProcessMessage(uSynergyContext *context, const uint8_t *message) -{ - // We have a packet! - if (memcmp(message+4, "Synergy", 7)==0) - { - // Welcome message - // kMsgHello = "Synergy%2i%2i" - // kMsgHelloBack = "Synergy%2i%2i%s" - sAddString(context, "Synergy"); - sAddUInt16(context, USYNERGY_PROTOCOL_MAJOR); - sAddUInt16(context, USYNERGY_PROTOCOL_MINOR); - sAddUInt32(context, (uint32_t)strlen(context->m_clientName)); - sAddString(context, context->m_clientName); - if (!sSendReply(context)) - { - // Send reply failed, let's try to reconnect - sTrace(context, "SendReply failed, trying to reconnect in a second"); - context->m_connected = USYNERGY_FALSE; - context->m_sleepFunc(context->m_cookie, 1000); - } - else - { - // Let's assume we're connected - char buffer[256+1]; - sprintf(buffer, "Connected as client \"%s\"", context->m_clientName); - sTrace(context, buffer); - context->m_hasReceivedHello = USYNERGY_TRUE; - } - return; - } - else if (USYNERGY_IS_PACKET("QINF")) - { - // Screen info. Reply with DINF - // kMsgQInfo = "QINF" - // kMsgDInfo = "DINF%2i%2i%2i%2i%2i%2i%2i" - uint16_t x = 0, y = 0, warp = 0; - sAddString(context, "DINF"); - sAddUInt16(context, x); - sAddUInt16(context, y); - sAddUInt16(context, context->m_clientWidth); - sAddUInt16(context, context->m_clientHeight); - sAddUInt16(context, warp); - sAddUInt16(context, 0); // mx? - sAddUInt16(context, 0); // my? - sSendReply(context); - return; - } - else if (USYNERGY_IS_PACKET("CIAK")) - { - // Do nothing? - // kMsgCInfoAck = "CIAK" - return; - } - else if (USYNERGY_IS_PACKET("CROP")) - { - // Do nothing? - // kMsgCResetOptions = "CROP" - return; - } - else if (USYNERGY_IS_PACKET("CINN")) - { - // Screen enter. Reply with CNOP - // kMsgCEnter = "CINN%2i%2i%4i%2i" - - // Obtain the Synergy sequence number - context->m_sequenceNumber = sNetToNative32(message + 12); - context->m_isCaptured = USYNERGY_TRUE; - - // Call callback - if (context->m_screenActiveCallback != 0L) - context->m_screenActiveCallback(context->m_cookie, USYNERGY_TRUE); - } - else if (USYNERGY_IS_PACKET("COUT")) - { - // Screen leave - // kMsgCLeave = "COUT" - context->m_isCaptured = USYNERGY_FALSE; - - // Call callback - if (context->m_screenActiveCallback != 0L) - context->m_screenActiveCallback(context->m_cookie, USYNERGY_FALSE); - } - else if (USYNERGY_IS_PACKET("DMDN")) - { - // Mouse down - // kMsgDMouseDown = "DMDN%1i" - char btn = message[8]-1; - if (btn==2) - context->m_mouseButtonRight = USYNERGY_TRUE; - else if (btn==1) - context->m_mouseButtonMiddle = USYNERGY_TRUE; - else - context->m_mouseButtonLeft = USYNERGY_TRUE; - sSendMouseCallback(context); - } - else if (USYNERGY_IS_PACKET("DMUP")) - { - // Mouse up - // kMsgDMouseUp = "DMUP%1i" - char btn = message[8]-1; - if (btn==2) - context->m_mouseButtonRight = USYNERGY_FALSE; - else if (btn==1) - context->m_mouseButtonMiddle = USYNERGY_FALSE; - else - context->m_mouseButtonLeft = USYNERGY_FALSE; - sSendMouseCallback(context); - } - else if (USYNERGY_IS_PACKET("DMMV")) - { - // Mouse move. Reply with CNOP - // kMsgDMouseMove = "DMMV%2i%2i" - context->m_mouseX = sNetToNative16(message+8); - context->m_mouseY = sNetToNative16(message+10); - sSendMouseCallback(context); - } - else if (USYNERGY_IS_PACKET("DMWM")) - { - // Mouse wheel - // kMsgDMouseWheel = "DMWM%2i%2i" - // kMsgDMouseWheel1_0 = "DMWM%2i" - context->m_mouseWheelX += sNetToNative16(message+8); - context->m_mouseWheelY += sNetToNative16(message+10); - sSendMouseCallback(context); - } - else if (USYNERGY_IS_PACKET("DKDN")) - { - // Key down - // kMsgDKeyDown = "DKDN%2i%2i%2i" - // kMsgDKeyDown1_0 = "DKDN%2i%2i" - //uint16_t id = sNetToNative16(message+8); - uint16_t mod = sNetToNative16(message+10); - uint16_t key = sNetToNative16(message+12); - sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_FALSE); - } - else if (USYNERGY_IS_PACKET("DKRP")) - { - // Key repeat - // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" - // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" - uint16_t mod = sNetToNative16(message+10); -// uint16_t count = sNetToNative16(message+12); - uint16_t key = sNetToNative16(message+14); - sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_TRUE); - } - else if (USYNERGY_IS_PACKET("DKUP")) - { - // Key up - // kMsgDKeyUp = "DKUP%2i%2i%2i" - // kMsgDKeyUp1_0 = "DKUP%2i%2i" - //uint16 id=Endian::sNetToNative(sbuf[4]); - uint16_t mod = sNetToNative16(message+10); - uint16_t key = sNetToNative16(message+12); - sSendKeyboardCallback(context, key, mod, USYNERGY_FALSE, USYNERGY_FALSE); - } - else if (USYNERGY_IS_PACKET("DGBT")) - { - // Joystick buttons - // kMsgDGameButtons = "DGBT%1i%2i"; - uint8_t joy_num = message[8]; - if (joy_numm_joystickButtons[joy_num] = (message[9] << 8) | message[10]; - sSendJoystickCallback(context, joy_num); - } - } - else if (USYNERGY_IS_PACKET("DGST")) - { - // Joystick sticks - // kMsgDGameSticks = "DGST%1i%1i%1i%1i%1i"; - uint8_t joy_num = message[8]; - if (joy_numm_joystickSticks[joy_num], message+9, 4); - sSendJoystickCallback(context, joy_num); - } - } - else if (USYNERGY_IS_PACKET("DSOP")) - { - // Set options - // kMsgDSetOptions = "DSOP%4I" - } - else if (USYNERGY_IS_PACKET("CALV")) - { - // Keepalive, reply with CALV and then CNOP - // kMsgCKeepAlive = "CALV" - sAddString(context, "CALV"); - sSendReply(context); - // now reply with CNOP - } - else if (USYNERGY_IS_PACKET("DCLP")) - { - // Clipboard message - // kMsgDClipboard = "DCLP%1i%4i%s" - // - // The clipboard message contains: - // 1 uint32: The size of the message - // 4 chars: The identifier ("DCLP") - // 1 uint8: The clipboard index - // 1 uint32: The sequence number. It's zero, because this message is always coming from the server? - // 1 uint32: The total size of the remaining 'string' (as per the Synergy %s string format (which is 1 uint32 for size followed by a char buffer (not necessarily null terminated)). - // 1 uint32: The number of formats present in the message - // And then 'number of formats' times the following: - // 1 uint32: The format of the clipboard data - // 1 uint32: The size n of the clipboard data - // n uint8: The clipboard data - const uint8_t * parse_msg = message+17; - uint32_t num_formats = sNetToNative32(parse_msg); - parse_msg += 4; - for (; num_formats; num_formats--) - { - // Parse clipboard format header - uint32_t format = sNetToNative32(parse_msg); - uint32_t size = sNetToNative32(parse_msg+4); - parse_msg += 8; - - // Call callback - if (context->m_clipboardCallback) - context->m_clipboardCallback(context->m_cookie, format, parse_msg, size); - - parse_msg += size; - } - } - else - { - // Unknown packet, could be any of these - // kMsgCNoop = "CNOP" - // kMsgCClose = "CBYE" - // kMsgCClipboard = "CCLP%1i%4i" - // kMsgCScreenSaver = "CSEC%1i" - // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" - // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" - // kMsgDMouseRelMove = "DMRM%2i%2i" - // kMsgEIncompatible = "EICV%2i%2i" - // kMsgEBusy = "EBSY" - // kMsgEUnknown = "EUNK" - // kMsgEBad = "EBAD" - char buffer[64]; - sprintf(buffer, "Unknown packet '%c%c%c%c'", message[4], message[5], message[6], message[7]); - sTrace(context, buffer); - return; - } - - // Reply with CNOP maybe? - sAddString(context, "CNOP"); - sSendReply(context); -} -#undef USYNERGY_IS_PACKET - - - -/** -@brief Mark context as being disconnected -**/ -static void sSetDisconnected(uSynergyContext *context) -{ - context->m_connected = USYNERGY_FALSE; - context->m_hasReceivedHello = USYNERGY_FALSE; - context->m_isCaptured = USYNERGY_FALSE; - context->m_replyCur = context->m_replyBuffer + 4; - context->m_sequenceNumber = 0; -} - - - -/** -@brief Update a connected context -**/ -static void sUpdateContext(uSynergyContext *context) -{ - /* Receive data (blocking) */ - int receive_size = USYNERGY_RECEIVE_BUFFER_SIZE - context->m_receiveOfs; - int num_received = 0; - int packlen = 0; - if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer + context->m_receiveOfs, receive_size, &num_received) == USYNERGY_FALSE) - { - /* Receive failed, let's try to reconnect */ - char buffer[128]; - sprintf(buffer, "Receive failed (%d bytes asked, %d bytes received), trying to reconnect in a second", receive_size, num_received); - sTrace(context, buffer); - sSetDisconnected(context); - context->m_sleepFunc(context->m_cookie, 1000); - return; - } - context->m_receiveOfs += num_received; - - /* If we didn't receive any data then we're probably still polling to get connected and - therefore not getting any data back. To avoid overloading the system with a Synergy - thread that would hammer on polling, we let it rest for a bit if there's no data. */ - if (num_received == 0) - context->m_sleepFunc(context->m_cookie, 500); - - /* Check for timeouts */ - if (context->m_hasReceivedHello) - { - uint32_t cur_time = context->m_getTimeFunc(); - if (num_received == 0) - { - /* Timeout after 2 secs of inactivity (we received no CALV) */ - if ((cur_time - context->m_lastMessageTime) > USYNERGY_IDLE_TIMEOUT) - sSetDisconnected(context); - } - else - context->m_lastMessageTime = cur_time; - } - - /* Eat packets */ - for (;;) - { - /* Grab packet length and bail out if the packet goes beyond the end of the buffer */ - packlen = sNetToNative32(context->m_receiveBuffer); - if (packlen+4 > context->m_receiveOfs) - break; - - /* Process message */ - sProcessMessage(context, context->m_receiveBuffer); - - /* Move packet to front of buffer */ - memmove(context->m_receiveBuffer, context->m_receiveBuffer+packlen+4, context->m_receiveOfs-packlen-4); - context->m_receiveOfs -= packlen+4; - } - - /* Throw away over-sized packets */ - if (packlen > USYNERGY_RECEIVE_BUFFER_SIZE) - { - /* Oversized packet, ditch tail end */ - char buffer[128]; - sprintf(buffer, "Oversized packet: '%c%c%c%c' (length %d)", context->m_receiveBuffer[4], context->m_receiveBuffer[5], context->m_receiveBuffer[6], context->m_receiveBuffer[7], packlen); - sTrace(context, buffer); - num_received = context->m_receiveOfs-4; // 4 bytes for the size field - while (num_received != packlen) - { - int buffer_left = packlen - num_received; - int to_receive = buffer_left < USYNERGY_RECEIVE_BUFFER_SIZE ? buffer_left : USYNERGY_RECEIVE_BUFFER_SIZE; - int ditch_received = 0; - if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer, to_receive, &ditch_received) == USYNERGY_FALSE) - { - /* Receive failed, let's try to reconnect */ - sTrace(context, "Receive failed, trying to reconnect in a second"); - sSetDisconnected(context); - context->m_sleepFunc(context->m_cookie, 1000); - break; - } - else - { - num_received += ditch_received; - } - } - context->m_receiveOfs = 0; - } -} - - -//--------------------------------------------------------------------------------------------------------------------- -// Public interface -//--------------------------------------------------------------------------------------------------------------------- - - - -/** -@brief Initialize uSynergy context -**/ -void uSynergyInit(uSynergyContext *context) -{ - /* Zero memory */ - memset(context, 0, sizeof(uSynergyContext)); - - /* Initialize to default state */ - sSetDisconnected(context); -} - - -/** -@brief Update uSynergy -**/ -void uSynergyUpdate(uSynergyContext *context) -{ - if (context->m_connected) - { - /* Update context, receive data, call callbacks */ - sUpdateContext(context); - } - else - { - /* Try to connect */ - if (context->m_connectFunc(context->m_cookie)) - context->m_connected = USYNERGY_TRUE; - } -} - - - -/** -@brief Send clipboard data -**/ -void uSynergySendClipboard(uSynergyContext *context, const char *text) -{ - // Calculate maximum size that will fit in a reply packet - uint32_t overhead_size = 4 + /* Message size */ - 4 + /* Message ID */ - 1 + /* Clipboard index */ - 4 + /* Sequence number */ - 4 + /* Rest of message size (because it's a Synergy string from here on) */ - 4 + /* Number of clipboard formats */ - 4 + /* Clipboard format */ - 4; /* Clipboard data length */ - uint32_t max_length = USYNERGY_REPLY_BUFFER_SIZE - overhead_size; - - // Clip text to max length - uint32_t text_length = (uint32_t)strlen(text); - if (text_length > max_length) - { - char buffer[128]; - sprintf(buffer, "Clipboard buffer too small, clipboard truncated at %d characters", max_length); - sTrace(context, buffer); - text_length = max_length; - } - - // Assemble packet - sAddString(context, "DCLP"); - sAddUInt8(context, 0); /* Clipboard index */ - sAddUInt32(context, context->m_sequenceNumber); - sAddUInt32(context, 4+4+4+text_length); /* Rest of message size: numFormats, format, length, data */ - sAddUInt32(context, 1); /* Number of formats (only text for now) */ - sAddUInt32(context, USYNERGY_CLIPBOARD_FORMAT_TEXT); - sAddUInt32(context, text_length); - sAddString(context, text); - sSendReply(context); -} +/* +uSynergy client -- Implementation for the embedded Synergy client library + version 1.0.0, July 7th, 2012 + +Copyright (c) 2012 Alex Evans + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*/ +#include "uSynergy.h" +#include +#include + + + +//--------------------------------------------------------------------------------------------------------------------- +// Internal helpers +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Read 16 bit integer in network byte order and convert to native byte order +**/ +static int16_t sNetToNative16(const unsigned char *value) +{ +#ifdef USYNERGY_LITTLE_ENDIAN + return value[1] | (value[0] << 8); +#else + return value[0] | (value[1] << 8); +#endif +} + + + +/** +@brief Read 32 bit integer in network byte order and convert to native byte order +**/ +static int32_t sNetToNative32(const unsigned char *value) +{ +#ifdef USYNERGY_LITTLE_ENDIAN + return value[3] | (value[2] << 8) | (value[1] << 16) | (value[0] << 24); +#else + return value[0] | (value[1] << 8) | (value[2] << 16) | (value[3] << 24); +#endif +} + + + +/** +@brief Trace text to client +**/ +static void sTrace(uSynergyContext *context, const char* text) +{ + // Don't trace if we don't have a trace function + if (context->m_traceFunc != 0L) + context->m_traceFunc(context->m_cookie, text); +} + + + +/** +@brief Add string to reply packet +**/ +static void sAddString(uSynergyContext *context, const char *string) +{ + size_t len = strlen(string); + memcpy(context->m_replyCur, string, len); + context->m_replyCur += len; +} + + + +/** +@brief Add uint8 to reply packet +**/ +static void sAddUInt8(uSynergyContext *context, uint8_t value) +{ + *context->m_replyCur++ = value; +} + + + +/** +@brief Add uint16 to reply packet +**/ +static void sAddUInt16(uSynergyContext *context, uint16_t value) +{ + uint8_t *reply = context->m_replyCur; + *reply++ = (uint8_t)(value >> 8); + *reply++ = (uint8_t)value; + context->m_replyCur = reply; +} + + + +/** +@brief Add uint32 to reply packet +**/ +static void sAddUInt32(uSynergyContext *context, uint32_t value) +{ + uint8_t *reply = context->m_replyCur; + *reply++ = (uint8_t)(value >> 24); + *reply++ = (uint8_t)(value >> 16); + *reply++ = (uint8_t)(value >> 8); + *reply++ = (uint8_t)value; + context->m_replyCur = reply; +} + + + +/** +@brief Send reply packet +**/ +static uSynergyBool sSendReply(uSynergyContext *context) +{ + // Set header size + uint8_t *reply_buf = context->m_replyBuffer; + uint32_t reply_len = (uint32_t)(context->m_replyCur - reply_buf); /* Total size of reply */ + uint32_t body_len = reply_len - 4; /* Size of body */ + uSynergyBool ret; + reply_buf[0] = (uint8_t)(body_len >> 24); + reply_buf[1] = (uint8_t)(body_len >> 16); + reply_buf[2] = (uint8_t)(body_len >> 8); + reply_buf[3] = (uint8_t)body_len; + + // Send reply + ret = context->m_sendFunc(context->m_cookie, context->m_replyBuffer, reply_len); + + // Reset reply buffer write pointer + context->m_replyCur = context->m_replyBuffer+4; + return ret; +} + + + +/** +@brief Call mouse callback after a mouse event +**/ +static void sSendMouseCallback(uSynergyContext *context) +{ + // Skip if no callback is installed + if (context->m_mouseCallback == 0L) + return; + + // Send callback + context->m_mouseCallback(context->m_cookie, context->m_mouseX, context->m_mouseY, context->m_mouseWheelX, + context->m_mouseWheelY, context->m_mouseButtonLeft, context->m_mouseButtonRight, context->m_mouseButtonMiddle); +} + + + +/** +@brief Send keyboard callback when a key has been pressed or released +**/ +static void sSendKeyboardCallback(uSynergyContext *context, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) +{ + // Skip if no callback is installed + if (context->m_keyboardCallback == 0L) + return; + + // Send callback + context->m_keyboardCallback(context->m_cookie, key, modifiers, down, repeat); +} + + + +/** +@brief Send joystick callback +**/ +static void sSendJoystickCallback(uSynergyContext *context, uint8_t joyNum) +{ + int8_t *sticks; + + // Skip if no callback is installed + if (context->m_joystickCallback == 0L) + return; + + // Send callback + sticks = context->m_joystickSticks[joyNum]; + context->m_joystickCallback(context->m_cookie, joyNum, context->m_joystickButtons[joyNum], sticks[0], sticks[1], sticks[2], sticks[3]); +} + + + +/** +@brief Parse a single client message, update state, send callbacks and send replies +**/ +#define USYNERGY_IS_PACKET(pkt_id) memcmp(message+4, pkt_id, 4)==0 +static void sProcessMessage(uSynergyContext *context, const uint8_t *message) +{ + // We have a packet! + if (memcmp(message+4, "Synergy", 7)==0) + { + // Welcome message + // kMsgHello = "Synergy%2i%2i" + // kMsgHelloBack = "Synergy%2i%2i%s" + sAddString(context, "Synergy"); + sAddUInt16(context, USYNERGY_PROTOCOL_MAJOR); + sAddUInt16(context, USYNERGY_PROTOCOL_MINOR); + sAddUInt32(context, (uint32_t)strlen(context->m_clientName)); + sAddString(context, context->m_clientName); + if (!sSendReply(context)) + { + // Send reply failed, let's try to reconnect + sTrace(context, "SendReply failed, trying to reconnect in a second"); + context->m_connected = USYNERGY_FALSE; + context->m_sleepFunc(context->m_cookie, 1000); + } + else + { + // Let's assume we're connected + char buffer[256+1]; + sprintf(buffer, "Connected as client \"%s\"", context->m_clientName); + sTrace(context, buffer); + context->m_hasReceivedHello = USYNERGY_TRUE; + } + return; + } + else if (USYNERGY_IS_PACKET("QINF")) + { + // Screen info. Reply with DINF + // kMsgQInfo = "QINF" + // kMsgDInfo = "DINF%2i%2i%2i%2i%2i%2i%2i" + uint16_t x = 0, y = 0, warp = 0; + sAddString(context, "DINF"); + sAddUInt16(context, x); + sAddUInt16(context, y); + sAddUInt16(context, context->m_clientWidth); + sAddUInt16(context, context->m_clientHeight); + sAddUInt16(context, warp); + sAddUInt16(context, 0); // mx? + sAddUInt16(context, 0); // my? + sSendReply(context); + return; + } + else if (USYNERGY_IS_PACKET("CIAK")) + { + // Do nothing? + // kMsgCInfoAck = "CIAK" + return; + } + else if (USYNERGY_IS_PACKET("CROP")) + { + // Do nothing? + // kMsgCResetOptions = "CROP" + return; + } + else if (USYNERGY_IS_PACKET("CINN")) + { + // Screen enter. Reply with CNOP + // kMsgCEnter = "CINN%2i%2i%4i%2i" + + // Obtain the Synergy sequence number + context->m_sequenceNumber = sNetToNative32(message + 12); + context->m_isCaptured = USYNERGY_TRUE; + + // Call callback + if (context->m_screenActiveCallback != 0L) + context->m_screenActiveCallback(context->m_cookie, USYNERGY_TRUE); + } + else if (USYNERGY_IS_PACKET("COUT")) + { + // Screen leave + // kMsgCLeave = "COUT" + context->m_isCaptured = USYNERGY_FALSE; + + // Call callback + if (context->m_screenActiveCallback != 0L) + context->m_screenActiveCallback(context->m_cookie, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DMDN")) + { + // Mouse down + // kMsgDMouseDown = "DMDN%1i" + char btn = message[8]-1; + if (btn==2) + context->m_mouseButtonRight = USYNERGY_TRUE; + else if (btn==1) + context->m_mouseButtonMiddle = USYNERGY_TRUE; + else + context->m_mouseButtonLeft = USYNERGY_TRUE; + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMUP")) + { + // Mouse up + // kMsgDMouseUp = "DMUP%1i" + char btn = message[8]-1; + if (btn==2) + context->m_mouseButtonRight = USYNERGY_FALSE; + else if (btn==1) + context->m_mouseButtonMiddle = USYNERGY_FALSE; + else + context->m_mouseButtonLeft = USYNERGY_FALSE; + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMMV")) + { + // Mouse move. Reply with CNOP + // kMsgDMouseMove = "DMMV%2i%2i" + context->m_mouseX = sNetToNative16(message+8); + context->m_mouseY = sNetToNative16(message+10); + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DMWM")) + { + // Mouse wheel + // kMsgDMouseWheel = "DMWM%2i%2i" + // kMsgDMouseWheel1_0 = "DMWM%2i" + context->m_mouseWheelX += sNetToNative16(message+8); + context->m_mouseWheelY += sNetToNative16(message+10); + sSendMouseCallback(context); + } + else if (USYNERGY_IS_PACKET("DKDN")) + { + // Key down + // kMsgDKeyDown = "DKDN%2i%2i%2i" + // kMsgDKeyDown1_0 = "DKDN%2i%2i" + //uint16_t id = sNetToNative16(message+8); + uint16_t mod = sNetToNative16(message+10); + uint16_t key = sNetToNative16(message+12); + sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DKRP")) + { + // Key repeat + // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" + // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" + uint16_t mod = sNetToNative16(message+10); +// uint16_t count = sNetToNative16(message+12); + uint16_t key = sNetToNative16(message+14); + sSendKeyboardCallback(context, key, mod, USYNERGY_TRUE, USYNERGY_TRUE); + } + else if (USYNERGY_IS_PACKET("DKUP")) + { + // Key up + // kMsgDKeyUp = "DKUP%2i%2i%2i" + // kMsgDKeyUp1_0 = "DKUP%2i%2i" + //uint16 id=Endian::sNetToNative(sbuf[4]); + uint16_t mod = sNetToNative16(message+10); + uint16_t key = sNetToNative16(message+12); + sSendKeyboardCallback(context, key, mod, USYNERGY_FALSE, USYNERGY_FALSE); + } + else if (USYNERGY_IS_PACKET("DGBT")) + { + // Joystick buttons + // kMsgDGameButtons = "DGBT%1i%2i"; + uint8_t joy_num = message[8]; + if (joy_numm_joystickButtons[joy_num] = (message[9] << 8) | message[10]; + sSendJoystickCallback(context, joy_num); + } + } + else if (USYNERGY_IS_PACKET("DGST")) + { + // Joystick sticks + // kMsgDGameSticks = "DGST%1i%1i%1i%1i%1i"; + uint8_t joy_num = message[8]; + if (joy_numm_joystickSticks[joy_num], message+9, 4); + sSendJoystickCallback(context, joy_num); + } + } + else if (USYNERGY_IS_PACKET("DSOP")) + { + // Set options + // kMsgDSetOptions = "DSOP%4I" + } + else if (USYNERGY_IS_PACKET("CALV")) + { + // Keepalive, reply with CALV and then CNOP + // kMsgCKeepAlive = "CALV" + sAddString(context, "CALV"); + sSendReply(context); + // now reply with CNOP + } + else if (USYNERGY_IS_PACKET("DCLP")) + { + // Clipboard message + // kMsgDClipboard = "DCLP%1i%4i%s" + // + // The clipboard message contains: + // 1 uint32: The size of the message + // 4 chars: The identifier ("DCLP") + // 1 uint8: The clipboard index + // 1 uint32: The sequence number. It's zero, because this message is always coming from the server? + // 1 uint32: The total size of the remaining 'string' (as per the Synergy %s string format (which is 1 uint32 for size followed by a char buffer (not necessarily null terminated)). + // 1 uint32: The number of formats present in the message + // And then 'number of formats' times the following: + // 1 uint32: The format of the clipboard data + // 1 uint32: The size n of the clipboard data + // n uint8: The clipboard data + const uint8_t * parse_msg = message+17; + uint32_t num_formats = sNetToNative32(parse_msg); + parse_msg += 4; + for (; num_formats; num_formats--) + { + // Parse clipboard format header + uint32_t format = sNetToNative32(parse_msg); + uint32_t size = sNetToNative32(parse_msg+4); + parse_msg += 8; + + // Call callback + if (context->m_clipboardCallback) + context->m_clipboardCallback(context->m_cookie, format, parse_msg, size); + + parse_msg += size; + } + } + else + { + // Unknown packet, could be any of these + // kMsgCNoop = "CNOP" + // kMsgCClose = "CBYE" + // kMsgCClipboard = "CCLP%1i%4i" + // kMsgCScreenSaver = "CSEC%1i" + // kMsgDKeyRepeat = "DKRP%2i%2i%2i%2i" + // kMsgDKeyRepeat1_0 = "DKRP%2i%2i%2i" + // kMsgDMouseRelMove = "DMRM%2i%2i" + // kMsgEIncompatible = "EICV%2i%2i" + // kMsgEBusy = "EBSY" + // kMsgEUnknown = "EUNK" + // kMsgEBad = "EBAD" + char buffer[64]; + sprintf(buffer, "Unknown packet '%c%c%c%c'", message[4], message[5], message[6], message[7]); + sTrace(context, buffer); + return; + } + + // Reply with CNOP maybe? + sAddString(context, "CNOP"); + sSendReply(context); +} +#undef USYNERGY_IS_PACKET + + + +/** +@brief Mark context as being disconnected +**/ +static void sSetDisconnected(uSynergyContext *context) +{ + context->m_connected = USYNERGY_FALSE; + context->m_hasReceivedHello = USYNERGY_FALSE; + context->m_isCaptured = USYNERGY_FALSE; + context->m_replyCur = context->m_replyBuffer + 4; + context->m_sequenceNumber = 0; +} + + + +/** +@brief Update a connected context +**/ +static void sUpdateContext(uSynergyContext *context) +{ + /* Receive data (blocking) */ + int receive_size = USYNERGY_RECEIVE_BUFFER_SIZE - context->m_receiveOfs; + int num_received = 0; + int packlen = 0; + if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer + context->m_receiveOfs, receive_size, &num_received) == USYNERGY_FALSE) + { + /* Receive failed, let's try to reconnect */ + char buffer[128]; + sprintf(buffer, "Receive failed (%d bytes asked, %d bytes received), trying to reconnect in a second", receive_size, num_received); + sTrace(context, buffer); + sSetDisconnected(context); + context->m_sleepFunc(context->m_cookie, 1000); + return; + } + context->m_receiveOfs += num_received; + + /* If we didn't receive any data then we're probably still polling to get connected and + therefore not getting any data back. To avoid overloading the system with a Synergy + thread that would hammer on polling, we let it rest for a bit if there's no data. */ + if (num_received == 0) + context->m_sleepFunc(context->m_cookie, 500); + + /* Check for timeouts */ + if (context->m_hasReceivedHello) + { + uint32_t cur_time = context->m_getTimeFunc(); + if (num_received == 0) + { + /* Timeout after 2 secs of inactivity (we received no CALV) */ + if ((cur_time - context->m_lastMessageTime) > USYNERGY_IDLE_TIMEOUT) + sSetDisconnected(context); + } + else + context->m_lastMessageTime = cur_time; + } + + /* Eat packets */ + for (;;) + { + /* Grab packet length and bail out if the packet goes beyond the end of the buffer */ + packlen = sNetToNative32(context->m_receiveBuffer); + if (packlen+4 > context->m_receiveOfs) + break; + + /* Process message */ + sProcessMessage(context, context->m_receiveBuffer); + + /* Move packet to front of buffer */ + memmove(context->m_receiveBuffer, context->m_receiveBuffer+packlen+4, context->m_receiveOfs-packlen-4); + context->m_receiveOfs -= packlen+4; + } + + /* Throw away over-sized packets */ + if (packlen > USYNERGY_RECEIVE_BUFFER_SIZE) + { + /* Oversized packet, ditch tail end */ + char buffer[128]; + sprintf(buffer, "Oversized packet: '%c%c%c%c' (length %d)", context->m_receiveBuffer[4], context->m_receiveBuffer[5], context->m_receiveBuffer[6], context->m_receiveBuffer[7], packlen); + sTrace(context, buffer); + num_received = context->m_receiveOfs-4; // 4 bytes for the size field + while (num_received != packlen) + { + int buffer_left = packlen - num_received; + int to_receive = buffer_left < USYNERGY_RECEIVE_BUFFER_SIZE ? buffer_left : USYNERGY_RECEIVE_BUFFER_SIZE; + int ditch_received = 0; + if (context->m_receiveFunc(context->m_cookie, context->m_receiveBuffer, to_receive, &ditch_received) == USYNERGY_FALSE) + { + /* Receive failed, let's try to reconnect */ + sTrace(context, "Receive failed, trying to reconnect in a second"); + sSetDisconnected(context); + context->m_sleepFunc(context->m_cookie, 1000); + break; + } + else + { + num_received += ditch_received; + } + } + context->m_receiveOfs = 0; + } +} + + +//--------------------------------------------------------------------------------------------------------------------- +// Public interface +//--------------------------------------------------------------------------------------------------------------------- + + + +/** +@brief Initialize uSynergy context +**/ +void uSynergyInit(uSynergyContext *context) +{ + /* Zero memory */ + memset(context, 0, sizeof(uSynergyContext)); + + /* Initialize to default state */ + sSetDisconnected(context); +} + + +/** +@brief Update uSynergy +**/ +void uSynergyUpdate(uSynergyContext *context) +{ + if (context->m_connected) + { + /* Update context, receive data, call callbacks */ + sUpdateContext(context); + } + else + { + /* Try to connect */ + if (context->m_connectFunc(context->m_cookie)) + context->m_connected = USYNERGY_TRUE; + } +} + + + +/** +@brief Send clipboard data +**/ +void uSynergySendClipboard(uSynergyContext *context, const char *text) +{ + // Calculate maximum size that will fit in a reply packet + uint32_t overhead_size = 4 + /* Message size */ + 4 + /* Message ID */ + 1 + /* Clipboard index */ + 4 + /* Sequence number */ + 4 + /* Rest of message size (because it's a Synergy string from here on) */ + 4 + /* Number of clipboard formats */ + 4 + /* Clipboard format */ + 4; /* Clipboard data length */ + uint32_t max_length = USYNERGY_REPLY_BUFFER_SIZE - overhead_size; + + // Clip text to max length + uint32_t text_length = (uint32_t)strlen(text); + if (text_length > max_length) + { + char buffer[128]; + sprintf(buffer, "Clipboard buffer too small, clipboard truncated at %d characters", max_length); + sTrace(context, buffer); + text_length = max_length; + } + + // Assemble packet + sAddString(context, "DCLP"); + sAddUInt8(context, 0); /* Clipboard index */ + sAddUInt32(context, context->m_sequenceNumber); + sAddUInt32(context, 4+4+4+text_length); /* Rest of message size: numFormats, format, length, data */ + sAddUInt32(context, 1); /* Number of formats (only text for now) */ + sAddUInt32(context, USYNERGY_CLIPBOARD_FORMAT_TEXT); + sAddUInt32(context, text_length); + sAddString(context, text); + sSendReply(context); +} diff --git a/deps/imgui-1.65/examples/libs/usynergy/uSynergy.h b/demo/deps/imgui-1.65/examples/libs/usynergy/uSynergy.h similarity index 100% rename from deps/imgui-1.65/examples/libs/usynergy/uSynergy.h rename to demo/deps/imgui-1.65/examples/libs/usynergy/uSynergy.h diff --git a/deps/imgui-1.65/imconfig.h b/demo/deps/imgui-1.65/imconfig.h similarity index 100% rename from deps/imgui-1.65/imconfig.h rename to demo/deps/imgui-1.65/imconfig.h diff --git a/deps/imgui-1.65/imgui.cpp b/demo/deps/imgui-1.65/imgui.cpp similarity index 100% rename from deps/imgui-1.65/imgui.cpp rename to demo/deps/imgui-1.65/imgui.cpp diff --git a/deps/imgui-1.65/imgui.h b/demo/deps/imgui-1.65/imgui.h similarity index 100% rename from deps/imgui-1.65/imgui.h rename to demo/deps/imgui-1.65/imgui.h diff --git a/deps/imgui-1.65/imgui_demo.cpp b/demo/deps/imgui-1.65/imgui_demo.cpp similarity index 100% rename from deps/imgui-1.65/imgui_demo.cpp rename to demo/deps/imgui-1.65/imgui_demo.cpp diff --git a/deps/imgui-1.65/imgui_draw.cpp b/demo/deps/imgui-1.65/imgui_draw.cpp similarity index 100% rename from deps/imgui-1.65/imgui_draw.cpp rename to demo/deps/imgui-1.65/imgui_draw.cpp diff --git a/deps/imgui-1.65/imgui_internal.h b/demo/deps/imgui-1.65/imgui_internal.h similarity index 100% rename from deps/imgui-1.65/imgui_internal.h rename to demo/deps/imgui-1.65/imgui_internal.h diff --git a/deps/imgui-1.65/imgui_widgets.cpp b/demo/deps/imgui-1.65/imgui_widgets.cpp similarity index 100% rename from deps/imgui-1.65/imgui_widgets.cpp rename to demo/deps/imgui-1.65/imgui_widgets.cpp diff --git a/deps/imgui-1.65/imstb_rectpack.h b/demo/deps/imgui-1.65/imstb_rectpack.h similarity index 100% rename from deps/imgui-1.65/imstb_rectpack.h rename to demo/deps/imgui-1.65/imstb_rectpack.h diff --git a/deps/imgui-1.65/imstb_textedit.h b/demo/deps/imgui-1.65/imstb_textedit.h similarity index 100% rename from deps/imgui-1.65/imstb_textedit.h rename to demo/deps/imgui-1.65/imstb_textedit.h diff --git a/deps/imgui-1.65/imstb_truetype.h b/demo/deps/imgui-1.65/imstb_truetype.h similarity index 100% rename from deps/imgui-1.65/imstb_truetype.h rename to demo/deps/imgui-1.65/imstb_truetype.h diff --git a/deps/imgui-1.65/misc/fonts/Cousine-Regular.ttf b/demo/deps/imgui-1.65/misc/fonts/Cousine-Regular.ttf similarity index 100% rename from deps/imgui-1.65/misc/fonts/Cousine-Regular.ttf rename to demo/deps/imgui-1.65/misc/fonts/Cousine-Regular.ttf diff --git a/deps/imgui-1.65/misc/fonts/DroidSans.ttf b/demo/deps/imgui-1.65/misc/fonts/DroidSans.ttf similarity index 100% rename from deps/imgui-1.65/misc/fonts/DroidSans.ttf rename to demo/deps/imgui-1.65/misc/fonts/DroidSans.ttf diff --git a/deps/imgui-1.65/misc/fonts/Karla-Regular.ttf b/demo/deps/imgui-1.65/misc/fonts/Karla-Regular.ttf similarity index 100% rename from deps/imgui-1.65/misc/fonts/Karla-Regular.ttf rename to demo/deps/imgui-1.65/misc/fonts/Karla-Regular.ttf diff --git a/deps/imgui-1.65/misc/fonts/ProggyClean.ttf b/demo/deps/imgui-1.65/misc/fonts/ProggyClean.ttf similarity index 100% rename from deps/imgui-1.65/misc/fonts/ProggyClean.ttf rename to demo/deps/imgui-1.65/misc/fonts/ProggyClean.ttf diff --git a/deps/imgui-1.65/misc/fonts/ProggyTiny.ttf b/demo/deps/imgui-1.65/misc/fonts/ProggyTiny.ttf similarity index 100% rename from deps/imgui-1.65/misc/fonts/ProggyTiny.ttf rename to demo/deps/imgui-1.65/misc/fonts/ProggyTiny.ttf diff --git a/deps/imgui-1.65/misc/fonts/README.txt b/demo/deps/imgui-1.65/misc/fonts/README.txt similarity index 100% rename from deps/imgui-1.65/misc/fonts/README.txt rename to demo/deps/imgui-1.65/misc/fonts/README.txt diff --git a/deps/imgui-1.65/misc/fonts/Roboto-Medium.ttf b/demo/deps/imgui-1.65/misc/fonts/Roboto-Medium.ttf similarity index 100% rename from deps/imgui-1.65/misc/fonts/Roboto-Medium.ttf rename to demo/deps/imgui-1.65/misc/fonts/Roboto-Medium.ttf diff --git a/deps/imgui-1.65/misc/fonts/binary_to_compressed_c.cpp b/demo/deps/imgui-1.65/misc/fonts/binary_to_compressed_c.cpp similarity index 100% rename from deps/imgui-1.65/misc/fonts/binary_to_compressed_c.cpp rename to demo/deps/imgui-1.65/misc/fonts/binary_to_compressed_c.cpp diff --git a/deps/imgui-1.65/misc/freetype/README.md b/demo/deps/imgui-1.65/misc/freetype/README.md similarity index 100% rename from deps/imgui-1.65/misc/freetype/README.md rename to demo/deps/imgui-1.65/misc/freetype/README.md diff --git a/deps/imgui-1.65/misc/freetype/imgui_freetype.cpp b/demo/deps/imgui-1.65/misc/freetype/imgui_freetype.cpp similarity index 100% rename from deps/imgui-1.65/misc/freetype/imgui_freetype.cpp rename to demo/deps/imgui-1.65/misc/freetype/imgui_freetype.cpp diff --git a/deps/imgui-1.65/misc/freetype/imgui_freetype.h b/demo/deps/imgui-1.65/misc/freetype/imgui_freetype.h similarity index 100% rename from deps/imgui-1.65/misc/freetype/imgui_freetype.h rename to demo/deps/imgui-1.65/misc/freetype/imgui_freetype.h diff --git a/deps/imgui-1.65/misc/natvis/README.txt b/demo/deps/imgui-1.65/misc/natvis/README.txt similarity index 100% rename from deps/imgui-1.65/misc/natvis/README.txt rename to demo/deps/imgui-1.65/misc/natvis/README.txt diff --git a/deps/imgui-1.65/misc/natvis/imgui.natvis b/demo/deps/imgui-1.65/misc/natvis/imgui.natvis similarity index 100% rename from deps/imgui-1.65/misc/natvis/imgui.natvis rename to demo/deps/imgui-1.65/misc/natvis/imgui.natvis diff --git a/deps/imgui-1.65/misc/stl/imgui_stl.cpp b/demo/deps/imgui-1.65/misc/stl/imgui_stl.cpp similarity index 100% rename from deps/imgui-1.65/misc/stl/imgui_stl.cpp rename to demo/deps/imgui-1.65/misc/stl/imgui_stl.cpp diff --git a/deps/imgui-1.65/misc/stl/imgui_stl.h b/demo/deps/imgui-1.65/misc/stl/imgui_stl.h similarity index 100% rename from deps/imgui-1.65/misc/stl/imgui_stl.h rename to demo/deps/imgui-1.65/misc/stl/imgui_stl.h diff --git a/deps/stb/stb_image.h b/demo/deps/stb/stb_image.h similarity index 100% rename from deps/stb/stb_image.h rename to demo/deps/stb/stb_image.h diff --git a/src/main.cpp b/demo/main.cpp similarity index 100% rename from src/main.cpp rename to demo/main.cpp diff --git a/src/Array2D.h b/include/Array2D.h similarity index 99% rename from src/Array2D.h rename to include/Array2D.h index 737b687..9203ed1 100644 --- a/src/Array2D.h +++ b/include/Array2D.h @@ -343,12 +343,12 @@ struct Array2D { for (int j = 0; j < 4; j++) { - int yp = utils::clamp(y+j-1, 0, NY-1); + int yp = aml::clamp(y+j-1, 0, NY-1); r[j] = 0; for (int i = 0; i < 4; i++) { - int xp = utils::clamp(x+i-1, 0, NX-1); - r[j] += u[i] * data[yp][xp]; + int xp = aml::clamp(x+i-1, 0, NX-1); + r[j] += u[i] * data[yp*NX + xp]; } vox += v[j] * r[j]; } diff --git a/src/Array3D.h b/include/Array3D.h similarity index 100% rename from src/Array3D.h rename to include/Array3D.h diff --git a/src/FluidSim2D.h b/include/FluidSim2D.h similarity index 99% rename from src/FluidSim2D.h rename to include/FluidSim2D.h index 08da98d..5f82226 100644 --- a/src/FluidSim2D.h +++ b/include/FluidSim2D.h @@ -8,8 +8,6 @@ #include #include #include -#include "FluidSimSettings.h" - #include "Array2D.h" #include "MACGrid2D.h" #include "PerformanceCounter.h" diff --git a/src/FluidSim3D.h b/include/FluidSim3D.h similarity index 97% rename from src/FluidSim3D.h rename to include/FluidSim3D.h index 0bfcf92..a5aa78f 100644 --- a/src/FluidSim3D.h +++ b/include/FluidSim3D.h @@ -4,8 +4,7 @@ #ifndef FLUID_SIM_FLUIDSIM_H -#include - +#include #include "FluidSimSettings.h" #include "MACGrid3D.h" diff --git a/src/FluidSimSettings.h b/include/FluidSimSettings.h similarity index 100% rename from src/FluidSimSettings.h rename to include/FluidSimSettings.h diff --git a/src/MACGrid2D.h b/include/MACGrid2D.h similarity index 100% rename from src/MACGrid2D.h rename to include/MACGrid2D.h diff --git a/src/MACGrid3D.h b/include/MACGrid3D.h similarity index 100% rename from src/MACGrid3D.h rename to include/MACGrid3D.h diff --git a/src/PerformanceCounter.h b/include/PerformanceCounter.h similarity index 90% rename from src/PerformanceCounter.h rename to include/PerformanceCounter.h index 13e3360..697497a 100644 --- a/src/PerformanceCounter.h +++ b/include/PerformanceCounter.h @@ -1,42 +1,39 @@ -// -// Created by lasagnaphil on 2018-11-26. -// - -#ifndef FLUID_SIM_PERFORMANCECOUNTER_H -#define FLUID_SIM_PERFORMANCECOUNTER_H - -#include -#include -#include - -struct PerformanceCounter { - using Clock = std::chrono::high_resolution_clock; - using TimePoint = decltype(Clock::now()); - - static constexpr int SampleCount = 30; - TimePoint currentTime; - int currentStage = 0; - int currentFrame = 0; - Vec samples = {}; - Vec average = {}; - float avgTimePerFrame; - bool sampleFinished = false; - - Vec averageStore; - - static PerformanceCounter create(int numStages); - - void beginStage(); - - void endStage(); - - void endFrame(); - - void renderUI(); - - void saveToFile(const char* filename); - - void free(); -}; - -#endif //FLUID_SIM_PERFORMANCECOUNTER_H +// +// Created by lasagnaphil on 2018-11-26. +// + +#ifndef FLUID_SIM_PERFORMANCECOUNTER_H +#define FLUID_SIM_PERFORMANCECOUNTER_H + +#include +#include + +struct PerformanceCounter { + using Clock = std::chrono::high_resolution_clock; + using TimePoint = decltype(Clock::now()); + + static constexpr int SampleCount = 30; + TimePoint currentTime; + int currentStage = 0; + int currentFrame = 0; + Vec samples = {}; + Vec average = {}; + float avgTimePerFrame; + bool sampleFinished = false; + + Vec averageStore; + + static PerformanceCounter create(int numStages); + + void beginStage(); + + void endStage(); + + void endFrame(); + + void saveToFile(const char* filename); + + void free(); +}; + +#endif //FLUID_SIM_PERFORMANCECOUNTER_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..75dd852 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,32 @@ +file(GLOB LIBRARY_INTERNAL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) +file(GLOB LIBRARY_INTERNAL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +add_library(fluid_sim ${LIBRARY_HEADERS} ${LIBRARY_INTERNAL_HEADERS} ${LIBRARY_INTERNAL_SOURCES}) + +target_include_directories(fluid_sim + PUBLIC ${LIBRARY_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} +) + +# altlib +target_include_directories(fluid_sim PUBLIC altlib) +target_link_libraries(fluid_sim PUBLIC altlib) + +# altmath +target_include_directories(fluid_sim PUBLIC altmath) +target_link_libraries(fluid_sim PUBLIC altmath) + +# PThreads +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) +target_link_libraries(fluid_sim PRIVATE Threads::Threads) + +# OpenMP +find_package(OpenMP) +if (OpenMP_FOUND) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") +endif() + diff --git a/src/FluidSim2D.cpp b/src/FluidSim2D.cpp index dd49bdf..7b09c69 100644 --- a/src/FluidSim2D.cpp +++ b/src/FluidSim2D.cpp @@ -11,7 +11,6 @@ #include #include #include "FluidSim2D.h" -#include "InputManager.h" #define USE_GHOST_PRESSURE #define USE_LEVEL_SET diff --git a/src/FluidSim3D.cpp b/src/FluidSim3D.cpp index 9e7557d..a780cc4 100644 --- a/src/FluidSim3D.cpp +++ b/src/FluidSim3D.cpp @@ -2,9 +2,8 @@ // Created by lasagnaphil on 9/13/18. // #include +#include #include "FluidSim3D.h" -#include "FirstPersonCamera.h" -#include "InputManager.h" #include "Defer.h" #include "log.h" @@ -41,27 +40,7 @@ void FluidSim3D::runFrame() { } void FluidSim3D::update() { - static int nextStage = 0; - auto inputMgr = InputManager::get(); - if (inputMgr->isKeyEntered(SDL_SCANCODE_RETURN)) { - /* - if (nextStage == 0) { - applyAdvection(); - stage = Stage::ADVECTION; - } - else if (nextStage == 1) { - applyGravity(); - stage = Stage::GRAVITY; - } - else if (nextStage == 2) { - applyProjection(); - stage = Stage::PROJECTION; - } - nextStage = (nextStage + 1) % 3; - rendered = false; - */ - runFrame(); - } + runFrame(); } void FluidSim3D::debugPrint() { diff --git a/src/PerformanceCounter.cpp b/src/PerformanceCounter.cpp index 641815d..49f5968 100644 --- a/src/PerformanceCounter.cpp +++ b/src/PerformanceCounter.cpp @@ -49,17 +49,6 @@ void PerformanceCounter::endFrame() { } } -void PerformanceCounter::renderUI() { - if (sampleFinished) { - for (int i = 0; i < average.size; i++) { - ImGui::Text("Stage %d: %f ms", i, average[i]); - } - ImGui::Text("Avg time per frame: %f ms", avgTimePerFrame); - } else { - ImGui::Text("Sampling frames..."); - } -} - void PerformanceCounter::free() { samples.free(); average.free();