From e77dfde1bc934806690c0ec2f0bfc353bd33a99b Mon Sep 17 00:00:00 2001 From: Seth Hamilton Date: Mon, 15 Sep 2025 10:58:01 -0500 Subject: [PATCH] reorganize to use .bat files instead of .sh. Move demo to an example project --- .gitignore | 3 +- run_before_build.bat => activate.bat | 2 +- {src => assets}/shaders/fragment.glsl | 0 {src => assets}/shaders/vertex.glsl | 0 bin/LivePlotter.exp | Bin 1419 -> 0 bytes bin/LivePlotter.lib | 3 -- build.bat | 10 ++++++ build.sh | 22 ------------- examples/{ => csharp}/LivePlotter.cs | 0 examples/demo/activate.bat | 0 examples/demo/build.bat | 12 +++++++ examples/demo/export.bat | 22 +++++++++++++ {src/demo => examples/demo/src}/demo.cpp | 0 examples/demo/src/util.cpp | 40 +++++++++++++++++++++++ export.bat | 22 +++++++++++++ export_compdb.sh | 5 --- inc/util.hpp | 9 +++-- src/util.cpp | 4 --- 18 files changed, 115 insertions(+), 39 deletions(-) rename run_before_build.bat => activate.bat (65%) rename {src => assets}/shaders/fragment.glsl (100%) rename {src => assets}/shaders/vertex.glsl (100%) delete mode 100644 bin/LivePlotter.exp delete mode 100644 bin/LivePlotter.lib create mode 100644 build.bat delete mode 100644 build.sh rename examples/{ => csharp}/LivePlotter.cs (100%) create mode 100644 examples/demo/activate.bat create mode 100644 examples/demo/build.bat create mode 100644 examples/demo/export.bat rename {src/demo => examples/demo/src}/demo.cpp (100%) create mode 100644 examples/demo/src/util.cpp create mode 100644 export.bat delete mode 100644 export_compdb.sh diff --git a/.gitignore b/.gitignore index 796b275..d80ffa7 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ x64** **.exe .cache** tags -bin/* +**/bin/** +**/obj/** compile_commands.json diff --git a/run_before_build.bat b/activate.bat similarity index 65% rename from run_before_build.bat rename to activate.bat index 8a4e494..7a6b935 100644 --- a/run_before_build.bat +++ b/activate.bat @@ -1 +1 @@ -"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" && bash +"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" diff --git a/src/shaders/fragment.glsl b/assets/shaders/fragment.glsl similarity index 100% rename from src/shaders/fragment.glsl rename to assets/shaders/fragment.glsl diff --git a/src/shaders/vertex.glsl b/assets/shaders/vertex.glsl similarity index 100% rename from src/shaders/vertex.glsl rename to assets/shaders/vertex.glsl diff --git a/bin/LivePlotter.exp b/bin/LivePlotter.exp deleted file mode 100644 index f37678f07ad64d98887928d08180077e40a2a7dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1419 zcmYdkV`BLK|Ns99%nS??3=p7~nvz(O2w{WBTMP^gDGUq@c8nk%1A_!%-mEkr#Lw=CzYYNB(bQ3p|~W!fT6S?1)-6Lfq{XAfq{XUL56{WffdYBU|?Wi z1G7{Z7#P^WEDZ(*1_3b31L|*P1|0?l20^fx4+8@OCzxfxz`!5`W(6=XFmQocCJYP= z!eCYi0|Ns$m}S8Li3Mhc2nGfQkSmxOY#10AM8UE#3=9msV3q>|1A`ctmB7Hjzz1fz zFfcHPgISK~QRdq#$kv3qeqd0H-9737{;1lA;`v^K%RIGE;gx85sZn2c;~BwA92BJp%&) z4h9B@2y*@ext^H;IVXbL&dg9;<(HV7%D_;;z`y`eQuK>O~i;{3Yv&9!$LF>6Nc4jBBl&G&_v7_4xx#dGn_yZv0yk0 z7XkSI6zm`xgh9TAoGxq=e)0EdF~ng9R* diff --git a/bin/LivePlotter.lib b/bin/LivePlotter.lib deleted file mode 100644 index ed8983b..0000000 --- a/bin/LivePlotter.lib +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d3493c95ff50fb289d73875d4c862070cb134cce84349bd9c802dfd7aa500d41 -size 2986 diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..8b99014 --- /dev/null +++ b/build.bat @@ -0,0 +1,10 @@ +@ECHO off +SET flags=-Od -ZI -MDd +IF "%1" == "release" ( + SET flags=-O2 -MTd +) +SET srcs=src\* +mkdir bin obj +cl %srcs% ext\glfw\build\src\Debug\glfw3.lib kernel32.lib user32.lib Gdi32.lib Shell32.lib -I inc -I ext\glm -I ext\glfw\include %flags% -std:c++20 -MP -LD -Fo:obj\\ -Fe:bin\\LivePlotter.dll +COPY /Y assets\* bin +COPY /Y assets\shaders\* bin diff --git a/build.sh b/build.sh deleted file mode 100644 index aabc36d..0000000 --- a/build.sh +++ /dev/null @@ -1,22 +0,0 @@ -( - cd bin - rm * - demo_srcs=../src/demo/*.cpp - demo_srcs+=" ../src/util.cpp" - plotter_srcs=../src/*.cpp - glad_src=../src/glad.c - glfw_lib=../ext/glfw/build/src/Debug/glfw3.lib - if [ $# -eq 1 ] && [ "$1" == "release" ] - then - dll_flags="-O2 -MTd" - exe_flags="-O2 -MT" - else - dll_flags="-Od -ZI -MDd" - exe_flags="-Od -ZI -MD" - fi - echo $flags - cl $plotter_srcs $glad_src $glfw_lib kernel32.lib user32.lib Gdi32.lib Shell32.lib -I ../inc -I ../ext/glm -I ../ext/glfw/include $dll_flags -MP -std:c++20 -LD -FeLivePlotter.dll - cp ../src/shaders/* . - cp ../assets/* . - cl $demo_srcs -I ../inc -I ../ext/glm $exe_flags -MP -std:c++20 -Fedemo.exe -) diff --git a/examples/LivePlotter.cs b/examples/csharp/LivePlotter.cs similarity index 100% rename from examples/LivePlotter.cs rename to examples/csharp/LivePlotter.cs diff --git a/examples/demo/activate.bat b/examples/demo/activate.bat new file mode 100644 index 0000000..e69de29 diff --git a/examples/demo/build.bat b/examples/demo/build.bat new file mode 100644 index 0000000..027a686 --- /dev/null +++ b/examples/demo/build.bat @@ -0,0 +1,12 @@ +SET flags=-Od -ZI -MD +IF "%1" == "release" ( + SET flags=-O2 -MT +) +SET srcs=src\* +mkdir bin obj +( +PUSHD ..\.. +CALL build.bat %1 +POPD +COPY /Y ..\..\bin\* bin && cl %srcs% bin\LivePlotter.lib -I ..\..\inc -I ..\..\ext\glm %flags% -std:c++20 -MP -Fo:obj\\ -Fe:bin\\ +) diff --git a/examples/demo/export.bat b/examples/demo/export.bat new file mode 100644 index 0000000..2c8d3c5 --- /dev/null +++ b/examples/demo/export.bat @@ -0,0 +1,22 @@ +@ECHO off +SETLOCAL ENABLEDELAYEDEXPANSION + +ECHO [ > compile_commands.json + +FOR /r "src\" %%F IN (*.cpp) DO ( + +SET "file=%%F" +SET "file=!file:\=/!" +SET "directory=%~dp0" +SET "directory=!directory:\=/!" + +ECHO { >> compile_commands.json +ECHO "directory": "!directory!", >> compile_commands.json +ECHO "command": "cl !file! -I inc -I ../../ext/glm -I ../../ext/glfw/include %flags% -std:c++20 -MD -MP -Fo:obj\\ ", >> compile_commands.json + +ECHO "file": "!file!" >> compile_commands.json +ECHO }, >> compile_commands.json + +) + +ECHO ] >> compile_commands.json diff --git a/src/demo/demo.cpp b/examples/demo/src/demo.cpp similarity index 100% rename from src/demo/demo.cpp rename to examples/demo/src/demo.cpp diff --git a/examples/demo/src/util.cpp b/examples/demo/src/util.cpp new file mode 100644 index 0000000..2ab9d7a --- /dev/null +++ b/examples/demo/src/util.cpp @@ -0,0 +1,40 @@ +#include "util.hpp" + +using namespace std; + +bool read_file(string* s, const char* filepath) { + ifstream file(filepath); + if (!file.is_open()) { + return false; + } + *s = { istreambuf_iterator(file), istreambuf_iterator() }; + return true; +} + +vector split_str(string s, char delim) { + vector res; + string cur_word; + istringstream ss(s); + while (getline(ss, cur_word, delim)) { + res.push_back(cur_word); + } + return res; +} + +// https://songho.ca/opengl/gl_quaternion.html +glm::mat4 quat_to_mat4(glm::quat q) { + glm::vec4 col0 = glm::vec4( + 1 - 2 * q.y * q.y - 2 * q.z * q.z, 2 * q.x * q.y + 2 * q.w * q.z, 2 * q.x * q.z - 2 * q.w * q.y, 0); + + glm::vec4 col1 = glm::vec4( + 2 * q.x * q.y - 2 * q.w * q.z, 1 - 2 * q.x * q.x - 2 * q.z * q.z, 2 * q.y * q.z + 2 * q.w * q.x, 0); + + glm::vec4 col2 = glm::vec4( + 2 * q.x * q.z + 2 * q.w * q.y, 2 * q.y * q.z - 2 * q.w * q.x, 1 - 2 * q.x * q.x - 2 * q.y * q.y, 0); + + glm::vec4 col3 = glm::vec4(0, 0, 0, 1); + + return glm::mat4(col0, col1, col2, col3); +} + +float randf() { return (float)abs(rand()) / (float)RAND_MAX; } diff --git a/export.bat b/export.bat new file mode 100644 index 0000000..9dcea62 --- /dev/null +++ b/export.bat @@ -0,0 +1,22 @@ +@ECHO off +SETLOCAL ENABLEDELAYEDEXPANSION + +ECHO [ > compile_commands.json + +FOR /r "src\" %%F IN (*.cpp) DO ( + +SET "file=%%F" +SET "file=!file:\=/!" +SET "directory=%~dp0" +SET "directory=!directory:\=/!" + +ECHO { >> compile_commands.json +ECHO "directory": "!directory!", >> compile_commands.json +ECHO "command": "cl !file! -I inc -I ext/glm -I ext/glfw/include %flags% -std:c++20 -MP -LD -Fo:obj\\ ", >> compile_commands.json + +ECHO "file": "!file!" >> compile_commands.json +ECHO }, >> compile_commands.json + +) + +ECHO ] >> compile_commands.json diff --git a/export_compdb.sh b/export_compdb.sh deleted file mode 100644 index 46046a3..0000000 --- a/export_compdb.sh +++ /dev/null @@ -1,5 +0,0 @@ -srcs=src/* - -echo [ > compile_commands.json -find src -iname "*.cpp" -exec sh -c 'echo { \"directory\": \"$(cygpath -m $(pwd))\", \"command\": \"cl "$(cygpath -m {})" -I inc -I ext/glm -I ext/glfw/include -Od -std:c++20 -Fo\", \"file\": \"$(cygpath -m {})\" }, >> compile_commands.json' \; -echo ] >> compile_commands.json diff --git a/inc/util.hpp b/inc/util.hpp index 7e899d5..3ac3546 100644 --- a/inc/util.hpp +++ b/inc/util.hpp @@ -11,9 +11,12 @@ typedef unsigned int uint; -bool read_file(std::string* s, const char* filepath); -std::vector split_str(std::string s, char delim); +using namespace std; + +bool read_file(string* s, const char* filepath); +vector split_str(string s, char delim); glm::mat4 quat_to_mat4(glm::quat q); float randf(); template T lerp(T start, T end, float t) { return t * end + (1 - t) * start; } -template float ilerp(T start, T end, T pos) { return (pos - start) / (end - start); } \ No newline at end of file +template float ilerp(T start, T end, T pos) { return (pos - start) / (end - start); } + diff --git a/src/util.cpp b/src/util.cpp index 319fa87..2ab9d7a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,7 +1,3 @@ -#include -#include -#include - #include "util.hpp" using namespace std;