Skip to content

Commit d3092a1

Browse files
committed
Performance Update.
Changelog: - Remove refresh delay. - Add output buffers. - Add FPS Counter. - Optimize I/O performance.
1 parent 883525c commit d3092a1

14 files changed

+193
-32
lines changed

β€Ž.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ž.idea/Mouse-Debugger.iml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ž.idea/inspectionProfiles/Project_Default.xml

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ž.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ž.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ž.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Ž.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€ŽDebugger.py

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
import win32api
2-
import win32con
32
import time
43
import numpy as np
5-
from colorama import Fore, Style, init
4+
from colorama import Fore, Style
65
import win32gui
7-
import os
6+
import printer
87

98
def get_mouse_position():
109
return win32api.GetCursorPos()
1110

11+
1212
def get_mouse_speed(prev_pos, prev_time, cur_pos, cur_time):
1313
if prev_pos is None or prev_time is None:
1414
return 0
1515
distance = np.linalg.norm(np.array(cur_pos) - np.array(prev_pos))
1616
time_diff = cur_time - prev_time
1717
return distance / time_diff
1818

19+
1920
def get_pixel_color(x, y):
2021
hdc = win32gui.GetDC(0)
2122
color = win32gui.GetPixel(hdc, x, y)
2223
win32gui.ReleaseDC(0, hdc)
2324
return color & 0xFF, (color >> 8) & 0xFF, (color >> 16) & 0xFF
2425

26+
2527
def color_to_ansi(rgb):
2628
if rgb[0] > rgb[1] and rgb[0] > rgb[2]:
2729
return Fore.RED
@@ -32,49 +34,40 @@ def color_to_ansi(rgb):
3234
else:
3335
return Fore.WHITE
3436

35-
def print_debug_info(prev_mouse_pos, prev_time, prev_speed, prev_window_title):
37+
38+
def print_debug_info(prev_mouse_pos, prev_time, prev_speed, prev_window_title, printTool: printer.printer):
3639
cur_mouse_pos = get_mouse_position()
3740
cur_time = time.time()
3841

3942
mouse_speed = get_mouse_speed(prev_mouse_pos, prev_time, cur_mouse_pos, cur_time)
4043
mouse_color = get_pixel_color(cur_mouse_pos[0], cur_mouse_pos[1])
4144
window_title = win32gui.GetWindowText(win32gui.GetForegroundWindow())
4245

43-
os.system('cls')
44-
print(Style.BRIGHT + Fore.CYAN + f'WA Modern Console Debug Information' + Style.RESET_ALL)
45-
print(f'Mouse Position:')
46-
print(f' X: {Fore.YELLOW}------> {cur_mouse_pos[0]}{Style.RESET_ALL}')
47-
print(f' Y: {Fore.YELLOW}------> {cur_mouse_pos[1]}{Style.RESET_ALL}')
48-
print(f'Mouse Color: {color_to_ansi(mouse_color)}RGB({mouse_color[0]}, {mouse_color[1]}, {mouse_color[2]}){Style.RESET_ALL}')
49-
print(f'Mouse Speed: {mouse_speed:.2f} pixels per second')
46+
printTool.join(Style.BRIGHT + Fore.CYAN + f'WA Modern Console Debug Information' + Style.RESET_ALL)
47+
printTool.join(f'Mouse Position:')
48+
printTool.join(f' X: {Fore.YELLOW}------> {cur_mouse_pos[0]}{Style.RESET_ALL} ')
49+
printTool.join(f' Y: {Fore.YELLOW}------> {cur_mouse_pos[1]}{Style.RESET_ALL} ')
50+
printTool.join(f'Mouse Color: {color_to_ansi(mouse_color)}RGB({mouse_color[0]}, {mouse_color[1]}, {mouse_color[2]}){Style.RESET_ALL} ')
51+
printTool.join(f'Mouse Speed: {mouse_speed:.2f} pixels per second ')
5052

5153
if mouse_speed == 0 and prev_speed == 0:
52-
print(f'Is Mouse Stopped: {Fore.RED}πŸ›‘ True{Style.RESET_ALL}')
54+
printTool.join(f'Is Mouse Stopped: {Fore.RED}πŸ›‘ True{Style.RESET_ALL} ')
5355
else:
54-
print(f'Is Mouse Stopped: {Fore.GREEN}βœ… False{Style.RESET_ALL}')
56+
printTool.join(f'Is Mouse Stopped: {Fore.GREEN}βœ… False{Style.RESET_ALL}')
5557

56-
print(f'Mouse Sensitivity: {Fore.MAGENTA}Medium{Style.RESET_ALL}')
58+
printTool.join(f'Mouse Sensitivity: {Fore.MAGENTA}Medium{Style.RESET_ALL}')
5759

58-
print('\nColor Intensity:')
59-
print(f' Red Intensity: {Fore.RED}πŸ”΄ {mouse_color[0]}{Style.RESET_ALL}')
60-
print(f' Green Intensity: {Fore.GREEN}🟒 {mouse_color[1]}{Style.RESET_ALL}')
61-
print(f' Blue Intensity: {Fore.BLUE}πŸ”΅ {mouse_color[2]}{Style.RESET_ALL}')
60+
printTool.join('\nColor Intensity:')
61+
printTool.join(f' Red Intensity: {Fore.RED}πŸ”΄ {mouse_color[0]}{Style.RESET_ALL} ')
62+
printTool.join(f' Green Intensity: {Fore.GREEN}🟒 {mouse_color[1]}{Style.RESET_ALL} ')
63+
printTool.join(f' Blue Intensity: {Fore.BLUE}πŸ”΅ {mouse_color[2]}{Style.RESET_ALL} ')
6264

63-
print('\nWindow Information:')
64-
print(f' Window Title: {window_title}')
65+
printTool.join('\nWindow Information:')
66+
printTool.join(f' Window Title: {window_title} ')
6567

6668
if window_title != prev_window_title:
67-
print(f' {Fore.YELLOW}πŸ”„ Window Changed!{Style.RESET_ALL}')
69+
printTool.join(f' {Fore.YELLOW}πŸ”„ Window Changed!{Style.RESET_ALL}')
70+
else:
71+
printTool.join(f' {Fore.YELLOW} {Style.RESET_ALL}')
6872

6973
return cur_mouse_pos, cur_time, mouse_speed, window_title
70-
71-
if __name__ == "__main__":
72-
init()
73-
prev_mouse_pos = None
74-
prev_time = None
75-
prev_speed = 0
76-
prev_window_title = ""
77-
78-
while True:
79-
prev_mouse_pos, prev_time, prev_speed, prev_window_title = print_debug_info(prev_mouse_pos, prev_time, prev_speed, prev_window_title)
80-
time.sleep(0.5)
5.6 KB
Binary file not shown.
2.31 KB
Binary file not shown.

0 commit comments

Comments
Β (0)