#include "TZR_render.h" #include "TZR_globals.h" #include "TZR_resource.h" #include "sdl_error.h" #include #include static int pixel_draw_end(void) { if (___tzr_config.interlace) { static int odd = 0; odd ^= 1; for (int i = odd; i < ___tzr_config.height; i += 2) { const SDL_Rect rect = { 0, i, ___tzr_config.width, 1 }; if (SDL_RenderCopy(___tzr_renderer, ___tzr_target_pre, &rect, &rect) < 0) return sdl_error(-1); } } if (SDL_SetRenderTarget(___tzr_renderer, NULL) < 0) return sdl_error(-1); if (SDL_SetRenderDrawColor(___tzr_renderer, 0, 0, 0, 255) < 0) return sdl_error(-1); if (SDL_RenderClear(___tzr_renderer) < 0) return sdl_error(-1); int win_w, win_h; SDL_GetWindowSize(___tzr_window, &win_w, &win_h); win_w = win_w ? win_w : 1; win_h = win_h ? win_h : 1; const int width = ___tzr_config.width * ___tzr_config.ratio; const float ratio_w = win_w / (float)(width); const float ratio_h = win_h / (float)___tzr_config.height; ___tzr_scale = (ratio_w < ratio_h) ? ratio_w : ratio_h; if (___tzr_scale > 1.0f && ___tzr_config.pixel_perfect) ___tzr_scale = (int)___tzr_scale; ___tzr_off_x = (win_w - width * ___tzr_scale) / 2; ___tzr_off_y = (win_h - ___tzr_config.height * ___tzr_scale) / 2; const SDL_Rect dest = { ___tzr_off_x, ___tzr_off_y, width * ___tzr_scale, ___tzr_config.height * ___tzr_scale }; if (SDL_RenderCopy(___tzr_renderer, ___tzr_target, NULL, &dest) < 0) return sdl_error(-1); return 0; } int TZR_DrawEnd(void) { if (!___tzr_config.hd_render && pixel_draw_end()) return -1; if (___tzr_config.target_fps > 0) { ___tzr_next_time += ___tzr_min_dt; if (___tzr_config.target_fps == 60 && ___tzr_tick % 3 < 2) ___tzr_next_time += 1; const unsigned long cur_time = SDL_GetTicks64(); if (___tzr_next_time <= cur_time) ___tzr_next_time = cur_time; else SDL_Delay(___tzr_next_time - cur_time); } SDL_RenderPresent(___tzr_renderer); ___tzr_tick += 1; return 0; }