- 好友
- 0
- 在线时间
- 114 小时
- 最后登录
- 2025-8-17
平民

- UID
- 650235
- 第纳尔
- 228
- 精华
- 0
- 互助
- 0
- 荣誉
- 0
- 贡献
- 0
- 魅力
- 2
- 注册时间
- 2012-2-7
 鲜花( 2)  鸡蛋( 0)
|
本帖最后由 aliang227 于 2025-9-15 02:37 编辑
版主提示:此修改仅适用于16th北半球,其他MOD并不通用,请谨慎修改
【魔改系列】八个帖子收尾,后会有期
【魔改系列】内置的npc跑路?让更多npc加入队伍
https://bbs.mountblade.com.cn/thread-2112291-1-1.html
【魔改系列】领主带兵能力提升
https://bbs.mountblade.com.cn/thread-2111976-1-1.html
【魔改系列】君主自动花钱买关系
https://bbs.mountblade.com.cn/thread-2111973-1-1.html
【魔改系列】每个城堡刷出巡逻队
https://bbs.mountblade.com.cn/thread-2111925-1-1.html
【魔改系列】分封制变为封建制的税收制度补丁
https://bbs.mountblade.com.cn/thread-2102924-1-1.html
【魔改系列】战斗结束重新计算领主声望
https://bbs.mountblade.com.cn/thread-2102923-1-1.html
【魔改系列】战场人数调大,千人团战时切换武器卡顿优化
https://bbs.mountblade.com.cn/thread-2112284-1-1.html
【魔改系列】战场人数调大,千人团战时匹配敌人的卡顿优化
https://bbs.mountblade.com.cn/thread-2112275-1-1.html
受士气计算引起的卡顿优化启发
https://bbs.mountblade.com.cn/thread-2086832-1-1.html
我觉得士气的对我的游戏性影响不大,索性直接注释了士气的调用
发现我还是只能开500人团,千人团还是卡,而且还是1s一卡,还是只能开到500
我的显存负载都不高,还是在cpu上
之前一直听说战团单核所以性能差,没往这里想,突然思路打开了,然后翻了下代码,发现还有一个地方嵌套遍历的厉害 , 里面存在一个 当前单位的大嵌套,这小块的思路也很简单
遍历战场所有士兵,寻找距离最近的敌人,保存到slot里
我直接注释掉这里,瞬间就不卡了,但是这个东西注释了,也不太好,单纯的遍历1k人+1k匹马,是很快的,重点还是减少嵌套
为了不影响太大,主要优化思路就是
1、获取上一轮记录的最近敌人,获取上一轮记录的和最近这个敌人的距离
2、如果敌人存活,获取该单位和这个敌人的距离
3、如果本轮和敌人距离 小于 (上一轮距离+1000),那么就不进行计算,否则重新查找敌人
这么一来,
1、刚进战场的时候,给每个人匹配一遍,后面直接开打就行,,
2、中途敌人挂了,也就几个单位需要重算,这个量就小很多了,
3、后期,几十或者几百个单位同时锁定一个敌人,触发的重算,因为战场人数整体变少了,遍历就很快了,也没啥影响
修改方式,基于16th北半球,但是应该是通用的,有源码的同学可以直接照着改
源码:
formations_scripts.py ,找到 store_battlegroup_data 方法找到 (try_for_agents, ":enemy_agent"),
将 (agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent, -1),
(try_for_agents, ":enemy_agent"),
(agent_is_alive, ":enemy_agent"),
(agent_is_human, ":enemy_agent"),
(agent_get_team, ":enemy_team_no", ":enemy_agent"),
(teams_are_enemies, ":enemy_team_no", ":bgteam"),
(agent_slot_eq, ":enemy_agent", slot_agent_is_running_away, 0),
(agent_get_position, pos0, ":enemy_agent"),
(get_distance_between_positions, ":new_distance", pos0, pos1),
(try_begin),
(agent_get_slot, ":closest_enemy", ":cur_agent", slot_agent_nearest_enemy_agent),
(eq, ":closest_enemy", -1),
(agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent, ":enemy_agent"),
(else_try),
(agent_get_position, pos2, ":closest_enemy"),
(get_distance_between_positions, ":old_distance", pos2, pos1),
(lt, ":new_distance", ":old_distance"),
(agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent, ":enemy_agent"),
(try_end),
(try_end),
替换为
(try_begin),
(try_begin),
(agent_get_slot, ":closest_enemy", ":cur_agent", slot_agent_nearest_enemy_agent),
(gt, ":closest_enemy", 0),
(agent_is_alive, ":closest_enemy"),
(agent_get_position, pos0, ":closest_enemy"),
(get_distance_between_positions, ":new_distance", pos0, pos1),
(agent_get_slot, ":last_distance",":cur_agent", slot_agent_nearest_enemy_agent_old),
(val_add,":last_distance",1000),
(lt, ":new_distance", ":last_distance"),
(agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent_old, ":new_distance"),
(else_try),
(agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent, -1),
(try_for_agents, ":enemy_agent"),
(agent_is_alive, ":enemy_agent"),
(agent_is_human, ":enemy_agent"),
(agent_get_team, ":enemy_team_no", ":enemy_agent"),
(teams_are_enemies, ":enemy_team_no", ":bgteam"),
(agent_slot_eq, ":enemy_agent", slot_agent_is_running_away, 0),
(agent_get_position, pos0, ":enemy_agent"),
(get_distance_between_positions, ":new_distance", pos0, pos1),
(try_begin),
(agent_get_slot, ":closest_enemy", ":cur_agent", slot_agent_nearest_enemy_agent),
(eq, ":closest_enemy", -1),
(agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent, ":enemy_agent"),
(agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent_old, ":new_distance"),
(else_try),
(agent_get_position, pos2, ":closest_enemy"),
(get_distance_between_positions, ":old_distance", pos2, pos1),
(lt, ":new_distance", ":old_distance"),
(agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent, ":enemy_agent"),
(agent_set_slot, ":cur_agent", slot_agent_nearest_enemy_agent_old, ":new_distance"),
(try_end),
(try_end),
(try_end),
(try_end),
slot_agent_nearest_enemy_agent_old 在formations_constants.py定义,或者 直接写成 30 (和formations_constants.py中定义不重复即可)
txt版本scripts.txt
store_battlegroup_data -1 那一行改成
store_battlegroup_data -1
371 2133 2 1224979098644774912 0 2133 2 1224979098644774913 0 2133 2 1224979098644774914 0 2133 2 1224979098644774915 0 2133 2 1224979098644774916 0 2133 2 1224979098644774917 0 2133 2 1224979098644774918 0 2133 2 1224979098644774919 0 2133 2 1224979098644774920 0 2133 2 1224979098644774921 0 2133 2 1224979098644774922 0 2133 2 1224979098644774923 0 2133 2 1224979098644774924 0 2133 2 1224979098644774925 0 2133 2 1224979098644774926 0 2133 2 1224979098644774927 0 6 3 1224979098644774928 0 4 6 3 1224979098644774929 5 176 509 3 1224979098644774928 1224979098644774929 0 3 0 6 3 1224979098644774930 0 9 2120 3 1224979098644774929 185 1224979098644774930 549 3 1224979098644774928 1224979098644774929 0 2120 3 1224979098644774929 221 1224979098644774930 509 3 1224979098644774928 1224979098644774929 -1 3 0 3 0 12 1 1224979098644774931 1702 1 1224979098644774931 1704 1 1224979098644774931 1773 2 1224979098644774932 1224979098644774931 4 0 565 3 1224979098644774931 29 0 2147484193 3 1224979098644774931 29 1224979098644774932 525 3 1224979098644774932 1224979098644774931 29 1783 2 1224979098644774931 1224979098644774932 3 0 545 3 1224979098644774931 15 0 1770 2 1224979098644774933 1224979098644774931 4 0 1792 2 1224979098644774934 1224979098644774933 31 2 1224979098644774934 1224979098644774931 2133 2 1224979098644774932 -1 3 0 1718 2 1224979098644774935 1224979098644774931 2171 2 1224979098644774936 1224979098644774935 1727 3 1224979098644774937 1224979098644774931 0 2133 2 1224979098644774938 0 2133 2 1224979098644774939 0 2133 2 1224979098644774940 0 1726 3 1224979098644774941 1224979098644774931 0 4 0 33 3 1224979098644774941 288230376151712887 288230376151713137 527 3 1224979098644774939 1224979098644774941 42 527 3 72057594037927936 1224979098644774941 44 567 3 1224979098644774941 45 72057594037927936 2133 2 1224979098644774940 1224979098644774939 3 0 1710 2 1 1224979098644774931 726 2 1224979098644774942 1 727 2 1224979098644774943 1 4 0 31 2 1224979098644774932 -1 4 0 31 2 1224979098644774933 0 2133 2 1224979098644774912 1 2133 2 1224979098644774913 1224979098644774942 2133 2 1224979098644774914 1224979098644774943 2133 2 1224979098644774915 1224979098644774936 5 0 31 2 1224979098644774933 1 2133 2 1224979098644774916 1 2133 2 1224979098644774917 1224979098644774942 2133 2 1224979098644774918 1224979098644774943 2133 2 1224979098644774919 1224979098644774936 5 0 31 2 1224979098644774933 2 2133 2 1224979098644774920 1 2133 2 1224979098644774921 1224979098644774942 2133 2 1224979098644774922 1224979098644774943 2133 2 1224979098644774923 1224979098644774936 5 0 31 2 1224979098644774933 3 2133 2 1224979098644774924 1 2133 2 1224979098644774925 1224979098644774942 2133 2 1224979098644774926 1224979098644774943 2133 2 1224979098644774927 1224979098644774936 3 0 5 0 4 0 2120 3 1224979098644774929 104 1224979098644774932 549 3 1224979098644774933 1224979098644774929 0 1763 2 72057594037927936 1224979098644774931 32 2 72057594037927936 0 509 3 1224979098644774933 1224979098644774929 1 3 0 2120 3 1224979098644774929 14 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1 509 3 1224979098644774933 1224979098644774929 1224979098644774944 4 0 2120 3 1224979098644774929 185 1224979098644774932 549 3 1224979098644774933 1224979098644774929 0 2120 3 1224979098644774929 221 1224979098644774932 2147484217 3 1224979098644774933 1224979098644774929 0 509 3 1224979098644774933 1224979098644774929 1224979098644774931 3 0 4 0 32 2 1224979098644774937 0 2120 3 1224979098644774929 23 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1 509 3 1224979098644774933 1224979098644774929 1224979098644774944 5 0 2120 3 1224979098644774929 41 1224979098644774932 509 3 1224979098644774933 1224979098644774929 1 3 0 4 0 31 2 1224979098644774938 10 2120 3 1224979098644774929 32 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1 509 3 1224979098644774933 1224979098644774929 1224979098644774944 3 0 2120 3 1224979098644774929 50 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1224979098644774936 509 3 1224979098644774933 1224979098644774929 1224979098644774944 2120 3 1224979098644774929 68 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1224979098644774939 509 3 1224979098644774933 1224979098644774929 1224979098644774944 2120 3 1224979098644774929 77 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1224979098644774940 509 3 1224979098644774933 1224979098644774929 1224979098644774944 4 0 565 3 1224979098644774931 26 1 2120 3 1224979098644774929 86 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1224979098644774939 509 3 1224979098644774933 1224979098644774929 1224979098644774944 2120 3 1224979098644774929 95 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1 509 3 1224979098644774933 1224979098644774929 1224979098644774944 3 0 2120 3 1224979098644774929 158 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1224979098644774942 509 3 1224979098644774933 1224979098644774929 1224979098644774944 2120 3 1224979098644774929 167 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 2105 2 1224979098644774944 1224979098644774943 509 3 1224979098644774933 1224979098644774929 1224979098644774944 3 0 1772 2 1224979098644774945 1224979098644774931 4 0 31 2 1224979098644774945 1 529 3 1224979098644774944 1224979098644774933 8 2105 2 1224979098644774944 1 509 3 1224979098644774933 8 1224979098644774944 5 0 31 2 1224979098644774945 2 529 3 1224979098644774944 1224979098644774933 9 2105 2 1224979098644774944 1 509 3 1224979098644774933 9 1224979098644774944 5 0 31 2 1224979098644774945 0 529 3 1224979098644774944 1224979098644774933 7 2105 2 1224979098644774944 1 509 3 1224979098644774933 7 1224979098644774944 6 3 1224979098644774946 0 4 1788 2 1224979098644774946 1224979098644774933 529 3 72057594037927936 1224979098644774946 2 729 2 0 72057594037927936 529 3 72057594037927936 1224979098644774946 3 730 2 0 72057594037927936 791 1 0 710 3 1224979098644774947 0 1 529 3 1224979098644774948 1224979098644774946 11 4 0 1073741855 2 1224979098644774948 0 2147483678 2 1224979098644774947 1224979098644774948 509 3 1224979098644774946 11 1224979098644774947 3 0 3 0 3 0 4 0 4 0 525 3 1224979098644774949 1224979098644774931 28 32 2 1224979098644774949 0 1702 1 1224979098644774949 1710 2 0 1224979098644774949 710 3 1224979098644774947 0 1 525 3 1224979098644774950 1224979098644774931 30 2105 2 1224979098644774950 1000 2147483678 2 1224979098644774947 1224979098644774950 505 3 1224979098644774931 30 1224979098644774947 5 0 505 3 1224979098644774931 28 -1 12 1 1224979098644774951 1702 1 1224979098644774951 1704 1 1224979098644774951 1770 2 1224979098644774946 1224979098644774951 1788 2 1224979098644774946 1224979098644774933 545 3 1224979098644774951 15 0 1710 2 0 1224979098644774951 710 3 1224979098644774947 0 1 4 0 525 3 1224979098644774949 1224979098644774931 28 31 2 1224979098644774949 -1 505 3 1224979098644774931 28 1224979098644774951 505 3 1224979098644774931 30 1224979098644774947 5 0 1710 2 2 1224979098644774949 710 3 1224979098644774948 2 1 2147483678 2 1224979098644774947 1224979098644774948 505 3 1224979098644774931 28 1224979098644774951 505 3 1224979098644774931 30 1224979098644774947 3 0 3 0 3 0 3 0 4 0 30 2 1224979098644774932 0 525 3 1224979098644774949 1224979098644774931 28 2147483679 2 1224979098644774949 -1 1710 2 0 1224979098644774949 710 3 1224979098644774947 0 1 4 0 2147483678 2 1224979098644774947 350 1773 2 72057594037927936 1224979098644774949 2120 3 1224979098644774929 113 72057594037927936 1770 2 72057594037927936 1224979098644774949 529 3 1224979098644774944 72057594037927936 1224979098644774929 2105 2 1224979098644774944 1 509 3 72057594037927936 1224979098644774929 1224979098644774944 3 0 2120 3 1224979098644774929 131 1224979098644774932 529 3 1224979098644774948 1224979098644774933 1224979098644774929 4 0 1073741855 2 1224979098644774948 0 2147483678 2 1224979098644774947 1224979098644774948 509 3 1224979098644774933 1224979098644774929 1224979098644774947 2120 3 1224979098644774929 122 1224979098644774932 509 3 1224979098644774933 1224979098644774929 1224979098644774949 3 0 2133 2 1224979098644774952 0 1772 2 1224979098644774953 1224979098644774949 2120 3 1224979098644774929 176 1224979098644774932 529 3 1224979098644774944 1224979098644774933 1224979098644774929 4 0 1073741855 2 1224979098644774944 3 31 2 1224979098644774944 0 2147483679 2 1224979098644774953 2 2133 2 1224979098644774952 1 5 0 1073741855 2 1224979098644774944 1 31 2 1224979098644774944 4 31 2 1224979098644774953 0 2133 2 1224979098644774952 1 3 0 31 2 1224979098644774952 1 2120 3 1224979098644774929 149 1224979098644774932 529 3 1224979098644774948 1224979098644774933 1224979098644774929 4 0 1073741855 2 1224979098644774948 0 2147483678 2 1224979098644774947 1224979098644774948 509 3 1224979098644774933 1224979098644774929 1224979098644774947 2120 3 1224979098644774929 140 1224979098644774932 509 3 1224979098644774933 1224979098644774929 1224979098644774949 3 0 3 0 3 0 6 3 1224979098644774928 0 4 2133 2 1224979098644774954 0 2133 2 1224979098644774955 0 2133 2 1224979098644774956 0 2133 2 1224979098644774957 0 6 3 1224979098644774930 0 9 2120 3 1224979098644774929 14 1224979098644774930 529 3 1224979098644774958 1224979098644774928 1224979098644774929 32 2 1224979098644774958 0 2105 2 1224979098644774954 1224979098644774958 2120 3 1224979098644774929 50 1224979098644774930 529 3 1224979098644774959 1224979098644774928 1224979098644774929 2105 2 1224979098644774955 1224979098644774959 2120 3 1224979098644774929 158 1224979098644774930 529 3 1224979098644774960 1224979098644774928 1224979098644774929 2105 2 1224979098644774956 1224979098644774960 2120 3 1224979098644774929 167 1224979098644774930 529 3 1224979098644774961 1224979098644774928 1224979098644774929 2105 2 1224979098644774957 1224979098644774961 2120 3 1224979098644774929 50 1224979098644774930 2108 2 1224979098644774959 1224979098644774958 509 3 1224979098644774928 1224979098644774929 1224979098644774959 2120 3 1224979098644774929 23 1224979098644774930 529 3 1224979098644774944 1224979098644774928 1224979098644774929 2107 2 1224979098644774944 100 2108 2 1224979098644774944 1224979098644774958 509 3 1224979098644774928 1224979098644774929 1224979098644774944 2120 3 1224979098644774929 32 1224979098644774930 529 3 1224979098644774944 1224979098644774928 1224979098644774929 2107 2 1224979098644774944 100 2108 2 1224979098644774944 1224979098644774958 509 3 1224979098644774928 1224979098644774929 1224979098644774944 2120 3 1224979098644774929 68 1224979098644774930 529 3 1224979098644774944 1224979098644774928 1224979098644774929 2108 2 1224979098644774944 1224979098644774958 509 3 1224979098644774928 1224979098644774929 1224979098644774944 2120 3 1224979098644774929 77 1224979098644774930 529 3 1224979098644774944 1224979098644774928 1224979098644774929 2108 2 1224979098644774944 1224979098644774958 509 3 1224979098644774928 1224979098644774929 1224979098644774944 2120 3 1224979098644774929 95 1224979098644774930 529 3 72057594037927936 1224979098644774928 1224979098644774929 4 0 32 2 72057594037927936 0 2120 3 1224979098644774929 86 1224979098644774930 529 3 1224979098644774944 1224979098644774928 1224979098644774929 2108 2 1224979098644774944 72057594037927936 509 3 1224979098644774928 1224979098644774929 1224979098644774944 3 0 2120 3 1224979098644774929 158 1224979098644774930 2108 2 1224979098644774960 1224979098644774958 509 3 1224979098644774928 1224979098644774929 1224979098644774960 2120 3 1224979098644774929 167 1224979098644774930 2108 2 1224979098644774961 1224979098644774958 509 3 1224979098644774928 1224979098644774929 1224979098644774961 2120 3 1224979098644774929 176 1224979098644774930 529 3 72057594037927936 1224979098644774928 1224979098644774929 4 0 2147483681 3 72057594037927936 0 8 1 3 936748722493063948 1224979098644774928 1224979098644774930 3 0 3 0 4 0 31 2 1224979098644774928 0 2105 2 1224979098644774954 1224979098644774912 2105 2 1224979098644774955 1224979098644774915 2105 2 1224979098644774956 1224979098644774913 2105 2 1224979098644774957 1224979098644774914 5 0 31 2 1224979098644774928 1 2105 2 1224979098644774954 1224979098644774916 2105 2 1224979098644774955 1224979098644774919 2105 2 1224979098644774956 1224979098644774917 2105 2 1224979098644774957 1224979098644774918 5 0 31 2 1224979098644774928 2 2105 2 1224979098644774954 1224979098644774920 2105 2 1224979098644774955 1224979098644774923 2105 2 1224979098644774956 1224979098644774921 2105 2 1224979098644774957 1224979098644774922 5 0 31 2 1224979098644774928 3 2105 2 1224979098644774954 1224979098644774924 2105 2 1224979098644774955 1224979098644774927 2105 2 1224979098644774956 1224979098644774925 2105 2 1224979098644774957 1224979098644774926 3 0 32 2 1224979098644774954 0 509 3 1224979098644774928 5 1224979098644774954 2108 2 1224979098644774955 1224979098644774954 509 3 1224979098644774928 10 1224979098644774955 2108 2 1224979098644774956 1224979098644774954 509 3 1224979098644774928 12 1224979098644774956 2108 2 1224979098644774957 1224979098644774954 509 3 1224979098644774928 13 1224979098644774957 3 0
这么改完,我基本开的最高特效,不再是1s一大卡了,变成了轻微一顿
这个其实还有一个 每秒1次的 AI 切换武器
改造的时候,没有动原来的,重新编写了那几个函数,把嵌套遍历拍平了,不会编译源码的话,会比较费劲
简单改法,可以把间隔拉长试试,mission_templates.txt
1.000000 0.000000 0.000000 0 246 1700 1 1224979098644774912 12 1 1224979098644774913
改成 10s 检查一次
10.000000 0.000000 0.000000 0 246 1700 1 1224979098644774912 12 1 1224979098644774913
|
|