// core.c #include #include #define SDL_MAIN_HANDLED #include #ifdef __WIN32__ # define SHARED_OBJECT "ampler.dll" # define SHARED_OBJECT_ACTIVE SHARED_OBJECT "-active.dll" #else # define SHARED_OBJECT "./ampler.so" # define SHARED_OBJECT_ACTIVE SHARED_OBJECT #endif #define SHARED_MAIN "ampler_main" #ifdef __WIN32__ int copy_shared_object() { if (system("copy " SHARED_OBJECT " " SHARED_OBJECT_ACTIVE " /Y")) { puts("failed copying to " SHARED_OBJECT_ACTIVE); // puts(SDL_GetError()); return 1; } return 0; } #else int copy_shared_object() { return 0; } #endif 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, 512, 512, SDL_WINDOW_RESIZABLE); r = SDL_CreateRenderer(w, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); void *u_data = NULL; while (1) { if (copy_shared_object()) 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; }