mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
cache note arc points, untruncate time
This commit is contained in:
@@ -3,17 +3,8 @@ from typing import Any, Optional
|
|||||||
|
|
||||||
from libs.global_data import global_data
|
from libs.global_data import global_data
|
||||||
|
|
||||||
|
def get_current_ms() -> float:
|
||||||
def rounded(num: float) -> int:
|
return time.time() * 1000
|
||||||
sign = 1 if (num >= 0) else -1
|
|
||||||
num = abs(num)
|
|
||||||
result = int(num)
|
|
||||||
if (num - result >= 0.5):
|
|
||||||
result += 1
|
|
||||||
return sign * result
|
|
||||||
|
|
||||||
def get_current_ms() -> int:
|
|
||||||
return rounded(time.time() * 1000)
|
|
||||||
|
|
||||||
|
|
||||||
class BaseAnimation():
|
class BaseAnimation():
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ def rounded(num: float) -> int:
|
|||||||
result += 1
|
result += 1
|
||||||
return sign * result
|
return sign * result
|
||||||
|
|
||||||
def get_current_ms() -> int:
|
def get_current_ms() -> float:
|
||||||
"""Get the current time in milliseconds"""
|
"""Get the current time in milliseconds"""
|
||||||
return rounded(time.time() * 1000)
|
return time.time() * 1000
|
||||||
|
|
||||||
def strip_comments(code: str) -> str:
|
def strip_comments(code: str) -> str:
|
||||||
"""Strip comments from a string of code"""
|
"""Strip comments from a string of code"""
|
||||||
|
|||||||
@@ -1627,6 +1627,8 @@ class GaugeHitEffect:
|
|||||||
|
|
||||||
class NoteArc:
|
class NoteArc:
|
||||||
"""Note arcing from the player to the gauge"""
|
"""Note arcing from the player to the gauge"""
|
||||||
|
_arc_points_cache = {}
|
||||||
|
|
||||||
def __init__(self, note_type: int, current_ms: float, player_num: PlayerNum, big: bool, is_balloon: bool, start_x: float = 0, start_y: float = 0):
|
def __init__(self, note_type: int, current_ms: float, player_num: PlayerNum, big: bool, is_balloon: bool, start_x: float = 0, start_y: float = 0):
|
||||||
self.note_type = note_type
|
self.note_type = note_type
|
||||||
self.is_big = big
|
self.is_big = big
|
||||||
@@ -1660,13 +1662,20 @@ class NoteArc:
|
|||||||
self.x_i = self.start_x
|
self.x_i = self.start_x
|
||||||
self.y_i = self.start_y
|
self.y_i = self.start_y
|
||||||
self.is_finished = False
|
self.is_finished = False
|
||||||
self.arc_points_cache = []
|
|
||||||
for i in range(self.arc_points + 1):
|
cache_key = (self.start_x, self.start_y, self.end_x, self.end_y, self.control_x, self.control_y, self.arc_points)
|
||||||
t = i / self.arc_points
|
|
||||||
t_inv = 1.0 - t
|
if cache_key not in NoteArc._arc_points_cache:
|
||||||
x = int(t_inv * t_inv * self.start_x + 2 * t_inv * t * self.control_x + t * t * self.end_x)
|
arc_points_list = []
|
||||||
y = int(t_inv * t_inv * self.start_y + 2 * t_inv * t * self.control_y + t * t * self.end_y)
|
for i in range(self.arc_points + 1):
|
||||||
self.arc_points_cache.append((x, y))
|
t = i / self.arc_points
|
||||||
|
t_inv = 1.0 - t
|
||||||
|
x = int(t_inv * t_inv * self.start_x + 2 * t_inv * t * self.control_x + t * t * self.end_x)
|
||||||
|
y = int(t_inv * t_inv * self.start_y + 2 * t_inv * t * self.control_y + t * t * self.end_y)
|
||||||
|
arc_points_list.append((x, y))
|
||||||
|
NoteArc._arc_points_cache[cache_key] = arc_points_list
|
||||||
|
|
||||||
|
self.arc_points_cache = NoteArc._arc_points_cache[cache_key]
|
||||||
|
|
||||||
self.explosion_x, self.explosion_y = self.arc_points_cache[0]
|
self.explosion_x, self.explosion_y = self.arc_points_cache[0]
|
||||||
self.explosion_anim = tex.get_animation(22)
|
self.explosion_anim = tex.get_animation(22)
|
||||||
|
|||||||
Reference in New Issue
Block a user