Просмотр исходного кода

(250712) 优化静态鬼屋模式帧率

detopoi 1 год назад
Родитель
Сommit
637e57d7d0

+ 3 - 0
client_local/const/game.py

@@ -54,6 +54,9 @@ WATER_DAMPING = 100
 PET = None
 PET = None
 ENVIRONMENT_EFFECT = []
 ENVIRONMENT_EFFECT = []
 
 
+IS_CUSTOM_LEVEL = False
+CURRENT_MAP_NAME = ""  # 对于自定义关卡生效
+
 DISPLAY_NPC_NAME_CARD = False
 DISPLAY_NPC_NAME_CARD = False
 DISPLAY_NPC_BLOOD = False
 DISPLAY_NPC_BLOOD = False
 DISPLAY_FRAME_RATE = False
 DISPLAY_FRAME_RATE = False

+ 2 - 0
client_local/control.py

@@ -241,6 +241,8 @@ class Control:
         hero_name = self.cfg_json["your_hero"]
         hero_name = self.cfg_json["your_hero"]
         character_color = self.cfg_json["your_character_color"]
         character_color = self.cfg_json["your_character_color"]
         G.TOTAL_LEVEL = G.CURRENT_LEVEL + 1
         G.TOTAL_LEVEL = G.CURRENT_LEVEL + 1
+        G.IS_CUSTOM_LEVEL = True
+        G.CURRENT_MAP_NAME = map_name
         self.set_level(self.your_name, map_name, hero_name, character_color)
         self.set_level(self.your_name, map_name, hero_name, character_color)
         G.HAS_RECORD = False
         G.HAS_RECORD = False
 
 

+ 32 - 12
client_local/level/level.py

@@ -66,17 +66,35 @@ def get_light_npc_coordinates():
     return coords
     return coords
 
 
 
 
+_last_light_states = None
+
 def get_player_mask(mask_surface, bgl):
 def get_player_mask(mask_surface, bgl):
-    bgl = min(max(bgl, 0), 255)
-    mask_surface.fill((bgl, bgl, bgl, 0))  # 初始为完全透明
-    for player in [current_level.me] + current_level.npcs + list(current_level.obstacle_instances.values()):
-        x, y = player.x_pos, player.y_pos
-        if player.light == 0:
-            continue
-        circleMask = circleMasks[player.light]
-        circle_radius = player.light * MASK_STEP
+    """
+    只在光源状态变化时才重绘遮罩;否则直接返回上次绘制结果。
+    """
+    global _last_light_states
+    # 收集当前所有光源状态 (x, y, light)
+    curr = []
+    for p in [current_level.me] + current_level.npcs + list(current_level.obstacle_instances.values()):
+        if p.light:
+            curr.append((p.x_pos, p.y_pos, p.light))
+    curr_key = tuple(curr)
+    # 如果没变化,直接复用
+    if curr_key == _last_light_states:
+        return mask_surface
+    # 状态变化:重绘
+    _last_light_states = curr_key
+    bgl = max(0, min(bgl, 255))
+    fill = mask_surface.fill
+    blit = mask_surface.blit
+    masks = circleMasks
+    fill((bgl, bgl, bgl, 0))
+    for x, y, light in curr:
         # 叠加亮度
         # 叠加亮度
-        mask_surface.blit(circleMask, (x-circle_radius, y-circle_radius-15), special_flags=pygame.BLEND_RGBA_ADD)    # 15是补偿值(大概是角色中心)
+        cm = masks[light]
+        r = light * MASK_STEP
+        blit(cm, (x - r, y - r - 15),
+             special_flags=pygame.BLEND_RGBA_ADD)
     return mask_surface
     return mask_surface
 
 
 
 
@@ -215,7 +233,7 @@ class Level:
         self.load_obstacle()  # 加载障碍
         self.load_obstacle()  # 加载障碍
         self.load_music()  # 加载音乐
         self.load_music()  # 加载音乐
 
 
-        self.mask_surface = pygame.Surface((self.map_x_pos, self.map_y_pos), pygame.SRCALPHA)
+        self.mask_surface = pygame.Surface((self.map_x_pos, self.map_y_pos), pygame.SRCALPHA).convert_alpha()
         self.haunt_Mode = False
         self.haunt_Mode = False
         self.bg_light = 0
         self.bg_light = 0
         self.underwater = False
         self.underwater = False
@@ -721,8 +739,10 @@ class Level:
             self.mask_surface = special_colour_mask(self.mask_surface, self.rgb_light)
             self.mask_surface = special_colour_mask(self.mask_surface, self.rgb_light)
             self.main_area.blit(self.mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
             self.main_area.blit(self.mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
 
 
-        if self.haunt_Mode:   # 鬼屋模式下显示玩家
-            self.mask_surface = get_player_mask(self.mask_surface, self.bg_light)
+        if self.haunt_Mode:
+            # 只在 get_player_mask 检测到状态变化时才重绘 mask_surface
+            get_player_mask(self.mask_surface, self.bg_light)
+            # 直接将已有 surface MULT 回主画面
             self.main_area.blit(self.mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
             self.main_area.blit(self.mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)
 
 
         # 显示顶层特效
         # 显示顶层特效

+ 3 - 3
client_local/skill/parametric2_skill.py

@@ -1063,7 +1063,7 @@ class CustomTrackingDirectionLaserFireBallEffect(Skill):
         if not self.knife_begin and self.knife_end:
         if not self.knife_begin and self.knife_end:
             e = self.effect_fire
             e = self.effect_fire
             if self.delta_len != 0:
             if self.delta_len != 0:
-                if self.current_time - self.skill_time_init <= 1000 + self.decay_init_time:
+                if self.current_time - self.skill_time_init <= 1000 + self.decay_init_time:  # 初始发射
                     delta_time = self.current_time - self.old_time  # 计算两次调用update的间隔: △t=t-t'
                     delta_time = self.current_time - self.old_time  # 计算两次调用update的间隔: △t=t-t'
                     final_dx = self.delta_x
                     final_dx = self.delta_x
                     final_dy = self.delta_y
                     final_dy = self.delta_y
@@ -1073,10 +1073,10 @@ class CustomTrackingDirectionLaserFireBallEffect(Skill):
                     new_y = e.y_pos + self.speed * delta_time * (final_dy/final_sqrt_norm)
                     new_y = e.y_pos + self.speed * delta_time * (final_dy/final_sqrt_norm)
                     e.set_xy_pos(new_x, new_y)
                     e.set_xy_pos(new_x, new_y)
                     self.old_time = self.current_time
                     self.old_time = self.current_time
-                elif 1000 + self.decay_init_time < self.current_time - self.skill_time_init <= 1000 + self.decay_init_time + self.stop_time:
+                elif 1000 + self.decay_init_time < self.current_time - self.skill_time_init <= 1000 + self.decay_init_time + self.stop_time:  # 停留
                     e.set_xy_pos(e.x_pos, e.y_pos)
                     e.set_xy_pos(e.x_pos, e.y_pos)
                     self.old_time = self.current_time
                     self.old_time = self.current_time
-                else:
+                else:  # 开始追踪
                     total_time = self.current_time - self.skill_time_init - self.decay_init_time - 1000 - self.stop_time
                     total_time = self.current_time - self.skill_time_init - self.decay_init_time - 1000 - self.stop_time
                     delta_time = self.current_time - self.old_time  # 计算两次调用update的间隔: △t=t-t'
                     delta_time = self.current_time - self.old_time  # 计算两次调用update的间隔: △t=t-t'
                     self.rho = max(0, 1-total_time/(self.decay_rate*self.end_time))
                     self.rho = max(0, 1-total_time/(self.decay_rate*self.end_time))

+ 6 - 2
client_local/sprite/hero.py

@@ -57,9 +57,13 @@ class Hero(Player):
         Indicator(self, self.skill_instances)
         Indicator(self, self.skill_instances)
 
 
         self.cfg_json = load_json("config.json")
         self.cfg_json = load_json("config.json")
-        self.map_file = load_json("game/map_set/" + self.cfg_json["map_set"] + ".json")
+        self.map_file = load_json(f"game/map_set/{self.cfg_json['map_set']}.json")
         # print("here:", G.CURRENT_LEVEL)
         # print("here:", G.CURRENT_LEVEL)
-        self.map_json = load_json("game/map/" + self.map_file["maps"][G.CURRENT_LEVEL] + ".json")
+        if not G.IS_CUSTOM_LEVEL:
+            self.map_json = load_json(f"game/map/{self.map_file['maps'][G.CURRENT_LEVEL]}.json")
+        else:
+            G.IS_CUSTOM_LEVEL = False
+            self.map_json = load_json(f"game/map/{G.CURRENT_MAP_NAME}.json")
         try:
         try:
             # 特殊亮度
             # 特殊亮度
             if "player_light" in self.map_json["basic"].keys():
             if "player_light" in self.map_json["basic"].keys():

+ 1 - 1
client_local/ui/game/game_top.py

@@ -7,7 +7,7 @@ class GameTop(UIInstance):
     def __init__(self):
     def __init__(self):
         super().__init__("game", "gameTop")
         super().__init__("game", "gameTop")
         self.font = pygame.font.Font("res/font/simsun.ttc", 16)
         self.font = pygame.font.Font("res/font/simsun.ttc", 16)
-        self.rend = self.font.render("v20250707", True, (0, 196, 255))
+        self.rend = self.font.render("v20250708", True, (0, 196, 255))
 
 
     def draw(self, screen: pygame.Surface):
     def draw(self, screen: pygame.Surface):
         super().draw(screen)
         super().draw(screen)