From 2e1d17125193f359f4af14011611198440734ad5 Mon Sep 17 00:00:00 2001 From: bxwtf Date: Sat, 18 Dec 2021 17:36:08 +0000 Subject: [PATCH] initial commit --- .gitignore | 3 +++ ampler.c | 23 +++++++++++++++++ compile-ampler.bat | 64 ++++++++++++++++++++++++++++++++++++++++++++++ compile-core.bat | 1 + core.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 .gitignore create mode 100644 ampler.c create mode 100644 compile-ampler.bat create mode 100644 compile-core.bat create mode 100644 core.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fc303d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +*.exe +*.dll diff --git a/ampler.c b/ampler.c new file mode 100644 index 0000000..8d73361 --- /dev/null +++ b/ampler.c @@ -0,0 +1,23 @@ +// ampler.c + +#include +#include + +#include + +int ampler_main(SDL_Window *w, SDL_Renderer *r, void **u_data) { + SDL_Event e; + while (1) { + while(SDL_PollEvent(&e)) + if (e.type == SDL_QUIT) + return 1; + SDL_RenderPresent(r); + SDL_Delay(1); + + if (!remove("reload-trigger")) { + puts("removed reload-trigger, reloading..."); + return 0; + } + } +} + diff --git a/compile-ampler.bat b/compile-ampler.bat new file mode 100644 index 0000000..ad5b18c --- /dev/null +++ b/compile-ampler.bat @@ -0,0 +1,64 @@ +@echo off + +:: https://stackoverflow.com/questions/32895172/how-to-detect-change-in-txt-file-using-batch +:: https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file + +setlocal enableDelayedExpansion + +set compmsg=compiling... + +del reload-trigger + +:do_compile +set "stime=%time: =0%" +set "stime=%stime:~0,-3%" +set "stime=%stime::=%" +set "sdate=%date:~6,4%%date:~3,2%%date:~0,2%" + +cls +echo %compmsg% +echo. +:: taskkill /F /IM main.exe +:: taskkill /F /IM Microsoft.Photos.exe +:: taskkill /F /IM Video.UI.exe +echo. +echo compiling main.c +echo. +echo %time% + +:: cl main.c /O2 /MP /nologo /I include /link lib/avcodec.lib lib/avformat.lib lib/swscale.lib lib/avutil.lib lib/SDL2.lib lib/swresample.lib +tcc\tcc ampler.c -o ampler.dll -shared -lsdl2 -lws2_32 -g -rdynamic + +echo %time% +if %ERRORLEVEL% GEQ 1 goto compiler_error +:: del *.obj +:: del *.exp +:: del *.lib +del ampler.def +echo. +echo creating reload-trigger +echo. +echo > reload-trigger +echo. + +:compiler_error + +:do_compare_times +for %%f in (*.c *.h) do ( + set compmsg=%%f compiling... + + for /f "tokens=*" %%g in ('forfiles /m %%f /c "cmd /c echo @ftime"') do (set ftime=%%g) + + set "ftime=!ftime::=!" + + for /f "tokens=*" %%g in ('forfiles /m %%f /c "cmd /c echo @fdate"') do (set fdate=%%g) + + set "fdate=!fdate:~6,4!!fdate:~3,2!!fdate:~0,2!" + + if /i !ftime! gtr !stime! if /i !fdate! geq !sdate! (goto do_compile) +) + +REM timeout /t 1 > nul + +goto do_compare_times + diff --git a/compile-core.bat b/compile-core.bat new file mode 100644 index 0000000..9734e75 --- /dev/null +++ b/compile-core.bat @@ -0,0 +1 @@ +tcc\tcc.exe core.c -o core.exe -lsdl2 -lws2_32 -g || cmd diff --git a/core.c b/core.c new file mode 100644 index 0000000..3229bc8 --- /dev/null +++ b/core.c @@ -0,0 +1,61 @@ +// core.c + +#include +#include + +#define SDL_MAIN_HANDLED +#include + +#define SHARED_OBJECT "ampler.dll" +#define SHARED_MAIN "ampler_main" + + +#define SHARED_OBJECT_ACTIVE SHARED_OBJECT "-active.dll" + +int main(int argc, char **argv) { + puts("start."); + SDL_Init(SDL_INIT_EVERYTHING); + + SDL_Window *w; + SDL_Renderer *r; + + w = SDL_CreateWindow("core", + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + 480, 480, SDL_WINDOW_RESIZABLE); + r = SDL_CreateRenderer(w, -1, + SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); + + //SDL_CreateWindowAndRenderer( + // 1080, 480, SDL_WINDOW_RESIZABLE, &w, &r); + + void *u_data = NULL; + while (1) { + if (system("copy " SHARED_OBJECT " " SHARED_OBJECT_ACTIVE " /Y")) { + puts("failed copying to " SHARED_OBJECT_ACTIVE); + // puts(SDL_GetError()); + break; + } + + void *so = SDL_LoadObject(SHARED_OBJECT_ACTIVE); + if (so == 0) { + puts("failed load " SHARED_OBJECT_ACTIVE); + puts(SDL_GetError()); + break; + } + + int(*shared_main)(SDL_Window *, SDL_Renderer *, void **) + = SDL_LoadFunction(so, SHARED_MAIN); + + if(shared_main(w, r, &u_data)) + break; + + SDL_UnloadObject(so); + } + + quit: + SDL_DestroyRenderer(r); + SDL_DestroyWindow(w); + SDL_Quit(); + return 0; +} +