initial commit

master
bxwtf 2021-12-18 17:36:08 +00:00
commit 2e1d171251
5 changed files with 152 additions and 0 deletions

3
.gitignore vendored 100644
View File

@ -0,0 +1,3 @@
*.exe
*.dll

23
ampler.c 100644
View File

@ -0,0 +1,23 @@
// ampler.c
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
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;
}
}
}

64
compile-ampler.bat 100644
View File

@ -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

1
compile-core.bat 100644
View File

@ -0,0 +1 @@
tcc\tcc.exe core.c -o core.exe -lsdl2 -lws2_32 -g || cmd

61
core.c 100644
View File

@ -0,0 +1,61 @@
// core.c
#include <stdio.h>
#include <stdlib.h>
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#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;
}