mirror of
https://gitea.tendokyu.moe/TeamTofuShop/segatools.git
synced 2026-09-22 22:37:59 +03:00
## Overview This PR addresses the severe memory leak and performance issues observed in `mai2`, while also introducing improvements to the touch emulation logic. ## Root Cause Analysis As discussed previously, the root cause of the `mai2` memory leak is not a global `segatools` buffer bug. Instead, the game aggressively spams overlapped empty reads specifically on the `LED 15070` UART. On real hardware, the serial driver naturally throttles this. Under emulation, without a throttle, it hits approximately **260kHz of empty async reads**, which causes the memory usage to explode. ## The Fix Instead of introducing complex locking mechanisms and condition variables globally in `uart.c`, this PR applies a targeted fix: * Added a local `Sleep(1)` directly in `common/board/led15070.c` to rate-limit empty reads on the LED path. * Because this is isolated to LED communications, it completely resolves the memory leak without introducing any lag, livelocks, or overhead to other critical inputs. ## Additional Changes in this PR Alongside the memory leak fix, this PR includes a few touch-related improvements (as touch emulation was reviewed during the debugging process): * Enhanced touch input handling and improved auto-scan state management. * Implemented IOCTL handling for touch input to properly manage communication status. ## Testing * **mai2:** Tested successfully on multiple machines. The memory leak is completely gone, and the game runs smoothly. * **chusan:** Tested to ensure no regressions. Sliders and inputs work flawlessly without the lag. Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/101 Co-authored-by: Gl0w1amp <gl0w1amp@noreply.gitea.tendokyu.moe> Co-committed-by: Gl0w1amp <gl0w1amp@noreply.gitea.tendokyu.moe>
32 lines
587 B
C
32 lines
587 B
C
#pragma once
|
|
|
|
#include <windows.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include "hooklib/uart.h"
|
|
|
|
struct touch_config
|
|
{
|
|
bool enable_1p;
|
|
bool enable_2p;
|
|
};
|
|
|
|
enum
|
|
{
|
|
commandRSET = 0x45, // E
|
|
commandHALT = 0x4C, // L
|
|
commandSTAT = 0x41, // A
|
|
commandRatio = 0x72, // r
|
|
commandSens = 0x6B, // k
|
|
req_start = 0x7b, // {
|
|
req_end = 0x7d, // }
|
|
res_start = 0x28, // (
|
|
res_end = 0x29, // )
|
|
};
|
|
|
|
extern const char *sensor_map[34];
|
|
const char *sensor_to_str(uint8_t sensor);
|
|
|
|
HRESULT touch_hook_init(const struct touch_config *cfg);
|