diff --git a/sim_scenes/func.py b/sim_scenes/func.py index d404eef7ece0d17476e1d411d01940144dbef583..2064cc844a29e95b3f841a80dba2754c744ff410 100644 --- a/sim_scenes/func.py +++ b/sim_scenes/func.py @@ -307,11 +307,15 @@ def create_3d_card(left=-.885, top=0.495, width=0.02, height=0.02): position=(left, top, 0) ) + panel.switch_flag = 0 + def switch_color(): if panel.color == color.black: panel.color = color.white + panel.switch_flag = 1 else: panel.color = color.black + panel.switch_flag = 0 panel.switch_color = switch_color diff --git a/sim_scenes/science/speed_of_light_3d.py b/sim_scenes/science/speed_of_light_3d.py index 1c3743c713d9910bcb24c09e612dc28fc9efcaab..76f29cdbab62ac12d057cd6a999f6aae44ca3e72 100644 --- a/sim_scenes/science/speed_of_light_3d.py +++ b/sim_scenes/science/speed_of_light_3d.py @@ -98,12 +98,18 @@ def on_timer_changed(time_data: TimeData): distance = round(init.light_ship.position[2] / AU, 4) text = init.arrived_info.replace("${distance}", "%.4f AU" % distance) init.text_panel.text = text.replace("${speed}", str(round(velocity / LIGHT_SPEED, 1)) + "倍光速") - init._3d_card.switch_color() - light_ship.switch_position() + # if time_data.total_seconds > 20: # wait_for(0.03) +def on_before_evolving(evolve_args): + init._3d_card.switch_color() + light_ship.switch_position() + if init._3d_card.switch_flag == 1: + evolve_args["evolve_dt"] = 0.0 + + # 订阅重新开始事件 # 按键盘的 “O” 重置键会触发 on_reset UrsinaEvent.on_reset_subscription(on_reset) @@ -113,6 +119,8 @@ UrsinaEvent.on_ready_subscription(on_ready) # 运行中,每时每刻都会触发 on_timer_changed UrsinaEvent.on_timer_changed_subscription(on_timer_changed) +UrsinaEvent.on_before_evolving_subscription(on_before_evolving) + def body_arrived(body): # # 到达每个行星都会触发,对光速飞船进行加速,超光速前进(使用未来曲率引擎技术) diff --git a/simulators/ursina/ursina_event.py b/simulators/ursina/ursina_event.py index 9532cc6b3284904c7ec6c20759088036371ef2ba..a0bc6dba5d58e581ad7ee0f9fcc1352f7cbf2542 100644 --- a/simulators/ursina/ursina_event.py +++ b/simulators/ursina/ursina_event.py @@ -36,6 +36,8 @@ class UrsinaEvent: UrsinaEvent.on_body_size_changed_callback = [] # 逐步演变触发的订阅事件 UrsinaEvent.on_evolving_callback = [] + # 逐步演变触发前的订阅事件 + UrsinaEvent.on_before_evolving_callback = [] # 计时器触发的订阅事件 UrsinaEvent.on_timer_changed_callback = [] @@ -78,6 +80,19 @@ class UrsinaEvent: for f in UrsinaEvent.on_evolving_callback: f(evolve_dt) + @staticmethod + def on_before_evolving_subscription(fun): + UrsinaEvent.on_before_evolving_callback.append(fun) + + @staticmethod + def on_before_evolving_unsubscription(fun): + UrsinaEvent.on_before_evolving_callback.remove(fun) + + @staticmethod + def on_before_evolving(evolve_args): + for f in UrsinaEvent.on_before_evolving_callback: + f(evolve_args) + @staticmethod def on_application_run_callback_subscription(fun): UrsinaEvent.on_application_run_callback.append(fun) diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index 1223d954f2f36859a60bfd98b7c4036c2ed0a612..e196871fc93357e5fda67446df1dd976ecc49067 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -224,7 +224,10 @@ class UrsinaSimulator(Simulator): UrsinaEvent.on_evolving(evolve_dt) # interval_fator 能让更新天体运行状态(位置、速度)更精确 evolve_dt = evolve_dt * self.interval_fator - super().evolve(evolve_dt) + evolve_args = {"evolve_dt": evolve_dt} + UrsinaEvent.on_before_evolving(evolve_args) + # if evolve_args["evolve_dt"] > 0: + super().evolve(evolve_args["evolve_dt"]) if self.show_timer or self.timer_enabled: timer = BodyTimer()