stellaris吧 关注:303,646贴子:7,248,161

回复:Stellaris开发日志 #182 脚本编写的可能风险以及如何避免他们

只看楼主收藏回复

新年快乐
我写了这篇开发日志,就不能不告诉你“新年快乐”bug。简单地说,我们在一个相当大的星系上玩开发版MP,并达到了相当晚的时间。并且由于我们都在远程工作,以各种不同的电脑和互联网连接速度运行,性能可能有点慢,但大部分还是可以接受的。然后,突然间,我们注意到了巨大的延时尖峰——大约20 s或者更多——在1月1日。这些尖峰如此引人注目,以至于每次我们的游戏都冻结了,于是我们就开始祝福其他人新年快乐!
这种延时的爆发恰好与几个大帝国决定机飞,并开始同化他们的帝国相吻合。现在,同化属于应该在脚本中完成的事情,事后看来或许不应该那么做……甚至通过在每个1月1日为每个同化国家触发一个事件来工作。这个事件反过来为他们的每个行星都触发了一个事件,而这一被触发的事件有选择了行星上的每个pop,并至少对每个pop使用了一次modify_species,有时能多达四次。这加起来是十分重要的性能开销。
在尝试了各种解决方案后,我们发现最好的修复办法是,首先检查在这一国家作用域内的every_owned_species,检查这一物种是否应该被同化。如果应该,那么用modify_species来创造将被同化的物种,设置一个物种标志,用以指向正在被同化的物种。然后,不是为每一个被同化的pop创建一个新物种,脚本被重写为:查找已经被创造的pop应该被同化的物种,并简单地对其使用change_species。这一结果仍然是不可读的脚本(我会节省你们的眼神,不把它放在这里),但是在我的测试中,这样做减少了超过50%的每年的tick数。因为我们尽可能少地运行了复杂的效果(modify_species)。
Happy New Year
I can’t write this dev diary without telling you about the “Happy New Year” bug. Basically, we were playing dev MP on a reasonably large galaxy and reached reasonably late into the game, and since we were all working remotely on wildly varying computers and internet connection speeds, the performance was perhaps a tad sluggish, but still acceptable for the most part. Then, suddenly, we noticed huge lag spikes - 20 seconds and more - on the 1st of January. So noticeable were these spikes that we began wishing each other a Happy New Year each time the game froze!
It just so happened that the onset of this lag coincided with several large empires deciding to become synthetic and starting to assimilating their empires. Now, assimilation falls into the category of things that are done in script that maybe, in hindsight, should probably not have been done that way… and works by firing an event for each assimilating country every 1st of January. This event in turn fired an event for each of their planets that selected a bunch of pops on the planet and used modify_species on each of them at least once, but sometimes up to four times. This added up to a fairly significant performance hog!
After trying various solutions, it turned out the best way to fix this was to first go through every_owned_species from the country scope, check whether this species should be assimilated, and if so use modify_species to create the species it would assimilate to, setting a species flag that pointed to the species it was being assimilated from. Then, instead of creating a new species for every pop that was assimilated, the scripts were rewritten to find the already-created species that the pop should become, and simply use change_species on it. The result is still unreadable script (I will spare your eyes and not post it here), but in my tests it reduced the yearly tick by over 50%, thanks to the complicated effect (modify_species) being run as seldom as possible.


IP属地:重庆18楼2020-09-04 22:53
回复
    现在就是这些了!我想对大多数人来说,这是一个比平时更枯燥的开发日志,但是我希望它仍然很有趣。(括弧笑)最后,我想你们中比较勇的那些可能会把我叫出来,给我看在一些并不符合我之前讲述那些原则的脚本。请随便这么做,因为对于这个职业来说,没有什么比让一些相当糟糕的事情变得不那么糟糕更令人满意了
    That’s it for me, for now! I’m guessing this was a bit of a drier dev diary than usual for most of you, but hopefully it was interesting nonetheless. :) As a final note, I suspect that the more intrepid among you could call me out on bits of script in the base game that don’t quite live up to these guidelines. Please, feel free to do so, because there are few things more satisfying in this profession than taking something really horrible and making something less horrible out of it!


    IP属地:重庆20楼2020-09-04 22:57
    回复
      2026-01-11 22:53:22
      广告
      不感兴趣
      开通SVIP免广告
      开发日志就是这些了,不保证翻译准确性。
      快来氵快来氵


      IP属地:重庆来自Android客户端21楼2020-09-04 23:00
      回复
        第7楼也被吞了……


        IP属地:重庆22楼2020-09-04 23:10
        回复
          卧槽,半夜看这个要做噩梦


          IP属地:上海来自Android客户端23楼2020-09-05 00:22
          收起回复
            论花费25影响力的控制人口增长决议有多必要:

            另,现在一开星球界面就卡爆,有人知道为啥吗?


            IP属地:北京26楼2020-09-05 10:13
            收起回复
              蠢驴居然开始优化了....惊了


              IP属地:湖北27楼2020-09-05 11:02
              回复
                蠢驴居然自己开始检讨代码效率了?


                IP属地:广东来自Android客户端28楼2020-09-05 13:37
                回复
                  2026-01-11 22:47:22
                  广告
                  不感兴趣
                  开通SVIP免广告
                  啊, 他们终于开始玩我剩的东西了.jpg


                  IP属地:山东29楼2020-09-06 17:04
                  回复
                    普通人:modder好好看好好学,这就是优化
                    modder:优化?蠢驴你配?配几把?这不是我优化蠢驴的破玩意?


                    来自Android客户端30楼2020-09-06 18:16
                    回复
                      论优化,那都是modder玩剩下的...无尽群星的优化可是在很早之前就出现了


                      IP属地:广西31楼2020-09-06 23:05
                      回复


                        IP属地:江苏来自Android客户端32楼2020-09-07 14:40
                        回复
                          快100个mod 进游戏进半天


                          IP属地:江苏来自Android客户端33楼2020-09-10 00:27
                          回复