diff --git a/main.cpp b/main.cpp index 89fb39b..6b36601 100644 --- a/main.cpp +++ b/main.cpp @@ -7,11 +7,13 @@ #include #include -template -using sdl_deleter_t = decltype([](auto* ptr) { sdl_destroyfunc(ptr); }); +template +struct sdl_wrapper_t : std::unique_ptr { + explicit sdl_wrapper_t(SDLT* p) + : std::unique_ptr{p, deletef} {} -template -using sdl_wrapper_t = std::unique_ptr>; + operator SDLT*() { return std::unique_ptr::get(); } +}; using window_t = sdl_wrapper_t; using surface_t = sdl_wrapper_t; @@ -42,11 +44,11 @@ int main() { )}; renderer_t renderer{ - SDL_CreateRenderer(window.get(), -1, SDL_RENDERER_ACCELERATED) + SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED) }; - SDL_SetRenderDrawColor(renderer.get(), 0, 0, 0, 0); - SDL_RenderClear(renderer.get()); - SDL_SetRenderDrawColor(renderer.get(), 255, 0, 0, 255); + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); + SDL_RenderClear(renderer); + SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); if (!window) { std::println( @@ -55,7 +57,7 @@ int main() { return EXIT_FAILURE; } - auto surface = surface_t{SDL_GetWindowSurface(window.get())}; + auto surface = surface_t{SDL_GetWindowSurface(window)}; auto point = Point{.x = width / 2, .y = height / 2}; const Point directions[] = { @@ -71,7 +73,7 @@ int main() { bool quit = false; auto next_frame = std::chrono::steady_clock::now(); while (!quit) { - SDL_RenderDrawPoint(renderer.get(), point.x, point.y); + SDL_RenderDrawPoint(renderer, point.x, point.y); Point newpoint; do { newpoint = point + directions[dist(rne)]; @@ -86,7 +88,8 @@ int main() { while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { quit = true; } } - SDL_RenderPresent(renderer.get()); + SDL_RenderPresent(renderer); + // SDL_RenderClear(renderer); } } }