Optimized SDL_RenderDrawCircle.

Change mouse warping strategy in hidden test cheat.
This commit is contained in:
Muzychenko Andrey 2022-05-27 13:54:36 +03:00
parent 4183e7f0bf
commit cfe2691892
3 changed files with 42 additions and 18 deletions

View File

@ -21,6 +21,8 @@ gdrv_bitmap8* DebugOverlay::dbScreen = nullptr;
static int SDL_RenderDrawCircle(SDL_Renderer* renderer, int x, int y, int radius)
{
SDL_Point points[256];
int pointCount = 0;
int offsetx, offsety, d;
int status;
@ -29,21 +31,28 @@ static int SDL_RenderDrawCircle(SDL_Renderer* renderer, int x, int y, int radius
d = radius - 1;
status = 0;
while (offsety >= offsetx) {
status += SDL_RenderDrawPoint(renderer, x + offsetx, y + offsety);
status += SDL_RenderDrawPoint(renderer, x + offsety, y + offsetx);
status += SDL_RenderDrawPoint(renderer, x - offsetx, y + offsety);
status += SDL_RenderDrawPoint(renderer, x - offsety, y + offsetx);
status += SDL_RenderDrawPoint(renderer, x + offsetx, y - offsety);
status += SDL_RenderDrawPoint(renderer, x + offsety, y - offsetx);
status += SDL_RenderDrawPoint(renderer, x - offsetx, y - offsety);
status += SDL_RenderDrawPoint(renderer, x - offsety, y - offsetx);
while (offsety >= offsetx)
{
if (pointCount + 8 > 256)
{
status = SDL_RenderDrawPoints(renderer, points, pointCount);
pointCount = 0;
if (status < 0) {
status = -1;
break;
if (status < 0) {
status = -1;
break;
}
}
points[pointCount++] = { x + offsetx, y + offsety };
points[pointCount++] = { x + offsety, y + offsetx };
points[pointCount++] = { x - offsetx, y + offsety };
points[pointCount++] = { x - offsety, y + offsetx };
points[pointCount++] = { x + offsetx, y - offsety };
points[pointCount++] = { x + offsety, y - offsetx };
points[pointCount++] = { x - offsetx, y - offsety };
points[pointCount++] = { x - offsety, y - offsetx };
if (d >= 2 * offsetx) {
d -= 2 * offsetx + 1;
offsetx += 1;
@ -59,6 +68,9 @@ static int SDL_RenderDrawCircle(SDL_Renderer* renderer, int x, int y, int radius
}
}
if (pointCount > 0)
status = SDL_RenderDrawPoints(renderer, points, pointCount);
return status;
}

View File

@ -227,7 +227,8 @@ std::vector<uint8_t>* midi::MdsToMidi(std::string file)
fseek(fileHandle, 0, SEEK_END);
auto fileSize = static_cast<uint32_t>(ftell(fileHandle));
auto fileBuf = reinterpret_cast<riff_header*>(new uint8_t [fileSize]);
auto buffer = new uint8_t[fileSize];
auto fileBuf = reinterpret_cast<riff_header*>(buffer);
fseek(fileHandle, 0, SEEK_SET);
fread(fileBuf, 1, fileSize, fileHandle);
fclose(fileHandle);
@ -371,7 +372,7 @@ std::vector<uint8_t>* midi::MdsToMidi(std::string file)
}
while (false);
delete[] fileBuf;
delete[] buffer;
if (returnCode && midiOut)
{
delete midiOut;

View File

@ -211,11 +211,22 @@ int winmain::WinMain(LPCSTR lpCmdLine)
float dy = static_cast<float>(y - last_mouse_y) / static_cast<float>(h);
pb::ballset(dx, dy);
SDL_WarpMouseInWindow(window, last_mouse_x, last_mouse_y);
// Original creates continuous mouse movement with mouse capture.
// Alternative solution: mouse warp at window edges.
int xMod = 0, yMod = 0;
if (x == 0 || x >= w - 1)
xMod = w - 2;
if (y == 0 || y >= h - 1)
yMod = h - 2;
if (xMod != 0 || yMod != 0)
{
// Mouse warp does not work over remote desktop or in some VMs
x = abs(x - xMod); y = abs(y - yMod);
SDL_WarpMouseInWindow(window, x, y);
}
// Mouse warp does not work over remote desktop or in some VMs
//last_mouse_x = x;
//last_mouse_y = y;
last_mouse_x = x;
last_mouse_y = y;
}
if (!single_step && !no_time_loss)
{